Search in sources :

Example 1 with EntityKind

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

the class LogicalFlowDecoratorSummaryDao method summarizeForCondition.

private List<DecoratorRatingSummary> summarizeForCondition(Condition condition) {
    // this is intentionally TARGET only as we use to calculate auth source stats
    Condition dataFlowJoinCondition = LOGICAL_FLOW.ID.eq(LOGICAL_FLOW_DECORATOR.LOGICAL_FLOW_ID);
    Collection<Field<?>> groupingFields = newArrayList(LOGICAL_FLOW_DECORATOR.DECORATOR_ENTITY_KIND, LOGICAL_FLOW_DECORATOR.DECORATOR_ENTITY_ID, LOGICAL_FLOW_DECORATOR.RATING);
    Field<Integer> countField = DSL.count(LOGICAL_FLOW_DECORATOR.DECORATOR_ENTITY_ID).as("count");
    return dsl.select(groupingFields).select(countField).from(LOGICAL_FLOW_DECORATOR).innerJoin(LOGICAL_FLOW).on(dsl.renderInlined(dataFlowJoinCondition)).where(dsl.renderInlined(condition)).groupBy(groupingFields).fetch(r -> {
        EntityKind decoratorEntityKind = EntityKind.valueOf(r.getValue(LOGICAL_FLOW_DECORATOR.DECORATOR_ENTITY_KIND));
        long decoratorEntityId = r.getValue(LOGICAL_FLOW_DECORATOR.DECORATOR_ENTITY_ID);
        EntityReference decoratorRef = EntityReference.mkRef(decoratorEntityKind, decoratorEntityId);
        AuthoritativenessRatingValue rating = AuthoritativenessRatingValue.of(r.getValue(LOGICAL_FLOW_DECORATOR.RATING));
        Integer count = r.getValue(countField);
        return ImmutableDecoratorRatingSummary.builder().decoratorEntityReference(decoratorRef).rating(rating).count(count).build();
    });
}
Also used : AuthoritativenessRatingValue(org.finos.waltz.model.rating.AuthoritativenessRatingValue) EntityReference(org.finos.waltz.model.EntityReference) EntityKind(org.finos.waltz.model.EntityKind)

Example 2 with EntityKind

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

the class AssessmentsTest method createUpdateAndRemoveSingleRating.

