Search in sources :

Example 1 with QueryResults

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

the class NodeQueryServiceImpl method query.

@Override
public QueryResults query(String userId, String query, HttpServletRequest request) throws DatastoreException, ParseException, NotFoundException, UnauthorizedException {
    // Parse and validate the query
    QueryStatement stmt = new QueryStatement(query);
    // Convert from a query statement to a basic query
    BasicQuery basic = QueryTranslator.createBasicQuery(stmt);
    QueryResults results = executeQueryWithAnnotations(userId, basic, request);
    results.setResults(formulateResult(stmt, results.getResults()));
    return results;
}
Also used : BasicQuery(org.sagebionetworks.repo.model.query.BasicQuery) QueryStatement(org.sagebionetworks.repo.web.query.QueryStatement) QueryResults(org.sagebionetworks.repo.model.QueryResults) NodeQueryResults(org.sagebionetworks.repo.model.NodeQueryResults)

Example 2 with QueryResults

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

the class DBOUserGroupDAOImpl method getMigrationObjectData.

@Override
public QueryResults<MigratableObjectData> getMigrationObjectData(long offset, long limit, boolean includeDependencies) throws DatastoreException {
    // get a page of user groups
    List<MigratableObjectData> ods = null;
    {
        MapSqlParameterSource param = new MapSqlParameterSource();
        param.addValue(OFFSET_PARAM_NAME, offset);
        param.addValue(LIMIT_PARAM_NAME, limit);
        ods = simpleJdbcTemplate.query(SELECT_ALL_PAGINATED_WITH_ETAG, new RowMapper<MigratableObjectData>() {

            @Override
            public MigratableObjectData mapRow(ResultSet rs, int rowNum) throws SQLException {
                // NOTE this is an outer join, so we have to handle the case in which there
                // is no etag for the given user group
                String ugId = rs.getString(COL_USER_GROUP_ID);
                String etag = rs.getString(COL_USER_PROFILE_ETAG);
                if (etag == null)
                    etag = DEFAULT_ETAG;
                MigratableObjectData od = new MigratableObjectData();
                MigratableObjectDescriptor id = new MigratableObjectDescriptor();
                id.setId(ugId);
                id.setType(MigratableObjectType.PRINCIPAL);
                od.setId(id);
                od.setEtag(etag);
                // UserGroups have no dependencies
                od.setDependencies(new HashSet<MigratableObjectDescriptor>(0));
                return od;
            }
        }, param);
    }
    QueryResults<MigratableObjectData> queryResults = new QueryResults<MigratableObjectData>();
    queryResults.setResults(ods);
    queryResults.setTotalNumberOfResults((int) getCount());
    return queryResults;
}
Also used : 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) HashSet(java.util.HashSet)

Example 3 with QueryResults

use of org.sagebionetworks.repo.model.QueryResults 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 QueryResults

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

the class UserProfileManagerImpl method getInRange.

@Override
public QueryResults<UserProfile> getInRange(UserInfo userInfo, long startIncl, long endExcl, boolean includeEmail) throws DatastoreException, NotFoundException {
    ObjectSchema schema = SchemaCache.getSchema(UserProfile.class);
    List<UserProfile> userProfiles = userProfileDAO.getInRange(startIncl, endExcl, schema);
    long totalNumberOfResults = userProfileDAO.getCount();
    for (UserProfile userProfile : userProfiles) {
        UserProfileManagerUtils.clearPrivateFields(userProfile);
        if (includeEmail) {
            UserGroup userGroup = userGroupDAO.get(userProfile.getOwnerId());
            if (userGroup != null)
                userProfile.setEmail(StringUtil.obfuscateEmailAddress(userGroup.getName()));
        }
    }
    QueryResults<UserProfile> result = new QueryResults<UserProfile>(userProfiles, (int) totalNumberOfResults);
    return result;
}
Also used : ObjectSchema(org.sagebionetworks.schema.ObjectSchema) UserProfile(org.sagebionetworks.repo.model.UserProfile) QueryResults(org.sagebionetworks.repo.model.QueryResults) UserGroup(org.sagebionetworks.repo.model.UserGroup)

Example 5 with QueryResults

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

the class NodeDAOImpl method getMigrationObjectDataWithoutDependencies.

public QueryResults<MigratableObjectData> getMigrationObjectDataWithoutDependencies(long offset, long limit) throws DatastoreException {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue(OFFSET_PARAM_NAME, offset);
    params.addValue(LIMIT_PARAM_NAME, limit);
    List<MigratableObjectData> ods = this.simpleJdbcTemplate.query(SQL_GET_NODES_PAGINATED, new RowMapper<MigratableObjectData>() {

        @Override
        public MigratableObjectData mapRow(ResultSet rs, int rowNum) throws SQLException {
            MigratableObjectData data = new MigratableObjectData();
            data.setId(ObjectDescriptorUtils.createEntityObjectDescriptor(rs.getLong(COL_NODE_ID)));
            data.setEtag(rs.getString(COL_NODE_ETAG));
            data.setDependencies(new HashSet<MigratableObjectDescriptor>(0));
            return data;
        }
    }, params);
    QueryResults<MigratableObjectData> queryResults = new QueryResults<MigratableObjectData>();
    queryResults.setResults(ods);
    queryResults.setTotalNumberOfResults((int) getCount());
    return queryResults;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) MigratableObjectData(org.sagebionetworks.repo.model.MigratableObjectData) QueryResults(org.sagebionetworks.repo.model.QueryResults) HashSet(java.util.HashSet)

Aggregations

QueryResults (org.sagebionetworks.repo.model.QueryResults)23 ArrayList (java.util.ArrayList)8 ResultSet (java.sql.ResultSet)6 Test (org.junit.Test)6 MigratableObjectData (org.sagebionetworks.repo.model.MigratableObjectData)6 SQLException (java.sql.SQLException)5 HashSet (java.util.HashSet)5 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)5 NodeQueryResults (org.sagebionetworks.repo.model.NodeQueryResults)4 Collection (java.util.Collection)3 MigratableObjectDescriptor (org.sagebionetworks.repo.model.MigratableObjectDescriptor)3 UserInfo (org.sagebionetworks.repo.model.UserInfo)3 BasicQuery (org.sagebionetworks.repo.model.query.BasicQuery)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ACTAccessRequirement (org.sagebionetworks.repo.model.ACTAccessRequirement)2 AccessRequirement (org.sagebionetworks.repo.model.AccessRequirement)2 EntityHeader (org.sagebionetworks.repo.model.EntityHeader)2 MigratableDAO (org.sagebionetworks.repo.model.MigratableDAO)2 MigratableObjectCount (org.sagebionetworks.repo.model.MigratableObjectCount)2