diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/CollatedObjectProperty.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/CollatedObjectProperty.java new file mode 100644 index 000000000..6e4ca58f5 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/CollatedObjectProperty.java @@ -0,0 +1,23 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; + +import java.util.List; + +public class CollatedObjectProperty extends ObjectPropertyTemplateModel { + + private List subclassList = null; + + CollatedObjectProperty(String predicateUri) { + super(predicateUri); + // TODO Auto-generated constructor stub + } + + public List getSubclassList() { + return subclassList; + } + + public List getStatements() { + return subclassList; + } +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DataPropertyStatementTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DataPropertyStatementTemplateModel.java new file mode 100644 index 000000000..dfbb6936f --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DataPropertyStatementTemplateModel.java @@ -0,0 +1,22 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class DataPropertyStatementTemplateModel extends PropertyStatementTemplateModel { + + private static final Log log = LogFactory.getLog(DataPropertyStatementTemplateModel.class); + + // not sure whether we want the objects or the uris here + //protected DataProperty property = null; + protected String predicateUri = null; + protected String data = null; + + DataPropertyStatementTemplateModel(String subjectUri, String predicateUri, String data) { + this.subjectUri = subjectUri; + this.predicateUri = predicateUri; + this.data = data; + } +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DataPropertyTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DataPropertyTemplateModel.java new file mode 100644 index 000000000..026b7a1e9 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DataPropertyTemplateModel.java @@ -0,0 +1,12 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; + +public class DataPropertyTemplateModel extends PropertyTemplateModel { + + DataPropertyTemplateModel(String predicateUri) { + super(predicateUri); + // TODO Auto-generated constructor stub + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DummyPropertyGroupTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DummyPropertyGroupTemplateModel.java new file mode 100644 index 000000000..35edadd9f --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DummyPropertyGroupTemplateModel.java @@ -0,0 +1,20 @@ +package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; + +import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup; + +public class DummyPropertyGroupTemplateModel extends + PropertyGroupTemplateModel { + + private String name; + + DummyPropertyGroupTemplateModel(String name) { + super(null); + this.name = name; + } + + @Override + public String getName() { + return name; + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java new file mode 100644 index 000000000..8b76fffdd --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java @@ -0,0 +1,89 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import edu.cornell.mannlib.vedit.beans.LoginStatusBean; +import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao; +import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; +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; + +/** The entire grouped property list for the subject. + * If there are no groups defined or populated, use a dummy group so that the + * display logic in the templates is the same whether or not there are groups. + * @author rjy7 + * + */ +public class GroupedPropertyList extends BaseTemplateModel { + + private static final Log log = LogFactory.getLog(GroupedPropertyList.class); + private static final int MAX_GROUP_DISPLAY_RANK = 99; + + /** Don't include these properties in the list. */ + private static final Collection SUPPRESSED_OBJECT_PROPERTIES = Collections + .unmodifiableCollection(Arrays + .asList(new String[] { VitroVocabulary.IND_MAIN_IMAGE })); + + // RY Do we really want to store subject and vreq as members? Could just pass around. + private Individual subject; + private VitroRequest vreq; + + private List groups; + + GroupedPropertyList(Individual subject, VitroRequest vreq) { + // RY Do we really want to store these as members? Could just pass around. + this.subject = subject; + this.vreq = vreq; + + // Get the property groups + WebappDaoFactory wdf = vreq.getWebappDaoFactory(); + PropertyGroupDao pgDao = wdf.getPropertyGroupDao(); + List groupList = pgDao.getPublicGroups(false); // may be returned empty but not null + + List groups = new ArrayList(groupList.size()); + for (PropertyGroup g : groupList) { + groups.add(new PropertyGroupTemplateModel(g)); + // Properties unassigned to any group go in a dummy group with name an empty string. Templates + // must test for <#if ! group.name?has_content> or <#if group.name == ""> or <#if group.name?length == 0> + groups.add(new DummyPropertyGroupTemplateModel("")); + } + // If there are no groups, create a dummy group, so that the template display logic is the same + // in both cases. Name is null. Templates must test for <#if ! group.name??> + if (groups.isEmpty()) { + groups.add(new DummyPropertyGroupTemplateModel(null)); + } + } + + /** + * Return true iff the user is editing. + */ + private boolean getEditingStatus() { + // These tests may change once self-editing issues are straightened out. + boolean isSelfEditing = VitroRequestPrep.isSelfEditing(vreq); + boolean isCurator = LoginStatusBean.getBean(vreq).isLoggedInAtLeast(LoginStatusBean.CURATOR); + return isSelfEditing || isCurator; + } + + /* + * Public getters for templates + */ + + public List getGroups() { + return groups; + } + + +} 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 cbd29ed56..109a3db3e 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 @@ -152,17 +152,19 @@ public class IndividualTemplateModel extends BaseTemplateModel { return models; } - public List getPropertyList() { - PropertyListBuilder propListBuilder = new PropertyListBuilder(individual, vreq); - return propListBuilder.getPropertyList(); + public GroupedPropertyList getPropertyList() { +// PropertyListBuilder propListBuilder = new PropertyListBuilder(individual, vreq); +// return propListBuilder.getPropertyList(); + return new GroupedPropertyList(individual, vreq); } - /* These methods simply forward to the Individual methods. It would be desirable to implement a scheme - for proxying or delegation so that the methods don't need to be simply listed here. - A Ruby-style method missing method would be ideal. - Update: DynamicProxy doesn't work because the proxied object is of type Individual, so we cannot - declare new methods here that are not declared in the Individual interface. - */ + /* These methods simply forward to the methods of the wrapped individual. It would be desirable to + * implement a scheme for proxying or delegation so that the methods don't need to be simply listed here. + * A Ruby-style method missing method would be ideal. + * Update: DynamicProxy doesn't work because the proxied object is of type Individual, so we cannot + * declare new methods here that are not declared in the Individual interface. + */ + public String getName() { return individual.getName(); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyStatementTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyStatementTemplateModel.java new file mode 100644 index 000000000..b9f140871 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyStatementTemplateModel.java @@ -0,0 +1,23 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class ObjectPropertyStatementTemplateModel extends PropertyStatementTemplateModel { + + private static final Log log = LogFactory.getLog(ObjectPropertyStatementTemplateModel.class); + + // not sure whether we want the objects or the uris here + //protected ObjectProperty property = null; + protected String predicateUri = null; + //protected Individual object = null; + protected String objectUri = null; + + ObjectPropertyStatementTemplateModel(String subjectUri, String predicateUri, String objectUri) { + this.subjectUri = subjectUri; + this.predicateUri = predicateUri; + this.objectUri = objectUri; + } +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java new file mode 100644 index 000000000..cd5d5607b --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java @@ -0,0 +1,12 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; + +public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel { + + ObjectPropertyTemplateModel(String predicateUri) { + super(predicateUri); + // TODO Auto-generated constructor stub + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/PropertyGroupTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/PropertyGroupTemplateModel.java new file mode 100644 index 000000000..ba5205ca9 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/PropertyGroupTemplateModel.java @@ -0,0 +1,29 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; + +import java.util.List; + +import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup; +import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel; + +public class PropertyGroupTemplateModel extends BaseTemplateModel { + + protected PropertyGroup group; + protected List properties; + + PropertyGroupTemplateModel() { } + + PropertyGroupTemplateModel(PropertyGroup group) { + this.group = group; + } + + public String getName() { + return group.getName(); + } + + public List getProperties() { + return properties; + } + +} 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/PropertyListBuilder.java deleted file mode 100644 index 6aae3c3cc..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/PropertyListBuilder.java +++ /dev/null @@ -1,83 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import edu.cornell.mannlib.vedit.beans.LoginStatusBean; -import edu.cornell.mannlib.vitro.webapp.beans.Individual; -import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; -import edu.cornell.mannlib.vitro.webapp.beans.Property; -import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup; -import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; -import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao; -import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; -import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; -import edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep; - -public class PropertyListBuilder { - - private static final Log log = LogFactory.getLog(PropertyListBuilder.class); - private static final int MAX_GROUP_DISPLAY_RANK = 99; - - // Don't include these properties in the list. - private static final Collection SUPPRESSED_OBJECT_PROPERTIES = Collections - .unmodifiableCollection(Arrays - .asList(new String[] { VitroVocabulary.IND_MAIN_IMAGE })); - - protected Individual subject; - protected VitroRequest vreq; - - PropertyListBuilder(Individual individual, VitroRequest vreq) { - this.subject = individual; - this.vreq = vreq; - } - - protected List getPropertyList() { - - // Determine whether we're editing or not. - // These tests may change once self-editing issues are straightened out. - boolean isSelfEditing = VitroRequestPrep.isSelfEditing(vreq); - boolean isCurator = LoginStatusBean.getBean(vreq).isLoggedInAtLeast(LoginStatusBean.CURATOR); - boolean isEditing = isSelfEditing || isCurator; - - // Determine whether to return a grouped or ungrouped property list. - // If the call specified ungrouped, use ungrouped. - // If the call specified grouped: - - WebappDaoFactory wdf = vreq.getWebappDaoFactory(); - PropertyGroupDao pgDao = wdf.getPropertyGroupDao(); - List groupsList = pgDao.getPublicGroups(false); // may be returned empty but not null - // Use ungrouped if no property groups are defined - - // If < 2 property groups are populated, we also want ungrouped, but we won't know that until we - // get the property list. - - - // Assemble the property list - List mergedPropertyList = new ArrayList(); - // First get the properties this entity actually has, presumably populated with statements - List objectPropertyList = subject.getObjectPropertyList(); - - for (ObjectProperty op : objectPropertyList) { - if (!SUPPRESSED_OBJECT_PROPERTIES.contains(op)) { - op.setEditLabel(op.getDomainPublic()); - mergedPropertyList.add(op); - }else{ - log.debug("suppressed " + op.getURI()); - } - } - - // If < 2 property groups populated, we want ungrouped. - // This can just be handled by not including a group, or using an "empty" group with no name. - - return null; - } -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/PropertyStatementTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/PropertyStatementTemplateModel.java new file mode 100644 index 000000000..b60da85c9 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/PropertyStatementTemplateModel.java @@ -0,0 +1,27 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel; + +public abstract class PropertyStatementTemplateModel extends BaseTemplateModel { + + private static final Log log = LogFactory.getLog(PropertyStatementTemplateModel.class); + + protected Individual subject = null; // not sure whether we want subject, or subject uri + protected String subjectUri = null; + + + public String getEditLink() { + return null; + } + + public String getDeleteLink() { + return null; + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/PropertyTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/PropertyTemplateModel.java new file mode 100644 index 000000000..e9ff62e37 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/PropertyTemplateModel.java @@ -0,0 +1,23 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; + +import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel; + +/** + * Represents the property statement list for a single property of an individual. + */ +public abstract class PropertyTemplateModel extends BaseTemplateModel { + + // Not sure whether we need the property or the uri. + protected String predicateUri = null; + + PropertyTemplateModel(String predicateUri) { + this.predicateUri = predicateUri; + } + + public String getAddLink() { + return null; + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/SubclassList.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/SubclassList.java new file mode 100644 index 000000000..89faed32f --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/SubclassList.java @@ -0,0 +1,26 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; + +import java.util.List; + +/** List of object property statements for an individual, where the objects belong to a single subclass **/ + +public class SubclassList { + + String name = null; + List statements = null; + + SubclassList(String name, List statements) { + this.name = name; + this.statements = statements; + } + + public String getName() { + return name; + } + + public List getStatements() { + return statements; + } +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/UncollatedObjectProperty.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/UncollatedObjectProperty.java new file mode 100644 index 000000000..191f5a761 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/UncollatedObjectProperty.java @@ -0,0 +1,20 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; + +import java.util.List; + +public class UncollatedObjectProperty extends ObjectPropertyTemplateModel { + + private List statements = null; + + UncollatedObjectProperty(String predicateUri) { + super(predicateUri); + // TODO Auto-generated constructor stub + } + + public List getStatements() { + return statements; + } + +}