@Test
public void createUpdateAndRemoveSingleRating() {
    String user = NameHelper.mkUserId("user");
    String name = NameHelper.mkName("testAssessment");
    String role = NameHelper.mkName("testRole");
    SchemeDetail schemeDetail = createScheme();
    AssessmentDefinition def = ImmutableAssessmentDefinition.builder().name(name).description("desc").isReadOnly(false).permittedRole(role).entityKind(EntityKind.APPLICATION).lastUpdatedBy(user).visibility(AssessmentVisibility.SECONDARY).ratingSchemeId(schemeDetail.id).build();
    long defId = definitionService.save(def);
    definitionService.save(ImmutableAssessmentDefinition.copyOf(def).withId(defId).withDescription("updated desc"));
    Collection<AssessmentDefinition> allDefs = definitionService.findAll();
    AssessmentDefinition found = find(d -> d.id().equals(Optional.of(defId)), allDefs).orElseThrow(AssertionError::new);
    assertEquals("updated desc", found.description());
    assertEquals(found, definitionService.getById(defId));
    EntityReference app1 = appHelper.createNewApp(NameHelper.mkName("app1"), ouIds.a);
    EntityReference app2 = appHelper.createNewApp(NameHelper.mkName("app2"), ouIds.b);
    SaveAssessmentRatingCommand cmd = ImmutableSaveAssessmentRatingCommand.builder().assessmentDefinitionId(defId).entityReference(app1).ratingId(schemeDetail.y).lastUpdatedBy(user).build();
    ratingService.store(cmd, user);
    changeLogHelper.assertChangeLogContainsAtLeastOneMatchingOperation(app1, Operation.ADD);
    assertNotNull(find(r -> r.assessmentDefinitionId() == defId && r.ratingId() == schemeDetail.y, ratingService.findForEntity(app1)));
    assertTrue(ratingService.findForEntity(app2).isEmpty());
    ratingService.store(ImmutableSaveAssessmentRatingCommand.copyOf(cmd).withRatingId(schemeDetail.n), user);
    changeLogHelper.assertChangeLogContainsAtLeastOneMatchingOperation(app1, Operation.UPDATE);
    assertNotNull(find(r -> r.assessmentDefinitionId() == defId && r.ratingId() == schemeDetail.n, ratingService.findForEntity(app1)));
    List<AssessmentRating> allRatingsAfterUpdate = ratingService.findByDefinitionId(defId);
    assertEquals(1, allRatingsAfterUpdate.size());
    assertTrue(find(r -> r.entityReference().equals(app1) && r.ratingId() == schemeDetail.n, allRatingsAfterUpdate).isPresent());
    ratingService.remove(ImmutableRemoveAssessmentRatingCommand.builder().assessmentDefinitionId(defId).entityReference(app1).lastUpdatedBy(user).build(), user);
    changeLogHelper.assertChangeLogContainsAtLeastOneMatchingOperation(app1, Operation.REMOVE);
    assertTrue(ratingService.findForEntity(app1).isEmpty());
    List<AssessmentRating> allRatingsAfterRemoval = ratingService.findByDefinitionId(defId);
    assertTrue(allRatingsAfterRemoval.isEmpty());
}
Also used : ImmutableSaveAssessmentRatingCommand(org.finos.waltz.model.assessment_rating.ImmutableSaveAssessmentRatingCommand) SaveAssessmentRatingCommand(org.finos.waltz.model.assessment_rating.SaveAssessmentRatingCommand) EntityKind(org.finos.waltz.model.EntityKind) AssessmentVisibility(org.finos.waltz.model.assessment_definition.AssessmentVisibility) AssessmentRating(org.finos.waltz.model.assessment_rating.AssessmentRating) Autowired(org.springframework.beans.factory.annotation.Autowired) ImmutableRemoveAssessmentRatingCommand(org.finos.waltz.model.assessment_rating.ImmutableRemoveAssessmentRatingCommand) RatingSchemeService(org.finos.waltz.service.rating_scheme.RatingSchemeService) ImmutableRatingSchemeItem(org.finos.waltz.model.rating.ImmutableRatingSchemeItem) AssessmentDefinition(org.finos.waltz.model.assessment_definition.AssessmentDefinition) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) ChangeLogHelper(org.finos.waltz.integration_test.inmem.helpers.ChangeLogHelper) Collection(java.util.Collection) AppHelper(org.finos.waltz.integration_test.inmem.helpers.AppHelper) NameHelper(org.finos.waltz.integration_test.inmem.helpers.NameHelper) RatingSchemeHelper(org.finos.waltz.integration_test.inmem.helpers.RatingSchemeHelper) AssessmentDefinitionService(org.finos.waltz.service.assessment_definition.AssessmentDefinitionService) Operation(org.finos.waltz.model.Operation) Test(org.junit.jupiter.api.Test) List(java.util.List) ImmutableAssessmentDefinition(org.finos.waltz.model.assessment_definition.ImmutableAssessmentDefinition) CollectionUtilities.find(org.finos.waltz.common.CollectionUtilities.find) Assertions(org.junit.jupiter.api.Assertions) EntityReference(org.finos.waltz.model.EntityReference) AssessmentRatingService(org.finos.waltz.service.assessment_rating.AssessmentRatingService) Optional(java.util.Optional) AssessmentDefinition(org.finos.waltz.model.assessment_definition.AssessmentDefinition) ImmutableAssessmentDefinition(org.finos.waltz.model.assessment_definition.ImmutableAssessmentDefinition) ImmutableSaveAssessmentRatingCommand(org.finos.waltz.model.assessment_rating.ImmutableSaveAssessmentRatingCommand) SaveAssessmentRatingCommand(org.finos.waltz.model.assessment_rating.SaveAssessmentRatingCommand) AssessmentRating(org.finos.waltz.model.assessment_rating.AssessmentRating) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with EntityKind

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

the class EntityNamedNoteTypeDao method create.

/**
 * Creates a new record and returns the generated id.  All fields in the command must be
 * provided.
 * @param command an EntityNameNoteTypeChangeCommand object
 * @return the id of the note type created.
 */
