Merge pull request #914 from tuub/DS-1965

DS-1965: Adds date fields to the form used to edit policies (JSPUI).
This commit is contained in:
Andrea Schweer
2015-05-15 10:29:35 +12:00
3 changed files with 70 additions and 24 deletions

View File

@@ -289,6 +289,8 @@ jsp.dspace-admin.general.eperson = EPerson
jsp.dspace-admin.general.group = Group
jsp.dspace-admin.general.group-colon = Group:
jsp.dspace-admin.general.next.button = Next >
jsp.dspace-admin.general.policy-end-date-colon = End Date:
jsp.dspace-admin.general.policy-start-date-colon = Start Date:
jsp.dspace-admin.general.remove = Remove
jsp.dspace-admin.general.save = Save
jsp.dspace-admin.general.update = Update

View File

@@ -9,6 +9,7 @@ package org.dspace.app.webui.servlet.admin;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -16,6 +17,7 @@ import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.time.DateUtils;
import org.dspace.app.util.AuthorizeUtil;
import org.dspace.app.webui.servlet.DSpaceServlet;
@@ -493,6 +495,20 @@ public class AuthorizeAdminServlet extends DSpaceServlet
.getIntParameter(request, "collection_id");
int communityId = UIUtil.getIntParameter(request, "community_id");
int itemId = UIUtil.getIntParameter(request, "item_id");
Date startDate = null;
try {
startDate = DateUtils.parseDate(request.getParameter("policy_start_date"),
new String[]{"yyyy-MM-dd", "yyyy-MM", "yyyy"});
} catch (Exception ex) {
//Ignore start date is already null
}
Date endDate = null;
try {
endDate = DateUtils.parseDate(request.getParameter("policy_end_date"),
new String[]{"yyyy-MM-dd", "yyyy-MM", "yyyy"});
} catch (Exception ex) {
//Ignore end date is already null
}
Item item = null;
Collection collection = null;
@@ -574,6 +590,11 @@ public class AuthorizeAdminServlet extends DSpaceServlet
// modify the policy
policy.setAction(actionId);
policy.setGroup(group);
// start and end dates are used for Items and Bitstreams only.
// Set start and end date even if they are null to be able to
// delete previously set dates.
policy.setStartDate(startDate);
policy.setEndDate(endDate);
policy.update();
// show edit form!

View File

@@ -8,6 +8,7 @@
--%>
<%@page import="org.apache.commons.lang.time.DateFormatUtils"%>
<%--
- policy editor - for new or existing policies
-
@@ -25,8 +26,8 @@
- "id_name" - name/value passed in from id_name/id above
- group_id - set if user selected a group
- eperson_id - set if user selected an eperson
- start_date - not set, unused
- end_date - not set, unused
- start_date - start date of a policy (e.g. for embargo feature)
- end_date - end date of a policy
- action_id - set to whatever user chose
- (new policy) - set to a the string passed in above if policy is a new one
--%>
@@ -81,10 +82,10 @@
<form action="<%= request.getContextPath() %>/tools/authorize" method="post">
<div class="input-group">
<span class="col-md-2">
<%-- <td>Group:</td> --%>
<label for="tgroup_id"><fmt:message key="jsp.dspace-admin.general.group-colon"/></label>
<div class="input-group">
<span class="col-md-2">
<%-- <td>Group:</td> --%>
<label for="tgroup_id"><fmt:message key="jsp.dspace-admin.general.group-colon"/></label>
</span>
<span class="col-md-10">
<select class="form-control" size="15" name="group_id" id="tgroup_id">
@@ -101,24 +102,46 @@
<label for="taction_id"><fmt:message key="jsp.dspace-admin.general.action-colon"/></label>
</span>
<span class="col-md-10">
<input type="hidden" name="<%=id_name%>" value="<%=id%>" />
<input type="hidden" name="policy_id" value="<%=policy.getID()%>" />
<select class="form-control" name="action_id" id="taction_id">
<% for( int i = 0; i < Constants.actionText.length; i++ )
{
// only display if action i is relevant
// to resource type resourceRelevance
if( (Constants.actionTypeRelevance[i]&resourceRelevance) > 0)
{ %>
<option value="<%= i %>"
<%=(policy.getAction() == i ? "selected=\"selected\"" : "")%>>
<%= Constants.actionText[i]%>
</option>
<% }
} %>
</select>
</span>
</div>
<input type="hidden" name="<%=id_name%>" value="<%=id%>" />
<input type="hidden" name="policy_id" value="<%=policy.getID()%>" />
<select class="form-control" name="action_id" id="taction_id">
<% for( int i = 0; i < Constants.actionText.length; i++ )
{
// only display if action i is relevant
// to resource type resourceRelevance
if( (Constants.actionTypeRelevance[i]&resourceRelevance) > 0)
{ %>
<option value="<%= i %>"
<%=(policy.getAction() == i ? "selected=\"selected\"" : "")%>>
<%= Constants.actionText[i]%>
</option>
<% }
} %>
</select>
</span>
<%
// start and end dates are used for Items and Bitstreams only.
if (resourceType == Constants.ITEM || resourceType == Constants.BITSTREAM)
{
%>
<!-- policy start date -->
<span class="col-md-2">
<label for="t_start_date_id"><fmt:message key="jsp.dspace-admin.general.policy-start-date-colon"/></label>
</span>
<span class="col-md-10">
<input class="form-control" name="policy_start_date" maxlength="10" size="10" type="text"
value="<%= policy.getStartDate() != null ? DateFormatUtils.format(policy.getStartDate(), "yyyy-MM-dd") : "" %>" />
</span>
<!-- policy end date -->
<span class="col-md-2">
<label for="t_end_date_id"><fmt:message key="jsp.dspace-admin.general.policy-end-date-colon"/></label>
</span>
<span class="col-md-10">
<input class="form-control" name="policy_end_date" maxlength="10" size="10" type="text"
value="<%= policy.getEndDate() != null ? DateFormatUtils.format(policy.getEndDate(), "yyyy-MM-dd") : "" %>" />
</span>
<%} // if Item||Bitstream%>
</div>
<% if( newpolicy != null ) { %> <input name="newpolicy" type="hidden" value="<%=newpolicy%>"/> <% } %>
<div class="btn-group pull-right col-md-2">