Search in sources :

Example 6 with Measurable

use of org.finos.waltz.model.measurable.Measurable in project waltz by khartec.

the class ScenarioRatingImporter method addMissingColumns.

private void addMissingColumns(List<Measurable> measurables, List<ScenarioRatingRow> ratingRows, Roadmap roadmap, ScenarioAxisItemDao scenarioAxisItemDao, Map<String, ScenarioAxisItem> scenarioAxesByName, Scenario scenario) {
    List<String> columns = ratingRows.stream().map(r -> lower(r.column())).distinct().collect(toList());
    Map<String, Measurable> allColumnMeasurables = measurables.stream().filter(m -> m.categoryId() == roadmap.columnType().id()).collect(toMap(m -> lower(m.name()), m -> m, (m1, m2) -> m2.concrete() ? m2 : m1));
    for (String column : columns) {
        if (!scenarioAxesByName.containsKey(column)) {
            Measurable measurable = allColumnMeasurables.get(column);
            checkNotNull(measurable, String.format("measurable with name [%s] not found", column));
            scenarioAxisItemDao.add(scenario.id().get(), AxisOrientation.COLUMN, measurable.entityReference(), 0);
        }
    }
}
Also used : ICsvMapReader(org.supercsv.io.ICsvMapReader) ScenarioAxisItemDao(org.finos.waltz.data.scenario.ScenarioAxisItemDao) APPLICATION(org.finos.waltz.schema.tables.Application.APPLICATION) EntityKind(org.finos.waltz.model.EntityKind) RatingScheme(org.finos.waltz.model.rating.RatingScheme) DIConfiguration(org.finos.waltz.service.DIConfiguration) StringUtilities.lower(org.finos.waltz.common.StringUtilities.lower) CsvPreference(org.supercsv.prefs.CsvPreference) Scenario(org.finos.waltz.model.scenario.Scenario) ArrayList(java.util.ArrayList) Checks.checkTrue(org.finos.waltz.common.Checks.checkTrue) Measurable(org.finos.waltz.model.measurable.Measurable) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) SCENARIO_RATING_ITEM(org.finos.waltz.schema.tables.ScenarioRatingItem.SCENARIO_RATING_ITEM) Map(java.util.Map) DSLContext(org.jooq.DSLContext) Application(org.finos.waltz.model.application.Application) MeasurableDao(org.finos.waltz.data.measurable.MeasurableDao) ScenarioDao(org.finos.waltz.data.scenario.ScenarioDao) Collection(java.util.Collection) IOException(java.io.IOException) AxisOrientation(org.finos.waltz.model.AxisOrientation) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MapUtilities.indexBy(org.finos.waltz.common.MapUtilities.indexBy) ScenarioRatingItemRecord(org.finos.waltz.schema.tables.records.ScenarioRatingItemRecord) CsvMapReader(org.supercsv.io.CsvMapReader) ApplicationDao(org.finos.waltz.data.application.ApplicationDao) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) ExternalIdValue(org.finos.waltz.model.external_identifier.ExternalIdValue) ScenarioAxisItem(org.finos.waltz.model.scenario.ScenarioAxisItem) Tuple(org.jooq.lambda.tuple.Tuple) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) RatingSchemeDAO(org.finos.waltz.data.rating_scheme.RatingSchemeDAO) RoadmapDao(org.finos.waltz.data.roadmap.RoadmapDao) Roadmap(org.finos.waltz.model.roadmap.Roadmap) Measurable(org.finos.waltz.model.measurable.Measurable)

Example 7 with Measurable

use of org.finos.waltz.model.measurable.Measurable in project waltz by khartec.

the class TaxonomyManagementUtilities method validateMeasurableInCategory.

public static Measurable validateMeasurableInCategory(MeasurableService measurableService, long measurableId, long categoryId) {
    Measurable measurable = measurableService.getById(measurableId);
    checkNotNull(measurable, "Cannot find measurable [%d]", measurableId);
    checkTrue(categoryId == measurable.categoryId(), "Measurable [%s / %d] is not in category [%d], instead it is in category [%d]", measurable.name(), measurable.id(), categoryId, measurable.categoryId());
    return measurable;
}
Also used : Measurable(org.finos.waltz.model.measurable.Measurable)

Example 8 with Measurable

use of org.finos.waltz.model.measurable.Measurable in project waltz by khartec.

the class AddMeasurableCommandProcessor method preview.

