Search in sources :

Example 1 with DBONodeAccessRequirement

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

the class DBOAccessRequirementDAOImpl method getEntities.

public List<Long> getEntities(Long accessRequirementId) {
    MapSqlParameterSource param = new MapSqlParameterSource();
    param.addValue(COL_NODE_ACCESS_REQUIREMENT_REQUIREMENT_ID, accessRequirementId);
    List<DBONodeAccessRequirement> nars = simpleJdbcTemplate.query(SELECT_FOR_NAR_SQL, nodeAccessRequirementRowMapper, param);
    List<Long> ans = new ArrayList<Long>();
    for (DBONodeAccessRequirement nar : nars) ans.add(nar.getNodeId());
    return ans;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) DBONodeAccessRequirement(org.sagebionetworks.repo.model.dbo.persistence.DBONodeAccessRequirement) ArrayList(java.util.ArrayList)

Example 2 with DBONodeAccessRequirement

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

the class DBOAccessRequirementDAOImpl method populateNodeAccessRequirement.

@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void populateNodeAccessRequirement(Long accessRequirementId, List<String> entityIds) throws DatastoreException {
    if (entityIds == null || entityIds.isEmpty())
        return;
    List<DBONodeAccessRequirement> batch = new ArrayList<DBONodeAccessRequirement>();
    for (String s : new HashSet<String>(entityIds)) {
        // eliminate duplicate entityIds
        DBONodeAccessRequirement nar = new DBONodeAccessRequirement();
        nar.setAccessRequirementId(accessRequirementId);
        Long nodeId = KeyFactory.stringToKey(s);
        nar.setNodeId(nodeId);
        batch.add(nar);
    }
    basicDao.createBatch(batch);
}
Also used : DBONodeAccessRequirement(org.sagebionetworks.repo.model.dbo.persistence.DBONodeAccessRequirement) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with DBONodeAccessRequirement

use of org.sagebionetworks.repo.model.dbo.persistence.DBONodeAccessRequirement 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

DBONodeAccessRequirement (org.sagebionetworks.repo.model.dbo.persistence.DBONodeAccessRequirement)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 MigratableObjectData (org.sagebionetworks.repo.model.MigratableObjectData)1 MigratableObjectDescriptor (org.sagebionetworks.repo.model.MigratableObjectDescriptor)1 QueryResults (org.sagebionetworks.repo.model.QueryResults)1 Transactional (org.springframework.transaction.annotation.Transactional)1