Search in sources :

Example 6 with EntityKind

use of org.finos.waltz.model.EntityKind in project waltz by khartec.

the class EntityCostExtractor method registerCostsForSelector.

private void registerCostsForSelector(String costsForSelectorPath) {
    post(costsForSelectorPath, (request, response) -> {
        IdSelectionOptions idSelectionOptions = WebUtilities.readIdSelectionOptionsFromBody(request);
        EntityKind targetKind = WebUtilities.getKind(request);
        GenericSelector genericSelector = genericSelectorFactory.applyForKind(targetKind, idSelectionOptions);
        SelectJoinStep<Record1<Integer>> latestYear = DSL.select(DSL.max(COST.YEAR)).from(COST);
        SelectSeekStep2<Record, String, Long> qry = dsl.select(COST.ENTITY_ID.as("Entity ID"), COST.ENTITY_KIND.as("Entity Kind")).select(ENTITY_NAME_FIELD.as("Name")).select(COST_KIND.NAME.as("Kind"), COST_KIND.DESCRIPTION.as("Kind Description")).select(COST.YEAR.as("Year"), COST.AMOUNT.as("Amount"), COST.PROVENANCE.as("Provenance")).from(COST).innerJoin(COST_KIND).on(COST.COST_KIND_ID.eq(COST_KIND.ID)).where(COST.ENTITY_ID.in(genericSelector.selector()).and(COST.ENTITY_KIND.eq(genericSelector.kind().name()))).and(COST.YEAR.eq(latestYear)).orderBy(ENTITY_NAME_FIELD.as("Name"), COST.COST_KIND_ID);
        return writeExtract(mkFilename(idSelectionOptions.entityReference()), qry, request, response);
    });
}
Also used : GenericSelector(org.finos.waltz.data.GenericSelector) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) EntityKind(org.finos.waltz.model.EntityKind)

Example 7 with EntityKind

use of org.finos.waltz.model.EntityKind in project waltz by khartec.

the class FlowLineageHarness method findIncomingByRefs.

private static void findIncomingByRefs(DSLContext dsl, Set<EntityReference> entityReferences) {
    Map<EntityKind, Collection<EntityReference>> refsByKind = groupBy(ref -> ref.kind(), entityReferences);
    Condition anyTargetMatches = refsByKind.entrySet().stream().map(entry -> LOGICAL_FLOW.TARGET_ENTITY_KIND.eq(entry.getKey().name()).and(LOGICAL_FLOW.TARGET_ENTITY_ID.in(map(entry.getValue(), ref -> ref.id())))).collect(Collectors.reducing(DSL.falseCondition(), (acc, c) -> acc.or(c)));
    System.out.println(anyTargetMatches);
    Field<String> SOURCE_NAME_FIELD = InlineSelectFieldFactory.mkNameField(LOGICAL_FLOW.SOURCE_ENTITY_ID, LOGICAL_FLOW.SOURCE_ENTITY_KIND, newArrayList(EntityKind.APPLICATION, EntityKind.ACTOR));
    dsl.select(LOGICAL_FLOW.fields()).select(SOURCE_NAME_FIELD).from(LOGICAL_FLOW).where(anyTargetMatches.and(LogicalFlowDao.LOGICAL_NOT_REMOVED)).forEach(System.out::println);
    dsl.select().from(LOGICAL_FLOW_DECORATOR).innerJoin(LOGICAL_FLOW).on(LOGICAL_FLOW.ID.eq(LOGICAL_FLOW_DECORATOR.LOGICAL_FLOW_ID)).where(anyTargetMatches).forEach(System.out::println);
}
Also used : Condition(org.jooq.Condition) ACTOR(org.finos.waltz.model.EntityKind.ACTOR) LOGICAL_FLOW_DECORATOR(org.finos.waltz.schema.tables.LogicalFlowDecorator.LOGICAL_FLOW_DECORATOR) LogicalFlowDao(org.finos.waltz.data.logical_flow.LogicalFlowDao) DSL(org.jooq.impl.DSL) EntityKind(org.finos.waltz.model.EntityKind) ParseException(org.jooq.tools.json.ParseException) Collection(java.util.Collection) Set(java.util.Set) DIConfiguration(org.finos.waltz.service.DIConfiguration) Field(org.jooq.Field) CollectionUtilities.map(org.finos.waltz.common.CollectionUtilities.map) ListUtilities.newArrayList(org.finos.waltz.common.ListUtilities.newArrayList) Collectors(java.util.stream.Collectors) Condition(org.jooq.Condition) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) LOGICAL_FLOW(org.finos.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW) InlineSelectFieldFactory(org.finos.waltz.data.InlineSelectFieldFactory) MapUtilities.groupBy(org.finos.waltz.common.MapUtilities.groupBy) Map(java.util.Map) SetUtilities(org.finos.waltz.common.SetUtilities) EntityReference(org.finos.waltz.model.EntityReference) DSLContext(org.jooq.DSLContext) APPLICATION(org.finos.waltz.model.EntityKind.APPLICATION) Collection(java.util.Collection) EntityKind(org.finos.waltz.model.EntityKind)

