Search in sources :

Example 1 with LifecyclePhase

use of org.finos.waltz.model.application.LifecyclePhase in project waltz by khartec.

the class InvolvementImporter method main.

public static void main(String[] args) throws IOException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    ApplicationService applicationService = ctx.getBean(ApplicationService.class);
    PersonService personService = ctx.getBean(PersonService.class);
    Map<String, Application> appsByExtId = indexBy(a -> ExternalIdValue.orElse(a.assetCode(), null), applicationService.findAll());
    Map<String, Person> peopleByName = indexBy(p -> toSurnameFirstname(p.displayName()).toLowerCase(), personService.all());
    Siphon<String[]> incorrectSizeSiphon = mkSiphon(arr -> arr.length != 3);
    Siphon<Tuple2<String, ?>> unknownAppSiphon = mkSiphon(t -> !appsByExtId.containsKey(t.v1));
    Siphon<Tuple2<?, String>> unknownPersonSiphon = mkSiphon(t -> !peopleByName.containsKey(t.v2.toLowerCase()));
    Siphon<Tuple2<Application, ?>> retiredAppSiphon = mkSiphon(t -> t.v1.lifecyclePhase() == LifecyclePhase.RETIRED);
    List<Tuple2<Application, Person>> r = IOUtilities.streamLines(classLoader.getResourceAsStream(fileName)).map(line -> line.split("\t")).filter(d -> incorrectSizeSiphon.test(d)).map(arr -> Tuple.tuple(arr[1], arr[0])).filter(t -> unknownAppSiphon.test(t)).map(t -> t.map1(extId -> appsByExtId.get(extId))).filter(t -> retiredAppSiphon.test(t)).filter(t -> unknownPersonSiphon.test(t)).map(t -> t.map2(n -> peopleByName.get(n.toLowerCase()))).collect(Collectors.toList());
    Set<Application> distinctApps = r.stream().map(t -> t.v1).distinct().collect(Collectors.toSet());
    Set<Person> distinctPeople = r.stream().map(t -> t.v2).distinct().collect(Collectors.toSet());
    System.out.println("----");
    System.out.println("Wrong size count: " + incorrectSizeSiphon.getResults().size());
    System.out.println("Apps not found count: " + unknownAppSiphon.getResults().size());
    System.out.println("Retired app count: " + retiredAppSiphon.getResults().size());
    System.out.println("Person not found count: " + unknownPersonSiphon.getResults().size());
    System.out.println("----");
    System.out.println("Good record count: " + r.size());
    System.out.println("Distinct App count: " + distinctApps.size());
    System.out.println("Distinct People count: " + distinctPeople.size());
    Map<String, Long> unknownPersonCounts = countBy(Tuple2::v2, unknownPersonSiphon.getResults());
    DebugUtilities.dump(unknownPersonCounts);
}
Also used : LifecyclePhase(org.finos.waltz.model.application.LifecyclePhase) ApplicationService(org.finos.waltz.service.application.ApplicationService) Application(org.finos.waltz.model.application.Application) ArrayUtilities(org.finos.waltz.common.ArrayUtilities) Set(java.util.Set) StreamUtilities.mkSiphon(org.finos.waltz.common.StreamUtilities.mkSiphon) DIConfiguration(org.finos.waltz.service.DIConfiguration) IOException(java.io.IOException) PersonService(org.finos.waltz.service.person.PersonService) MapUtilities.countBy(org.finos.waltz.common.MapUtilities.countBy) Collectors(java.util.stream.Collectors) IOUtilities(org.finos.waltz.common.IOUtilities) Person(org.finos.waltz.model.person.Person) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MapUtilities.indexBy(org.finos.waltz.common.MapUtilities.indexBy) Tuple2(org.jooq.lambda.tuple.Tuple2) List(java.util.List) DebugUtilities(org.finos.waltz.common.DebugUtilities) ExternalIdValue(org.finos.waltz.model.external_identifier.ExternalIdValue) Tuple(org.jooq.lambda.tuple.Tuple) Map(java.util.Map) Siphon(org.finos.waltz.common.StreamUtilities.Siphon) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PersonService(org.finos.waltz.service.person.PersonService) Tuple2(org.jooq.lambda.tuple.Tuple2) Application(org.finos.waltz.model.application.Application) Person(org.finos.waltz.model.person.Person) ApplicationService(org.finos.waltz.service.application.ApplicationService)

