From 17a60cb81c20a89ae5be1bf7e9cb38c0a85ee638 Mon Sep 17 00:00:00 2001 From: brianjlowe Date: Tue, 4 Oct 2011 20:50:31 +0000 Subject: [PATCH] NIHVIVO-3116 and assorted cleanup of legacy backend editor --- .../vedit/controller/BaseEditController.java | 3 +- .../vedit/controller/OperationController.java | 19 +- .../cornell/mannlib/vedit/util/FormUtils.java | 271 ++++++++++-------- .../vedit/validator/impl/IntValidator.java | 4 +- .../mannlib/vitro/webapp/beans/Keyword.java | 64 ----- .../beans/KeywordIndividualRelation.java | 32 --- .../vitro/webapp/beans/KeywordProperty.java | 44 --- .../vitro/webapp/beans/ObjectProperty.java | 163 ++++------- .../beans/ObjectPropertyStatementImpl.java | 1 - .../mannlib/vitro/webapp/beans/Property.java | 14 +- .../DashboardPropertyListController.java | 7 +- .../edit/ApplicationBeanRetryController.java | 2 +- .../edit/ClassgroupRetryController.java | 3 +- .../DataPropertyStatementRetryController.java | 3 +- .../edit/DatapropRetryController.java | 18 +- .../edit/DatatypeRetryController.java | 3 +- .../edit/EntityRetryController.java | 4 +- .../edit/ExternalIdRetryController.java | 3 +- .../edit/NamespaceRetryController.java | 3 +- ...bjectPropertyStatementRetryController.java | 3 +- .../edit/OntologyRetryController.java | 3 +- .../edit/PropertyGroupRetryController.java | 3 +- .../edit/PropertyRetryController.java | 22 +- .../edit/VclassRetryController.java | 5 +- .../AllClassGroupsListingController.java | 7 +- ...ataPropertyHierarchyListingController.java | 18 +- .../DatatypePropertiesListingController.java | 12 +- ...ectPropertyHierarchyListingController.java | 37 ++- .../PropertyGroupsListingController.java | 52 +++- .../PropertyWebappsListingController.java | 6 +- .../vitro/webapp/dao/IndividualDao.java | 1 - .../vitro/webapp/dao/PropertyInstanceDao.java | 2 - .../FilteringPropertyInstanceDao.java | 6 - .../dao/filtering/IndividualDaoFiltering.java | 2 - .../filtering/ObjectPropertyFiltering.java | 72 ++--- .../webapp/dao/jena/IndividualDaoJena.java | 11 - .../vitro/webapp/dao/jena/IndividualJena.java | 2 - .../vitro/webapp/dao/jena/IndividualSDB.java | 3 - .../vitro/webapp/dao/jena/JenaBaseDao.java | 41 ++- .../dao/jena/ObjectPropertyDaoJena.java | 61 +--- .../dao/jena/PropertyInstanceDaoJena.java | 7 - .../vitro/webapp/dao/jena/VClassDaoJena.java | 4 +- .../listener/impl/KeywordPreProcessor.java | 23 -- .../listener/impl/KeywordSearchReindexer.java | 24 -- .../individual/GroupedPropertyList.java | 10 +- .../ObjectPropertyTemplateModel.java | 5 +- .../vitro/webapp/dao/IndividualDaoStub.java | 1 - 47 files changed, 442 insertions(+), 662 deletions(-) delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/beans/Keyword.java delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/beans/KeywordIndividualRelation.java delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/beans/KeywordProperty.java delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/edit/listener/impl/KeywordPreProcessor.java delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/edit/listener/impl/KeywordSearchReindexer.java diff --git a/webapp/src/edu/cornell/mannlib/vedit/controller/BaseEditController.java b/webapp/src/edu/cornell/mannlib/vedit/controller/BaseEditController.java index 707f67bde..0e97159b6 100644 --- a/webapp/src/edu/cornell/mannlib/vedit/controller/BaseEditController.java +++ b/webapp/src/edu/cornell/mannlib/vedit/controller/BaseEditController.java @@ -33,7 +33,8 @@ public class BaseEditController extends VitroHttpServlet { public static final String JSP_PREFIX = "/templates/edit/specific/"; - protected static DateFormat DISPLAY_DATE_FORMAT = new SimpleDateFormat("MM/dd/yyyy"); + protected static DateFormat DISPLAY_DATE_FORMAT = new SimpleDateFormat("MM/dd/yyyy"); + protected static final int BASE_10 = 10; private static final Log log = LogFactory.getLog(BaseEditController.class.getName()); private static final String DEFAULT_LANDING_PAGE = Controllers.SITE_ADMIN; diff --git a/webapp/src/edu/cornell/mannlib/vedit/controller/OperationController.java b/webapp/src/edu/cornell/mannlib/vedit/controller/OperationController.java index 80ae4f85e..6d8b6e158 100644 --- a/webapp/src/edu/cornell/mannlib/vedit/controller/OperationController.java +++ b/webapp/src/edu/cornell/mannlib/vedit/controller/OperationController.java @@ -11,7 +11,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -23,6 +22,7 @@ import edu.cornell.mannlib.vedit.forwarder.PageForwarder; import edu.cornell.mannlib.vedit.listener.ChangeListener; import edu.cornell.mannlib.vedit.listener.EditPreProcessor; import edu.cornell.mannlib.vedit.util.FormUtils; +import edu.cornell.mannlib.vedit.util.FormUtils.NegativeIntegerException; import edu.cornell.mannlib.vedit.util.OperationUtils; import edu.cornell.mannlib.vedit.validator.ValidationObject; import edu.cornell.mannlib.vedit.validator.Validator; @@ -201,17 +201,6 @@ public class OperationController extends BaseEditController { } } - private void applySimpleMask(EditProcessObject epo, Object newObj) { - // apply the simple mask - //if (epo.getSimpleMask() != null) { - // Iterator smaskIt = epo.getSimpleMask().iterator(); - // while (smaskIt.hasNext()){ - // Object[] simpleMaskPair = (Object[]) smaskIt.next(); - // FormUtils.beanSet(newObj,(String)simpleMaskPair[0],simpleMaskPair[1].toString()); - // } - //} - } - private Object getNewObj(EditProcessObject epo) { Object newObj = null; if (epo.getOriginalBean() != null) { // we're updating or deleting an existing bean @@ -292,10 +281,14 @@ public class OperationController extends BaseEditController { epo.getBadValueMap().remove(currParam); } catch (NumberFormatException e) { if (currValue.length()>0) { - valid=false; + valid = false; epo.getErrMsgMap().put(currParam,"Please enter an integer"); epo.getBadValueMap().put(currParam,currValue); } + } catch (NegativeIntegerException nie) { + valid = false; + epo.getErrMsgMap().put(currParam,"Please enter a positive integer"); + epo.getBadValueMap().put(currParam,currValue); } catch (IllegalArgumentException f) { valid=false; log.error("doPost() reports IllegalArgumentException for "+currParam); diff --git a/webapp/src/edu/cornell/mannlib/vedit/util/FormUtils.java b/webapp/src/edu/cornell/mannlib/vedit/util/FormUtils.java index 7b14c77ea..7a7607b34 100644 --- a/webapp/src/edu/cornell/mannlib/vedit/util/FormUtils.java +++ b/webapp/src/edu/cornell/mannlib/vedit/util/FormUtils.java @@ -5,6 +5,7 @@ package edu.cornell.mannlib.vedit.util; import java.lang.reflect.Method; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.Iterator; @@ -26,32 +27,45 @@ import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; public class FormUtils { - protected static final Log log = LogFactory.getLog(FormUtils.class.getName()); + protected static final Log log = LogFactory.getLog(FormUtils.class.getName()); + protected static final int BASE_10 = 10; + protected static final Class[] SUPPORTED_TYPES = { String.class, + int.class, + Integer.class, + boolean.class, + Date.class + }; + + protected static final List SUPPORTED_TYPE_LIST = Arrays + .asList(SUPPORTED_TYPES); /* this class needs to be reworked */ - public static String htmlFormFromBean (Object bean, String action, FormObject foo) { - return htmlFormFromBean(bean,action,null,foo,new HashMap()); + public static void populateFormFromBean (Object bean, + String action, + FormObject foo) { + populateFormFromBean(bean,action,null,foo,new HashMap()); } - public static String htmlFormFromBean (Object bean, String action, FormObject foo, Map badValuesHash) { - return htmlFormFromBean(bean,action,null,foo,badValuesHash); + public static void populateFormFromBean (Object bean, + String action, + FormObject foo, + Map badValuesHash) { + populateFormFromBean(bean,action,null,foo,badValuesHash); } /** - * Creates a basic XHTML editing form for a bean class - * - * This is the simplest version, creating an input field for each and every setter method in the bean. - * - * @param bean the bean class for which an editing form should be built - * @return XHTML markup of an editing form for the specified class - * @author bjl23 + * Populates form objects with bean values */ - public static String htmlFormFromBean (Object bean, String action, EditProcessObject epo, FormObject foo, Map BadValuesHash) { - - String formMarkup = ""; - - Class beanClass = (epo != null && epo.getBeanClass() != null) ? epo.getBeanClass() : bean.getClass(); + public static void populateFormFromBean (Object bean, + String action, + EditProcessObject epo, + FormObject foo, + Map BadValuesHash) { + Class beanClass = + (epo != null && epo.getBeanClass() != null) + ? epo.getBeanClass() + : bean.getClass(); Method[] meths = beanClass.getMethods(); @@ -60,32 +74,16 @@ public class FormUtils { if (meths[i].getName().indexOf("set") == 0) { // we have a setter method - Method currMeth = meths[i]; Class[] currMethParamTypes = currMeth.getParameterTypes(); Class currMethType = currMethParamTypes[0]; - String currMethTypeStr = currMethType.toString(); + + if (SUPPORTED_TYPE_LIST.contains(currMethType)) { + //we only want people directly to type in ints, strings, and dates + //of course, most of the ints are probably foreign keys anyway... - if (currMethTypeStr.equals("int") || currMethTypeStr.indexOf("class java.lang.String")>-1 || currMethTypeStr.indexOf("class java.util.Date")>-1) { - //we only want people directly to type in ints, strings, and dates - //of course, most of the ints are probably foreign keys anyway... - - String elementName = currMeth.getName().substring(3,currMeth.getName().length()); - - formMarkup += ""; - - formMarkup += "

"+elementName+"

"; - - formMarkup += ""; - - formMarkup += " makeOptionListFromBeans (List beanList, + String valueField, + String bodyField, + String selectedValue, + String selectedBody) { + return makeOptionListFromBeans ( + beanList, valueField, bodyField, selectedValue, selectedBody, true); } - public static List /*of Option*/ makeOptionListFromBeans (List beanList, String valueField, String bodyField, String selectedValue, String selectedBody, boolean forceSelectedInclusion) { - List optList = new LinkedList(); + public static List