Example 8 with EntityKind

use of org.finos.waltz.model.EntityKind in project waltz by khartec.

the class AttestationInstanceEndpoint method register.

@Override
public void register() {
    String attestInstancePath = mkPath(BASE_URL, "attest", ":id");
    String attestEntityForUserPath = mkPath(BASE_URL, "attest-entity");
    String findByEntityRefPath = mkPath(BASE_URL, "entity", ":kind", ":id");
    String findByRunIdPath = mkPath(BASE_URL, "run", ":id");
    String findUnattestedByUserPath = mkPath(BASE_URL, "unattested", "user");
    String findAllByUserPath = mkPath(BASE_URL, "all", "user");
    String findHistoricalForPendingByUserPath = mkPath(BASE_URL, "historical", "user");
    String findPersonsByInstancePath = mkPath(BASE_URL, ":id", "person");
    String findBySelectorPath = mkPath(BASE_URL, "selector");
    String findLatestMeasurableAttestationsPath = mkPath(BASE_URL, "latest", "measurable-category", "entity", ":kind", ":id");
    String findApplicationAttestationInstancesForKindAndSelectorPath = mkPath(BASE_URL, "applications", "attested-entity", ":kind", ":id");
    String findApplicationAttestationSummaryForSelectorPath = mkPath(BASE_URL, "app-summary");
    String cleanupOrphansPath = mkPath(BASE_URL, "cleanup-orphans");
    String reassignRecipientsPath = mkPath(BASE_URL, "reassign-recipients");
    String getCountsOfRecipientsToReassignPath = mkPath(BASE_URL, "reassign-counts");
    DatumRoute<Boolean> attestInstanceRoute = (req, res) -> attestationInstanceService.attestInstance(getId(req), getUsername(req));
    ListRoute<AttestationInstance> findByEntityRefRoute = (req, res) -> attestationInstanceService.findByEntityReference(getEntityReference(req));
    ListRoute<AttestationInstance> findUnattestedByRecipientRoute = (req, res) -> attestationInstanceService.findByRecipient(getUsername(req), true);
    ListRoute<AttestationInstance> findAllByRecipientRoute = (req, res) -> attestationInstanceService.findByRecipient(getUsername(req), false);
    ListRoute<AttestationInstance> findHistoricalForPendingByRecipientRoute = (req, res) -> attestationInstanceService.findHistoricalForPendingByUserId(getUsername(req));
    ListRoute<AttestationInstance> findByRunIdRoute = (req, res) -> attestationInstanceService.findByRunId(getId(req));
    ListRoute<Person> findPersonsByInstanceRoute = (request, response) -> {
        long id = Long.valueOf(request.params("id"));
        return attestationInstanceService.findPersonsByInstanceId(id);
    };
    ListRoute<AttestationInstance> findBySelectorRoute = ((request, response) -> attestationInstanceService.findByIdSelector(readIdSelectionOptionsFromBody(request)));
    ListRoute<LatestMeasurableAttestationInfo> findLatestMeasurableAttestationsRoute = ((request, response) -> attestationInstanceService.findLatestMeasurableAttestations(getEntityReference(request)));
    ListRoute<ApplicationAttestationInstanceSummary> findApplicationAttestationInstancesForKindAndSelectorRoute = ((request, response) -> {
        EntityKind attestedKind = getKind(request);
        Long attestedId = StringUtilities.parseLong(request.params("id"), null);
        ApplicationAttestationInstanceInfo applicationAttestationInstanceInfo = readBody(request, ApplicationAttestationInstanceInfo.class);
        return attestationInstanceService.findApplicationAttestationInstancesForKindAndSelector(attestedKind, attestedId, applicationAttestationInstanceInfo);
    });
    ListRoute<ApplicationAttestationSummaryCounts> findApplicationAttestationSummaryForSelectorRoute = ((request, response) -> attestationInstanceService.findAttestationInstanceSummaryForSelector(readBody(request, ApplicationAttestationInstanceInfo.class)));
    DatumRoute<Boolean> attestEntityForUserRoute = (req, res) -> attestationInstanceService.attestForEntity(getUsername(req), readCreateCommand(req));
    postForDatum(attestInstancePath, attestInstanceRoute);
    postForDatum(attestEntityForUserPath, attestEntityForUserRoute);
    getForList(findByEntityRefPath, findByEntityRefRoute);
    getForList(findUnattestedByUserPath, findUnattestedByRecipientRoute);
    getForList(findAllByUserPath, findAllByRecipientRoute);
    getForList(findHistoricalForPendingByUserPath, findHistoricalForPendingByRecipientRoute);
    getForList(findByRunIdPath, findByRunIdRoute);
    getForList(findPersonsByInstancePath, findPersonsByInstanceRoute);
    getForList(findLatestMeasurableAttestationsPath, findLatestMeasurableAttestationsRoute);
    postForList(findBySelectorPath, findBySelectorRoute);
    postForList(findApplicationAttestationInstancesForKindAndSelectorPath, findApplicationAttestationInstancesForKindAndSelectorRoute);
    postForList(findApplicationAttestationSummaryForSelectorPath, findApplicationAttestationSummaryForSelectorRoute);
    getForDatum(cleanupOrphansPath, this::cleanupOrphansRoute);
    postForDatum(reassignRecipientsPath, this::reassignRecipientsRoute);
    getForDatum(getCountsOfRecipientsToReassignPath, this::getCountsOfRecipientsToReassign);
}
Also used : ListRoute(org.finos.waltz.web.ListRoute) Logger(org.slf4j.Logger) Endpoint(org.finos.waltz.web.endpoints.Endpoint) EntityKind(org.finos.waltz.model.EntityKind) DatumRoute(org.finos.waltz.web.DatumRoute) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) Person(org.finos.waltz.model.person.Person) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) UserRoleService(org.finos.waltz.service.user.UserRoleService) Service(org.springframework.stereotype.Service) Request(spark.Request) AttestationInstanceService(org.finos.waltz.service.attestation.AttestationInstanceService) WebUtilities(org.finos.waltz.web.WebUtilities) SystemRole(org.finos.waltz.model.user.SystemRole) Response(spark.Response) org.finos.waltz.model.attestation(org.finos.waltz.model.attestation) EndpointUtilities(org.finos.waltz.web.endpoints.EndpointUtilities) StringUtilities(org.finos.waltz.common.StringUtilities) Person(org.finos.waltz.model.person.Person) EntityKind(org.finos.waltz.model.EntityKind)

