use of org.apache.abdera.model.Categories in project datawave by NationalSecurityAgency.
the class AtomServiceBean method getCategories.
/**
* @return Atom Categories document that lists category names
*/
@GET
@GZIP
@Produces("application/atomcat+xml")
@Path("/categories")
public Categories getCategories() {
Principal p = ctx.getCallerPrincipal();
Set<Authorizations> auths = new HashSet<>();
if (p instanceof DatawavePrincipal) {
DatawavePrincipal dp = (DatawavePrincipal) p;
for (Collection<String> cbAuths : dp.getAuthorizations()) auths.add(new Authorizations(cbAuths.toArray(new String[cbAuths.size()])));
}
Categories result;
Connector connection = null;
try {
result = abdera.newCategories();
Map<String, String> trackingMap = connectionFactory.getTrackingMap(Thread.currentThread().getStackTrace());
connection = connectionFactory.getConnection(poolName, Priority.NORMAL, trackingMap);
try (Scanner scanner = ScannerHelper.createScanner(connection, tableName + "Categories", auths)) {
Map<String, String> props = new HashMap<>();
props.put(MatchingKeySkippingIterator.ROW_DELIMITER_OPTION, "\0");
props.put(MatchingKeySkippingIterator.NUM_SCANS_STRING_NAME, "5");
IteratorSetting setting = new IteratorSetting(30, MatchingKeySkippingIterator.class, props);
scanner.addScanIterator(setting);
for (Map.Entry<Key, Value> entry : scanner) {
String collectionName = entry.getKey().getRow().toString();
result.addCategory(collectionName);
}
}
if (result.getCategories().isEmpty())
throw new NoResultsException(null);
else
return result;
} catch (WebApplicationException web) {
throw web;
} catch (Exception e) {
VoidResponse response = new VoidResponse();
QueryException qe = new QueryException(DatawaveErrorCode.COLLECTION_ERROR, e);
log.error(qe);
response.addException(qe.getBottomQueryException());
throw new DatawaveWebApplicationException(qe, response);
} finally {
if (null != connection) {
try {
connectionFactory.returnConnection(connection);
} catch (Exception e) {
log.error("Error returning connection to factory", e);
}
}
}
}
use of org.apache.abdera.model.Categories in project datawave by NationalSecurityAgency.
the class AtomMessageBodyWriter method writeTo.
@Override
public void writeTo(Object message, Class<?> clazz, Type type, Annotation[] annotations, MediaType media, MultivaluedMap<String, Object> httpHeaders, OutputStream out) throws IOException, WebApplicationException {
if (Entry.class.isAssignableFrom(clazz)) {
Entry entry = (Entry) message;
entry.writeTo(out);
} else if (Feed.class.isAssignableFrom(clazz)) {
Feed feed = (Feed) message;
feed.writeTo(out);
} else if (Service.class.isAssignableFrom(clazz)) {
Service service = (Service) message;
service.writeTo(out);
} else if (Categories.class.isAssignableFrom(clazz)) {
Categories categories = (Categories) message;
categories.writeTo(out);
}
}
Aggregations