Search in sources :

Example 1 with Measurable

use of com.khartec.waltz.model.measurable.Measurable in project waltz by khartec.

the class MeasurableHarness method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    MeasurableIdSelectorFactory factory = ctx.getBean(MeasurableIdSelectorFactory.class);
    MeasurableService measurableService = ctx.getBean(MeasurableService.class);
    EntityReference ref = mkRef(EntityKind.FLOW_DIAGRAM, 2);
    IdSelectionOptions options = mkOpts(ref, HierarchyQueryScope.EXACT);
    Select<Record1<Long>> selector = factory.apply(options);
    System.out.println("--selector");
    System.out.println(selector);
    System.out.println("---");
    List<Measurable> measurables = measurableService.findByMeasurableIdSelector(options);
    measurables.forEach(System.out::println);
    System.out.println("-----");
    measurables.stream().filter(m -> OptionalUtilities.contentsEqual(m.id(), 486L)).forEach(System.out::println);
    System.out.println("-----");
}
Also used : Measurable(com.khartec.waltz.model.measurable.Measurable) HierarchyQueryScope(com.khartec.waltz.model.HierarchyQueryScope) EntityReference(com.khartec.waltz.model.EntityReference) OptionalUtilities(com.khartec.waltz.common.OptionalUtilities) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EntityKind(com.khartec.waltz.model.EntityKind) MeasurableService(com.khartec.waltz.service.measurable.MeasurableService) List(java.util.List) IdSelectionOptions(com.khartec.waltz.model.IdSelectionOptions) DIConfiguration(com.khartec.waltz.service.DIConfiguration) Record1(org.jooq.Record1) MeasurableIdSelectorFactory(com.khartec.waltz.data.measurable.MeasurableIdSelectorFactory) IdSelectionOptions.mkOpts(com.khartec.waltz.model.IdSelectionOptions.mkOpts) Select(org.jooq.Select) EntityReference.mkRef(com.khartec.waltz.model.EntityReference.mkRef) Measurable(com.khartec.waltz.model.measurable.Measurable) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MeasurableIdSelectorFactory(com.khartec.waltz.data.measurable.MeasurableIdSelectorFactory) EntityReference(com.khartec.waltz.model.EntityReference) MeasurableService(com.khartec.waltz.service.measurable.MeasurableService) IdSelectionOptions(com.khartec.waltz.model.IdSelectionOptions) Record1(org.jooq.Record1)

Example 2 with Measurable

use of com.khartec.waltz.model.measurable.Measurable in project waltz by khartec.

the class MeasurableRatingService method remove.

public Collection<MeasurableRating> remove(RemoveMeasurableRatingCommand command) {
    checkNotNull(command, "command cannot be null");
    Measurable measurable = measurableDao.getById(command.measurableId());
    boolean success = measurableRatingDao.remove(command);
    perspectiveRatingDao.cascadeRemovalOfMeasurableRating(command.entityReference(), command.measurableId());
    if (success && measurable != null) {
        writeChangeLogEntry(command, format("Removed: %s", measurable.name()), Operation.REMOVE);
    }
    return findForEntity(command.entityReference());
}
Also used : Measurable(com.khartec.waltz.model.measurable.Measurable)

Example 3 with Measurable

use of com.khartec.waltz.model.measurable.Measurable in project waltz by khartec.

the class MeasurableRatingService method save.

// -- HELPERS --
private Collection<MeasurableRating> save(SaveMeasurableRatingCommand command, Function<SaveMeasurableRatingCommand, Boolean> action, String messageTemplate, Operation operation) {
    checkNotNull(command, "command cannot be null");
    Measurable measurable = measurableDao.getById(command.measurableId());
    checkNotNull(measurable, format("Unknown measurable with id: %d", command.measurableId()));
    checkTrue(measurable.concrete(), "Cannot rate against an abstract measurable");
    boolean success = action.apply(command);
    if (success) {
        writeChangeLogEntry(command, format(messageTemplate, measurable.name(), command.rating()), operation);
    }
    return findForEntity(command.entityReference());
}
Also used : Measurable(com.khartec.waltz.model.measurable.Measurable)

