From f03b69f309d470d0175891b1a458c91111007d1d Mon Sep 17 00:00:00 2001 From: rjy7 Date: Mon, 3 Jan 2011 17:29:27 +0000 Subject: [PATCH] NIHVIVO-1491 Move property list building routines into an object that will define methods to get and remove specific properties --- ...tBuilder.java => GroupedPropertyList.java} | 103 +++++++++--------- .../individual/IndividualTemplateModel.java | 5 +- .../freemarker/body/individual/individual.ftl | 6 +- 3 files changed, 58 insertions(+), 56 deletions(-) rename webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/{PropertyListBuilder.java => GroupedPropertyList.java} (92%) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/PropertyListBuilder.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java similarity index 92% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/PropertyListBuilder.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java index c71cae7cf..be9dda50b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/PropertyListBuilder.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java @@ -7,7 +7,6 @@ import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.List; -import java.util.Map; import org.apache.commons.logging.Log; 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.filters.VitroRequestPrep; -/** - * Build the list of ontology properties for display on an individual profile page. - * @author rjy7 - * +/* This class extends ArrayList rather than BaseTemplateModel so the template can simply + * call individual.propertyList. Otherwise, the class must declare a member list object + * 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 { -// RY We may not need this class. Logic for building the list can be moved to GroupedPropertyList.java. -// Wait and see how much code remains here - if little, just put in IndividualTemplateModel. -public class PropertyListBuilder { - - private static final Log log = LogFactory.getLog(PropertyListBuilder.class); + private static final long serialVersionUID = 1L; + private static final Log log = LogFactory.getLog(GroupedPropertyList.class); private static final int MAX_GROUP_DISPLAY_RANK = 99; - protected Individual subject; - protected VitroRequest vreq; - protected WebappDaoFactory wdf; - - PropertyListBuilder(Individual individual, VitroRequest vreq) { - this.subject = individual; + private Individual subject; + private VitroRequest vreq; + private WebappDaoFactory wdf; + + GroupedPropertyList(Individual subject, VitroRequest vreq) { + this.subject = subject; this.vreq = vreq; this.wdf = vreq.getWebappDaoFactory(); - } - - // RY Create the list here first to get it working. Then consider moving to GroupedPropertyList constructor. - protected List getPropertyList() { - + // Determine whether we're editing or not. boolean userCanEditThisProfile = getEditingStatus(); - + // Create the property list for the subject. The properties will be put into groups later. List propertyList = new ArrayList(); @@ -89,36 +82,35 @@ public class PropertyListBuilder { //dp.setLabel(dp.getPublicName()); propertyList.add(dp); } - + if (userCanEditThisProfile) { mergeAllPossibleDataProperties(propertyList); } - - sort(propertyList); //*** Does this do data and obj props, or just obj props?? - - // Put the list into groups - List groupList = addPropertiesToGroups(propertyList); - - // Build the template data model from the groupList - List groups = new ArrayList(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 propertyGroupList = addPropertiesToGroups(propertyList); + + // Build the template data model from the groupList + //groups = new ArrayList(propertyGroupList.size()); + for (PropertyGroup pg : propertyGroupList) { + add(new PropertyGroupTemplateModel(vreq, pg, subject)); + } + + } + /** * Return true iff the user is editing. * 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() { boolean isSelfEditing = VitroRequestPrep.isSelfEditing(vreq); boolean isCurator = LoginStatusBean.getBean(vreq).isLoggedInAtLeast(LoginStatusBean.CURATOR); return isSelfEditing || isCurator; } - + @SuppressWarnings("unchecked") protected void sort(List propertyList) { try { @@ -181,7 +173,7 @@ public class PropertyListBuilder { log.error("a null Collection is returned from PropertyInstanceDao.getAllPossiblePropInstForIndividual()"); } } - + protected void mergeAllPossibleDataProperties(List propertyList) { DataPropertyDao dpDao = wdf.getDataPropertyDao(); // 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())"); } } - + private List addPropertiesToGroups(List propertyList) { - + // Get the property groups PropertyGroupDao pgDao = wdf.getPropertyGroupDao(); List groupList = pgDao.getPublicGroups(false); // may be returned empty but not null @@ -213,7 +205,7 @@ public class PropertyListBuilder { // List groupList = new ArrayList(); 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. @@ -226,7 +218,7 @@ public class PropertyListBuilder { groupList.add(dummyGroup); return groupList; } - + /* * 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 @@ -241,9 +233,9 @@ public class PropertyListBuilder { log.error("Exception on sorting groupList in addPropertiesToGroups()"); } } - + populateGroupListWithProperties(groupList, groupForUnassignedProperties, propertyList); - + // Remove unpopulated groups try { int removedCount = pgDao.removeUnpopulatedGroups(groupList); @@ -267,7 +259,7 @@ public class PropertyListBuilder { return groupList; } - + private void populateGroupListWithProperties(List groupList, PropertyGroup groupForUnassignedProperties, List propertyList) { @@ -309,12 +301,12 @@ public class PropertyListBuilder { } } } - - private class PropertyRanker implements Comparator { + private class PropertyRanker implements Comparator { + WebappDaoFactory wdf; PropertyGroupDao pgDao; - + private PropertyRanker(VitroRequest vreq) { this.wdf = vreq.getWebappDaoFactory(); this.pgDao = wdf.getPropertyGroupDao(); @@ -382,4 +374,15 @@ public class PropertyListBuilder { return 0; } } + + /* Access methods for templates */ + + public PropertyTemplateModel get(String propertyUri) { + return null; + } + + public PropertyTemplateModel getAndRemoveFromList(String propertyUri) { + return null; + } } + diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java index 0ee63f3ca..7f272e678 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java @@ -122,9 +122,8 @@ public class IndividualTemplateModel extends BaseTemplateModel { return models; } - public List getPropertyList() { - PropertyListBuilder propListBuilder = new PropertyListBuilder(individual, vreq); - return propListBuilder.getPropertyList(); + public GroupedPropertyList getPropertyList() { + return new GroupedPropertyList(individual, vreq); } /* These methods simply forward to the methods of the wrapped individual. It would be desirable to diff --git a/webapp/web/templates/freemarker/body/individual/individual.ftl b/webapp/web/templates/freemarker/body/individual/individual.ftl index 3d7ea07e5..6d29b3059 100644 --- a/webapp/web/templates/freemarker/body/individual/individual.ftl +++ b/webapp/web/templates/freemarker/body/individual/individual.ftl @@ -25,9 +25,9 @@