From af9820b7f3f970d4890fce518ec98923a5042e32 Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Thu, 18 Feb 2021 18:33:23 +0100 Subject: [PATCH] Added template model, freemarker macro and pass checks in EditRequestDispatchController for individual deletion --- .../EditRequestDispatchController.java | 2 +- .../BaseIndividualTemplateModel.java | 20 +++++++++++++++++++ .../freemarker/lib/lib-properties.ftl | 10 ++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java index 529db4d45..bb6f8292a 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java @@ -360,7 +360,7 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet { String predicateUri = EditConfigurationUtils.getPredicateUri(vreq); String formParam = getFormParam(vreq); //if no form parameter, then predicate uri and subject uri must both be populated - if (formParam == null || "".equals(formParam)) { + if ((formParam == null || "".equals(formParam)) && !isDeleteForm(vreq)) { if ((predicateUri == null || predicateUri.trim().length() == 0)) { return true; } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/BaseIndividualTemplateModel.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/BaseIndividualTemplateModel.java index 8c25395ff..a4d3509a6 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/BaseIndividualTemplateModel.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/BaseIndividualTemplateModel.java @@ -7,6 +7,7 @@ import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.RequestedAct import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.RequestedAction.SOME_URI; import java.util.Collection; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -27,6 +28,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; 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.controller.freemarker.UrlBuilder.Route; import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; @@ -37,6 +39,7 @@ import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel; public abstract class BaseIndividualTemplateModel extends BaseTemplateModel { private static final Log log = LogFactory.getLog(BaseIndividualTemplateModel.class); + private static final String EDIT_PATH = "editRequestDispatch"; protected final Individual individual; protected final LoginStatusBean loginStatusBean; @@ -148,6 +151,23 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel { public String getName() { return individual.getName(); } + + public String getDeleteUrl() { + Collection types = getMostSpecificTypes(); + ParamMap params = new ParamMap( + "objectUri", individual.getURI(), + "cmd", "delete", + "statement_label",getNameStatement().getValue(), + "statement_object",individual.getURI() + ); + Iterator typesIterator = types.iterator(); + if (types.iterator().hasNext()) { + String type = typesIterator.next(); + params.put("statement_type", type); + } + + return UrlBuilder.getUrl(EDIT_PATH, params); + } public Collection getMostSpecificTypes() { ObjectPropertyStatementDao opsDao = vreq.getWebappDaoFactory().getObjectPropertyStatementDao(); diff --git a/webapp/src/main/webapp/templates/freemarker/lib/lib-properties.ftl b/webapp/src/main/webapp/templates/freemarker/lib/lib-properties.ftl index 3e5223fc6..34b00e51c 100644 --- a/webapp/src/main/webapp/templates/freemarker/lib/lib-properties.ftl +++ b/webapp/src/main/webapp/templates/freemarker/lib/lib-properties.ftl @@ -203,6 +203,16 @@ name will be used as the label. --> ${i18n().edit_entry} +<#macro deleteIndividualLink individual redirectUrl="/"> + <#local url = individual.deleteUrl + "&redirectUrl=" + "${redirectUrl}"> + <@showDeleteIndividualLink url /> + + + +<#macro showDeleteIndividualLink url> + ${i18n().delete_entry} + + <#macro deleteLink propertyLocalName propertyName statement rangeUri=""> <#local url = statement.deleteUrl> <#if url?has_content>