Search in sources :

Example 21 with EventBase

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

the class DiscoveryTransformer method readFromCache.

@Override
public List<Object> readFromCache(List<CacheableQueryRow> cacheableQueryRowList) {
    List<Object> eventList = new ArrayList<>();
    for (CacheableQueryRow cqr : cacheableQueryRowList) {
        if (this.variableFieldList == null) {
            this.variableFieldList = cqr.getVariableColumnNames();
        }
        Map<String, String> markings = cqr.getMarkings();
        String dataType = cqr.getDataType();
        String internalId = cqr.getEventId();
        String row = cqr.getRow();
        EventBase event = this.responseObjectFactory.getEvent();
        event.setMarkings(markings);
        Metadata metadata = new Metadata();
        metadata.setDataType(dataType);
        metadata.setInternalId(internalId);
        metadata.setRow(row);
        metadata.setTable(logic.getTableName());
        event.setMetadata(metadata);
        List<FieldBase> fieldList = new ArrayList<>();
        Map<String, String> columnValueMap = cqr.getColumnValues();
        for (Map.Entry<String, String> entry : columnValueMap.entrySet()) {
            String columnName = entry.getKey();
            String columnValue = entry.getValue();
            String columnVisibility = cqr.getColumnVisibility(columnName);
            Long columnTimestamp = cqr.getColumnTimestamp(columnName);
            Map<String, String> columnMarkings = cqr.getColumnMarkings(columnName);
            FieldBase field = this.responseObjectFactory.getField();
            field.setName(columnName);
            field.setMarkings(columnMarkings);
            field.setColumnVisibility(columnVisibility);
            field.setTimestamp(columnTimestamp);
            field.setValue(columnValue);
            fieldList.add(field);
        }
        event.setFields(fieldList);
        eventList.add(event);
    }
    return eventList;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) ArrayList(java.util.ArrayList) Metadata(datawave.webservice.query.result.event.Metadata) CacheableQueryRow(datawave.webservice.query.cachedresults.CacheableQueryRow) FieldBase(datawave.webservice.query.result.event.FieldBase) HashMap(java.util.HashMap) Map(java.util.Map)

Example 22 with EventBase

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

the class DiscoveryTransformer method writeToCache.

@Override
public List<CacheableQueryRow> writeToCache(Object o) throws QueryException {
    List<CacheableQueryRow> cqoList = new ArrayList<>();
    EventBase event = (EventBase) o;
    CacheableQueryRow cqo = new CacheableQueryRowImpl();
    Metadata metadata = event.getMetadata();
    cqo.setColFam(metadata.getDataType() + ":" + cqo.getEventId());
    cqo.setDataType(metadata.getDataType());
    cqo.setEventId(metadata.getInternalId());
    cqo.setRow(metadata.getRow());
    List<FieldBase> fields = event.getFields();
    for (FieldBase f : fields) {
        cqo.addColumn(f.getName(), f.getTypedValue(), f.getMarkings(), f.getColumnVisibility(), f.getTimestamp());
    }
    cqoList.add(cqo);
    return cqoList;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) ArrayList(java.util.ArrayList) Metadata(datawave.webservice.query.result.event.Metadata) FieldBase(datawave.webservice.query.result.event.FieldBase) CacheableQueryRow(datawave.webservice.query.cachedresults.CacheableQueryRow) CacheableQueryRowImpl(datawave.webservice.query.cachedresults.CacheableQueryRowImpl)

Example 23 with EventBase

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

the class DocumentTransformer method buildResponse.

protected EventBase buildResponse(Document document, Key documentKey, ColumnVisibility eventCV, String colf, String row, MarkingFunctions mf) throws MarkingFunctions.Exception {
    Map<String, String> markings = mf.translateFromColumnVisibility(eventCV);
    EventBase event = null;
    final Collection<FieldBase<?>> documentFields = buildDocumentFields(documentKey, null, document, eventCV, mf);
    // if documentFields is empty, then the response contained only timing metadata
    if (!documentFields.isEmpty()) {
        event = this.responseObjectFactory.getEvent();
        event.setMarkings(markings);
        event.setFields(new ArrayList<>(documentFields));
        Metadata metadata = new Metadata();
        String[] colfParts = StringUtils.split(colf, '\0');
        if (colfParts.length >= 1) {
            metadata.setDataType(colfParts[0]);
        }
        if (colfParts.length >= 2) {
            metadata.setInternalId(colfParts[1]);
        }
        if (this.tableName != null) {
            metadata.setTable(this.tableName);
        }
        metadata.setRow(row);
        event.setMetadata(metadata);
        if (eventQueryDataDecoratorTransformer != null) {
            event = (EventBase) eventQueryDataDecoratorTransformer.transform(event);
        }
        // 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.
        event.setSizeInBytes(Math.round(document.sizeInBytes() * 2.5d));
    }
    return event;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) FieldBase(datawave.webservice.query.result.event.FieldBase) Metadata(datawave.webservice.query.result.event.Metadata)

Example 24 with EventBase

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

the class DocumentTransformer method _transform.

private EventBase _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());
    EventBase 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 : EventBase(datawave.webservice.query.result.event.EventBase) 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)

Example 25 with EventBase

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

the class EventQueryDataDecoratorTransformer method transform.

@Override
public Object transform(Object o) {
    if (o instanceof EventBase) {
        EventBase e = (EventBase) o;
        List<? extends FieldBase> fields = e.getFields();
        Multimap<String, FieldBase> fieldMap = HashMultimap.create();
        for (FieldBase f : fields) {
            fieldMap.put(f.getName(), f);
        }
        for (String d : requestedDecorators) {
            EventQueryDataDecorator decorator = dataDecorators.get(d);
            if (decorator != null) {
                decorator.decorateData(fieldMap);
            }
        }
        e.setFields(new ArrayList<>(fieldMap.values()));
        return e;
    } else {
        return o;
    }
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) FieldBase(datawave.webservice.query.result.event.FieldBase)

Aggregations

EventBase (datawave.webservice.query.result.event.EventBase)43 ArrayList (java.util.ArrayList)28 FieldBase (datawave.webservice.query.result.event.FieldBase)23 Metadata (datawave.webservice.query.result.event.Metadata)18 EventQueryResponseBase (datawave.webservice.result.EventQueryResponseBase)11 CacheableQueryRow (datawave.webservice.query.cachedresults.CacheableQueryRow)10 BaseQueryResponse (datawave.webservice.result.BaseQueryResponse)6 DefaultEventQueryResponse (datawave.webservice.result.DefaultEventQueryResponse)5 Map (java.util.Map)5 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)5 TransformIterator (org.apache.commons.collections4.iterators.TransformIterator)5 Exception (datawave.marking.MarkingFunctions.Exception)4 QueryImpl (datawave.webservice.query.QueryImpl)4 QueryException (datawave.webservice.query.exception.QueryException)4 HashMap (java.util.HashMap)4 CacheableQueryRowImpl (datawave.webservice.query.cachedresults.CacheableQueryRowImpl)3 GenericQueryConfiguration (datawave.webservice.query.configuration.GenericQueryConfiguration)3 DatawaveTransformIterator (datawave.webservice.query.iterator.DatawaveTransformIterator)3 DefaultEvent (datawave.webservice.query.result.event.DefaultEvent)3 Date (java.util.Date)3