Search in sources :

Example 1 with EntityNamedNoteTypeRecord

use of org.finos.waltz.schema.tables.records.EntityNamedNoteTypeRecord 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();
}
Also used : EntityNamedNoteTypeRecord(org.finos.waltz.schema.tables.records.EntityNamedNoteTypeRecord) EntityKind(org.finos.waltz.model.EntityKind)

Example 2 with EntityNamedNoteTypeRecord

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

the class FinosLicenceComplianceImporter method createEntityNoteDefinitionIfNotExists.

private EntityNamedNoteTypeRecord createEntityNoteDefinitionIfNotExists(String name, String description) {
    checkNotEmpty(name, "name must be provided");
    checkNotEmpty(description, "description must be provided");
    EntityNamedNoteTypeRecord existingRecord = dsl.selectFrom(ENTITY_NAMED_NOTE_TYPE).where(ENTITY_NAMED_NOTE_TYPE.NAME.eq(name)).fetchOne();
    if (existingRecord != null) {
        return existingRecord;
    }
    EntityNamedNoteTypeRecord record = dsl.newRecord(ENTITY_NAMED_NOTE_TYPE);
    record.setApplicableEntityKinds(EntityKind.LICENCE.name());
    record.setName(name);
    record.setDescription(description);
    record.setIsReadonly(true);
    record.insert();
    return record;
}
Also used : EntityNamedNoteTypeRecord(org.finos.waltz.schema.tables.records.EntityNamedNoteTypeRecord)

Example 3 with EntityNamedNoteTypeRecord

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

the class EntityNamedNoteTypeDao method update.

public boolean update(long id, EntityNamedNoteTypeChangeCommand command) {
    EntityNamedNoteTypeRecord record = new EntityNamedNoteTypeRecord();
    record.set(ENTITY_NAMED_NOTE_TYPE.ID, id);
    record.changed(ENTITY_NAMED_NOTE_TYPE.ID, false);
    command.name().ifPresent(record::setName);
    command.externalId().ifPresent(record::setExternalId);
    command.description().ifPresent(record::setDescription);
    command.applicableEntityKinds().ifPresent(kinds -> record.setApplicableEntityKinds(join(kinds, SEPARATOR)));
    command.isReadOnly().ifPresent(record::setIsReadonly);
    command.position().ifPresent(record::setPosition);
    return dsl.executeUpdate(record) == 1;
}
Also used : EntityNamedNoteTypeRecord(org.finos.waltz.schema.tables.records.EntityNamedNoteTypeRecord)

Example 4 with EntityNamedNoteTypeRecord

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

the class FinosLicenceComplianceImporter method importData.

private void importData(String path) throws IOException, URISyntaxException {
    EntityNamedNoteTypeRecord conditionsNoteType = createEntityNoteDefinitionIfNotExists(ENTITY_NOTE_CONDITIONS_NAME, ENTITY_NOTE_CONDITIONS_DESC);
    EntityNamedNoteTypeRecord terminationsNoteType = createEntityNoteDefinitionIfNotExists(ENTITY_NOTE_TERMINATIONS_NAME, ENTITY_NOTE_TERMINATIONS_DESC);
    EntityNamedNoteTypeRecord versioningNoteType = createEntityNoteDefinitionIfNotExists(ENTITY_NOTE_VERSIONING_NAME, ENTITY_NOTE_VERSIONING_DESC);
    EntityNamedNoteTypeRecord otherNoteType = createEntityNoteDefinitionIfNotExists(ENTITY_NOTE_OTHER_NAME, ENTITY_NOTE_OTHER_DESC);
    deleteExisting();
    List<LicenceCompliance> compliances = parseData(path);
    System.out.printf("Parsed %s licence compliance files \n", compliances.size());
    Map<String, Licence> licencesByExternalId = licenceDao.findAll().stream().filter(l -> l.externalId().isPresent()).collect(toMap(l -> l.externalId().get(), l -> l));
    List<EntityNamedNoteRecord> notes = compliances.stream().flatMap(c -> {
        return Stream.of(c.licenseId()).map(id -> Tuple.tuple(id, c));
    }).flatMap(t -> {
        Map<ComplianceType, List<ComplianceTerm>> termsByType = Arrays.stream(t.v2.terms()).collect(groupingBy(term -> term.type()));
        return Stream.of(maybeMkConditionNamedNote(termsByType.get(ComplianceType.CONDITION), licencesByExternalId.get(t.v1), conditionsNoteType), maybeMkBulletNamedNote(termsByType.get(ComplianceType.TERMINATION), licencesByExternalId.get(t.v1), terminationsNoteType), maybeMkBulletNamedNote(termsByType.get(ComplianceType.LICENSE_VERSIONS), licencesByExternalId.get(t.v1), versioningNoteType), maybeMkOtherNamedNote(termsByType.get(ComplianceType.OTHER), licencesByExternalId.get(t.v1), otherNoteType));
    }).filter(o -> o.isPresent()).map(o -> o.get()).collect(toList());
    int[] noteStoreExecute = dsl.batchStore(notes).execute();
    System.out.println("Entity Note records stored: " + noteStoreExecute.length);
}
Also used : java.util(java.util) EntityKind(org.finos.waltz.model.EntityKind) URISyntaxException(java.net.URISyntaxException) DIConfiguration(org.finos.waltz.service.DIConfiguration) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) MapperFeature(com.fasterxml.jackson.databind.MapperFeature) Licence(org.finos.waltz.model.licence.Licence) ENTITY_NAMED_NOTE_TYPE(org.finos.waltz.schema.tables.EntityNamedNoteType.ENTITY_NAMED_NOTE_TYPE) LicenceDao(org.finos.waltz.data.licence.LicenceDao) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) DSLContext(org.jooq.DSLContext) URI(java.net.URI) Path(java.nio.file.Path) Checks.checkNotEmpty(org.finos.waltz.common.Checks.checkNotEmpty) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) ENTITY_NAMED_NOTE(org.finos.waltz.schema.tables.EntityNamedNote.ENTITY_NAMED_NOTE) Collectors(java.util.stream.Collectors) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) Tuple(org.jooq.lambda.tuple.Tuple) Stream(java.util.stream.Stream) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) Paths(java.nio.file.Paths) EntityNamedNoteRecord(org.finos.waltz.schema.tables.records.EntityNamedNoteRecord) SetUtilities(org.finos.waltz.common.SetUtilities) EntityNamedNoteTypeRecord(org.finos.waltz.schema.tables.records.EntityNamedNoteTypeRecord) EntityNamedNoteRecord(org.finos.waltz.schema.tables.records.EntityNamedNoteRecord) Licence(org.finos.waltz.model.licence.Licence) EntityNamedNoteTypeRecord(org.finos.waltz.schema.tables.records.EntityNamedNoteTypeRecord)

Aggregations

EntityNamedNoteTypeRecord (org.finos.waltz.schema.tables.records.EntityNamedNoteTypeRecord)4 EntityKind (org.finos.waltz.model.EntityKind)2 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 MapperFeature (com.fasterxml.jackson.databind.MapperFeature)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Checks.checkNotEmpty (org.finos.waltz.common.Checks.checkNotEmpty)1 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)1 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)1 SetUtilities (org.finos.waltz.common.SetUtilities)1 LicenceDao (org.finos.waltz.data.licence.LicenceDao)1