use of org.finos.waltz.model.external_identifier.ExternalIdValue 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.external_identifier.ExternalIdValue in project waltz by khartec.
the class ReportGridExtractor method writeExcelBody.
private int writeExcelBody(List<Tuple2<Application, ArrayList<Object>>> reportRows, SXSSFSheet sheet) {
AtomicInteger rowNum = new AtomicInteger(1);
reportRows.forEach(r -> {
long appId = r.v1.entityReference().id();
String appName = r.v1.name();
Optional<ExternalIdValue> assetCode = r.v1.assetCode();
LifecyclePhase lifecyclePhase = r.v1.lifecyclePhase();
List<Object> appInfo = asList(appId, appName, assetCode, lifecyclePhase.name());
List<Object> values = concat(appInfo, r.v2);
Row row = sheet.createRow(rowNum.getAndIncrement());
AtomicInteger colNum = new AtomicInteger(0);
for (Object value : values) {
Object v = value instanceof Optional ? ((Optional<?>) value).orElse(null) : value;
int nextColNum = colNum.getAndIncrement();
if (v == null) {
row.createCell(nextColNum);
} else if (v instanceof Number) {
Cell cell = row.createCell(nextColNum, CellType.NUMERIC);
cell.setCellValue(((Number) v).doubleValue());
} else if (v instanceof ExternalIdValue) {
Cell cell = row.createCell(nextColNum, CellType.STRING);
cell.setCellValue(((ExternalIdValue) v).value());
} else {
Cell cell = row.createCell(nextColNum);
cell.setCellValue(Objects.toString(v));
}
}
});
return rowNum.get();
}
use of org.finos.waltz.model.external_identifier.ExternalIdValue in project waltz by khartec.
the class ReportGridExtractor method simplify.
private List<Object> simplify(Tuple2<Application, ArrayList<Object>> row) {
long appId = row.v1.entityReference().id();
String appName = row.v1.name();
Optional<ExternalIdValue> assetCode = row.v1.assetCode();
LifecyclePhase lifecyclePhase = row.v1.lifecyclePhase();
List<Object> appInfo = asList(appId, appName, assetCode, lifecyclePhase.name());
return map(concat(appInfo, row.v2), value -> {
if (value == null)
return null;
if (value instanceof Optional) {
return ((Optional<?>) value).orElse(null);
} else {
return value;
}
});
}
use of org.finos.waltz.model.external_identifier.ExternalIdValue in project waltz by khartec.
the class AttestationExtractor method writeExcelBody.
private int writeExcelBody(Set<ApplicationAttestationInstanceSummary> reportRows, SXSSFSheet sheet) {
AtomicInteger rowNum = new AtomicInteger(1);
reportRows.forEach(r -> {
List<Object> values = asList(r.appRef().id(), r.appRef().name().get(), r.appAssetCode(), r.appCriticality(), r.appLifecyclePhase(), r.appKind(), r.attestedAt(), r.attestedBy());
org.apache.poi.ss.usermodel.Row row = sheet.createRow(rowNum.getAndIncrement());
AtomicInteger colNum = new AtomicInteger(0);
for (Object value : values) {
Object v = value instanceof Optional ? ((Optional<?>) value).orElse(null) : value;
int nextColNum = colNum.getAndIncrement();
if (v == null) {
row.createCell(nextColNum);
} else if (v instanceof Number) {
Cell cell = row.createCell(nextColNum, CellType.NUMERIC);
cell.setCellValue(((Number) v).doubleValue());
} else if (v instanceof ExternalIdValue) {
Cell cell = row.createCell(nextColNum, CellType.STRING);
cell.setCellValue(((ExternalIdValue) v).value());
} else {
Cell cell = row.createCell(nextColNum);
cell.setCellValue(Objects.toString(v));
}
}
});
return rowNum.get();
}
Aggregations