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