Search in sources :

Example 1 with AccessRequirement

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());
}
Also used : HashMap(java.util.HashMap) TermsOfUseAccessRequirement(org.sagebionetworks.repo.model.TermsOfUseAccessRequirement) AccessRequirement(org.sagebionetworks.repo.model.AccessRequirement) Test(org.junit.Test)

Example 2 with AccessRequirement

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;
}
Also used : DBOAccessRequirement(org.sagebionetworks.repo.model.dbo.persistence.DBOAccessRequirement) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) DBOAccessRequirement(org.sagebionetworks.repo.model.dbo.persistence.DBOAccessRequirement) AccessRequirement(org.sagebionetworks.repo.model.AccessRequirement) DBONodeAccessRequirement(org.sagebionetworks.repo.model.dbo.persistence.DBONodeAccessRequirement)

Example 3 with AccessRequirement

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;
}
Also used : TermsOfUseAccessApproval(org.sagebionetworks.repo.model.TermsOfUseAccessApproval) AccessApproval(org.sagebionetworks.repo.model.AccessApproval) ACTAccessApproval(org.sagebionetworks.repo.model.ACTAccessApproval) ArrayList(java.util.ArrayList) QueryResults(org.sagebionetworks.repo.model.QueryResults) TermsOfUseAccessRequirement(org.sagebionetworks.repo.model.TermsOfUseAccessRequirement) AccessRequirement(org.sagebionetworks.repo.model.AccessRequirement) ACTAccessRequirement(org.sagebionetworks.repo.model.ACTAccessRequirement)

Example 4 with AccessRequirement

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());
}
Also used : ACTAccessRequirement(org.sagebionetworks.repo.model.ACTAccessRequirement) AccessRequirement(org.sagebionetworks.repo.model.AccessRequirement) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with AccessRequirement

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);
            }
        }
    }
}
Also used : AccessApproval(org.sagebionetworks.repo.model.AccessApproval) NotFoundException(org.sagebionetworks.repo.web.NotFoundException) AccessRequirement(org.sagebionetworks.repo.model.AccessRequirement)

Aggregations

AccessRequirement (org.sagebionetworks.repo.model.AccessRequirement)22 TermsOfUseAccessRequirement (org.sagebionetworks.repo.model.TermsOfUseAccessRequirement)11 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)7 TermsOfUseAccessApproval (org.sagebionetworks.repo.model.TermsOfUseAccessApproval)5 DBOAccessRequirement (org.sagebionetworks.repo.model.dbo.persistence.DBOAccessRequirement)5 ACTAccessRequirement (org.sagebionetworks.repo.model.ACTAccessRequirement)4 AccessApproval (org.sagebionetworks.repo.model.AccessApproval)4 JSONObjectAdapterImpl (org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl)4 UserInfo (org.sagebionetworks.repo.model.UserInfo)3 UserProfile (org.sagebionetworks.repo.model.UserProfile)3 JSONObjectAdapter (org.sagebionetworks.schema.adapter.JSONObjectAdapter)3 JSONObject (org.json.JSONObject)2 Synapse (org.sagebionetworks.client.Synapse)2 SynapseException (org.sagebionetworks.client.exceptions.SynapseException)2 Annotations (org.sagebionetworks.repo.model.Annotations)2 EntityPath (org.sagebionetworks.repo.model.EntityPath)2 MigratableObjectDescriptor (org.sagebionetworks.repo.model.MigratableObjectDescriptor)2 PaginatedResults (org.sagebionetworks.repo.model.PaginatedResults)2 Project (org.sagebionetworks.repo.model.Project)2