Search in sources :

Example 1 with Licence

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;
    }
}
Also used : Path(java.nio.file.Path) 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) Files(java.nio.file.Files) URI(java.net.URI)

Example 2 with Licence

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

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 Licence (org.finos.waltz.model.licence.Licence)2