use of org.finos.waltz.schema.tables.records.LicenceRecord 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