Updates for institutional internal class processing and including special values for individual controller

This commit is contained in:
hjkhjk54 2011-07-14 15:13:01 +00:00
parent 1c82582023
commit a5d42ac5ac
2 changed files with 27 additions and 10 deletions

View file

@ -47,6 +47,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Rdf
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.RedirectResponseValues; 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.ResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; 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.IndividualDao; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao; import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
@ -142,6 +143,8 @@ public class IndividualController extends FreemarkerHttpServlet {
body.put("individual", wrap(itm, BeansWrapper.EXPOSE_SAFE)); body.put("individual", wrap(itm, BeansWrapper.EXPOSE_SAFE));
body.put("headContent", getRdfLinkTag(itm)); body.put("headContent", getRdfLinkTag(itm));
//If special values required for individuals like menu, include values in template values
this.includeSpecialEditingValues(vreq, body);
String template = getIndividualTemplate(individual, vreq); String template = getIndividualTemplate(individual, vreq);
return new TemplateResponseValues(template, body); return new TemplateResponseValues(template, body);
@ -210,6 +213,13 @@ public class IndividualController extends FreemarkerHttpServlet {
return map; return map;
} }
//Get special values for cases such as Menu Management editing
private void includeSpecialEditingValues(VitroRequest vreq, Map<String, Object> body) {
if(vreq.getAttribute(VitroRequest.SPECIAL_WRITE_MODEL) != null) {
body.put("reorderUrl", DisplayVocabulary.REORDER_MENU_URL);
}
}
private Map<String, Object> getRelatedSubject(VitroRequest vreq) { private Map<String, Object> getRelatedSubject(VitroRequest vreq) {
Map<String, Object> map = null; Map<String, Object> map = null;

View file

@ -33,6 +33,7 @@ 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.VClassGroupCache;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; 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; import edu.cornell.mannlib.vitro.webapp.controller.edit.utils.LocalNamespaceClassUtils;
/* /*
* Custom controller for menu management. This will be replaced later once N3 Editing * Custom controller for menu management. This will be replaced later once N3 Editing
@ -131,8 +132,8 @@ public class InstitutionalInternalClassController extends FreemarkerHttpServlet
} }
private void processSelectExistingClass(VitroRequest vreq, Map<String, Object> data) { private void processSelectExistingClass(VitroRequest vreq, Map<String, Object> data) {
//Check if internal class is already set and be sure to include that in the data to be returned //Check if local classes exist and use for selection
data.put("useExistingInternalClass", true); data.put("useExistingLocalClass", true);
data.put("submitAction", "Save"); data.put("submitAction", "Save");
} }
@ -188,13 +189,18 @@ public class InstitutionalInternalClassController extends FreemarkerHttpServlet
if(classUri != null && !classUri.isEmpty()) { if(classUri != null && !classUri.isEmpty()) {
Model writeModel = ModelContext.getBaseOntModelSelector(getServletContext()).getTBoxModel(); Model writeModel = ModelContext.getBaseOntModelSelector(getServletContext()).getTBoxModel();
writeModel.enterCriticalSection(Lock.WRITE); writeModel.enterCriticalSection(Lock.WRITE);
writeModel.notifyEvent(new EditEvent(null,true));
try { try {
//remove existing internal classes if there are any as assuming only one log.debug("Should be removing these statements " + writeModel.listStatements(null,
writeModel.remove(
writeModel.listStatements(null,
ResourceFactory.createProperty(VitroVocabulary.IS_INTERNAL_CLASSANNOT), ResourceFactory.createProperty(VitroVocabulary.IS_INTERNAL_CLASSANNOT),
(RDFNode) null)); (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.add(
writeModel.createStatement( writeModel.createStatement(
ResourceFactory.createResource(classUri), ResourceFactory.createResource(classUri),
@ -203,6 +209,7 @@ public class InstitutionalInternalClassController extends FreemarkerHttpServlet
} catch(Exception ex) { } catch(Exception ex) {
log.error("Error occurred in adding statement for " + classUri + " becoming internal class", ex); log.error("Error occurred in adding statement for " + classUri + " becoming internal class", ex);
} finally { } finally {
writeModel.notifyEvent(new EditEvent(null,true));
writeModel.leaveCriticalSection(); writeModel.leaveCriticalSection();
} }
} }
@ -239,11 +246,11 @@ public class InstitutionalInternalClassController extends FreemarkerHttpServlet
StmtIterator internalIt = mainModel.listStatements(null, StmtIterator internalIt = mainModel.listStatements(null,
ResourceFactory.createProperty(VitroVocabulary.IS_INTERNAL_CLASSANNOT), ResourceFactory.createProperty(VitroVocabulary.IS_INTERNAL_CLASSANNOT),
(RDFNode) null); (RDFNode) null);
if(internalIt.hasNext()){ while(internalIt.hasNext()){
Statement s = internalIt.nextStatement(); Statement s = internalIt.nextStatement();
if(s.getObject().isResource()){ //The class IS an internal class so the subject is what we're looking for
internalClassUri = internalIt.nextStatement().getResource().getURI(); internalClassUri = s.getSubject().getURI();
} log.debug("Found internal class uri " + internalClassUri);
} }
return internalClassUri; return internalClassUri;
} }