Updates for NIHVIVO-3086 and NIHVIVO-2980 and subtasks: updating page data getters to rely on java class name, separating out internal class-specific set up and processing for menu management into VIVO code.

This commit is contained in:
hjkhjk54 2011-08-02 15:24:29 +00:00
parent 266d3d007d
commit fcdff9ea54
7 changed files with 651 additions and 7 deletions

View file

@ -59,7 +59,8 @@ display:Home
a display:HomePage ;
a display:Page ;
display:title "Home" ;
display:urlMapping "/" .
display:urlMapping "/" ;
display:hasDataGetter display:homeDataGetter .
display:Events
a display:Page ;
@ -96,21 +97,24 @@ display:Research
#The data getter objects used above
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#peopleDataGetter>
a <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#ClassGroupPage> ;
a <java:edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.ClassGroupPageData>;
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#forClassGroup>
<http://vivoweb.org/ontology#vitroClassGrouppeople> .
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#researchDataGetter>
a <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#ClassGroupPage> ;
a <java:edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.ClassGroupPageData>;
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#forClassGroup>
<http://vivoweb.org/ontology#vitroClassGrouppublications> .
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#organizationsDataGetter>
a <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#ClassGroupPage> ;
a <java:edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.ClassGroupPageData>;
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#forClassGroup>
<http://vivoweb.org/ontology#vitroClassGrouporganizations> .
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#eventsDataGetter>
a <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#ClassGroupPage> ;
a <java:edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.ClassGroupPageData>;
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#forClassGroup>
<http://vivoweb.org/ontology#vitroClassGroupevents> .
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#homeDataGetter>
a <java:edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.BrowseDataGetter> .

View file

@ -9,7 +9,7 @@
<#assign disableClass = 'class="disable inline" disabled="disabled"' />
</#if>
<input type="checkbox" ${disableClass} name="display-internalClass" value="${internalClassUri}" id="display-internalClass" <#if pageInternalOnly?has_content>checked</#if> role="input" />
<input type="checkbox" ${disableClass} name="display-internalClass" value="${internalClassUri}" id="display-internalClass" <#if internalClass?has_content && isInternal?has_content>checked</#if> role="input" />
<label ${disableClass} class="inline" for="display-internalClass">Only display <em>${associatedPage}</em> within my institution</label>
${enableInternalClass}

View file

