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;
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations