@Override
  public void addPolicies(Context c, List<ResourcePolicy> policies, DSpaceObject dest)
      throws SQLException, AuthorizeException {
    // now add them to the destination object
    List<ResourcePolicy> newPolicies = new LinkedList<>();

    for (ResourcePolicy srp : policies) {
      ResourcePolicy rp = resourcePolicyService.create(c);

      // copy over values
      rp.setdSpaceObject(dest);
      rp.setAction(srp.getAction());
      rp.setEPerson(srp.getEPerson());
      rp.setGroup(srp.getGroup());
      rp.setStartDate(srp.getStartDate());
      rp.setEndDate(srp.getEndDate());
      rp.setRpName(srp.getRpName());
      rp.setRpDescription(srp.getRpDescription());
      rp.setRpType(srp.getRpType());

      // and add policy to list of new policies
      newPolicies.add(rp);
    }

    resourcePolicyService.update(c, newPolicies);
  }
  @Override
  public ResourcePolicy findByTypeIdGroupAction(
      Context c, DSpaceObject dso, Group group, int action, int policyID) throws SQLException {
    List<ResourcePolicy> policies = resourcePolicyService.find(c, dso, group, action, policyID);

    if (CollectionUtils.isNotEmpty(policies)) {
      return policies.iterator().next();
    } else {
      return null;
    }
  }
  @Override
  public List<Group> getAuthorizedGroups(Context c, DSpaceObject o, int actionID)
      throws java.sql.SQLException {
    List<ResourcePolicy> policies = getPoliciesActionFilter(c, o, actionID);

    List<Group> groups = new ArrayList<Group>();
    for (ResourcePolicy resourcePolicy : policies) {
      if (resourcePolicy.getGroup() != null) {
        groups.add(resourcePolicy.getGroup());
      }
    }
    return groups;
  }
 @Override
 public List<String> getEPersonDeleteConstraints(Context context, EPerson ePerson)
     throws SQLException {
   List<String> resultList = new ArrayList<>();
   List<BasicWorkflowItem> workflowItems = workflowItemService.findByOwner(context, ePerson);
   if (CollectionUtils.isNotEmpty(workflowItems)) {
     resultList.add("workflowitem");
   }
   List<TaskListItem> taskListItems = taskListItemService.findByEPerson(context, ePerson);
   if (CollectionUtils.isNotEmpty(taskListItems)) {
     resultList.add("tasklistitem");
   }
   return resultList;
 }
  @Override
  public void inheritPolicies(Context c, DSpaceObject src, DSpaceObject dest)
      throws SQLException, AuthorizeException {
    // find all policies for the source object
    List<ResourcePolicy> policies = getPolicies(c, src);

    // Only inherit non-ADMIN policies (since ADMIN policies are automatically inherited)
    List<ResourcePolicy> nonAdminPolicies = new ArrayList<ResourcePolicy>();
    for (ResourcePolicy rp : policies) {
      if (rp.getAction() != Constants.ADMIN) {
        nonAdminPolicies.add(rp);
      }
    }
    addPolicies(c, nonAdminPolicies, dest);
  }
 @Override
 public List<String> getEPersonDeleteConstraints(Context context, EPerson ePerson)
     throws SQLException {
   List<String> constraints = new ArrayList<String>();
   if (CollectionUtils.isNotEmpty(claimedTaskService.findByEperson(context, ePerson))) {
     constraints.add("cwf_claimtask");
   }
   if (CollectionUtils.isNotEmpty(poolTaskService.findByEPerson(context, ePerson))) {
     constraints.add("cwf_pooltask");
   }
   if (CollectionUtils.isNotEmpty(workflowItemRoleService.findByEPerson(context, ePerson))) {
     constraints.add("cwf_workflowitemrole");
   }
   return constraints;
 }