@ -0,0 +1,261 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import javax.servlet.http.HttpServletResponse;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.shared.Lock;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Statement;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.ManageMenus;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.RedirectResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
import edu.cornell.mannlib.vitro.webapp.controller.edit.utils.LocalNamespaceClassUtils;
/*
* Custom controller for menu management. This will be replaced later once N3 Editing
* has been successfully refactored and integrated with menu management.
*/
public class InstitutionalInternalClassController extends FreemarkerHttpServlet {
private static final Log log = LogFactory.getLog(InstitutionalInternalClassController.class);
private static final String EDIT_FORM = "/processInstitutionalInternalClass";
public final static Actions REQUIRED_ACTIONS = new Actions(new ManageMenus());
private static final String DISPLAY_FORM = "/institutionalInternalClassForm.ftl";
private static HashMap<String, String> localNamespaces = new HashMap<String, String>();
private static HashMap<String, String> localNamespaceClasses = new HashMap<String, String>();
private static final String CREATE_CLASS_PARAM = "createClass";
private static final String REDIRECT_PAGE = "/siteAdmin";
@Override
protected Actions requiredActions(VitroRequest vreq) {
return REQUIRED_ACTIONS;
}
@Override
protected ResponseValues processRequest(VitroRequest vreq) {
//Based on existing of local namespaces and number of local classes present
//as well as command parameter, execute command
Map<String, Object> data = new HashMap<String,Object>();
//Get all local classes and namespace information
retrieveLocalClasses(vreq, data);
if(isSubmission(vreq)){
processSubmission(vreq, data);
} else if(isCreateNewClass(vreq)) {
//Local namespace(s) exist and user wishes to create a new class
//Either cmd = create new or no local classes exist at all and one must be created
processCreateNewClass(vreq, data);
} else if(isSelectExistingClass(vreq)) {
//Local namespace(s) exist and user can select an existing class
processSelectExistingClass(vreq, data);
} else if(isCreateOntologies(vreq)) {
//Not being handled expliclity but message will display indicating
//no local namespaces exist and one must be created
processCreateOntologies(vreq, data);
} else {
}
//Retrieve local namespaces
//Check if existing local namespaces
data.put("formUrl", vreq.getContextPath() + EDIT_FORM);
data.put("cancelUrl", vreq.getContextPath() + REDIRECT_PAGE);
//if no local namespaces, then provide message to display
//if existing namespace(s), then check
//if single namespace, retrieve all classes belonging to that local namespace
//if multiple namespaces, generate select list with namespaces
//for instertion: VClassDaoJena.insertVClass
//
if(isSubmission(vreq)){
return redirectToSiteAdmin();
}
return new TemplateResponseValues(DISPLAY_FORM, data);
}
private boolean isSubmission(VitroRequest vreq) {
String submit = vreq.getParameter("submitForm");
return(submit!= null && !submit.isEmpty());
}
private void processCreateOntologies(VitroRequest vreq, Map<String, Object> data) {
data.put("submitAction", "");
}
private boolean isCreateOntologies(VitroRequest vreq) {
//no local namespaces
return (localNamespaces.size() == 0);
}
private void processCreateNewClass(VitroRequest vreq, Map<String, Object> data) {
//this may need to be changed on the basis of how new classes interact with new ontologies
data.put("submitAction", "Create Class");
data.put("createNewClass", true);
}
private boolean isCreateNewClass(VitroRequest vreq) {
String command = vreq.getParameter("cmd");
if(command != null && command.equals(CREATE_CLASS_PARAM)) {
return true;
}
//If local namespace exists but no classes in local namespaces, then need to enable creation of new classes
return(localNamespaces.size() > 0 && localNamespaceClasses.size() == 0);
}
private void processSelectExistingClass(VitroRequest vreq, Map<String, Object> data) {
//Check if local classes exist and use for selection
data.put("useExistingLocalClass", true);
data.put("submitAction", "Save");
}
private boolean isSelectExistingClass(VitroRequest vreq) {
//Local namespaces exist and there are existing classes within those namespaces
return (localNamespaces.size() > 0 && localNamespaceClasses.size() > 0);
}
private void retrieveLocalClasses(VitroRequest vreq, Map<String, Object> data) {
localNamespaces = LocalNamespaceClassUtils.getLocalOntologyNamespaces(vreq);
//Get classes for local namespaces
localNamespaceClasses = LocalNamespaceClassUtils.getLocalNamespacesClasses(vreq, localNamespaces);
data.put("existingLocalClasses", localNamespaceClasses);
data.put("existingLocalNamespaces", localNamespaces);
String noLocalOntologiesMessage = "There are currently no local ontologies. You must create a new ontology";
data.put("noLocalOntologiesMessage", noLocalOntologiesMessage);
if(localNamespaces.size() == 0) {
data.put("ontologiesExist", false);
}
else {
data.put("ontologiesExist", true);
if(localNamespaces.size() > 1) {
data.put("multipleLocalNamespaces", true);
} else {
data.put("multipleLocalNamespaces", false);
data.put("existingLocalNamespace", localNamespaces.keySet().iterator().next());
}
//Get current internal class if it exists
data.put("existingInternalClass", retrieveCurrentInternalClass());
}
//Place default namespace within data to pass back to template
String defaultNamespace = vreq.getWebappDaoFactory().getDefaultNamespace();
data.put("defaultNamespace", defaultNamespace);
}
//Process submission on submitting form
private void processSubmission(VitroRequest vreq, Map<String, Object> data) {
//If new class, need to generate new class
String classUri = null;
if(isNewClassSubmission(vreq)){
VClass v= generateNewVClass(vreq.getParameter("localClassName"), vreq.getParameter("existingLocalNamespaces"));
classUri = v.getURI();
try {
vreq.getWebappDaoFactory().getVClassDao().insertNewVClass(v);
} catch(Exception ex) {
log.error("Insertion of new class " + vreq.getParameter("name") + " resulted in error ", ex);
}
} else {
//Existing class so get URI from that
classUri = getExistingClassUri(vreq);
}
//If existing class, need to simply add a statement specifying existing class is an internal class
if(classUri != null && !classUri.isEmpty()) {
Model writeModel = ModelContext.getBaseOntModelSelector(getServletContext()).getTBoxModel();
writeModel.enterCriticalSection(Lock.WRITE);
writeModel.notifyEvent(new EditEvent(null,true));
try {
log.debug("Should be removing these statements " + writeModel.listStatements(null,
ResourceFactory.createProperty(VitroVocabulary.IS_INTERNAL_CLASSANNOT),
(RDFNode) null).toList().toString());
//remove existing internal classes if there are any as assuming only one
writeModel.removeAll(null,
ResourceFactory.createProperty(VitroVocabulary.IS_INTERNAL_CLASSANNOT),
(RDFNode) null);
log.debug("Are there any statements left for internal class annotation: " + writeModel.listStatements(null,
ResourceFactory.createProperty(VitroVocabulary.IS_INTERNAL_CLASSANNOT),
(RDFNode) null).toList().toString());
writeModel.add(
writeModel.createStatement(
ResourceFactory.createResource(classUri),
ResourceFactory.createProperty(VitroVocabulary.IS_INTERNAL_CLASSANNOT),
writeModel.createLiteral("true")));
} catch(Exception ex) {
log.error("Error occurred in adding statement for " + classUri + " becoming internal class", ex);
} finally {
writeModel.notifyEvent(new EditEvent(null,true));
writeModel.leaveCriticalSection();
}
}
}
private VClass generateNewVClass(String newClassName, String namespace) {
VClass newClass = new VClass();
newClass.setName(newClassName);
newClass.setNamespace(namespace);
String uri = namespace + newClassName.replaceAll(" ", "");
newClass.setURI(uri);
//How to g
return newClass;
}
private boolean isNewClassSubmission(VitroRequest vreq) {
String localName = vreq.getParameter("localClassName");
return (localName != null && !localName.isEmpty());
}
private String getExistingClassUri(VitroRequest vreq) {
return vreq.getParameter("existingLocalClasses");
}
private RedirectResponseValues redirectToSiteAdmin() {
return new RedirectResponseValues(REDIRECT_PAGE, HttpServletResponse.SC_SEE_OTHER);
}
//Get current internal class
private String retrieveCurrentInternalClass() {
String internalClassUri = "";
Model mainModel = ModelContext.getBaseOntModelSelector(getServletContext()).getTBoxModel();
StmtIterator internalIt = mainModel.listStatements(null,
ResourceFactory.createProperty(VitroVocabulary.IS_INTERNAL_CLASSANNOT),
(RDFNode) null);
while(internalIt.hasNext()){
Statement s = internalIt.nextStatement();
//The class IS an internal class so the subject is what we're looking for
internalClassUri = s.getSubject().getURI();
log.debug("Found internal class uri " + internalClassUri);
}
return internalClassUri;
}
}

