Produce the pick-lists for range and domain.
Still not submitting the results.
This commit is contained in:
parent
190bf87979
commit
c8368dbe2d
3 changed files with 210 additions and 86 deletions
|
@ -6,23 +6,27 @@ import java.lang.reflect.Method;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.apache.commons.lang.StringEscapeUtils;
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vedit.beans.EditProcessObject;
|
import edu.cornell.mannlib.vedit.beans.EditProcessObject;
|
||||||
import edu.cornell.mannlib.vedit.beans.FormObject;
|
import edu.cornell.mannlib.vedit.beans.FormObject;
|
||||||
import edu.cornell.mannlib.vedit.beans.Option;
|
import edu.cornell.mannlib.vedit.beans.Option;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
|
||||||
public class FormUtils {
|
public class FormUtils {
|
||||||
|
@ -247,6 +251,35 @@ public class FormUtils {
|
||||||
}
|
}
|
||||||
return vclassOptionList;
|
return vclassOptionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Option> makeOptionListOfSubVClasses(
|
||||||
|
WebappDaoFactory wadf, String parentVClassUri,
|
||||||
|
String selectedVClassURI) {
|
||||||
|
VClassDao vClassDao = wadf.getVClassDao();
|
||||||
|
|
||||||
|
Set<String> uris = new HashSet<>(vClassDao.getAllSubClassURIs(parentVClassUri));
|
||||||
|
uris.add(parentVClassUri);
|
||||||
|
|
||||||
|
List<Option> options = new LinkedList<>();
|
||||||
|
for (String vclassUri: uris) {
|
||||||
|
VClass vclass = vClassDao.getVClassByURI(vclassUri);
|
||||||
|
Option option = new Option();
|
||||||
|
option.setValue(vclass.getURI());
|
||||||
|
option.setBody(vclass.getPickListName());
|
||||||
|
options.add(option);
|
||||||
|
if(Objects.equals(selectedVClassURI, vclass.getURI())) {
|
||||||
|
option.setSelected(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(options, new Comparator<Option>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Option o1, Option o2) {
|
||||||
|
return o1.getBody().compareTo(o2.getBody());
|
||||||
|
}});
|
||||||
|
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
public static void beanSet(Object newObj, String field, String value) {
|
public static void beanSet(Object newObj, String field, String value) {
|
||||||
beanSet (newObj, field, value, null);
|
beanSet (newObj, field, value, null);
|
||||||
|
|
|
@ -2,7 +2,11 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.controller.edit;
|
package edu.cornell.mannlib.vitro.webapp.controller.edit;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.RequestDispatcher;
|
import javax.servlet.RequestDispatcher;
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
@ -14,14 +18,17 @@ import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vedit.beans.EditProcessObject;
|
import edu.cornell.mannlib.vedit.beans.EditProcessObject;
|
||||||
import edu.cornell.mannlib.vedit.beans.FormObject;
|
import edu.cornell.mannlib.vedit.beans.FormObject;
|
||||||
|
import edu.cornell.mannlib.vedit.beans.Option;
|
||||||
import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
||||||
import edu.cornell.mannlib.vedit.util.FormUtils;
|
import edu.cornell.mannlib.vedit.util.FormUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionListener;
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionListener;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.FauxProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.FauxProperty;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.FauxPropertyDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.FauxPropertyDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
|
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,8 +37,7 @@ import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
|
||||||
public class FauxPropertyRetryController extends BaseEditController {
|
public class FauxPropertyRetryController extends BaseEditController {
|
||||||
private static final Log log = LogFactory
|
private static final Log log = LogFactory
|
||||||
.getLog(FauxPropertyRetryController.class);
|
.getLog(FauxPropertyRetryController.class);
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doPost(HttpServletRequest req, HttpServletResponse response) {
|
public void doPost(HttpServletRequest req, HttpServletResponse response) {
|
||||||
if (!isAuthorizedToDisplayPage(req, response,
|
if (!isAuthorizedToDisplayPage(req, response,
|
||||||
|
@ -39,93 +45,32 @@ public class FauxPropertyRetryController extends BaseEditController {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
VitroRequest request = new VitroRequest(req);
|
|
||||||
|
|
||||||
// create an EditProcessObject for this and put it in the session
|
// create an EditProcessObject for this and put it in the session
|
||||||
EditProcessObject epo = super.createEpo(request);
|
EditProcessObject epo = super.createEpo(req);
|
||||||
|
|
||||||
ServletContext ctx = getServletContext();
|
// Populate it.
|
||||||
|
EpoPopulator populator = new EpoPopulator(req, epo);
|
||||||
|
populator.populate();
|
||||||
|
|
||||||
FauxPropertyDao fpDao = ModelAccess.on(ctx).getWebappDaoFactory()
|
req.setAttribute("bodyJsp", "/templates/edit/formBasic.jsp");
|
||||||
.getFauxPropertyDao();
|
req.setAttribute("colspan", "5");
|
||||||
epo.setDataAccessObject(fpDao);
|
req.setAttribute("formJsp",
|
||||||
|
"/templates/edit/specific/fauxProperty_retry.jsp");
|
||||||
|
req.setAttribute("scripts", "/templates/edit/formBasic.js");
|
||||||
|
req.setAttribute("title", "Faux Property Editing Form");
|
||||||
|
req.setAttribute("_action", epo.getAction());
|
||||||
|
setRequestAttributes(req, epo);
|
||||||
|
|
||||||
FauxProperty fpForEditing = null;
|
try {
|
||||||
if (epo.getUseRecycledBean()) {
|
RequestDispatcher rd = req
|
||||||
fpForEditing = (FauxProperty) epo.getNewBean();
|
.getRequestDispatcher(Controllers.BASIC_JSP);
|
||||||
} else {
|
rd.forward(req, response);
|
||||||
String create = request.getParameter("create");
|
} catch (Exception e) {
|
||||||
String baseUri = request.getParameter("baseUri");
|
log.error("Could not forward to view.");
|
||||||
String rangeUri = request.getParameter("rangeUri");
|
log.error(e.getMessage());
|
||||||
String domainUri = request.getParameter("domainUri");
|
log.error(e.getStackTrace());
|
||||||
if (create != null) {
|
|
||||||
fpForEditing = new FauxProperty(null, baseUri, null);
|
|
||||||
epo.setAction("insert");
|
|
||||||
} else {
|
|
||||||
fpForEditing = fpDao.getFauxPropertyByUris(domainUri, baseUri,
|
|
||||||
rangeUri);
|
|
||||||
if (fpForEditing == null) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"FauxProperty does not exist for <" + domainUri
|
|
||||||
+ "> ==> <" + baseUri + "> ==> <"
|
|
||||||
+ rangeUri + ">");
|
|
||||||
}
|
|
||||||
epo.setAction("update");
|
|
||||||
}
|
|
||||||
epo.setOriginalBean(fpForEditing);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set any validators
|
|
||||||
// TODO NONE YET
|
|
||||||
|
|
||||||
// set up any listeners
|
|
||||||
epo.setChangeListenerList(Collections
|
|
||||||
.singletonList(new PropertyRestrictionListener(ctx)));
|
|
||||||
|
|
||||||
// where should the postinsert pageforwarder go?
|
|
||||||
// TODO
|
|
||||||
// make a postdelete pageforwarder that will send us to the control
|
|
||||||
// panel for the base property.
|
|
||||||
// TODO
|
|
||||||
|
|
||||||
FormObject foo = new FormObject();
|
|
||||||
foo.setErrorMap(epo.getErrMsgMap());
|
|
||||||
|
|
||||||
// We will need to set a lot of option lists and stuff.
|
|
||||||
// TODO
|
|
||||||
|
|
||||||
// Put attributes on the request so the JSP can populate the fields.
|
|
||||||
// request.setAttribute("transitive",propertyForEditing.getTransitive());
|
|
||||||
// request.setAttribute("objectIndividualSortPropertyURI",
|
|
||||||
// propertyForEditing.getObjectIndividualSortPropertyURI());
|
|
||||||
// TODO
|
|
||||||
|
|
||||||
// checkboxes are pretty annoying : we don't know if someone *unchecked*
|
|
||||||
// a box, so we have to default to false on updates.
|
|
||||||
// propertyForEditing.setSymmetric(false);
|
|
||||||
// TODO
|
|
||||||
|
|
||||||
epo.setFormObject(foo);
|
|
||||||
|
|
||||||
FormUtils.populateFormFromBean(fpForEditing, epo.getAction(), foo,
|
|
||||||
epo.getBadValueMap());
|
|
||||||
|
|
||||||
RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
|
|
||||||
request.setAttribute("bodyJsp","/templates/edit/formBasic.jsp");
|
|
||||||
request.setAttribute("colspan","5");
|
|
||||||
request.setAttribute("formJsp","/templates/edit/specific/fauxProperty_retry.jsp");
|
|
||||||
request.setAttribute("scripts","/templates/edit/formBasic.js");
|
|
||||||
request.setAttribute("title","Faux Property Editing Form");
|
|
||||||
request.setAttribute("_action",epo.getAction());
|
|
||||||
setRequestAttributes(request,epo);
|
|
||||||
|
|
||||||
try {
|
|
||||||
rd.forward(request, response);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Could not forward to view.");
|
|
||||||
log.error(e.getMessage());
|
|
||||||
log.error(e.getStackTrace());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -133,4 +78,140 @@ public class FauxPropertyRetryController extends BaseEditController {
|
||||||
doPost(request, response);
|
doPost(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class EpoPopulator {
|
||||||
|
private final VitroRequest req;
|
||||||
|
private final ServletContext ctx;
|
||||||
|
private final EditProcessObject epo;
|
||||||
|
|
||||||
|
private final FauxPropertyDao fpDao;
|
||||||
|
|
||||||
|
private FauxProperty beanForEditing;
|
||||||
|
private Property baseProperty;
|
||||||
|
|
||||||
|
EpoPopulator(HttpServletRequest req, EditProcessObject epo) {
|
||||||
|
this.req = new VitroRequest(req);
|
||||||
|
this.ctx = req.getSession().getServletContext();
|
||||||
|
|
||||||
|
this.epo = epo;
|
||||||
|
|
||||||
|
this.fpDao = ModelAccess.on(ctx).getWebappDaoFactory()
|
||||||
|
.getFauxPropertyDao();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void populate() {
|
||||||
|
epo.setDataAccessObject(fpDao);
|
||||||
|
epo.setAction(determineAction());
|
||||||
|
|
||||||
|
if (epo.getUseRecycledBean()) {
|
||||||
|
beanForEditing = (FauxProperty) epo.getNewBean();
|
||||||
|
} else {
|
||||||
|
beanForEditing = locateBeanForEditing();
|
||||||
|
epo.setOriginalBean(beanForEditing);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.baseProperty = req.getUnfilteredWebappDaoFactory()
|
||||||
|
.getObjectPropertyDao()
|
||||||
|
.getObjectPropertyByURI(beanForEditing.getURI());
|
||||||
|
|
||||||
|
doABunchOfOtherJunk();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String determineAction() {
|
||||||
|
return (req.getParameter("create") == null) ? "update" : "insert";
|
||||||
|
}
|
||||||
|
|
||||||
|
private FauxProperty locateBeanForEditing() {
|
||||||
|
String baseUri = req.getParameter("baseUri");
|
||||||
|
String rangeUri = req.getParameter("rangeUri");
|
||||||
|
String domainUri = req.getParameter("domainUri");
|
||||||
|
|
||||||
|
if (epo.getAction().equals("insert")) {
|
||||||
|
return new FauxProperty(null, baseUri, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
FauxProperty bean = fpDao.getFauxPropertyByUris(domainUri, baseUri,
|
||||||
|
rangeUri);
|
||||||
|
if (bean == null) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"FauxProperty does not exist for <" + domainUri
|
||||||
|
+ "> ==> <" + baseUri + "> ==> <" + rangeUri
|
||||||
|
+ ">");
|
||||||
|
}
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doABunchOfOtherJunk() {
|
||||||
|
// set any validators
|
||||||
|
// TODO NONE YET
|
||||||
|
|
||||||
|
// set up any listeners
|
||||||
|
epo.setChangeListenerList(Collections
|
||||||
|
.singletonList(new PropertyRestrictionListener(ctx)));
|
||||||
|
|
||||||
|
// where should the postinsert pageforwarder go?
|
||||||
|
// TODO
|
||||||
|
// make a postdelete pageforwarder that will send us to the control
|
||||||
|
// panel for the base property.
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
FormObject foo = new FormObject();
|
||||||
|
foo.setErrorMap(epo.getErrMsgMap());
|
||||||
|
|
||||||
|
foo.setOptionLists(new HashMap<>(createOptionsMap()));
|
||||||
|
|
||||||
|
// We will need to set a lot of option lists and stuff.
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
// Put attributes on the request so the JSP can populate the fields.
|
||||||
|
// request.setAttribute("transitive",propertyForEditing.getTransitive());
|
||||||
|
// request.setAttribute("objectIndividualSortPropertyURI",
|
||||||
|
// propertyForEditing.getObjectIndividualSortPropertyURI());
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
// checkboxes are pretty annoying : we don't know if someone
|
||||||
|
// *unchecked*
|
||||||
|
// a box, so we have to default to false on updates.
|
||||||
|
// propertyForEditing.setSymmetric(false);
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
epo.setFormObject(foo);
|
||||||
|
|
||||||
|
FormUtils.populateFormFromBean(beanForEditing, epo.getAction(),
|
||||||
|
foo, epo.getBadValueMap());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, List<Option>> createOptionsMap() {
|
||||||
|
Map<String, List<Option>> map = new HashMap<>();
|
||||||
|
map.put("DomainVClassURI",
|
||||||
|
createRootedVClassOptionList(
|
||||||
|
baseProperty.getDomainVClassURI(),
|
||||||
|
beanForEditing.getDomainURI()));
|
||||||
|
map.put("RangeVClassURI",
|
||||||
|
createRootedVClassOptionList(
|
||||||
|
baseProperty.getRangeVClassURI(),
|
||||||
|
beanForEditing.getRangeURI()));
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Option> createRootedVClassOptionList(String rootVClassUri,
|
||||||
|
String currentSelection) {
|
||||||
|
WebappDaoFactory wadf = req.getUnfilteredWebappDaoFactory();
|
||||||
|
|
||||||
|
List<Option> list = new ArrayList<>();
|
||||||
|
list.add(new Option("", "(none specified)"));
|
||||||
|
|
||||||
|
if (rootVClassUri == null) {
|
||||||
|
list.addAll(FormUtils.makeVClassOptionList(wadf,
|
||||||
|
currentSelection));
|
||||||
|
} else {
|
||||||
|
list.addAll(FormUtils.makeOptionListOfSubVClasses(wadf,
|
||||||
|
rootVClassUri, currentSelection));
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,4 +3,14 @@
|
||||||
<%@ taglib prefix="form" uri="http://vitro.mannlib.cornell.edu/edit/tags" %>
|
<%@ taglib prefix="form" uri="http://vitro.mannlib.cornell.edu/edit/tags" %>
|
||||||
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
|
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
|
||||||
|
|
||||||
<h1>Like, TOTALLY BOGUS.</h1>
|
<tr><td colspan="5"><hr class="formDivider"/></td></tr>
|
||||||
|
<tr class="editformcell">
|
||||||
|
<td valign="top" colspan="2">
|
||||||
|
<b>Domain class</b><br />
|
||||||
|
<select name="DomainVClassURI"><form:option name="DomainVClassURI"/></select>
|
||||||
|
</td>
|
||||||
|
<td valign="top" colspan="2">
|
||||||
|
<b>Range class</b><br />
|
||||||
|
<select name="RangeVClassURI" ><form:option name="RangeVClassURI"/></select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
Loading…
Add table
Reference in a new issue