@Test public void retrieveDefaultPropertyUsesTheFirstQuadFound() { List<SummaryProp> defaultProperties = Lists.newArrayList(summaryPropertyWithPath(DEFAULT_PATH, DEFAULT_PATH_2)); SummaryPropDataRetriever instance = new SummaryPropDataRetriever(USER_CONFIGURED_PATH, defaultProperties); QuadStore quadStore = mock(QuadStore.class); CursorQuad foundQuad1 = quadWithObject(OBJECT_1, Optional.empty()); CursorQuad foundQuad2 = quadWithObject(OBJECT_2, Optional.empty()); given(quadStore.getQuads(SOURCE, DEFAULT_PATH, Direction.OUT, "")).willReturn(Stream.of(foundQuad1, foundQuad2)); CursorQuad bjectOfPath2 = quadWithObject(OBJECT_OF_PATH2, Optional.empty()); given(quadStore.getQuads(OBJECT_1, DEFAULT_PATH_2, Direction.OUT, "")).willReturn(Stream.of(bjectOfPath2)); instance.createSummaryProperty(subjectWithUri(SOURCE), dataSetWithQuadStore(quadStore), COLLECTION); verify(quadStore).getQuads(SOURCE, DEFAULT_PATH, Direction.OUT, ""); verify(quadStore).getQuads(OBJECT_1, DEFAULT_PATH_2, Direction.OUT, ""); verify(quadStore, never()).getQuads(OBJECT_2, DEFAULT_PATH_2, Direction.OUT, ""); }
public Optional<TypedValue> createSummaryProperty(SubjectReference source, DataSet dataSet, String typeUri) { QuadStore quadStore = dataSet.getQuadStore(); final Optional<TypedValue> localConfiguredSummaryProp = getType(quadStore, source.getSubjectUri(), typeUri) .flatMap(collection -> getDataQuad(quadStore, collection.getObject(), summaryPropConfigPredicate)) .flatMap(userConfigured -> { try { SummaryProp summaryProp = OBJECT_MAPPER.readValue(userConfigured.getObject(), SummaryProp.class); return getDataQuad(summaryProp.getPath(), source.getSubjectUri(), quadStore) .map(quad -> createTypedValue(quad, dataSet)); } catch (IOException e) { LOG.error("Cannot parse SummaryProp: '{}'", userConfigured.getObject()); } return Optional.empty(); }); if (localConfiguredSummaryProp.isPresent()) { return localConfiguredSummaryProp; } else { for (SummaryProp prop : defaultProperties) { Optional<CursorQuad> quad = getDataQuad(prop.getPath(), source.getSubjectUri(), quadStore); if (quad.isPresent()) { return Optional.of(createTypedValue(quad.get(), dataSet)); } } return Optional.empty(); } }
SummaryPropDataRetriever { public Optional<TypedValue> createSummaryProperty(SubjectReference source, DataSet dataSet, String typeUri) { QuadStore quadStore = dataSet.getQuadStore(); final Optional<TypedValue> localConfiguredSummaryProp = getType(quadStore, source.getSubjectUri(), typeUri) .flatMap(collection -> getDataQuad(quadStore, collection.getObject(), summaryPropConfigPredicate)) .flatMap(userConfigured -> { try { SummaryProp summaryProp = OBJECT_MAPPER.readValue(userConfigured.getObject(), SummaryProp.class); return getDataQuad(summaryProp.getPath(), source.getSubjectUri(), quadStore) .map(quad -> createTypedValue(quad, dataSet)); } catch (IOException e) { LOG.error("Cannot parse SummaryProp: '{}'", userConfigured.getObject()); } return Optional.empty(); }); if (localConfiguredSummaryProp.isPresent()) { return localConfiguredSummaryProp; } else { for (SummaryProp prop : defaultProperties) { Optional<CursorQuad> quad = getDataQuad(prop.getPath(), source.getSubjectUri(), quadStore); if (quad.isPresent()) { return Optional.of(createTypedValue(quad.get(), dataSet)); } } return Optional.empty(); } } }
SummaryPropDataRetriever { public Optional<TypedValue> createSummaryProperty(SubjectReference source, DataSet dataSet, String typeUri) { QuadStore quadStore = dataSet.getQuadStore(); final Optional<TypedValue> localConfiguredSummaryProp = getType(quadStore, source.getSubjectUri(), typeUri) .flatMap(collection -> getDataQuad(quadStore, collection.getObject(), summaryPropConfigPredicate)) .flatMap(userConfigured -> { try { SummaryProp summaryProp = OBJECT_MAPPER.readValue(userConfigured.getObject(), SummaryProp.class); return getDataQuad(summaryProp.getPath(), source.getSubjectUri(), quadStore) .map(quad -> createTypedValue(quad, dataSet)); } catch (IOException e) { LOG.error("Cannot parse SummaryProp: '{}'", userConfigured.getObject()); } return Optional.empty(); }); if (localConfiguredSummaryProp.isPresent()) { return localConfiguredSummaryProp; } else { for (SummaryProp prop : defaultProperties) { Optional<CursorQuad> quad = getDataQuad(prop.getPath(), source.getSubjectUri(), quadStore); if (quad.isPresent()) { return Optional.of(createTypedValue(quad.get(), dataSet)); } } return Optional.empty(); } } SummaryPropDataRetriever(String summaryPropConfigPredicate, List<SummaryProp> defaultProperties); }
SummaryPropDataRetriever { public Optional<TypedValue> createSummaryProperty(SubjectReference source, DataSet dataSet, String typeUri) { QuadStore quadStore = dataSet.getQuadStore(); final Optional<TypedValue> localConfiguredSummaryProp = getType(quadStore, source.getSubjectUri(), typeUri) .flatMap(collection -> getDataQuad(quadStore, collection.getObject(), summaryPropConfigPredicate)) .flatMap(userConfigured -> { try { SummaryProp summaryProp = OBJECT_MAPPER.readValue(userConfigured.getObject(), SummaryProp.class); return getDataQuad(summaryProp.getPath(), source.getSubjectUri(), quadStore) .map(quad -> createTypedValue(quad, dataSet)); } catch (IOException e) { LOG.error("Cannot parse SummaryProp: '{}'", userConfigured.getObject()); } return Optional.empty(); }); if (localConfiguredSummaryProp.isPresent()) { return localConfiguredSummaryProp; } else { for (SummaryProp prop : defaultProperties) { Optional<CursorQuad> quad = getDataQuad(prop.getPath(), source.getSubjectUri(), quadStore); if (quad.isPresent()) { return Optional.of(createTypedValue(quad.get(), dataSet)); } } return Optional.empty(); } } SummaryPropDataRetriever(String summaryPropConfigPredicate, List<SummaryProp> defaultProperties); Optional<TypedValue> createSummaryProperty(SubjectReference source, DataSet dataSet, String typeUri); }
SummaryPropDataRetriever { public Optional<TypedValue> createSummaryProperty(SubjectReference source, DataSet dataSet, String typeUri) { QuadStore quadStore = dataSet.getQuadStore(); final Optional<TypedValue> localConfiguredSummaryProp = getType(quadStore, source.getSubjectUri(), typeUri) .flatMap(collection -> getDataQuad(quadStore, collection.getObject(), summaryPropConfigPredicate)) .flatMap(userConfigured -> { try { SummaryProp summaryProp = OBJECT_MAPPER.readValue(userConfigured.getObject(), SummaryProp.class); return getDataQuad(summaryProp.getPath(), source.getSubjectUri(), quadStore) .map(quad -> createTypedValue(quad, dataSet)); } catch (IOException e) { LOG.error("Cannot parse SummaryProp: '{}'", userConfigured.getObject()); } return Optional.empty(); }); if (localConfiguredSummaryProp.isPresent()) { return localConfiguredSummaryProp; } else { for (SummaryProp prop : defaultProperties) { Optional<CursorQuad> quad = getDataQuad(prop.getPath(), source.getSubjectUri(), quadStore); if (quad.isPresent()) { return Optional.of(createTypedValue(quad.get(), dataSet)); } } return Optional.empty(); } } SummaryPropDataRetriever(String summaryPropConfigPredicate, List<SummaryProp> defaultProperties); Optional<TypedValue> createSummaryProperty(SubjectReference source, DataSet dataSet, String typeUri);  }