use of uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable in project Gaffer by gchq.
the class GetTraitsHandler method createCurrentTraits.
private Set<StoreTrait> createCurrentTraits(final Store store) {
final Set<StoreTrait> traits = Sets.newHashSet(store.getTraits());
final Schema schema = store.getSchema();
final boolean hasAggregatedGroups = isNotEmpty(schema.getAggregatedGroups());
final boolean hasVisibility = nonNull(schema.getVisibilityProperty());
boolean hasGroupBy = false;
boolean hasValidation = false;
for (final SchemaElementDefinition def : new ChainedIterable<SchemaElementDefinition>(schema.getEntities().values(), schema.getEdges().values())) {
hasValidation = hasValidation || def.hasValidation();
hasGroupBy = hasGroupBy || isNotEmpty(def.getGroupBy());
if (hasGroupBy && hasValidation) {
break;
}
}
if (!hasAggregatedGroups) {
traits.remove(StoreTrait.INGEST_AGGREGATION);
traits.remove(StoreTrait.QUERY_AGGREGATION);
}
if (!hasGroupBy && traits.contains(StoreTrait.INGEST_AGGREGATION)) {
traits.remove(StoreTrait.QUERY_AGGREGATION);
}
if (!hasValidation) {
traits.remove(StoreTrait.STORE_VALIDATION);
}
if (!hasVisibility) {
traits.remove(StoreTrait.VISIBILITY);
}
return traits;
}
use of uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable in project Gaffer by gchq.
the class RoadTrafficCsvElementGenerator method _apply.
@Override
public Iterable<Element> _apply(final CSVRecord record) {
// Check that the record has the expected number of fields
if (!record.isConsistent()) {
return Collections.emptyList();
}
final FreqMap vehicleCountsByType = getVehicleCounts(record);
final Date startDate = getDate(record.get(dCount.fieldName()), record.get(Hour.fieldName()));
final Date endDate = null != startDate ? DateUtils.addMilliseconds(DateUtils.addHours(startDate, 1), -1) : null;
final String region = record.get(Region_Name.fieldName());
final String location = record.get(ONS_LA_Name.fieldName());
final String road = record.get(Road.fieldName());
final String junctionA = road + ":" + record.get(A_Junction.fieldName());
final String junctionB = road + ":" + record.get(B_Junction.fieldName());
final String junctionALocation = record.get(A_Ref_E.fieldName()) + "," + record.get(A_Ref_N.fieldName());
final String junctionBLocation = record.get(B_Ref_E.fieldName()) + "," + record.get(B_Ref_N.fieldName());
final List<Edge> edges = Arrays.asList(new Edge.Builder().group(ElementGroup.REGION_CONTAINS_LOCATION).source(region).dest(location).directed(true).build(), new Edge.Builder().group(ElementGroup.LOCATION_CONTAINS_ROAD).source(location).dest(road).directed(true).build(), new Edge.Builder().group(ElementGroup.ROAD_HAS_JUNCTION).source(road).dest(junctionA).directed(true).build(), new Edge.Builder().group(ElementGroup.ROAD_HAS_JUNCTION).source(road).dest(junctionB).directed(true).build(), new Edge.Builder().group(ElementGroup.JUNCTION_LOCATED_AT).source(junctionA).dest(junctionALocation).directed(true).build(), new Edge.Builder().group(ElementGroup.JUNCTION_LOCATED_AT).source(junctionB).dest(junctionBLocation).directed(true).build(), new Edge.Builder().group(ElementGroup.ROAD_USE).source(junctionA).dest(junctionB).directed(true).property("startDate", startDate).property("endDate", endDate).property("count", getTotalCount(vehicleCountsByType)).property("countByVehicleType", vehicleCountsByType).build());
final List<Entity> entities = Arrays.asList(new Entity.Builder().group(ElementGroup.JUNCTION_USE).vertex(junctionA).property("countByVehicleType", vehicleCountsByType).property("startDate", startDate).property("endDate", endDate).property("count", getTotalCount(vehicleCountsByType)).build(), new Entity.Builder().group(ElementGroup.JUNCTION_USE).vertex(junctionB).property("countByVehicleType", vehicleCountsByType).property("endDate", endDate).property("startDate", startDate).property("count", getTotalCount(vehicleCountsByType)).build());
final List<Entity> cardinalityEntities = createCardinalities(edges);
// Create an iterable containing all the edges and entities
return new ChainedIterable<>(edges, entities, cardinalityEntities);
}
use of uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable in project Gaffer by gchq.
the class AccumuloStore method validateSchema.
@Override
protected void validateSchema(final ValidationResult validationResult, final Serialiser serialiser) {
super.validateSchema(validationResult, serialiser);
final String timestampProperty = getSchema().getConfig(AccumuloStoreConstants.TIMESTAMP_PROPERTY);
if (null != timestampProperty) {
final Iterable<SchemaElementDefinition> defs = new ChainedIterable<>(getSchema().getEntities().values(), getSchema().getEdges().values());
for (final SchemaElementDefinition def : defs) {
final TypeDefinition typeDef = def.getPropertyTypeDef(timestampProperty);
if (null != typeDef && null != typeDef.getAggregateFunction() && !(typeDef.getAggregateFunction() instanceof Max)) {
validationResult.addError("The aggregator for the " + timestampProperty + " property must be set to: " + Max.class.getName() + " this cannot be overridden for this Accumulo Store, as you have told Accumulo to store this property in the timestamp column.");
}
}
}
}
use of uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable in project Gaffer by gchq.
the class FederatedGetAllElementsHandlerTest method validateMergeResultsFromFieldObjects.
@Override
protected boolean validateMergeResultsFromFieldObjects(final CloseableIterable<? extends Element> result, final Object... resultParts) {
assertNotNull(result);
final Iterable[] resultPartItrs = Arrays.copyOf(resultParts, resultParts.length, Iterable[].class);
final ArrayList<Object> elements = Lists.newArrayList(new ChainedIterable<>(resultPartItrs));
int i = 0;
for (Element e : result) {
assertTrue(e instanceof Entity);
elements.contains(e);
i++;
}
assertEquals(elements.size(), i);
return true;
}
use of uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable in project Gaffer by gchq.
the class FederatedGetElementsHandlerTest method validateMergeResultsFromFieldObjects.
@Override
protected boolean validateMergeResultsFromFieldObjects(final CloseableIterable<? extends Element> result, final Object... resultParts) {
assertNotNull(result);
final Iterable[] resultPartItrs = Arrays.copyOf(resultParts, resultParts.length, Iterable[].class);
final ArrayList<Object> elements = Lists.newArrayList(new ChainedIterable<>(resultPartItrs));
int i = 0;
for (Element e : result) {
assertTrue(e instanceof Entity);
elements.contains(e);
i++;
}
assertEquals(elements.size(), i);
return true;
}
Aggregations