use of datawave.webservice.query.result.event.EventBase in project datawave by NationalSecurityAgency.
the class TermFrequencyQueryTransformer method createResponse.
@Override
public BaseQueryResponse createResponse(List<Object> resultList) {
DefaultEventQueryResponse response = new DefaultEventQueryResponse();
List<EventBase> eventList = new ArrayList<>();
for (Object o : resultList) {
EventBase result = (EventBase) o;
eventList.add(result);
}
response.setEvents(eventList);
response.setReturnedEvents(new Long(eventList.size()));
return response;
}
use of datawave.webservice.query.result.event.EventBase in project datawave by NationalSecurityAgency.
the class GroupingTest method runTestQueryWithGrouping.
protected BaseQueryResponse runTestQueryWithGrouping(Map<String, Integer> expected, String querystr, Date startDate, Date endDate, Map<String, String> extraParms, Connector connector) throws Exception {
log.debug("runTestQueryWithGrouping");
QueryImpl settings = new QueryImpl();
settings.setBeginDate(startDate);
settings.setEndDate(endDate);
settings.setPagesize(Integer.MAX_VALUE);
settings.setQueryAuthorizations(auths.serialize());
settings.setQuery(querystr);
settings.setParameters(extraParms);
settings.setId(UUID.randomUUID());
log.debug("query: " + settings.getQuery());
log.debug("logic: " + settings.getQueryLogicName());
GenericQueryConfiguration config = logic.initialize(connector, settings, authSet);
logic.setupQuery(config);
DocumentTransformer transformer = (DocumentTransformer) (logic.getTransformer(settings));
TransformIterator iter = new DatawaveTransformIterator(logic.iterator(), transformer);
List<Object> eventList = new ArrayList<>();
while (iter.hasNext()) {
eventList.add(iter.next());
}
BaseQueryResponse response = transformer.createResponse(eventList);
// un-comment to look at the json output
ObjectMapper mapper = new ObjectMapper();
mapper.enable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME);
mapper.writeValue(temporaryFolder.newFile(), response);
Assert.assertTrue(response instanceof DefaultEventQueryResponse);
DefaultEventQueryResponse eventQueryResponse = (DefaultEventQueryResponse) response;
Assert.assertEquals("Got the wrong number of events", expected.size(), (long) eventQueryResponse.getReturnedEvents());
for (EventBase event : eventQueryResponse.getEvents()) {
String firstKey = "";
String secondKey = "";
Integer value = null;
for (Object field : event.getFields()) {
FieldBase fieldBase = (FieldBase) field;
switch(fieldBase.getName()) {
case "COUNT":
value = Integer.valueOf(fieldBase.getValueString());
break;
case "GENDER":
case "GEN":
case "BIRTHDAY":
firstKey = fieldBase.getValueString();
break;
case "AGE":
case "AG":
case "RECORD":
secondKey = fieldBase.getValueString();
break;
}
}
log.debug("mapping is " + firstKey + "-" + secondKey + " count:" + value);
String key;
if (!firstKey.isEmpty() && !secondKey.isEmpty()) {
key = firstKey + "-" + secondKey;
} else if (!firstKey.isEmpty()) {
key = firstKey;
} else {
key = secondKey;
}
Assert.assertEquals(expected.get(key), value);
}
return response;
}
use of datawave.webservice.query.result.event.EventBase in project datawave by NationalSecurityAgency.
the class QueryWizardResultResponse method buildTableColumnHeadings.
private HashSet<String> buildTableColumnHeadings(StringBuilder builder, DefaultEventQueryResponse tempResponse) {
HashSet<String> fieldnameSet = new HashSet<>();
builder.append("<thead><tr><th>DataType</th>");
for (EventBase event : tempResponse.getEvents()) {
for (Object field : event.getFields()) {
if (field instanceof DefaultField) {
fieldnameSet.add(((DefaultField) field).getName());
}
}
}
for (String fieldname : fieldnameSet) {
builder.append("<th>");
builder.append(fieldname);
builder.append("</th>");
}
builder.append("</tr></thead>");
return fieldnameSet;
}
use of datawave.webservice.query.result.event.EventBase in project datawave by NationalSecurityAgency.
the class DefaultEventQueryResponse method merge.
@Override
public void merge(EventQueryResponseBase other) {
if (null != other.getEvents()) {
if (null == this.events) {
this.events = new ArrayList<DefaultEvent>();
}
for (EventBase event : other.getEvents()) {
this.events.add((DefaultEvent) event);
}
}
if (null != other.getFields()) {
if (null == this.fields) {
this.fields = new ArrayList<String>(other.getFields());
} else {
this.fields.addAll(other.getFields());
}
}
this.returnedEvents += other.getReturnedEvents();
this.totalEvents += other.getTotalEvents();
this.setOperationTimeMS(this.getOperationTimeMS() + other.getOperationTimeMS());
// If either is partial results, then this is partial results
if (this.isPartialResults() != other.isPartialResults()) {
this.setPartialResults(true);
}
if (null != other.getMessages()) {
if (null == this.getMessages()) {
this.setMessages(other.getMessages());
} else {
this.getMessages().addAll(other.getMessages());
}
}
if (null != other.getExceptions()) {
if (null == this.getExceptions()) {
this.setExceptions(new LinkedList<QueryExceptionType>(other.getExceptions()));
} else {
this.getExceptions().addAll(other.getExceptions());
}
}
}
use of datawave.webservice.query.result.event.EventBase in project datawave by NationalSecurityAgency.
the class DefaultEventQueryResponse method setEvents.
/*
* (non-Javadoc)
*
* @see datawave.webservice.result.EventQueryResponse#setEvents(java.util.List)
*/
@Override
public void setEvents(List<EventBase> entries) {
if (entries == null) {
this.events = null;
} else {
List<DefaultEvent> events = new ArrayList<>(entries.size());
for (EventBase event : entries) {
events.add((DefaultEvent) event);
}
this.events = events;
}
}
Aggregations