Example 2 with LifecyclePhase

use of org.finos.waltz.model.application.LifecyclePhase 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();
}
Also used : LifecyclePhase(org.finos.waltz.model.application.LifecyclePhase) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Row(org.apache.poi.ss.usermodel.Row) ExternalIdValue(org.finos.waltz.model.external_identifier.ExternalIdValue) Cell(org.apache.poi.ss.usermodel.Cell)

Example 3 with LifecyclePhase

use of org.finos.waltz.model.application.LifecyclePhase 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;
        }
    });
}
Also used : ExternalIdValue(org.finos.waltz.model.external_identifier.ExternalIdValue) LifecyclePhase(org.finos.waltz.model.application.LifecyclePhase)

Example 4 with LifecyclePhase

use of org.finos.waltz.model.application.LifecyclePhase in project waltz by khartec.

the class AppGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    ApplicationService applicationDao = ctx.getBean(ApplicationService.class);
    OrganisationalUnitService ouDao = ctx.getBean(OrganisationalUnitService.class);
    List<String> animals = Unchecked.supplier(() -> readLines(getClass().getResourceAsStream("/app-names.txt"))).get();
    OrganisationalUnit[] organisationalUnits = ouDao.findAll().toArray(new OrganisationalUnit[0]);
    List<AppRegistrationRequest> registrationRequests = new ArrayList<>();
    for (int i = 0; i < NUM_APPS; i++) {
        String animal = randomPick(animals.toArray(new String[0])) + " - " + i;
        OrganisationalUnit organisationalUnit = randomPick(organisationalUnits);
        LifecyclePhase phase = rnd.nextInt(10) > 7 ? randomPick(LifecyclePhase.values()) : LifecyclePhase.PRODUCTION;
        Criticality businessCriticality = rnd.nextInt(10) > 7 ? randomPick(Criticality.values()) : Criticality.HIGH;
        AppRegistrationRequest app = ImmutableAppRegistrationRequest.builder().name(animal).assetCode("wltz-0" + i).description("All about " + animal).applicationKind(randomPick(ApplicationKind.values())).lifecyclePhase(phase).overallRating(randomPick(RagRating.R, RagRating.A, RagRating.A, RagRating.G, RagRating.G)).organisationalUnitId(organisationalUnit.id().get()).businessCriticality(businessCriticality).build();
        registrationRequests.add(app);
    }
    registrationRequests.forEach(a -> applicationDao.registerApp(a, "admin"));
    return null;
}
Also used : OrganisationalUnitService(org.finos.waltz.service.orgunit.OrganisationalUnitService) ArrayList(java.util.ArrayList) DSLContext(org.jooq.DSLContext) OrganisationalUnit(org.finos.waltz.model.orgunit.OrganisationalUnit) LifecyclePhase(org.finos.waltz.model.application.LifecyclePhase) ImmutableAppRegistrationRequest(org.finos.waltz.model.application.ImmutableAppRegistrationRequest) AppRegistrationRequest(org.finos.waltz.model.application.AppRegistrationRequest) ApplicationService(org.finos.waltz.service.application.ApplicationService) Criticality(org.finos.waltz.model.Criticality)

Aggregations

LifecyclePhase (org.finos.waltz.model.application.LifecyclePhase)4 ExternalIdValue (org.finos.waltz.model.external_identifier.ExternalIdValue)3 ApplicationService (org.finos.waltz.service.application.ApplicationService)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 Cell (org.apache.poi.ss.usermodel.Cell)1 Row (org.apache.poi.ss.usermodel.Row)1 ArrayUtilities (org.finos.waltz.common.ArrayUtilities)1 DebugUtilities (org.finos.waltz.common.DebugUtilities)1 IOUtilities (org.finos.waltz.common.IOUtilities)1 MapUtilities.countBy (org.finos.waltz.common.MapUtilities.countBy)1 MapUtilities.indexBy (org.finos.waltz.common.MapUtilities.indexBy)1 Siphon (org.finos.waltz.common.StreamUtilities.Siphon)1 StreamUtilities.mkSiphon (org.finos.waltz.common.StreamUtilities.mkSiphon)1 Criticality (org.finos.waltz.model.Criticality)1