Re-refactoring in template model objects: move vreq instance member out of BaseTemplateModel and into only those classes that use it. Also add final modifier to some instance variables, and remove initializations to null.

This commit is contained in:
ryounes 2011-07-07 22:19:35 +00:00
parent 2e757891e3
commit f99b450c83
27 changed files with 83 additions and 110 deletions

View file

@ -76,6 +76,7 @@ public class MenuDaoJena extends JenaBaseDao implements MenuDao {
//run SPARQL query to get menu and menu items
QueryExecution qexec = QueryExecutionFactory.create(menuQuery, displayModel, initialBindings );
try{
// ryounes Seems suspicious that a dao is creating a template model object. What's this all about?
MainMenu menu = new MainMenu();
/* bdc34: currently there is no good way to decide which url to show

View file

@ -16,16 +16,6 @@ public abstract class BaseTemplateModel {
private static final Log log = LogFactory.getLog(BaseTemplateModel.class);
protected static ServletContext servletContext;
protected final VitroRequest vreq;
protected BaseTemplateModel(VitroRequest vreq) {
this.vreq = vreq;
}
// Provide no-arg constructor for types that don't need vreq.
protected BaseTemplateModel() {
this.vreq = null;
};
// Convenience method so subclasses can call getUrl(path)
protected String getUrl(String path) {

View file

@ -6,7 +6,7 @@ import java.util.LinkedHashSet;
public class Tags extends BaseTemplateModel {
protected LinkedHashSet<String> tags = null;
protected final LinkedHashSet<String> tags;
public Tags() {
this.tags = new LinkedHashSet<String>();

View file

@ -16,11 +16,12 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.SiteAdminControlle
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
public class User extends BaseTemplateModel {
private final VitroRequest vreq;
private final UserAccount currentUser;
private final String profileUrl;
public User(VitroRequest vreq) {
super(vreq);
this.vreq = vreq;
this.currentUser = LoginStatusBean.getCurrentUser(vreq);
this.profileUrl = figureAssociatedProfileUrl();
}

View file

@ -16,8 +16,8 @@ public class VClassGroupTemplateModel extends BaseTemplateModel {
private static final Log log = LogFactory.getLog(VClassGroupTemplateModel.class.getName());
private VClassGroup vClassGroup = null;
private List<VClassTemplateModel> classes = null;
private final VClassGroup vClassGroup;
private List<VClassTemplateModel> classes;
public VClassGroupTemplateModel(VClassGroup vClassGroup) {
this.vClassGroup = vClassGroup;

View file

@ -15,7 +15,7 @@ public class VClassTemplateModel extends BaseTemplateModel {
private static final Log log = LogFactory.getLog(VClassTemplateModel.class);
private static final String PATH = Route.INDIVIDUAL_LIST.path();
private VClass vclass;
private final VClass vclass;
public VClassTemplateModel(VClass vclass) {
this.vclass = vclass;

View file

@ -7,10 +7,11 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
public class EditConfigurationTemplateModel extends BaseTemplateModel {
EditConfigurationVTwo editConfig;
VitroRequest vreq;
public EditConfigurationTemplateModel( EditConfigurationVTwo editConfig, VitroRequest vreq){
final EditConfigurationVTwo editConfig;
final VitroRequest vreq;
public EditConfigurationTemplateModel(EditConfigurationVTwo editConfig, VitroRequest vreq){
this.editConfig = editConfig;
this.vreq = vreq;
}

View file

@ -9,7 +9,12 @@ import com.hp.hpl.jena.rdf.model.Literal;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission;
public class EditSubmissionTemplateModel {
private EditSubmission editSub;
private final EditSubmission editSub;
public EditSubmissionTemplateModel(EditSubmission editSub){
this.editSub = editSub;
}
public Map<String, Literal> getLiteralsFromForm() {
return editSub.getLiteralsFromForm();
@ -23,11 +28,4 @@ public class EditSubmissionTemplateModel {
return editSub.getUrisFromForm();
}
public EditSubmissionTemplateModel(EditSubmission editSub){
this.editSub = editSub;
}
}

View file

@ -9,7 +9,12 @@ import com.hp.hpl.jena.rdf.model.Literal;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.MultiValueEditSubmission;
public class MultiValueEditSubmissionTemplateModel {
private MultiValueEditSubmission editSub;
private final MultiValueEditSubmission editSub;
public MultiValueEditSubmissionTemplateModel(MultiValueEditSubmission editSub){
this.editSub = editSub;
}
public Map<String, List<Literal>> getLiteralsFromForm() {
return editSub.getLiteralsFromForm();
@ -24,11 +29,4 @@ public class MultiValueEditSubmissionTemplateModel {
return editSub.getUrisFromForm();
}
public MultiValueEditSubmissionTemplateModel(MultiValueEditSubmission editSub){
this.editSub = editSub;
}
}

View file

@ -31,13 +31,16 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
private static final Log log = LogFactory.getLog(BaseIndividualTemplateModel.class);
protected Individual individual;
protected final Individual individual;
protected final LoginStatusBean loginStatusBean;
protected final VitroRequest vreq;
protected GroupedPropertyList propertyList;
protected LoginStatusBean loginStatusBean;
private EditingPolicyHelper policyHelper;
public BaseIndividualTemplateModel(Individual individual, VitroRequest vreq) {
super(vreq);
this.vreq = vreq;
this.individual = individual;
this.loginStatusBean = LoginStatusBean.getBean(vreq);
// Needed for getting portal-sensitive urls. Remove if multi-portal support is removed.

View file

@ -19,8 +19,8 @@ public abstract class BaseObjectPropertyDataPostProcessor implements
private static final Log log = LogFactory.getLog(BaseObjectPropertyDataPostProcessor.class);
protected ObjectPropertyTemplateModel objectPropertyTemplateModel;
protected WebappDaoFactory wdf;
protected final ObjectPropertyTemplateModel objectPropertyTemplateModel;
protected final WebappDaoFactory wdf;
public BaseObjectPropertyDataPostProcessor(ObjectPropertyTemplateModel optm, WebappDaoFactory wdf) {
this.objectPropertyTemplateModel = optm;

View file

@ -38,7 +38,7 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
private static final Pattern ORDER_BY_SUBCLASS_PATTERN =
Pattern.compile("ORDER\\s+BY\\s+(DESC\\s*\\(\\s*)?\\?" + SUBCLASS_VARIABLE_NAME, Pattern.CASE_INSENSITIVE);
private SortedMap<String, List<ObjectPropertyStatementTemplateModel>> subclasses;
private final SortedMap<String, List<ObjectPropertyStatementTemplateModel>> subclasses;
CollatedObjectPropertyTemplateModel(ObjectProperty op, Individual subject,
VitroRequest vreq, EditingPolicyHelper policyHelper,
@ -47,8 +47,6 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
super(op, subject, vreq, policyHelper);
subclasses = new TreeMap<String, List<ObjectPropertyStatementTemplateModel>>();
if (populatedObjectPropertyList.contains(op)) {
log.debug("Getting data for populated object property " + op.getURI());
@ -66,6 +64,7 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
}
} else {
log.debug("Object property " + getUri() + " is unpopulated.");
subclasses = new TreeMap<String, List<ObjectPropertyStatementTemplateModel>>();
}
}

View file

@ -26,10 +26,10 @@ public class DataPropertyStatementTemplateModel extends PropertyStatementTemplat
private static final Log log = LogFactory.getLog(DataPropertyStatementTemplateModel.class);
private static final String EDIT_PATH = "edit/editDatapropStmtRequestDispatch.jsp";
protected String value = null;
protected String value;
// Used for editing
protected String dataPropHash = null;
protected String dataPropHash;
//Extended to include vitro request to check for special parameters
DataPropertyStatementTemplateModel(String subjectUri, String propertyUri,

View file

@ -31,7 +31,7 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
private static final String TYPE = "data";
private static final String EDIT_PATH = "edit/editDatapropStmtRequestDispatch.jsp";
private List<DataPropertyStatementTemplateModel> statements;
private final List<DataPropertyStatementTemplateModel> statements;
DataPropertyTemplateModel(DataProperty dp, Individual subject, VitroRequest vreq,
EditingPolicyHelper policyHelper, List<DataProperty> populatedDataPropertyList) {

View file

@ -44,19 +44,17 @@ public class GroupedPropertyList extends BaseTemplateModel {
@SuppressWarnings("serial")
protected static final List<String> VITRO_PROPS_TO_ADD_TO_LIST = new ArrayList<String>() {{
add(VitroVocabulary.PRIMARY_LINK);
add(VitroVocabulary.ADDITIONAL_LINK);
add(VitroVocabulary.IND_MAIN_IMAGE);
}};
private Individual subject;
private VitroRequest vreq;
private WebappDaoFactory wdf;
private final Individual subject;
private final VitroRequest vreq;
private final WebappDaoFactory wdf;
private List<PropertyGroupTemplateModel> groups;
GroupedPropertyList(Individual subject, VitroRequest vreq, EditingPolicyHelper policyHelper) {
super(vreq);
this.vreq = vreq;
this.subject = subject;
this.wdf = vreq.getWebappDaoFactory();

View file

@ -25,11 +25,11 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
private static final String EDIT_PATH = "edit/editRequestDispatch.jsp";
private Map<String, String> data;
private final Map<String, String> data;
// Used for editing
private String objectUri;
private String templateName;
private final String objectUri;
private final String templateName;
//Updating to include Vitro Request
ObjectPropertyStatementTemplateModel(String subjectUri, String propertyUri, String objectKey,
@ -42,18 +42,6 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
setEditAccess(policyHelper);
}
/**
* This method handles the special case where we are creating a DataPropertyStatementTemplateModel
* outside the GroupedPropertyList. Specifically, it allows vitro:primaryLink and vitro:additionalLink
* to be treated like object property statements and thus have editing links. (In a future version,
* these properties will be replaced by vivo core ontology properties.) It could potentially be used
* for other properties outside the property list as well.
*/
ObjectPropertyStatementTemplateModel(String subjectUri, String propertyUri,
VitroRequest vreq, EditingPolicyHelper policyHelper) {
super(subjectUri, propertyUri, policyHelper, vreq);
}
private void setEditAccess(EditingPolicyHelper policyHelper) {
// If the policyHelper is non-null, we are in edit mode, so create the list of editing permissions.
// We do this now rather than in getEditUrl() and getDeleteUrl(), because getEditUrl() also needs to know

View file

@ -91,10 +91,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
private String objectKey;
// Used for editing
private boolean addAccess = false;
//To allow for checking of special parameters
private VitroRequest vitroRequest = null;
private boolean addAccess; // defaults to false
ObjectPropertyTemplateModel(ObjectProperty op, Individual subject, VitroRequest vreq,
EditingPolicyHelper policyHelper)
@ -588,7 +585,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
"predicateUri", propertyUri);
//Check if special parameters being sent
HashMap<String, String> specialParams = UrlBuilder.getSpecialParams(vitroRequest);
HashMap<String, String> specialParams = UrlBuilder.getSpecialParams(vreq);
if(specialParams.size() > 0) {
params.putAll(specialParams);
}

View file

@ -22,8 +22,8 @@ public class PropertyGroupTemplateModel extends BaseTemplateModel {
private static final Log log = LogFactory.getLog(PropertyGroupTemplateModel.class);
private String name;
private List<PropertyTemplateModel> properties;
private final String name;
private final List<PropertyTemplateModel> properties;
PropertyGroupTemplateModel(VitroRequest vreq, PropertyGroup group,
Individual subject, EditingPolicyHelper policyHelper,

View file

@ -20,21 +20,21 @@ public abstract class PropertyStatementTemplateModel extends BaseTemplateModel {
EDIT, DELETE;
}
protected final VitroRequest vreq;
// Used for editing
protected String subjectUri = null;
protected String propertyUri = null;
private List<EditAccess> editAccessList = null;
protected final String subjectUri;
protected final String propertyUri;
private final List<EditAccess> editAccessList;
PropertyStatementTemplateModel(String subjectUri, String propertyUri, EditingPolicyHelper policyHelper, VitroRequest vreq) {
super(vreq);
this.vreq = vreq;
// Instantiate the list even if not editing, so calls to getEditUrl() and getDeleteUrl() from
// dump methods don't generate an error when they call isEditable() and isDeletable().
editAccessList = new ArrayList<EditAccess>();
if (policyHelper != null) { // we're editing
this.subjectUri = subjectUri;
this.propertyUri = propertyUri;
}
}
protected void markEditable() {

View file

@ -26,15 +26,17 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
private static final Log log = LogFactory.getLog(PropertyTemplateModel.class);
protected final VitroRequest vreq;
protected final String subjectUri;
protected final String propertyUri;
private final String localName;
protected Map<String, Object> verboseDisplay;
protected boolean addAccess; // defaults to false
private String name;
private String localName;
protected String propertyUri;
protected Map<String, Object> verboseDisplay = null;
protected String subjectUri = null;
protected boolean addAccess = false;
PropertyTemplateModel(Property property, Individual subject, EditingPolicyHelper policyHelper, VitroRequest vreq) {
super(vreq);
this.vreq = vreq;
subjectUri = subject.getURI();
propertyUri = property.getURI();
localName = property.getLocalName();

View file

@ -19,7 +19,7 @@ public class UncollatedObjectPropertyTemplateModel extends ObjectPropertyTemplat
private static final Log log = LogFactory.getLog(UncollatedObjectPropertyTemplateModel.class);
private List<ObjectPropertyStatementTemplateModel> statements;
private final List<ObjectPropertyStatementTemplateModel> statements;
UncollatedObjectPropertyTemplateModel(ObjectProperty op, Individual subject,
VitroRequest vreq, EditingPolicyHelper policyHelper,

View file

@ -19,10 +19,11 @@ public abstract class BaseListedIndividual extends BaseTemplateModel {
private static final Log log = LogFactory.getLog(BaseListedIndividual.class);
protected Individual individual;
protected final Individual individual;
protected final VitroRequest vreq;
public BaseListedIndividual(Individual individual, VitroRequest vreq) {
super(vreq);
this.vreq = vreq;
this.individual = individual;
}

View file

@ -17,10 +17,12 @@ public class MainMenu extends Menu {
private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(MainMenu.class);
public MainMenu(){ }
protected VitroRequest vreq;
public MainMenu() { }
public MainMenu(VitroRequest vreq) {
super(vreq);
this.vreq = vreq;
}
public void addItem(String text, String path) {

View file

@ -18,11 +18,6 @@ public class Menu extends BaseTemplateModel {
protected List<MenuItem> items;
public Menu(VitroRequest vreq) {
super(vreq);
items = new ArrayList<MenuItem>();
}
public Menu() {
items = new ArrayList<MenuItem>();
}

View file

@ -11,8 +11,8 @@ public class MenuItem extends BaseTemplateModel {
private static final Log log = LogFactory.getLog(MenuItem.class.getName());
private String text;
private String path;
private final String text;
private final String path;
private boolean active;
public MenuItem(String linkText, String path) {

View file

@ -22,10 +22,11 @@ public abstract class BaseIndividualSearchResult extends BaseTemplateModel {
private static final Log log = LogFactory.getLog(BaseIndividualSearchResult.class);
protected Individual individual;
protected final VitroRequest vreq;
protected final Individual individual;
public BaseIndividualSearchResult(Individual individual, VitroRequest vreq) {
super(vreq);
this.vreq = vreq;
this.individual = individual;
}

View file

@ -12,8 +12,6 @@ public class IndividualSearchResult extends BaseIndividualSearchResult {
private static final Log log = LogFactory.getLog(IndividualSearchResult.class);
protected Individual individual;
public IndividualSearchResult(Individual individual, VitroRequest vreq) {
super(individual, vreq);
}