View file

@ -0,0 +1,89 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.PageDao;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassGroupTemplateModel;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
/**
* This will pass these variables to the template:
* classGroupUri: uri of the classgroup associated with this page.
* vClassGroup: a data structure that is the classgroup associated with this page.
*/
public class InternalClassesDataGetter extends IndividualsForClassesDataGetter{
private static final Log log = LogFactory.getLog(InternalClassesDataGetter.class);
//Use different template name for internal class template
@Override
protected void setTemplateName() {
super.restrictClassesTemplateName = "internalClass";
}
//Retrieve classes and check whether or not page to be filtered by internal class only
@Override
protected Map<String, Object> getClassIntersectionsMap(PageDao pageDao,
String pageUri) {
// TODO Auto-generated method stub
return pageDao.getClassesAndCheckInternal(pageUri);
}
//Retrieve current internal class uri to restrict by
@Override
protected List<String> retrieveRestrictClasses(
ServletContext context, Map<String, Object> classIntersectionsMap) {
List<String> restrictClasses = new ArrayList<String>();
String internalClass = (String) classIntersectionsMap.get("isInternal");
//if internal class restriction specified and is true
if(internalClass != null && internalClass.equals("true")) {
//Get internal class
Model mainModel = ModelContext.getBaseOntModelSelector(context).getTBoxModel();;
StmtIterator internalIt = mainModel.listStatements(null, ResourceFactory.createProperty(VitroVocabulary.IS_INTERNAL_CLASSANNOT), (RDFNode) null);
//Checks for just one statement
if(internalIt.hasNext()){
Statement s = internalIt.nextStatement();
//The class IS an internal class so the subject is what we're looking for
String internalClassUri = s.getSubject().getURI();
log.debug("Found internal class uri " + internalClassUri);
restrictClasses.add(internalClassUri);
}
}
return restrictClasses;
}
@Override
public String getType(){
return DataGetterUtils.generateDataGetterTypeURI(InternalClassesDataGetter.class.getName());
}
}

