Search in sources :

Example 16 with MigratableObjectDescriptor

use of org.sagebionetworks.repo.model.MigratableObjectDescriptor in project Synapse-Repository-Services by Sage-Bionetworks.

the class NodeDAOImplTest method checkMigrationDependenciesNoParentDistinctModifier.

public void checkMigrationDependenciesNoParentDistinctModifier(String id) throws Exception {
    // first check what happens if dependencies are NOT requested
    QueryResults<MigratableObjectData> results = nodeDao.getMigrationObjectData(0, 10000, false);
    List<MigratableObjectData> ods = results.getResults();
    assertEquals(ods.size(), results.getTotalNumberOfResults());
    assertTrue(ods.size() > 0);
    boolean foundId = false;
    for (MigratableObjectData od : ods) {
        if (od.getId().getId().equals(id)) {
            foundId = true;
        }
        assertEquals(MigratableObjectType.ENTITY, od.getId().getType());
    }
    assertTrue(foundId);
    // now query for objects WITH dependencies
    results = nodeDao.getMigrationObjectData(0, 10000, true);
    ods = results.getResults();
    assertEquals(ods.size(), results.getTotalNumberOfResults());
    assertTrue(ods.size() > 0);
    foundId = false;
    for (MigratableObjectData od : ods) {
        if (od.getId().getId().equals(id)) {
            foundId = true;
            // since there's no parent or ACL, the only dependency size is zero.
            Collection<MigratableObjectDescriptor> deps = od.getDependencies();
            assertEquals("id: " + id + " dependencies: " + deps.toString(), 0, deps.size());
        }
        assertEquals(MigratableObjectType.ENTITY, od.getId().getType());
    }
    assertTrue(foundId);
}
Also used : MigratableObjectData(org.sagebionetworks.repo.model.MigratableObjectData) MigratableObjectDescriptor(org.sagebionetworks.repo.model.MigratableObjectDescriptor)

Example 17 with MigratableObjectDescriptor

use of org.sagebionetworks.repo.model.MigratableObjectDescriptor in project Synapse-Repository-Services by Sage-Bionetworks.

the class ObjectDescriptorUtils method createObjectDescriptor.

public static MigratableObjectDescriptor createObjectDescriptor(String id, MigratableObjectType type) {
    MigratableObjectDescriptor obj = new MigratableObjectDescriptor();
    obj.setId(id);
    obj.setType(type);
    return obj;
}
Also used : MigratableObjectDescriptor(org.sagebionetworks.repo.model.MigratableObjectDescriptor)

Example 18 with MigratableObjectDescriptor

use of org.sagebionetworks.repo.model.MigratableObjectDescriptor in project Synapse-Repository-Services by Sage-Bionetworks.

the class IT100BackupRestoration method testAccessRequirementRoundTrip.

/**
 * Test the complete round trip of Access Requirement/Approval migration.
 * @throws SynapseException
 * @throws JSONObjectAdapterException
 * @throws InterruptedException
 */
