Search in sources :

Example 1 with MeasurableCategoryRecord

use of org.finos.waltz.schema.tables.records.MeasurableCategoryRecord 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 MeasurableCategoryRecord

use of org.finos.waltz.schema.tables.records.MeasurableCategoryRecord in project waltz by khartec.

the class GenericTaxonomyLoader method createCategory.

private Long createCategory(GenericTaxonomyLoadConfig config, DSLContext tx) {
    MeasurableCategoryRecord categoryRecord = tx.newRecord(MEASURABLE_CATEGORY);
    categoryRecord.setDescription(config.taxonomyDescription());
    categoryRecord.setName(config.taxonomyName());
    categoryRecord.setExternalId(config.taxonomyExternalId());
    categoryRecord.setRatingSchemeId(config.ratingSchemeId());
    categoryRecord.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
    categoryRecord.setEditable(true);
    categoryRecord.setLastUpdatedBy("admin");
    categoryRecord.insert();
    return categoryRecord.getId();
}
Also used : MeasurableCategoryRecord(org.finos.waltz.schema.tables.records.MeasurableCategoryRecord)

Example 3 with MeasurableCategoryRecord

use of org.finos.waltz.schema.tables.records.MeasurableCategoryRecord in project waltz by khartec.

the class WaltzUtilities method getOrCreateMeasurableCategory.

public static Long getOrCreateMeasurableCategory(DSLContext dsl, String externalId, String name) {
    Long categoryId = dsl.select(MEASURABLE_CATEGORY.ID).from(MEASURABLE_CATEGORY).where(MEASURABLE_CATEGORY.EXTERNAL_ID.eq(externalId)).fetchOne(MEASURABLE_CATEGORY.ID);
    if (categoryId != null) {
        return categoryId;
    } else {
        MeasurableCategoryRecord measurableCategoryRecord = dsl.newRecord(MEASURABLE_CATEGORY);
        measurableCategoryRecord.setName(name);
        measurableCategoryRecord.setDescription(name);
        measurableCategoryRecord.setExternalId(externalId);
        measurableCategoryRecord.setRatingSchemeId(1L);
        measurableCategoryRecord.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
        measurableCategoryRecord.setLastUpdatedBy("admin");
        measurableCategoryRecord.store();
        return measurableCategoryRecord.getId();
    }
}
Also used : MeasurableCategoryRecord(org.finos.waltz.schema.tables.records.MeasurableCategoryRecord)

Example 4 with MeasurableCategoryRecord

use of org.finos.waltz.schema.tables.records.MeasurableCategoryRecord in project waltz by khartec.

the class HigherEducationTaxonomyImport method getOrCreateCategoryId.

private long getOrCreateCategoryId(DSLContext tx) {
    log("Attempting to find category id using external id: %s", CATEGORY_EXTERNAL_ID);
    return tx.select(MEASURABLE_CATEGORY.ID).from(MEASURABLE_CATEGORY).where(MEASURABLE_CATEGORY.EXTERNAL_ID.eq(CATEGORY_EXTERNAL_ID)).fetchOptional(MEASURABLE_CATEGORY.ID).orElseGet(() -> {
        log("Could not find an existing category, therefore creating a new one");
        MeasurableCategoryRecord record = tx.newRecord(MEASURABLE_CATEGORY);
        record.setName("UK Higher Education Capabilities");
        record.setDescription("UK Higher Education Capabilities sourced from UCISA");
        record.setEditable(false);
        record.setLastUpdatedBy("admin");
        record.setRatingSchemeId(1L);
        record.setExternalId(CATEGORY_EXTERNAL_ID);
        log("Storing the new category and getting returning it's Waltz id");
        record.store();
        return record.getId();
    });
}
Also used : MeasurableCategoryRecord(org.finos.waltz.schema.tables.records.MeasurableCategoryRecord)

Aggregations

MeasurableCategoryRecord (org.finos.waltz.schema.tables.records.MeasurableCategoryRecord)4 Set (java.util.Set)1 CollectionUtilities (org.finos.waltz.common.CollectionUtilities)1 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)1 MeasurableCategory (org.finos.waltz.model.measurable_category.MeasurableCategory)1 MEASURABLE (org.finos.waltz.schema.Tables.MEASURABLE)1 MEASURABLE_CATEGORY (org.finos.waltz.schema.Tables.MEASURABLE_CATEGORY)1 MeasurableRecord (org.finos.waltz.schema.tables.records.MeasurableRecord)1 MeasurableService (org.finos.waltz.service.measurable.MeasurableService)1 MeasurableCategoryService (org.finos.waltz.service.measurable_category.MeasurableCategoryService)1 DSLContext (org.jooq.DSLContext)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Service (org.springframework.stereotype.Service)1