Commit df5b942136f4d5095d32b857244ae97c2e8ed56e

Authored by Tiago Guimarães
1 parent 6e0b3946c7
Exists in DSpace52++

Only Restricted after workflow tasks

dspace-api/src/main/java/org/dspace/workflow/WorkflowManager.java
... ... @@ -43,6 +43,7 @@ import org.dspace.storage.rdbms.TableRow;
43 43 import org.dspace.storage.rdbms.TableRowIterator;
44 44 import org.dspace.usage.UsageWorkflowEvent;
45 45 import org.dspace.utils.DSpace;
  46 +import pt.uminho.sdum.submit.RestrictAccess;
46 47  
47 48 /**
48 49 * Workflow state machine
... ... @@ -722,6 +723,7 @@ public class WorkflowManager
722 723 + collection.getID()));
723 724  
724 725 InstallItem.installItem(c, wfi);
  726 + RestrictAccess.restrictItemAccess(c,item);
725 727  
726 728 // Log the event
727 729 log.info(LogManager.getHeader(c, "install_item", "workflow_id="
... ...
dspace-api/src/main/java/pt/uminho/sdum/submit/RestrictAccess.java
... ... @@ -0,0 +1,66 @@
  1 +package pt.uminho.sdum.submit;
  2 +
  3 +import org.dspace.authorize.AuthorizeException;
  4 +import org.dspace.authorize.AuthorizeManager;
  5 +import org.dspace.authorize.ResourcePolicy;
  6 +import org.dspace.content.Bitstream;
  7 +import org.dspace.content.Bundle;
  8 +import org.dspace.content.Item;
  9 +import org.dspace.core.Context;
  10 +import org.dspace.eperson.Group;
  11 +
  12 +import java.sql.SQLException;
  13 +import java.text.ParseException;
  14 +import java.text.SimpleDateFormat;
  15 +import java.util.Date;
  16 +
  17 +/**
  18 + * Created by tmmguimaraes on 25/07/2016.
  19 + */
  20 +public class RestrictAccess {
  21 +
  22 + private static final Date date = policyDate();
  23 +
  24 + private static Date policyDate(){
  25 + Date d = null;
  26 + try {
  27 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
  28 + d = sdf.parse("9999");
  29 + } catch (ParseException e) {
  30 + e.printStackTrace();
  31 + }
  32 + return d;
  33 + }
  34 +
  35 +
  36 +
  37 + public static void restrictItemAccess(Context context,Item item){
  38 +
  39 + if(item.getMetadata("dc.rights").equals("restrictedAccess")
  40 + || item.getMetadata("dc.rights").equals("closedAccess")) {
  41 +
  42 + Group anonGroup = null;
  43 + try {
  44 + anonGroup = Group.find(context, Group.ANONYMOUS_ID);
  45 +
  46 + for (Bundle b : item.getBundles()) {
  47 + if(b.getName().startsWith("ORIG")) {
  48 + AuthorizeManager.removeGroupPolicies(context, b, anonGroup);
  49 + for (Bitstream bit : b.getBitstreams()) {
  50 + for(ResourcePolicy rp: AuthorizeManager.getPolicies(context,bit)) {
  51 + rp.setStartDate(date);
  52 + rp.update();
  53 + }
  54 + }
  55 + }
  56 + }
  57 +
  58 + context.commit();
  59 + } catch (SQLException e) {
  60 + e.printStackTrace();
  61 + } catch (AuthorizeException e) {
  62 + e.printStackTrace();
  63 + }
  64 + }
  65 + }
  66 +}
... ...
dspace-api/src/main/java/pt/uminho/sdum/submit/step/AccessStep.java
... ... @@ -1,64 +0,0 @@
1   -package pt.uminho.sdum.submit.step;
2   -
3   -import org.dspace.app.util.SubmissionInfo;
4   -import org.dspace.authorize.AuthorizeException;
5   -import org.dspace.authorize.AuthorizeManager;
6   -import org.dspace.authorize.ResourcePolicy;
7   -import org.dspace.content.Bitstream;
8   -import org.dspace.content.Bundle;
9   -import org.dspace.content.Item;
10   -import org.dspace.core.Context;
11   -import org.dspace.eperson.Group;
12   -import org.dspace.submit.step.CompleteStep;
13   -
14   -import javax.servlet.ServletException;
15   -import javax.servlet.http.HttpServletRequest;
16   -import javax.servlet.http.HttpServletResponse;
17   -import java.io.IOException;
18   -import java.sql.SQLException;
19   -import java.text.ParseException;
20   -import java.text.SimpleDateFormat;
21   -import java.util.Date;
22   -
23   -/**
24   - * @author tmmguimaraes on 15/04/2016.
25   - */
26   -public class AccessStep extends CompleteStep {
27   -
28   -
29   - @Override
30   - public int doProcessing(Context context, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, SubmissionInfo submissionInfo) throws ServletException, IOException, SQLException, AuthorizeException {
31   - int s = super.doProcessing(context,httpServletRequest,httpServletResponse,submissionInfo);
32   -
33   - Date d = null;
34   - try {
35   - SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
36   - d = sdf.parse("9999");
37   - } catch (ParseException e) {
38   - e.printStackTrace();
39   - }
40   -
41   - Item item = submissionInfo.getSubmissionItem().getItem();
42   - if(item.getMetadata("dc.rights").equals("restrictedAccess")
43   - || item.getMetadata("dc.rights").equals("closedAccess")) {
44   -
45   -
46   -
47   - Group anonGroup = Group.find(context, Group.ANONYMOUS_ID);
48   -
49   - for (Bundle b : item.getBundles()) {
50   - if(b.getName().startsWith("ORIG")) {
51   - AuthorizeManager.removeGroupPolicies(context, b, anonGroup);
52   - for (Bitstream bit : b.getBitstreams()) {
53   - for(ResourcePolicy rp: AuthorizeManager.getPolicies(context,bit)) {
54   - rp.setStartDate(d);
55   - rp.update();
56   - }
57   - }
58   - }
59   - }
60   - context.commit();
61   - }
62   - return s;
63   - }
64   -}
dspace/config/item-submission.xml
... ... @@ -108,7 +108,7 @@
108 108 <!-- a special step, it is currently NEVER editable in a workflow. -->
109 109 <step id="complete">
110 110 <heading>submit.progressbar.complete</heading>
111   - <processing-class>pt.uminho.sdum.submit.step.AccessStep</processing-class>
  111 + <processing-class>org.dspace.submit.step.CompleteStep</processing-class>
112 112 <jspui-binding>org.dspace.app.webui.submit.step.JSPCompleteStep</jspui-binding>
113 113 <workflow-editable>false</workflow-editable>
114 114 </step>
... ...