use of org.sagebionetworks.repo.model.AccessRequirement in project Synapse-Repository-Services by Sage-Bionetworks.
the class AccessRequirementControllerAutowiredTest method testRoundTrip.
@Test
public void testRoundTrip() throws Exception {
// create a new access requirement
AccessRequirement accessRequirement = null;
Map<String, String> extraParams = new HashMap<String, String>();
accessRequirement = newAccessRequirement();
String entityId = project.getId();
accessRequirement.setEntityIds(Arrays.asList(new String[] { entityId }));
AccessRequirement clone = ServletTestHelper.createAccessRequirement(dispatchServlet, accessRequirement, userName, extraParams);
assertNotNull(clone);
// test getAccessRequirementsForEntity
PaginatedResults<AccessRequirement> results = ServletTestHelper.getAccessRequirements(dispatchServlet, entityId, userName);
List<AccessRequirement> ars = results.getResults();
assertEquals(1, ars.size());
// get the unmet access requirements for the entity,
// when the user is the entity owner (should be none)
results = ServletTestHelper.getUnmetAccessRequirements(dispatchServlet, entityId, userName);
ars = results.getResults();
assertEquals(0, ars.size());
// get the unmet access requirements for the entity
results = ServletTestHelper.getUnmetAccessRequirements(dispatchServlet, entityId, TestUserDAO.TEST_USER_NAME);
ars = results.getResults();
assertEquals(1, ars.size());
// test deletion
ServletTestHelper.deleteAccessRequirements(dispatchServlet, ars.get(0).getId().toString(), userName);
results = ServletTestHelper.getAccessRequirements(dispatchServlet, entityId, userName);
ars = results.getResults();
assertEquals(0, ars.size());
}
use of org.sagebionetworks.repo.model.AccessRequirement in project Synapse-Repository-Services by Sage-Bionetworks.
the class DBOAccessRequirementDAOImpl method get.
@Override
public AccessRequirement get(String id) throws DatastoreException, NotFoundException {
MapSqlParameterSource param = new MapSqlParameterSource();
param.addValue(COL_ACCESS_REQUIREMENT_ID.toLowerCase(), id);
DBOAccessRequirement dbo = basicDao.getObjectById(DBOAccessRequirement.class, param);
List<Long> entities = getEntities(dbo.getId());
AccessRequirement dto = AccessRequirementUtils.copyDboToDto(dbo, entities);
return dto;
}
use of org.sagebionetworks.repo.model.AccessRequirement in project Synapse-Repository-Services by Sage-Bionetworks.
the class AccessApprovalManagerImpl method getAccessApprovalsForEntity.
@Override
public QueryResults<AccessApproval> getAccessApprovalsForEntity(UserInfo userInfo, String entityId) throws DatastoreException, NotFoundException, ForbiddenException {
ACTUtils.verifyACTTeamMembershipOrIsAdmin(userInfo, userGroupDAO);
List<AccessRequirement> ars = accessRequirementDAO.getForNode(entityId);
List<AccessApproval> aas = new ArrayList<AccessApproval>();
for (AccessRequirement ar : ars) {
aas.addAll(accessApprovalDAO.getForAccessRequirement(ar.getId().toString()));
}
QueryResults<AccessApproval> result = new QueryResults<AccessApproval>(aas, aas.size());
return result;
}
use of org.sagebionetworks.repo.model.AccessRequirement in project Synapse-Repository-Services by Sage-Bionetworks.
the class AccessRequirementManagerImpl method deleteAccessRequirement.
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
@Override
public void deleteAccessRequirement(UserInfo userInfo, String accessRequirementId) throws NotFoundException, DatastoreException, UnauthorizedException, ForbiddenException {
AccessRequirement accessRequirement = accessRequirementDAO.get(accessRequirementId);
ACTUtils.verifyACTTeamMembershipOrIsAdmin(userInfo, userGroupDAO);
accessRequirementDAO.delete(accessRequirement.getId().toString());
}
use of org.sagebionetworks.repo.model.AccessRequirement in project Synapse-Repository-Services by Sage-Bionetworks.
the class AccessRequirementBackupDriver method createOrUpdateAccessRequirementAndApprovals.
private void createOrUpdateAccessRequirementAndApprovals(AccessRequirementBackup backup) throws DatastoreException, NotFoundException, InvalidModelException, ConflictingUpdateException {
// create the access requirement
AccessRequirement ar = backup.getAccessRequirement();
AccessRequirement arFromSystem = null;
try {
arFromSystem = accessRequirementDAO.get(ar.getId().toString());
} catch (NotFoundException e) {
arFromSystem = null;
}
if (null == arFromSystem) {
ar = accessRequirementDAO.create(ar);
} else {
// Update only when backup is different from the current system
if (!arFromSystem.getEtag().equals(ar.getEtag())) {
ar = accessRequirementDAO.updateFromBackup(ar);
}
}
// create the access approvals
for (AccessApproval aa : backup.getAccessApprovals()) {
if (!ar.getId().equals(aa.getRequirementId()))
throw new IllegalStateException("AccessApproval references requirement " + aa.getRequirementId() + ", the ID in the backup file is " + backup.getAccessRequirement().getId() + ", and the ID after restoration is " + ar.getId());
AccessApproval aaFromSystem = null;
try {
aaFromSystem = accessApprovalDAO.get(aa.getId().toString());
} catch (NotFoundException e) {
aaFromSystem = null;
}
if (null == aaFromSystem) {
accessApprovalDAO.create(aa);
} else {
// Update only when backup is different from the current system
if (!arFromSystem.getEtag().equals(ar.getEtag())) {
accessApprovalDAO.updateFromBackup(aa);
}
}
}
}
Aggregations