public TaxonomyChangePreview preview(TaxonomyChangeCommand cmd) {
    doBasicValidation(cmd);
    Measurable m = validatePrimaryMeasurable(measurableService, cmd);
    return ImmutableTaxonomyChangePreview.builder().command(ImmutableTaxonomyChangeCommand.copyOf(cmd).withPrimaryReference(m.entityReference())).build();
}
Also used : Measurable(org.finos.waltz.model.measurable.Measurable) ImmutableMeasurable(org.finos.waltz.model.measurable.ImmutableMeasurable)

Example 9 with Measurable

use of org.finos.waltz.model.measurable.Measurable in project waltz by khartec.

the class AddMeasurableCommandProcessor method apply.

public TaxonomyChangeCommand apply(TaxonomyChangeCommand cmd, String userId) {
    doBasicValidation(cmd);
    validatePrimaryMeasurable(measurableService, cmd);
    Measurable primaryReference = measurableService.getById(cmd.primaryReference().id());
    Optional<Long> parentId = cmd.changeType() == TaxonomyChangeType.ADD_CHILD ? primaryReference.id() : primaryReference.parentId();
    Measurable newMeasurable = ImmutableMeasurable.builder().categoryId(cmd.changeDomain().id()).parentId(parentId).name(getNameParam(cmd)).description(mkSafe(getDescriptionParam(cmd))).externalId(Optional.ofNullable(getExternalIdParam(cmd))).concrete(getConcreteParam(cmd, true)).lastUpdatedBy(userId).lastUpdatedAt(DateTimeUtilities.nowUtc()).build();
    measurableService.create(newMeasurable, userId);
    return ImmutableTaxonomyChangeCommand.copyOf(cmd).withLastUpdatedAt(DateTimeUtilities.nowUtc()).withLastUpdatedBy(userId).withStatus(TaxonomyChangeLifecycleStatus.EXECUTED);
}
Also used : Measurable(org.finos.waltz.model.measurable.Measurable) ImmutableMeasurable(org.finos.waltz.model.measurable.ImmutableMeasurable)

Example 10 with Measurable

use of org.finos.waltz.model.measurable.Measurable in project waltz by khartec.

the class MoveMeasurableCommandProcessor method apply.

public TaxonomyChangeCommand apply(TaxonomyChangeCommand cmd, String userId) {
    Measurable measurableToMove = validate(cmd);
    TaxonomyChangeLifecycleStatus outcome = measurableToMove.id().map(id -> measurableService.updateParentId(id, getDestination(cmd), userId)).map(success -> success ? TaxonomyChangeLifecycleStatus.EXECUTED : TaxonomyChangeLifecycleStatus.FAILED).orElse(TaxonomyChangeLifecycleStatus.FAILED);
    return ImmutableTaxonomyChangeCommand.copyOf(cmd).withLastUpdatedAt(DateTimeUtilities.nowUtc()).withLastUpdatedBy(userId).withStatus(outcome);
}
Also used : Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) Measurable(org.finos.waltz.model.measurable.Measurable) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) org.finos.waltz.model.taxonomy_management(org.finos.waltz.model.taxonomy_management) Service(org.springframework.stereotype.Service) TaxonomyCommandProcessor(org.finos.waltz.service.taxonomy_management.TaxonomyCommandProcessor) EntityKind(org.finos.waltz.model.EntityKind) MeasurableService(org.finos.waltz.service.measurable.MeasurableService) SetUtilities(org.finos.waltz.common.SetUtilities) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) TaxonomyManagementUtilities.validateMeasurableInCategory(org.finos.waltz.service.taxonomy_management.TaxonomyManagementUtilities.validateMeasurableInCategory) Measurable(org.finos.waltz.model.measurable.Measurable)

Aggregations

Measurable (org.finos.waltz.model.measurable.Measurable)26 MeasurableDao (org.finos.waltz.data.measurable.MeasurableDao)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 EntityKind (org.finos.waltz.model.EntityKind)6 Collectors (java.util.stream.Collectors)5 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)5 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)5 DIConfiguration (org.finos.waltz.service.DIConfiguration)5 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 IOException (java.io.IOException)4 InputStreamReader (java.io.InputStreamReader)4 Collection (java.util.Collection)4 Map (java.util.Map)4 Checks.checkTrue (org.finos.waltz.common.Checks.checkTrue)4 MapUtilities.indexBy (org.finos.waltz.common.MapUtilities.indexBy)4 StringUtilities.lower (org.finos.waltz.common.StringUtilities.lower)4 ApplicationDao (org.finos.waltz.data.application.ApplicationDao)4 RatingSchemeDAO (org.finos.waltz.data.rating_scheme.RatingSchemeDAO)4 RoadmapDao (org.finos.waltz.data.roadmap.RoadmapDao)4