Search in sources :

Example 1 with FacetsBase

use of datawave.webservice.query.result.event.FacetsBase in project datawave by NationalSecurityAgency.

the class FacetedTransformer method _transform.

private FacetsBase _transform(Entry<Key, Document> documentEntry) throws EmptyObjectException {
    if (documentEntry == null) {
        // buildResponse will return a null object if there was only metadata in the document
        throw new EmptyObjectException();
    }
    Key documentKey = correctKey(documentEntry.getKey());
    Document document = documentEntry.getValue();
    if (null == documentKey || null == document)
        throw new IllegalArgumentException("Null key or value. Key:" + documentKey + ", Value: " + documentEntry.getValue());
    extractMetrics(document, documentKey);
    document.debugDocumentSize(documentKey);
    String row = documentKey.getRow().toString();
    String colf = documentKey.getColumnFamily().toString();
    int index = colf.indexOf("\0");
    Preconditions.checkArgument(-1 != index);
    String dataType = colf.substring(0, index);
    String uid = colf.substring(index + 1);
    // We don't have to consult the Document to rebuild the Visibility, the key
    // should have the correct top-level visibility
    ColumnVisibility eventCV = new ColumnVisibility(documentKey.getColumnVisibility());
    FacetsBase output = null;
    try {
        // build response method here
        output = buildResponse(document, documentKey, eventCV, colf, row, this.markingFunctions);
    } catch (Exception ex) {
        log.error("Error building response document", ex);
        throw new RuntimeException(ex);
    }
    if (output == null) {
        // buildResponse will return a null object if there was only metadata in the document
        throw new EmptyObjectException();
    }
    if (cardinalityConfiguration != null) {
        collectCardinalities(document, documentKey, uid, dataType);
    }
    return output;
}
Also used : EmptyObjectException(datawave.webservice.query.exception.EmptyObjectException) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Document(datawave.query.attributes.Document) Key(org.apache.accumulo.core.data.Key) EmptyObjectException(datawave.webservice.query.exception.EmptyObjectException) FacetsBase(datawave.webservice.query.result.event.FacetsBase)

Example 2 with FacetsBase

use of datawave.webservice.query.result.event.FacetsBase in project datawave by NationalSecurityAgency.

the class FacetedTransformer method buildResponse.

protected FacetsBase buildResponse(Document document, Key documentKey, ColumnVisibility eventCV, String colf, String row, MarkingFunctions mf) throws MarkingFunctions.Exception {
    FacetsBase facetedResponse = responseObjectFactory.getFacets();
    final Collection<FieldCardinalityBase> documentFields = buildFacets(documentKey, null, document, eventCV, mf);
    facetedResponse.setMarkings(mf.translateFromColumnVisibility(eventCV));
    facetedResponse.setFields(new ArrayList<>(documentFields));
    // assign an estimate of the event size based on the document size
    // in practice this is about 2.5 times the size of the document estimated size
    // we need to set something here for page size trigger purposes.
    facetedResponse.setSizeInBytes(Math.round(document.sizeInBytes() * 2.5d));
    return facetedResponse;
}
Also used : FacetsBase(datawave.webservice.query.result.event.FacetsBase) FieldCardinalityBase(datawave.webservice.query.result.event.FieldCardinalityBase)

Example 3 with FacetsBase

use of datawave.webservice.query.result.event.FacetsBase in project datawave by NationalSecurityAgency.

the class FacetedTransformer method createResponse.

@Override
public BaseQueryResponse createResponse(List<Object> resultList) {
    FacetQueryResponseBase response = responseObjectFactory.getFacetQueryResponse();
    Set<ColumnVisibility> combinedColumnVisibility = new HashSet<>();
    for (Object result : resultList) {
        FacetsBase facet = (FacetsBase) result;
        response.addFacet(facet);
        for (FieldCardinalityBase fcb : facet.getFields()) {
            if (StringUtils.isNotBlank(fcb.getColumnVisibility())) {
                combinedColumnVisibility.add(new ColumnVisibility(fcb.getColumnVisibility()));
            }
        }
    }
    try {
        ColumnVisibility columnVisibility = this.markingFunctions.combine(combinedColumnVisibility);
        response.setMarkings(this.markingFunctions.translateFromColumnVisibility(columnVisibility));
    } catch (MarkingFunctions.Exception e) {
        log.warn(e);
    // original ignored these exceptions
    }
    return response;
}
Also used : FacetQueryResponseBase(datawave.webservice.result.FacetQueryResponseBase) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) HashSet(java.util.HashSet) FacetsBase(datawave.webservice.query.result.event.FacetsBase) FieldCardinalityBase(datawave.webservice.query.result.event.FieldCardinalityBase) MarkingFunctions(datawave.marking.MarkingFunctions)

Aggregations

FacetsBase (datawave.webservice.query.result.event.FacetsBase)3 FieldCardinalityBase (datawave.webservice.query.result.event.FieldCardinalityBase)2 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)2 MarkingFunctions (datawave.marking.MarkingFunctions)1 Document (datawave.query.attributes.Document)1 EmptyObjectException (datawave.webservice.query.exception.EmptyObjectException)1 FacetQueryResponseBase (datawave.webservice.result.FacetQueryResponseBase)1 HashSet (java.util.HashSet)1 Key (org.apache.accumulo.core.data.Key)1