Search in sources :

Example 1 with FieldCardinalityBase

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

the class FacetedTransformer method buildFacets.

/**
 * Accepts an attribute. The document data will be placed into the value of the Field.
 *
 * @param documentKey
 * @param fieldName
 * @param attr
 * @param topLevelColumnVisibility
 * @param markingFunctions
 * @return
 */
protected Collection<FieldCardinalityBase> buildFacets(Key documentKey, String fieldName, Attribute<?> attr, ColumnVisibility topLevelColumnVisibility, MarkingFunctions markingFunctions) {
    Set<FieldCardinalityBase> myFields = new HashSet<>();
    if (attr instanceof Attributes) {
        Attributes attributeList = Attributes.class.cast(attr);
        for (Attribute<?> embeddedAttr : attributeList.getAttributes()) myFields.addAll(buildFacets(documentKey, fieldName, embeddedAttr, topLevelColumnVisibility, markingFunctions));
    } else {
        // Use the markings on the Field if we're returning the markings to the client
        if (attr instanceof Cardinality) {
            try {
                Cardinality card = (Cardinality) attr;
                FieldValueCardinality v = card.getContent();
                StringType value = new StringType();
                value.setDelegate(v.toString());
                value.setNormalizedValue(v.toString());
                FieldCardinalityBase fc = this.responseObjectFactory.getFieldCardinality();
                fc.setField(v.getFieldName());
                // reduces colvis based on
                fc.setMarkings(markingFunctions.translateFromColumnVisibilityForAuths(attr.getColumnVisibility(), auths));
                // visibility
                fc.setColumnVisibility(new String(markingFunctions.translateToColumnVisibility(fc.getMarkings()).flatten()));
                fc.setLower(v.getFloorValue());
                fc.setUpper(v.getCeilingValue());
                fc.setCardinality(v.getEstimate().cardinality());
                myFields.add(fc);
            } catch (Exception e) {
                log.error("unable to process markings:" + e);
            }
        }
    }
    return myFields;
}
Also used : FieldValueCardinality(datawave.query.attributes.FieldValueCardinality) Cardinality(datawave.query.attributes.Cardinality) StringType(datawave.data.type.StringType) Attributes(datawave.query.attributes.Attributes) FieldValueCardinality(datawave.query.attributes.FieldValueCardinality) EmptyObjectException(datawave.webservice.query.exception.EmptyObjectException) FieldCardinalityBase(datawave.webservice.query.result.event.FieldCardinalityBase) HashSet(java.util.HashSet)

Example 2 with FieldCardinalityBase

use of datawave.webservice.query.result.event.FieldCardinalityBase 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 FieldCardinalityBase

use of datawave.webservice.query.result.event.FieldCardinalityBase 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

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