NIHVIVO-1491 Move property list building routines into an object that will define methods to get and remove specific properties

This commit is contained in:
rjy7 2011-01-03 17:29:27 +00:00
parent 0b1e24b7e9
commit f03b69f309
3 changed files with 58 additions and 56 deletions

View file

@ -7,7 +7,6 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -27,35 +26,29 @@ import edu.cornell.mannlib.vitro.webapp.dao.PropertyInstanceDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep; import edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep;
/** /* This class extends ArrayList rather than BaseTemplateModel so the template can simply
* Build the list of ontology properties for display on an individual profile page. * call individual.propertyList. Otherwise, the class must declare a member list object
* @author rjy7 * and the template must call individual.propertyList.groups, which is semantically awkward.
* * But if we need the methods in BaseTemplateModel we'll have to do that.
*/ */
public class GroupedPropertyList extends ArrayList<PropertyGroupTemplateModel> {
// RY We may not need this class. Logic for building the list can be moved to GroupedPropertyList.java. private static final long serialVersionUID = 1L;
// Wait and see how much code remains here - if little, just put in IndividualTemplateModel. private static final Log log = LogFactory.getLog(GroupedPropertyList.class);
public class PropertyListBuilder {
private static final Log log = LogFactory.getLog(PropertyListBuilder.class);
private static final int MAX_GROUP_DISPLAY_RANK = 99; private static final int MAX_GROUP_DISPLAY_RANK = 99;
protected Individual subject; private Individual subject;
protected VitroRequest vreq; private VitroRequest vreq;
protected WebappDaoFactory wdf; private WebappDaoFactory wdf;
PropertyListBuilder(Individual individual, VitroRequest vreq) { GroupedPropertyList(Individual subject, VitroRequest vreq) {
this.subject = individual; this.subject = subject;
this.vreq = vreq; this.vreq = vreq;
this.wdf = vreq.getWebappDaoFactory(); this.wdf = vreq.getWebappDaoFactory();
}
// RY Create the list here first to get it working. Then consider moving to GroupedPropertyList constructor.
protected List<PropertyGroupTemplateModel> getPropertyList() {
// Determine whether we're editing or not. // Determine whether we're editing or not.
boolean userCanEditThisProfile = getEditingStatus(); boolean userCanEditThisProfile = getEditingStatus();
// 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>(); List<Property> propertyList = new ArrayList<Property>();
@ -89,36 +82,35 @@ public class PropertyListBuilder {
//dp.setLabel(dp.getPublicName()); //dp.setLabel(dp.getPublicName());
propertyList.add(dp); propertyList.add(dp);
} }
if (userCanEditThisProfile) { if (userCanEditThisProfile) {
mergeAllPossibleDataProperties(propertyList); mergeAllPossibleDataProperties(propertyList);
} }
sort(propertyList); //*** Does this do data and obj props, or just obj props??
// Put the list into groups
List<PropertyGroup> groupList = addPropertiesToGroups(propertyList);
// Build the template data model from the groupList
List<PropertyGroupTemplateModel> groups = new ArrayList<PropertyGroupTemplateModel>(groupList.size());
for (PropertyGroup pg : groupList) {
groups.add(new PropertyGroupTemplateModel(vreq, pg, subject));
}
return groups;
}
sort(propertyList); //*** Does this do data and obj props, or just obj props??
// Put the list into groups
List<PropertyGroup> propertyGroupList = addPropertiesToGroups(propertyList);
// Build the template data model from the groupList
//groups = new ArrayList<PropertyGroupTemplateModel>(propertyGroupList.size());
for (PropertyGroup pg : propertyGroupList) {
add(new PropertyGroupTemplateModel(vreq, pg, subject));
}
}
/** /**
* Return true iff the user is editing. * Return true iff the user is editing.
* These tests may change once self-editing issues are straightened out. What we really need to know * These tests may change once self-editing issues are straightened out. What we really need to know
* is whether the user can edit this profile, not whether in general they are an editor. * is whether the user can edit this profile, not whether in general he/she is an editor.
*/ */
private boolean getEditingStatus() { private boolean getEditingStatus() {
boolean isSelfEditing = VitroRequestPrep.isSelfEditing(vreq); boolean isSelfEditing = VitroRequestPrep.isSelfEditing(vreq);
boolean isCurator = LoginStatusBean.getBean(vreq).isLoggedInAtLeast(LoginStatusBean.CURATOR); boolean isCurator = LoginStatusBean.getBean(vreq).isLoggedInAtLeast(LoginStatusBean.CURATOR);
return isSelfEditing || isCurator; return isSelfEditing || isCurator;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected void sort(List<Property> propertyList) { protected void sort(List<Property> propertyList) {
try { try {
@ -181,7 +173,7 @@ public class PropertyListBuilder {
log.error("a null Collection is returned from PropertyInstanceDao.getAllPossiblePropInstForIndividual()"); log.error("a null Collection is returned from PropertyInstanceDao.getAllPossiblePropInstForIndividual()");
} }
} }
protected void mergeAllPossibleDataProperties(List<Property> propertyList) { protected void mergeAllPossibleDataProperties(List<Property> propertyList) {
DataPropertyDao dpDao = wdf.getDataPropertyDao(); DataPropertyDao dpDao = wdf.getDataPropertyDao();
// RY *** Does this exclude properties in the excluded namespaces already? If not, need same test as above // RY *** Does this exclude properties in the excluded namespaces already? If not, need same test as above
@ -203,9 +195,9 @@ public class PropertyListBuilder {
log.error("a null Collection is returned from DataPropertyDao.getAllPossibleDatapropsForIndividual())"); log.error("a null Collection is returned from DataPropertyDao.getAllPossibleDatapropsForIndividual())");
} }
} }
private List<PropertyGroup> addPropertiesToGroups(List<Property> propertyList) { private List<PropertyGroup> addPropertiesToGroups(List<Property> propertyList) {
// Get the property groups // Get the property groups
PropertyGroupDao pgDao = wdf.getPropertyGroupDao(); PropertyGroupDao pgDao = wdf.getPropertyGroupDao();
List<PropertyGroup> groupList = pgDao.getPublicGroups(false); // may be returned empty but not null List<PropertyGroup> groupList = pgDao.getPublicGroups(false); // may be returned empty but not null
@ -213,7 +205,7 @@ public class PropertyListBuilder {
// List<PropertyGroup> groupList = new ArrayList<PropertyGroup>(); // List<PropertyGroup> groupList = new ArrayList<PropertyGroup>();
int groupCount = groupList.size(); 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 * 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. * not a real group. This allows the looping structure in the template to be the same whether there are groups or not.
@ -226,7 +218,7 @@ public class PropertyListBuilder {
groupList.add(dummyGroup); groupList.add(dummyGroup);
return groupList; return groupList;
} }
/* /*
* This group will hold properties that are not assigned to any groups. In case no real property groups are * 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 * populated, we end up with the dummy group case above, and we will change the name to null to signal to the
@ -241,9 +233,9 @@ public class PropertyListBuilder {
log.error("Exception on sorting groupList in addPropertiesToGroups()"); log.error("Exception on sorting groupList in addPropertiesToGroups()");
} }
} }
populateGroupListWithProperties(groupList, groupForUnassignedProperties, propertyList); populateGroupListWithProperties(groupList, groupForUnassignedProperties, propertyList);
// Remove unpopulated groups // Remove unpopulated groups
try { try {
int removedCount = pgDao.removeUnpopulatedGroups(groupList); int removedCount = pgDao.removeUnpopulatedGroups(groupList);
@ -267,7 +259,7 @@ public class PropertyListBuilder {
return groupList; return groupList;
} }
private void populateGroupListWithProperties(List<PropertyGroup> groupList, private void populateGroupListWithProperties(List<PropertyGroup> groupList,
PropertyGroup groupForUnassignedProperties, List<Property> propertyList) { PropertyGroup groupForUnassignedProperties, List<Property> propertyList) {
@ -309,12 +301,12 @@ public class PropertyListBuilder {
} }
} }
} }
private class PropertyRanker implements Comparator {
private class PropertyRanker implements Comparator {
WebappDaoFactory wdf; WebappDaoFactory wdf;
PropertyGroupDao pgDao; PropertyGroupDao pgDao;
private PropertyRanker(VitroRequest vreq) { private PropertyRanker(VitroRequest vreq) {
this.wdf = vreq.getWebappDaoFactory(); this.wdf = vreq.getWebappDaoFactory();
this.pgDao = wdf.getPropertyGroupDao(); this.pgDao = wdf.getPropertyGroupDao();
@ -382,4 +374,15 @@ public class PropertyListBuilder {
return 0; return 0;
} }
} }
/* Access methods for templates */
public PropertyTemplateModel get(String propertyUri) {
return null;
}
public PropertyTemplateModel getAndRemoveFromList(String propertyUri) {
return null;
}
} }

View file

@ -122,9 +122,8 @@ public class IndividualTemplateModel extends BaseTemplateModel {
return models; return models;
} }
public List<PropertyGroupTemplateModel> getPropertyList() { public GroupedPropertyList getPropertyList() {
PropertyListBuilder propListBuilder = new PropertyListBuilder(individual, vreq); return new GroupedPropertyList(individual, vreq);
return propListBuilder.getPropertyList();
} }
/* These methods simply forward to the methods of the wrapped individual. It would be desirable to /* These methods simply forward to the methods of the wrapped individual. It would be desirable to

View file

@ -25,9 +25,9 @@
<nav role="navigation"> <nav role="navigation">
<ul id ="individual-tools-people" role="list"> <ul id ="individual-tools-people" role="list">
<li role="listitem"><a class="picto-font picto-uri" href="#">j</a></li> <li role="listitem"><a class="picto-font picto-uri" href="#">j</a></li>
<li role="listitem"><a class="picto-font picto-pdf" href="#">F</a></li> <li role="listitem"><a class="picto-font picto-pdf" href="#">F</a></li>
<li role="listitem"><a class="picto-font picto-share" href="#">R</a></li> <li role="listitem"><a class="picto-font picto-share" href="#">R</a></li>
<li role="listitem"><a class="icon-rdf" href="#">RDF</a></li> <li role="listitem"><a class="icon-rdf" href="#">RDF</a></li>
</ul> </ul>
</nav> </nav>