Package org.dspace.authorize

Examples of org.dspace.authorize.ResourcePolicy


        // create the default authorization policy for collections
        // of 'anonymous' READ
        Group anonymousGroup = Group.find(context, 0);

        ResourcePolicy myPolicy = ResourcePolicy.create(context);
        myPolicy.setResource(c);
        myPolicy.setAction(Constants.READ);
        myPolicy.setGroup(anonymousGroup);
        myPolicy.update();

        // now create the default policies for submitted items
        myPolicy = ResourcePolicy.create(context);
        myPolicy.setResource(c);
        myPolicy.setAction(Constants.DEFAULT_ITEM_READ);
        myPolicy.setGroup(anonymousGroup);
        myPolicy.update();

        myPolicy = ResourcePolicy.create(context);
        myPolicy.setResource(c);
        myPolicy.setAction(Constants.DEFAULT_BITSTREAM_READ);
        myPolicy.setGroup(anonymousGroup);
        myPolicy.update();

        context.addEvent(new Event(Event.CREATE, Constants.COLLECTION,
                c.getID(), c.handle, c.getIdentifiers(context)));

        log.info(LogManager.getHeader(context, "create_collection",
View Full Code Here


                }
            }
            if(!isAnonymousInPlace){
                // add policies for all the groups
                for(Group g : authorizedGroups){
                    ResourcePolicy rp = AuthorizeManager.createOrModifyPolicy(null, context, null, g.getID(), null, embargoDate, Constants.READ, reason, dso);
                    if(rp!=null)
                        rp.update();
                }

            }
            else{
                // add policy just for anonymous
                ResourcePolicy rp = AuthorizeManager.createOrModifyPolicy(null, context, null, 0, null, embargoDate, Constants.READ, reason, dso);
                if(rp!=null)
                    rp.update();
            }
        }

    }
View Full Code Here

                        {

                            // before create a new policy check if an identical policy is already in place
                            if(!AuthorizeManager.isAnIdenticalPolicyAlreadyInPlace(c, myitem, groupID, actionID, -1)){
                                // now add the policy
                                ResourcePolicy rp = ResourcePolicy.create(c);

                                rp.setResource(myitem);
                                rp.setAction(actionID);
                                rp.setGroup(group);

                                rp.setRpName(name);
                                rp.setRpDescription(description);
                                rp.setStartDate(startDate);
                                rp.setEndDate(endDate);

                                rp.update();
                            }
                        }
                    }
                }
                else if (contentType == Constants.BUNDLE)
                {
                    // build list of all items in a collection
                    // build list of all bundles in those items
                    while (i.hasNext())
                    {
                        Item myitem = i.next();

                        Bundle[] bundles = myitem.getBundles();

                        for (int j = 0; j < bundles.length; j++)
                        {
                            Bundle bundle = bundles[j]; // t for target

                            // is this a replace? delete policies first
                            if (isReplace || clearOnly)
                            {
                                AuthorizeManager.removeAllPolicies(c, bundle);
                            }

                            if (!clearOnly)
                            {
                                // before create a new policy check if an identical policy is already in place
                                if(!AuthorizeManager.isAnIdenticalPolicyAlreadyInPlace(c, bundle, groupID, actionID, -1)){
                                    // now add the policy
                                    ResourcePolicy rp = ResourcePolicy.create(c);

                                    rp.setResource(bundle);
                                    rp.setAction(actionID);
                                    rp.setGroup(group);

                                    rp.setRpName(name);
                                    rp.setRpDescription(description);
                                    rp.setStartDate(startDate);
                                    rp.setEndDate(endDate);

                                    rp.update();
                                }
                            }
                        }
                    }
                }
                else if (contentType == Constants.BITSTREAM)
                {
                    // build list of all bitstreams in a collection
                    // iterate over items, bundles, get bitstreams
                    while (i.hasNext())
                    {
                        Item myitem = i.next();
                        System.out.println("Item " + myitem.getID());

                        Bundle[] bundles = myitem.getBundles();

                        for (int j = 0; j < bundles.length; j++)
                        {
                            System.out.println("Bundle " + bundles[j].getID());

                            Bitstream[] bitstreams = bundles[j].getBitstreams();

                            for (int k = 0; k < bitstreams.length; k++)
                            {
                                Bitstream bitstream = bitstreams[k]; // t for target

                                if ( filter == null ||
                                        bitstream.getName().indexOf( filter ) != -1 )
                                {
                                    // is this a replace? delete policies first
                                    if (isReplace || clearOnly)
                                    {
                                        AuthorizeManager.removeAllPolicies(c, bitstream);
                                    }

                                    if (!clearOnly)
                                    {
                                        // before create a new policy check if an identical policy is already in place
                                        if(!AuthorizeManager.isAnIdenticalPolicyAlreadyInPlace(c, bitstream,  groupID, actionID, -1)){
                                            // now add the policy
                                            ResourcePolicy rp = ResourcePolicy.create(c);

                                            rp.setResource(bitstream);
                                            rp.setAction(actionID);
                                            rp.setGroup(group);

                                            rp.setRpName(name);
                                            rp.setRpDescription(description);
                                            rp.setStartDate(startDate);
                                            rp.setEndDate(endDate);

                                            rp.update();
                                        }
                                    }
                                }
                            }
                        }
View Full Code Here

        // create the default authorization policy for communities
        // of 'anonymous' READ
        Group anonymousGroup = Group.find(context, 0);

        ResourcePolicy myPolicy = ResourcePolicy.create(context);
        myPolicy.setResource(c);
        myPolicy.setAction(Constants.READ);
        myPolicy.setGroup(anonymousGroup);
        myPolicy.update();

        context.addEvent(new Event(Event.CREATE, Constants.COMMUNITY, c.getID(),
                c.handle, c.getIdentifiers(context)));

        // if creating a top-level Community, simulate an ADD event at the Site.
View Full Code Here

                    groupID=Integer.parseInt(request.getParameter("group_id"));
                }catch (NumberFormatException nfe){
                    return STATUS_EDIT_POLICIES_ERROR_SELECT_GROUP;
                }
            }
            ResourcePolicy rp = null;
            if( (rp= AuthorizeManager.createOrModifyPolicy(null, context, name, groupID, null, dateStartDate, org.dspace.core.Constants.READ, reason, b))==null){
                return STATUS_EDIT_POLICIES_DUPLICATED_POLICY;
            }
            rp.update();
            context.commit();
            return STATUS_EDIT_POLICIES;
        }
        // FORM: EditBitstreamPolicies SELECTED OPERATION: go to EditPolicyForm
        else if(org.dspace.submit.step.AccessStep.wasEditPolicyPressed(context, buttonPressed, subInfo)){
View Full Code Here

            if(request.getParameter("private_option")!=null){
                item.setDiscoverable(false);
            }

            Date dateStartDate = getEmbargoUntil(request);
            ResourcePolicy rp = null;
            if( (rp=AuthorizeManager.createOrModifyPolicy(null, context, name, groupID, null, dateStartDate, org.dspace.core.Constants.READ, reason, item))==null){
                return STATUS_DUPLICATED_POLICY;
            }
            rp.update();
            context.commit();
            return STATUS_COMPLETE;
        }