Example 4 with Measurable

use of com.khartec.waltz.model.measurable.Measurable in project waltz by khartec.

the class MeasurableRelationshipsGenerator method main.

public static void main(String[] args) throws IOException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    MeasurableDao measurableDao = ctx.getBean(MeasurableDao.class);
    List<Measurable> regions = loadMeasurablesForCategory(measurableDao, REGION_CATEGORY_EXTERNAL_ID);
    List<Measurable> functions = loadMeasurablesForCategory(measurableDao, FUNCTION_CATEGORY_EXTERNAL_ID);
    final int maxRelationshipCount = 50;
    final int minRelationshipCount = 5;
    final Random random = new Random();
    List<EntityRelationshipRecord> relationshipRecords = functions.stream().flatMap(function -> {
        int relationshipCount = random.nextInt(maxRelationshipCount - minRelationshipCount) + minRelationshipCount;
        return IntStream.range(0, relationshipCount).mapToObj(i -> ListUtilities.randomPick(regions)).distinct().map(region -> creatRelationshipRecord(function, region, ArrayUtilities.randomPick(RelationshipKind.RELATES_TO)));
    }).collect(toList());
    System.out.println("Deleting existing Measurable relationships ...");
    int deleteCount = dsl.deleteFrom(ENTITY_RELATIONSHIP).where(ENTITY_RELATIONSHIP.PROVENANCE.eq(PROVENANCE).and(ENTITY_RELATIONSHIP.KIND_A.eq(EntityKind.MEASURABLE.name())).and(ENTITY_RELATIONSHIP.KIND_B.eq(EntityKind.MEASURABLE.name()))).execute();
    System.out.println("Deleted: " + deleteCount + " existing Measurable relationships");
    System.out.println("Inserting Measurable relationships ...");
    int[] insertCount = dsl.batchInsert(relationshipRecords).execute();
    System.out.println("Inserted: " + insertCount.length + " Measurable relationships ...");
}
Also used : IntStream(java.util.stream.IntStream) Measurable(com.khartec.waltz.model.measurable.Measurable) DSL(org.jooq.impl.DSL) ListUtilities(com.khartec.waltz.common.ListUtilities) IOException(java.io.IOException) Random(java.util.Random) MEASURABLE(com.khartec.waltz.schema.tables.Measurable.MEASURABLE) ENTITY_RELATIONSHIP(com.khartec.waltz.schema.tables.EntityRelationship.ENTITY_RELATIONSHIP) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EntityKind(com.khartec.waltz.model.EntityKind) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) DIConfiguration(com.khartec.waltz.service.DIConfiguration) EntityRelationshipRecord(com.khartec.waltz.schema.tables.records.EntityRelationshipRecord) RelationshipKind(com.khartec.waltz.model.entity_relationship.RelationshipKind) MEASURABLE_CATEGORY(com.khartec.waltz.schema.tables.MeasurableCategory.MEASURABLE_CATEGORY) DSLContext(org.jooq.DSLContext) ArrayUtilities(com.khartec.waltz.common.ArrayUtilities) MeasurableDao(com.khartec.waltz.data.measurable.MeasurableDao) Measurable(com.khartec.waltz.model.measurable.Measurable) EntityRelationshipRecord(com.khartec.waltz.schema.tables.records.EntityRelationshipRecord) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Random(java.util.Random) MeasurableDao(com.khartec.waltz.data.measurable.MeasurableDao) DSLContext(org.jooq.DSLContext)

Example 5 with Measurable

use of com.khartec.waltz.model.measurable.Measurable in project waltz by khartec.

the class SqlServerMeasurableSearch method search.

