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());
}
}
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();
}
}
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();
}
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;
}
}
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);
}
}
Aggregations