View Full Code Here

    }

    public static boolean wasEditPolicyPressed(Context context, String buttonPressed, SubmissionInfo subInfo) throws SQLException {
        if (buttonPressed.startsWith("submit_edit_edit_policies_") && !buttonPressed.equals(FORM_EDIT_BUTTON_CANCEL)){
            String idPolicy = buttonPressed.substring("submit_edit_edit_policies_".length());
            ResourcePolicy rp = ResourcePolicy.find(context, Integer.parseInt(idPolicy));
            subInfo.put(SUB_INFO_SELECTED_RP, rp);
            return true;
        }
        return false;
    }
View Full Code Here

        if (buttonPressed.equals(FORM_EDIT_BUTTON_CANCEL)){
            return STATUS_COMPLETE;
        }
        else if (buttonPressed.equals(FORM_EDIT_BUTTON_SAVE)){
            String idPolicy = request.getParameter("policy_id");
            ResourcePolicy resourcePolicy = ResourcePolicy.find(context, Integer.parseInt(idPolicy));
            subInfo.put(SUB_INFO_SELECTED_RP, resourcePolicy);
            Date dateStartDate = getEmbargoUntil(request);
            if( (resourcePolicy=AuthorizeManager.createOrModifyPolicy(resourcePolicy, context, name, groupID, null, dateStartDate, Constants.READ, reason, dso))==null){
                return EDIT_POLICY_STATUS_DUPLICATED_POLICY;
            }

            resourcePolicy.update();
            context.commit();
        }
        return STATUS_COMPLETE;
    }
View Full Code Here

        return STATUS_COMPLETE;
    }

    public static void removePolicy(Context context, String buttonPressed) throws SQLException {
        String idPolicy = buttonPressed.substring("submit_delete_edit_policies_".length());
        ResourcePolicy rp = ResourcePolicy.find(context, Integer.parseInt(idPolicy));
        rp.delete();
    }
View Full Code Here

                    + " has no default bitstream READ policies");
        }

        while (i.hasNext())
        {
            ResourcePolicy rp = (ResourcePolicy) i.next();
            rp.setAction(Constants.READ);
        }

        replaceAllBitstreamPolicies(policies);
    }
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.