Example 9 with EntityKind

use of org.finos.waltz.model.EntityKind in project waltz by khartec.

the class ReportGridExtractor method prepareReportRows.

private List<Tuple2<Application, ArrayList<Object>>> prepareReportRows(Set<Tuple2<ReportGridColumnDefinition, Boolean>> colsWithCommentRequirement, ReportGridInstance reportGridInstance) {
    Set<ReportGridCell> tableData = reportGridInstance.cellData();
    Map<Long, Application> applicationsById = indexById(reportGridInstance.applications());
    Map<Long, RatingSchemeItem> ratingsById = indexById(reportGridInstance.ratingSchemeItems());
    Map<Long, Collection<ReportGridCell>> tableDataByAppId = groupBy(tableData, ReportGridCell::applicationId);
    boolean allowCostsExport = settingsService.getValue(SettingsService.ALLOW_COST_EXPORTS_KEY).map(r -> StringUtilities.isEmpty(r) || Boolean.parseBoolean(r)).orElse(true);
    return tableDataByAppId.entrySet().stream().map(r -> {
        Long appId = r.getKey();
        Application app = applicationsById.getOrDefault(appId, null);
        ArrayList<Object> reportRow = new ArrayList<>();
        Collection<ReportGridCell> cells = r.getValue();
        Map<Tuple3<Long, EntityKind, Long>, ReportGridCell> cellValuesByColumnRefForApp = indexBy(cells, k -> tuple(k.columnEntityId(), k.columnEntityKind(), k.entityFieldReferenceId()));
        // find data for columns
        colsWithCommentRequirement.forEach(t -> {
            ReportGridColumnDefinition colDef = t.v1;
            Boolean needsComment = t.v2;
            boolean isCostColumn = colDef.columnEntityKind().equals(EntityKind.COST_KIND);
            if (!allowCostsExport && isCostColumn) {
                reportRow.add("REDACTED");
            } else {
                ReportGridCell cell = cellValuesByColumnRefForApp.getOrDefault(tuple(colDef.columnEntityId(), colDef.columnEntityKind(), getIdOrDefault(colDef.entityFieldReference(), null)), null);
                reportRow.add(getValueFromReportCell(ratingsById, cell));
                if (needsComment) {
                    reportRow.add(getCommentFromCell(cell));
                }
            }
        });
        return tuple(app, reportRow);
    }).sorted(Comparator.comparing(t -> t.v1.name())).collect(toList());
}
Also used : CellType(org.apache.poi.ss.usermodel.CellType) LifecyclePhase(org.finos.waltz.model.application.LifecyclePhase) java.util(java.util) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IdUtilities.getIdOrDefault(org.finos.waltz.model.utils.IdUtilities.getIdOrDefault) EntityKind(org.finos.waltz.model.EntityKind) ReportGridService(org.finos.waltz.service.report_grid.ReportGridService) org.finos.waltz.model.report_grid(org.finos.waltz.model.report_grid) SurveyQuestionService(org.finos.waltz.service.survey.SurveyQuestionService) Autowired(org.springframework.beans.factory.annotation.Autowired) Spark.post(spark.Spark.post) CollectionUtilities(org.finos.waltz.common.CollectionUtilities) CsvPreference(org.supercsv.prefs.CsvPreference) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Tuple2(org.jooq.lambda.tuple.Tuple2) Tuple3(org.jooq.lambda.tuple.Tuple3) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Service(org.springframework.stereotype.Service) CsvListWriter(org.supercsv.io.CsvListWriter) Cell(org.apache.poi.ss.usermodel.Cell) SXSSFSheet(org.apache.poi.xssf.streaming.SXSSFSheet) IdUtilities.indexById(org.finos.waltz.model.utils.IdUtilities.indexById) Collectors.toSet(java.util.stream.Collectors.toSet) StringUtilities(org.finos.waltz.common.StringUtilities) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) SurveyQuestion(org.finos.waltz.model.survey.SurveyQuestion) MapUtilities(org.finos.waltz.common.MapUtilities) Application(org.finos.waltz.model.application.Application) StringWriter(java.io.StringWriter) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) NameProvider(org.finos.waltz.model.NameProvider) SettingsService(org.finos.waltz.service.settings.SettingsService) Collectors.toList(java.util.stream.Collectors.toList) ExternalIdValue(org.finos.waltz.model.external_identifier.ExternalIdValue) Stream(java.util.stream.Stream) CheckedConsumer.unchecked(org.jooq.lambda.fi.util.function.CheckedConsumer.unchecked) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) ListUtilities(org.finos.waltz.common.ListUtilities) WebUtilities(org.finos.waltz.web.WebUtilities) Row(org.apache.poi.ss.usermodel.Row) EntityReference(org.finos.waltz.model.EntityReference) IdUtilities(org.finos.waltz.model.utils.IdUtilities) EntityFieldReference(org.finos.waltz.model.entity_field_reference.EntityFieldReference) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) Tuple3(org.jooq.lambda.tuple.Tuple3) Application(org.finos.waltz.model.application.Application)

