Search in sources :

Example 1 with Categories

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);
            }
        }
    }
}
Also used : NoResultsException(datawave.webservice.common.exception.NoResultsException) Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) WebApplicationException(javax.ws.rs.WebApplicationException) Categories(org.apache.abdera.model.Categories) HashMap(java.util.HashMap) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) WebApplicationException(javax.ws.rs.WebApplicationException) NoResultsException(datawave.webservice.common.exception.NoResultsException) QueryException(datawave.webservice.query.exception.QueryException) QueryException(datawave.webservice.query.exception.QueryException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) VoidResponse(datawave.webservice.result.VoidResponse) DefaultValue(javax.ws.rs.DefaultValue) Value(org.apache.accumulo.core.data.Value) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) Map(java.util.Map) HashMap(java.util.HashMap) Principal(java.security.Principal) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) Key(org.apache.accumulo.core.data.Key) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 2 with Categories

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);
    }
}
Also used : Entry(org.apache.abdera.model.Entry) Categories(org.apache.abdera.model.Categories) Service(org.apache.abdera.model.Service) Feed(org.apache.abdera.model.Feed)

Aggregations

Categories (org.apache.abdera.model.Categories)2 DatawavePrincipal (datawave.security.authorization.DatawavePrincipal)1 DatawaveWebApplicationException (datawave.webservice.common.exception.DatawaveWebApplicationException)1 NoResultsException (datawave.webservice.common.exception.NoResultsException)1 QueryException (datawave.webservice.query.exception.QueryException)1 VoidResponse (datawave.webservice.result.VoidResponse)1 Principal (java.security.Principal)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 DefaultValue (javax.ws.rs.DefaultValue)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Entry (org.apache.abdera.model.Entry)1 Feed (org.apache.abdera.model.Feed)1 Service (org.apache.abdera.model.Service)1 Connector (org.apache.accumulo.core.client.Connector)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1