Package org.dspace.authorize

Examples of org.dspace.authorize.ResourcePolicy


                                                    String name, String description, String startDateParam, String endDateParam) throws SQLException, AuthorizeException
  {
    FlowResult result = new FlowResult();
    boolean added = false;
 
    ResourcePolicy policy = ResourcePolicy.find(context, policyID);
   
    // check authorization to edit an existent policy
    if (policy != null)
    {
        AuthorizeUtil.authorizeManagePolicy(context, policy);
    }
   
    /* First and foremost, if no group or action was selected, throw an error back to the user */
    if (actionID == -1) {
      result.setContinue(false);
      result.addError("action_id");
      return result;
    }
    if (groupID == -1) {
      result.setContinue(false);
      result.addError("group_id");
      return result;
    }


        // check dates
        Date startDate = null;
        Date endDate = null;

        // 05/01/2012 valid date
        if(StringUtils.isNotBlank(startDateParam)){

            try {
                startDate = DateUtils.parseDate(startDateParam, new String[]{"yyyy-MM-dd", "yyyy-MM", "yyyy"});
            } catch (ParseException e) {
                startDate = null;
            }
            if(startDate==null){
                result.setContinue(false);
                result.addError("startDate");
                return result;
            }
        }

        if(StringUtils.isNotBlank(endDateParam)){
            try {
                endDate = DateUtils.parseDate(endDateParam, new String[]{"yyyy-MM-dd", "yyyy-MM", "yyyy"});
            } catch (ParseException e) {
                endDate = null;
            }

            if(endDate==null){
                result.setContinue(false);
                result.addError("endDate");
                return result;
            }
        }

        if(endDate!=null && startDate!=null){
            if(startDate.after(endDate)){
                result.setContinue(false);
                result.addError("startDateGreaterThenEndDate");
                return result;
            }
        }
        // end check dates

        // check if a similar policy is already in place
        if(policy==null){
            if(AuthorizeManager.isAnIdenticalPolicyAlreadyInPlace(context, objectType, objectID, groupID, actionID, -1)){
                result.setContinue(false);
                result.addError("duplicatedPolicy");
                return result;
            }
        }
        else{
            if(AuthorizeManager.isAnIdenticalPolicyAlreadyInPlace(context, objectType, objectID, groupID, actionID, policy.getID())){
                result.setContinue(false);
                result.addError("duplicatedPolicy");
                return result;
            }
        }


           


        /* If the policy doesn't exist, create a new one and set its parent resource */
    DSpaceObject policyParent = null;
    if (policy == null)
    {
      switch (objectType) {
      case Constants.COMMUNITY:
          {
              policyParent = Community.find(context, objectID);
              AuthorizeUtil.authorizeManageCommunityPolicy(context, (Community)policyParent);
              break;
          }
      case Constants.COLLECTION:
            {
              policyParent = Collection.find(context, objectID);
              AuthorizeUtil.authorizeManageCollectionPolicy(context, (Collection)policyParent);       
              break;
            }
      case Constants.ITEM:
            {
              policyParent = Item.find(context, objectID);
              AuthorizeUtil.authorizeManageItemPolicy(context, (Item) policyParent);
              break;
            }
      case Constants.BUNDLE:
            {
              policyParent = Bundle.find(context, objectID);
              AuthorizeUtil.authorizeManageItemPolicy(context, (Item) (policyParent.getParentObject()));
              break;
            }
      case Constants.BITSTREAM:
            {
              policyParent = Bitstream.find(context, objectID);
              AuthorizeUtil
                        .authorizeManageItemPolicy(context, (Item) (policyParent
                                .getParentObject()));
              break;
            }
      }
      policy = ResourcePolicy.create(context);
      policy.setResource(policyParent);
            policy.setRpType(ResourcePolicy.TYPE_CUSTOM);
      added = true;
    }
   
      Group group = Group.find(context, groupID);
     
      //  modify the policy
      policy.setAction(actionID);
      policy.setGroup(group);

        policy.setRpName(name);
        policy.setRpDescription(description);

        if(endDate!=null) policy.setEndDate(endDate);
        else policy.setEndDate(null);


        if(startDate!=null) policy.setStartDate(startDate);
        else policy.setStartDate(null);

       
      // propagate the changes to the logo, which is treated on the same level as the parent object
      Bitstream logo = null;
      DSpaceObject logoContainer = null;
      if (objectType == Constants.COLLECTION)
      {
        logoContainer = Collection.find(context, objectID);
          logo = ((Collection)logoContainer).getLogo();
      }
      else if (objectType == Constants.COMMUNITY)
      {
        logoContainer = Community.find(context, objectID);
          logo = ((Community)logoContainer).getLogo();
      }
     
      if (logo != null)
      {
          List policySet = AuthorizeManager.getPolicies(context, logoContainer);
          AuthorizeManager.removeAllPolicies(context, logo);
          AuthorizeManager.addPolicies(context, policySet, logo);
      }
     
      // Perform the update action
      policy.update();
      context.commit();
     
      result.setContinue(true);
      result.setOutcome(true);
      if (added)
        {
            result.setMessage(new Message("default", "A new policy was created successfully"));
        }
      else
        {
            result.setMessage(new Message("default", "The policy was edited successfully"));
        }
     
      result.setParameter("policyID", policy.getID());
     
    return result;
  }
