Fix comments (mostly alignments)

This commit is contained in:
ryounes 2011-07-25 15:52:51 +00:00
parent b765eeab79
commit 25ddcac07a

View file

@ -9,7 +9,6 @@ import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -44,9 +43,11 @@ public class GroupedPropertyList extends BaseTemplateModel {
private static final int MAX_GROUP_DISPLAY_RANK = 99;
@SuppressWarnings("serial")
protected static final List<String> VITRO_PROPS_TO_ADD_TO_LIST = new ArrayList<String>() {{
protected static final List<String> VITRO_PROPS_TO_ADD_TO_LIST = new ArrayList<String>() {
{
add(VitroVocabulary.IND_MAIN_IMAGE);
}};
}
};
private final Individual subject;
private final VitroRequest vreq;
@ -54,25 +55,30 @@ public class GroupedPropertyList extends BaseTemplateModel {
private List<PropertyGroupTemplateModel> groups;
GroupedPropertyList(Individual subject, VitroRequest vreq, EditingPolicyHelper policyHelper) {
GroupedPropertyList(Individual subject, VitroRequest vreq,
EditingPolicyHelper policyHelper) {
this.vreq = vreq;
this.subject = subject;
this.wdf = vreq.getWebappDaoFactory();
boolean editing = policyHelper != null;
// Create the property list for the subject. The properties will be put into groups later.
// Create the property list for the subject. The properties will be put
// into groups later.
List<Property> propertyList = new ArrayList<Property>();
// First get all the object properties that occur in statements in the db with this subject as subject.
// This may include properties that are not defined as "possible properties" for a subject of this class,
// First get all the object properties that occur in statements in the
// db with this subject as subject.
// This may include properties that are not defined as
// "possible properties" for a subject of this class,
// so we cannot just rely on getting that list.
List<ObjectProperty> populatedObjectPropertyList = subject.getPopulatedObjectPropertyList();
List<ObjectProperty> populatedObjectPropertyList = subject
.getPopulatedObjectPropertyList();
propertyList.addAll(populatedObjectPropertyList);
// If editing this page, merge in object properties applicable to the individual that are currently
// unpopulated, so the properties are displayed to allow statements to be added to these properties.
// RY In future, we should limit this to properties that the user CAN add properties to.
// RY In future, we should limit this to properties that the user has permission to add properties to.
if (editing) {
mergeAllPossibleObjectProperties(populatedObjectPropertyList, propertyList);
}
@ -83,7 +89,8 @@ public class GroupedPropertyList extends BaseTemplateModel {
// DataPropertyStatements. Note that this does not apply to object properties, because the queries
// can be customized and thus differ from property to property. So it's easier for now to keep the
// two working in parallel.
List<DataProperty> populatedDataPropertyList = subject.getPopulatedDataPropertyList();
List<DataProperty> populatedDataPropertyList = subject
.getPopulatedDataPropertyList();
propertyList.addAll(populatedDataPropertyList);
if (editing) {
@ -96,10 +103,12 @@ public class GroupedPropertyList extends BaseTemplateModel {
List<PropertyGroup> propertyGroupList = addPropertiesToGroups(propertyList);
// Build the template data model from the groupList
groups = new ArrayList<PropertyGroupTemplateModel>(propertyGroupList.size());
groups = new ArrayList<PropertyGroupTemplateModel>(
propertyGroupList.size());
for (PropertyGroup propertyGroup : propertyGroupList) {
groups.add(new PropertyGroupTemplateModel(vreq, propertyGroup, subject,
policyHelper, populatedDataPropertyList, populatedObjectPropertyList));
groups.add(new PropertyGroupTemplateModel(vreq, propertyGroup,
subject, policyHelper, populatedDataPropertyList,
populatedObjectPropertyList));
}
if (!editing) {
@ -116,7 +125,8 @@ public class GroupedPropertyList extends BaseTemplateModel {
Iterator<PropertyGroupTemplateModel> iGroups = groups.iterator();
while (iGroups.hasNext()) {
PropertyGroupTemplateModel pgtm = iGroups.next();
Iterator<PropertyTemplateModel> iProperties = pgtm.getProperties().iterator();
Iterator<PropertyTemplateModel> iProperties = pgtm.getProperties()
.iterator();
while (iProperties.hasNext()) {
PropertyTemplateModel property = iProperties.next();
if (property instanceof ObjectPropertyTemplateModel) {
@ -140,22 +150,28 @@ public class GroupedPropertyList extends BaseTemplateModel {
try {
Collections.sort(propertyList, new PropertyRanker(vreq));
} catch (Exception ex) {
log.error("Exception sorting merged property list: " + ex.getMessage());
log.error("Exception sorting merged property list: "
+ ex.getMessage());
}
}
private void mergeAllPossibleObjectProperties(List<ObjectProperty> populatedObjectPropertyList, List<Property> propertyList) {
private void mergeAllPossibleObjectProperties(
List<ObjectProperty> populatedObjectPropertyList,
List<Property> propertyList) {
// There is no ObjectPropertyDao.getAllPossibleObjectPropertiesForIndividual() parallel to
// DataPropertyDao.getAllPossibleDatapropsForIndividual(). The comparable method for object properties
// is defined using PropertyInstance rather than ObjectProperty.
PropertyInstanceDao piDao = wdf.getPropertyInstanceDao();
Collection<PropertyInstance> allPropInstColl = piDao.getAllPossiblePropInstForIndividual(subject.getURI());
Collection<PropertyInstance> allPropInstColl = piDao
.getAllPossiblePropInstForIndividual(subject.getURI());
if (allPropInstColl != null) {
for (PropertyInstance pi : allPropInstColl) {
if (pi != null) {
if (! alreadyOnObjectPropertyList(populatedObjectPropertyList, pi)) {
addObjectPropertyToPropertyList(pi.getPropertyURI(), propertyList);
if (!alreadyOnObjectPropertyList(
populatedObjectPropertyList, pi)) {
addObjectPropertyToPropertyList(pi.getPropertyURI(),
propertyList);
}
} else {
log.error("a property instance in the Collection created by PropertyInstanceDao.getAllPossiblePropInstForIndividual() is unexpectedly null");
@ -175,7 +191,8 @@ public class GroupedPropertyList extends BaseTemplateModel {
}
}
private boolean alreadyOnObjectPropertyList(List<ObjectProperty> opList, PropertyInstance pi) {
private boolean alreadyOnObjectPropertyList(List<ObjectProperty> opList,
PropertyInstance pi) {
if (pi.getPropertyURI() == null) {
return false;
}
@ -187,7 +204,8 @@ public class GroupedPropertyList extends BaseTemplateModel {
return false;
}
private void addObjectPropertyToPropertyList(String propertyUri, List<Property> propertyList) {
private void addObjectPropertyToPropertyList(String propertyUri,
List<Property> propertyList) {
ObjectPropertyDao opDao = wdf.getObjectPropertyDao();
ObjectProperty op = opDao.getObjectPropertyByURI(propertyUri);
if (op == null) {
@ -201,7 +219,8 @@ public class GroupedPropertyList extends BaseTemplateModel {
protected void mergeAllPossibleDataProperties(List<Property> propertyList) {
DataPropertyDao dpDao = wdf.getDataPropertyDao();
Collection <DataProperty> allDatapropColl = dpDao.getAllPossibleDatapropsForIndividual(subject.getURI());
Collection<DataProperty> allDatapropColl = dpDao
.getAllPossibleDatapropsForIndividual(subject.getURI());
if (allDatapropColl != null) {
for (DataProperty dp : allDatapropColl) {
if (dp != null) {
@ -219,7 +238,8 @@ public class GroupedPropertyList extends BaseTemplateModel {
}
}
private boolean alreadyOnPropertyList(List<Property> propertyList, Property p) {
private boolean alreadyOnPropertyList(List<Property> propertyList,
Property p) {
if (p.getURI() == null) {
log.error("Property p has no propertyURI in alreadyOnPropertyList()");
return true; // don't add to list
@ -227,7 +247,8 @@ public class GroupedPropertyList extends BaseTemplateModel {
return (alreadyOnPropertyList(propertyList, p.getURI()));
}
private boolean alreadyOnPropertyList(List<Property> propertyList, String propertyUri) {
private boolean alreadyOnPropertyList(List<Property> propertyList,
String propertyUri) {
for (Property p : propertyList) {
String uri = p.getURI();
if (uri != null && uri.equals(propertyUri)) {
@ -237,7 +258,8 @@ public class GroupedPropertyList extends BaseTemplateModel {
return false;
}
private List<PropertyGroup> addPropertiesToGroups(List<Property> propertyList) {
private List<PropertyGroup> addPropertiesToGroups(
List<Property> propertyList) {
// Get the property groups
PropertyGroupDao pgDao = wdf.getPropertyGroupDao();
@ -248,8 +270,10 @@ public class GroupedPropertyList extends BaseTemplateModel {
int groupCount = groupList.size();
/*
* If no property groups are defined, create a dummy group with a null name to signal to the template that it's
* not a real group. This allows the looping structure in the template to be the same whether there are groups or not.
* If no property groups are defined, create a dummy group with a null
* name to signal to the template that it's not a real group. This
* allows the looping structure in the template to be the same whether
* there are groups or not.
*/
if (groupCount == 0) {
log.warn("groupList has no groups on entering addPropertiesToGroups(); will create a new group");
@ -260,11 +284,13 @@ public class GroupedPropertyList extends BaseTemplateModel {
}
/*
* This group will hold properties that are not assigned to any groups. In case no real property groups are
* populated, we end up with the dummy group case above, and we will change the name to null to signal to the
* template that it shouldn't be treated like a group.
* This group will hold properties that are not assigned to any groups.
* In case no real property groups are populated, we end up with the
* dummy group case above, and we will change the name to null to signal
* to the template that it shouldn't be treated like a group.
*/
PropertyGroup groupForUnassignedProperties = pgDao.createDummyPropertyGroup("", MAX_GROUP_DISPLAY_RANK);
PropertyGroup groupForUnassignedProperties = pgDao
.createDummyPropertyGroup("", MAX_GROUP_DISPLAY_RANK);
if (groupCount > 1) {
try {
@ -274,24 +300,29 @@ public class GroupedPropertyList extends BaseTemplateModel {
}
}
populateGroupListWithProperties(groupList, groupForUnassignedProperties, propertyList);
populateGroupListWithProperties(groupList,
groupForUnassignedProperties, propertyList);
// Remove unpopulated groups
try {
int removedCount = pgDao.removeUnpopulatedGroups(groupList);
if (removedCount == 0) {
log.warn("Of "+groupCount+" groups, none removed by removeUnpopulatedGroups");
log.warn("Of " + groupCount
+ " groups, none removed by removeUnpopulatedGroups");
}
groupCount -= removedCount;
} catch (Exception ex) {
log.error("Exception on trying to prune groups list with properties: "+ex.getMessage());
log.error("Exception on trying to prune groups list with properties: "
+ ex.getMessage());
}
// If the group for unassigned properties is populated, add it to the group list.
// If the group for unassigned properties is populated, add it to the
// group list.
if (groupForUnassignedProperties.getPropertyList().size() > 0) {
groupList.add(groupForUnassignedProperties);
// If no real property groups are populated, the groupForUnassignedProperties moves from case 2 to case 1 above, so change
// the name to null to signal to the templates that there are no real groups.
// If no real property groups are populated, the groupForUnassignedProperties
// moves from case 2 to case 1 above, so change the name to null
// to signal to the templates that there are no real groups.
if (groupCount == 0) {
groupForUnassignedProperties.setName(null);
}
@ -301,7 +332,8 @@ public class GroupedPropertyList extends BaseTemplateModel {
}
private void populateGroupListWithProperties(List<PropertyGroup> groupList,
PropertyGroup groupForUnassignedProperties, List<Property> propertyList) {
PropertyGroup groupForUnassignedProperties,
List<Property> propertyList) {
// Clear out the property lists on the groups
for (PropertyGroup pg : groupList) {
@ -314,7 +346,8 @@ public class GroupedPropertyList extends BaseTemplateModel {
for (Property p : propertyList) {
if (p.getURI() == null) {
log.error("Property p has null URI in populateGroupListWithProperties()");
// If the property is not assigned to any group, add it to the group for unassigned properties
// If the property is not assigned to any group, add it to the
// group for unassigned properties
} else {
String groupUriForProperty = p.getGroupURI();
boolean assignedToGroup = false;
@ -335,7 +368,8 @@ public class GroupedPropertyList extends BaseTemplateModel {
if (!assignedToGroup) {
if (groupForUnassignedProperties != null) {
groupForUnassignedProperties.getPropertyList().add(p);
log.debug("adding property " + getLabel(p) + " to group for unassigned properties");
log.debug("adding property " + getLabel(p)
+ " to group for unassigned properties");
}
}
}
@ -372,7 +406,8 @@ public class GroupedPropertyList extends BaseTemplateModel {
try {
return Integer.parseInt(tierStr);
} catch (NumberFormatException ex) {
log.error("Cannot decode object property display tier value "+tierStr+" as an integer");
log.error("Cannot decode object property display tier value "
+ tierStr + " as an integer");
}
} else {
log.error("Property is of unknown class in PropertyRanker()");
@ -381,8 +416,8 @@ public class GroupedPropertyList extends BaseTemplateModel {
}
}
// Since we're now including some vitro properties in the property list, which don't have labels,
// use their local name instead.
// Since we're now including some vitro properties in the property list,
// which don't have labels, use their local name instead.
private String getLabel(Property property) {
String label = property.getLabel();
if (label == null) {
@ -417,8 +452,8 @@ public class GroupedPropertyList extends BaseTemplateModel {
for (PropertyTemplateModel ptm : properties) {
if (propertyUri.equals(ptm.getUri())) {
// Remove the property from the group.
// NB Works with a for-each loop instead of an iterator, since
// iteration doesn't continue after the remove.
// NB Works with a for-each loop instead of an iterator,
// since iteration doesn't continue after the remove.
properties.remove(ptm);
// If this is the only property in the group, remove the group as well.
// NB Works with a for-each loop instead of an iterator, since
@ -433,4 +468,3 @@ public class GroupedPropertyList extends BaseTemplateModel {
return null;
}
}