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