Example 10 with EntityKind

use of org.finos.waltz.model.EntityKind in project waltz by khartec.

the class ComplexityExtractor method register.

@Override
public void register() {
    String findBySelectorPath = WebUtilities.mkPath("data-extract", "complexity", "target-kind", ":kind", "selector");
    post(findBySelectorPath, (request, response) -> {
        IdSelectionOptions idSelectionOptions = WebUtilities.readIdSelectionOptionsFromBody(request);
        EntityKind targetKind = WebUtilities.getKind(request);
        GenericSelector genericSelector = genericSelectorFactory.applyForKind(targetKind, idSelectionOptions);
        SelectConditionStep<Record> qry = dsl.select(ENTITY_NAME_FIELD.as("Entity Name")).select(COMPLEXITY.ENTITY_ID).select(COMPLEXITY_KIND.NAME.as("Complexity Kind")).select(COMPLEXITY.SCORE.as("Score")).select(COMPLEXITY.PROVENANCE).from(COMPLEXITY).innerJoin(COMPLEXITY_KIND).on(COMPLEXITY.COMPLEXITY_KIND_ID.eq(COMPLEXITY_KIND.ID)).where(COMPLEXITY.ENTITY_ID.in(genericSelector.selector()).and(COMPLEXITY.ENTITY_KIND.eq(genericSelector.kind().name())));
        return writeExtract(mkFilename(idSelectionOptions), qry, request, response);
    });
}
Also used : GenericSelector(org.finos.waltz.data.GenericSelector) Record(org.jooq.Record) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) EntityKind(org.finos.waltz.model.EntityKind)

Aggregations

EntityKind (org.finos.waltz.model.EntityKind)15 EntityReference (org.finos.waltz.model.EntityReference)5 Autowired (org.springframework.beans.factory.annotation.Autowired)4 IOException (java.io.IOException)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)3 IdSelectionOptions (org.finos.waltz.model.IdSelectionOptions)3 String.format (java.lang.String.format)2 Collection (java.util.Collection)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors.toList (java.util.stream.Collectors.toList)2 Collectors.toSet (java.util.stream.Collectors.toSet)2 Stream (java.util.stream.Stream)2 ListUtilities (org.finos.waltz.common.ListUtilities)2 StringUtilities (org.finos.waltz.common.StringUtilities)2 WebUtilities (org.finos.waltz.web.WebUtilities)2 DSL (org.jooq.impl.DSL)2