public long create(EntityNamedNoteTypeChangeCommand command) {
    String name = Checks.checkOptionalIsPresent(command.name(), "Name must be provided");
    Set<EntityKind> applicableEntityKinds = Checks.checkOptionalIsPresent(command.applicableEntityKinds(), "Applicable Entity Kinds must be provided");
    String kinds = join(applicableEntityKinds, SEPARATOR);
    EntityNamedNoteTypeRecord record = dsl.newRecord(ENTITY_NAMED_NOTE_TYPE);
    record.setName(name);
    record.setExternalId(command.externalId().orElse(""));
    record.setDescription(command.description().orElse(""));
    record.setApplicableEntityKinds(kinds);
    record.setIsReadonly(command.isReadOnly().orElse(false));
    record.setPosition(command.position().orElse(0));
    record.store();
    return record.getId();
}
Also used : EntityNamedNoteTypeRecord(org.finos.waltz.schema.tables.records.EntityNamedNoteTypeRecord) EntityKind(org.finos.waltz.model.EntityKind)

Example 4 with EntityKind

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

the class AssessmentRatingBulkImport method load.

public void load(String filename, AssessmentRatingBulkImportConfig config) throws IOException {
    InputStream inputStream = IOUtilities.getFileResource(filename).getInputStream();
    Workbook workbook = new XSSFWorkbook(inputStream);
    Sheet sheet = workbook.getSheetAt(config.sheetPosition());
    Set<AssessmentRatingEntry> existingRatings = dsl.select(ASSESSMENT_RATING.ENTITY_ID, ASSESSMENT_RATING.ENTITY_KIND, ASSESSMENT_RATING.RATING_ID, ASSESSMENT_RATING.DESCRIPTION).from(ASSESSMENT_RATING).where(ASSESSMENT_RATING.ASSESSMENT_DEFINITION_ID.eq(config.assessmentDefinitionId())).fetchSet(r -> ImmutableAssessmentRatingEntry.builder().entity(readRef(r, ASSESSMENT_RATING.ENTITY_KIND, ASSESSMENT_RATING.ENTITY_ID)).ratingId(r.get(ASSESSMENT_RATING.RATING_ID)).description(r.get(ASSESSMENT_RATING.DESCRIPTION)).build());
    EntityKind subjectKind = EntityKind.valueOf(dsl.select(ASSESSMENT_DEFINITION.ENTITY_KIND).from(ASSESSMENT_DEFINITION).where(ASSESSMENT_DEFINITION.ID.eq(config.assessmentDefinitionId())).fetchOne(ASSESSMENT_DEFINITION.ENTITY_KIND));
    Aliases<Long> ratingAliases = mkRatingAliases(config);
    Map<String, Long> externalIdToEntityIdMap = loadExternalIdToEntityIdMap(subjectKind);
    StreamUtilities.Siphon<Tuple5<String, String, String, Long, Optional<Long>>> noEntityFoundSiphon = mkSiphon(t -> t.v4 == null);
    StreamUtilities.Siphon<Tuple5<String, String, String, Long, Optional<Long>>> noRatingFoundSiphon = mkSiphon(t -> !t.v5.isPresent());
    Set<AssessmentRatingEntry> requiredRatings = streamRows(sheet).skip(config.numberOfHeaderRows()).map(r -> tuple(strVal(r, Columns.A), strVal(r, Columns.B), strVal(r, Columns.C))).map(t -> t.concat(tuple(externalIdToEntityIdMap.get(t.v1), ratingAliases.lookup(t.v2)))).filter(noEntityFoundSiphon).filter(noRatingFoundSiphon).map(t -> ImmutableAssessmentRatingEntry.builder().entity(mkRef(subjectKind, t.v4)).ratingId(t.v5.get()).description(t.v3).build()).collect(toSet());
    noEntityFoundSiphon.getResults().forEach(t -> System.out.printf("Couldn't find an entity id for row: %s%n", t.limit3()));
    noRatingFoundSiphon.getResults().forEach(t -> System.out.printf("Couldn't find a rating id for row: %s%n", t.limit3()));
    DiffResult<AssessmentRatingEntry> diff = DiffResult.mkDiff(existingRatings, requiredRatings, AssessmentRatingEntry::entity, Object::equals);
    dsl.transaction(ctx -> {
        DSLContext tx = ctx.dsl();
        int[] insertedRecords = diff.otherOnly().stream().map(r -> mkAssessmentRatingRecord(config.assessmentDefinitionId(), r, config.updateUser())).collect(Collectors.collectingAndThen(toSet(), tx::batchInsert)).execute();
        LOG.debug(format("inserted new assessment ratings for %d records", IntStream.of(insertedRecords).sum()));
        int[] updatedRecords = diff.differingIntersection().stream().map(r -> dsl.update(ASSESSMENT_RATING).set(ASSESSMENT_RATING.DESCRIPTION, r.description()).set(ASSESSMENT_RATING.RATING_ID, r.ratingId()).set(ASSESSMENT_RATING.LAST_UPDATED_AT, DateTimeUtilities.nowUtcTimestamp()).set(ASSESSMENT_RATING.LAST_UPDATED_BY, config.updateUser()).where(ASSESSMENT_RATING.ASSESSMENT_DEFINITION_ID.eq(config.assessmentDefinitionId()).and(ASSESSMENT_RATING.ENTITY_KIND.eq(r.entity().kind().name()).and(ASSESSMENT_RATING.ENTITY_ID.eq(r.entity().id()))))).collect(Collectors.collectingAndThen(toSet(), tx::batch)).execute();
        LOG.debug(format("Updated ratings or descriptions for %d records", IntStream.of(updatedRecords).sum()));
        if (config.mode().equals(SynchronisationMode.FULL)) {
            int[] removedRecords = diff.waltzOnly().stream().map(r -> dsl.deleteFrom(ASSESSMENT_RATING).where(ASSESSMENT_RATING.ASSESSMENT_DEFINITION_ID.eq(config.assessmentDefinitionId()).and(ASSESSMENT_RATING.ENTITY_ID.eq(r.entity().id()).and(ASSESSMENT_RATING.ENTITY_KIND.eq(r.entity().kind().name()))))).collect(Collectors.collectingAndThen(toSet(), tx::batch)).execute();
            LOG.debug(format("Deleted assessment ratings for %d records", IntStream.of(removedRecords).sum()));
        }
    // throw new  IllegalArgumentException("BBooooooOOOOOooMMMMMMMM!");
    });
}
Also used : IntStream(java.util.stream.IntStream) XlsUtilities.strVal(org.finos.waltz.jobs.XlsUtilities.strVal) Tables(org.finos.waltz.schema.Tables) EntityKind(org.finos.waltz.model.EntityKind) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StreamUtilities.mkSiphon(org.finos.waltz.common.StreamUtilities.mkSiphon) DIConfiguration(org.finos.waltz.service.DIConfiguration) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Tuple5(org.jooq.lambda.tuple.Tuple5) XlsUtilities.streamRows(org.finos.waltz.jobs.XlsUtilities.streamRows) Map(java.util.Map) DSLContext(org.jooq.DSLContext) JooqUtilities.readRef(org.finos.waltz.data.JooqUtilities.readRef) org.finos.waltz.common(org.finos.waltz.common) Collectors.toSet(java.util.stream.Collectors.toSet) Sheet(org.apache.poi.ss.usermodel.Sheet) Logger(org.slf4j.Logger) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) String.format(java.lang.String.format) Workbook(org.apache.poi.ss.usermodel.Workbook) Component(org.springframework.stereotype.Component) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) Optional(java.util.Optional) AssessmentRatingRecord(org.finos.waltz.schema.tables.records.AssessmentRatingRecord) InputStream(java.io.InputStream) InputStream(java.io.InputStream) DSLContext(org.jooq.DSLContext) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Tuple5(org.jooq.lambda.tuple.Tuple5) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Sheet(org.apache.poi.ss.usermodel.Sheet) EntityKind(org.finos.waltz.model.EntityKind)

Example 5 with EntityKind

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

the class MeasurableRelationshipEndpoint method getReference.

private EntityReference getReference(String qualifier, Request request) {
    EntityKind kind = readEnum(request, "kind" + qualifier, EntityKind.class, s -> null);
    long id = getLong(request, "id" + qualifier);
    return mkRef(kind, id);
}
Also used : 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