use of org.finos.waltz.model.licence.Licence in project waltz by khartec.
the class FinosLicenceComplianceImporter method parseData.
private List<LicenceCompliance> parseData(String directoryPath) throws IOException, URISyntaxException {
URI directoryUrl = this.getClass().getClassLoader().getResource(directoryPath).toURI();
try (Stream<Path> paths = Files.walk(Paths.get(directoryUrl))) {
List<LicenceCompliance> compliances = paths.filter(Files::isRegularFile).map(this::parseCompliance).filter(l -> l.isPresent()).map(l -> l.get()).collect(toList());
System.out.printf("Parsed %s FINOS licence files \n", compliances.size());
return compliances;
}
}
use of org.finos.waltz.model.licence.Licence 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