From d18806f2dfc1f6f3b3a1c224874a6f26ad5b8b43 Mon Sep 17 00:00:00 2001 From: j2blake Date: Wed, 11 May 2011 16:55:53 +0000 Subject: [PATCH 01/47] NIHVIVO-2601 Fix admin login controller so it correctly handles forced password changes. --- .../webapp/controller/authenticate/AdminLoginController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/AdminLoginController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/AdminLoginController.java index 5f1a6b780..ec5adcd0c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/AdminLoginController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/AdminLoginController.java @@ -97,7 +97,7 @@ public class AdminLoginController extends FreemarkerHttpServlet { if (auth.isCurrentPassword(username, password)) { auth.recordLoginAgainstUserAccount(username, INTERNAL); - if (auth.isPasswordChangeRequired(username)) { + if (!newPassword.isEmpty()) { auth.recordNewPassword(username, newPassword); } From e66b540f41393df3052e63a32010420fa82f9091 Mon Sep 17 00:00:00 2001 From: manolobevia Date: Wed, 11 May 2011 17:14:28 +0000 Subject: [PATCH 02/47] NIHVIVO-2280: Worked on pagination, accounts per page, sorting columns for accounts display, and select all email addresses. Work in progress, nothing final. --- .../body/accounts/userAccounts-list.ftl | 286 ++++++++---------- 1 file changed, 130 insertions(+), 156 deletions(-) diff --git a/webapp/web/templates/freemarker/body/accounts/userAccounts-list.ftl b/webapp/web/templates/freemarker/body/accounts/userAccounts-list.ftl index fa4a3239c..e6264302d 100644 --- a/webapp/web/templates/freemarker/body/accounts/userAccounts-list.ftl +++ b/webapp/web/templates/freemarker/body/accounts/userAccounts-list.ftl @@ -3,152 +3,13 @@ <#-- Template for displaying list of user accounts -->
-

Account |

- - - -
- -
- -
- - - -
+ <#--current page: +
--> -
- - - - -
- - - - - - - - - - - - - - - - - <#list accounts as account> - - - - - - - - - - -
Account Management
Email Address
First name
Last Name
Status
Roles
Login Count
- - - - ${account.emailAddress} - - ${account.firstName}${account.lastName}${account.status} - <#list account.permissionSets as permissionSet> -
${permissionSet}
- -
${account.loginCount}
- -
- - - - -
- - <#--link on user's email address currently does nothing--> - - - current page: -
- - sort order: + <#--sort order: - <#assign directions = ["ASC", "DESC"]> + <#--<#assign directions = ["ASC", "DESC"]> <#list fields as field> - + --> + -
- show accounts per page - -
- - -
\ No newline at end of file + + + +

Account |

+ + + + +
+ +
+ +
+ + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + <#list accounts as account> + + + + + + + + + + +
Account Management
+
+
+ Email Address +
+
+
First name
Last Name
Status
Roles
Login Count
+ + + + ${account.emailAddress} + + ${account.firstName}${account.lastName}${account.status} + <#list account.permissionSets as permissionSet> +
${permissionSet}
+ +
${account.loginCount}
+ +<#--link on user's email address currently does nothing--> + +${scripts.add('')} \ No newline at end of file From 44f4189767b09096188f2fc2334db1411cba9383 Mon Sep 17 00:00:00 2001 From: j2blake Date: Wed, 11 May 2011 19:24:00 +0000 Subject: [PATCH 03/47] NIHVIVO-1420 Get rid of VitroRequestPrep.isSelfEditing() and use other, more meaningful methods instead. --- .../UseRestrictedPagesByRoleLevelPolicy.java | 4 +++ .../usepages/UseMiscellaneousEditorPages.java | 11 +++++++ .../webapp/edit/n3editing/EditN3Utils.java | 29 +++++++++--------- webapp/web/edit/dashboardPropsList.jsp | 30 ++++++++++++------- 4 files changed, 50 insertions(+), 24 deletions(-) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/usepages/UseMiscellaneousEditorPages.java diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/UseRestrictedPagesByRoleLevelPolicy.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/UseRestrictedPagesByRoleLevelPolicy.java index 09ca36896..6cdde2ce3 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/UseRestrictedPagesByRoleLevelPolicy.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/UseRestrictedPagesByRoleLevelPolicy.java @@ -27,6 +27,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.UseAdvance import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.UseBasicAjaxControllers; import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.UseMiscellaneousAdminPages; import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.UseMiscellaneousCuratorPages; +import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.UseMiscellaneousEditorPages; import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.UseMiscellaneousPages; import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel; @@ -93,6 +94,9 @@ public class UseRestrictedPagesByRoleLevelPolicy implements PolicyIface { } else if (whatToAuth instanceof SeeIndividualEditingPanel) { result = isAuthorized(whatToAuth, RoleLevel.EDITOR, userRole); + } else if (whatToAuth instanceof UseMiscellaneousEditorPages) { + result = isAuthorized(whatToAuth, RoleLevel.EDITOR, userRole); + } else if (whatToAuth instanceof UseBasicAjaxControllers) { result = isAuthorized(whatToAuth, RoleLevel.SELF, userRole); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/usepages/UseMiscellaneousEditorPages.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/usepages/UseMiscellaneousEditorPages.java new file mode 100644 index 000000000..6b03bc755 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/usepages/UseMiscellaneousEditorPages.java @@ -0,0 +1,11 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages; + +import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction; + +/** Should we allow the user to use the odd-lots pages that were designed for Editors, Curators or DBAs? */ +public class UseMiscellaneousEditorPages extends RequestedAction implements + UsePagesRequestedAction { + // no fields +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3Utils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3Utils.java index 64efba566..9733c809c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3Utils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3Utils.java @@ -10,23 +10,24 @@ import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers; import edu.cornell.mannlib.vitro.webapp.auth.identifier.RoleIdentifier; import edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory; -import edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep; public class EditN3Utils { - public static String getEditorUri(HttpServletRequest request){ - String editorUri = "Unknown N3 Editor"; - boolean selfEditing = VitroRequestPrep.isSelfEditing(request); - IdentifierBundle ids = - RequestIdentifiers.getIdBundleForRequest(request); - - if( selfEditing ) - editorUri = SelfEditingIdentifierFactory.getSelfEditingUri(ids); - else - editorUri = RoleIdentifier.getUri(ids); - - return editorUri; - } + public static String getEditorUri(HttpServletRequest request) { + IdentifierBundle ids = RequestIdentifiers.getIdBundleForRequest(request); + + String editorUri = SelfEditingIdentifierFactory.getSelfEditingUri(ids); + + if (editorUri == null) { + editorUri = RoleIdentifier.getUri(ids); + } + + if (editorUri == null) { + editorUri = "Unknown N3 Editor"; + } + + return editorUri; + } /** * Strips from a string any characters that are not valid in XML 1.0 diff --git a/webapp/web/edit/dashboardPropsList.jsp b/webapp/web/edit/dashboardPropsList.jsp index 9a51eaf6a..f15dfb74c 100644 --- a/webapp/web/edit/dashboardPropsList.jsp +++ b/webapp/web/edit/dashboardPropsList.jsp @@ -1,19 +1,23 @@ <%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Property" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.UseMiscellaneousEditorPages" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.KeywordProperty" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Property" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %> <%@ page import="java.util.ArrayList" %> <%@ page import="org.apache.commons.logging.Log" %> <%@ page import="org.apache.commons.logging.LogFactory" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %> <%@ page import="edu.cornell.mannlib.vedit.beans.LoginStatusBean" %> <%! public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.dashboardPropsList.jsp"); @@ -21,18 +25,24 @@ public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp. <% boolean showSelfEdits=false; boolean showCuratorEdits=false; -if( VitroRequestPrep.isSelfEditing(request) ) { + +IdentifierBundle ids = RequestIdentifiers.getIdBundleForRequest(request); +String editorUri = SelfEditingIdentifierFactory.getSelfEditingUri(ids); +if (editorUri != null) { showSelfEdits=true; log.debug("self editing active"); } else { log.debug("self editing inactive"); } -if (LoginStatusBean.getBean(request).isLoggedInAtLeast(LoginStatusBean.EDITOR)) { + +if (PolicyHelper.isAuthorizedForActions(request, new UseMiscellaneousEditorPages())) { showCuratorEdits=true; log.debug("curator editing active"); } else { log.debug("curator editing inactive"); -}%> +} +%> + <%-- just moving this into page scope for easy use --%> <% log.debug("Starting dashboardPropsList.jsp"); From d171d52e72ffc5943250262a5a7afae53c0439fc Mon Sep 17 00:00:00 2001 From: j2blake Date: Wed, 11 May 2011 19:24:35 +0000 Subject: [PATCH 04/47] NIHVIVO-1420 Get rid of VitroRequestPrep.isSelfEditing() and use other, more meaningful methods instead. --- .../webapp/filters/VitroRequestPrep.java | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java index feb08fe42..275280f98 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java @@ -14,17 +14,13 @@ import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.hp.hpl.jena.query.Dataset; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory.SelfEditing; import edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList; import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean; import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel; @@ -194,25 +190,6 @@ public class VitroRequestPrep implements Filter { sc.setAttribute("FilterFactory", ff); } - /** - * Check to see whether any of the current identifiers is a SelfEditing - * identifier. - */ - public static boolean isSelfEditing(HttpServletRequest request) { - HttpSession session = request.getSession(false); - if (session == null) { - return false; - } - - IdentifierBundle idBundle = RequestIdentifiers.getIdBundleForRequest(request); - SelfEditing selfId = SelfEditingIdentifierFactory.getSelfEditingIdentifier(idBundle); - if (selfId == null) { - return false; - } - - return true; - } - @Override public void destroy() { // Nothing to do. From ba94c924580ed535a44a21d668b1ada2acbc1b15 Mon Sep 17 00:00:00 2001 From: j2blake Date: Wed, 11 May 2011 19:29:05 +0000 Subject: [PATCH 05/47] NIHVIVO-2631 Remove the tests - they test very little code, but they fail sometimes on Windows because temp directories can't be deleted. --- .../backend/FileStorageSetupTest.java | 145 ------------------ 1 file changed, 145 deletions(-) delete mode 100644 webapp/test/edu/cornell/mannlib/vitro/webapp/filestorage/backend/FileStorageSetupTest.java diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/filestorage/backend/FileStorageSetupTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/filestorage/backend/FileStorageSetupTest.java deleted file mode 100644 index 32f3aca27..000000000 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/filestorage/backend/FileStorageSetupTest.java +++ /dev/null @@ -1,145 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.filestorage.backend; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import java.io.File; -import java.io.IOException; - -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; - -import org.apache.log4j.Level; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import stubs.edu.cornell.mannlib.vitro.webapp.config.ConfigurationPropertiesStub; -import stubs.javax.servlet.ServletContextStub; -import edu.cornell.mannlib.vitro.testing.AbstractTestClass; -import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; - -/** - * Test the methods of {@link FileStorageSetup} - */ -public class FileStorageSetupTest extends AbstractTestClass { - // ---------------------------------------------------------------------- - // framework - // ---------------------------------------------------------------------- - - private static File tempDir; - private static File vivoHomeDir; - private static File fsBaseDir; - - private FileStorageSetup fss; - private ServletContextEvent sce; - private ServletContext sc; - - @Before - public void createFileStorageSetup() { - fss = new FileStorageSetup(); - } - - @Before - public void createContext() { - sc = new ServletContextStub(); - sce = new ServletContextEvent(sc); - } - - @Before - public void createBaseDirectory() throws IOException { - tempDir = createTempDirectory("FileStorageFactoryTest"); - vivoHomeDir = new File(tempDir, "fsBaseDirectory"); - vivoHomeDir.mkdir(); - fsBaseDir = new File(vivoHomeDir, FileStorageSetup.FILE_STORAGE_SUBDIRECTORY); - fsBaseDir.mkdir(); - } - - @After - public void cleanupBaseDirectory() { - purgeDirectoryRecursively(tempDir); - } - - // ---------------------------------------------------------------------- - // tests - // ---------------------------------------------------------------------- - - @Test - public void baseDirectoryNotSpecified() { - setLoggerLevel(FileStorageSetup.class, Level.OFF); - setConfigurationProperties(null, "http://vivo.myDomain.edu/individual/"); - fss.contextInitialized(sce); - assertNull("no base directory", - sc.getAttribute(FileStorageSetup.ATTRIBUTE_NAME)); - } - - @Test - public void baseDirectoryDoesntExist() { - setLoggerLevel(FileStorageSetup.class, Level.OFF); - setConfigurationProperties("/bogus/Directory", - "http://vivo.myDomain.edu/individual/"); - fss.contextInitialized(sce); - assertNull("no such directory", - sc.getAttribute(FileStorageSetup.ATTRIBUTE_NAME)); - } - - @Test - public void defaultNamespaceNotSpecified() { - setLoggerLevel(FileStorageSetup.class, Level.OFF); - setConfigurationProperties(vivoHomeDir.getPath(), null); - fss.contextInitialized(sce); - assertNull("no default namespace", - sc.getAttribute(FileStorageSetup.ATTRIBUTE_NAME)); - } - - // This no longer throws an exception - it should be a success. - @Test - public void defaultNamespaceIsBogus() { - setLoggerLevel(FileStorageSetup.class, Level.ERROR); - setConfigurationProperties(vivoHomeDir.getPath(), "namespace"); - fss.contextInitialized(sce); - - Object o = sc.getAttribute(FileStorageSetup.ATTRIBUTE_NAME); - FileStorage fs = (FileStorage) o; - - assertEquals("implementation class", FileStorageImpl.class, - fs.getClass()); - } - - @Test - public void success() { - setConfigurationProperties(vivoHomeDir.getPath(), - "http://vivo.myDomain.edu/individual/"); - fss.contextInitialized(sce); - - Object o = sc.getAttribute(FileStorageSetup.ATTRIBUTE_NAME); - FileStorage fs = (FileStorage) o; - - assertEquals("implementation class", FileStorageImpl.class, - fs.getClass()); - } - - // ---------------------------------------------------------------------- - // Helper methods - // ---------------------------------------------------------------------- - - private void setConfigurationProperties(String baseDir, - String defaultNamespace) { - ConfigurationPropertiesStub props = new ConfigurationPropertiesStub(); - - if (baseDir != null) { - props.setProperty(FileStorageSetup.PROPERTY_VITRO_HOME_DIR, - baseDir); - } - if (defaultNamespace != null) { - props.setProperty(FileStorageSetup.PROPERTY_DEFAULT_NAMESPACE, - defaultNamespace); - } - - setLoggerLevel(ConfigurationProperties.class, Level.WARN); - props.setBean(sc); - } - -} From 7002110c285541ed7566a0aea42658043274860e Mon Sep 17 00:00:00 2001 From: j2blake Date: Wed, 11 May 2011 20:59:30 +0000 Subject: [PATCH 06/47] NIHVIVO-2299 Improve the code in the common family of Identifiers. --- .../identifier/AbstractCommonIdentifier.java | 24 ++ .../CommonIdentifierBundleFactory.java | 79 ++++-- .../identifier/HasAssociatedIndividual.java | 186 ++------------ .../webapp/auth/identifier/HasRoleLevel.java | 27 ++- .../webapp/auth/identifier/IsBlacklisted.java | 228 ++++++++++++++++++ .../vitro/webapp/auth/identifier/IsUser.java | 39 +++ ...isplayRestrictedDataByRoleLevelPolicy.java | 16 +- .../DisplayRestrictedDataToSelfPolicy.java | 41 +--- .../UseRestrictedPagesByRoleLevelPolicy.java | 15 +- .../policy/setup/CommonPolicyFamilySetup.java | 2 +- .../AbstractRelationshipPolicy.java | 21 -- .../SelfEditorRelationshipPolicy.java | 5 +- .../SelfEditorRelationshipPolicyTest.java | 2 +- 13 files changed, 397 insertions(+), 288 deletions(-) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/AbstractCommonIdentifier.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/IsBlacklisted.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/IsUser.java diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/AbstractCommonIdentifier.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/AbstractCommonIdentifier.java new file mode 100644 index 000000000..1f631dea1 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/AbstractCommonIdentifier.java @@ -0,0 +1,24 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.auth.identifier; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +/** + * A base class for the Identifiers created by the + * CommonIdentifierBundleFactory. + */ +public abstract class AbstractCommonIdentifier { + protected static Collection getIdentifiersForClass( + IdentifierBundle ids, Class clazz) { + Set set = new HashSet(); + for (Identifier id : ids) { + if (clazz.isAssignableFrom(id.getClass())) { + set.add(clazz.cast(id)); + } + } + return set; + } +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/CommonIdentifierBundleFactory.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/CommonIdentifierBundleFactory.java index 7652e6f13..86381ba0c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/CommonIdentifierBundleFactory.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/CommonIdentifierBundleFactory.java @@ -29,26 +29,46 @@ public class CommonIdentifierBundleFactory implements IdentifierBundleFactory { private static final Log log = LogFactory .getLog(CommonIdentifierBundleFactory.class); + private final ServletContext context; + + public CommonIdentifierBundleFactory(ServletContext context) { + this.context = context; + } + @Override public IdentifierBundle getIdentifierBundle(ServletRequest request, - HttpSession session, ServletContext context) { + HttpSession session, ServletContext unusedContext) { // If this is not an HttpServletRequest, we might as well fail now. HttpServletRequest req = (HttpServletRequest) request; ArrayIdentifierBundle bundle = new ArrayIdentifierBundle(); - bundle.addAll(determineRoleLevelIdentifiers(req)); - bundle.addAll(determineAssociatedIndividualIdentifiers(req)); + bundle.addAll(createUserIdentifiers(req)); + bundle.addAll(createRoleLevelIdentifiers(req)); + bundle.addAll(createBlacklistOrAssociatedIndividualIdentifiers(req)); return bundle; } + /** + * If the user is logged in, create an identifier that shows his URI. + */ + private Collection createUserIdentifiers( + HttpServletRequest req) { + LoginStatusBean bean = LoginStatusBean.getBean(req); + if (bean.isLoggedIn()) { + return Collections.singleton(new IsUser(bean.getUserURI())); + } else { + return Collections.emptySet(); + } + } + /** * Create an identifier that shows the role level of the current user, or * PUBLIC if the user is not logged in. */ - private Collection determineRoleLevelIdentifiers( + private Collection createRoleLevelIdentifiers( HttpServletRequest req) { RoleLevel roleLevel = RoleLevel.getRoleFromLoginStatus(req); return Collections.singleton(new HasRoleLevel(roleLevel)); @@ -56,37 +76,48 @@ public class CommonIdentifierBundleFactory implements IdentifierBundleFactory { /** * Find all of the individuals that are associated with the current user, - * and create an Identifier for each one. + * and create either an IsBlacklisted or HasAssociatedIndividual for each + * one. */ - private Collection determineAssociatedIndividualIdentifiers( + private Collection createBlacklistOrAssociatedIndividualIdentifiers( HttpServletRequest req) { Collection ids = new ArrayList(); + for (Individual ind : getAssociatedIndividuals(req)) { + // If they are blacklisted, this factory will return an identifier + Identifier id = IsBlacklisted.getInstance(ind, context); + if (id != null) { + ids.add(id); + } else { + ids.add(new HasAssociatedIndividual(ind.getURI())); + } + } + + return ids; + } + + private Collection getAssociatedIndividuals( + HttpServletRequest req) { + Collection individuals = new ArrayList(); + LoginStatusBean bean = LoginStatusBean.getBean(req); String username = bean.getUsername(); if (!bean.isLoggedIn()) { - log.debug("No SelfEditing: not logged in."); - return ids; + log.debug("No Associated Individuals: not logged in."); + return individuals; } if (StringUtils.isEmpty(username)) { - log.debug("No SelfEditing: username is empty."); - return ids; + log.debug("No Associated Individuals: username is empty."); + return individuals; } - HttpSession session = req.getSession(false); - if (session == null) { - log.debug("No SelfEditing: session is null."); - return ids; - } - - ServletContext context = session.getServletContext(); WebappDaoFactory wdf = (WebappDaoFactory) context .getAttribute("webappDaoFactory"); if (wdf == null) { log.error("Could not get a WebappDaoFactory from the ServletContext"); - return ids; + return individuals; } IndividualDao indDao = wdf.getIndividualDao(); @@ -96,22 +127,18 @@ public class CommonIdentifierBundleFactory implements IdentifierBundleFactory { if (uri == null) { log.debug("Could not find an Individual with a netId of " + username); - return ids; + return individuals; } Individual ind = indDao.getIndividualByURI(uri); if (ind == null) { log.warn("Found a URI for the netId " + username + " but could not build Individual"); - return ids; + return individuals; } - log.debug("Found an Individual for netId " + username + " URI: " + uri); - // Use the factory method to fill in the Blacklisting reason, if there - // is one. - ids.add(HasAssociatedIndividual.getInstance(ind, context)); - - return ids; + individuals.add(ind); + return individuals; } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/HasAssociatedIndividual.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/HasAssociatedIndividual.java index b012d02f0..f29e1a0e4 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/HasAssociatedIndividual.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/HasAssociatedIndividual.java @@ -2,27 +2,9 @@ package edu.cornell.mannlib.vitro.webapp.auth.identifier; -import java.io.File; -import java.io.FileFilter; -import java.io.FileInputStream; -import java.io.IOException; - -import javax.servlet.ServletContext; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import com.hp.hpl.jena.query.Query; -import com.hp.hpl.jena.query.QueryExecution; -import com.hp.hpl.jena.query.QueryExecutionFactory; -import com.hp.hpl.jena.query.QueryFactory; -import com.hp.hpl.jena.query.QuerySolution; -import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.rdf.model.Model; -import com.hp.hpl.jena.rdf.model.RDFNode; - -import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; /** * The current user is associated with this Individual. @@ -30,172 +12,34 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual; * This includes a thick factory method that will look through a directory of * files to determine whether the associated individual is blacklisted. */ -public class HasAssociatedIndividual implements Identifier { - private static final Log log = LogFactory - .getLog(HasAssociatedIndividual.class); +public class HasAssociatedIndividual extends AbstractCommonIdentifier implements + Identifier { - private final static String BLACKLIST_SPARQL_DIR = "/admin/selfEditBlacklist"; - private static final String NOT_BLACKLISTED = null; - - // ---------------------------------------------------------------------- - // static methods - // ---------------------------------------------------------------------- - - public static HasAssociatedIndividual getInstance(Individual individual, - ServletContext context) { - if (individual == null) { - throw new NullPointerException("individual may not be null."); - } - if (context == null) { - throw new NullPointerException("context may not be null."); - } - - String reasonForBlacklisting = checkForBlacklisted(individual, context); - return new HasAssociatedIndividual(individual.getURI(), - reasonForBlacklisting); + public static Collection getIdentifiers( + IdentifierBundle ids) { + return getIdentifiersForClass(ids, HasAssociatedIndividual.class); } - /** - * Runs through .sparql files in the BLACKLIST_SPARQL_DIR. - * - * The first that returns one or more rows will be cause the user to be - * blacklisted. - * - * The first variable from the first solution set will be returned. - */ - private static String checkForBlacklisted(Individual ind, - ServletContext context) { - String realPath = context.getRealPath(BLACKLIST_SPARQL_DIR); - File blacklistDir = new File(realPath); - if (!blacklistDir.isDirectory() || !blacklistDir.canRead()) { - log.debug("cannot read blacklist directory " + realPath); - return NOT_BLACKLISTED; + public static Collection getIndividualUris(IdentifierBundle ids) { + Set set = new HashSet(); + for (HasAssociatedIndividual id : getIdentifiers(ids)) { + set.add(id.getAssociatedIndividualUri()); } - - log.debug("checking directlry " + realPath - + " for blacklisting sparql query files"); - File[] files = blacklistDir.listFiles(new FileFilter() { - @Override - public boolean accept(File pathname) { - return pathname.getName().endsWith(".sparql"); - } - }); - - String reasonForBlacklist = NOT_BLACKLISTED; - for (File file : files) { - try { - reasonForBlacklist = runSparqlFileForBlacklist(file, ind, - context); - if (reasonForBlacklist != NOT_BLACKLISTED) - break; - } catch (RuntimeException ex) { - log.error( - "Could not run blacklist check query for file " - + file.getAbsolutePath() + File.separatorChar - + file.getName(), ex); - } - } - return reasonForBlacklist; + return set; } - /** - * Runs the SPARQL query in the file with the uri of the individual - * substituted in. - * - * The URI of ind will be substituted into the query where ever the token - * "?individualURI" is found. - * - * If there are any solution sets, then the URI of the variable named - * "cause" will be returned. Make sure that it is a resource with a URI. - * Otherwise null will be returned. - */ - private static String runSparqlFileForBlacklist(File file, Individual ind, - ServletContext context) { - if (!file.canRead()) { - log.debug("cannot read blacklisting SPARQL file " + file.getName()); - return NOT_BLACKLISTED; - } - - String queryString = null; - FileInputStream fis = null; - try { - fis = new FileInputStream(file); - byte b[] = new byte[fis.available()]; - fis.read(b); - queryString = new String(b); - } catch (IOException ioe) { - log.debug(ioe); - return NOT_BLACKLISTED; - } finally { - if (fis != null) { - try { - fis.close(); - } catch (IOException e) { - log.warn("could not close file", e); - } - } - } - - if (StringUtils.isEmpty(queryString)) { - log.debug(file.getName() + " is empty"); - return NOT_BLACKLISTED; - } - - Model model = (Model) context.getAttribute("jenaOntModel"); - - queryString = queryString.replaceAll("\\?individualURI", - "<" + ind.getURI() + ">"); - log.debug(queryString); - - Query query = QueryFactory.create(queryString); - QueryExecution qexec = QueryExecutionFactory.create(query, model); - try { - ResultSet results = qexec.execSelect(); - while (results.hasNext()) { - QuerySolution solution = results.nextSolution(); - if (solution.contains("cause")) { - RDFNode node = solution.get("cause"); - if (node.isResource()) { - return node.asResource().getURI(); - } else if (node.isLiteral()) { - return node.asLiteral().getString(); - } - } else { - log.error("Query solution must contain a variable " - + "\"cause\" of type Resource or Literal."); - return NOT_BLACKLISTED; - } - } - } finally { - qexec.close(); - } - return NOT_BLACKLISTED; - } - - // ---------------------------------------------------------------------- - // the Identifier - // ---------------------------------------------------------------------- - private final String associatedIndividualUri; - private final String reasonForBlacklisting; - public HasAssociatedIndividual(String associatedIndividualUri, - String reasonForBlacklisting) { + public HasAssociatedIndividual(String associatedIndividualUri) { this.associatedIndividualUri = associatedIndividualUri; - this.reasonForBlacklisting = reasonForBlacklisting; } public String getAssociatedIndividualUri() { return associatedIndividualUri; } - public boolean isBlacklisted() { - return reasonForBlacklisting != NOT_BLACKLISTED; - } - @Override public String toString() { - return "HasAssociatedIndividual['" + associatedIndividualUri - + "', blacklist='" + reasonForBlacklisting + "']"; + return "HasAssociatedIndividual['" + associatedIndividualUri + "']"; } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/HasRoleLevel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/HasRoleLevel.java index 29d3759b5..730e3d6a7 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/HasRoleLevel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/HasRoleLevel.java @@ -2,12 +2,37 @@ package edu.cornell.mannlib.vitro.webapp.auth.identifier; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel; /** * The current user has this RoleLevel. */ -public class HasRoleLevel implements Identifier { +public class HasRoleLevel extends AbstractCommonIdentifier implements Identifier { + public static Collection getIdentifiers(IdentifierBundle ids) { + return getIdentifiersForClass(ids, HasRoleLevel.class); + } + + public static Collection getRoleLevelUris(IdentifierBundle ids) { + Set set = new HashSet(); + for (HasRoleLevel id : getIdentifiers(ids)) { + set.add(id.getRoleLevel().getURI()); + } + return set; + } + + public static RoleLevel getUsersRoleLevel(IdentifierBundle whoToAuth) { + Collection roleIds = getIdentifiers(whoToAuth); + if (roleIds.isEmpty()) { + return RoleLevel.PUBLIC; + } else { + return roleIds.iterator().next().getRoleLevel(); + } + } + private final RoleLevel roleLevel; public HasRoleLevel(RoleLevel roleLevel) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/IsBlacklisted.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/IsBlacklisted.java new file mode 100644 index 000000000..74fd6d277 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/IsBlacklisted.java @@ -0,0 +1,228 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.auth.identifier; + +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import javax.servlet.ServletContext; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.query.QueryExecution; +import com.hp.hpl.jena.query.QueryExecutionFactory; +import com.hp.hpl.jena.query.QueryFactory; +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.RDFNode; + +import edu.cornell.mannlib.vitro.webapp.beans.Individual; + +/** + * The current user is blacklisted for this reason. + */ +public class IsBlacklisted extends AbstractCommonIdentifier implements + Identifier { + private static final Log log = LogFactory.getLog(IsBlacklisted.class); + + private final static String BLACKLIST_SPARQL_DIR = "/admin/selfEditBlacklist"; + private static final String NOT_BLACKLISTED = null; + + // ---------------------------------------------------------------------- + // static methods + // ---------------------------------------------------------------------- + + /** + * If this individual is blacklisted, return an appropriate Identifier. + * Otherwise, return null. + */ + public static IsBlacklisted getInstance(Individual individual, + ServletContext context) { + if (individual == null) { + throw new NullPointerException("individual may not be null."); + } + if (context == null) { + throw new NullPointerException("context may not be null."); + } + + String reasonForBlacklisting = checkForBlacklisted(individual, context); + IsBlacklisted id = new IsBlacklisted(individual.getURI(), + reasonForBlacklisting); + if (id.isBlacklisted()) { + return id; + } else { + return null; + } + } + + /** + * Runs through .sparql files in the BLACKLIST_SPARQL_DIR. + * + * The first that returns one or more rows will be cause the user to be + * blacklisted. + * + * The first variable from the first solution set will be returned. + */ + private static String checkForBlacklisted(Individual ind, + ServletContext context) { + String realPath = context.getRealPath(BLACKLIST_SPARQL_DIR); + File blacklistDir = new File(realPath); + if (!blacklistDir.isDirectory() || !blacklistDir.canRead()) { + log.debug("cannot read blacklist directory " + realPath); + return NOT_BLACKLISTED; + } + + log.debug("checking directlry " + realPath + + " for blacklisting sparql query files"); + File[] files = blacklistDir.listFiles(new FileFilter() { + @Override + public boolean accept(File pathname) { + return pathname.getName().endsWith(".sparql"); + } + }); + + String reasonForBlacklist = NOT_BLACKLISTED; + for (File file : files) { + try { + reasonForBlacklist = runSparqlFileForBlacklist(file, ind, + context); + if (reasonForBlacklist != NOT_BLACKLISTED) + break; + } catch (RuntimeException ex) { + log.error( + "Could not run blacklist check query for file " + + file.getAbsolutePath() + File.separatorChar + + file.getName(), ex); + } + } + return reasonForBlacklist; + } + + /** + * Runs the SPARQL query in the file with the uri of the individual + * substituted in. + * + * The URI of ind will be substituted into the query where ever the token + * "?individualURI" is found. + * + * If there are any solution sets, then the URI of the variable named + * "cause" will be returned. Make sure that it is a resource with a URI. + * Otherwise null will be returned. + */ + private static String runSparqlFileForBlacklist(File file, Individual ind, + ServletContext context) { + if (!file.canRead()) { + log.debug("cannot read blacklisting SPARQL file " + file.getName()); + return NOT_BLACKLISTED; + } + + String queryString = null; + FileInputStream fis = null; + try { + fis = new FileInputStream(file); + byte b[] = new byte[fis.available()]; + fis.read(b); + queryString = new String(b); + } catch (IOException ioe) { + log.debug(ioe); + return NOT_BLACKLISTED; + } finally { + if (fis != null) { + try { + fis.close(); + } catch (IOException e) { + log.warn("could not close file", e); + } + } + } + + if (StringUtils.isEmpty(queryString)) { + log.debug(file.getName() + " is empty"); + return NOT_BLACKLISTED; + } + + Model model = (Model) context.getAttribute("jenaOntModel"); + + queryString = queryString.replaceAll("\\?individualURI", + "<" + ind.getURI() + ">"); + log.debug(queryString); + + Query query = QueryFactory.create(queryString); + QueryExecution qexec = QueryExecutionFactory.create(query, model); + try { + ResultSet results = qexec.execSelect(); + while (results.hasNext()) { + QuerySolution solution = results.nextSolution(); + if (solution.contains("cause")) { + RDFNode node = solution.get("cause"); + if (node.isResource()) { + return node.asResource().getURI(); + } else if (node.isLiteral()) { + return node.asLiteral().getString(); + } + } else { + log.error("Query solution must contain a variable " + + "\"cause\" of type Resource or Literal."); + return NOT_BLACKLISTED; + } + } + } finally { + qexec.close(); + } + return NOT_BLACKLISTED; + } + + public static Collection getIdentifiers(IdentifierBundle ids) { + return getIdentifiersForClass(ids, IsBlacklisted.class); + } + + public static Collection getBlacklistReasons(IdentifierBundle ids) { + Set set = new HashSet(); + for (IsBlacklisted id : getIdentifiers(ids)) { + if (id.isBlacklisted()) { + set.add(id.getReasonForBlacklisting()); + } + } + return set; + } + + // ---------------------------------------------------------------------- + // the Identifier + // ---------------------------------------------------------------------- + + private final String associatedIndividualUri; + private final String reasonForBlacklisting; + + public IsBlacklisted(String associatedIndividualUri, + String reasonForBlacklisting) { + this.associatedIndividualUri = associatedIndividualUri; + this.reasonForBlacklisting = reasonForBlacklisting; + } + + public String getAssociatedIndividualUri() { + return associatedIndividualUri; + } + + public boolean isBlacklisted() { + return reasonForBlacklisting != NOT_BLACKLISTED; + } + + public String getReasonForBlacklisting() { + return reasonForBlacklisting; + } + + @Override + public String toString() { + return "IsBlacklisted['" + reasonForBlacklisting + "']"; + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/IsUser.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/IsUser.java new file mode 100644 index 000000000..def5bdb78 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/IsUser.java @@ -0,0 +1,39 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.auth.identifier; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +/** + * The current user has this URI. + */ +public class IsUser extends AbstractCommonIdentifier implements Identifier { + public static Collection getIdentifiers(IdentifierBundle ids) { + return getIdentifiersForClass(ids, IsUser.class); + } + + public static Collection getUserUris(IdentifierBundle ids) { + Set set = new HashSet(); + for (IsUser id : getIdentifiers(ids)) { + set.add(id.getUri()); + } + return set; + } + + private final String uri; + + public IsUser(String uri) { + this.uri = uri; + } + + public String getUri() { + return uri; + } + + @Override + public String toString() { + return "IsUser[" + uri + "]"; + } +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/DisplayRestrictedDataByRoleLevelPolicy.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/DisplayRestrictedDataByRoleLevelPolicy.java index 383fecaba..96044995a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/DisplayRestrictedDataByRoleLevelPolicy.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/DisplayRestrictedDataByRoleLevelPolicy.java @@ -8,7 +8,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.vitro.webapp.auth.identifier.HasRoleLevel; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.Identifier; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionPolicyHelper; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization; @@ -51,7 +50,7 @@ public class DisplayRestrictedDataByRoleLevelPolicy implements PolicyIface { return defaultDecision("whatToAuth was null"); } - RoleLevel userRole = getUsersRoleLevel(whoToAuth); + RoleLevel userRole = HasRoleLevel.getUsersRoleLevel(whoToAuth); PolicyDecision result; if (whatToAuth instanceof DisplayDataProperty) { @@ -164,17 +163,4 @@ public class DisplayRestrictedDataByRoleLevelPolicy implements PolicyIface { .canDisplayPredicate(uri, userRole); } - /** - * The user is nobody unless they have a HasRoleLevel identifier. - */ - private RoleLevel getUsersRoleLevel(IdentifierBundle whoToAuth) { - RoleLevel userRole = RoleLevel.PUBLIC; - for (Identifier id : whoToAuth) { - if (id instanceof HasRoleLevel) { - userRole = ((HasRoleLevel) id).getRoleLevel(); - } - } - return userRole; - } - } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/DisplayRestrictedDataToSelfPolicy.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/DisplayRestrictedDataToSelfPolicy.java index 8911a2fa8..4c21f39fd 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/DisplayRestrictedDataToSelfPolicy.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/DisplayRestrictedDataToSelfPolicy.java @@ -2,9 +2,7 @@ package edu.cornell.mannlib.vitro.webapp.auth.policy; -import java.util.ArrayList; import java.util.Collection; -import java.util.List; import javax.servlet.ServletContext; @@ -13,7 +11,6 @@ import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.vitro.webapp.auth.identifier.HasAssociatedIndividual; import edu.cornell.mannlib.vitro.webapp.auth.identifier.HasRoleLevel; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.Identifier; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionPolicyHelper; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization; @@ -24,9 +21,9 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.display.DisplayData import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.display.DisplayObjectProperty; import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.display.DisplayObjectPropertyStatement; import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction; +import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel; import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; -import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel; /** * Permit display of various data if it relates to the user's associated @@ -60,12 +57,13 @@ public class DisplayRestrictedDataToSelfPolicy implements PolicyIface { return defaultDecision("whatToAuth was null"); } - RoleLevel userRole = getUsersRoleLevel(whoToAuth); + RoleLevel userRole = HasRoleLevel.getUsersRoleLevel(whoToAuth); if (userRole != RoleLevel.SELF) { return defaultDecision("not a self-editor"); } - Collection associated = getAssociatedIndividualUris(whoToAuth); + Collection associated = HasAssociatedIndividual + .getIndividualUris(whoToAuth); if (associated.isEmpty()) { return defaultDecision("not self-editing for anyone"); } @@ -177,35 +175,4 @@ public class DisplayRestrictedDataToSelfPolicy implements PolicyIface { return false; } - /** - * The user is nobody unless they have a HasRoleLevel identifier. - */ - private RoleLevel getUsersRoleLevel(IdentifierBundle whoToAuth) { - RoleLevel userRole = RoleLevel.PUBLIC; - for (Identifier id : whoToAuth) { - if (id instanceof HasRoleLevel) { - userRole = ((HasRoleLevel) id).getRoleLevel(); - } - } - return userRole; - } - - /** - * Find out who the user has self-editing rights for. We only include the - * ones that are not blacklisted. - */ - private Collection getAssociatedIndividualUris( - IdentifierBundle whoToAuth) { - List list = new ArrayList(); - for (Identifier id : whoToAuth) { - if (id instanceof HasAssociatedIndividual) { - HasAssociatedIndividual haiId = (HasAssociatedIndividual) id; - if (!haiId.isBlacklisted()) { - list.add(haiId.getAssociatedIndividualUri()); - } - } - } - return list; - } - } \ No newline at end of file diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/UseRestrictedPagesByRoleLevelPolicy.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/UseRestrictedPagesByRoleLevelPolicy.java index 6cdde2ce3..df5d2ffc7 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/UseRestrictedPagesByRoleLevelPolicy.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/UseRestrictedPagesByRoleLevelPolicy.java @@ -6,7 +6,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.vitro.webapp.auth.identifier.HasRoleLevel; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.Identifier; 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.PolicyDecision; @@ -49,7 +48,7 @@ public class UseRestrictedPagesByRoleLevelPolicy implements PolicyIface { return defaultDecision("whatToAuth was null"); } - RoleLevel userRole = getUsersRoleLevel(whoToAuth); + RoleLevel userRole = HasRoleLevel.getUsersRoleLevel(whoToAuth); PolicyDecision result; if (whatToAuth instanceof UseAdvancedDataToolsPages) { @@ -141,16 +140,4 @@ public class UseRestrictedPagesByRoleLevelPolicy implements PolicyIface { return new BasicPolicyDecision(Authorization.INCONCLUSIVE, message); } - /** - * The user is nobody unless they have a HasRoleLevel identifier. - */ - private RoleLevel getUsersRoleLevel(IdentifierBundle whoToAuth) { - RoleLevel userRole = RoleLevel.PUBLIC; - for (Identifier id : whoToAuth) { - if (id instanceof HasRoleLevel) { - userRole = ((HasRoleLevel) id).getRoleLevel(); - } - } - return userRole; - } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/setup/CommonPolicyFamilySetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/setup/CommonPolicyFamilySetup.java index 94f0623f3..7da3e744a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/setup/CommonPolicyFamilySetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/setup/CommonPolicyFamilySetup.java @@ -41,7 +41,7 @@ public class CommonPolicyFamilySetup implements ServletContextListener { new UseRestrictedPagesByRoleLevelPolicy()); // This factory creates Identifiers for all of the above policies. - CommonIdentifierBundleFactory factory = new CommonIdentifierBundleFactory(); + CommonIdentifierBundleFactory factory = new CommonIdentifierBundleFactory(ctx); ActiveIdentifierBundleFactories.addFactory(sce, factory); } catch (Exception e) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/specialrelationships/AbstractRelationshipPolicy.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/specialrelationships/AbstractRelationshipPolicy.java index 0fb8e1928..c238d246c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/specialrelationships/AbstractRelationshipPolicy.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/specialrelationships/AbstractRelationshipPolicy.java @@ -19,9 +19,6 @@ import com.hp.hpl.jena.rdf.model.SimpleSelector; import com.hp.hpl.jena.rdf.model.StmtIterator; import com.hp.hpl.jena.shared.Lock; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.HasAssociatedIndividual; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.Identifier; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; import edu.cornell.mannlib.vitro.webapp.auth.policy.BasicPolicyDecision; import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionPolicyHelper; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization; @@ -47,24 +44,6 @@ public abstract class AbstractRelationshipPolicy implements PolicyIface { this.model = model; } - /** - * Check to see whether we are self-editing, and for which Individuals. - */ - protected List getUrisOfSelfEditor(IdentifierBundle ids) { - List uris = new ArrayList(); - if (ids != null) { - for (Identifier id : ids) { - if (id instanceof HasAssociatedIndividual) { - HasAssociatedIndividual selfEditId = (HasAssociatedIndividual) id; - if (!selfEditId.isBlacklisted()) { - uris.add(selfEditId.getAssociatedIndividualUri()); - } - } - } - } - return uris; - } - protected boolean canModifyResource(String uri) { return PropertyRestrictionPolicyHelper.getBean(ctx).canModifyResource( uri, RoleLevel.SELF); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/specialrelationships/SelfEditorRelationshipPolicy.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/specialrelationships/SelfEditorRelationshipPolicy.java index ba0d984e1..af4d2f5d8 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/specialrelationships/SelfEditorRelationshipPolicy.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/specialrelationships/SelfEditorRelationshipPolicy.java @@ -2,6 +2,7 @@ package edu.cornell.mannlib.vitro.webapp.auth.policy.specialrelationships; +import java.util.ArrayList; import java.util.List; import javax.servlet.ServletContext; @@ -13,6 +14,7 @@ import org.apache.commons.logging.LogFactory; import com.hp.hpl.jena.ontology.OntModel; +import edu.cornell.mannlib.vitro.webapp.auth.identifier.HasAssociatedIndividual; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; import edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision; @@ -128,7 +130,8 @@ public class SelfEditorRelationshipPolicy extends AbstractRelationshipPolicy private PolicyDecision isAuthorized(IdentifierBundle ids, DistilledAction action) { - List userUris = getUrisOfSelfEditor(ids); + List userUris = new ArrayList( + HasAssociatedIndividual.getIndividualUris(ids)); if (userUris.isEmpty()) { return inconclusiveDecision("Not self-editing."); diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/specialrelationships/SelfEditorRelationshipPolicyTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/specialrelationships/SelfEditorRelationshipPolicyTest.java index 368c25d3f..c21ee81c7 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/specialrelationships/SelfEditorRelationshipPolicyTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/specialrelationships/SelfEditorRelationshipPolicyTest.java @@ -420,7 +420,7 @@ public class SelfEditorRelationshipPolicyTest extends AbstractTestClass { // ---------------------------------------------------------------------- private HasAssociatedIndividual makeSelfEditingId(String uri) { - return new HasAssociatedIndividual(uri, null); + return new HasAssociatedIndividual(uri); } private void assertDecision(Authorization expected, PolicyDecision decision) { From e8e461da9d29f7e48485b18846505181987e46be Mon Sep 17 00:00:00 2001 From: j2blake Date: Wed, 11 May 2011 21:17:27 +0000 Subject: [PATCH 07/47] This test class contains no tests. --- .../webapp/dao/jena/EntityDaoJenaTest.java | 60 ------------------- 1 file changed, 60 deletions(-) delete mode 100644 webapp/test/edu/cornell/mannlib/vitro/webapp/dao/jena/EntityDaoJenaTest.java diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/dao/jena/EntityDaoJenaTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/dao/jena/EntityDaoJenaTest.java deleted file mode 100644 index 99de41cf6..000000000 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/dao/jena/EntityDaoJenaTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.dao.jena; - -import com.hp.hpl.jena.ontology.OntModel; -import com.hp.hpl.jena.ontology.OntModelSpec; -import com.hp.hpl.jena.rdf.model.Model; -import com.hp.hpl.jena.rdf.model.ModelFactory; -import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler; - -import edu.cornell.mannlib.vitro.testing.AbstractTestClass; -import edu.cornell.mannlib.vitro.webapp.auth.policy.JenaNetidPolicyTest; -import edu.cornell.mannlib.vitro.webapp.dao.jena.IndividualDaoJena; -import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import org.apache.log4j.Level; -import org.junit.Before; -import org.junit.Test; - -import java.io.InputStream; -import java.util.Collection; - -public class EntityDaoJenaTest extends AbstractTestClass { - - OntModel dorkHobbyModel; - - @Before - public void setUp() throws Exception { - // Suppress error logging. - setLoggerLevel(RDFDefaultErrorHandler.class, Level.OFF); - - Model model = ModelFactory.createDefaultModel(); - InputStream in = JenaNetidPolicyTest.class.getResourceAsStream("resources/dorkyhobbies.owl"); - model.read(in,null); - dorkHobbyModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM,model); - } - - /** - * This is a class that had no tests, so Brian and I pulled one back. But it - * doesn't compile, and it appears to be intended to test a method that has - * not been implemented. So for now, we give it a pass. - */ - @Test - public void testGetEntitiesByProperties() { - // This is the class that had no tests, so we pulled one back. -// IndividualDaoJena edj = new IndividualDaoJena(); -// edj.setOntModel(dorkHobbyModel); -// String propURI="http://test.mannlib.cornell.edu#hasHobby", -// ignoreEntURI="http://test.mannlib.cornell.edu#bob", -// classURI=null; -// -// //bob hasHobby x -// Collection ents = -// edj.getIndividualsByObjectProperty(propURI, ignoreEntURI, classURI, true); -// assertNotNull(ents); - } - -} From 8db9f1dd879560855d80aa3cf6ecd8360cf241f2 Mon Sep 17 00:00:00 2001 From: j2blake Date: Wed, 11 May 2011 21:18:30 +0000 Subject: [PATCH 08/47] remove compiler warnings. --- .../auth/identifier/SelfEditingIdentifierFactory.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/SelfEditingIdentifierFactory.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/SelfEditingIdentifierFactory.java index 5ba828ffd..5807e9ce7 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/SelfEditingIdentifierFactory.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/SelfEditingIdentifierFactory.java @@ -16,7 +16,6 @@ import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecutionFactory; @@ -31,7 +30,6 @@ import com.hp.hpl.jena.rdf.model.Resource; import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration; -import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; @@ -44,6 +42,7 @@ public class SelfEditingIdentifierFactory implements IdentifierBundleFactory { private static final int MAXIMUM_USERNAME_LENGTH = 100; + @Override public IdentifierBundle getIdentifierBundle(ServletRequest request, HttpSession session, ServletContext context) { if (!(request instanceof HttpServletRequest)) { @@ -202,7 +201,8 @@ public class SelfEditingIdentifierFactory implements IdentifierBundleFactory { log.debug("checking directlry " + realPath + " for blacklisting sparql query files"); File[] files = blacklistDir.listFiles(new FileFilter(){ - public boolean accept(File pathname) { + @Override + public boolean accept(File pathname) { return pathname.getName().endsWith(".sparql"); }} ); From 491f5d3728d3ee40aa186970c68bfb7c41acf0c0 Mon Sep 17 00:00:00 2001 From: j2blake Date: Wed, 11 May 2011 21:19:00 +0000 Subject: [PATCH 09/47] NIHVIVO-2299 Improve the code in the common family of Identifiers. --- .../auth/policy/BaseSelfEditingPolicy.java | 21 ------------------- .../webapp/auth/policy/SelfEditingPolicy.java | 5 ++++- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/BaseSelfEditingPolicy.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/BaseSelfEditingPolicy.java index 3c96fc9ee..70319776f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/BaseSelfEditingPolicy.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/BaseSelfEditingPolicy.java @@ -2,14 +2,8 @@ package edu.cornell.mannlib.vitro.webapp.auth.policy; -import java.util.ArrayList; -import java.util.List; - import javax.servlet.ServletContext; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.Identifier; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory.SelfEditing; import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionPolicyHelper; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision; @@ -37,21 +31,6 @@ public abstract class BaseSelfEditingPolicy { uri, roleLevel); } - protected List getUrisOfSelfEditor(IdentifierBundle ids) { - List uris = new ArrayList(); - if (ids != null) { - for (Identifier id : ids) { - if (id instanceof SelfEditing) { - SelfEditing selfEditId = (SelfEditing) id; - if (selfEditId.getBlacklisted() == null) { - uris.add(selfEditId.getValue()); - } - } - } - } - return uris; - } - protected PolicyDecision cantModifyResource(String uri) { return inconclusiveDecision("No access to admin resources; cannot modify " + uri); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/SelfEditingPolicy.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/SelfEditingPolicy.java index 5c2023598..d83af46aa 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/SelfEditingPolicy.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/SelfEditingPolicy.java @@ -2,10 +2,12 @@ package edu.cornell.mannlib.vitro.webapp.auth.policy; +import java.util.ArrayList; import java.util.List; import javax.servlet.ServletContext; +import edu.cornell.mannlib.vitro.webapp.auth.identifier.HasAssociatedIndividual; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyIface; @@ -35,7 +37,8 @@ public class SelfEditingPolicy extends BaseSelfEditingPolicy implements return inconclusiveDecision("whatToAuth was null"); } - List userUris = getUrisOfSelfEditor(whoToAuth); + List userUris = new ArrayList( + HasAssociatedIndividual.getIndividualUris(whoToAuth)); if (userUris.isEmpty()) { return inconclusiveDecision("Not self-editing."); From f41d69753b0b6988c26c59902ee442e5a5c8511d Mon Sep 17 00:00:00 2001 From: j2blake Date: Wed, 11 May 2011 21:19:57 +0000 Subject: [PATCH 10/47] NIHVIVO-2299 Continue converting from older Identifiers to newer Identifiers. --- .../webapp/edit/n3editing/EditN3Utils.java | 26 +++++++++---------- .../auth/policy/SelfEditingPolicyTest.java | 21 +++++---------- .../setup/SelfEditingPolicySetupTest.java | 19 ++++---------- 3 files changed, 24 insertions(+), 42 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3Utils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3Utils.java index 9733c809c..dd74eab29 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3Utils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3Utils.java @@ -2,31 +2,31 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +import java.util.ArrayList; +import java.util.List; + import javax.servlet.http.HttpServletRequest; import org.apache.xerces.util.XMLChar; +import edu.cornell.mannlib.vitro.webapp.auth.identifier.HasAssociatedIndividual; +import edu.cornell.mannlib.vitro.webapp.auth.identifier.HasRoleLevel; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; +import edu.cornell.mannlib.vitro.webapp.auth.identifier.IsUser; import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.RoleIdentifier; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory; public class EditN3Utils { + /** Several places could give an editor URI. Return the first one. */ public static String getEditorUri(HttpServletRequest request) { IdentifierBundle ids = RequestIdentifiers.getIdBundleForRequest(request); - String editorUri = SelfEditingIdentifierFactory.getSelfEditingUri(ids); - - if (editorUri == null) { - editorUri = RoleIdentifier.getUri(ids); - } - - if (editorUri == null) { - editorUri = "Unknown N3 Editor"; - } - - return editorUri; + List uris = new ArrayList(); + uris.addAll(IsUser.getUserUris(ids)); + uris.addAll(HasAssociatedIndividual.getIndividualUris(ids)); + uris.addAll(HasRoleLevel.getRoleLevelUris(ids)); + uris.add("Unknown N3 Editor"); + return uris.get(0); } /** diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/SelfEditingPolicyTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/SelfEditingPolicyTest.java index 852d7d8d6..49d41e304 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/SelfEditingPolicyTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/SelfEditingPolicyTest.java @@ -15,8 +15,8 @@ import stubs.edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestricti import stubs.javax.servlet.ServletContextStub; import edu.cornell.mannlib.vitro.testing.AbstractTestClass; import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle; +import edu.cornell.mannlib.vitro.webapp.auth.identifier.HasAssociatedIndividual; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory; import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionPolicyHelper; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision; @@ -69,14 +69,11 @@ public class SelfEditingPolicyTest extends AbstractTestClass { policy = new SelfEditingPolicy(ctx); - ids = new ArrayIdentifierBundle(); - ids.add(new SelfEditingIdentifierFactory.NetId("test223")); - IndividualImpl ind = new IndividualImpl(); ind.setURI(SELFEDITOR_URI); - ids.add(new SelfEditingIdentifierFactory.SelfEditing(ind, - SelfEditingIdentifierFactory.NOT_BLACKLISTED)); - + + ids = new ArrayIdentifierBundle(); + ids.add(new HasAssociatedIndividual(SELFEDITOR_URI)); } @Test @@ -323,19 +320,13 @@ public class SelfEditingPolicyTest extends AbstractTestClass { private void setUpTwoSEIs() { ids = new ArrayIdentifierBundle(); - ids.add(new SelfEditingIdentifierFactory.NetId("bozoUser")); - IndividualImpl ind1 = new IndividualImpl(); ind1.setURI(SAFE_NS + "bozoUri"); - ids.add(new SelfEditingIdentifierFactory.SelfEditing(ind1, - SelfEditingIdentifierFactory.NOT_BLACKLISTED)); - - ids.add(new SelfEditingIdentifierFactory.NetId("test223")); + ids.add(new HasAssociatedIndividual(ind1.getURI())); IndividualImpl ind2 = new IndividualImpl(); ind2.setURI(SELFEDITOR_URI); - ids.add(new SelfEditingIdentifierFactory.SelfEditing(ind2, - SelfEditingIdentifierFactory.NOT_BLACKLISTED)); + ids.add(new HasAssociatedIndividual(ind2.getURI())); } // ---------------------------------------------------------------------- diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/setup/SelfEditingPolicySetupTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/setup/SelfEditingPolicySetupTest.java index 4b833c6b0..2df6dee75 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/setup/SelfEditingPolicySetupTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/setup/SelfEditingPolicySetupTest.java @@ -20,9 +20,9 @@ import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler; import edu.cornell.mannlib.vitro.testing.AbstractTestClass; import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle; +import edu.cornell.mannlib.vitro.webapp.auth.identifier.HasAssociatedIndividual; import edu.cornell.mannlib.vitro.webapp.auth.identifier.Identifier; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory; import edu.cornell.mannlib.vitro.webapp.auth.policy.SelfEditingPolicy; import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionPolicyHelper; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization; @@ -88,7 +88,7 @@ public class SelfEditingPolicySetupTest extends AbstractTestClass { PropertyRestrictionPolicyHelper.setBean(ctx, PropertyRestrictionPolicyHelperStub .getInstance(new String[] { ADMIN_NS })); - + policy = new SelfEditingPolicy(ctx); Assert.assertNotNull(policy); @@ -96,8 +96,7 @@ public class SelfEditingPolicySetupTest extends AbstractTestClass { seIndividual.setURI(SELFEDITOR_URI); ids = new ArrayIdentifierBundle(); - ids.add(new SelfEditingIdentifierFactory.SelfEditing(seIndividual, - SelfEditingIdentifierFactory.NOT_BLACKLISTED)); + ids.add(new HasAssociatedIndividual(SELFEDITOR_URI)); // setLoggerLevel(SelfEditingPolicySetupTest.class, Level.DEBUG); } @@ -125,16 +124,8 @@ public class SelfEditingPolicySetupTest extends AbstractTestClass { @Test public void noSelfEditorIdentifier() { ids.clear(); - ids.add(new Identifier() { /* empty identifier */ }); - assertAddObjectPropStmt(SELFEDITOR_URI, SAFE_PREDICATE, SAFE_RESOURCE, - Authorization.INCONCLUSIVE); - } - - @Test - public void blacklistedSelfEditor() { - ids.clear(); - ids.add(new SelfEditingIdentifierFactory.SelfEditing(seIndividual, - "Don't like this guy.")); + ids.add(new Identifier() { /* empty identifier */ + }); assertAddObjectPropStmt(SELFEDITOR_URI, SAFE_PREDICATE, SAFE_RESOURCE, Authorization.INCONCLUSIVE); } From b8471f62cf3c139c34fa753cd3ada717b68bc87b Mon Sep 17 00:00:00 2001 From: ryounes Date: Wed, 11 May 2011 22:08:39 +0000 Subject: [PATCH 11/47] NIHVIVO-2437 Filtered search based on refinement links. Change default boolean operator from OR to AND. Unrelated code cleanup in ApplicationDaoJena.java. --- solr/exampleSolr/conf/schema.xml | 2 +- .../webapp/dao/jena/ApplicationDaoJena.java | 13 +- .../controller/SolrPagedSearchController.java | 243 ++++-------------- 3 files changed, 61 insertions(+), 197 deletions(-) diff --git a/solr/exampleSolr/conf/schema.xml b/solr/exampleSolr/conf/schema.xml index 49a2aff5a..dadb1c40c 100644 --- a/solr/exampleSolr/conf/schema.xml +++ b/solr/exampleSolr/conf/schema.xml @@ -508,7 +508,7 @@ ALLTEXT - + -<#-- Template for the Fake External Authentication page. --> +<#-- Template for login using internal vitro account (even when external auth is enabled). Accessible at /admin/login --> -
+

Internal Login

<#if errorNoUser??> -

No username supplied.

+ <#assign errorMessage = "No email supplied." /> <#if errorNoPassword??> -

No password supplied

+ <#assign errorMessage = "No password supplied." /> <#if errorLoginFailed??> -

Username or Password was incorrect.

+ <#assign errorMessage = "Email or Password was incorrect." /> - <#if newPasswordRequired??> -

This is your first time logging in. You must supply a new password.

+ <#if (errorNoUser?? || errorNoPassword?? || errorLoginFailed?? )> + -

- Enter the username and password for your internal VIVO account. -

- -
-
Username:
-
Password:
+ <#if ( !newPasswordRequired?? )> +

Enter the email address and password for your internal Vitro account.

+ <#else> +

You must change your password to log in.

+ + <#if newPasswordRequired??> -
New Password:
+ + + +

Minimum of 6 characters in length.

+ + + + + + + <#else> + + + + + - +

-
+
\ No newline at end of file From 41440465592a147b0a0a2743a6f7daa3dc64e98c Mon Sep 17 00:00:00 2001 From: briancaruso Date: Thu, 12 May 2011 16:02:37 +0000 Subject: [PATCH 14/47] Refactoring the N3 editing to reorganize packages --- .../FedoraDatastreamController.java | 4 +- .../vitro/webapp/controller/JSONServlet.java | 4 +- .../controller/edit/N3MultiPartUpload.java | 10 +- .../controller/edit/PrimitiveRdfEdit.java | 2 +- .../freemarker/IndividualController.java | 9 +- .../freemarker/N3EditFormController.java | 4 +- .../freemarker/SamplesController.java | 1 - .../webapp/edit/elements/BaseEditElement.java | 2 +- .../edit/elements/DateTimeWithPrecision.java | 6 +- .../webapp/edit/elements/EditElement.java | 4 +- ...ividualDataPropertyStatementProcessor.java | 2 +- .../webapp/edit/n3editing/N3Validator.java | 9 - .../EditConfiguration.java | 8 +- .../n3editing/{ => configuration}/Field.java | 2 +- .../{ => configuration}/ModelSelector.java | 2 +- .../SelectListGenerator.java | 64 +-- .../StandardModelSelector.java | 2 +- .../StandardWDFSelector.java | 2 +- .../{ => configuration}/WDFSelector.java | 2 +- .../DefaultPropertyFormGenerator.java | 21 + .../EditConfigurationGenerator.java | 10 + .../BaseEditSubmissionPreprocessor.java | 5 +- .../CreateLabelFromNameFields.java | 6 +- ...issingIndividualFormModelPreprocessor.java | 5 +- .../EditSubmissionPreprocessor.java | 4 +- .../FoafNameToRdfsLabelPreprocessor.java | 2 +- .../ModelChangePreprocessor.java | 2 +- .../validators}/BasicValidation.java | 5 +- .../DateTimeIntervalValidation.java | 4 +- .../configuration/validators/N3Validator.java | 12 + .../validators}/StartDateBeforeEndDate.java | 5 +- .../validators}/StartYearBeforeEndYear.java | 5 +- ...ava => EditRequestDispatchController.java} | 82 +-- .../n3editing/controller/ProcessRdfForm.java | 528 ------------------ .../controller/ProcessRdfFormController.java | 227 ++++++++ .../processEdit/AdditionsAndRetractions.java | 52 ++ .../{ => processEdit}/EditN3Generator.java | 6 +- .../{ => processEdit}/EditN3Utils.java | 23 +- .../{ => processEdit}/EditSubmission.java | 8 +- .../n3editing/processEdit/ProcessRdfForm.java | 277 +++++++++ .../{ => processEdit}/RdfLiteralHash.java | 2 +- .../{ => processEdit}/SparqlEvaluate.java | 15 +- .../webapp/web/jsptags/ErrorMessage.java | 4 +- .../jsptags/InputElementFormattingTag.java | 8 +- .../vitro/webapp/web/jsptags/Options.java | 11 - .../vitro/webapp/web/jsptags/Value.java | 6 - .../DataPropertyStatementTemplateModel.java | 2 +- .../webapp/web/widgets/SelectListWidget.java | 5 +- .../elements/DateTimeWithPrecisionTest.java | 6 +- .../edit/n3editing/BasicValidationTest.java | 2 + .../edit/n3editing/EditN3GeneratorTest.java | 2 + .../edit/n3editing/EditN3UtilsTest.java | 2 + .../edit/n3editing/EditSubmissionTest.java | 2 + .../edit/n3editing/RdfLiteralHashTest.java | 1 + .../edit/n3editing/SparqlEvaluateTest.java | 3 + .../edit/editDatapropStmtRequestDispatch.jsp | 4 +- webapp/web/edit/editRequestDispatch.jsp | 2 +- .../forms/addMissingWithMonikerAndLink.jsp | 2 +- webapp/web/edit/forms/admin/mayEditAs.jsp | 4 +- .../edit/forms/autoCompleteDatapropForm.jsp | 2 +- .../edit/forms/autoCompleteObjPropForm.jsp | 2 +- webapp/web/edit/forms/datapropStmtDelete.jsp | 6 +- .../web/edit/forms/dateTimeIntervalForm.jsp | 6 +- webapp/web/edit/forms/dateTimeValueForm.jsp | 6 +- .../forms/defaultAddMissingIndividualForm.jsp | 6 +- webapp/web/edit/forms/defaultDatapropForm.jsp | 2 +- webapp/web/edit/forms/defaultLinkForm.jsp | 2 +- webapp/web/edit/forms/defaultObjPropForm.jsp | 4 +- webapp/web/edit/forms/propDelete.jsp | 2 +- webapp/web/edit/forms/rdfsLabelForm.jsp | 4 +- .../web/edit/forms/test/dateTimePrecTest.jsp | 2 +- .../datapropertyBackButtonProblems.jsp | 10 +- webapp/web/edit/n3Delete.jsp | 10 +- webapp/web/edit/postEditCleanUp.jsp | 4 +- webapp/web/edit/processDatapropRdfForm.jsp | 12 +- webapp/web/edit/processRdfForm2.jsp | 12 +- webapp/web/edit/selfeditcheck.jsp | 4 +- 77 files changed, 853 insertions(+), 754 deletions(-) delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/N3Validator.java rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => configuration}/EditConfiguration.java (98%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => configuration}/Field.java (99%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => configuration}/ModelSelector.java (82%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => configuration}/SelectListGenerator.java (92%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => configuration}/StandardModelSelector.java (94%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => configuration}/StandardWDFSelector.java (90%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => configuration}/WDFSelector.java (83%) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultPropertyFormGenerator.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/EditConfigurationGenerator.java rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => configuration/preprocessors}/BaseEditSubmissionPreprocessor.java (68%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => configuration/preprocessors}/CreateLabelFromNameFields.java (89%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => configuration/preprocessors}/DefaultAddMissingIndividualFormModelPreprocessor.java (93%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => configuration/preprocessors}/EditSubmissionPreprocessor.java (53%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => configuration/preprocessors}/FoafNameToRdfsLabelPreprocessor.java (94%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => configuration/preprocessors}/ModelChangePreprocessor.java (79%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => configuration/validators}/BasicValidation.java (97%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => configuration/validators}/DateTimeIntervalValidation.java (96%) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/validators/N3Validator.java rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => configuration/validators}/StartDateBeforeEndDate.java (92%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => configuration/validators}/StartYearBeforeEndYear.java (89%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/{EditRequestDispatch.java => EditRequestDispatchController.java} (81%) delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfForm.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/AdditionsAndRetractions.java rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => processEdit}/EditN3Generator.java (98%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => processEdit}/EditN3Utils.java (81%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => processEdit}/EditSubmission.java (97%) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/ProcessRdfForm.java rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => processEdit}/RdfLiteralHash.java (99%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/{ => processEdit}/SparqlEvaluate.java (94%) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/FedoraDatastreamController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/FedoraDatastreamController.java index fec08ca55..db59e7174 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/FedoraDatastreamController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/FedoraDatastreamController.java @@ -231,7 +231,7 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons } //check if fedora is on line - OntModel sessionOntModel = (OntModel)req.getSession().getAttribute("jenaOntModel"); + OntModel sessionOntModel = (OntModel)rawRequest.getSession().getAttribute("jenaOntModel"); synchronized (FedoraDatastreamController.class) { if( fedoraUrl == null ){ setup( sessionOntModel, getServletContext() ); @@ -280,7 +280,7 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons "enough information to complete your request.(Missing fileRes)"); //check if file individual has a fedora:PID for a data stream - VitroRequest vreq = new VitroRequest(req); + VitroRequest vreq = new VitroRequest(rawRequest); IndividualDao iwDao = vreq.getWebappDaoFactory().getIndividualDao(); Individual fileEntity = iwDao.getIndividualByURI(fileUri); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/JSONServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/JSONServlet.java index 72c3ade99..af6d82d5f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/JSONServlet.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/JSONServlet.java @@ -40,8 +40,8 @@ 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; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.SelectListGenerator; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.SelectListGenerator; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/N3MultiPartUpload.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/N3MultiPartUpload.java index f7ed0e0e9..338bb3bea 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/N3MultiPartUpload.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/N3MultiPartUpload.java @@ -38,11 +38,11 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.UserDao; import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Generator; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Utils; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Generator; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission; import edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.FileUploadServletRequest; import edu.cornell.mannlib.vitro.webapp.utils.MailUtil; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/PrimitiveRdfEdit.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/PrimitiveRdfEdit.java index 0ff5ebdd9..2e8e8cd27 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/PrimitiveRdfEdit.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/PrimitiveRdfEdit.java @@ -26,7 +26,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.ajax.VitroAjaxController; import edu.cornell.mannlib.vitro.webapp.dao.jena.DependentResourceDeleteJena; import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Utils; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils; public class PrimitiveRdfEdit extends VitroAjaxController { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualController.java index cb2445797..ec2d97ac1 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualController.java @@ -48,8 +48,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission; import edu.cornell.mannlib.vitro.webapp.filestorage.model.FileInfo; import edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasoner; import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper; @@ -144,11 +142,8 @@ public class IndividualController extends FreemarkerHttpServlet { } private void cleanUpSession(VitroRequest vreq) { - // Session cleanup: any time we are at an entity page we shouldn't have an editing config or submission - HttpSession session = vreq.getSession(); - session.removeAttribute("editjson"); - EditConfiguration.clearAllConfigsInSession(session); - EditSubmission.clearAllEditSubmissionsInSession(session); + // We should not remove edit configurations from the session because the user + // may resubmit the forms via the back button and the system is setup to handle this. } private Map getVerbosePropertyValues(VitroRequest vreq) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/N3EditFormController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/N3EditFormController.java index 8f1b2ce27..0e0c4506a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/N3EditFormController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/N3EditFormController.java @@ -11,8 +11,8 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues; 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.edit.n3editing.EditConfiguration; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission; import freemarker.template.ObjectWrapper; import freemarker.template.TemplateModelException; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/SamplesController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/SamplesController.java index b45a82215..0c3f0caa2 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/SamplesController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/SamplesController.java @@ -13,7 +13,6 @@ import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; 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.edit.n3editing.EditConfiguration; /** * Freemarker controller and template samples. diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/elements/BaseEditElement.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/elements/BaseEditElement.java index 3d98df9d4..158bbb8c6 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/elements/BaseEditElement.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/elements/BaseEditElement.java @@ -9,7 +9,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field; import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.TemplateException; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecision.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecision.java index ddce96da7..1a5816397 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecision.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecision.java @@ -25,9 +25,9 @@ import com.hp.hpl.jena.rdf.model.ResourceFactory; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission; import freemarker.template.Configuration; /** diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/elements/EditElement.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/elements/EditElement.java index 662c43954..ebc5b562d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/elements/EditElement.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/elements/EditElement.java @@ -6,8 +6,8 @@ import java.util.Map; import com.hp.hpl.jena.rdf.model.Literal; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission; import freemarker.template.Configuration; /** * All classes that implement this interface must have a public constructor that diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/listener/impl/IndividualDataPropertyStatementProcessor.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/listener/impl/IndividualDataPropertyStatementProcessor.java index 7736fd74b..763190bd5 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/listener/impl/IndividualDataPropertyStatementProcessor.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/listener/impl/IndividualDataPropertyStatementProcessor.java @@ -19,7 +19,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao; import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.BasicValidation; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.BasicValidation; public class IndividualDataPropertyStatementProcessor implements ChangeListener { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/N3Validator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/N3Validator.java deleted file mode 100644 index f135b3d87..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/N3Validator.java +++ /dev/null @@ -1,9 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; - -import java.util.Map; - -public interface N3Validator { - public Map validate(EditConfiguration editConfig, EditSubmission editSub); -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditConfiguration.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/EditConfiguration.java similarity index 98% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditConfiguration.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/EditConfiguration.java index 03c0df221..f2582028c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditConfiguration.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/EditConfiguration.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; @@ -33,6 +33,12 @@ import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers; import edu.cornell.mannlib.vitro.webapp.auth.identifier.UserToIndIdentifierFactory; import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.EditSubmissionPreprocessor; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ModelChangePreprocessor; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.N3Validator; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Generator; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.SparqlEvaluate; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; /** diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/Field.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/Field.java similarity index 99% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/Field.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/Field.java index 56189ddda..1c3f357fa 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/Field.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/Field.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/ModelSelector.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/ModelSelector.java similarity index 82% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/ModelSelector.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/ModelSelector.java index 3d77a041d..bc8829059 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/ModelSelector.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/ModelSelector.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/SelectListGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/SelectListGenerator.java similarity index 92% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/SelectListGenerator.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/SelectListGenerator.java index 96e38ce97..bfcb198f6 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/SelectListGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/SelectListGenerator.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration; import java.util.ArrayList; import java.util.Collections; @@ -187,8 +187,8 @@ public class SelectListGenerator { for( Individual ind : individuals ){ String uri = ind.getURI(); if( uri != null ){ - optionsMap.put(uri,ind.getName().trim()); - ++optionsCount; + optionsMap.put(uri,ind.getName().trim()); + ++optionsCount; } } @@ -212,13 +212,13 @@ public class SelectListGenerator { // individuals asserted in subclasses boolean inferenceAvailable = false; if (wDaoFact instanceof WebappDaoFactoryJena) { - PelletListener pl = ((WebappDaoFactoryJena) wDaoFact) - .getPelletListener(); - if (pl != null && pl.isConsistent() - && !pl.isInErrorState() - && !pl.isReasoning()) { - inferenceAvailable = true; - } + PelletListener pl = ((WebappDaoFactoryJena) wDaoFact) + .getPelletListener(); + if (pl != null && pl.isConsistent() + && !pl.isInErrorState() + && !pl.isReasoning()) { + inferenceAvailable = true; + } } VClass vclass = wDaoFact.getVClassDao().getVClassByURI( vclassUri ); @@ -227,41 +227,41 @@ public class SelectListGenerator { optionsMap.put("", "Could not find class " + vclassUri); }else{ Map individualMap = new HashMap(); - + for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(),-1,-1)) { - if (ind.getURI() != null) { - individualMap.put(ind.getURI(), ind); - } + if (ind.getURI() != null) { + individualMap.put(ind.getURI(), ind); + } } if (!inferenceAvailable) { - for (String subclassURI : wDaoFact.getVClassDao().getAllSubClassURIs(vclass.getURI())) { - for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(subclassURI,-1,-1)) { - if (ind.getURI() != null) { - individualMap.put(ind.getURI(), ind); - } + for (String subclassURI : wDaoFact.getVClassDao().getAllSubClassURIs(vclass.getURI())) { + for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(subclassURI,-1,-1)) { + if (ind.getURI() != null) { + individualMap.put(ind.getURI(), ind); + } } - } + } } List individuals = new ArrayList(); individuals.addAll(individualMap.values()); Collections.sort(individuals); - + for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(),-1,-1)) { - if (ind.getURI() != null) { - individualMap.put(ind.getURI(), ind); - } + if (ind.getURI() != null) { + individualMap.put(ind.getURI(), ind); + } } if (!inferenceAvailable) { - for (String subclassURI : wDaoFact.getVClassDao().getAllSubClassURIs(vclass.getURI())) { - for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(subclassURI,-1,-1)) { - if (ind.getURI() != null) { - individualMap.put(ind.getURI(), ind); - } + for (String subclassURI : wDaoFact.getVClassDao().getAllSubClassURIs(vclass.getURI())) { + for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(subclassURI,-1,-1)) { + if (ind.getURI() != null) { + individualMap.put(ind.getURI(), ind); + } } - } + } } individuals.addAll(individualMap.values()); @@ -274,8 +274,8 @@ public class SelectListGenerator { for( Individual ind : individuals ) { String uri = ind.getURI(); if( uri != null ) { - optionsMap.put(uri,ind.getName().trim()); - ++optionsCount; + optionsMap.put(uri,ind.getName().trim()); + ++optionsCount; } } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/StandardModelSelector.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/StandardModelSelector.java similarity index 94% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/StandardModelSelector.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/StandardModelSelector.java index 1313a9667..5129d2b80 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/StandardModelSelector.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/StandardModelSelector.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/StandardWDFSelector.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/StandardWDFSelector.java similarity index 90% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/StandardWDFSelector.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/StandardWDFSelector.java index df9dd6512..c5fcaaac5 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/StandardWDFSelector.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/StandardWDFSelector.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/WDFSelector.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/WDFSelector.java similarity index 83% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/WDFSelector.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/WDFSelector.java index 66a45ed4b..98c404064 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/WDFSelector.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/WDFSelector.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultPropertyFormGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultPropertyFormGenerator.java new file mode 100644 index 000000000..eff15d902 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultPropertyFormGenerator.java @@ -0,0 +1,21 @@ +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators; + +import javax.servlet.http.HttpSession; + +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; + +/** + * Generates the edit configuration for a default property form. + * + */ +public class DefaultPropertyFormGenerator implements EditConfigurationGenerator { + + @Override + public EditConfiguration getEditConfiguration(VitroRequest vreq, + HttpSession session) { + // TODO Generate a edit conf for the default object property form and return it. + return null; + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/EditConfigurationGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/EditConfigurationGenerator.java new file mode 100644 index 000000000..6beed22b8 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/EditConfigurationGenerator.java @@ -0,0 +1,10 @@ +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators; + +import javax.servlet.http.HttpSession; + +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; + +public interface EditConfigurationGenerator { + public EditConfiguration getEditConfiguration( VitroRequest vreq, HttpSession session ); +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/BaseEditSubmissionPreprocessor.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/BaseEditSubmissionPreprocessor.java similarity index 68% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/BaseEditSubmissionPreprocessor.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/BaseEditSubmissionPreprocessor.java index 124c508c7..7ae4d246e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/BaseEditSubmissionPreprocessor.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/BaseEditSubmissionPreprocessor.java @@ -1,6 +1,9 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors; + +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; + public abstract class BaseEditSubmissionPreprocessor implements EditSubmissionPreprocessor { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/CreateLabelFromNameFields.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/CreateLabelFromNameFields.java similarity index 89% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/CreateLabelFromNameFields.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/CreateLabelFromNameFields.java index 643052ca6..a6ab3e67e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/CreateLabelFromNameFields.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/CreateLabelFromNameFields.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors; import java.util.Map; @@ -11,6 +11,10 @@ import org.apache.commons.logging.LogFactory; import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.vocabulary.XSD; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission; + public class CreateLabelFromNameFields extends BaseEditSubmissionPreprocessor { private static final Log log = LogFactory.getLog(CreateLabelFromNameFields.class.getName()); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/DefaultAddMissingIndividualFormModelPreprocessor.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/DefaultAddMissingIndividualFormModelPreprocessor.java similarity index 93% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/DefaultAddMissingIndividualFormModelPreprocessor.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/DefaultAddMissingIndividualFormModelPreprocessor.java index 99c4bf57f..06fbcf9e4 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/DefaultAddMissingIndividualFormModelPreprocessor.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/DefaultAddMissingIndividualFormModelPreprocessor.java @@ -1,9 +1,12 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ResourceFactory; + + + import javax.servlet.http.HttpServletRequest; /** diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditSubmissionPreprocessor.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/EditSubmissionPreprocessor.java similarity index 53% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditSubmissionPreprocessor.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/EditSubmissionPreprocessor.java index f50d42c31..8a14c01d8 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditSubmissionPreprocessor.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/EditSubmissionPreprocessor.java @@ -1,6 +1,8 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors; + +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission; public interface EditSubmissionPreprocessor { public void preprocess(EditSubmission editSubmission); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/FoafNameToRdfsLabelPreprocessor.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/FoafNameToRdfsLabelPreprocessor.java similarity index 94% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/FoafNameToRdfsLabelPreprocessor.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/FoafNameToRdfsLabelPreprocessor.java index 512d4e80e..49e979740 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/FoafNameToRdfsLabelPreprocessor.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/FoafNameToRdfsLabelPreprocessor.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors; import javax.servlet.http.HttpServletRequest; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/ModelChangePreprocessor.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/ModelChangePreprocessor.java similarity index 79% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/ModelChangePreprocessor.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/ModelChangePreprocessor.java index fbc668a1b..89e03c517 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/ModelChangePreprocessor.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/ModelChangePreprocessor.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors; import com.hp.hpl.jena.rdf.model.Model; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/BasicValidation.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/validators/BasicValidation.java similarity index 97% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/BasicValidation.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/validators/BasicValidation.java index 596ad7f29..e2c30274b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/BasicValidation.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/validators/BasicValidation.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators; import java.util.ArrayList; import java.util.Arrays; @@ -24,6 +24,9 @@ import com.hp.hpl.jena.rdf.model.ModelFactory; import edu.cornell.mannlib.vitro.webapp.beans.Datatype; import edu.cornell.mannlib.vitro.webapp.dao.jena.DatatypeDaoJena; import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission; /** * User: bdc34 diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/DateTimeIntervalValidation.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/validators/DateTimeIntervalValidation.java similarity index 96% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/DateTimeIntervalValidation.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/validators/DateTimeIntervalValidation.java index 1d0e06e06..3954a6356 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/DateTimeIntervalValidation.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/validators/DateTimeIntervalValidation.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators; import java.util.Calendar; import java.util.HashMap; @@ -15,6 +15,8 @@ import com.hp.hpl.jena.rdf.model.Literal; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary.Precision; import edu.cornell.mannlib.vitro.webapp.edit.elements.DateTimeWithPrecision; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission; public class DateTimeIntervalValidation implements N3Validator { private static Log log = LogFactory.getLog(DateTimeIntervalValidation.class); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/validators/N3Validator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/validators/N3Validator.java new file mode 100644 index 000000000..255ffc828 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/validators/N3Validator.java @@ -0,0 +1,12 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators; + +import java.util.Map; + +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission; + +public interface N3Validator { + public Map validate(EditConfiguration editConfig, EditSubmission editSub); +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/StartDateBeforeEndDate.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/validators/StartDateBeforeEndDate.java similarity index 92% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/StartDateBeforeEndDate.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/validators/StartDateBeforeEndDate.java index 254e3b6c2..a6c4b0dc0 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/StartDateBeforeEndDate.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/validators/StartDateBeforeEndDate.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators; import java.util.Calendar; import java.util.HashMap; @@ -11,6 +11,9 @@ import org.apache.commons.logging.LogFactory; import com.hp.hpl.jena.rdf.model.Literal; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission; + public class StartDateBeforeEndDate implements N3Validator { private String startFieldName; private String endFieldName; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/StartYearBeforeEndYear.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/validators/StartYearBeforeEndYear.java similarity index 89% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/StartYearBeforeEndYear.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/validators/StartYearBeforeEndYear.java index fa5c5226f..fb7eb2df1 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/StartYearBeforeEndYear.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/validators/StartYearBeforeEndYear.java @@ -1,12 +1,15 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators; import java.util.HashMap; import java.util.Map; import com.hp.hpl.jena.rdf.model.Literal; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission; + public class StartYearBeforeEndYear implements N3Validator { private String startFieldName; private String endFieldName; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatch.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java similarity index 81% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatch.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java index 99d9a45a7..40598fc83 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatch.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java @@ -2,6 +2,9 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.controller; +import java.util.HashMap; +import java.util.Map; + import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; @@ -12,8 +15,9 @@ import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; 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.WebappDaoFactory; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils; /** @@ -26,11 +30,11 @@ import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils; * form. Try adding the behavior logic to the code that generates the * EditConfiguration for the form. */ -public class EditRequestDispatch extends FreemarkerHttpServlet { +public class EditRequestDispatchController extends FreemarkerHttpServlet { private static final long serialVersionUID = 1L; - public static Log log = LogFactory.getLog(EditRequestDispatch.class); + public static Log log = LogFactory.getLog(EditRequestDispatchController.class); - final String DEFAULT_OBJ_FORM = "defaultObjPropForm.jsp"; + final String DEFAULT_OBJ_FORM = "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultPropertyFormGenerator"; final String DEFAULT_ERROR_FORM = "error.jsp"; final String DEFAULT_ADD_INDIVIDUAL = "defaultAddMissingIndividualForm.jsp"; @Override @@ -117,15 +121,12 @@ public class EditRequestDispatch extends FreemarkerHttpServlet { // Keep track of what form we are using so it can be returned to after a failed validation // I'd like to get this from the request but sometimes that doesn't work well, internal forwards etc. - String url = "/edit/editRequestDispatch.jsp"; - vreq.setAttribute("formUrl", url + "?" + vreq.getQueryString()); - - //this are only used by the old jsp forms - vreq.setAttribute("preForm", "/edit/formPrefix.jsp"); - vreq.setAttribute("postForm", "/edit/formSuffix.jsp"); + //TODO: this needs to be the same as the mapping in web.xml + vreq.setAttribute("formUrl", "/edit/editRequest?" + vreq.getQueryString()); if ("delete".equals(command)) { - // %><% + //TODO: delete command is used with the defualt delete form + //maybe it doesn't need to be in here? return null; } @@ -138,6 +139,7 @@ public class EditRequestDispatch extends FreemarkerHttpServlet { // so maybe this logic shouldn't be here? if ( isEditOfExistingStmt && (wdf.getObjectPropertyDao().skipEditForm(predicateUri)) ) { log.debug("redirecting to object for predicate " + predicateUri); + //TODO: implement this feature // %> // // @@ -146,19 +148,15 @@ public class EditRequestDispatch extends FreemarkerHttpServlet { // <% return null; } - - String form = DEFAULT_OBJ_FORM; + //use default object property form if nothing else works + String editConfGeneratorName = DEFAULT_OBJ_FORM; // *** handle the case where the form is specified as a request parameter *** if( predicateUri == null && ( formParam != null && !formParam.isEmpty()) ){ - //case where a form was passed as a http parameter - form = formParam; - vreq.setAttribute("form", form); - //followed by - return null; + //form parameter must be a fully qualified java class name of a EditConfigurationGenerator implementation. + editConfGeneratorName = formParam; } - // *** handle the case where the form is decided by the predicate parameter *** @@ -170,34 +168,48 @@ public class EditRequestDispatch extends FreemarkerHttpServlet { ObjectProperty objectProp = wdf.getObjectPropertyDao().getObjectPropertyByURI(predicateUri); if( objectProp != null ){ vreq.setAttribute("predicate", objectProp); + //custom entry form use to be a jsp but it should now be a fully qualified java class name of a + //EditConfigurationGenerator implementation. customForm = objectProp.getCustomEntryForm(); + if (customForm != null && customForm.length() > 0) { + //if there is a custom form on the predicate, use that + editConfGeneratorName = objectProp.getCustomEntryForm(); + } } // Forward to create new is part of the default object property form // it should be handled in that form's EditConfiguration, not here. // The code that sets up the EditConfiguration should decide on - // different configurations and templates to use based on isForwardToCreateNew. + // different configurations and templates to use based on isForwardToCreateNew. + //TODO: make sure that forward to create new works on the default object property form if( isFowardToCreateNew(vreq, objectProp, command)){ return handleForwardToCreateNew(vreq, command, objectProp, isEditOfExistingStmt); } - - //Offer create new and select from existing are ignored if there is a custom form - if (customForm != null && customForm.length() > 0) { - //if there is a custom form on the predicate, use that - form = objectProp.getCustomEntryForm(); - } else { - //if it is nothing special, then use the default object property form - form = DEFAULT_OBJ_FORM ; - } - vreq.setAttribute("form", form); + + vreq.setAttribute("form", editConfGeneratorName); - // Now here we can no longer forward to a JSP. - // Somehow we need to be able to specify some java code that generates the - // EditConfiguration and the do the freemarker template merge. - - return null; + /**** make the edit configuration ***/ + EditConfiguration editConfig = makeEditConfiguration( editConfGeneratorName, vreq, session); + + //what template? + String template = editConfig.getTemplate(); + + //what goes in the map for templates? + Map templateData = new HashMap(); + templateData.put("editConfiguration", editConfig); + + return new TemplateResponseValues(editConfig.getTemplate(), templateData); } + private EditConfiguration makeEditConfiguration( + String editConfGeneratorName, VitroRequest vreq, HttpSession session) { + + //TODO: instianciate generator obj + //TODO: call getEditConfiguration() + + return null; + } + /* Forward to create new is part of the default object property form it should be handled in that form's EditConfiguration, not here. diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfForm.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfForm.java deleted file mode 100644 index 104f616bd..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfForm.java +++ /dev/null @@ -1,528 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.edit.n3editing.controller; - -import java.io.IOException; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Random; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -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.shared.Lock; - -import edu.cornell.mannlib.vitro.webapp.beans.Individual; -import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl; -import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; -import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; -import edu.cornell.mannlib.vitro.webapp.controller.freemarker.TemplateProcessingHelper.TemplateProcessingException; -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.InsertException; -import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; -import edu.cornell.mannlib.vitro.webapp.dao.jena.DependentResourceDeleteJena; -import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Generator; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Utils; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.ModelChangePreprocessor; - -/** - * This servlet will process EditConfigurations with query parameters - * to perform an edit. - * - * TODO: rename this class ProcessN3Edit - */ -public class ProcessRdfForm extends FreemarkerHttpServlet{ - - private Log log = LogFactory.getLog(ProcessRdfForm.class); - - //bdc34: this is likely to become a servlet instead of a jsp. - // You can get a reference to the servlet from the context. - // this will need to be converted from a jsp to something else - public static final String POST_EDIT_CLEANUP_JSP = "postEditCleanUp.jsp"; - - public void doPost(HttpServletRequest request, HttpServletResponse response) throws - ServletException, IOException{ - doGet(request, response); - } - - public void doGet(HttpServletRequest request, HttpServletResponse response) throws - ServletException, IOException{ - VitroRequest vreq = new VitroRequest(request); - - //get the EditConfiguration - EditConfiguration configuration = getEditConfiguration(request); - if(configuration == null){ - doEditConfigNotFound( vreq, response); - return; - } - - //get the EditSubmission - EditSubmission submission = new EditSubmission(vreq.getParameterMap(), configuration); - EditSubmission.putEditSubmissionInSession(request.getSession(), submission); - - boolean hasErrors = processValidationErrors(vreq, configuration, submission, response); - if( hasErrors) - return; //processValidationErrors() already forwarded to redisplay the form with validation messages - - // get the models to work with in case the write model and query model are not the defaults - OntModel queryModel = configuration.getQueryModelSelector().getModel(request, getServletContext()); - OntModel writeModel = configuration.getWriteModelSelector().getModel(request,getServletContext()); - - AdditionsAndRetractions changes; - if(configuration.isUpdate()){ - changes = editExistingResource(configuration, submission); - }else{ - changes = createNewResource(configuration, submission); - } - - changes = getMinimalChanges( changes ); - - if( configuration.isUseDependentResourceDelete() ) - changes = addDependentDeletes(changes, queryModel); - - preprocessModels(changes, configuration, vreq); - - applyChangesToWriteModel(changes, queryModel, writeModel, EditN3Utils.getEditorUri(vreq) ); - - //Here we are trying to get the entity to return to URL, - //Maybe this should be in POST_EDIT_CLEANUP? - if( configuration.getEntityToReturnTo() != null ){ - request.setAttribute("entityToReturnTo", substitueForURL( configuration, submission)); - } - - doPostEdit(vreq,response); - } - - /** - * Execute any modelChangePreprocessors in the editConfiguration; - * Move to EditN3Utils - */ - protected void preprocessModels(AdditionsAndRetractions changes, EditConfiguration editConfiguration, VitroRequest request){ - - List modelChangePreprocessors = editConfiguration.getModelChangePreprocessors(); - if ( modelChangePreprocessors != null ) { - for ( ModelChangePreprocessor pp : modelChangePreprocessors ) { - //these work by side effect - pp.preprocess( changes.getRetractions(), changes.getAdditions(), request ); - } - } - } - - //Move to EditN3Utils - protected AdditionsAndRetractions getMinimalChanges( AdditionsAndRetractions changes ){ - //make a model with all the assertions and a model with all the - //retractions, do a diff on those and then only add those to the jenaOntModel - Model allPossibleAssertions = changes.getAdditions(); - Model allPossibleRetractions = changes.getRetractions(); - - //find the minimal change set - Model assertions = allPossibleAssertions.difference( allPossibleRetractions ); - Model retractions = allPossibleRetractions.difference( allPossibleAssertions ); - return new AdditionsAndRetractions(assertions,retractions); - } - - protected AdditionsAndRetractions addDependentDeletes( AdditionsAndRetractions changes, Model queryModel){ - //Add retractions for dependent resource delete if that is configured and - //if there are any dependent resources. - Model depResRetractions = - DependentResourceDeleteJena - .getDependentResourceDeleteForChange(changes.getAdditions(),changes.getRetractions(),queryModel); - - changes.getRetractions().add(depResRetractions); - return changes; - } - - - protected void applyChangesToWriteModel(AdditionsAndRetractions changes, OntModel queryModel, OntModel writeModel, String editorUri) { - //side effect: modify the write model with the changes - Lock lock = null; - try{ - lock = writeModel.getLock(); - lock.enterCriticalSection(Lock.WRITE); - writeModel.getBaseModel().notifyEvent(new EditEvent(editorUri,true)); - writeModel.add( changes.getAdditions() ); - writeModel.remove( changes.getRetractions() ); - }catch(Throwable t){ - log.error("error adding edit change n3required model to in memory model \n"+ t.getMessage() ); - }finally{ - writeModel.getBaseModel().notifyEvent(new EditEvent(editorUri,false)); - lock.leaveCriticalSection(); - } - } - - private EditConfiguration getEditConfiguration(HttpServletRequest request) { - HttpSession session = request.getSession(); - EditConfiguration editConfiguration = EditConfiguration.getConfigFromSession(session, request); - return editConfiguration; - } - - @SuppressWarnings("static-access") - private AdditionsAndRetractions createNewResource(EditConfiguration editConfiguration , EditSubmission submission){ - List errorMessages = new ArrayList(); - - EditN3Generator n3Subber = editConfiguration.getN3Generator(); - - if(log.isDebugEnabled()){ - log.debug("creating a new relation " + editConfiguration.getPredicateUri()); - } - - //handle creation of a new object property and maybe a resource - List n3Required = editConfiguration.getN3Required(); - List n3Optional = editConfiguration.getN3Optional(); - - /* ********** URIs and Literals on Form/Parameters *********** */ - //sub in resource uris off form - n3Required = n3Subber.subInUris(submission.getUrisFromForm(), n3Required); - n3Optional = n3Subber.subInUris(submission.getUrisFromForm(), n3Optional); - if(log.isDebugEnabled()) { - Utilities.logRequiredOpt("substituted in URIs off from ",n3Required,n3Optional); - } - - //sub in literals from form - n3Required = n3Subber.subInLiterals(submission.getLiteralsFromForm(), n3Required); - n3Optional = n3Subber.subInLiterals(submission.getLiteralsFromForm(), n3Optional); - if(log.isDebugEnabled()) { - Utilities.logRequiredOpt("substituted in literals off from ",n3Required,n3Optional); - } - - /* ****************** URIs and Literals in Scope ************** */ - n3Required = n3Subber.subInUris( editConfiguration.getUrisInScope(), n3Required); - n3Optional = n3Subber.subInUris( editConfiguration.getUrisInScope(), n3Optional); - if(log.isDebugEnabled()) { - Utilities.logRequiredOpt("substituted in URIs from scope ",n3Required,n3Optional); - } - - n3Required = n3Subber.subInLiterals( editConfiguration.getLiteralsInScope(), n3Required); - n3Optional = n3Subber.subInLiterals( editConfiguration.getLiteralsInScope(), n3Optional); - if(log.isDebugEnabled()) { - Utilities.logRequiredOpt("substituted in Literals from scope ",n3Required,n3Optional); - } - - //deal with required N3 - List requiredNewModels = new ArrayList(); - for(String n3 : n3Required){ - try{ - Model model = ModelFactory.createDefaultModel(); - StringReader reader = new StringReader(n3); - model.read(reader, "", "N3"); - requiredNewModels.add(model); - } catch(Throwable t){ - errorMessages.add("error processing required n3 string \n" + t.getMessage() + '\n' + "n3: \n" + n3); - } - } - - if(!errorMessages.isEmpty()){ - String error = "problems processing required n3: \n"; - for(String errorMsg: errorMessages){ - error += errorMsg + '\n'; - } - if(log.isDebugEnabled()){ - log.debug(error); - } - } - List requiredAssertions = requiredNewModels; - - //deal with optional N3 - List optionalNewModels = new ArrayList(); - for(String n3 : n3Optional){ - try{ - Model model = ModelFactory.createDefaultModel(); - StringReader reader = new StringReader(n3); - model.read(reader, "", "N3"); - optionalNewModels.add(model); - }catch(Throwable t){ - //if an optional N3 block fails to parse it will be ignored - //this is what is meant by optional. - } - } - requiredAssertions.addAll( optionalNewModels ); - - return new AdditionsAndRetractions(requiredAssertions, Collections.emptyList()); - } - - @SuppressWarnings("static-access") - private AdditionsAndRetractions editExistingResource(EditConfiguration editConfiguration, EditSubmission submission) { - - Map> fieldAssertions = Utilities.fieldsToAssertionMap(editConfiguration.getFields()); - Map> fieldRetractions = Utilities.fieldsToRetractionMap(editConfiguration.getFields()); - EditN3Generator n3Subber = editConfiguration.getN3Generator(); - - /* ********** URIs and Literals on Form/Parameters *********** */ - fieldAssertions = n3Subber.substituteIntoValues(submission.getUrisFromForm(), submission.getLiteralsFromForm(), fieldAssertions); - if(log.isDebugEnabled()) { - Utilities.logAddRetract("substituted in literals from form",fieldAssertions,fieldRetractions); - } - - /* ****************** URIs and Literals in Scope ************** */ - fieldAssertions = n3Subber.substituteIntoValues(editConfiguration.getUrisInScope(), editConfiguration.getLiteralsInScope(), fieldAssertions ); - fieldRetractions = n3Subber.substituteIntoValues(editConfiguration.getUrisInScope(), editConfiguration.getLiteralsInScope(), fieldRetractions); - if(log.isDebugEnabled()) { - Utilities.logAddRetract("substituted in URIs and Literals from scope",fieldAssertions,fieldRetractions); - } - - //do edits ever need new resources? (YES) -/* Map varToNewResource = newToUriMap(editConfiguration.getNewResources(),wdf); - fieldAssertions = n3Subber.substituteIntoValues(varToNewResource, null, fieldAssertions); - if(log.isDebugEnabled()) { - Utilities.logAddRetract("substituted in URIs for new resources",fieldAssertions,fieldRetractions); - } - entToReturnTo = n3Subber.subInUris(varToNewResource,entToReturnTo); -*/ - //editing an existing statement - List requiredFieldAssertions = new ArrayList(); - List requiredFieldRetractions = new ArrayList(); - - List errorMessages = new ArrayList(); - - for(String fieldName : fieldAssertions.keySet()){ - List assertions = fieldAssertions.get(fieldName); - List retractions = fieldRetractions.get(fieldName); - - for(String n3: assertions){ - try{ - Model model = ModelFactory.createDefaultModel(); - StringReader reader = new StringReader(n3); - model.read(reader, "", "N3"); - }catch(Throwable t){ - String errMsg = "error processing N3 assertion string from field " + fieldName + "\n" + - t.getMessage() + '\n' + "n3: \n" + n3; - errorMessages.add(errMsg); - if(log.isDebugEnabled()){ - log.debug(errMsg); - } - } - } - - for(String n3 : retractions){ - try{ - Model model = ModelFactory.createDefaultModel(); - StringReader reader = new StringReader(n3); - model.read(reader, "", "N3"); - requiredFieldRetractions.add(model); - }catch(Throwable t){ - String errMsg = "error processing N3 retraction string from field " + fieldName + "\n"+ - t.getMessage() + '\n' + "n3: \n" + n3; - errorMessages.add(errMsg); - if(log.isDebugEnabled()){ - log.debug(errMsg); - } - } - } - } - - return new AdditionsAndRetractions(requiredFieldAssertions, requiredFieldRetractions); - } - - private void doEditConfigNotFound(VitroRequest request, HttpServletResponse response) { - HashMapmap = new HashMap(); - map.put("message", "No editing configuration found, cannot process edit."); - ResponseValues values = new TemplateResponseValues("message.ftl", map); - try { - doResponse(request,response,values); - } catch (TemplateProcessingException e) { - log.error("Could not process template for doEditConfigNotFound()",e); - } - } - - private boolean processValidationErrors(VitroRequest vreq, - EditConfiguration editConfiguration, EditSubmission submission, - HttpServletResponse response) throws ServletException, IOException { - - Map errors = submission.getValidationErrors(); - - if(errors != null && !errors.isEmpty()){ - String form = editConfiguration.getFormUrl(); - vreq.setAttribute("formUrl", form); - vreq.setAttribute("view", vreq.getParameter("view")); - - RequestDispatcher requestDispatcher = vreq.getRequestDispatcher(editConfiguration.getFormUrl()); - requestDispatcher.forward(vreq, response); - return true; - } - return false; - } - - private void doPostEdit(VitroRequest vreq, HttpServletResponse response) throws ServletException, IOException { - RequestDispatcher requestDispatcher = vreq.getRequestDispatcher(POST_EDIT_CLEANUP_JSP); - requestDispatcher.forward(vreq, response); - } - - //Move to EditN3Utils but keep make new uris here - public static class Utilities { - - private static Log log = LogFactory.getLog(ProcessRdfForm.class); - static Random random = new Random(); - - public static Map> fieldsToAssertionMap( Map fields){ - Map> out = new HashMap>(); - for( String fieldName : fields.keySet()){ - Field field = fields.get(fieldName); - - List copyOfN3 = new ArrayList(); - for( String str : field.getAssertions()){ - copyOfN3.add(str); - } - out.put( fieldName, copyOfN3 ); - } - return out; - } - - public static Map> fieldsToRetractionMap( Map fields){ - Map> out = new HashMap>(); - for( String fieldName : fields.keySet()){ - Field field = fields.get(fieldName); - - List copyOfN3 = new ArrayList(); - for( String str : field.getRetractions()){ - copyOfN3.add(str); - } - out.put( fieldName, copyOfN3 ); - } - return out; - } - - public static Map newToUriMap(Map newResources, WebappDaoFactory wdf){ - HashMap newVarsToUris = new HashMap(); - HashSet newUris = new HashSet(); - for( String key : newResources.keySet()){ - String prefix = newResources.get(key); - String uri = makeNewUri(prefix, wdf); - while( newUris.contains(uri) ){ - uri = makeNewUri(prefix,wdf); - } - newVarsToUris.put(key,uri); - newUris.add(uri); - } - return newVarsToUris; - } - - - public static String makeNewUri(String prefix, WebappDaoFactory wdf){ - if( prefix == null || prefix.length() == 0 ){ - String uri = null; - try{ - uri = wdf.getIndividualDao().getUnusedURI(null); - }catch(InsertException ex){ - log.error("could not create uri"); - } - return uri; - } - - String goodURI = null; - int attempts = 0; - while( goodURI == null && attempts < 30 ){ - Individual ind = new IndividualImpl(); - ind.setURI( prefix + random.nextInt() ); - try{ - goodURI = wdf.getIndividualDao().getUnusedURI(ind); - }catch(InsertException ex){ - log.debug("could not create uri"); - } - attempts++; - } - if( goodURI == null ) - log.error("could not create uri for prefix " + prefix); - return goodURI; - - } - - private static boolean logAddRetract(String msg, Map>add, Map>retract){ - log.debug(msg); - if( add != null ) log.debug( "assertions: " + add.toString() ); - if( retract != null ) log.debug( "retractions: " + retract.toString() ); - return true; - } - - private static boolean logRequiredOpt(String msg, Listrequired, Listoptional){ - log.debug(msg); - if( required != null ) log.debug( "required: " + required.toString() ); - if( optional != null ) log.debug( "optional: " + optional.toString() ); - return true; - } - - } - - /** - * This is intended to substitute vars from the EditConfiguration and - * EditSubmission into the URL to return to. - */ - protected String substitueForURL(EditConfiguration configuration, EditSubmission submission){ - - List entToReturnTo = new ArrayList(1); - entToReturnTo.add(configuration.getEntityToReturnTo()); - - EditN3Generator n3Subber = configuration.getN3Generator(); - // Substitute in URIs from the submission - entToReturnTo = n3Subber.subInUris(submission.getUrisFromForm(), entToReturnTo); - - // Substitute in URIs from the scope of the EditConfiguration - entToReturnTo = n3Subber.subInUris(configuration.getUrisInScope(), entToReturnTo); - - //The problem is that subInURI will add < and > around URIs for the N3 syntax. - //for the URL to return to, replace < and > from URI additions. - return entToReturnTo.get(0).trim().replaceAll("<","").replaceAll(">",""); - } - - /** - * This is a data structure to allow a method to return - * a pair of Model objects for additions and retractions. - * - * Move this to its own class - */ - protected class AdditionsAndRetractions { - Model additions; - Model retractions; - - public AdditionsAndRetractions(Listadds, Listretractions){ - Model allAdds = ModelFactory.createDefaultModel(); - Model allRetractions = ModelFactory.createDefaultModel(); - - for( Model model : adds ) { - allAdds.add( model ); - } - for( Model model : retractions ){ - allRetractions.add( model ); - } - - this.setAdditions(allAdds); - this.setRetractions(allRetractions); - } - - public AdditionsAndRetractions(Model add, Model retract){ - this.additions = add; - this.retractions = retract; - } - - public Model getAdditions() { - return additions; - } - public void setAdditions(Model additions) { - this.additions = additions; - } - public Model getRetractions() { - return retractions; - } - public void setRetractions(Model retractions) { - this.retractions = retractions; - } - } -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java new file mode 100644 index 000000000..14b1d10af --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java @@ -0,0 +1,227 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.controller; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Random; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.hp.hpl.jena.ontology.OntModel; + +import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; +import edu.cornell.mannlib.vitro.webapp.controller.freemarker.TemplateProcessingHelper.TemplateProcessingException; +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.InsertException; +import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.AdditionsAndRetractions; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.ProcessRdfForm; + +/** + * This servlet will process EditConfigurations with query parameters + * to perform an edit. + * + * TODO: rename this class ProcessN3Edit + */ +public class ProcessRdfFormController extends FreemarkerHttpServlet{ + + private Log log = LogFactory.getLog(ProcessRdfFormController.class); + + + //bdc34: this is likely to become a servlet instead of a jsp. + // You can get a reference to the servlet from the context. + // this will need to be converted from a jsp to something else + public static final String POST_EDIT_CLEANUP_JSP = "postEditCleanUp.jsp"; + + public void doPost(HttpServletRequest request, HttpServletResponse response) throws + ServletException, IOException{ + doGet(request, response); + } + + public void doGet(HttpServletRequest request, HttpServletResponse response) throws + ServletException, IOException{ + VitroRequest vreq = new VitroRequest(request); + + //get the EditConfiguration + EditConfiguration configuration = getEditConfiguration(request); + if(configuration == null){ + doEditConfigNotFound( vreq, response); + return; + } + + //get the EditSubmission + EditSubmission submission = new EditSubmission(vreq.getParameterMap(), configuration); + EditSubmission.putEditSubmissionInSession(request.getSession(), submission); + + boolean hasErrors = doValidationErrors(vreq, configuration, submission, response); + if( hasErrors) + return; //processValidationErrors() already forwarded to redisplay the form with validation messages + + // get the models to work with in case the write model and query model are not the defaults + OntModel queryModel = configuration.getQueryModelSelector().getModel(request, getServletContext()); + OntModel writeModel = configuration.getWriteModelSelector().getModel(request,getServletContext()); + + AdditionsAndRetractions changes; + if(configuration.isUpdate()){ + changes = ProcessRdfForm.editExistingResource(configuration, submission); + }else{ + changes = ProcessRdfForm.createNewResource(configuration, submission); + } + + if( configuration.isUseDependentResourceDelete() ) + changes = ProcessRdfForm.addDependentDeletes(changes, queryModel); + + ProcessRdfForm.preprocessModels(changes, configuration, vreq); + + ProcessRdfForm.applyChangesToWriteModel(changes, queryModel, writeModel, EditN3Utils.getEditorUri(vreq) ); + + //Here we are trying to get the entity to return to URL, + //Maybe this should be in POST_EDIT_CLEANUP? + if( configuration.getEntityToReturnTo() != null ){ + request.setAttribute("entityToReturnTo", ProcessRdfForm.substitueForURL( configuration, submission)); + } + + doPostEdit(vreq,response); + } + private EditConfiguration getEditConfiguration(HttpServletRequest request) { + HttpSession session = request.getSession(); + EditConfiguration editConfiguration = EditConfiguration.getConfigFromSession(session, request); + return editConfiguration; + } + private void doEditConfigNotFound(VitroRequest request, HttpServletResponse response) { + HashMapmap = new HashMap(); + map.put("message", "No editing configuration found, cannot process edit."); + ResponseValues values = new TemplateResponseValues("message.ftl", map); + try { + doResponse(request,response,values); + } catch (TemplateProcessingException e) { + log.error("Could not process template for doEditConfigNotFound()",e); + } + } + + private boolean doValidationErrors(VitroRequest vreq, + EditConfiguration editConfiguration, EditSubmission submission, + HttpServletResponse response) throws ServletException, IOException { + + Map errors = submission.getValidationErrors(); + + if(errors != null && !errors.isEmpty()){ + String form = editConfiguration.getFormUrl(); + vreq.setAttribute("formUrl", form); + vreq.setAttribute("view", vreq.getParameter("view")); + + RequestDispatcher requestDispatcher = vreq.getRequestDispatcher(editConfiguration.getFormUrl()); + requestDispatcher.forward(vreq, response); + return true; + } + return false; + } + + private void doPostEdit(VitroRequest vreq, HttpServletResponse response) throws ServletException, IOException { + RequestDispatcher requestDispatcher = vreq.getRequestDispatcher(POST_EDIT_CLEANUP_JSP); + requestDispatcher.forward(vreq, response); + } + + //Move to EditN3Utils but keep make new uris here + public static class Utilities { + + private static Log log = LogFactory.getLog(ProcessRdfFormController.class); + static Random random = new Random(); + + public static Map> fieldsToAssertionMap( Map fields){ + Map> out = new HashMap>(); + for( String fieldName : fields.keySet()){ + Field field = fields.get(fieldName); + + List copyOfN3 = new ArrayList(); + for( String str : field.getAssertions()){ + copyOfN3.add(str); + } + out.put( fieldName, copyOfN3 ); + } + return out; + } + + public static Map> fieldsToRetractionMap( Map fields){ + Map> out = new HashMap>(); + for( String fieldName : fields.keySet()){ + Field field = fields.get(fieldName); + + List copyOfN3 = new ArrayList(); + for( String str : field.getRetractions()){ + copyOfN3.add(str); + } + out.put( fieldName, copyOfN3 ); + } + return out; + } + + public static Map newToUriMap(Map newResources, WebappDaoFactory wdf){ + HashMap newVarsToUris = new HashMap(); + HashSet newUris = new HashSet(); + for( String key : newResources.keySet()){ + String prefix = newResources.get(key); + String uri = makeNewUri(prefix, wdf); + while( newUris.contains(uri) ){ + uri = makeNewUri(prefix,wdf); + } + newVarsToUris.put(key,uri); + newUris.add(uri); + } + return newVarsToUris; + } + + + public static String makeNewUri(String prefix, WebappDaoFactory wdf){ + if( prefix == null || prefix.length() == 0 ){ + String uri = null; + try{ + uri = wdf.getIndividualDao().getUnusedURI(null); + }catch(InsertException ex){ + log.error("could not create uri"); + } + return uri; + } + + String goodURI = null; + int attempts = 0; + while( goodURI == null && attempts < 30 ){ + Individual ind = new IndividualImpl(); + ind.setURI( prefix + random.nextInt() ); + try{ + goodURI = wdf.getIndividualDao().getUnusedURI(ind); + }catch(InsertException ex){ + log.debug("could not create uri"); + } + attempts++; + } + if( goodURI == null ) + log.error("could not create uri for prefix " + prefix); + return goodURI; + + } + + + + } +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/AdditionsAndRetractions.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/AdditionsAndRetractions.java new file mode 100644 index 000000000..2f3e6b36b --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/AdditionsAndRetractions.java @@ -0,0 +1,52 @@ +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit; + +import java.util.List; +import java.util.Map; + +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; + +/** + * This is a data structure to allow a method to return + * a pair of Model objects for additions and retractions. + * + * Move this to its own class + */ +public class AdditionsAndRetractions { + Model additions; + Model retractions; + + public AdditionsAndRetractions(Listadds, Listretractions){ + Model allAdds = ModelFactory.createDefaultModel(); + Model allRetractions = ModelFactory.createDefaultModel(); + + for( Model model : adds ) { + allAdds.add( model ); + } + for( Model model : retractions ){ + allRetractions.add( model ); + } + + this.setAdditions(allAdds); + this.setRetractions(allRetractions); + } + + public AdditionsAndRetractions(Model add, Model retract){ + this.additions = add; + this.retractions = retract; + } + + public Model getAdditions() { + return additions; + } + public void setAdditions(Model additions) { + this.additions = additions; + } + public Model getRetractions() { + return retractions; + } + public void setRetractions(Model retractions) { + this.retractions = retractions; + } + +} \ No newline at end of file diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3Generator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/EditN3Generator.java similarity index 98% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3Generator.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/EditN3Generator.java index a040b72ff..b2bc6cfad 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3Generator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/EditN3Generator.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit; import java.math.BigDecimal; import java.util.ArrayList; @@ -19,6 +19,8 @@ import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.vocabulary.XSD; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; + /** * Builds the N3 strings for the given EditConfiguration, model * and EditSubmission. Main responsibility is the proper substitution @@ -107,7 +109,7 @@ public class EditN3Generator { * references, Matcher.quoteReplacement() serves the purpose. * */ - protected String subInLiterals(String var, Literal literal, String target){ + public String subInLiterals(String var, Literal literal, String target){ String varRegex = "\\?" + var + "(?=\\.\\p{Space}|\\p{Space})"; if (target==null ) { log.error("subInLiterals was passed a null target"); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3Utils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/EditN3Utils.java similarity index 81% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3Utils.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/EditN3Utils.java index dd74eab29..031ea158f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3Utils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/EditN3Utils.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit; import java.util.ArrayList; import java.util.List; @@ -16,18 +16,17 @@ import edu.cornell.mannlib.vitro.webapp.auth.identifier.IsUser; import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers; public class EditN3Utils { + /** Several places could give an editor URI. Return the first one. */ + public static String getEditorUri(HttpServletRequest request) { + IdentifierBundle ids = RequestIdentifiers.getIdBundleForRequest(request); - /** Several places could give an editor URI. Return the first one. */ - public static String getEditorUri(HttpServletRequest request) { - IdentifierBundle ids = RequestIdentifiers.getIdBundleForRequest(request); - - List uris = new ArrayList(); - uris.addAll(IsUser.getUserUris(ids)); - uris.addAll(HasAssociatedIndividual.getIndividualUris(ids)); - uris.addAll(HasRoleLevel.getRoleLevelUris(ids)); - uris.add("Unknown N3 Editor"); - return uris.get(0); - } + List uris = new ArrayList(); + uris.addAll(IsUser.getUserUris(ids)); + uris.addAll(HasAssociatedIndividual.getIndividualUris(ids)); + uris.addAll(HasRoleLevel.getRoleLevelUris(ids)); + uris.add("Unknown N3 Editor"); + return uris.get(0); + } /** * Strips from a string any characters that are not valid in XML 1.0 diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditSubmission.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/EditSubmission.java similarity index 97% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditSubmission.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/EditSubmission.java index 095964fd8..61ed8e286 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditSubmission.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/EditSubmission.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -29,6 +29,10 @@ import com.hp.hpl.jena.vocabulary.XSD; import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral; import edu.cornell.mannlib.vitro.webapp.edit.elements.EditElement; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.BasicValidation; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.N3Validator; public class EditSubmission { private String editKey; @@ -209,7 +213,7 @@ public class EditSubmission { validationErrors.putAll(this.basicValidation.validateFiles( fileItems ) ); } - protected Literal createLiteral(String value, String datatypeUri, String lang) { + public Literal createLiteral(String value, String datatypeUri, String lang) { if( datatypeUri != null ){ if( "http://www.w3.org/2001/XMLSchema:anyURI".equals(datatypeUri) ){ try { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/ProcessRdfForm.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/ProcessRdfForm.java new file mode 100644 index 000000000..21cc34314 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/ProcessRdfForm.java @@ -0,0 +1,277 @@ +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit; + +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +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.shared.Lock; + +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.dao.jena.DependentResourceDeleteJena; +import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ModelChangePreprocessor; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.controller.ProcessRdfFormController.Utilities; + +public class ProcessRdfForm { + + private static Log log = LogFactory.getLog(ProcessRdfForm.class); + + /** + * Execute any modelChangePreprocessors in the editConfiguration; + * + */ + public static void preprocessModels(AdditionsAndRetractions changes, EditConfiguration editConfiguration, VitroRequest request){ + + List modelChangePreprocessors = editConfiguration.getModelChangePreprocessors(); + if ( modelChangePreprocessors != null ) { + for ( ModelChangePreprocessor pp : modelChangePreprocessors ) { + //these work by side effect + pp.preprocess( changes.getRetractions(), changes.getAdditions(), request ); + } + } + } + + protected static AdditionsAndRetractions getMinimalChanges( AdditionsAndRetractions changes ){ + //make a model with all the assertions and a model with all the + //retractions, do a diff on those and then only add those to the jenaOntModel + Model allPossibleAssertions = changes.getAdditions(); + Model allPossibleRetractions = changes.getRetractions(); + + //find the minimal change set + Model assertions = allPossibleAssertions.difference( allPossibleRetractions ); + Model retractions = allPossibleRetractions.difference( allPossibleAssertions ); + return new AdditionsAndRetractions(assertions,retractions); + } + + public static AdditionsAndRetractions addDependentDeletes( AdditionsAndRetractions changes, Model queryModel){ + //Add retractions for dependent resource delete if that is configured and + //if there are any dependent resources. + Model depResRetractions = + DependentResourceDeleteJena + .getDependentResourceDeleteForChange(changes.getAdditions(),changes.getRetractions(),queryModel); + + changes.getRetractions().add(depResRetractions); + return changes; + } + + + public static void applyChangesToWriteModel(AdditionsAndRetractions changes, OntModel queryModel, OntModel writeModel, String editorUri) { + //side effect: modify the write model with the changes + Lock lock = null; + try{ + lock = writeModel.getLock(); + lock.enterCriticalSection(Lock.WRITE); + writeModel.getBaseModel().notifyEvent(new EditEvent(editorUri,true)); + writeModel.add( changes.getAdditions() ); + writeModel.remove( changes.getRetractions() ); + }catch(Throwable t){ + log.error("error adding edit change n3required model to in memory model \n"+ t.getMessage() ); + }finally{ + writeModel.getBaseModel().notifyEvent(new EditEvent(editorUri,false)); + lock.leaveCriticalSection(); + } + } + + + @SuppressWarnings("static-access") + public static AdditionsAndRetractions createNewResource(EditConfiguration editConfiguration , EditSubmission submission){ + List errorMessages = new ArrayList(); + + EditN3Generator n3Subber = editConfiguration.getN3Generator(); + + if(log.isDebugEnabled()){ + log.debug("creating a new relation " + editConfiguration.getPredicateUri()); + } + + //handle creation of a new object property and maybe a resource + List n3Required = editConfiguration.getN3Required(); + List n3Optional = editConfiguration.getN3Optional(); + + /* ********** URIs and Literals on Form/Parameters *********** */ + //sub in resource uris off form + n3Required = n3Subber.subInUris(submission.getUrisFromForm(), n3Required); + n3Optional = n3Subber.subInUris(submission.getUrisFromForm(), n3Optional); + if(log.isDebugEnabled()) { + logRequiredOpt("substituted in URIs off from ",n3Required,n3Optional); + } + + //sub in literals from form + n3Required = n3Subber.subInLiterals(submission.getLiteralsFromForm(), n3Required); + n3Optional = n3Subber.subInLiterals(submission.getLiteralsFromForm(), n3Optional); + if(log.isDebugEnabled()) { + logRequiredOpt("substituted in literals off from ",n3Required,n3Optional); + } + + /* ****************** URIs and Literals in Scope ************** */ + n3Required = n3Subber.subInUris( editConfiguration.getUrisInScope(), n3Required); + n3Optional = n3Subber.subInUris( editConfiguration.getUrisInScope(), n3Optional); + if(log.isDebugEnabled()) { + logRequiredOpt("substituted in URIs from scope ",n3Required,n3Optional); + } + + n3Required = n3Subber.subInLiterals( editConfiguration.getLiteralsInScope(), n3Required); + n3Optional = n3Subber.subInLiterals( editConfiguration.getLiteralsInScope(), n3Optional); + if(log.isDebugEnabled()) { + logRequiredOpt("substituted in Literals from scope ",n3Required,n3Optional); + } + + //deal with required N3 + List requiredNewModels = new ArrayList(); + for(String n3 : n3Required){ + try{ + Model model = ModelFactory.createDefaultModel(); + StringReader reader = new StringReader(n3); + model.read(reader, "", "N3"); + requiredNewModels.add(model); + } catch(Throwable t){ + errorMessages.add("error processing required n3 string \n" + t.getMessage() + '\n' + "n3: \n" + n3); + } + } + + if(!errorMessages.isEmpty()){ + String error = "problems processing required n3: \n"; + for(String errorMsg: errorMessages){ + error += errorMsg + '\n'; + } + if(log.isDebugEnabled()){ + log.debug(error); + } + } + List requiredAssertions = requiredNewModels; + + //deal with optional N3 + List optionalNewModels = new ArrayList(); + for(String n3 : n3Optional){ + try{ + Model model = ModelFactory.createDefaultModel(); + StringReader reader = new StringReader(n3); + model.read(reader, "", "N3"); + optionalNewModels.add(model); + }catch(Throwable t){ + //if an optional N3 block fails to parse it will be ignored + //this is what is meant by optional. + } + } + requiredAssertions.addAll( optionalNewModels ); + + return getMinimalChanges(new AdditionsAndRetractions(requiredAssertions, Collections.emptyList())); + } + + @SuppressWarnings("static-access") + public static AdditionsAndRetractions editExistingResource(EditConfiguration editConfiguration, EditSubmission submission) { + + Map> fieldAssertions = Utilities.fieldsToAssertionMap(editConfiguration.getFields()); + Map> fieldRetractions = Utilities.fieldsToRetractionMap(editConfiguration.getFields()); + EditN3Generator n3Subber = editConfiguration.getN3Generator(); + + /* ********** URIs and Literals on Form/Parameters *********** */ + fieldAssertions = n3Subber.substituteIntoValues(submission.getUrisFromForm(), submission.getLiteralsFromForm(), fieldAssertions); + if(log.isDebugEnabled()) { + logAddRetract("substituted in literals from form",fieldAssertions,fieldRetractions); + } + + /* ****************** URIs and Literals in Scope ************** */ + fieldAssertions = n3Subber.substituteIntoValues(editConfiguration.getUrisInScope(), editConfiguration.getLiteralsInScope(), fieldAssertions ); + fieldRetractions = n3Subber.substituteIntoValues(editConfiguration.getUrisInScope(), editConfiguration.getLiteralsInScope(), fieldRetractions); + if(log.isDebugEnabled()) { + logAddRetract("substituted in URIs and Literals from scope",fieldAssertions,fieldRetractions); + } + + //do edits ever need new resources? (YES) +/* Map varToNewResource = newToUriMap(editConfiguration.getNewResources(),wdf); + fieldAssertions = n3Subber.substituteIntoValues(varToNewResource, null, fieldAssertions); + if(log.isDebugEnabled()) { + Utilities.logAddRetract("substituted in URIs for new resources",fieldAssertions,fieldRetractions); + } + entToReturnTo = n3Subber.subInUris(varToNewResource,entToReturnTo); +*/ + //editing an existing statement + List requiredFieldAssertions = new ArrayList(); + List requiredFieldRetractions = new ArrayList(); + + List errorMessages = new ArrayList(); + + for(String fieldName : fieldAssertions.keySet()){ + List assertions = fieldAssertions.get(fieldName); + List retractions = fieldRetractions.get(fieldName); + + for(String n3: assertions){ + try{ + Model model = ModelFactory.createDefaultModel(); + StringReader reader = new StringReader(n3); + model.read(reader, "", "N3"); + }catch(Throwable t){ + String errMsg = "error processing N3 assertion string from field " + fieldName + "\n" + + t.getMessage() + '\n' + "n3: \n" + n3; + errorMessages.add(errMsg); + if(log.isDebugEnabled()){ + log.debug(errMsg); + } + } + } + + for(String n3 : retractions){ + try{ + Model model = ModelFactory.createDefaultModel(); + StringReader reader = new StringReader(n3); + model.read(reader, "", "N3"); + requiredFieldRetractions.add(model); + }catch(Throwable t){ + String errMsg = "error processing N3 retraction string from field " + fieldName + "\n"+ + t.getMessage() + '\n' + "n3: \n" + n3; + errorMessages.add(errMsg); + if(log.isDebugEnabled()){ + log.debug(errMsg); + } + } + } + } + + return getMinimalChanges(new AdditionsAndRetractions(requiredFieldAssertions, requiredFieldRetractions)); + } + + + /** + * This is intended to substitute vars from the EditConfiguration and + * EditSubmission into the URL to return to. + */ + public static String substitueForURL(EditConfiguration configuration, EditSubmission submission){ + + List entToReturnTo = new ArrayList(1); + entToReturnTo.add(configuration.getEntityToReturnTo()); + + EditN3Generator n3Subber = configuration.getN3Generator(); + // Substitute in URIs from the submission + entToReturnTo = n3Subber.subInUris(submission.getUrisFromForm(), entToReturnTo); + + // Substitute in URIs from the scope of the EditConfiguration + entToReturnTo = n3Subber.subInUris(configuration.getUrisInScope(), entToReturnTo); + + //The problem is that subInURI will add < and > around URIs for the N3 syntax. + //for the URL to return to, replace < and > from URI additions. + return entToReturnTo.get(0).trim().replaceAll("<","").replaceAll(">",""); + } + + private static boolean logAddRetract(String msg, Map>add, Map>retract){ + log.debug(msg); + if( add != null ) log.debug( "assertions: " + add.toString() ); + if( retract != null ) log.debug( "retractions: " + retract.toString() ); + return true; + } + + private static boolean logRequiredOpt(String msg, Listrequired, Listoptional){ + log.debug(msg); + if( required != null ) log.debug( "required: " + required.toString() ); + if( optional != null ) log.debug( "optional: " + optional.toString() ); + return true; + } +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHash.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/RdfLiteralHash.java similarity index 99% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHash.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/RdfLiteralHash.java index 5109d39ba..e46aab8b2 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHash.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/RdfLiteralHash.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit; import java.util.List; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/SparqlEvaluate.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/SparqlEvaluate.java similarity index 94% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/SparqlEvaluate.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/SparqlEvaluate.java index 3e03e0541..fde47f7db 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/SparqlEvaluate.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/SparqlEvaluate.java @@ -1,10 +1,13 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit; import com.hp.hpl.jena.query.*; import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.Resource; + +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -82,7 +85,7 @@ public class SparqlEvaluate { // return varToUris; // } - protected Map sparqlEvaluateForLiterals( EditConfiguration editConfig, Map varToSparql) { + public Map sparqlEvaluateForLiterals( EditConfiguration editConfig, Map varToSparql) { Map uriScope = editConfig.getUrisInScope(); Map literalScope = editConfig.getLiteralsInScope(); @@ -104,7 +107,7 @@ public class SparqlEvaluate { return varToLiterals; } - protected Map sparqlEvaluateForUris( EditConfiguration editConfig, MapvarToSparql) { + public Map sparqlEvaluateForUris( EditConfiguration editConfig, MapvarToSparql) { Map uriScope = editConfig.getUrisInScope(); Map literalScope = editConfig.getLiteralsInScope(); @@ -133,7 +136,7 @@ public class SparqlEvaluate { return varToUris; } -// protected Map sparqlEvaluateForAdditionalLiterals( EditConfiguration editConfig) { +// public Map sparqlEvaluateForAdditionalLiterals( EditConfiguration editConfig) { // Map varToSpqrql = editConfig.getSparqlForAdditionalLiteralsInScope(); // Map uriScope = editConfig.getUrisInScope(); // Map literalScope = editConfig.getLiteralsInScope(); @@ -156,7 +159,7 @@ public class SparqlEvaluate { // return varToLiterals; // } - protected String queryToUri(String querystr){ + public String queryToUri(String querystr){ String value = null; QueryExecution qe = null; try{ @@ -192,7 +195,7 @@ public class SparqlEvaluate { } - protected Literal queryToLiteral(String querystr){ + public Literal queryToLiteral(String querystr){ Literal value = null; QueryExecution qe = null; try{ diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/ErrorMessage.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/ErrorMessage.java index 786bbb262..092b9b2d2 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/ErrorMessage.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/ErrorMessage.java @@ -2,8 +2,8 @@ package edu.cornell.mannlib.vitro.webapp.web.jsptags; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/InputElementFormattingTag.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/InputElementFormattingTag.java index efd101ddf..ac110d4d6 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/InputElementFormattingTag.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/InputElementFormattingTag.java @@ -43,10 +43,10 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfigurationLoader; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.SelectListGenerator; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.SelectListGenerator; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; import freemarker.template.Configuration; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/Options.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/Options.java index 2f9d59993..848503cec 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/Options.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/Options.java @@ -2,18 +2,7 @@ package edu.cornell.mannlib.vitro.webapp.web.jsptags; -import edu.cornell.mannlib.vitro.webapp.beans.Individual; -import edu.cornell.mannlib.vitro.webapp.beans.VClass; -import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; -import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; -import org.apache.commons.lang.StringEscapeUtils; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; -import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.TagSupport; -import java.util.List; /** * diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/Value.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/Value.java index 3bc9feaea..2c0ff8a23 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/Value.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/Value.java @@ -2,12 +2,6 @@ package edu.cornell.mannlib.vitro.webapp.web.jsptags; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission; -import org.apache.commons.lang.StringEscapeUtils; - -import javax.servlet.http.HttpSession; -import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.TagSupport; /** diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DataPropertyStatementTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DataPropertyStatementTemplateModel.java index 1fde3c36b..49c8f3363 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DataPropertyStatementTemplateModel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DataPropertyStatementTemplateModel.java @@ -19,7 +19,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap; import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.RdfLiteralHash; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash; public class DataPropertyStatementTemplateModel extends PropertyStatementTemplateModel { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/widgets/SelectListWidget.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/widgets/SelectListWidget.java index 924e96afa..a2976656b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/widgets/SelectListWidget.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/widgets/SelectListWidget.java @@ -14,9 +14,8 @@ import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.SelectListGenerator; -import edu.cornell.mannlib.vitro.webapp.web.directives.WidgetDirective; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.SelectListGenerator; import freemarker.core.Environment; import freemarker.template.SimpleScalar; diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecisionTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecisionTest.java index def105b0c..a09ea7f9b 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecisionTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecisionTest.java @@ -24,9 +24,9 @@ import com.hp.hpl.jena.datatypes.xsd.XSDDateTime; import com.hp.hpl.jena.rdf.model.Literal; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission; @RunWith(value= Parameterized.class) diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/BasicValidationTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/BasicValidationTest.java index a524b438a..cd60ae8ec 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/BasicValidationTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/BasicValidationTest.java @@ -10,6 +10,8 @@ import junit.framework.Assert; import org.junit.Test; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.BasicValidation; + public class BasicValidationTest { @Test diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3GeneratorTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3GeneratorTest.java index 4d2964153..adf85fe28 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3GeneratorTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3GeneratorTest.java @@ -14,6 +14,8 @@ import org.junit.Test; import com.hp.hpl.jena.rdf.model.Literal; import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Generator; public class EditN3GeneratorTest { diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3UtilsTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3UtilsTest.java index e824fdbd8..604babd38 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3UtilsTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditN3UtilsTest.java @@ -11,6 +11,8 @@ import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.vocabulary.RDFS; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils; + public class EditN3UtilsTest { diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditSubmissionTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditSubmissionTest.java index cdfd8d465..616f0cf4e 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditSubmissionTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditSubmissionTest.java @@ -14,6 +14,8 @@ import stubs.javax.servlet.http.HttpServletRequestStub; import com.hp.hpl.jena.rdf.model.Literal; import edu.cornell.mannlib.vitro.testing.AbstractTestClass; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission; public class EditSubmissionTest extends AbstractTestClass { HttpServletRequestStub request; diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHashTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHashTest.java index 862a277be..180a6bfcc 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHashTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHashTest.java @@ -19,6 +19,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash; public class RdfLiteralHashTest { diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/SparqlEvaluateTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/SparqlEvaluateTest.java index c558d53b9..e4ba6909e 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/SparqlEvaluateTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/SparqlEvaluateTest.java @@ -9,6 +9,9 @@ import org.junit.Test; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.SparqlEvaluate; + public class SparqlEvaluateTest { SparqlEvaluate sEval; diff --git a/webapp/web/edit/editDatapropStmtRequestDispatch.jsp b/webapp/web/edit/editDatapropStmtRequestDispatch.jsp index d533602fd..aff82a9c5 100644 --- a/webapp/web/edit/editDatapropStmtRequestDispatch.jsp +++ b/webapp/web/edit/editDatapropStmtRequestDispatch.jsp @@ -6,8 +6,8 @@ <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.RdfLiteralHash" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %> diff --git a/webapp/web/edit/editRequestDispatch.jsp b/webapp/web/edit/editRequestDispatch.jsp index 58d183b14..2af319f81 100644 --- a/webapp/web/edit/editRequestDispatch.jsp +++ b/webapp/web/edit/editRequestDispatch.jsp @@ -4,7 +4,7 @@ <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %> diff --git a/webapp/web/edit/forms/addMissingWithMonikerAndLink.jsp b/webapp/web/edit/forms/addMissingWithMonikerAndLink.jsp index 70cd68e79..1e669fee5 100644 --- a/webapp/web/edit/forms/addMissingWithMonikerAndLink.jsp +++ b/webapp/web/edit/forms/addMissingWithMonikerAndLink.jsp @@ -7,7 +7,7 @@ <%@ page import="com.hp.hpl.jena.rdf.model.Literal" %> <%@ page import="com.hp.hpl.jena.rdf.model.Model" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> <%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %> <% diff --git a/webapp/web/edit/forms/admin/mayEditAs.jsp b/webapp/web/edit/forms/admin/mayEditAs.jsp index 65387307d..8563a83c7 100644 --- a/webapp/web/edit/forms/admin/mayEditAs.jsp +++ b/webapp/web/edit/forms/admin/mayEditAs.jsp @@ -6,9 +6,9 @@ <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.ModelSelector" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.ModelSelector" %> <%@ page import="com.hp.hpl.jena.ontology.OntModel"%> <%@ page import="org.apache.commons.logging.Log" %> <%@ page import="org.apache.commons.logging.LogFactory" %> diff --git a/webapp/web/edit/forms/autoCompleteDatapropForm.jsp b/webapp/web/edit/forms/autoCompleteDatapropForm.jsp index a37b87478..cc8d81917 100644 --- a/webapp/web/edit/forms/autoCompleteDatapropForm.jsp +++ b/webapp/web/edit/forms/autoCompleteDatapropForm.jsp @@ -5,7 +5,7 @@ <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement" %> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %> <%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %> <%@page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%> diff --git a/webapp/web/edit/forms/autoCompleteObjPropForm.jsp b/webapp/web/edit/forms/autoCompleteObjPropForm.jsp index 8b4eb9302..80480c14f 100644 --- a/webapp/web/edit/forms/autoCompleteObjPropForm.jsp +++ b/webapp/web/edit/forms/autoCompleteObjPropForm.jsp @@ -6,7 +6,7 @@ <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %> <%@ page import="org.apache.commons.logging.Log" %> <%@ page import="org.apache.commons.logging.LogFactory" %> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> diff --git a/webapp/web/edit/forms/datapropStmtDelete.jsp b/webapp/web/edit/forms/datapropStmtDelete.jsp index 1d655e9b4..091eb28c9 100644 --- a/webapp/web/edit/forms/datapropStmtDelete.jsp +++ b/webapp/web/edit/forms/datapropStmtDelete.jsp @@ -7,14 +7,14 @@ <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Utils"%> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory"%> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.RdfLiteralHash" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.StandardModelSelector"%> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.StandardModelSelector"%> <%@ page import="com.hp.hpl.jena.shared.Lock"%> <%@ page import="com.hp.hpl.jena.ontology.OntModel"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent"%> diff --git a/webapp/web/edit/forms/dateTimeIntervalForm.jsp b/webapp/web/edit/forms/dateTimeIntervalForm.jsp index 9e6e250b0..65d8fc805 100644 --- a/webapp/web/edit/forms/dateTimeIntervalForm.jsp +++ b/webapp/web/edit/forms/dateTimeIntervalForm.jsp @@ -10,15 +10,15 @@ <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary"%> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration"%> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.JavaScript" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Css" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.edit.elements.DateTimeWithPrecision"%> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field"%> -<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.DateTimeIntervalValidation"%> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field"%> +<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.DateTimeIntervalValidation"%> <%@ page import="org.apache.commons.logging.Log" %> <%@ page import="org.apache.commons.logging.LogFactory" %> diff --git a/webapp/web/edit/forms/dateTimeValueForm.jsp b/webapp/web/edit/forms/dateTimeValueForm.jsp index 664f23060..b483e52c1 100644 --- a/webapp/web/edit/forms/dateTimeValueForm.jsp +++ b/webapp/web/edit/forms/dateTimeValueForm.jsp @@ -10,18 +10,18 @@ <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary"%> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration"%> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.JavaScript" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Css" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.edit.elements.DateTimeWithPrecision"%> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field"%> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field"%> <%@ page import="org.apache.commons.logging.Log" %> <%@ page import="org.apache.commons.logging.LogFactory" %> -<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.DateTimeIntervalValidation"%> +<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.DateTimeIntervalValidation"%> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%> <%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %> diff --git a/webapp/web/edit/forms/defaultAddMissingIndividualForm.jsp b/webapp/web/edit/forms/defaultAddMissingIndividualForm.jsp index 28825ff8d..26ac4a2bb 100644 --- a/webapp/web/edit/forms/defaultAddMissingIndividualForm.jsp +++ b/webapp/web/edit/forms/defaultAddMissingIndividualForm.jsp @@ -7,9 +7,9 @@ <%@ page import="com.hp.hpl.jena.rdf.model.Literal" %> <%@ page import="com.hp.hpl.jena.rdf.model.Model" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.ModelChangePreprocessor"%> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.DefaultAddMissingIndividualFormModelPreprocessor"%> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ModelChangePreprocessor"%> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.DefaultAddMissingIndividualFormModelPreprocessor"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena"%> diff --git a/webapp/web/edit/forms/defaultDatapropForm.jsp b/webapp/web/edit/forms/defaultDatapropForm.jsp index 780f620ff..127cc8aa9 100644 --- a/webapp/web/edit/forms/defaultDatapropForm.jsp +++ b/webapp/web/edit/forms/defaultDatapropForm.jsp @@ -7,7 +7,7 @@ <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest"%> <%@ page import="java.util.HashMap"%> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %> <%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %> <%@page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%> <%! private static HashMap defaultsForXSDtypes ; diff --git a/webapp/web/edit/forms/defaultLinkForm.jsp b/webapp/web/edit/forms/defaultLinkForm.jsp index 46ffba3b7..b00be7505 100644 --- a/webapp/web/edit/forms/defaultLinkForm.jsp +++ b/webapp/web/edit/forms/defaultLinkForm.jsp @@ -6,7 +6,7 @@ <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty" %> diff --git a/webapp/web/edit/forms/defaultObjPropForm.jsp b/webapp/web/edit/forms/defaultObjPropForm.jsp index 50eaea23b..0307a3a39 100644 --- a/webapp/web/edit/forms/defaultObjPropForm.jsp +++ b/webapp/web/edit/forms/defaultObjPropForm.jsp @@ -6,7 +6,7 @@ <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %> <%@ page import="org.apache.commons.logging.Log" %> <%@ page import="java.util.List" %> <%@ page import="org.apache.commons.logging.LogFactory" %> @@ -23,7 +23,7 @@ WebappDaoFactory wdf = vreq.getWebappDaoFactory(); %> -<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.SelectListGenerator"%> +<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.SelectListGenerator"%> <%@page import="java.util.Map"%> <%@page import="com.hp.hpl.jena.ontology.OntModel"%> <%@page import="edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch"%> diff --git a/webapp/web/edit/forms/propDelete.jsp b/webapp/web/edit/forms/propDelete.jsp index fbf0f1527..525cb4c4a 100644 --- a/webapp/web/edit/forms/propDelete.jsp +++ b/webapp/web/edit/forms/propDelete.jsp @@ -5,7 +5,7 @@ <%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory.SelfEditing"%> <%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory"%> <%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.RoleIdentifier"%> -<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Utils"%> +<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty"%> diff --git a/webapp/web/edit/forms/rdfsLabelForm.jsp b/webapp/web/edit/forms/rdfsLabelForm.jsp index 410254a31..98de933c4 100644 --- a/webapp/web/edit/forms/rdfsLabelForm.jsp +++ b/webapp/web/edit/forms/rdfsLabelForm.jsp @@ -9,8 +9,8 @@ <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary"%> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration"%> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.RdfLiteralHash"%> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration"%> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement" %> diff --git a/webapp/web/edit/forms/test/dateTimePrecTest.jsp b/webapp/web/edit/forms/test/dateTimePrecTest.jsp index de926ec61..daa508c7e 100644 --- a/webapp/web/edit/forms/test/dateTimePrecTest.jsp +++ b/webapp/web/edit/forms/test/dateTimePrecTest.jsp @@ -13,7 +13,7 @@ This is a test file for the DateTimeWithPrecision EditElement. <%@ page import="java.util.HashMap"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory"%> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> diff --git a/webapp/web/edit/messages/datapropertyBackButtonProblems.jsp b/webapp/web/edit/messages/datapropertyBackButtonProblems.jsp index 6db24c055..f77fcc765 100644 --- a/webapp/web/edit/messages/datapropertyBackButtonProblems.jsp +++ b/webapp/web/edit/messages/datapropertyBackButtonProblems.jsp @@ -9,10 +9,10 @@ <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.edit.EditLiteral" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Generator" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Generator" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %> <%@ page import="org.apache.commons.logging.Log" %> @@ -21,7 +21,7 @@ <%@ page import="java.util.*" %> <%@page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl"%> <%@page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement"%> -<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.RdfLiteralHash"%> +<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash"%> <%@page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty"%> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> diff --git a/webapp/web/edit/n3Delete.jsp b/webapp/web/edit/n3Delete.jsp index 7c413fd5d..c0b3bfc48 100644 --- a/webapp/web/edit/n3Delete.jsp +++ b/webapp/web/edit/n3Delete.jsp @@ -9,10 +9,10 @@ <%@ page import="com.hp.hpl.jena.shared.Lock" %> <%@ page import="com.thoughtworks.xstream.XStream" %> <%@ page import="com.thoughtworks.xstream.io.xml.DomDriver" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Generator" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Generator" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %> <%@ page import="java.io.StringReader" %> <%@ page import="java.util.*" %> @@ -33,7 +33,7 @@ <%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle"%> <%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory"%> <%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.RoleIdentifier"%> -<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Utils"%> +<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils"%> <%@page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep"%> <%@page import="edu.cornell.mannlib.vitro.webapp.dao.jena.DependentResourceDeleteJena"%> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> diff --git a/webapp/web/edit/postEditCleanUp.jsp b/webapp/web/edit/postEditCleanUp.jsp index 2e90be807..fff890d5c 100644 --- a/webapp/web/edit/postEditCleanUp.jsp +++ b/webapp/web/edit/postEditCleanUp.jsp @@ -1,7 +1,7 @@ <%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %> <%@ page import="org.apache.commons.lang.StringUtils" %> <%@page import="org.apache.commons.logging.Log"%> diff --git a/webapp/web/edit/processDatapropRdfForm.jsp b/webapp/web/edit/processDatapropRdfForm.jsp index 837a7bc75..18ad0bd83 100644 --- a/webapp/web/edit/processDatapropRdfForm.jsp +++ b/webapp/web/edit/processDatapropRdfForm.jsp @@ -9,10 +9,10 @@ <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.edit.EditLiteral" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Generator" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Generator" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %> <%@ page import="org.apache.commons.logging.Log" %> @@ -21,13 +21,13 @@ <%@ page import="java.util.*" %> <%@page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl"%> <%@page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement"%> -<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.RdfLiteralHash"%> +<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash"%> <%@page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty"%> <%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle"%> <%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory"%> <%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.RoleIdentifier"%> <%@page import="edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent"%> -<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Utils"%> +<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils"%> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> <%-- 2nd prototype of processing, adapted for data property editing diff --git a/webapp/web/edit/processRdfForm2.jsp b/webapp/web/edit/processRdfForm2.jsp index dde36eb75..0a8971448 100644 --- a/webapp/web/edit/processRdfForm2.jsp +++ b/webapp/web/edit/processRdfForm2.jsp @@ -9,10 +9,10 @@ <%@ page import="com.hp.hpl.jena.shared.Lock" %> <%@ page import="com.thoughtworks.xstream.XStream" %> <%@ page import="com.thoughtworks.xstream.io.xml.DomDriver" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Generator" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Generator" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field" %> <%@ page import="java.io.StringReader" %> <%@ page import="java.util.*" %> <%@ page import="java.util.Map" %> @@ -34,10 +34,10 @@ <%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle"%> <%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory"%> <%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.RoleIdentifier"%> -<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Utils"%> +<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils"%> <%@page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest"%> <%@page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep"%> -<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.ModelChangePreprocessor"%> +<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ModelChangePreprocessor"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %> <%@ page import="java.net.URLDecoder" %> <%@page import="edu.cornell.mannlib.vitro.webapp.dao.jena.DependentResourceDeleteJena"%> diff --git a/webapp/web/edit/selfeditcheck.jsp b/webapp/web/edit/selfeditcheck.jsp index 1cf75b1af..98e703a86 100644 --- a/webapp/web/edit/selfeditcheck.jsp +++ b/webapp/web/edit/selfeditcheck.jsp @@ -1,7 +1,7 @@ <%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %> <%@ page import="org.apache.commons.logging.Log" %> <%@ page import="org.apache.commons.logging.LogFactory" %> From 675e80d9509aee344a633d9d481dac8f0b33a3a7 Mon Sep 17 00:00:00 2001 From: cappadona Date: Thu, 12 May 2011 16:18:26 +0000 Subject: [PATCH 15/47] Markup cleanup for consistency and removed VIVO reference. --- .../freemarker/widgets/widget-login.ftl | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/webapp/web/templates/freemarker/widgets/widget-login.ftl b/webapp/web/templates/freemarker/widgets/widget-login.ftl index 77b20394b..c76468ba9 100644 --- a/webapp/web/templates/freemarker/widgets/widget-login.ftl +++ b/webapp/web/templates/freemarker/widgets/widget-login.ftl @@ -20,7 +20,7 @@ @@ -38,7 +38,7 @@ -
+ <#if externalAuthUrl??>