Beispiel #7
0
  public void addListPolicies(List parent, DSpaceObject dso, Collection owningCollection)
      throws WingException, SQLException {
    if (!isAdvancedFormEnabled) {
      return;
    }
    parent.addLabel(T_head_policies_table);

    java.util.List<ResourcePolicy> resourcePolicies =
        authorizeService.findPoliciesByDSOAndType(context, dso, ResourcePolicy.TYPE_CUSTOM);
    if (resourcePolicies.isEmpty()) {
      parent.addItem(T_no_policies);
      return;
    }

    for (ResourcePolicy rp : resourcePolicies) {
      int id = rp.getID();

      String name = "";
      if (rp.getRpName() != null) name = rp.getRpName();

      String action = resourcePolicyService.getActionText(rp);

      // if it is the default policy for the Submitter don't show it.
      if (dso instanceof org.dspace.content.Item) {
        org.dspace.content.Item item = (org.dspace.content.Item) dso;
        if (rp.getEPerson() != null) {
          if (item.getSubmitter().equals(rp.getEPerson())) continue;
        }
      }

      String group = "";
      if (rp.getGroup() != null) group = rp.getGroup().getName();

      // start
      String startDate = "";
      if (rp.getStartDate() != null) {
        startDate = DateFormatUtils.format(rp.getStartDate(), "yyyy-MM-dd");
      }

      // endDate
      String endDate = "";
      if (rp.getEndDate() != null) {
        endDate = DateFormatUtils.format(rp.getEndDate(), "yyyy-MM-dd");
      }

      parent.addItem(T_policy.parameterize(name, action, group, startDate, endDate));
    }
  }
 protected void grantSubmitterReadPolicies(Context context, Item item)
     throws SQLException, AuthorizeException {
   // A list of policies the user has for this item
   List<Integer> userHasPolicies = new ArrayList<Integer>();
   List<ResourcePolicy> itempols = authorizeService.getPolicies(context, item);
   EPerson submitter = item.getSubmitter();
   for (ResourcePolicy resourcePolicy : itempols) {
     if (submitter.equals(resourcePolicy.getEPerson())) {
       // The user has already got this policy so add it to the list
       userHasPolicies.add(resourcePolicy.getAction());
     }
   }
   // Make sure we don't add duplicate policies
   if (!userHasPolicies.contains(Constants.READ))
     addPolicyToItem(context, item, Constants.READ, submitter);
 }
 protected void grantGroupAllItemPolicies(Context context, Item item, Group group)
     throws AuthorizeException, SQLException {
   if (group != null) {
     // A list of policies the user has for this item
     List<Integer> groupHasPolicies = new ArrayList<Integer>();
     List<ResourcePolicy> itempols = authorizeService.getPolicies(context, item);
     for (ResourcePolicy resourcePolicy : itempols) {
       if (group.equals(resourcePolicy.getGroup())) {
         // The user has already got this policy so it it to the list
         groupHasPolicies.add(resourcePolicy.getAction());
       }
     }
     // Make sure we don't add duplicate policies
     if (!groupHasPolicies.contains(Constants.READ))
       addGroupPolicyToItem(context, item, Constants.READ, group);
     if (!groupHasPolicies.contains(Constants.WRITE))
       addGroupPolicyToItem(context, item, Constants.WRITE, group);
     if (!groupHasPolicies.contains(Constants.DELETE))
       addGroupPolicyToItem(context, item, Constants.DELETE, group);
     if (!groupHasPolicies.contains(Constants.ADD))
       addGroupPolicyToItem(context, item, Constants.ADD, group);
     if (!groupHasPolicies.contains(Constants.REMOVE))
       addGroupPolicyToItem(context, item, Constants.REMOVE, group);
   }
 }
Beispiel #10
0
  public void addName(String name_, List form, int errorFlag) throws WingException {
    if (isAdvancedFormEnabled) {
      Text name = form.addItem().addText("name");
      name.setSize(0, 30);
      name.setLabel(T_name);
      name.setHelp(T_name_help);

      if (name_ != null && errorFlag != org.dspace.submit.step.AccessStep.STATUS_COMPLETE)
        name.setValue(name_);
    }
  }
Beispiel #11
0
  public void addReason(String reason_, List form, int errorFlag) throws WingException {
    TextArea reason = form.addItem("reason", null).addTextArea("reason");
    reason.setLabel(T_reason);
    reason.setHelp(T_reason_help);

    if (!isAdvancedFormEnabled) {
      if (globalReason != null) reason.setValue(globalReason);
    } else {
      if (reason_ != null && errorFlag != org.dspace.submit.step.AccessStep.STATUS_COMPLETE)
        reason.setValue(reason_);
    }
  }
