Skip to content

Commit 099b822

Browse files
committed
Intermediate checkin - working convert package
Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
1 parent 6e7093d commit 099b822

2 files changed

Lines changed: 86 additions & 58 deletions

File tree

src/main/java/org/spdx/library/conversion/Spdx2to3Converter.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ public Relationship convertAndStore(org.spdx.library.model.v2.Relationship fromR
447447
if (existing.isPresent()) {
448448
return (Relationship)existing.get();
449449
}
450-
String toObjectUri = defaultUriPrefix = toModelStore.getNextId(IdType.SpdxId);
450+
String toObjectUri = defaultUriPrefix + toModelStore.getNextId(IdType.SpdxId);
451451
String exitingUri = alreadyConverted.putIfAbsent(fromUri, toObjectUri);
452452
if (Objects.nonNull(exitingUri)) {
453453
return (Relationship)getExistingObject(fromUri,
@@ -503,7 +503,7 @@ public Annotation convertAndStore(org.spdx.library.model.v2.Annotation fromAnnot
503503
if (existing.isPresent()) {
504504
return (Annotation)existing.get();
505505
}
506-
String toObjectUri = defaultUriPrefix = toModelStore.getNextId(IdType.SpdxId);
506+
String toObjectUri = defaultUriPrefix + toModelStore.getNextId(IdType.SpdxId);
507507
String exitingUri = alreadyConverted.putIfAbsent(fromUri, toObjectUri);
508508
if (Objects.nonNull(exitingUri)) {
509509
return (Annotation)getExistingObject(fromUri, SpdxConstantsV3.CORE_ANNOTATION).get();
@@ -564,6 +564,9 @@ public SpdxDocument convertAndStore(org.spdx.library.model.v2.SpdxDocument fromD
564564
for (org.spdx.library.model.v2.ExternalDocumentRef externalDocRef:fromDoc.getExternalDocumentRefs()) {
565565
toDoc.getNamespaceMaps().add(convertAndStore(externalDocRef, toDoc.getImportss()));
566566
}
567+
for (org.spdx.library.model.v2.license.ExtractedLicenseInfo extractedLicense:fromDoc.getExtractedLicenseInfos()) {
568+
convertAndStore(extractedLicense);
569+
}
567570
return toDoc;
568571
}
569572

@@ -598,7 +601,7 @@ public NamespaceMap convertAndStore(org.spdx.library.model.v2.ExternalDocumentRe
598601
}
599602
NamespaceMap toNamespaceMap = (NamespaceMap)SpdxModelClassFactory.getModelObject(toModelStore,
600603
toObjectUri, SpdxConstantsV3.CORE_NAMESPACE_MAP, copyManager, true, defaultUriPrefix);
601-
toNamespaceMap.setIdPrefix(externalDocRef.getId());
604+
toNamespaceMap.setPrefix(externalDocRef.getId());
602605
toNamespaceMap.setNamespace(externalDocRef.getSpdxDocumentNamespace());
603606
return toNamespaceMap;
604607
}
@@ -974,15 +977,16 @@ public SpdxFile convertAndStore(org.spdx.library.model.v2.SpdxFile spdxFile) thr
974977
for (org.spdx.library.model.v2.enumerations.FileType fileType : spdxFile.getFileTypes()) {
975978
convertAndAddFileType(fileType, toFile);
976979
}
977-
toFile.setCopyrightText(spdxFile.getNoticeText().orElseGet(null));
978-
String sha1 = spdxFile.getSha1();
979-
if (Objects.nonNull(sha1)) {
980-
Hash hash = toFile.createHash(toModelStore.getNextId(IdType.Anonymous))
981-
.setAlgorithm(HashAlgorithm.SHA1)
982-
.setHashValue(sha1)
983-
.build();
984-
toFile.getVerifiedUsings().add(hash);
980+
Optional<String> noticeText = spdxFile.getNoticeText();
981+
if (noticeText.isPresent()) {
982+
Optional<String> existingCopyrightText = toFile.getCopyrightText();
983+
if (existingCopyrightText.isPresent()) {
984+
toFile.setCopyrightText(existingCopyrightText.get() + "; " + noticeText.get());
985+
} else {
986+
toFile.setCopyrightText(noticeText.get());
987+
}
985988
}
989+
// - this is already captured in the checksums - String sha1 = spdxFile.getSha1();
986990
return toFile;
987991
}
988992

0 commit comments

Comments
 (0)