Search in sources :

Example 1 with MeasurableCategory

use of org.finos.waltz.model.measurable_category.MeasurableCategory in project waltz by khartec.

the class MeasurableHelper method createMeasurableCategory.

public long createMeasurableCategory(String name) {
    Set<MeasurableCategory> categories = categoryService.findByExternalId(name);
    return CollectionUtilities.maybeFirst(categories).map(c -> c.id().get()).orElseGet(() -> {
        long schemeId = ratingSchemeHelper.createEmptyRatingScheme("test");
        MeasurableCategoryRecord record = dsl.newRecord(MEASURABLE_CATEGORY);
        record.setDescription(name);
        record.setName(name);
        record.setExternalId(name);
        record.setRatingSchemeId(schemeId);
        record.setLastUpdatedBy("admin");
        record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
        record.setEditable(false);
        record.store();
        return record.getId();
    });
}
Also used : MeasurableCategory(org.finos.waltz.model.measurable_category.MeasurableCategory) MeasurableCategoryRecord(org.finos.waltz.schema.tables.records.MeasurableCategoryRecord) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) CollectionUtilities(org.finos.waltz.common.CollectionUtilities) MEASURABLE_CATEGORY(org.finos.waltz.schema.Tables.MEASURABLE_CATEGORY) MeasurableCategoryService(org.finos.waltz.service.measurable_category.MeasurableCategoryService) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) Service(org.springframework.stereotype.Service) MeasurableRecord(org.finos.waltz.schema.tables.records.MeasurableRecord) MeasurableService(org.finos.waltz.service.measurable.MeasurableService) DSLContext(org.jooq.DSLContext) MEASURABLE(org.finos.waltz.schema.Tables.MEASURABLE) MeasurableCategoryRecord(org.finos.waltz.schema.tables.records.MeasurableCategoryRecord) MeasurableCategory(org.finos.waltz.model.measurable_category.MeasurableCategory)

Example 2 with MeasurableCategory

use of org.finos.waltz.model.measurable_category.MeasurableCategory in project waltz by khartec.

the class AllocationHarness method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    AllocationSchemeService schemesService = ctx.getBean(AllocationSchemeService.class);
    MeasurableService measurableService = ctx.getBean(MeasurableService.class);
    MeasurableCategoryDao categoryDao = ctx.getBean(MeasurableCategoryDao.class);
    MeasurableRatingService ratingService = ctx.getBean(MeasurableRatingService.class);
    ApplicationService applicationService = ctx.getBean(ApplicationService.class);
    Tuple4<Application, MeasurableCategory, List<Measurable>, AllocationScheme> stuff = setup(dsl, schemesService, measurableService, categoryDao, applicationService);
    addRating(ratingService, stuff, 0);
    addRating(ratingService, stuff, 1);
    // addRating(ratingService, stuff, 2);
    // addAllocation(dsl, stuff, 0, 50);
    addAllocation(dsl, stuff, 1, 20);
    Long measurableCategory = stuff.v2.id().get();
    dumpRatings(dsl, stuff.v4);
    dumpAllocs(dsl, stuff.v4);
    doDiff(dsl, measurableCategory);
    System.out.println(ratingService.findByCategory(measurableCategory));
}
Also used : MeasurableRatingService(org.finos.waltz.service.measurable_rating.MeasurableRatingService) ImmutableAllocationScheme(org.finos.waltz.model.allocation_scheme.ImmutableAllocationScheme) AllocationScheme(org.finos.waltz.model.allocation_scheme.AllocationScheme) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MeasurableService(org.finos.waltz.service.measurable.MeasurableService) MeasurableCategoryDao(org.finos.waltz.data.measurable_category.MeasurableCategoryDao) AllocationSchemeService(org.finos.waltz.service.allocation_schemes.AllocationSchemeService) MeasurableCategory(org.finos.waltz.model.measurable_category.MeasurableCategory) List(java.util.List) ApplicationService(org.finos.waltz.service.application.ApplicationService)

Example 3 with MeasurableCategory

use of org.finos.waltz.model.measurable_category.MeasurableCategory in project waltz by khartec.

