Produce the pick-lists for range and domain.

Still not submitting the results.
This commit is contained in:
Jim Blake 2014-11-03 15:09:43 -05:00
parent 190bf87979
commit c8368dbe2d
3 changed files with 210 additions and 86 deletions

View file

@ -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 {
@ -248,6 +252,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);
} }

View file

@ -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;
/** /**
@ -31,7 +38,6 @@ 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,42 +45,103 @@ 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");
req.setAttribute("colspan", "5");
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);
try {
RequestDispatcher rd = req
.getRequestDispatcher(Controllers.BASIC_JSP);
rd.forward(req, response);
} catch (Exception e) {
log.error("Could not forward to view.");
log.error(e.getMessage());
log.error(e.getStackTrace());
}
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse 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(); .getFauxPropertyDao();
epo.setDataAccessObject(fpDao);
FauxProperty fpForEditing = null; }
void populate() {
epo.setDataAccessObject(fpDao);
epo.setAction(determineAction());
if (epo.getUseRecycledBean()) { if (epo.getUseRecycledBean()) {
fpForEditing = (FauxProperty) epo.getNewBean(); beanForEditing = (FauxProperty) epo.getNewBean();
} else { } else {
String create = request.getParameter("create"); beanForEditing = locateBeanForEditing();
String baseUri = request.getParameter("baseUri"); epo.setOriginalBean(beanForEditing);
String rangeUri = request.getParameter("rangeUri"); }
String domainUri = request.getParameter("domainUri");
if (create != null) { this.baseProperty = req.getUnfilteredWebappDaoFactory()
fpForEditing = new FauxProperty(null, baseUri, null); .getObjectPropertyDao()
epo.setAction("insert"); .getObjectPropertyByURI(beanForEditing.getURI());
} else {
fpForEditing = fpDao.getFauxPropertyByUris(domainUri, baseUri, 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); rangeUri);
if (fpForEditing == null) { if (bean == null) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"FauxProperty does not exist for <" + domainUri "FauxProperty does not exist for <" + domainUri
+ "> ==> <" + baseUri + "> ==> <" + "> ==> <" + baseUri + "> ==> <" + rangeUri
+ rangeUri + ">"); + ">");
} }
epo.setAction("update"); return bean;
}
epo.setOriginalBean(fpForEditing);
} }
private void doABunchOfOtherJunk() {
// set any validators // set any validators
// TODO NONE YET // TODO NONE YET
@ -91,6 +158,8 @@ public class FauxPropertyRetryController extends BaseEditController {
FormObject foo = new FormObject(); FormObject foo = new FormObject();
foo.setErrorMap(epo.getErrMsgMap()); foo.setErrorMap(epo.getErrMsgMap());
foo.setOptionLists(new HashMap<>(createOptionsMap()));
// We will need to set a lot of option lists and stuff. // We will need to set a lot of option lists and stuff.
// TODO // TODO
@ -100,37 +169,49 @@ public class FauxPropertyRetryController extends BaseEditController {
// propertyForEditing.getObjectIndividualSortPropertyURI()); // propertyForEditing.getObjectIndividualSortPropertyURI());
// TODO // TODO
// checkboxes are pretty annoying : we don't know if someone *unchecked* // checkboxes are pretty annoying : we don't know if someone
// *unchecked*
// a box, so we have to default to false on updates. // a box, so we have to default to false on updates.
// propertyForEditing.setSymmetric(false); // propertyForEditing.setSymmetric(false);
// TODO // TODO
epo.setFormObject(foo); epo.setFormObject(foo);
FormUtils.populateFormFromBean(fpForEditing, epo.getAction(), foo, FormUtils.populateFormFromBean(beanForEditing, epo.getAction(),
epo.getBadValueMap()); foo, epo.getBadValueMap());
}
RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
request.setAttribute("bodyJsp","/templates/edit/formBasic.jsp"); private Map<String, List<Option>> createOptionsMap() {
request.setAttribute("colspan","5"); Map<String, List<Option>> map = new HashMap<>();
request.setAttribute("formJsp","/templates/edit/specific/fauxProperty_retry.jsp"); map.put("DomainVClassURI",
request.setAttribute("scripts","/templates/edit/formBasic.js"); createRootedVClassOptionList(
request.setAttribute("title","Faux Property Editing Form"); baseProperty.getDomainVClassURI(),
request.setAttribute("_action",epo.getAction()); beanForEditing.getDomainURI()));
setRequestAttributes(request,epo); map.put("RangeVClassURI",
createRootedVClassOptionList(
try { baseProperty.getRangeVClassURI(),
rd.forward(request, response); beanForEditing.getRangeURI()));
} catch (Exception e) { return map;
log.error("Could not forward to view."); }
log.error(e.getMessage());
log.error(e.getStackTrace()); 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;
} }
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) {
doPost(request, response);
} }
} }

View file

@ -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>