@Test
public void testAccessRequirementRoundTrip() throws Exception {
    // first create a backup copy of all of the ARs
    // Start the daemon
    BackupSubmission submission = new BackupSubmission();
    // Create an AR, AA and get its ID, then add it's ID here:
    // Create an entity to which an AccessRequirement is added. We don't normally add ARs to projects, but it's convenient to do it here
    Project project = new Project();
    project.setDescription("foo");
    project = synapse.createEntity(project);
    assertNotNull(project);
    toDelete.add(project);
    // now create the access requirement
    TermsOfUseAccessRequirement ar = new TermsOfUseAccessRequirement();
    ar.setAccessType(ACCESS_TYPE.DOWNLOAD);
    ar.setEntityIds(Arrays.asList(new String[] { project.getId() }));
    ar.setEntityType(TermsOfUseAccessRequirement.class.getName());
    ar.setTermsOfUse("foo");
    ar = synapse.createAccessRequirement(ar);
    assertNotNull(ar.getId());
    // now create an approval
    TermsOfUseAccessApproval aa = new TermsOfUseAccessApproval();
    UserProfile up = synapse.getMyProfile();
    String userId = up.getOwnerId();
    aa.setAccessorId(userId);
    aa.setEntityType(TermsOfUseAccessApproval.class.getName());
    aa.setRequirementId(ar.getId());
    aa = synapse.createAccessApproval(aa);
    submission.setEntityIdsToBackup(new HashSet<String>(Arrays.asList(new String[] { ar.getId().toString() })));
    BackupRestoreStatus status = synapse.startBackupDaemon(submission, MigratableObjectType.ACCESSREQUIREMENT);
    assertNotNull(status);
    assertNotNull(status.getStatus());
    assertFalse(status.getErrorMessage(), DaemonStatus.FAILED == status.getStatus());
    assertTrue(DaemonType.BACKUP == status.getType());
    String restoreId = status.getId();
    assertNotNull(restoreId);
    // Wait for it to finish
    status = waitForDaemon(status.getId());
    assertNotNull(status.getBackupUrl());
    assertEquals(DaemonStatus.COMPLETED, status.getStatus());
    // delete the access requirement from the system
    MigratableObjectDescriptor mod = new MigratableObjectDescriptor();
    mod.setId(ar.getId().toString());
    mod.setType(MigratableObjectType.ACCESSREQUIREMENT);
    synapse.deleteObject(mod);
    // verify that it's deleted
    VariableContentPaginatedResults<AccessRequirement> vcprs = synapse.getAccessRequirements(project.getId());
    assertEquals(0L, vcprs.getTotalNumberOfResults());
    // Now restore the access requirements from this backup file
    RestoreSubmission restoreSub = new RestoreSubmission();
    String backupFileName = getFileNameFromUrl(status.getBackupUrl());
    restoreSub.setFileName(backupFileName);
    status = synapse.startRestoreDaemon(restoreSub, MigratableObjectType.ACCESSREQUIREMENT);
    // Wait for it to finish
    status = waitForDaemon(status.getId());
    assertEquals(DaemonStatus.COMPLETED, status.getStatus());
    // verify that it's restored
    vcprs = synapse.getAccessRequirements(project.getId());
    assertEquals(1L, vcprs.getTotalNumberOfResults());
    // now clean up the access requirement (cascading to the access approval)
    synapse.deleteObject(mod);
}
Also used : BackupSubmission(org.sagebionetworks.repo.model.daemon.BackupSubmission) TermsOfUseAccessRequirement(org.sagebionetworks.repo.model.TermsOfUseAccessRequirement) Project(org.sagebionetworks.repo.model.Project) UserProfile(org.sagebionetworks.repo.model.UserProfile) BackupRestoreStatus(org.sagebionetworks.repo.model.daemon.BackupRestoreStatus) RestoreSubmission(org.sagebionetworks.repo.model.daemon.RestoreSubmission) TermsOfUseAccessApproval(org.sagebionetworks.repo.model.TermsOfUseAccessApproval) MigratableObjectDescriptor(org.sagebionetworks.repo.model.MigratableObjectDescriptor) TermsOfUseAccessRequirement(org.sagebionetworks.repo.model.TermsOfUseAccessRequirement) AccessRequirement(org.sagebionetworks.repo.model.AccessRequirement) Test(org.junit.Test)

Example 19 with MigratableObjectDescriptor

use of org.sagebionetworks.repo.model.MigratableObjectDescriptor in project Synapse-Repository-Services by Sage-Bionetworks.

the class NodeDAOImpl method getMigrationObjectData.

@Override
public QueryResults<MigratableObjectData> getMigrationObjectData(long offset, long limit, boolean includeDependencies) throws DatastoreException {
    // if we don't want dependencies then use an alternate, faster query
    if (!includeDependencies)
        return getMigrationObjectDataWithoutDependencies(offset, limit);
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue(OFFSET_PARAM_NAME, offset);
    params.addValue(LIMIT_PARAM_NAME, limit);
    // Note: our goal here is not to list every dependency, but rather just the entity dependencies.
    List<MigratableObjectData> ods = this.simpleJdbcTemplate.query(SQL_GET_NODES_PAGINATED_DEPENDENCIES, new RowMapper<MigratableObjectData>() {

        @Override
        public MigratableObjectData mapRow(ResultSet rs, int rowNum) throws SQLException {
            MigratableObjectData data = new MigratableObjectData();
            long nodeId = rs.getLong(COL_NODE_ID);
            data.setId(ObjectDescriptorUtils.createEntityObjectDescriptor(nodeId));
            data.setEtag(rs.getString(COL_NODE_ETAG));
            // add the parent and benefactor as a dependency
            Set<MigratableObjectDescriptor> dependependencies = new HashSet<MigratableObjectDescriptor>(2);
            // this is null for the root node
            Long parentId = rs.getLong(COL_NODE_PARENT_ID);
            if (!rs.wasNull()) {
                // We had a parent id so add it as a dependency.
                dependependencies.add(ObjectDescriptorUtils.createEntityObjectDescriptor(parentId));
            }
            // Add the benefactor if it is not this node.
            long benefactorId = rs.getLong(COL_NODE_BENEFACTOR_ID);
            if (nodeId != benefactorId) {
                dependependencies.add(ObjectDescriptorUtils.createEntityObjectDescriptor(benefactorId));
            }
            data.setDependencies(dependependencies);
            return data;
        }
    }, params);
    QueryResults<MigratableObjectData> queryResults = new QueryResults<MigratableObjectData>();
    queryResults.setResults(ods);
    queryResults.setTotalNumberOfResults((int) getCount());
    return queryResults;
}
Also used : ResultSet(java.sql.ResultSet) Set(java.util.Set) HashSet(java.util.HashSet) SQLException(java.sql.SQLException) MigratableObjectData(org.sagebionetworks.repo.model.MigratableObjectData) MigratableObjectDescriptor(org.sagebionetworks.repo.model.MigratableObjectDescriptor) QueryResults(org.sagebionetworks.repo.model.QueryResults) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ResultSet(java.sql.ResultSet)

