NIHVIVO-1491 Methods to get a single property, with or without removing from the list
This commit is contained in:
parent
0cc376e0a1
commit
97ecd6100f
4 changed files with 52 additions and 14 deletions
|
@ -25,13 +25,9 @@ import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.PropertyInstanceDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
||||
|
||||
/* 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<PropertyGroupTemplateModel> {
|
||||
public class GroupedPropertyList extends BaseTemplateModel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Log log = LogFactory.getLog(GroupedPropertyList.class);
|
||||
|
@ -40,6 +36,7 @@ public class GroupedPropertyList extends ArrayList<PropertyGroupTemplateModel> {
|
|||
private Individual subject;
|
||||
private VitroRequest vreq;
|
||||
private WebappDaoFactory wdf;
|
||||
private List<PropertyGroupTemplateModel> groups;
|
||||
|
||||
GroupedPropertyList(Individual subject, VitroRequest vreq) {
|
||||
this.subject = subject;
|
||||
|
@ -93,9 +90,9 @@ public class GroupedPropertyList extends ArrayList<PropertyGroupTemplateModel> {
|
|||
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 pg : propertyGroupList) {
|
||||
add(new PropertyGroupTemplateModel(vreq, pg, subject));
|
||||
groups.add(new PropertyGroupTemplateModel(vreq, pg, subject));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -375,14 +372,51 @@ public class GroupedPropertyList extends ArrayList<PropertyGroupTemplateModel> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/* Access methods for templates */
|
||||
|
||||
public PropertyTemplateModel get(String propertyUri) {
|
||||
return null;
|
||||
public List<PropertyGroupTemplateModel> getAll() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
public PropertyTemplateModel getAndRemoveFromList(String propertyUri) {
|
||||
return null;
|
||||
public PropertyTemplateModel getProperty(String propertyUri) {
|
||||
|
||||
PropertyTemplateModel propertyTemplateModel = null;
|
||||
|
||||
groupLoop: for (PropertyGroupTemplateModel pgtm : groups) {
|
||||
List<PropertyTemplateModel> properties = pgtm.getProperties();
|
||||
for (PropertyTemplateModel ptm : properties) {
|
||||
if (propertyUri.equals(ptm.getUri())) {
|
||||
propertyTemplateModel = ptm;
|
||||
break groupLoop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return propertyTemplateModel;
|
||||
}
|
||||
|
||||
public PropertyTemplateModel getPropertyAndRemoveFromList(String propertyUri) {
|
||||
|
||||
PropertyTemplateModel propertyTemplateModel = null;
|
||||
|
||||
groupLoop: for (PropertyGroupTemplateModel pgtm : groups) {
|
||||
List<PropertyTemplateModel> properties = pgtm.getProperties();
|
||||
for (PropertyTemplateModel ptm : properties) {
|
||||
if (propertyUri.equals(ptm.getUri())) {
|
||||
propertyTemplateModel = ptm;
|
||||
// Remove the property from the group
|
||||
properties.remove(ptm);
|
||||
// If this is the only property in the group, remove the group as well
|
||||
if (properties.size() == 0) {
|
||||
groups.remove(pgtm);
|
||||
}
|
||||
break groupLoop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return propertyTemplateModel;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,10 @@ public class PropertyGroupTemplateModel extends BaseTemplateModel {
|
|||
}
|
||||
}
|
||||
|
||||
protected void remove(PropertyTemplateModel ptm) {
|
||||
properties.remove(ptm);
|
||||
}
|
||||
|
||||
/* Freemarker doesn't consider this a getter, because it takes a parameter, so to call it as group.name
|
||||
* in the templates the method name must be simply "name" and not "getName."
|
||||
*/
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<#-- Template for property listing on individual profile page -->
|
||||
|
||||
<#list propertyGroups as group>
|
||||
<#list propertyGroups.all as group>
|
||||
|
||||
<#assign groupname = group.name(nameForOtherGroup)>
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<a name="property-nav"></a>
|
||||
|
||||
<ul role="list">
|
||||
<#list propertyGroups as group>
|
||||
<#list propertyGroups.all as group>
|
||||
<#assign groupname = group.name(nameForOtherGroup)>
|
||||
<#if groupname?has_content>
|
||||
<#-- capitalize will capitalize each word in the name; cap_first only the first. We may need a custom
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue