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();
});
}
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());
}
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();
}
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!");
});
}
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);
}
Aggregations