use of datawave.marking.MarkingFunctions.Exception in project datawave by NationalSecurityAgency.
the class ShardIndexQueryTransformer method transform.
@Override
public EventBase transform(Entry<Key, Value> input) {
log.debug("Transform got " + input);
@SuppressWarnings("unchecked") Entry<Key, Value> entry = (Entry<Key, Value>) input;
if (entry.getKey() == null && entry.getValue() == null) {
return null;
}
if (null == entry.getKey() || null == entry.getValue()) {
throw new IllegalArgumentException("Null key or value. Key:" + entry.getKey() + ", Value: " + entry.getValue());
}
EventBase event = responseObjectFactory.getEvent();
ColumnVisibility columnVisibility = new ColumnVisibility(entry.getKey().getColumnVisibility());
Map<String, String> markings;
try {
markings = this.markingFunctions.translateFromColumnVisibilityForAuths(columnVisibility, this.auths);
} catch (Exception e1) {
throw new RuntimeException("could not make markings from: " + columnVisibility);
}
event.setMarkings(markings);
List<FieldBase> fields = new ArrayList<>();
Key key = entry.getKey();
String row = key.getRow().toString();
String cf = key.getColumnFamily().toString();
String cq = key.getColumnQualifier().toString();
String cv = key.getColumnVisibility().toString();
fields.add(makeField("VALUE", markings, cv, 0L, row));
/**
* Added query model to alias FIELD
*/
fields.add(makeField("FIELD", markings, cv, 0L, myQueryModel.aliasFieldNameReverseModel(cf)));
fields.add(makeField("DATE", markings, cv, 0L, cq.substring(0, 8)));
fields.add(makeField("DATA TYPE", markings, cv, 0L, cq.substring(9)));
// Parse the UID.List object from the value
Uid.List uidList = null;
long count = 0;
try {
uidList = Uid.List.parseFrom(entry.getValue().get());
if (null != uidList) {
count = uidList.getCOUNT();
}
} catch (InvalidProtocolBufferException e) {
log.error("Failed to parse Uid List", e);
}
fields.add(makeField("RECORD COUNT", markings, cv, 0L, Long.toString(count)));
event.setFields(fields);
Metadata metadata = new Metadata();
String id = logic.getTableName() + ":" + row + ":" + cf + ":" + cq;
metadata.setInternalId(UUID.nameUUIDFromBytes(id.getBytes()).toString());
metadata.setDataType(entry.getKey().getColumnFamily().toString());
metadata.setRow(entry.getKey().getRow().toString());
metadata.setTable(logic.getTableName());
event.setMetadata(metadata);
return event;
}
use of datawave.marking.MarkingFunctions.Exception in project datawave by NationalSecurityAgency.
the class DiscoveryTransformer method transform.
@Override
public EventBase transform(DiscoveredThing thing) {
Preconditions.checkNotNull(thing, "Received a null object to transform!");
EventBase event = this.responseObjectFactory.getEvent();
Map<String, String> markings;
try {
markings = this.markingFunctions.translateFromColumnVisibility(new ColumnVisibility(thing.getColumnVisibility()));
} catch (Exception e) {
throw new RuntimeException("could not parse to markings: " + thing.getColumnVisibility());
}
event.setMarkings(markings);
List<FieldBase> fields = new ArrayList<>();
fields.add(this.makeField("VALUE", markings, "", 0L, thing.getTerm()));
/**
* Added query model to alias FIELD
*/
fields.add(this.makeField("FIELD", markings, "", 0L, myQueryModel.aliasFieldNameReverseModel(thing.getField())));
fields.add(this.makeField("DATE", markings, "", 0L, thing.getDate()));
fields.add(this.makeField("DATA TYPE", markings, "", 0L, thing.getType()));
// If requested return counts separated by colvis, all counts by colvis could be > total record count
if (thing.getCountsByColumnVisibility() != null && !thing.getCountsByColumnVisibility().isEmpty()) {
for (Map.Entry<Writable, Writable> entry : thing.getCountsByColumnVisibility().entrySet()) {
try {
Map<String, String> eMarkings = this.markingFunctions.translateFromColumnVisibility(new ColumnVisibility(entry.getKey().toString()));
fields.add(this.makeField("RECORD COUNT", new HashMap<>(), entry.getKey().toString(), 0L, entry.getValue().toString()));
} catch (Exception e) {
throw new RuntimeException("could not parse to markings: " + thing.getColumnVisibility());
}
}
} else {
fields.add(this.makeField("RECORD COUNT", markings, "", 0L, Long.toString(thing.getCount())));
}
event.setFields(fields);
Metadata metadata = new Metadata();
// there is no UUID for a single index pointer
metadata.setInternalId("");
// duplicate
metadata.setDataType(thing.getType());
// duplicate
metadata.setRow(thing.getTerm());
metadata.setTable(logic.getTableName());
event.setMetadata(metadata);
return event;
}
use of datawave.marking.MarkingFunctions.Exception in project datawave by NationalSecurityAgency.
the class AttributeBag method updateMetadata.
private void updateMetadata() {
long ts = updateTimestamps();
ColumnVisibility vis = super.getColumnVisibility();
try {
vis = this.combineAndSetColumnVisibilities(getAttributes());
} catch (Exception e) {
log.error("got error combining visibilities", e);
}
setMetadata(vis, ts);
validMetadata = true;
}
use of datawave.marking.MarkingFunctions.Exception in project datawave by NationalSecurityAgency.
the class ShardQueryCountTableTransformer method transform.
@Override
public EventBase transform(Entry<Long, ColumnVisibility> untypedEntry) {
Long count = untypedEntry.getKey();
ColumnVisibility vis = untypedEntry.getValue();
Map<String, String> markings;
try {
markings = markingFunctions.translateFromColumnVisibilityForAuths(vis, auths);
} catch (Exception e1) {
throw new IllegalArgumentException("Unable to translate markings", e1);
}
EventBase e = this.responseObjectFactory.getEvent();
e.setMarkings(markings);
FieldBase field = this.makeField(COUNT_CELL, markings, vis, System.currentTimeMillis(), count);
e.setMarkings(markings);
List<FieldBase> fields = new ArrayList<>();
fields.add(field);
e.setFields(fields);
Metadata metadata = new Metadata();
metadata.setDataType(Constants.EMPTY_STRING);
// There is only one item returned for the entire query logic.
metadata.setInternalId(field.getName());
metadata.setRow(Constants.EMPTY_STRING);
e.setMetadata(metadata);
return e;
}
use of datawave.marking.MarkingFunctions.Exception in project datawave by NationalSecurityAgency.
the class EventQueryTransformer method transform.
@Override
public EventBase transform(Entry<Key, Value> entry) {
Key key = entry.getKey();
Value val = entry.getValue();
if (entry.getKey() == null && entry.getValue() == null)
return null;
if (null == entry.getKey() || null == entry.getValue()) {
throw new IllegalArgumentException("Null key or value. Key:" + entry.getKey() + ", Value: " + entry.getValue());
}
EventBase event = this.responseObjectFactory.getEvent();
Map<String, String> markings = null;
try {
markings = this.markingFunctions.translateFromColumnVisibilityForAuths(new ColumnVisibility(key.getColumnVisibility()), this.auths);
} catch (Exception e) {
log.error("could not translate " + key.getColumnVisibility() + " to markings, skipping entry");
return null;
}
if (null == markings || markings.isEmpty()) {
// can't process this one because we did not have valid security markings
log.error("Transformer visibility interpreter was null, skipping entry");
return null;
}
ByteArrayInputStream bais = new ByteArrayInputStream(entry.getValue().get());
Input i = new Input(bais);
eventFields = kryo.readObject(i, EventFields.class);
i.close();
String row = entry.getKey().getRow().toString();
String colf = entry.getKey().getColumnFamily().toString();
String colq = entry.getKey().getColumnQualifier().toString();
// evaluated by using the returnUidMapper (@see datawave.core.iterators.EvaluatingIterator: aggregateAltEvent)
if (!colq.equals("")) {
colf = colq;
}
int sepIndex = colf.indexOf(Constants.NULL_BYTE_STRING);
String baseUid = colf.substring(sepIndex + 1);
Set<FieldBase<?>> values = new HashSet<>();
String origFieldName = null;
String fieldName = null;
// Hold unique Column Visibilities and merge them at the end
// for the overall event ColumnVisibility.
Set<ColumnVisibility> visibilitiesToMerge = new HashSet<>();
for (Entry<String, Collection<FieldValue>> e : eventFields.asMap().entrySet()) {
origFieldName = e.getKey();
if (this.qm != null) {
fieldName = this.qm.aliasFieldNameReverseModel(origFieldName);
} else {
fieldName = origFieldName;
}
for (FieldValue fv : e.getValue()) {
visibilitiesToMerge.add(fv.getVisibility());
try {
Map<String, String> fieldMarkings = this.markingFunctions.translateFromColumnVisibility(fv.getVisibility());
String value = new String(fv.getValue(), Charset.forName("UTF-8"));
// if this is a content field name, then replace the value with the uid
if (getContentFieldNames().contains(fieldName)) {
value = baseUid;
}
values.add(this.makeField(fieldName, fieldMarkings, new String(fv.getVisibility().getExpression()), entry.getKey().getTimestamp(), value));
} catch (Exception e1) {
throw new RuntimeException("could not make markings from: " + fv.getVisibility());
}
}
}
ColumnVisibility columnVisibility = null;
try {
columnVisibility = this.markingFunctions.combine(visibilitiesToMerge);
event.setMarkings(this.markingFunctions.translateFromColumnVisibility(columnVisibility));
} catch (Exception e1) {
throw new RuntimeException("could not make markings from: " + columnVisibility);
}
event.setFields(new ArrayList<>(values));
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
// in practice this is about 6 times the size of the kryo bytes
event.setSizeInBytes(entry.getValue().getSize() * 6);
return event;
}
Aggregations