View file

@ -0,0 +1,85 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;
import org.json.JSONObject;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.vocabulary.RDF;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.JsonServlet;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController.PageRecord;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
/*
* This class includes methods that help in selecting a data getter based on
* parameters, and VIVO will have its own version or extend this
*/
public class MenuManagementDataUtils {
private static final Log log = LogFactory.getLog(MenuManagementDataUtils.class);
//Data that is to be returned to template that does not involve data getters
//e.g. what are the current class groups, etc.
public static void includeRequiredSystemData(ServletContext context, Map<String, Object> templateData) {
checkInstitutionalInternalClass(context, templateData);
}
//Check whether any classes exist with internal class restrictions
private static void checkInstitutionalInternalClass(ServletContext context, Map<String, Object> templateData) {
//TODO: replace with more generic ModelContext retrieval method
String internalClass = retrieveInternalClass(context);
if(internalClass != null) {
templateData.put("internalClass", internalClass);
templateData.put("internalClassUri", internalClass);
} else {
//need to initialize to empty string anyway
templateData.put("internalClassUri", "");
}
}
private static String retrieveInternalClass(ServletContext context) {
OntModel mainModel = ModelContext.getBaseOntModelSelector(context).getTBoxModel();
StmtIterator internalIt = mainModel.listStatements(null, ResourceFactory.createProperty(VitroVocabulary.IS_INTERNAL_CLASSANNOT), (RDFNode) null);
if(internalIt.hasNext()) {
String internalClass = internalIt.nextStatement().getSubject().getURI();
return internalClass;
}
return null;
}
}

View file