${externalAuthName}

or

@@ -46,13 +46,13 @@

Log in using your ${siteName} account

- - + + - - + + -

+

<#-- NC: remember me won't be ready for r1.2 --> @@ -74,16 +74,16 @@ - - - + + +

Minimum of 6 characters in length.

- - + + -

or Cancel

+

or Cancel

From e72604c727fa63d6c03bb5c78ffc404e3a159892 Mon Sep 17 00:00:00 2001 From: briancaruso Date: Thu, 12 May 2011 16:25:34 +0000 Subject: [PATCH 16/47] adding license statements --- .../configuration/generators/DefaultPropertyFormGenerator.java | 2 ++ .../configuration/generators/EditConfigurationGenerator.java | 2 ++ .../edit/n3editing/processEdit/AdditionsAndRetractions.java | 2 ++ .../vitro/webapp/edit/n3editing/processEdit/ProcessRdfForm.java | 2 ++ 4 files changed, 8 insertions(+) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultPropertyFormGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultPropertyFormGenerator.java index eff15d902..d32a41506 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultPropertyFormGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultPropertyFormGenerator.java @@ -1,3 +1,5 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators; import javax.servlet.http.HttpSession; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/EditConfigurationGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/EditConfigurationGenerator.java index 6beed22b8..4289155ef 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/EditConfigurationGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/EditConfigurationGenerator.java @@ -1,3 +1,5 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators; import javax.servlet.http.HttpSession; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/AdditionsAndRetractions.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/AdditionsAndRetractions.java index 2f3e6b36b..f60693a51 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/AdditionsAndRetractions.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/AdditionsAndRetractions.java @@ -1,3 +1,5 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + package edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit; import java.util.List; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/ProcessRdfForm.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/ProcessRdfForm.java index 21cc34314..e04c5fdc8 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/ProcessRdfForm.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/ProcessRdfForm.java @@ -1,3 +1,5 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + package edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit; import java.io.StringReader; From 69dd3019a71edb22e680227ece2f15c8e68abaf1 Mon Sep 17 00:00:00 2001 From: j2blake Date: Thu, 12 May 2011 19:26:20 +0000 Subject: [PATCH 17/47] NIHVIVO-2299 Rename Actions.EMPTY to Actions.AUTHORIZED, for consistency. --- .../mannlib/vitro/webapp/auth/requestedAction/Actions.java | 4 ++-- .../vitro/webapp/controller/ajax/VitroAjaxController.java | 2 +- .../webapp/controller/authenticate/AdminLoginController.java | 2 +- .../webapp/controller/freemarker/FreemarkerHttpServlet.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/Actions.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/Actions.java index b8bedc6b2..ecbf1638a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/Actions.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/Actions.java @@ -31,12 +31,12 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAct public class Actions { private static final Log log = LogFactory.getLog(Actions.class); - public static final Actions EMPTY = new Actions(); + public static final Actions AUTHORIZED = new Actions(); public static final Actions UNAUTHORIZED = new Actions( new UnauthorizedAction()); public static Actions notNull(Actions actions) { - return (actions == null) ? EMPTY : actions; + return (actions == null) ? AUTHORIZED : actions; } private final List> clauseList; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/ajax/VitroAjaxController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/ajax/VitroAjaxController.java index 2975b6bc3..4e85d7e35 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/ajax/VitroAjaxController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/ajax/VitroAjaxController.java @@ -67,7 +67,7 @@ public abstract class VitroAjaxController extends HttpServlet { */ @SuppressWarnings("unused") protected Actions requiredActions(VitroRequest vreq) { - return Actions.EMPTY; + return Actions.AUTHORIZED; } /** diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/AdminLoginController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/AdminLoginController.java index ec5adcd0c..4286f5d38 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/AdminLoginController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/AdminLoginController.java @@ -39,7 +39,7 @@ public class AdminLoginController extends FreemarkerHttpServlet { @Override protected Actions requiredActions(VitroRequest vreq) { - return Actions.EMPTY; // No requirements to use this page. + return Actions.AUTHORIZED; // No requirements to use this page. } @Override 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 0118c1173..046a13268 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 @@ -121,7 +121,7 @@ public class FreemarkerHttpServlet extends VitroHttpServlet { */ @SuppressWarnings("unused") protected Actions requiredActions(VitroRequest vreq) { - return Actions.EMPTY; + return Actions.AUTHORIZED; } // Subclasses will override From 42cee19d55907d50ec012cb502ef0c08c25aa8b2 Mon Sep 17 00:00:00 2001 From: j2blake Date: Thu, 12 May 2011 19:27:02 +0000 Subject: [PATCH 18/47] NIHVIVO-2299 Accept either an Actions object or a sequence of RequestedAction for authorization. --- .../webapp/controller/VitroHttpServlet.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroHttpServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroHttpServlet.java index 1aa9f51d8..5f7858b16 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroHttpServlet.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroHttpServlet.java @@ -26,6 +26,7 @@ import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper; import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions; +import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction; import edu.cornell.mannlib.vitro.webapp.beans.DisplayMessage; import edu.cornell.mannlib.vitro.webapp.controller.authenticate.LogoutRedirector; @@ -98,7 +99,19 @@ public class VitroHttpServlet extends HttpServlet { * Don't display a page that the user isn't authorized to see. * * @param actions - * the RequestedActions that need to be authorized. + * the RequestedActions that must be authorized. + */ + protected boolean isAuthorizedToDisplayPage(HttpServletRequest request, + HttpServletResponse response, RequestedAction... actions) { + return isAuthorizedToDisplayPage(request, response, + new Actions(Arrays.asList(actions))); + } + + /** + * Don't display a page that the user isn't authorized to see. + * + * @param actions + * the combination of RequestedActions that must be authorized. */ protected boolean isAuthorizedToDisplayPage(HttpServletRequest request, HttpServletResponse response, Actions actions) { @@ -112,7 +125,7 @@ public class VitroHttpServlet extends HttpServlet { + "' is authorized for actions: " + actions); return true; } - + log.debug("Servlet '" + this.getClass().getSimpleName() + "' is not authorized for actions: " + actions); From d4aff14e6f925ecd9c5b3aa8fe7f8af17852e6ba Mon Sep 17 00:00:00 2001 From: ryounes Date: Thu, 12 May 2011 20:42:14 +0000 Subject: [PATCH 19/47] NIHVIVO-2437 Minor refactoring --- .../controller/PagedSearchController.java | 2 +- .../controller/SolrPagedSearchController.java | 47 +++++++++++-------- .../body/search/search-xmlResults.ftl | 2 +- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java index 9f4931532..576c8176e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java @@ -364,7 +364,7 @@ public class PagedSearchController extends FreemarkerHttpServlet implements Sear body.put("title", qtxt + " - " + appBean.getApplicationName() + " Search Results"); - body.put("hitsLength",hitsLength); + body.put("hitCount",hitsLength); body.put("startIndex", startIndex); body.put("pagingLinks", getPagingLinks(startIndex, hitsPerPage, diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/SolrPagedSearchController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/SolrPagedSearchController.java index 18420b226..d71b5e73e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/SolrPagedSearchController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/SolrPagedSearchController.java @@ -73,10 +73,17 @@ public class SolrPagedSearchController extends FreemarkerHttpServlet { private static final long serialVersionUID = 1L; private static final Log log = LogFactory.getLog(SolrPagedSearchController.class); - private static final String XML_REQUEST_PARAM = "xml"; + private static final int DEFAULT_HITS_PER_PAGE = 25; private static final int DEFAULT_MAX_SEARCH_SIZE = 1000; - + + private static final String PARAM_XML_REQUEST = "xml"; + private static final String PARAM_START_INDEX = "startIndex"; + private static final String PARAM_HITS_PER_PAGE = "hitsPerPage"; + private static final String PARAM_CLASSGROUP = "classgroup"; + private static final String PARAM_RDFTYPE = "type"; + private static final String PARAM_QUERY_TEXT = "querytext"; + protected static final Map> templateTable; protected enum Format { @@ -148,7 +155,7 @@ public class SolrPagedSearchController extends FreemarkerHttpServlet { int startIndex = 0; try{ - startIndex = Integer.parseInt(vreq.getParameter("startIndex")); + startIndex = Integer.parseInt(vreq.getParameter(PARAM_START_INDEX)); }catch (Throwable e) { startIndex = 0; } @@ -156,7 +163,7 @@ public class SolrPagedSearchController extends FreemarkerHttpServlet { int hitsPerPage = DEFAULT_HITS_PER_PAGE; try{ - hitsPerPage = Integer.parseInt(vreq.getParameter("hitsPerPage")); + hitsPerPage = Integer.parseInt(vreq.getParameter(PARAM_HITS_PER_PAGE)); } catch (Throwable e) { hitsPerPage = DEFAULT_HITS_PER_PAGE; } @@ -244,18 +251,18 @@ public class SolrPagedSearchController extends FreemarkerHttpServlet { } ParamMap pagingLinkParams = new ParamMap(); - pagingLinkParams.put("querytext", qtxt); - pagingLinkParams.put("hitsPerPage", String.valueOf(hitsPerPage)); + pagingLinkParams.put(PARAM_QUERY_TEXT, qtxt); + pagingLinkParams.put(PARAM_HITS_PER_PAGE, String.valueOf(hitsPerPage)); if( wasXmlRequested ){ - pagingLinkParams.put(XML_REQUEST_PARAM,"1"); + pagingLinkParams.put(PARAM_XML_REQUEST,"1"); } /* Compile the data for the templates */ Map body = new HashMap(); - String classGroupParam = vreq.getParameter("classgroup"); + String classGroupParam = vreq.getParameter(PARAM_CLASSGROUP); boolean classGroupFilterRequested = false; if (!StringUtils.isEmpty(classGroupParam)) { VClassGroup grp = grpDao.getGroupByURI(classGroupParam); @@ -264,7 +271,7 @@ public class SolrPagedSearchController extends FreemarkerHttpServlet { body.put("classGroupName", grp.getPublicName()); } - String typeParam = vreq.getParameter("type"); + String typeParam = vreq.getParameter(PARAM_RDFTYPE); boolean typeFilterRequested = false; if (!StringUtils.isEmpty(typeParam)) { VClass type = vclassDao.getVClassByURI(typeParam); @@ -295,10 +302,10 @@ public class SolrPagedSearchController extends FreemarkerHttpServlet { vClassLinks.add(new VClassSearchLink(qtxt, vc)); } body.put("classLinks", vClassLinks); - pagingLinkParams.put("classgroup", classGroupParam); + pagingLinkParams.put(PARAM_CLASSGROUP, classGroupParam); } else { - pagingLinkParams.put("type", typeParam); + pagingLinkParams.put(PARAM_RDFTYPE, typeParam); } } @@ -312,7 +319,7 @@ public class SolrPagedSearchController extends FreemarkerHttpServlet { body.put("title", qtxt + " - " + appBean.getApplicationName() + " Search Results"); - body.put("hitsLength", hitCount); + body.put("hitCount", hitCount); body.put("startIndex", startIndex); body.put("pagingLinks", getPagingLinks(startIndex, hitsPerPage, @@ -443,7 +450,7 @@ public class SolrPagedSearchController extends FreemarkerHttpServlet { query.setRows(maxHitCount); // Classgroup filtering - Object param = vreq.getParameter("classgroup"); + Object param = vreq.getParameter(PARAM_CLASSGROUP); if( param != null && !"".equals(param)){ log.debug("Firing classgroup query "); log.debug("request.getParameter(classgroup) is "+ param.toString()); @@ -451,7 +458,7 @@ public class SolrPagedSearchController extends FreemarkerHttpServlet { } // rdf:type filtering - param = vreq.getParameter("type"); + param = vreq.getParameter(PARAM_RDFTYPE); if( param != null && !"".equals(param)){ log.debug("Firing type query "); log.debug("request.getParameter(type) is "+ param.toString()); @@ -483,14 +490,14 @@ public class SolrPagedSearchController extends FreemarkerHttpServlet { private class VClassGroupSearchLink extends LinkTemplateModel { VClassGroupSearchLink(String querytext, VClassGroup classgroup) { - super(classgroup.getPublicName(), "/search", "querytext", querytext, "classgroup", classgroup.getURI()); + super(classgroup.getPublicName(), "/search", PARAM_QUERY_TEXT, querytext, PARAM_CLASSGROUP, classgroup.getURI()); } } private class VClassSearchLink extends LinkTemplateModel { VClassSearchLink(String querytext, VClass type) { - super(type.getName(), "/search", "querytext", querytext, "type", type.getURI()); + super(type.getName(), "/search", PARAM_QUERY_TEXT, querytext, PARAM_RDFTYPE, type.getURI()); } } @@ -504,7 +511,7 @@ public class SolrPagedSearchController extends FreemarkerHttpServlet { } for (int i = 0; i < hitCount; i += hitsPerPage) { - params.put("startIndex", String.valueOf(i)); + params.put(PARAM_START_INDEX, String.valueOf(i)); if ( i < maxHitCount - hitsPerPage) { int pageNumber = i/hitsPerPage + 1; if (i >= startIndex && i < (startIndex + hitsPerPage)) { @@ -521,12 +528,12 @@ public class SolrPagedSearchController extends FreemarkerHttpServlet { } private String getPreviousPageLink(int startIndex, int hitsPerPage, String baseUrl, ParamMap params) { - params.put("startIndex", String.valueOf(startIndex-hitsPerPage)); + params.put(PARAM_START_INDEX, String.valueOf(startIndex-hitsPerPage)); return UrlBuilder.getUrl(baseUrl, params); } private String getNextPageLink(int startIndex, int hitsPerPage, String baseUrl, ParamMap params) { - params.put("startIndex", String.valueOf(startIndex+hitsPerPage)); + params.put(PARAM_START_INDEX, String.valueOf(startIndex+hitsPerPage)); return UrlBuilder.getUrl(baseUrl, params); } @@ -650,7 +657,7 @@ public class SolrPagedSearchController extends FreemarkerHttpServlet { protected boolean isRequestedFormatXml(HttpServletRequest req){ if( req != null ){ - String param = req.getParameter(XML_REQUEST_PARAM); + String param = req.getParameter(PARAM_XML_REQUEST); if( param != null && "1".equals(param)){ return true; }else{ diff --git a/webapp/web/templates/freemarker/body/search/search-xmlResults.ftl b/webapp/web/templates/freemarker/body/search/search-xmlResults.ftl index 9def574b8..b96094453 100644 --- a/webapp/web/templates/freemarker/body/search/search-xmlResults.ftl +++ b/webapp/web/templates/freemarker/body/search/search-xmlResults.ftl @@ -9,7 +9,7 @@ - + <#list individuals as individual> ${individual.uri?xml} From 9d8610f4103273cb769d39f86d3b80af7a77a94f Mon Sep 17 00:00:00 2001 From: ryounes Date: Thu, 12 May 2011 20:51:46 +0000 Subject: [PATCH 20/47] NIHVIVO-2437 Add commented-out servlet and listener specifications for Solr search --- webapp/config/web.xml | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/webapp/config/web.xml b/webapp/config/web.xml index 4c495732e..e6cb0573a 100644 --- a/webapp/config/web.xml +++ b/webapp/config/web.xml @@ -143,12 +143,20 @@ edu.cornell.mannlib.vitro.webapp.search.lucene.LuceneSetup - - + + + + edu.cornell.mannlib.vitro.webapp.auth.identifier.UserToIndIdentifierFactorySetup @@ -890,7 +898,13 @@ SearchController edu.cornell.mannlib.vitro.webapp.search.controller.PagedSearchController + + SearchController /search From 2d8873f41ebb03fdf1dfbdcf1a7cbf39c56848fe Mon Sep 17 00:00:00 2001 From: j2blake Date: Thu, 12 May 2011 20:59:08 +0000 Subject: [PATCH 21/47] NIHVIVO-2601 Improve the password-change functioning. --- .../authenticate/AdminLoginController.java | 69 +++++++++++++++---- .../templates/freemarker/body/adminLogin.ftl | 18 ++++- 2 files changed, 69 insertions(+), 18 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/AdminLoginController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/AdminLoginController.java index 4286f5d38..c44d73f25 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/AdminLoginController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/AdminLoginController.java @@ -7,7 +7,11 @@ import static edu.cornell.mannlib.vedit.beans.LoginStatusBean.AuthenticationSour import java.util.HashMap; import java.util.Map; +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.beans.User; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; @@ -23,9 +27,13 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Tem * URL can come here, but they need to pass Internal Authentication to proceed. */ public class AdminLoginController extends FreemarkerHttpServlet { + private static final Log log = LogFactory + .getLog(AdminLoginController.class); + public static final String PARAMETER_USERNAME = "username"; public static final String PARAMETER_PASSWORD = "password"; public static final String PARAMETER_NEW_PASSWORD = "newPassword"; + public static final String PARAMETER_CONFIRM_PASSWORD = "confirmPassword"; public static final String URL_THIS = "/admin/login"; public static final String URL_HOME_PAGE = "/"; @@ -36,6 +44,9 @@ public class AdminLoginController extends FreemarkerHttpServlet { private static final String MESSAGE_NO_PASSWORD = "errorNoPassword"; private static final String MESSAGE_LOGIN_FAILED = "errorLoginFailed"; private static final String MESSAGE_NEW_PASSWORD_REQUIRED = "newPasswordRequired"; + private static final String MESSAGE_NEW_PASSWORD_WRONG_LENGTH = "errorNewPasswordWrongLength"; + private static final String MESSAGE_NEW_PASSWORDS_DONT_MATCH = "errorNewPasswordsDontMatch"; + private static final String MESSAGE_NEW_PASSWORD_MATCHES_OLD = "errorNewPasswordMatchesOld"; @Override protected Actions requiredActions(VitroRequest vreq) { @@ -56,6 +67,7 @@ public class AdminLoginController extends FreemarkerHttpServlet { private final String username; private final String password; private final String newPassword; + private final String confirmPassword; public Core(VitroRequest vreq) { this.auth = Authenticator.getInstance(vreq); @@ -64,20 +76,40 @@ public class AdminLoginController extends FreemarkerHttpServlet { this.password = nonNull(vreq.getParameter(PARAMETER_PASSWORD)); this.newPassword = nonNull(vreq .getParameter(PARAMETER_NEW_PASSWORD)); + this.confirmPassword = nonNull(vreq + .getParameter(PARAMETER_CONFIRM_PASSWORD)); + + log.debug("Parameters: username='" + username + "', password='" + + password + "', newPassword='" + newPassword + + "', confirmPassword='" + confirmPassword + "'"); } public ResponseValues process() { if (username.isEmpty() && password.isEmpty()) { - return showInitialForm(); + return showForm(); } if (username.isEmpty()) { - return showFormWithMessage(MESSAGE_NO_USERNAME); + return showForm(MESSAGE_NO_USERNAME); } if (password.isEmpty()) { - return showFormWithMessage(MESSAGE_NO_PASSWORD); + return showForm(MESSAGE_NO_PASSWORD); } - if (newPasswordRequired() && newPassword.isEmpty()) { - return showFormWithMessage(MESSAGE_NEW_PASSWORD_REQUIRED); + if (newPasswordRequired()) { + if (newPassword.isEmpty()) { + return showForm(MESSAGE_NEW_PASSWORD_REQUIRED); + } + if (!isPasswordValidLength(newPassword)) { + return showForm(MESSAGE_NEW_PASSWORD_REQUIRED, + MESSAGE_NEW_PASSWORD_WRONG_LENGTH); + } + if (newPassword.equals(password)) { + return showForm(MESSAGE_NEW_PASSWORD_REQUIRED, + MESSAGE_NEW_PASSWORD_MATCHES_OLD); + } + if (!newPassword.equals(confirmPassword)) { + return showForm(MESSAGE_NEW_PASSWORD_REQUIRED, + MESSAGE_NEW_PASSWORDS_DONT_MATCH); + } } boolean loggedIn = tryToLogin(); @@ -85,7 +117,7 @@ public class AdminLoginController extends FreemarkerHttpServlet { return goToHomePage(); } - return showFormWithMessage(MESSAGE_LOGIN_FAILED); + return showForm(MESSAGE_LOGIN_FAILED); } private boolean newPasswordRequired() { @@ -93,6 +125,11 @@ public class AdminLoginController extends FreemarkerHttpServlet { && auth.isPasswordChangeRequired(username); } + private boolean isPasswordValidLength(String pw) { + return (pw.length() >= User.MIN_PASSWORD_LENGTH) + && (pw.length() <= User.MAX_PASSWORD_LENGTH); + } + private boolean tryToLogin() { if (auth.isCurrentPassword(username, password)) { auth.recordLoginAgainstUserAccount(username, INTERNAL); @@ -107,18 +144,20 @@ public class AdminLoginController extends FreemarkerHttpServlet { } } - private ResponseValues showInitialForm() { - Map body = new HashMap(); - body.put("controllerUrl", UrlBuilder.getUrl(URL_THIS)); - body.put("username", ""); - return new TemplateResponseValues(TEMPLATE_NAME, body); - } - - private ResponseValues showFormWithMessage(String messageCode) { + private ResponseValues showForm(String... codes) { Map body = new HashMap(); body.put("controllerUrl", UrlBuilder.getUrl(URL_THIS)); body.put("username", username); - body.put(messageCode, Boolean.TRUE); + body.put("password", password); + body.put("newPassword", newPassword); + body.put("confirmPassword", confirmPassword); + + for (String code : codes) { + body.put(code, Boolean.TRUE); + } + + log.debug("showing form with values: " + body); + return new TemplateResponseValues(TEMPLATE_NAME, body); } diff --git a/webapp/web/templates/freemarker/body/adminLogin.ftl b/webapp/web/templates/freemarker/body/adminLogin.ftl index 540b670bc..dec97ba6a 100644 --- a/webapp/web/templates/freemarker/body/adminLogin.ftl +++ b/webapp/web/templates/freemarker/body/adminLogin.ftl @@ -17,7 +17,19 @@ <#assign errorMessage = "Email or Password was incorrect." /> - <#if (errorNoUser?? || errorNoPassword?? || errorLoginFailed?? )> + <#if errorNewPasswordWrongLength??> + <#assign errorMessage = "Password must be between 6 and 12 characters." /> + + + <#if errorNewPasswordsDontMatch??> + <#assign errorMessage = "Passwords do not match." /> + + + <#if errorNewPasswordMatchesOld??> + <#assign errorMessage = "Your new password must be different from your existing password." /> + + + <#if errorMessage?has_content>