Skip to content

Commit

Permalink
Merge pull request #2604 from Micheleboychuk/resourcepolicies
Browse files Browse the repository at this point in the history
DS-4398 initial implementation of the resource policies endpoint
  • Loading branch information
tdonohue committed Feb 12, 2020
2 parents 707168d + b479851 commit 14445d5
Show file tree
Hide file tree
Showing 27 changed files with 4,302 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
Expand All @@ -25,6 +26,7 @@
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
import org.dspace.eperson.Group;
import org.dspace.eperson.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;

/**
Expand All @@ -46,6 +48,9 @@ public class ResourcePolicyServiceImpl implements ResourcePolicyService {
@Autowired(required = true)
protected ResourcePolicyDAO resourcePolicyDAO;

@Autowired
private GroupService groupService;

protected ResourcePolicyServiceImpl() {
}

Expand Down Expand Up @@ -313,4 +318,85 @@ public List<ResourcePolicy> findExceptRpType(Context c, DSpaceObject o, int acti
throws SQLException {
return resourcePolicyDAO.findByDSoAndActionExceptRpType(c, o, actionID, rpType);
}

@Override
public List<ResourcePolicy> findByEPerson(Context context, EPerson ePerson, int offset, int limit)
throws SQLException {
return resourcePolicyDAO.findByEPerson(context, ePerson, offset, limit);
}

@Override
public int countByEPerson(Context context, EPerson eperson) throws SQLException {
return resourcePolicyDAO.countByEPerson(context, eperson);
}

@Override
public List<ResourcePolicy> findByEPersonAndResourceUuid(Context context, EPerson eperson, UUID resourceUuid,
int offset, int limit) throws SQLException {
return resourcePolicyDAO.findByEPersonAndResourceUuid(context, eperson, resourceUuid, offset, limit);
}

@Override
public int countResourcePoliciesByEPersonAndResourceUuid(Context context, EPerson eperson, UUID resourceUuid)
throws SQLException {
return resourcePolicyDAO.countByEPersonAndResourceUuid(context, eperson, resourceUuid);
}

@Override
public List<ResourcePolicy> findByResouceUuidAndActionId(Context context, UUID resourceUuid, int actionId,
int offset, int limit) throws SQLException {
return resourcePolicyDAO.findByResouceUuidAndActionId(context, resourceUuid, actionId, offset, limit);
}

@Override
public int countByResouceUuidAndActionId(Context context, UUID resourceUuid, int actionId) throws SQLException {
return resourcePolicyDAO.countByResouceUuidAndActionId(context, resourceUuid, actionId);
}

@Override
public List<ResourcePolicy> findByResouceUuid(Context context, UUID resourceUuid, int offset, int limit)
throws SQLException {
return resourcePolicyDAO.findByResouceUuid(context, resourceUuid, offset, limit);
}

@Override
public int countByResourceUuid(Context context, UUID resourceUuid) throws SQLException {
return resourcePolicyDAO.countByResourceUuid(context, resourceUuid);
}

@Override
public List<ResourcePolicy> findByGroup(Context context, Group group, int offset, int limit) throws SQLException {
return resourcePolicyDAO.findByGroup(context, group, offset, limit);
}

@Override
public int countResourcePolicyByGroup(Context context, Group group) throws SQLException {
return resourcePolicyDAO.countResourcePolicyByGroup(context, group);
}

@Override
public List<ResourcePolicy> findByGroupAndResourceUuid(Context context, Group group, UUID resourceUuid,
int offset, int limit) throws SQLException {
return resourcePolicyDAO.findByGroupAndResourceUuid(context, group, resourceUuid, offset, limit);
}

@Override
public int countByGroupAndResourceUuid(Context context, Group group, UUID resourceUuid) throws SQLException {
return resourcePolicyDAO.countByGroupAndResourceUuid(context, group, resourceUuid);
}

@Override
public boolean isMyResourcePolicy(Context context, EPerson eperson, Integer id) throws SQLException {
boolean isMy = false;

ResourcePolicy resourcePolicy = resourcePolicyDAO.findOneById(context, id);
Group group = resourcePolicy.getGroup();

if (resourcePolicy.getEPerson() != null && resourcePolicy.getEPerson().getID() == eperson.getID()) {
isMy = true;
} else if (group != null && groupService.isMember(context, eperson, group)) {
isMy = true;
}
return isMy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.sql.SQLException;
import java.util.List;
import java.util.UUID;

import org.dspace.authorize.ResourcePolicy;
import org.dspace.content.DSpaceObject;
Expand Down Expand Up @@ -79,4 +80,153 @@ public List<ResourcePolicy> findByEPersonGroupTypeIdAction(Context context, EPer
*/
public List<ResourcePolicy> findByDSoAndActionExceptRpType(Context c, DSpaceObject o, int actionID,
String rpType) throws SQLException;