@Override
public List<Measurable> search(DSLContext dsl, String query, EntitySearchOptions options) {
    List<String> terms = mkTerms(query);
    if (terms.isEmpty()) {
        return emptyList();
    }
    Condition externalIdCondition = terms.stream().map(term -> MEASURABLE.EXTERNAL_ID.like("%" + term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
    List<Measurable> measurablesViaExternalId = dsl.selectDistinct(MEASURABLE.fields()).from(MEASURABLE).where(externalIdCondition).orderBy(MEASURABLE.EXTERNAL_ID).limit(options.limit()).fetch(MeasurableDao.TO_DOMAIN_MAPPER);
    Condition nameCondition = terms.stream().map(term -> MEASURABLE.NAME.like("%" + term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
    List<Measurable> measurablesViaName = dsl.selectDistinct(MEASURABLE.fields()).from(MEASURABLE).where(nameCondition).orderBy(MEASURABLE.NAME).limit(options.limit()).fetch(MeasurableDao.TO_DOMAIN_MAPPER);
    List<Measurable> measurablesViaFullText = dsl.selectFrom(MEASURABLE).where(JooqUtilities.MSSQL.mkContainsPrefix(terms)).limit(options.limit()).fetch(MeasurableDao.TO_DOMAIN_MAPPER);
    return new ArrayList<>(orderedUnion(measurablesViaExternalId, measurablesViaName, measurablesViaFullText));
}
Also used : Condition(org.jooq.Condition) Measurable(com.khartec.waltz.model.measurable.Measurable) DSL(org.jooq.impl.DSL) Collections.emptyList(java.util.Collections.emptyList) MEASURABLE(com.khartec.waltz.schema.tables.Measurable.MEASURABLE) Collectors(java.util.stream.Collectors) Condition(org.jooq.Condition) ArrayList(java.util.ArrayList) List(java.util.List) DSLContext(org.jooq.DSLContext) EntitySearchOptions(com.khartec.waltz.model.entity_search.EntitySearchOptions) SearchUtilities.mkTerms(com.khartec.waltz.data.SearchUtilities.mkTerms) JooqUtilities(com.khartec.waltz.data.JooqUtilities) DatabaseVendorSpecific(com.khartec.waltz.data.DatabaseVendorSpecific) SetUtilities.orderedUnion(com.khartec.waltz.common.SetUtilities.orderedUnion) FullTextSearch(com.khartec.waltz.data.FullTextSearch) MeasurableDao(com.khartec.waltz.data.measurable.MeasurableDao) Measurable(com.khartec.waltz.model.measurable.Measurable) ArrayList(java.util.ArrayList)

Aggregations

Measurable (com.khartec.waltz.model.measurable.Measurable)5 List (java.util.List)3 MeasurableDao (com.khartec.waltz.data.measurable.MeasurableDao)2 EntityKind (com.khartec.waltz.model.EntityKind)2 MEASURABLE (com.khartec.waltz.schema.tables.Measurable.MEASURABLE)2 DIConfiguration (com.khartec.waltz.service.DIConfiguration)2 DSLContext (org.jooq.DSLContext)2 DSL (org.jooq.impl.DSL)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 ArrayUtilities (com.khartec.waltz.common.ArrayUtilities)1 ListUtilities (com.khartec.waltz.common.ListUtilities)1 OptionalUtilities (com.khartec.waltz.common.OptionalUtilities)1 SetUtilities.orderedUnion (com.khartec.waltz.common.SetUtilities.orderedUnion)1 DatabaseVendorSpecific (com.khartec.waltz.data.DatabaseVendorSpecific)1 FullTextSearch (com.khartec.waltz.data.FullTextSearch)1 JooqUtilities (com.khartec.waltz.data.JooqUtilities)1 SearchUtilities.mkTerms (com.khartec.waltz.data.SearchUtilities.mkTerms)1 MeasurableIdSelectorFactory (com.khartec.waltz.data.measurable.MeasurableIdSelectorFactory)1 EntityReference (com.khartec.waltz.model.EntityReference)1 EntityReference.mkRef (com.khartec.waltz.model.EntityReference.mkRef)1