Search in sources :

Example 1 with EntityNamedNoteRecord

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

the class EntityNamedNoteDao method save.

public boolean save(EntityReference ref, long namedNoteTypeId, String noteText, UserTimestamp lastUpdate) {
    checkNotNull(ref, "ref cannot be null");
    checkNotNull(lastUpdate, "lastUpdate cannot be null");
    EntityNamedNoteRecord record = dsl.newRecord(ENTITY_NAMED_NOTE);
    record.setEntityId(ref.id());
    record.setEntityKind(ref.kind().name());
    record.setNoteText(noteText);
    record.setNamedNoteTypeId(namedNoteTypeId);
    record.setLastUpdatedAt(Timestamp.valueOf(lastUpdate.at()));
    record.setLastUpdatedBy(lastUpdate.by());
    record.setProvenance("waltz");
    if (dsl.executeUpdate(record) == 1) {
        return true;
    } else {
        return dsl.executeInsert(record) == 1;
    }
}
Also used : EntityNamedNoteRecord(org.finos.waltz.schema.tables.records.EntityNamedNoteRecord)

Example 2 with EntityNamedNoteRecord

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

the class FinosLicenceComplianceImporter method maybeMkConditionNamedNote.

private Optional<EntityNamedNoteRecord> maybeMkConditionNamedNote(List<ComplianceTerm> conditions, Licence licence, EntityNamedNoteTypeRecord typeRecord) {
    checkNotNull(typeRecord, "typeRecord cannot be null");
    if (licence == null || conditions == null || conditions.isEmpty()) {
        return Optional.empty();
    }
    EntityNamedNoteRecord record = dsl.newRecord(ENTITY_NAMED_NOTE);
    record.setEntityId(licence.id().get());
    record.setEntityKind(EntityKind.LICENCE.name());
    record.setNamedNoteTypeId(typeRecord.getId());
    record.setProvenance(PROVENANCE);
    record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
    record.setLastUpdatedBy("admin");
    StringBuilder noteText = new StringBuilder();
    noteText.append("| Description | Unmodified Binary | Modified Binary | Unmodified Source | Modified Source | Compliance Notes |").append("\n").append("| --- |:---:|:---:|:---:|:---:| --- |").append("\n");
    conditions.forEach(c -> {
        Set<ComplianceUseCase> complianceUseCases = SetUtilities.fromArray(c.useCases());
        noteText.append(" | ").append(c.description()).append(" | ").append(complianceUseCases.contains(ComplianceUseCase.UB) ? " X " : " ").append(" | ").append(complianceUseCases.contains(ComplianceUseCase.MB) ? " X " : " ").append(" | ").append(complianceUseCases.contains(ComplianceUseCase.US) ? " X " : " ").append(" | ").append(complianceUseCases.contains(ComplianceUseCase.MS) ? " X " : " ").append(" | ").append(c.complianceNotes()).append(" | ").append("\n");
    });
    record.setNoteText(noteText.toString());
    return Optional.of(record);
}
Also used : EntityNamedNoteRecord(org.finos.waltz.schema.tables.records.EntityNamedNoteRecord)

Example 3 with EntityNamedNoteRecord

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

the class FinosLicenceComplianceImporter method maybeMkBulletNamedNote.

private Optional<EntityNamedNoteRecord> maybeMkBulletNamedNote(List<ComplianceTerm> terms, Licence licence, EntityNamedNoteTypeRecord typeRecord) {
    checkNotNull(typeRecord, "typeRecord cannot be null");
    if (licence == null || terms == null || terms.isEmpty()) {
        return Optional.empty();
    }
    EntityNamedNoteRecord record = dsl.newRecord(ENTITY_NAMED_NOTE);
    record.setEntityId(licence.id().get());
    record.setEntityKind(EntityKind.LICENCE.name());
    record.setNamedNoteTypeId(typeRecord.getId());
    record.setProvenance(PROVENANCE);
    record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
    record.setLastUpdatedBy("admin");
    StringBuilder noteText = new StringBuilder();
    noteText.append("| Description |").append("\n").append("| --- |").append("\n");
    terms.forEach(c -> {
        noteText.append(" | ").append(c.description()).append(" | ").append("\n");
    });
    record.setNoteText(noteText.toString());
    return Optional.of(record);
}
Also used : EntityNamedNoteRecord(org.finos.waltz.schema.tables.records.EntityNamedNoteRecord)

Example 4 with EntityNamedNoteRecord

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

the class FinosLicenceComplianceImporter method maybeMkConditionNamedNote.

private Optional<EntityNamedNoteRecord> maybeMkConditionNamedNote(List<ComplianceTerm> conditions, Licence licence, EntityNamedNoteTypeRecord typeRecord) {
    checkNotNull(typeRecord, "typeRecord cannot be null");
    if (licence == null || conditions == null || conditions.isEmpty()) {
        return Optional.empty();
    }
    EntityNamedNoteRecord record = dsl.newRecord(ENTITY_NAMED_NOTE);
    record.setEntityId(licence.id().get());
    record.setEntityKind(EntityKind.LICENCE.name());
    record.setNamedNoteTypeId(typeRecord.getId());
    record.setProvenance(PROVENANCE);
    record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
    record.setLastUpdatedBy("admin");
    StringBuilder noteText = new StringBuilder();
    noteText.append("| Description | Unmodified Binary | Modified Binary | Unmodified Source | Modified Source | Compliance Notes |").append("\n").append("| --- |:---:|:---:|:---:|:---:| --- |").append("\n");
    conditions.forEach(c -> {
        Set<ComplianceUseCase> complianceUseCases = SetUtilities.fromArray(c.useCases());
        noteText.append(" | ").append(c.description()).append(" | ").append(complianceUseCases.contains(ComplianceUseCase.UB) ? " X " : " ").append(" | ").append(complianceUseCases.contains(ComplianceUseCase.MB) ? " X " : " ").append(" | ").append(complianceUseCases.contains(ComplianceUseCase.US) ? " X " : " ").append(" | ").append(complianceUseCases.contains(ComplianceUseCase.MS) ? " X " : " ").append(" | ").append(c.complianceNotes()).append(" | ").append("\n");
    });
    record.setNoteText(noteText.toString());
    return Optional.of(record);
}
Also used : EntityNamedNoteRecord(org.finos.waltz.schema.tables.records.EntityNamedNoteRecord)

Example 5 with EntityNamedNoteRecord

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

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

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