Search in sources :

Example 1 with BOOKMARK

use of org.finos.waltz.schema.tables.Bookmark.BOOKMARK in project waltz by khartec.

the class BookmarkGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    List<EntityReference> appRefs = dsl.select(APPLICATION.NAME, APPLICATION.ID).from(APPLICATION).fetch(r -> EntityReference.mkRef(EntityKind.APPLICATION, r.value2(), r.value1()));
    List<EntityReference> measurableRefs = dsl.select(MEASURABLE.NAME, MEASURABLE.ID).from(MEASURABLE).fetch(r -> EntityReference.mkRef(EntityKind.MEASURABLE, r.value2(), r.value1()));
    List<EntityReference> ouRefs = dsl.select(ORGANISATIONAL_UNIT.NAME, ORGANISATIONAL_UNIT.ID).from(ORGANISATIONAL_UNIT).fetch(r -> EntityReference.mkRef(EntityKind.ORG_UNIT, r.value2(), r.value1()));
    List<EntityReference> appGroupRefs = dsl.select(APPLICATION_GROUP.NAME, APPLICATION_GROUP.ID).from(APPLICATION_GROUP).fetch(r -> EntityReference.mkRef(EntityKind.APP_GROUP, r.value2(), r.value1()));
    List<EntityReference> refs = ListUtilities.concat(appRefs, measurableRefs, ouRefs, appGroupRefs);
    List<BookmarkRecord> bookmarks = refs.stream().flatMap(r -> RandomUtilities.randomlySizedIntStream(2, 15).mapToObj(idx -> {
        BookmarkRecord record = dsl.newRecord(BOOKMARK);
        record.setParentKind(r.kind().name());
        record.setParentId(r.id());
        record.setTitle(mkText(r.name().get()));
        record.setDescription(mkText(r.name().get()));
        record.setKind(randomPick(bookmarkKinds));
        record.setUrl(mkUrl(r.name().get()));
        record.setProvenance(SAMPLE_DATA_PROVENANCE);
        record.setLastUpdatedBy("admin");
        record.setUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
        record.setCreatedAt(DateTimeUtilities.nowUtcTimestamp());
        return record;
    })).collect(Collectors.toList());
    dsl.batchStore(bookmarks).execute();
    return null;
}
Also used : APPLICATION(org.finos.waltz.schema.tables.Application.APPLICATION) EntityKind(org.finos.waltz.model.EntityKind) Random(java.util.Random) BookmarkRecord(org.finos.waltz.schema.tables.records.BookmarkRecord) BOOKMARK(org.finos.waltz.schema.tables.Bookmark.BOOKMARK) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) RandomUtilities(org.finos.waltz.common.RandomUtilities) List(java.util.List) ORGANISATIONAL_UNIT(org.finos.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) MEASURABLE(org.finos.waltz.schema.tables.Measurable.MEASURABLE) ListUtilities(org.finos.waltz.common.ListUtilities) Map(java.util.Map) RandomUtilities.randomPick(org.finos.waltz.common.RandomUtilities.randomPick) APPLICATION_GROUP(org.finos.waltz.schema.tables.ApplicationGroup.APPLICATION_GROUP) EntityReference(org.finos.waltz.model.EntityReference) DSLContext(org.jooq.DSLContext) EntityReference(org.finos.waltz.model.EntityReference) DSLContext(org.jooq.DSLContext) BookmarkRecord(org.finos.waltz.schema.tables.records.BookmarkRecord)

Example 2 with BOOKMARK

use of org.finos.waltz.schema.tables.Bookmark.BOOKMARK in project waltz by khartec.

the class SpdxLicenceImporter method importData.

private void importData(String path) throws IOException, URISyntaxException {
    List<SpdxLicence> spdxLicences = parseData(path);
    Timestamp now = DateTimeUtilities.nowUtcTimestamp();
    // fetching existing licences
    Set<String> existingExternalIds = licenceDao.findAll().stream().filter(l -> l.externalId() != null).map(l -> l.externalId().get().toLowerCase()).collect(Collectors.toSet());
    // add only new ones
    List<LicenceRecord> records = spdxLicences.stream().filter(l -> !existingExternalIds.contains(l.licenseId().toLowerCase())).map(l -> {
        LicenceRecord record = dsl.newRecord(LICENCE);
        record.setName(l.name());
        record.setExternalId(l.licenseId());
        record.setProvenance(PROVENANCE);
        record.setApprovalStatus(ApprovalStatus.PENDING_APPROVAL.name());
        record.setCreatedAt(now);
        record.setCreatedBy("admin");
        record.setLastUpdatedAt(now);
        record.setLastUpdatedBy("admin");
        return record;
    }).collect(toList());
    int[] execute = dsl.batchStore(records).execute();
    System.out.println("Licence records stored to database: " + execute.length);
    // now create bookmarks from seeAlso section
    deleteExistingBookmarks();
    Map<String, LicenceRecord> licencesByExternalId = dsl.selectFrom(LICENCE).where(LICENCE.EXTERNAL_ID.isNotNull()).fetch().stream().collect(Collectors.toMap(l -> l.getExternalId(), l -> l));
    List<BookmarkRecord> bookmarks = spdxLicences.stream().flatMap(l -> {
        Long licenceId = licencesByExternalId.get(l.licenseId()).getId();
        Stream<BookmarkRecord> stream = Stream.of(l.seeAlso()).map(url -> {
            BookmarkRecord bookmarkRecord = dsl.newRecord(BOOKMARK);
            bookmarkRecord.setTitle("See Also");
            bookmarkRecord.setKind("DOCUMENTATION");
            bookmarkRecord.setUrl(url);
            bookmarkRecord.setParentKind(EntityKind.LICENCE.name());
            bookmarkRecord.setParentId(licenceId);
            bookmarkRecord.setIsPrimary(false);
            bookmarkRecord.setProvenance(PROVENANCE);
            bookmarkRecord.setLastUpdatedBy("admin");
            bookmarkRecord.setCreatedAt(now);
            bookmarkRecord.setUpdatedAt(now);
            bookmarkRecord.setIsRequired(false);
            return bookmarkRecord;
        });
        BookmarkRecord spdxRecord = dsl.newRecord(BOOKMARK);
        spdxRecord.setTitle("SPDX");
        spdxRecord.setKind("DOCUMENTATION");
        spdxRecord.setUrl(String.format(SPDX_LICENCE_TEMPLATE_URL, l.licenseId()));
        spdxRecord.setParentKind(EntityKind.LICENCE.name());
        spdxRecord.setParentId(licenceId);
        spdxRecord.setIsPrimary(false);
        spdxRecord.setProvenance(PROVENANCE);
        spdxRecord.setLastUpdatedBy("admin");
        spdxRecord.setCreatedAt(now);
        spdxRecord.setUpdatedAt(now);
        spdxRecord.setIsRequired(false);
        return Stream.concat(stream, Stream.of(spdxRecord));
    }).collect(toList());
    int[] bookmarkStoreExecute = dsl.batchStore(bookmarks).execute();
    System.out.println("Bookmark records stored: " + bookmarkStoreExecute.length);
}
Also used : EntityKind(org.finos.waltz.model.EntityKind) URISyntaxException(java.net.URISyntaxException) DIConfiguration(org.finos.waltz.service.DIConfiguration) BookmarkRecord(org.finos.waltz.schema.tables.records.BookmarkRecord) BOOKMARK(org.finos.waltz.schema.tables.Bookmark.BOOKMARK) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) LICENCE(org.finos.waltz.schema.tables.Licence.LICENCE) LicenceDao(org.finos.waltz.data.licence.LicenceDao) Map(java.util.Map) DSLContext(org.jooq.DSLContext) URI(java.net.URI) Path(java.nio.file.Path) Files(java.nio.file.Files) Timestamp(java.sql.Timestamp) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) ApprovalStatus(org.finos.waltz.model.ApprovalStatus) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) Paths(java.nio.file.Paths) Optional(java.util.Optional) LicenceRecord(org.finos.waltz.schema.tables.records.LicenceRecord) LicenceRecord(org.finos.waltz.schema.tables.records.LicenceRecord) Timestamp(java.sql.Timestamp) Stream(java.util.stream.Stream) BookmarkRecord(org.finos.waltz.schema.tables.records.BookmarkRecord)

Aggregations

List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)2 EntityKind (org.finos.waltz.model.EntityKind)2 BOOKMARK (org.finos.waltz.schema.tables.Bookmark.BOOKMARK)2 BookmarkRecord (org.finos.waltz.schema.tables.records.BookmarkRecord)2 DSLContext (org.jooq.DSLContext)2 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Timestamp (java.sql.Timestamp)1 Optional (java.util.Optional)1 Random (java.util.Random)1 Set (java.util.Set)1