diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/MenuManagementEdit.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/MenuManagementEdit.java index ad9592637..1d519bc81 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/MenuManagementEdit.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/MenuManagementEdit.java @@ -6,6 +6,7 @@ import java.io.File; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; +import java.io.Writer; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -22,6 +23,7 @@ import javax.servlet.http.HttpSession; import org.apache.commons.fileupload.FileItem; 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.ontology.OntModelSpec; @@ -79,7 +81,7 @@ public class MenuManagementEdit extends VitroHttpServlet { String command = getCommand(vreq); if(command != null) { - processCommand(command, vreq); + processCommand(command, vreq, resp); } else { System.out.println("Command is null"); } @@ -119,7 +121,7 @@ public class MenuManagementEdit extends VitroHttpServlet { //Parameter retrieval is identical, but in one case an entirey new menu item needs to be created //along with a new page - public void processCommand(String command, VitroRequest vreq) { + public void processCommand(String command, VitroRequest vreq, HttpServletResponse resp) { //Get parameters for menu item being edited String menuItem = vreq.getParameter("menuItem"); OntModel displayModel = getDisplayModel(vreq); @@ -139,7 +141,7 @@ public class MenuManagementEdit extends VitroHttpServlet { } else if(isDelete(command)) { processDelete(menuItem, displayModel, command, vreq); } else if(isReorder(command)) { - processReorder(displayModel, vreq); + processReorder(displayModel, vreq, resp); } //Edits to model occur here @@ -166,17 +168,34 @@ public class MenuManagementEdit extends VitroHttpServlet { } - private void processReorder(OntModel displayModel, VitroRequest vreq) { + private void processReorder(OntModel displayModel, VitroRequest vreq, HttpServletResponse resp) { //Get the new menu positions for all the elements String predicate = vreq.getParameter("predicate"); //Assuming these two are in the same order String[]individuals = vreq.getParameterValues("individuals"); String[] positions = vreq.getParameterValues("positions"); + String errorMessage = null; if(individuals.length > 0 && positions.length > 0 && individuals.length == positions.length) { removeStatements = removePositionStatements(displayModel, individuals); addStatements = addPositionStatements(displayModel, individuals, positions); } else { - //Throw an error? + errorMessage = "Number of individuals and positions is out of synch"; + } + try{ + JSONObject rObj = new JSONObject(); + resp.setCharacterEncoding("UTF-8"); + resp.setContentType("application/json;charset=UTF-8"); + + if( errorMessage != null ){ + rObj.put("errorMessage", errorMessage); + resp.setStatus(500 /*HttpURLConnection.HTTP_SERVER_ERROR*/); + }else{ + rObj.put("errorMessage", ""); + } + Writer writer = resp.getWriter(); + writer.write(rObj.toString()); + } catch(Exception ex) { + log.error("Error creating JSON object for response", ex); } } @@ -347,7 +366,9 @@ public class MenuManagementEdit extends VitroHttpServlet { Model addModel, OntModel displayModel) { String[] selectedClasses = vreq.getParameterValues("classInClassGroup"); Model dgModel = ModelFactory.createDefaultModel(); - dgModel.add(dgModel.createStatement(dataGetterResource, RDF.type, DisplayVocabulary.CLASSINDIVIDUALS_PAGE_TYPE)); + dgModel.add(dgModel.createStatement(dataGetterResource, + RDF.type, + ResourceFactory.createResource(DisplayVocabulary.CLASSINDIVIDUALS_PAGE_TYPE))); for(String classUri: selectedClasses) { dgModel.add(dgModel.createStatement( dataGetterResource, @@ -370,7 +391,9 @@ public class MenuManagementEdit extends VitroHttpServlet { private Model getClassGroupDataGetter(VitroRequest vreq, Resource dataGetterResource, Model addModel, OntModel displayModel) { Model dgModel = ModelFactory.createDefaultModel(); - dgModel.add(dgModel.createStatement(dataGetterResource, RDF.type, DisplayVocabulary.CLASSGROUP_PAGE_TYPE)); + dgModel.add(dgModel.createStatement(dataGetterResource, + RDF.type, + ResourceFactory.createResource(DisplayVocabulary.CLASSGROUP_PAGE_TYPE))); return dgModel; } @@ -471,7 +494,9 @@ public class MenuManagementEdit extends VitroHttpServlet { DisplayVocabulary.MENU_POSITION, addModel.createTypedLiteral(getLastPosition(displayModel)))); //page resource, type, title and url mapping, and what data getter associated - addModel.add(addModel.createStatement(pageResource, RDF.type, DisplayVocabulary.PAGE_TYPE)); + addModel.add(addModel.createStatement(pageResource, + RDF.type, + ResourceFactory.createResource(DisplayVocabulary.PAGE_TYPE))); //Need to create a data getter Model dataGetterStatements = generateDataGetter(pageResource, displayModel); addModel.add(dataGetterStatements); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/utils/LocalNamespaceClassUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/utils/LocalNamespaceClassUtils.java index f547ff5f8..4b2bdec5c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/utils/LocalNamespaceClassUtils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/utils/LocalNamespaceClassUtils.java @@ -7,10 +7,12 @@ import java.util.List; import java.util.ArrayList; import java.util.HashMap; import edu.cornell.mannlib.vedit.beans.Option; +import edu.cornell.mannlib.vitro.webapp.beans.Ontology; import edu.cornell.mannlib.vitro.webapp.beans.ResourceBean; import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean; import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -18,16 +20,17 @@ import org.apache.commons.logging.LogFactory; public class LocalNamespaceClassUtils { private static final Log log = LogFactory.getLog(LocalNamespaceClassUtils.class.getName()); - public static List getLocalNamespacesClasses(VitroRequest vreq, List namespace) { - HashMap namespaceHash = convertToHash(namespace); - List localClasses = new ArrayList(); + //Expects hash where key = namespace uri + //return hash where key = class uri, and value = display Name + (prefix) of ontology + public static HashMap getLocalNamespacesClasses(VitroRequest vreq, HashMap namespaces) { + HashMap localClasses = new HashMap(); List allClasses = vreq.getWebappDaoFactory().getVClassDao().getAllVclasses(); for(VClass v: allClasses) { String classNamespace = v.getNamespace(); String classUri = v.getURI(); System.out.println("uri is " + classUri + " and namespace is " + classNamespace); - if(namespaceHash.containsKey(classNamespace)){ - localClasses.add(v); + if(namespaces.containsKey(classNamespace)){ + localClasses.put(classUri, v.getName() + " ( " + namespaces.get(classNamespace) + ")"); } } return localClasses; @@ -43,24 +46,32 @@ public class LocalNamespaceClassUtils { //Retrieve all VClasses and sort into local namespaces //TODO: Check better mechanism utilizing sparql query - public static List getLocalOntologyNamespaces(VitroRequest vreq) { + //Can't depend on retrieval of classes b/c an ontology may not have any classes yet + //Display name and URI, with URI being key + public static HashMap getLocalOntologyNamespaces(VitroRequest vreq) { HashMap foundNamespaces = new HashMap(); String defaultNamespacePattern = getDefaultOntologyNamespace(vreq); - List localNamespaces = new ArrayList(); - List allClasses = vreq.getWebappDaoFactory().getVClassDao().getAllVclasses(); - for(VClass v: allClasses) { - String namespace = v.getNamespace(); - if(namespace.startsWith(defaultNamespacePattern) && !foundNamespaces.containsKey(namespace)) { - foundNamespaces.put(namespace, "true"); + + //Get all namespacs + //There's an APP for that! + OntologyDao dao = vreq.getFullWebappDaoFactory().getOntologyDao(); + List onts = dao.getAllOntologies(); + for(Ontology on: onts) { + String uri = on.getURI(); + if(uri.startsWith(defaultNamespacePattern)) { + String name = on.getName(); + String prefix = on.getPrefix(); + foundNamespaces.put(uri, name + " (" + prefix + ")"); } - } - localNamespaces.addAll(foundNamespaces.keySet()); - return localNamespaces; + } + + return foundNamespaces; } public static String getDefaultOntologyNamespace(VitroRequest vreq) { String defaultNamespace= vreq.getWebappDaoFactory().getDefaultNamespace(); - defaultNamespace = defaultNamespace.substring(0, defaultNamespace.lastIndexOf("/")) + "ontology/"; + //Assuming following linked data approach so expects /individual at end + defaultNamespace = defaultNamespace.substring(0, defaultNamespace.lastIndexOf("/individual")) + "/ontology/"; return defaultNamespace; } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/InstitutionalInternalClassController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/InstitutionalInternalClassController.java index e8d9273a8..85c3ef843 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/InstitutionalInternalClassController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/InstitutionalInternalClassController.java @@ -6,9 +6,15 @@ 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 org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -18,6 +24,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.ManageMenu 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; @@ -36,8 +43,8 @@ public class InstitutionalInternalClassController extends FreemarkerHttpServlet 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 List localNamespaces = new ArrayList(); - private static List localNamespaceClasses = new ArrayList(); + private static HashMap localNamespaces = new HashMap(); + private static HashMap localNamespaceClasses = new HashMap(); private static final String CREATE_CLASS_PARAM = "createClass"; private static final String REDIRECT_PAGE = "/siteAdmin"; @Override @@ -54,9 +61,12 @@ public class InstitutionalInternalClassController extends FreemarkerHttpServlet Map data = new HashMap(); //Get all local classes and namespace information retrieveLocalClasses(vreq, data); - if(isSelectExistingClass(vreq)) { + if(isSubmission(vreq)){ + processSubmission(vreq, data); + } else if(isSelectExistingClass(vreq)) { //Local namespace(s) exist and user can select an existing class processSelectExistingClass(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 @@ -65,8 +75,6 @@ public class InstitutionalInternalClassController extends FreemarkerHttpServlet //Not being handled expliclity but message will display indicating //no local namespaces exist and one must be created processCreateOntologies(vreq, data); - } else if(isSubmission(vreq)){ - processSubmission(vreq, data); } else { } @@ -75,14 +83,18 @@ public class InstitutionalInternalClassController extends FreemarkerHttpServlet //Check if existing local namespaces - data.put("formUrl", EDIT_FORM); - + 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); } @@ -105,7 +117,7 @@ public class InstitutionalInternalClassController extends FreemarkerHttpServlet private void processCreateNewClass(VitroRequest vreq, Map data) { //this may need to be changed on the basis of how new classes interact with new ontologies - data.put("submitAction", "createClass"); + data.put("submitAction", "Create Class"); data.put("createNewClass", true); } @@ -121,7 +133,7 @@ public class InstitutionalInternalClassController extends FreemarkerHttpServlet private void processSelectExistingClass(VitroRequest vreq, Map data) { //Check if internal class is already set and be sure to include that in the data to be returned data.put("useExistingInternalClass", true); - data.put("submitAction", "save"); + data.put("submitAction", "Save"); } private boolean isSelectExistingClass(VitroRequest vreq) { @@ -135,8 +147,8 @@ public class InstitutionalInternalClassController extends FreemarkerHttpServlet localNamespaces = LocalNamespaceClassUtils.getLocalOntologyNamespaces(vreq); //Get classes for local namespaces localNamespaceClasses = LocalNamespaceClassUtils.getLocalNamespacesClasses(vreq, localNamespaces); - data.put("existingLocalClasses", localNamespaces); - data.put("existingLocalNamespaces", localNamespaceClasses); + 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) { @@ -146,7 +158,12 @@ public class InstitutionalInternalClassController extends FreemarkerHttpServlet 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()); } } @@ -172,6 +189,12 @@ public class InstitutionalInternalClassController extends FreemarkerHttpServlet Model writeModel = ModelContext.getBaseOntModelSelector(getServletContext()).getTBoxModel(); writeModel.enterCriticalSection(Lock.WRITE); try { + //remove existing internal classes if there are any as assuming only one + writeModel.remove( + writeModel.listStatements(null, + ResourceFactory.createProperty(VitroVocabulary.IS_INTERNAL_CLASSANNOT), + (RDFNode) null)); + writeModel.add( writeModel.createStatement( ResourceFactory.createResource(classUri), @@ -205,4 +228,21 @@ public class InstitutionalInternalClassController extends FreemarkerHttpServlet } + private RedirectResponseValues redirectToSiteAdmin() { + return new RedirectResponseValues(REDIRECT_PAGE, HttpServletResponse.SC_SEE_OTHER); + } + + //Get current internal class + private String retrieveCurrentInternalClass() { + String internalClassUri = ""; + OntModel mainModel = (OntModel) getServletContext().getAttribute("jenaOntModel"); + StmtIterator internalIt = mainModel.listStatements(null, + ResourceFactory.createProperty(VitroVocabulary.IS_INTERNAL_CLASSANNOT), + (RDFNode) null); + if(internalIt.hasNext()){ + internalClassUri = internalIt.nextStatement().getResource().getURI(); + } + return internalClassUri; + } + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/MenuManagementController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/MenuManagementController.java index 3cd7cfbde..9f32381ea 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/MenuManagementController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/MenuManagementController.java @@ -287,8 +287,10 @@ public class MenuManagementController extends FreemarkerHttpServlet { } private void retrieveIndividualsForClassesPage(OntModel writeModel, - Resource dataGetter, Map data) { + Resource dataGetter, Map data) { data.put("isIndividualsForClassesPage", true); + data.put("isClassGroupPage", false); + data.put("includeAllClasses", false); //Get the classes and put them here this.getClassesForDataGetter(writeModel, dataGetter, data); //Also save the class group for display diff --git a/webapp/web/templates/freemarker/edit/forms/institutionalInternalClassForm.ftl b/webapp/web/templates/freemarker/edit/forms/institutionalInternalClassForm.ftl index 7e538d5a6..801790012 100644 --- a/webapp/web/templates/freemarker/edit/forms/institutionalInternalClassForm.ftl +++ b/webapp/web/templates/freemarker/edit/forms/institutionalInternalClassForm.ftl @@ -11,9 +11,9 @@ edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.Institu

Institutional Internal Class

- This class will be used to designate those individuals internal to your institution. +

This class will be used to designate those individuals internal to your institution. This will allow you to limit the individuals displayed on your menu pages (People, Research, etc.) - to only those within your institution. + to only those within your institution.

@@ -21,17 +21,19 @@ edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.Institu <#if ontologiesExist = false>
- ${noLocalOntologiesMessage} +

${noLocalOntologiesMessage}

<#elseif useExistingInternalClass?has_content>
<#--Populated based on class list returned--> +

Can't find an appropriate class? Create a new one.

<#elseif createNewClass?has_content>
@@ -42,20 +44,26 @@ edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.Institu <#--If more than one local namespace, generate select--> <#if multipleLocalNamespaces = true> <#else> - +
<#else> Problematic section as above should all have been handled - or Cancel -

* required fields

+ + <#if ontologiesExist = true> + or Cancel +

* required fields

+ + +
diff --git a/webapp/web/templates/freemarker/edit/forms/menuManagement-remove.ftl b/webapp/web/templates/freemarker/edit/forms/menuManagement-remove.ftl index 8d4b5af17..760dc2b4a 100644 --- a/webapp/web/templates/freemarker/edit/forms/menuManagement-remove.ftl +++ b/webapp/web/templates/freemarker/edit/forms/menuManagement-remove.ftl @@ -7,8 +7,10 @@
- -

Are you sure you want to remove ${menuItem} menu item?

+ + + +

Are you sure you want to remove ${menuName} menu item?

or Cancel
diff --git a/webapp/web/templates/freemarker/edit/forms/testMenuManagement.ftl b/webapp/web/templates/freemarker/edit/forms/testMenuManagement.ftl index 7494cbc9c..98fd4baa0 100644 --- a/webapp/web/templates/freemarker/edit/forms/testMenuManagement.ftl +++ b/webapp/web/templates/freemarker/edit/forms/testMenuManagement.ftl @@ -74,14 +74,14 @@ <#list classGroup as classInClassGroup>