/**
* Return a paginated list of policies that belong to an EPerson
*
* @param context DSpace context object
* @param ePerson ePerson whose policies want to find
* @param offset the position of the first result to return
* @param limit paging limit
* @throws SQLException if database error
*/
public List<ResourcePolicy> findByEPerson(Context context, EPerson ePerson, int offset, int limit)
throws SQLException;

/**
* Count all the resource policies of the ePerson
*
* @param context DSpace context object
* @param ePerson ePerson whose policies want to count
* @return total resource policies of the ePerson
* @throws SQLException if database error
*/
public int countByEPerson(Context context, EPerson eperson) throws SQLException;

/**
* Return a paginated list of policies related to a resourceUuid belong to an ePerson
*
* @param context DSpace context object
* @param ePerson ePerson whose policies want to find
* @param resourceUuid the uuid of an DSpace resource
* @param offset the position of the first result to return
* @param limit paging limit
* @return list of resource policies
* @throws SQLException if database error
*/
public List<ResourcePolicy> findByEPersonAndResourceUuid(Context context, EPerson ePerson, UUID resourceUuid,
int offset, int limit) throws SQLException;

/**
* Count all the policies related to a resourceUuid belong to an ePerson
*
* @param context DSpace context object
* @param resourceUuid the uuid of an DSpace resource
* @param ePerson ePerson whose policies want to find
* @return total policies
* @throws SQLException if database error
*/
public int countByEPersonAndResourceUuid(Context context, EPerson ePerson, UUID resourceUuid)
throws SQLException;

/**
* Return a paginated list of policies related to a DSpace resource filter by actionId
*
* @param context DSpace context object
* @param resourceUuid the uuid of an DSpace resource
* @param actionId id relative to action as READ, WRITE, DELITE etc.
* @param offset the position of the first result to return
* @param limit paging limit
* @return list of resource policies
* @throws SQLException if database error
*/
public List<ResourcePolicy> findByResouceUuidAndActionId(Context context, UUID resourceUuid, int actionId,
int offset, int limit) throws SQLException;

/**
* Count all the policies related to a resourceUuid and actionId
*
* @param context DSpace context object
* @param resourceUuid the uuid of an DSpace resource
* @param actionId id relative to action as READ, WRITE, DELITE etc.
* @return total policies
* @throws SQLException if database error
*/
public int countByResouceUuidAndActionId(Context context, UUID resourceUuid, int actionId)
throws SQLException;

/**
* Return a paginated list of policies related to a DSpace resource
*
* @param context DSpace context object
* @param resourceUuid the uuid of an DSpace resource
* @param offset the position of the first result to return
* @param limit paging limit
* @return list of resource policies
* @throws SQLException if database error
*/
public List<ResourcePolicy> findByResouceUuid(Context context, UUID resourceUuid, int offset, int limit)
throws SQLException;

/**
* Count all the policies by resourceUuid
*
* @param context DSpace context object
* @param resourceUuid the uuid of an DSpace resource
* @return total policies
* @throws SQLException if database error
*/
public int countByResourceUuid(Context context, UUID resourceUuid) throws SQLException;

/**
* Return a paginated list of policies related to a group
*
* @param context DSpace context object
* @param group DSpace group
* @param offset the position of the first result to return
* @param limit paging limit
* @return list of resource policies
* @throws SQLException if database error
*/
public List<ResourcePolicy> findByGroup(Context context, Group group, int offset, int limit)
throws SQLException;

/**
* Count all the resource policies of the group
*
* @param context DSpace context object
* @param group DSpace group
* @return total policies
* @throws SQLException if database error
*/
public int countResourcePolicyByGroup(Context context, Group group) throws SQLException;

/**
* Return a paginated list of policies related to a group and related to a resourceUuid
*
* @param context DSpace context object
* @param group DSpace group
* @param resourceUuid the uuid of an DSpace resource
* @param offset the position of the first result to return
* @param limit paging limit
* @return list of resource policies
* @throws SQLException if database error
*/
public List<ResourcePolicy> findByGroupAndResourceUuid(Context context, Group group, UUID resourceUuid,
int offset, int limit) throws SQLException;

/**
* Count all the resource policies of the group and of the resourceUuid
*
* @param context DSpace context object
* @param group DSpace group
* @param resourceUuid the uuid of an DSpace resource
* @return total policies
* @throws SQLException if database error
*/
public int countByGroupAndResourceUuid(Context context, Group group, UUID resourceUuid) throws SQLException;

public ResourcePolicy findOneById(Context context, Integer id) throws SQLException;


}

0 comments on commit 14445d5

Please sign in to comment.