updates to internal class form and menu edit

This commit is contained in:
hjkhjk54 2011-07-14 14:51:28 +00:00
parent a4f90721f3
commit aa0de11f90
3 changed files with 35 additions and 20 deletions

View file

@ -130,7 +130,7 @@ public class MenuManagementEdit extends VitroHttpServlet {
log.error("Display model not being retrieved correctly"); log.error("Display model not being retrieved correctly");
} }
//if Add, then create new menu item and new page elements, and use the values above //if Add, then create new menu item and new page elements, and use the values above
String errorMessage = "";
if(isAdd(command)){ if(isAdd(command)){
processAdd(menuItem, displayModel, command, vreq); processAdd(menuItem, displayModel, command, vreq);
} }
@ -141,7 +141,7 @@ public class MenuManagementEdit extends VitroHttpServlet {
} else if(isDelete(command)) { } else if(isDelete(command)) {
processDelete(menuItem, displayModel, command, vreq); processDelete(menuItem, displayModel, command, vreq);
} else if(isReorder(command)) { } else if(isReorder(command)) {
processReorder(displayModel, vreq, resp); errorMessage = processReorder(displayModel, vreq);
} }
//Edits to model occur here //Edits to model occur here
@ -161,32 +161,39 @@ public class MenuManagementEdit extends VitroHttpServlet {
displayModel.add(addStatements); displayModel.add(addStatements);
} catch(Exception ex) { } catch(Exception ex) {
log.error("An error occurred in processing command", ex);
errorMessage += "An error occurred and the operation could not be completed successfully.";
}finally { }finally {
displayModel.leaveCriticalSection(); displayModel.leaveCriticalSection();
} }
//if reorder, need to send back an AJAX response
if(isReorder(command)){
sendReorderResponse(errorMessage, resp);
}
} }
private void processReorder(OntModel displayModel, VitroRequest vreq, HttpServletResponse resp) { private String processReorder(OntModel displayModel, VitroRequest vreq) {
//Get the new menu positions for all the elements //Assuming individual uris passed in the order of their new menu positions
String predicate = vreq.getParameter("predicate");
//Assuming these two are in the same order
String[]individuals = vreq.getParameterValues("individuals"); String[]individuals = vreq.getParameterValues("individuals");
String[] positions = vreq.getParameterValues("positions");
String errorMessage = null; String errorMessage = null;
if(individuals.length > 0 && positions.length > 0 && individuals.length == positions.length) { if(individuals.length > 0 ) {
removeStatements = removePositionStatements(displayModel, individuals); removeStatements = removePositionStatements(displayModel, individuals);
addStatements = addPositionStatements(displayModel, individuals, positions); addStatements = addPositionStatements(displayModel, individuals);
} else { } else {
errorMessage = "Number of individuals and positions is out of synch"; errorMessage = "No individuals passed";
} }
try{ return errorMessage;
}
private void sendReorderResponse(String errorMessage, HttpServletResponse resp) {
try{
JSONObject rObj = new JSONObject(); JSONObject rObj = new JSONObject();
resp.setCharacterEncoding("UTF-8"); resp.setCharacterEncoding("UTF-8");
resp.setContentType("application/json;charset=UTF-8"); resp.setContentType("application/json;charset=UTF-8");
if( errorMessage != null ){ if( errorMessage != null && !errorMessage.isEmpty()){
rObj.put("errorMessage", errorMessage); rObj.put("errorMessage", errorMessage);
resp.setStatus(500 /*HttpURLConnection.HTTP_SERVER_ERROR*/); resp.setStatus(500 /*HttpURLConnection.HTTP_SERVER_ERROR*/);
}else{ }else{
@ -197,7 +204,7 @@ public class MenuManagementEdit extends VitroHttpServlet {
} catch(Exception ex) { } catch(Exception ex) {
log.error("Error creating JSON object for response", ex); log.error("Error creating JSON object for response", ex);
} }
} }
private Model removePositionStatements(OntModel displayModel, private Model removePositionStatements(OntModel displayModel,
@ -218,14 +225,13 @@ public class MenuManagementEdit extends VitroHttpServlet {
} }
private Model addPositionStatements(OntModel displayModel, private Model addPositionStatements(OntModel displayModel,
String[] individuals, String[] positions) { String[] individuals) {
Model addPositionStatements = ModelFactory.createDefaultModel(); Model addPositionStatements = ModelFactory.createDefaultModel();
int index = 0; int index = 0;
int len = individuals.length; int len = individuals.length;
for(index = 0; index < len; index++) { for(index = 0; index < len; index++) {
Resource individualResource = ResourceFactory.createResource(individuals[index]); Resource individualResource = ResourceFactory.createResource(individuals[index]);
int position = new Integer(positions[index]).intValue(); int position = index + 1;
addPositionStatements.add(addPositionStatements.createStatement( addPositionStatements.add(addPositionStatements.createStatement(
individualResource, individualResource,
DisplayVocabulary.MENU_POSITION, DisplayVocabulary.MENU_POSITION,

View file

@ -17,6 +17,10 @@ public class DisplayVocabulary {
/** <p>The ontology model that holds the vocabulary terms</p> */ /** <p>The ontology model that holds the vocabulary terms</p> */
private static OntModel m_model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null ); private static OntModel m_model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null );
//URL for menu management
public static final String PROCESS_MENU_MANAGEMENT_URL = "/processEditDisplayModel";
public static final String REORDER_MENU_URL = PROCESS_MENU_MANAGEMENT_URL + "?cmd=Reorder";
/*Uris for Models for Display*/ /*Uris for Models for Display*/
public static final String DISPLAY_TBOX_MODEL_URI = "http://vitro.mannlib.cornell.edu/default/vitro-kb-displayMetadataTBOX"; public static final String DISPLAY_TBOX_MODEL_URI = "http://vitro.mannlib.cornell.edu/default/vitro-kb-displayMetadataTBOX";

View file

@ -19,22 +19,27 @@ edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.Institu
<section> <section>
<form method="POST" action="${formUrl}" class="customForm"> <form method="POST" action="${formUrl}" class="customForm">
<input type="hidden" name="submitForm" id="submitForm" value="true" /> <input type="hidden" name="submitForm" id="submitForm" value="true" />
<#--If no local ontologies, display message for user to create a local ontology-->
<#if ontologiesExist = false> <#if ontologiesExist = false>
<section id="noLocalOntologyExists"> <section id="noLocalOntologyExists">
<p>${noLocalOntologiesMessage}</p> <p>${noLocalOntologiesMessage}</p>
</section> </section>
<#elseif useExistingInternalClass?has_content> <#--else if local ontologies exist and local classes exist, show drop-down of local classes-->
<#elseif useExistingLocalClass?has_content>
<section id="existingLocalClass"> <section id="existingLocalClass">
<#--Populated based on class list returned--> <#--Populated based on class list returned-->
<select id="existingLocalClasses" name="existingLocalClasses"> <select id="existingLocalClasses" name="existingLocalClasses">
<#assign classUris = existingLocalClasses?keys /> <#assign classUris = existingLocalClasses?keys />
<#--If internal class exists, check against value in drop-down and select option-->
<#list classUris as localClassUri> <#list classUris as localClassUri>
<option value="${localClassUri}" <#if existingInternalClass = localClassUri>selected</#if> >${existingLocalClasses[localClassUri]}</option> <option value="${localClassUri}" <#if existingInternalClass = localClassUri>selected</#if> >${existingLocalClasses[localClassUri]}</option>
</#list> </#list>
</select> </select>
<p>Can't find an appropriate class? Create a <a href="${formUrl}?cmd=createClass">new one</a>.</p> <p>Can't find an appropriate class? Create a <a href="${formUrl}?cmd=createClass">new one</a>.</p>
</section> </section>
<#--if parameter to create new class passed or if there are local ontologies but no local classes, show create new class page-->
<#elseif createNewClass?has_content> <#elseif createNewClass?has_content>
<section id="createNewLocalClass"> <section id="createNewLocalClass">
<h2>Create a new class</h2> <h2>Create a new class</h2>
@ -54,14 +59,14 @@ edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.Institu
</#if> </#if>
</section> </section>
<#--this case is an error case-->
<#else> <#else>
Problematic section as above should all have been handled Problematic section as above should all have been handled
</#if> </#if>
<#--only show submit and cancel if ontologies exist-->
<#if ontologiesExist = true> <#if ontologiesExist = true>
<input type="submit" name="submit-internalClass" value="${submitAction}" class="submit" /> or <a class="cancel" href="${cancelUrl}">Cancel</a> <input type="submit" name="submit-internalClass" value="${submitAction}" class="submit" /> or <a class="cancel" href="${cancelUrl}">Cancel</a>
<p class="requiredHint">* required fields</p>
</#if> </#if>
</form> </form>