Beispiel #12
0
  public void addListGroups(String groupID, List form, int errorFlag, Collection owningCollection)
      throws WingException, SQLException {

    if (isAdvancedFormEnabled) {
      // currently set group
      form.addLabel(T_groups);
      Select groupSelect = form.addItem().addSelect("group_id");
      groupSelect.setMultiple(false);

      java.util.List<Group> loadedGroups = null;

      // retrieve groups
      String name = ConfigurationManager.getProperty("webui.submission.restrictstep.groups");
      if (name != null) {
        Group uiGroup = groupService.findByName(context, name);
        if (uiGroup != null) loadedGroups = uiGroup.getMemberGroups();
      }
      if (loadedGroups == null || loadedGroups.size() == 0) {
        loadedGroups = groupService.findAll(context, GroupService.NAME);
      }

      // if no group selected for default set anonymous
      if (groupID == null || groupID.equals("")) groupID = "0";
      // when we're just loading the main step, also default to anonymous
      if (errorFlag == AccessStep.STATUS_COMPLETE) {
        groupID = "0";
      }
      for (Group group : loadedGroups) {
        boolean selectGroup = group.getID().toString().equals(groupID);
        groupSelect.addOption(selectGroup, group.getID().toString(), group.getName());
      }

      if (errorFlag == AccessStep.STATUS_DUPLICATED_POLICY
          || errorFlag == AccessStep.EDIT_POLICY_STATUS_DUPLICATED_POLICY
          || errorFlag == UploadWithEmbargoStep.STATUS_EDIT_POLICIES_DUPLICATED_POLICY
          || errorFlag == UploadWithEmbargoStep.STATUS_EDIT_POLICY_DUPLICATED_POLICY) {
        groupSelect.addError(T_error_duplicated_policy);
      }
    }
  }
  /**
   * notify the submitter that the item is archived
   *
   * @param context The relevant DSpace Context.
   * @param item which item was archived
   * @param coll collection name to display in template
   * @throws SQLException An exception that provides information on a database access error or other
   *     errors.
   * @throws IOException A general class of exceptions produced by failed or interrupted I/O
   *     operations.
   */
  protected void notifyOfArchive(Context context, Item item, Collection coll)
      throws SQLException, IOException {
    try {
      // Get submitter
      EPerson ep = item.getSubmitter();
      // Get the Locale
      Locale supportedLocale = I18nUtil.getEPersonLocale(ep);
      Email email = Email.getEmail(I18nUtil.getEmailFilename(supportedLocale, "submit_archive"));

      // Get the item handle to email to user
      String handle = handleService.findHandle(context, item);

      // Get title
      List<MetadataValue> titles =
          itemService.getMetadata(item, MetadataSchema.DC_SCHEMA, "title", null, Item.ANY);
      String title = "";
      try {
        title = I18nUtil.getMessage("org.dspace.workflow.WorkflowManager.untitled");
      } catch (MissingResourceException e) {
        title = "Untitled";
      }
      if (titles.size() > 0) {
        title = titles.iterator().next().getValue();
      }

      email.addRecipient(ep.getEmail());
      email.addArgument(title);
      email.addArgument(coll.getName());
      email.addArgument(handleService.getCanonicalForm(handle));

      email.send();
    } catch (MessagingException e) {
      log.warn(
          LogManager.getHeader(
              context, "notifyOfArchive", "cannot email user" + " item_id=" + item.getID()));
    }
  }
Beispiel #14
0
  public void addEmbargoDateSimpleForm(DSpaceObject dso, List form, int errorFlag)
      throws SQLException, WingException {

    String date = null;

    if (dso != null) {
      java.util.List<ResourcePolicy> policies =
          authorizeService.findPoliciesByDSOAndType(context, dso, ResourcePolicy.TYPE_CUSTOM);
      if (policies.size() > 0) {
        ResourcePolicy rp = policies.get(0);
        if (rp.getStartDate() != null) {
          date = DateFormatUtils.format(rp.getStartDate(), "yyyy-MM-dd");
        }
        globalReason = rp.getRpDescription();
      }
    }
    //        CheckBox privateCheckbox = form.addItem().addCheckBox("emabrgo_option");
    //        privateCheckbox.setLabel(T_item_embargoed);
    //        if(date!=null){
    //            privateCheckbox.addOption(true, CB_EMBARGOED, "");
    //        }
    //        else{
    //            privateCheckbox.addOption(false, CB_EMBARGOED, "");
    //        }

    // Date
    Text startDate = form.addItem().addText("embargo_until_date");
    startDate.setLabel(T_item_embargoed);
    if (errorFlag == org.dspace.submit.step.AccessStep.STATUS_ERROR_FORMAT_DATE) {
      startDate.addError(T_error_date_format);
    } else if (errorFlag == org.dspace.submit.step.AccessStep.STATUS_ERROR_MISSING_DATE) {
      startDate.addError(T_error_missing_date);
    }

    if (date != null) {
      startDate.setValue(date);
    }
    startDate.setHelp(T_label_date_help);
  }
