%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Feature" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.ProjectManagement" %>
<%@ page import="org.crosswire.xml.XMLBlock" %>
<%@ page import="org.crosswire.webtools.annotation.*" %>
<%@ page import="org.crosswire.webtools.*" %>
<%@ page import="javax.validation.constraints.NotNull" %>
<%!
@Description(value = "Delete a feature for a manuscript or manuscript page.", name = "feature/delete")
public static class MyParameters extends Parameters {
@NotNull
@Description(value = "feature ID to delete", example = "123")
public Integer featureID = null;
@Override
protected void customValidation() {
if (getUser() == null) {
addError(-5, "Must be logged in to delete manuscript feature tags.");
return;
}
}
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.getErrors().size() == 0) {
boolean manager = params.getUser().hasRole("VMR Administrator") || params.getUser().hasRole("Feature Manager");
String userName = params.getUser().getUserName();
Feature feature = Feature.getFeature(params.featureID);
do {
if (feature == null) {
params.addError(-6, "featureID: " + params.featureID + " not found.");
break;
}
// special check if we're and Index Manager and we want to edit an indexing feature.
if ("NoIdx".equals(feature.getFeatureCode()) && !manager) {
// In this special case, Index Managers can delete NoIdx features
manager = params.getUser().hasRole("Index Manager");
}
if (feature.getUserID() != null && feature.getUserID().length() > 0 && !feature.getUserID().equals(params.getUser().getUserName()) && !manager) {
String projectName = feature.getFeatureDefinition().getGroupID();
if (projectName != null && projectName.length() > 0) {
ProjectManagement.Project project = ProjectManagement.getProject(projectName);
if (project != null) {
manager = params.getUser().hasRole("Project Editor", project.getProjectName())
|| params.getUser().hasRole("Project Managing Editor", project.getProjectName())
|| params.getUser().hasRole("Project Feature Manager", project.getProjectName());
}
}
if (!manager) {
params.addError(-7, "User does not have the role, Feature Manager. To request change to existing data, consider discussing this feature on the forum.");
break;
}
}
Feature.deleteFeature(feature.getFeatureID());
Serializer.output(response, out, params, XMLBlock.createXMLBlock(""));
return;
} while (false);
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>