@ -0,0 +1,106 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;
import org.json.JSONObject;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.vocabulary.RDF;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.JsonServlet;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController.PageRecord;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
/*
* Handle processing of data retrieved from IndividualsForClasses data getter to return to form template
* and handle processing of form submission to create the appropriate individuals for classes data getter
*/
public class ProcessInternalClasses extends ProcessIndividualsForClasses {
private static final Log log = LogFactory.getLog(ProcessInternalClasses.class);
/**Retrieve and populate**/
//Based on institutional internal page and not general individualsForClasses
@Override
protected void populateRestrictedClasses(Map<String, Object> pageData, Map<String, Object> templateData) {
//for internal page, restrict results by internal is true or false, otherwise get
//actual restriction classes?
//Get internal class
String internalClassUris = (String) pageData.get("internalClass");
if(internalClassUris != null && !internalClassUris.isEmpty()) {
templateData.put("isInternal", "true");
}
}
/**Process submission**/
//Check and see if we should use this process
//Use this if either internal class is selected or all classes have been selected
public boolean useProcessor(VitroRequest vreq) {
return(internalClassSelected(vreq) || !allClassesSelected(vreq));
}
public Model processSubmission(VitroRequest vreq, Resource dataGetterResource) {
String dataGetterTypeUri = new InternalClassesDataGetter().getType();
String[] selectedClasses = vreq.getParameterValues("classInClassGroup");
Model dgModel = ModelFactory.createDefaultModel();
dgModel.add(dgModel.createStatement(dataGetterResource,
RDF.type,
ResourceFactory.createResource(dataGetterTypeUri)));
for(String classUri: selectedClasses) {
dgModel.add(dgModel.createStatement(
dataGetterResource,
ResourceFactory.createProperty(DisplayVocabulary.GETINDIVIDUALS_FOR_CLASS),
ResourceFactory.createResource(classUri)));
}
//Also check if internal class checked
if(internalClassSelected(vreq)) {
dgModel.add(dgModel.createStatement(
dataGetterResource,
ResourceFactory.createProperty(DisplayVocabulary.RESTRICT_RESULTS_BY_INTERNAL),
dgModel.createLiteral("true")));
}
return dgModel;
}
private boolean allClassesSelected(VitroRequest vreq) {
String allClasses = vreq.getParameter("allSelected");
return (allClasses != null && !allClasses.isEmpty());
}
private boolean internalClassSelected(VitroRequest vreq) {
String internalClass = vreq.getParameter("display-internalClass");
return (internalClass != null && !internalClass.isEmpty());
}
}

View file

@ -0,0 +1,99 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;
import org.json.JSONObject;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.vocabulary.RDF;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.JsonServlet;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController.PageRecord;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.*;
/*
* This class includes methods that help in selecting a data getter based on
* parameters, and VIVO will have its own version or extend this
*/
public class SelectDataGetterUtils {
private static final Log log = LogFactory.getLog(SelectDataGetterUtils.class);
/**Get data for an existing page and set variables for the template accordingly**/
public static void processAndRetrieveData(VitroRequest vreq, ServletContext context, Map<String, Object> pageData, String dataGetterClass, Map<String, Object> templateData) {
//The type of the data getter will show how to process the data from the data getter
ProcessDataGetter processor = selectProcessor(dataGetterClass);
processor.populateTemplate(context, pageData, templateData);
}
//This will be different in VIVO than in VITRO
private static ProcessDataGetter selectProcessor(String dataGetterClass) {
if(dataGetterClass.equals(ClassGroupPageData.class.getName())) {
return new ProcessClassGroup();
} else if(dataGetterClass.equals(InternalClassesDataGetter.class.getName())) {
return new ProcessInternalClasses();
//below should be for vitro specific version
//return new ProcessIndividualsForClasses();
}
return null;
}
/**Process parameters from form and select appropriate data getter on this basis **/
public static Model createDataGetterModel(VitroRequest vreq, Resource dataGetterResource) {
Model dataGetterModel = null;
if(dataGetterResource != null) {
//If "All selected" then use class group else use individuals for classes
dataGetterModel = ModelFactory.createDefaultModel();
ProcessInternalClasses individualsProcess = new ProcessInternalClasses();
ProcessClassGroup classGroupProcess = new ProcessClassGroup();
if(individualsProcess.useProcessor(vreq)) {
dataGetterModel = individualsProcess.processSubmission(vreq, dataGetterResource);
} else {
dataGetterModel = classGroupProcess.processSubmission(vreq, dataGetterResource);
}
} else {
log.error("Data getter is null ");
}
return dataGetterModel;
}
}