Beispiel #15
0
  public void addAccessRadios(
      String selectedRadio, String date, List form, int errorFlag, DSpaceObject dso)
      throws WingException, SQLException {

    if (!isAdvancedFormEnabled) {
      addEmbargoDateSimpleForm(dso, form, errorFlag);
    } else {

      org.dspace.app.xmlui.wing.element.Item radiosAndDate = form.addItem();
      Radio openAccessRadios = radiosAndDate.addRadio("open_access_radios");
      openAccessRadios.setLabel(T_radios_embargo);
      if (selectedRadio != null
          && Integer.parseInt(selectedRadio) == RADIO_OPEN_ACCESS_ITEM_EMBARGOED
          && errorFlag != org.dspace.submit.step.AccessStep.STATUS_COMPLETE) {
        openAccessRadios.addOption(RADIO_OPEN_ACCESS_ITEM_VISIBLE, T_item_will_be_visible);
        openAccessRadios.addOption(true, RADIO_OPEN_ACCESS_ITEM_EMBARGOED, T_item_embargoed);
      } else {
        openAccessRadios.addOption(true, RADIO_OPEN_ACCESS_ITEM_VISIBLE, T_item_will_be_visible);
        openAccessRadios.addOption(RADIO_OPEN_ACCESS_ITEM_EMBARGOED, T_item_embargoed);
      }

      // Date
      Text startDate = radiosAndDate.addText("embargo_until_date");
      startDate.setLabel("");
      startDate.setHelp(T_label_date_help);
      if (errorFlag == org.dspace.submit.step.AccessStep.STATUS_ERROR_FORMAT_DATE) {
        startDate.addError(T_error_date_format);
      } else if (errorFlag == org.dspace.submit.step.AccessStep.STATUS_ERROR_MISSING_DATE) {
        startDate.addError(T_error_missing_date);
      }

      if (date != null && errorFlag != org.dspace.submit.step.AccessStep.STATUS_COMPLETE) {
        startDate.setValue(date);
      }
    }
  }
  protected void logWorkflowEvent(
      Context c,
      String workflowId,
      String previousStepId,
      String previousActionConfigId,
      XmlWorkflowItem wfi,
      EPerson actor,
      Step newStep,
      WorkflowActionConfig newActionConfig)
      throws SQLException {
    try {
      // Fire an event so we can log our action !
      Item item = wfi.getItem();
      Collection myCollection = wfi.getCollection();
      String workflowStepString = null;

      List<EPerson> currentEpersonOwners = new ArrayList<EPerson>();
      List<Group> currentGroupOwners = new ArrayList<Group>();
      // These are only null if our item is sent back to the submission
      if (newStep != null && newActionConfig != null) {
        workflowStepString = workflowId + "." + newStep.getId() + "." + newActionConfig.getId();

        // Retrieve the current owners of the task
        List<ClaimedTask> claimedTasks = claimedTaskService.find(c, wfi, newStep.getId());
        List<PoolTask> pooledTasks = poolTaskService.find(c, wfi);
        for (PoolTask poolTask : pooledTasks) {
          if (poolTask.getEperson() != null) {
            currentEpersonOwners.add(poolTask.getEperson());
          } else {
            currentGroupOwners.add(poolTask.getGroup());
          }
        }
        for (ClaimedTask claimedTask : claimedTasks) {
          currentEpersonOwners.add(claimedTask.getOwner());
        }
      }
      String previousWorkflowStepString = null;
      if (previousStepId != null && previousActionConfigId != null) {
        previousWorkflowStepString =
            workflowId + "." + previousStepId + "." + previousActionConfigId;
      }

      // Fire our usage event !
      UsageWorkflowEvent usageWorkflowEvent =
          new UsageWorkflowEvent(
              c, item, wfi, workflowStepString, previousWorkflowStepString, myCollection, actor);

      usageWorkflowEvent.setEpersonOwners(
          currentEpersonOwners.toArray(new EPerson[currentEpersonOwners.size()]));
      usageWorkflowEvent.setGroupOwners(
          currentGroupOwners.toArray(new Group[currentGroupOwners.size()]));

      DSpaceServicesFactory.getInstance().getEventService().fireEvent(usageWorkflowEvent);
    } catch (Exception e) {
      // Catch all errors we do not want our workflow to crash because the logging threw an
      // exception
      log.error(
          LogManager.getHeader(
              c, "Error while logging workflow event", "Workflow Item: " + wfi.getID()),
          e);
    }
  }