Search in sources :

Example 1 with DatastoreException

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

the class ConceptJenaDAOImpl method listPropertyAsString.

/**
 * @param resource
 * @param prop
 * @return
 * @throws DatastoreException
 */
public static List<String> listPropertyAsString(Resource resource, Property prop) throws DatastoreException {
    try {
        List<String> results = new ArrayList<String>();
        StmtIterator it = listProperties(resource, prop);
        while (it.hasNext()) {
            Statement s = it.next();
            results.add(s.getString());
        }
        return results;
    } catch (Exception e) {
        // Convert any exception to a DatastoreException
        throw new DatastoreException("Cannot get a property: " + prop.getURI() + " for resource: " + resource.getURI() + " as a list of strings: " + e.getMessage());
    }
}
Also used : StmtIterator(com.hp.hpl.jena.rdf.model.StmtIterator) Statement(com.hp.hpl.jena.rdf.model.Statement) ArrayList(java.util.ArrayList) DatastoreException(org.sagebionetworks.repo.model.DatastoreException) DatastoreException(org.sagebionetworks.repo.model.DatastoreException) NotFoundException(org.sagebionetworks.repo.web.NotFoundException) IOException(java.io.IOException)

Example 2 with DatastoreException

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

the class ConceptJenaDAOImpl method getAllConcepts.

@Override
public List<ConceptSummary> getAllConcepts(String parentConceptURI) throws DatastoreException {
    if (parentConceptURI == null)
        throw new IllegalArgumentException("parentConceptURI cannot be null");
    // Create a query
    String queryString = String.format(SPARQL_GET_CHILDREN_CONCEPTS, parentConceptURI);
    // System.out.println(queryString);
    Query query = QueryFactory.create(queryString);
    QueryExecution qexec = QueryExecutionFactory.create(query, this.rdfModel);
    try {
        ResultSet resultSet = qexec.execSelect();
        List<ConceptSummary> results = new LinkedList<ConceptSummary>();
        while (resultSet.hasNext()) {
            QuerySolution soln = resultSet.nextSolution();
            if (soln == null)
                throw new DatastoreException("Null QuerySolution");
            RDFNode node = soln.get(URI);
            if (node == null)
                throw new DatastoreException("Failed to get URI from QuerySolution :" + soln.toString());
            // System.out.println(node);
            ConceptSummary summary = new ConceptSummary();
            summary.setUri(node.toString());
            Literal prefLit = soln.getLiteral(PREFERED_LABEL);
            if (prefLit == null)
                throw new DatastoreException("No preferred label for " + node.toString());
            summary.setPreferredLabel(prefLit.toString());
            results.add(summary);
        }
        return results;
    } finally {
        qexec.close();
    }
}
Also used : Query(com.hp.hpl.jena.query.Query) QuerySolution(com.hp.hpl.jena.query.QuerySolution) Literal(com.hp.hpl.jena.rdf.model.Literal) ResultSet(com.hp.hpl.jena.query.ResultSet) DatastoreException(org.sagebionetworks.repo.model.DatastoreException) QueryExecution(com.hp.hpl.jena.query.QueryExecution) LinkedList(java.util.LinkedList) RDFNode(com.hp.hpl.jena.rdf.model.RDFNode)

Example 3 with DatastoreException

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

the class DBOUserGroupDAOImpl method findGroup.

public DBOUserGroup findGroup(String name) throws DatastoreException {
    MapSqlParameterSource param = new MapSqlParameterSource();
    param.addValue(NAME_PARAM_NAME, name);
    List<DBOUserGroup> ugs = simpleJdbcTemplate.query(SELECT_BY_NAME_SQL, userGroupRowMapper, param);
    if (ugs.size() > 1)
        throw new DatastoreException("Expected 0-1 UserGroups but found " + ugs.size());
    if (ugs.size() == 0)
        return null;
    return ugs.iterator().next();
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) DBOUserGroup(org.sagebionetworks.repo.model.dbo.persistence.DBOUserGroup) DatastoreException(org.sagebionetworks.repo.model.DatastoreException)

Example 4 with DatastoreException

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

the class DBOUserGroupDAOImpl method deletePrincipal.

@Override
public boolean deletePrincipal(String name) {
    try {
        DBOUserGroup ug = findGroup(name);
        if (ug == null)
            return false;
        delete(ug.getId().toString());
        return true;
    } catch (DatastoreException e) {
        throw new RuntimeException(e);
    } catch (NotFoundException e) {
        return false;
    }
}
Also used : DBOUserGroup(org.sagebionetworks.repo.model.dbo.persistence.DBOUserGroup) NotFoundException(org.sagebionetworks.repo.web.NotFoundException) DatastoreException(org.sagebionetworks.repo.model.DatastoreException)

Example 5 with DatastoreException

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

the class DBOUserGroupDAOImpl method getGroupsByNames.

@Override
public Map<String, UserGroup> getGroupsByNames(Collection<String> groupName) throws DatastoreException {
    Map<String, UserGroup> dtos = new HashMap<String, UserGroup>();
    if (groupName.isEmpty())
        return dtos;
    MapSqlParameterSource param = new MapSqlParameterSource();
    param.addValue(NAME_PARAM_NAME, groupName);
    try {
        List<DBOUserGroup> dbos = simpleJdbcTemplate.query(SELECT_MULTI_BY_NAME_SQL, userGroupRowMapper, param);
        for (DBOUserGroup dbo : dbos) {
            UserGroup dto = new UserGroup();
            UserGroupUtils.copyDboToDto(dbo, dto);
            dtos.put(dto.getName(), dto);
        }
        return dtos;
    } catch (Exception e) {
        throw new DatastoreException("'getGroupsByNames' failed for group list: " + groupName, e);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) HashMap(java.util.HashMap) DBOUserGroup(org.sagebionetworks.repo.model.dbo.persistence.DBOUserGroup) DatastoreException(org.sagebionetworks.repo.model.DatastoreException) DatastoreException(org.sagebionetworks.repo.model.DatastoreException) SQLException(java.sql.SQLException) ConflictingUpdateException(org.sagebionetworks.repo.model.ConflictingUpdateException) NotFoundException(org.sagebionetworks.repo.web.NotFoundException) InvalidModelException(org.sagebionetworks.repo.model.InvalidModelException) DBOUserGroup(org.sagebionetworks.repo.model.dbo.persistence.DBOUserGroup) UserGroup(org.sagebionetworks.repo.model.UserGroup)

Aggregations

DatastoreException (org.sagebionetworks.repo.model.DatastoreException)58 NotFoundException (org.sagebionetworks.repo.web.NotFoundException)22 IOException (java.io.IOException)17 InvalidModelException (org.sagebionetworks.repo.model.InvalidModelException)14 ConflictingUpdateException (org.sagebionetworks.repo.model.ConflictingUpdateException)12 Transactional (org.springframework.transaction.annotation.Transactional)11 UserGroup (org.sagebionetworks.repo.model.UserGroup)9 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)9 Date (java.util.Date)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 NamedAnnotations (org.sagebionetworks.repo.model.NamedAnnotations)5 UnauthorizedException (org.sagebionetworks.repo.model.UnauthorizedException)5 DBOUserGroup (org.sagebionetworks.repo.model.dbo.persistence.DBOUserGroup)5 JSONObjectAdapterException (org.sagebionetworks.schema.adapter.JSONObjectAdapterException)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 File (java.io.File)3 ResultSet (java.sql.ResultSet)3 HashMap (java.util.HashMap)3 Annotations (org.sagebionetworks.repo.model.Annotations)3