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.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vedit.beans.EditProcessObject;
|
||||
import edu.cornell.mannlib.vedit.beans.FormObject;
|
||||
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.dao.VClassDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
|
||||
public class FormUtils {
|
||||
|
@ -248,6 +252,35 @@ public class FormUtils {
|
|||
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) {
|
||||
beanSet (newObj, field, value, null);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,11 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.edit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
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.FormObject;
|
||||
import edu.cornell.mannlib.vedit.beans.Option;
|
||||
import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
||||
import edu.cornell.mannlib.vedit.util.FormUtils;
|
||||
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.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.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.FauxPropertyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
|
||||
|
||||
/**
|
||||
|
@ -31,7 +38,6 @@ public class FauxPropertyRetryController extends BaseEditController {
|
|||
private static final Log log = LogFactory
|
||||
.getLog(FauxPropertyRetryController.class);
|
||||
|
||||
|
||||
@Override
|
||||
public void doPost(HttpServletRequest req, HttpServletResponse response) {
|
||||
if (!isAuthorizedToDisplayPage(req, response,
|
||||
|
@ -39,42 +45,103 @@ public class FauxPropertyRetryController extends BaseEditController {
|
|||
return;
|
||||
}
|
||||
|
||||
VitroRequest request = new VitroRequest(req);
|
||||
|
||||
// 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();
|
||||
epo.setDataAccessObject(fpDao);
|
||||
|
||||
FauxProperty fpForEditing = null;
|
||||
}
|
||||
|
||||
void populate() {
|
||||
epo.setDataAccessObject(fpDao);
|
||||
epo.setAction(determineAction());
|
||||
|
||||
if (epo.getUseRecycledBean()) {
|
||||
fpForEditing = (FauxProperty) epo.getNewBean();
|
||||
beanForEditing = (FauxProperty) epo.getNewBean();
|
||||
} else {
|
||||
String create = request.getParameter("create");
|
||||
String baseUri = request.getParameter("baseUri");
|
||||
String rangeUri = request.getParameter("rangeUri");
|
||||
String domainUri = request.getParameter("domainUri");
|
||||
if (create != null) {
|
||||
fpForEditing = new FauxProperty(null, baseUri, null);
|
||||
epo.setAction("insert");
|
||||
} else {
|
||||
fpForEditing = fpDao.getFauxPropertyByUris(domainUri, baseUri,
|
||||
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 (fpForEditing == null) {
|
||||
if (bean == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"FauxProperty does not exist for <" + domainUri
|
||||
+ "> ==> <" + baseUri + "> ==> <"
|
||||
+ rangeUri + ">");
|
||||
+ "> ==> <" + baseUri + "> ==> <" + rangeUri
|
||||
+ ">");
|
||||
}
|
||||
epo.setAction("update");
|
||||
}
|
||||
epo.setOriginalBean(fpForEditing);
|
||||
return bean;
|
||||
}
|
||||
|
||||
private void doABunchOfOtherJunk() {
|
||||
// set any validators
|
||||
// TODO NONE YET
|
||||
|
||||
|
@ -91,6 +158,8 @@ public class FauxPropertyRetryController extends BaseEditController {
|
|||
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
|
||||
|
||||
|
@ -100,37 +169,49 @@ public class FauxPropertyRetryController extends BaseEditController {
|
|||
// propertyForEditing.getObjectIndividualSortPropertyURI());
|
||||
// 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.
|
||||
// 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());
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) {
|
||||
doPost(request, response);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,4 +3,14 @@
|
|||
<%@ taglib prefix="form" uri="http://vitro.mannlib.cornell.edu/edit/tags" %>
|
||||
<%@ 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