the class AllocationHarness method setup.

private static Tuple4<Application, MeasurableCategory, List<Measurable>, AllocationScheme> setup(DSLContext dsl, AllocationSchemeService schemesService, MeasurableService measurableService, MeasurableCategoryDao categoryDao, ApplicationService applicationService) {
    deleteAll(dsl);
    Application app = mkApp(dsl, applicationService);
    MeasurableCategory category = mkCategory(dsl, categoryDao);
    List<Measurable> measurables = mkMeasurables(measurableService, category);
    AllocationScheme scheme = mkScheme(schemesService, category);
    return Tuple.tuple(app, category, measurables, scheme);
}
Also used : Measurable(org.finos.waltz.model.measurable.Measurable) ImmutableMeasurable(org.finos.waltz.model.measurable.ImmutableMeasurable) ImmutableAllocationScheme(org.finos.waltz.model.allocation_scheme.ImmutableAllocationScheme) AllocationScheme(org.finos.waltz.model.allocation_scheme.AllocationScheme) MeasurableCategory(org.finos.waltz.model.measurable_category.MeasurableCategory)

Example 4 with MeasurableCategory

use of org.finos.waltz.model.measurable_category.MeasurableCategory in project waltz by khartec.

the class MeasurableRatingService method removeForCategory.

/**
 * Removes all ratings for the given entity where the associated
 * measurable belongs to the given category.
 * @param ref EntityReference of the entity linked to the measurables
 * @param categoryId  Measurable Category identifier
 * @param username who is doing the removal
 * @return The remaining mappings for the given entity
 */
public Collection<MeasurableRating> removeForCategory(EntityReference ref, long categoryId, String username) {
    checkNotNull(ref, "Cannot remove entity ratings for a category if the given entity reference is null");
    MeasurableCategory category = checkNotNull(measurableCategoryDao.getById(categoryId), "Cannot find category: %d", categoryId);
    int removedCount = measurableRatingDao.removeForCategory(ref, categoryId);
    changeLogService.write(ImmutableChangeLog.builder().message(format("Removed all (%d) ratings for category: %s which are not read-only", removedCount, category.name())).parentReference(ref).userId(username).createdAt(DateTimeUtilities.nowUtc()).severity(Severity.INFORMATION).childKind(EntityKind.MEASURABLE).operation(Operation.REMOVE).build());
    return findForEntity(ref);
}
Also used : MeasurableCategory(org.finos.waltz.model.measurable_category.MeasurableCategory)

Aggregations

MeasurableCategory (org.finos.waltz.model.measurable_category.MeasurableCategory)4 AllocationScheme (org.finos.waltz.model.allocation_scheme.AllocationScheme)2 ImmutableAllocationScheme (org.finos.waltz.model.allocation_scheme.ImmutableAllocationScheme)2 MeasurableService (org.finos.waltz.service.measurable.MeasurableService)2 List (java.util.List)1 Set (java.util.Set)1 CollectionUtilities (org.finos.waltz.common.CollectionUtilities)1 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)1 MeasurableCategoryDao (org.finos.waltz.data.measurable_category.MeasurableCategoryDao)1 ImmutableMeasurable (org.finos.waltz.model.measurable.ImmutableMeasurable)1 Measurable (org.finos.waltz.model.measurable.Measurable)1 MEASURABLE (org.finos.waltz.schema.Tables.MEASURABLE)1 MEASURABLE_CATEGORY (org.finos.waltz.schema.Tables.MEASURABLE_CATEGORY)1 MeasurableCategoryRecord (org.finos.waltz.schema.tables.records.MeasurableCategoryRecord)1 MeasurableRecord (org.finos.waltz.schema.tables.records.MeasurableRecord)1 AllocationSchemeService (org.finos.waltz.service.allocation_schemes.AllocationSchemeService)1 ApplicationService (org.finos.waltz.service.application.ApplicationService)1 MeasurableCategoryService (org.finos.waltz.service.measurable_category.MeasurableCategoryService)1 MeasurableRatingService (org.finos.waltz.service.measurable_rating.MeasurableRatingService)1 DSLContext (org.jooq.DSLContext)1