use of org.finos.waltz.model.datatype.DataTypeDecorator in project waltz by khartec.
the class FlowSummaryWithTypesAndPhysicalsExport method main.
public static void main(String[] args) throws IOException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
DSLContext dsl = ctx.getBean(DSLContext.class);
ApplicationIdSelectorFactory appIdSelectorFactory = new ApplicationIdSelectorFactory();
ApplicationDao applicationDao = ctx.getBean(ApplicationDao.class);
OrganisationalUnitDao organisationalUnitDao = ctx.getBean(OrganisationalUnitDao.class);
LogicalFlowDao logicalFlowDao = ctx.getBean(LogicalFlowDao.class);
LogicalFlowDecoratorDao decoratorDao = ctx.getBean(LogicalFlowDecoratorDao.class);
DataTypeDao dataTypeDao = ctx.getBean(DataTypeDao.class);
Select<Record1<Long>> appSelector = mkAppIdSelector(appIdSelectorFactory);
Select<Record1<Long>> logicalFlowSelector = mkLogicalFlowSelectorFromAppSelector(appSelector);
System.out.println("Loading apps");
Set<Application> allApps = fromCollection(applicationDao.findAll());
System.out.println("Loading in scope apps");
Set<Long> inScopeAppIds = toIds(applicationDao.findByAppIdSelector(appSelector));
System.out.println("Loading OUs");
List<OrganisationalUnit> allOUs = organisationalUnitDao.findAll();
System.out.println("Loading DTs");
List<DataType> allDataTypes = dataTypeDao.findAll();
System.out.println("Loading Logical Flows");
List<LogicalFlow> logicalFlows = logicalFlowDao.findBySelector(logicalFlowSelector);
System.out.println("Loading decorators");
List<DataTypeDecorator> decorators = decoratorDao.findByAppIdSelector(appSelector);
System.out.println("Loading phys flows");
Map<Long, Collection<Tuple7<Long, String, String, String, String, String, String>>> physicalsByLogical = loadPhysicalsByLogical(dsl, logicalFlowSelector);
System.out.println("Indexing");
Map<Optional<Long>, Application> appsById = indexByOptId(allApps);
Map<Optional<Long>, DataType> dataTypesById = indexByOptId(allDataTypes);
Map<Optional<Long>, OrganisationalUnit> ousById = indexByOptId(allOUs);
Map<Long, Collection<DataTypeDecorator>> decoratorsByLogicalFlowId = groupBy(DataTypeDecorator::dataFlowId, decorators);
System.out.println("Processing");
CsvListWriter csvWriter = setupCSVWriter();
logicalFlows.stream().filter(lf -> lf.source().kind() == EntityKind.APPLICATION && lf.target().kind() == EntityKind.APPLICATION).map(Tuple::tuple).map(t -> t.concat(appsById.get(Optional.of(t.v1.source().id())))).map(t -> t.concat(appsById.get(Optional.of(t.v1.target().id())))).filter(t -> t.v2 != null && t.v3 != null).map(t -> t.concat(ousById.get(Optional.of(t.v2.organisationalUnitId())))).map(t -> t.concat(ousById.get(Optional.of(t.v3.organisationalUnitId())))).map(t -> t.concat(decoratorsByLogicalFlowId.getOrDefault(t.v1.id().orElse(-1L), emptyList()).stream().filter(d -> d.decoratorEntity().kind() == EntityKind.DATA_TYPE).map(d -> dataTypesById.get(Optional.of(d.decoratorEntity().id()))).sorted(Comparator.comparing(NameProvider::name)).collect(Collectors.toList()))).map(t -> t.concat(inScopeAppIds.contains(t.v2.id().get()))).map(t -> t.concat(inScopeAppIds.contains(t.v3.id().get()))).flatMap(t -> physicalsByLogical.getOrDefault(t.v1.id().orElse(-1L), newArrayList(tuple(-1L, "-", "-", "-", "-", "-", "-"))).stream().map(p -> t.concat(p.skip1()))).map(t -> newArrayList(// src
t.v2.name(), t.v2.assetCode().map(ExternalIdValue::value).orElse(""), t.v2.applicationKind().name(), t.v2.entityLifecycleStatus().name(), // src OU
Optional.ofNullable(t.v4).map(NameProvider::name).orElse("?"), t.v7.toString(), // trg
t.v3.name(), t.v3.assetCode().map(ExternalIdValue::value).orElse(""), t.v3.applicationKind().name(), t.v3.entityLifecycleStatus().name(), // trg OU
Optional.ofNullable(t.v5).map(NameProvider::name).orElse("?"), t.v8.toString(), StringUtilities.joinUsing(t.v6, NameProvider::name, ","), t.v9, t.v10, t.v11, t.v12, t.v13, t.v14)).forEach(Unchecked.consumer(csvWriter::write));
}
use of org.finos.waltz.model.datatype.DataTypeDecorator in project waltz by khartec.
the class PhysicalSpecificationServiceTest method propagateDataTypesToLogicalFlows.
@Test
public void propagateDataTypesToLogicalFlows() {
String username = mkName("propagateDataTypesToLogicalFlows");
EntityReference a = appHelper.createNewApp("a", ouIds.a);
EntityReference b = appHelper.createNewApp("b", ouIds.a1);
LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
Long specId = psHelper.createPhysicalSpec(a, "findByEntityReference");
pfHelper.createPhysicalFlow(flow.entityReference().id(), specId, username);
assertThrows(IllegalArgumentException.class, () -> psSvc.propagateDataTypesToLogicalFlows(null, specId), "Should throw exception if username is null as cannot be logged");
Long dt1Id = dtHelper.createDataType("dt1");
Long dt2Id = dtHelper.createDataType("dt2");
lfHelper.createLogicalFlowDecorators(flow.entityReference(), asSet(dt1Id));
psSvc.propagateDataTypesToLogicalFlows(username, specId);
List<DataTypeDecorator> lfDecorators = lfHelper.fetchDecoratorsForFlow(flow.entityReference().id());
assertEquals(asSet(dt1Id), map(lfDecorators, DataTypeDecorator::dataTypeId), "Propagating does not remove data types from the logical");
dtdSvc.updateDecorators(username, mkRef(EntityKind.PHYSICAL_SPECIFICATION, specId), asSet(dt1Id), emptySet());
psSvc.propagateDataTypesToLogicalFlows(username, specId);
assertEquals(asSet(dt1Id), map(lfDecorators, DataTypeDecorator::dataTypeId), "Can handle data types that already exist on the logical flow");
dtdSvc.updateDecorators(username, mkRef(EntityKind.PHYSICAL_SPECIFICATION, specId), asSet(dt2Id), emptySet());
psSvc.propagateDataTypesToLogicalFlows(username, specId);
List<DataTypeDecorator> lfDecoratorsWithSpecDts = lfHelper.fetchDecoratorsForFlow(flow.entityReference().id());
assertEquals(asSet(dt1Id, dt2Id), map(lfDecoratorsWithSpecDts, DataTypeDecorator::dataTypeId), "Adds data types that are not currently on the logical flow");
}
use of org.finos.waltz.model.datatype.DataTypeDecorator in project waltz by khartec.
the class PhysicalFlowUploadService method getOrCreateLogicalFlow.
private LogicalFlow getOrCreateLogicalFlow(EntityReference source, EntityReference target, EntityReference dataType, String username) {
LogicalFlow flow = logicalFlowDao.getBySourceAndTarget(source, target);
if (flow == null) {
LocalDateTime now = nowUtc();
LogicalFlow flowToAdd = ImmutableLogicalFlow.builder().source(source).target(target).lastUpdatedBy(username).lastUpdatedAt(now).provenance("waltz").created(UserTimestamp.mkForUser(username, now)).build();
flow = logicalFlowDao.addFlow(flowToAdd);
}
EntityReference logicalFlowEntityRef = EntityReference.mkRef(EntityKind.LOGICAL_DATA_FLOW, flow.id().get());
DataTypeDecorator existingDecorator = dataTypeDecoratorService.getByEntityRefAndDataTypeId(logicalFlowEntityRef, dataType.id());
if (existingDecorator == null) {
dataTypeDecoratorService.addDecorators(username, logicalFlowEntityRef, fromArray(dataType.id()));
}
return flow;
}
use of org.finos.waltz.model.datatype.DataTypeDecorator in project waltz by khartec.
the class PhysicalFlowUploadService method getOrCreatePhysicalSpec.
private PhysicalSpecification getOrCreatePhysicalSpec(PhysicalFlowParsed flow, String username) {
EntityReference owner = flow.owner();
DataFormatKind format = flow.format();
String name = flow.name();
// check database
PhysicalSpecification spec = physicalSpecificationDao.getByParsedFlow(flow);
if (spec == null) {
// create
LocalDateTime now = nowUtc();
PhysicalSpecification specToAdd = ImmutablePhysicalSpecification.builder().owningEntity(owner).format(format).name(name).externalId(Optional.ofNullable(flow.specExternalId()).orElse("")).description(Optional.ofNullable(flow.specDescription()).orElse("")).lastUpdatedBy(username).lastUpdatedAt(now).provenance("waltz").created(UserTimestamp.mkForUser(username, now)).build();
Long id = physicalSpecificationDao.create(specToAdd);
spec = ImmutablePhysicalSpecification.copyOf(specToAdd).withId(id);
}
long dataTypeId = flow.dataType().id();
EntityReference specificationEntityRef = EntityReference.mkRef(EntityKind.PHYSICAL_SPECIFICATION, spec.id().get());
DataTypeDecorator existingDataType = dataTypeDecoratorService.getByEntityRefAndDataTypeId(specificationEntityRef, dataTypeId);
if (existingDataType == null) {
dataTypeDecoratorService.addDecorators(username, specificationEntityRef, fromArray(dataTypeId));
}
return spec;
}
use of org.finos.waltz.model.datatype.DataTypeDecorator in project waltz by khartec.
the class DataTypeDecoratorServiceTest method findByFlowIds.
@Test
public void findByFlowIds() {
Collection<DataTypeDecorator> lfDecs = dtdSvc.findByFlowIds(emptyList(), EntityKind.LOGICAL_DATA_FLOW);
Collection<DataTypeDecorator> psDecs = dtdSvc.findByFlowIds(emptyList(), EntityKind.PHYSICAL_SPECIFICATION);
assertEquals(emptyList(), lfDecs, "If empty id list provided returns empty list");
assertEquals(emptyList(), psDecs, "If empty id list provided returns empty list");
Collection<DataTypeDecorator> invalidId = dtdSvc.findByFlowIds(asList(-1L), EntityKind.LOGICAL_DATA_FLOW);
assertEquals(emptyList(), invalidId, "If flow id doesn't exist returns empty list");
assertThrows(IllegalArgumentException.class, () -> dtdSvc.findByFlowIds(asList(-1L), EntityKind.APPLICATION), "If unsupported kind id throws exception");
EntityReference a = appHelper.createNewApp("a", ouIds.a);
EntityReference b = appHelper.createNewApp("b", ouIds.a1);
LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
Collection<DataTypeDecorator> withNoDecorators = dtdSvc.findByFlowIds(asList(flow.entityReference().id()), EntityKind.LOGICAL_DATA_FLOW);
assertEquals(emptyList(), withNoDecorators, "flow has no decorators");
Long dtId = dataTypeHelper.createDataType("findByFlowIds");
String username = mkName("findByFlowIds");
dtdSvc.updateDecorators(username, flow.entityReference(), asSet(dtId), emptySet());
Collection<DataTypeDecorator> flowDecorators = dtdSvc.findByFlowIds(asList(flow.entityReference().id()), EntityKind.LOGICAL_DATA_FLOW);
assertEquals(1, flowDecorators.size(), "Flow with one datatype associated returns a set with one decorator");
assertEquals(dtId, Long.valueOf(first(flowDecorators).dataTypeId()), "Returns the correct datatype id on the decorator");
Long dtId2 = dataTypeHelper.createDataType("findByFlowIds2");
Long dtId3 = dataTypeHelper.createDataType("findByFlowIds3");
dtdSvc.updateDecorators(username, flow.entityReference(), asSet(dtId2, dtId3), emptySet());
Collection<DataTypeDecorator> multipleDecorators = dtdSvc.findByFlowIds(asList(flow.entityReference().id()), EntityKind.LOGICAL_DATA_FLOW);
assertEquals(3, multipleDecorators.size());
assertEquals(asSet(dtId, dtId2, dtId3), map(multipleDecorators, DataTypeDecorator::dataTypeId), "Returns all decorators for the flow");
assertThrows(UnsupportedOperationException.class, () -> dtdSvc.findByFlowIds(asSet(dtId), EntityKind.PHYSICAL_SPECIFICATION), "Find by flow ids is only supported for logical flows");
}
Aggregations