View Full Code Here


  {
    FlowResult result = new FlowResult();
 
    for (String id : policyIDs)
    {
      ResourcePolicy policyDeleted = ResourcePolicy.find(context, Integer.valueOf(id));
      // check authorization
      AuthorizeUtil.authorizeManagePolicy(context, policyDeleted);
      policyDeleted.delete();
      }
 
    result.setContinue(true);
    result.setOutcome(true);
    result.setMessage(new Message("default","The policies were deleted successfully"));
View Full Code Here

        String rpDescription = parameters.getParameter("description", null);
        String rpStartDate = parameters.getParameter("startDate", null);
        String rpEndDate = parameters.getParameter("endDate", null);

        // The current policy, if it exists (i.e. we are not creating a new one)
        ResourcePolicy policy = ResourcePolicy.find(context, policyID);

        if (policy != null){
            if(rpName==null || rpName.equals(""))
                rpName = policy.getRpName();

            if(rpDescription==null || rpDescription.equals(""))
                rpDescription = policy.getRpDescription();

            if(StringUtils.isBlank(rpStartDate) && policy.getStartDate()!=null){
                rpStartDate = DateFormatUtils.format(policy.getStartDate(), "yyyy-MM-dd");
            }

            if(StringUtils.isBlank(rpEndDate) && policy.getEndDate() != null){
                rpEndDate = DateFormatUtils.format(policy.getEndDate(), "yyyy-MM-dd");
            }
        }

        // The currently set group; it's value depends on wether previously clicked the "Set" button to change
        // the associated group, came here to edit an existing group, or create a new one.
        Group currentGroup;
        if (groupID != -1) {
            currentGroup = Group.find(context, groupID);
        }
        else if (policy != null) {
            currentGroup = policy.getGroup();
        }
        else
        {
            currentGroup = null;
        }

        // Same for the current action; it can either blank (-1), manually set, or inherited from the current policy
        if (policy != null && actionID == -1)
        {
            actionID = policy.getAction();


        }



        String errorString = parameters.getParameter("errors",null);
        ArrayList<String> errors = new ArrayList<String>();
        if (errorString != null)
        {
            for (String error : errorString.split(","))
            {
                errors.add(error);
            }
        }


        /* Set up our current Dspace object */
        DSpaceObject dso;
        switch (objectType) {
            case Constants.COMMUNITY: dso = Community.find(context, objectID); break;
            case Constants.COLLECTION: dso = Collection.find(context, objectID); break;
            case Constants.ITEM: dso = org.dspace.content.Item.find(context, objectID); break;
            case Constants.BUNDLE: dso = Bundle.find(context, objectID); break;
            case Constants.BITSTREAM: dso = Bitstream.find(context, objectID); break;
            default: dso = null;
        }


        // DIVISION: edit-container-policies
        Division main = body.addInteractiveDivision("edit-policy",contextPath+"/admin/authorize",Division.METHOD_POST,"primary administrative authorization");

        if (policyID >= 0) {
            objectID = policy.getResourceID();
            objectType = policy.getResourceType();
            main.setHead(T_main_head_edit.parameterize(policyID,Constants.typeText[objectType],objectID));
        }
        else
        {
            main.setHead(T_main_head_new.parameterize(Constants.typeText[objectType], objectID));
View Full Code Here

        String date=null;

        if(dso!=null){
            java.util.List<ResourcePolicy> policies = AuthorizeManager.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){
View Full Code Here

TOP

Related Classes of org.dspace.authorize.ResourcePolicy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.