From 93b53a67c3086b2c55d5ce53cb80ecf6c54d5948 Mon Sep 17 00:00:00 2001 From: bdc34 Date: Sun, 11 Jul 2010 21:21:40 +0000 Subject: [PATCH] Hiding delete for core:authorInAuthorship NIHVIVO-739 Adding error message when Freemarker template system is not configured correctly in web.xml Adding principal investigator and co-pi role custom forms NIHVIVO-626 --- webapp/config/web.xml | 6 +++- .../vitro/webapp/auth/policy/VivoPolicy.java | 34 +++++++++++++++++++ .../ifaces/DefaultInconclusivePolicy.java | 4 +-- .../auth/policy/setup/VivoPolicySetup.java | 32 +++++++++++++++++ .../freemarker/FreeMarkerHttpServlet.java | 2 ++ .../search/indexing/IndexBuilderThread.java | 10 +++--- 6 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/VivoPolicy.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/setup/VivoPolicySetup.java diff --git a/webapp/config/web.xml b/webapp/config/web.xml index 1c7dddd9b..eceeb412a 100644 --- a/webapp/config/web.xml +++ b/webapp/config/web.xml @@ -124,6 +124,10 @@ edu.cornell.mannlib.vitro.webapp.search.lucene.LuceneSetup + + edu.cornell.mannlib.vitro.webapp.auth.policy.setup.VivoPolicySetup + + edu.cornell.mannlib.vitro.webapp.auth.policy.setup.SelfEditingPolicySetup @@ -150,7 +154,7 @@ edu.cornell.mannlib.vitro.webapp.auth.policy.setup.DbAdminEditingPolicySetup - + edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreeMarkerSetup diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/VivoPolicy.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/VivoPolicy.java new file mode 100644 index 000000000..ebe80565e --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/VivoPolicy.java @@ -0,0 +1,34 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.auth.policy; + +import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; +import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization; +import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.DefaultInconclusivePolicy; +import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision; +import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.DropObjectPropStmt; +import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction; + +public class VivoPolicy extends DefaultInconclusivePolicy{ + + private static String AUTHORSHIP = "http://vivoweb.org/ontology/core#informationResourceInAuthorship"; + @Override + public PolicyDecision isAuthorized(IdentifierBundle whoToAuth, + RequestedAction whatToAuth) { + + if( whatToAuth instanceof DropObjectPropStmt ){ + DropObjectPropStmt dops = (DropObjectPropStmt)whatToAuth; + + /* Do not offer the user the option to delete so they will use the custom form instead */ + /* see issue NIHVIVO-739 */ + if( AUTHORSHIP.equals( dops.getUriOfPredicate() )) { + return new BasicPolicyDecision(Authorization.UNAUTHORIZED, + "Use the custom edit form for core:informationResourceInAuthorship"); + } + } + + return super.isAuthorized(whoToAuth, whatToAuth); + } + + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/ifaces/DefaultInconclusivePolicy.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/ifaces/DefaultInconclusivePolicy.java index 1a9770aa6..606b1d20c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/ifaces/DefaultInconclusivePolicy.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/ifaces/DefaultInconclusivePolicy.java @@ -26,7 +26,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.DefineObje import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.RemoveOwlClass; /** - * a policy where every type of action is authorized as INCONCLUSIVE + * A policy where every type of action is authorized as INCONCLUSIVE * by default. * * @author bdc34 @@ -46,5 +46,5 @@ public class DefaultInconclusivePolicy implements PolicyIface{ } protected static PolicyDecision INCONCLUSIVE_DECISION = new BasicPolicyDecision( Authorization.INCONCLUSIVE, - "THis is the default decision defined in DefaultInconclusivePolicy"); + "This is the default decision defined in DefaultInconclusivePolicy"); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/setup/VivoPolicySetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/setup/VivoPolicySetup.java new file mode 100644 index 000000000..d1e1d5abb --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/setup/VivoPolicySetup.java @@ -0,0 +1,32 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.auth.policy.setup; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList; +import edu.cornell.mannlib.vitro.webapp.auth.policy.VivoPolicy; + +public class VivoPolicySetup implements ServletContextListener{ + private static final Log log = LogFactory.getLog(VivoPolicySetup.class); + + @Override + public void contextInitialized(ServletContextEvent sce) { + log.debug("Setting up VivoPolicy"); + + //need to make a policy and add it to the ServeltContext + ServletPolicyList.addPolicy(sce.getServletContext(), new VivoPolicy()); + + //Note: The VivoPolicy doesn't use any identifier bundles so none are added here. + } + + @Override + public void contextDestroyed(ServletContextEvent arg0) { + //do nothing + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerHttpServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerHttpServlet.java index 2c868f61b..64b7a9afd 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerHttpServlet.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerHttpServlet.java @@ -105,6 +105,8 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet { // load templates from. Thus configurations are associated with themes rather than portals. Map themeToConfigMap = (Map) (getServletContext().getAttribute("themeToConfigMap")); + if( themeToConfigMap == null ) + log.error("The templating system is not configured correctly. Make sure that you have the FreeMarkerSetup context listener in your web.xml"); if (themeToConfigMap.containsKey(themeDir)) { return themeToConfigMap.get(themeDir); } else { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilderThread.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilderThread.java index 05799ea8c..9c75754dc 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilderThread.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilderThread.java @@ -6,7 +6,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** - * Thread that executes the methods in IndexBuilder. + * Thread that executes the methods in IndexBuilder. * * @author bdc34 * @@ -36,9 +36,11 @@ public class IndexBuilderThread extends Thread{ log.debug("full re-index requested"); indexBuilder.indexRebuild(); }else{ - log.debug("updated requested"); - Thread.sleep(250); - indexBuilder.updatedIndex(); + if( indexBuilder != null && indexBuilder.isThereWorkToDo() ){ + Thread.sleep(250); //wait a bit to let a bit more work to come into the queue + log.debug("work found for IndexBuilder, starting update"); + indexBuilder.updatedIndex(); + } } }catch (Throwable e) { log.error(e,e);