Example 20 with MigratableObjectDescriptor

use of org.sagebionetworks.repo.model.MigratableObjectDescriptor in project Synapse-Repository-Services by Sage-Bionetworks.

the class DBOAccessRequirementDAOImpl method getMigrationObjectData.

@Override
public QueryResults<MigratableObjectData> getMigrationObjectData(long offset, long limit, boolean includeDependencies) throws DatastoreException {
    // (1) get one 'page' of AccessRequirements (just their IDs and Etags)
    List<MigratableObjectData> ods = null;
    {
        MapSqlParameterSource param = new MapSqlParameterSource();
        param.addValue(OFFSET_PARAM_NAME, offset);
        param.addValue(LIMIT_PARAM_NAME, limit);
        ods = simpleJdbcTemplate.query(SELECT_FOR_RANGE_SQL, new RowMapper<MigratableObjectData>() {

            @Override
            public MigratableObjectData mapRow(ResultSet rs, int rowNum) throws SQLException {
                String id = rs.getString(COL_ACCESS_REQUIREMENT_ID);
                String etag = rs.getString(COL_ACCESS_REQUIREMENT_ETAG);
                MigratableObjectData objectData = new MigratableObjectData();
                MigratableObjectDescriptor od = new MigratableObjectDescriptor();
                od.setId(id);
                od.setType(MigratableObjectType.ACCESSREQUIREMENT);
                objectData.setId(od);
                objectData.setEtag(etag);
                objectData.setDependencies(new HashSet<MigratableObjectDescriptor>(0));
                return objectData;
            }
        }, param);
    }
    // (2) find the dependencies
    if (includeDependencies && !ods.isEmpty()) {
        Map<String, MigratableObjectData> arMap = new HashMap<String, MigratableObjectData>();
        for (MigratableObjectData od : ods) arMap.put(od.getId().getId(), od);
        List<DBONodeAccessRequirement> nars = null;
        {
            MapSqlParameterSource param = new MapSqlParameterSource();
            param.addValue(COL_NODE_ACCESS_REQUIREMENT_REQUIREMENT_ID, arMap.keySet());
            nars = simpleJdbcTemplate.query(SELECT_FOR_MULTIPLE_NAR_SQL, nodeAccessRequirementRowMapper, param);
        }
        // (3) add the dependencies to the objects
        for (DBONodeAccessRequirement nar : nars) {
            MigratableObjectDescriptor od = ObjectDescriptorUtils.createEntityObjectDescriptor(nar.getNodeId());
            MigratableObjectData objectData = arMap.get(nar.getAccessRequirementId().toString());
            objectData.getDependencies().add(od);
        }
    }
    // (4) return the 'page' of objects, along with the total result count
    QueryResults<MigratableObjectData> queryResults = new QueryResults<MigratableObjectData>();
    queryResults.setResults(ods);
    queryResults.setTotalNumberOfResults((int) getCount());
    return queryResults;
}
Also used : SQLException(java.sql.SQLException) HashMap(java.util.HashMap) MigratableObjectData(org.sagebionetworks.repo.model.MigratableObjectData) MigratableObjectDescriptor(org.sagebionetworks.repo.model.MigratableObjectDescriptor) QueryResults(org.sagebionetworks.repo.model.QueryResults) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) DBONodeAccessRequirement(org.sagebionetworks.repo.model.dbo.persistence.DBONodeAccessRequirement) ResultSet(java.sql.ResultSet) HashSet(java.util.HashSet)

Aggregations

MigratableObjectDescriptor (org.sagebionetworks.repo.model.MigratableObjectDescriptor)25 MigratableObjectData (org.sagebionetworks.repo.model.MigratableObjectData)21 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)5 MigratableDAO (org.sagebionetworks.repo.model.MigratableDAO)4 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 QueryResults (org.sagebionetworks.repo.model.QueryResults)3 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)3 HashMap (java.util.HashMap)2 AccessRequirement (org.sagebionetworks.repo.model.AccessRequirement)2 TermsOfUseAccessRequirement (org.sagebionetworks.repo.model.TermsOfUseAccessRequirement)2 UserProfile (org.sagebionetworks.repo.model.UserProfile)2 SocketTimeoutException (java.net.SocketTimeoutException)1 Set (java.util.Set)1 SynapseAdministration (org.sagebionetworks.client.SynapseAdministration)1 SynapseNotFoundException (org.sagebionetworks.client.exceptions.SynapseNotFoundException)1 SynapseServiceException (org.sagebionetworks.client.exceptions.SynapseServiceException)1 ConflictingUpdateException (org.sagebionetworks.repo.model.ConflictingUpdateException)1