From 3efb8be533ae14b8eb144481c0c8440f9048d58f Mon Sep 17 00:00:00 2001 From: "miriam.baglioni" Date: Tue, 22 Nov 2022 16:42:13 +0100 Subject: [PATCH] [EOSC Dump] modifying schema and code for eosc if guidelines to accomodate elements with more than one correspondence --- .../eu/dnetlib/dhp/eosc/model/EoscResult.java | 6 +- .../dhp/oa/graph/dump/ResultMapper.java | 91 ++----------------- .../dhp/oa/graph/dump/DumpJobTest.java | 8 +- 3 files changed, 13 insertions(+), 92 deletions(-) diff --git a/dump-schema/src/main/java/eu/dnetlib/dhp/eosc/model/EoscResult.java b/dump-schema/src/main/java/eu/dnetlib/dhp/eosc/model/EoscResult.java index b7be494..caa98cc 100644 --- a/dump-schema/src/main/java/eu/dnetlib/dhp/eosc/model/EoscResult.java +++ b/dump-schema/src/main/java/eu/dnetlib/dhp/eosc/model/EoscResult.java @@ -15,7 +15,7 @@ import eu.dnetlib.dhp.oa.model.community.CommunityResult; public class EoscResult extends CommunityResult { @JsonSchema(description = "Describes a reference to the EOSC Interoperability Framework (IF) Guidelines") - private EoscInteroperabilityFramework eoscIF; + private List eoscIF; @JsonSchema(description = "The subject dumped by type associated to the result") private Map> subject; @@ -45,11 +45,11 @@ public class EoscResult extends CommunityResult { this.keywords = keywords; } - public EoscInteroperabilityFramework getEoscIF() { + public List getEoscIF() { return eoscIF; } - public void setEoscIF(EoscInteroperabilityFramework eoscIF) { + public void setEoscIF(List eoscIF) { this.eoscIF = eoscIF; } diff --git a/dump/src/main/java/eu/dnetlib/dhp/oa/graph/dump/ResultMapper.java b/dump/src/main/java/eu/dnetlib/dhp/oa/graph/dump/ResultMapper.java index 3a9786d..9ca571d 100644 --- a/dump/src/main/java/eu/dnetlib/dhp/oa/graph/dump/ResultMapper.java +++ b/dump/src/main/java/eu/dnetlib/dhp/oa/graph/dump/ResultMapper.java @@ -56,28 +56,6 @@ public class ResultMapper implements Serializable { addTypeSpecificInformation(out, input, ort); -// if (Optional.ofNullable(((eu.dnetlib.dhp.schema.oaf.Result) in).getMeasures()).isPresent()) { -// String downloads = ""; -// String views = ""; -// for (eu.dnetlib.dhp.schema.oaf.Measure m : ((eu.dnetlib.dhp.schema.oaf.Result) in) -// .getMeasures() -// .stream() -// .filter(m -> m.getId().equals("downloads") || m.getId().equals("views")) -// .collect(Collectors.toList())) { -// if (m.getId().equals("downloads")) { -// downloads = m.getUnit().get(0).getValue(); -// } -// if (m.getId().equals("views")) { -// views = m.getUnit().get(0).getValue(); -// } -// -// } -// if (downloads != "" && views != "") { -// ((EoscResult) out).setIndicator(Indicator.newInstance(downloads, views)); -// } -// -// } - Optional .ofNullable(input.getAuthor()) .ifPresent( @@ -269,77 +247,20 @@ public class ResultMapper implements Serializable { !s.getValue().equalsIgnoreCase("EOSC::RO-crate")) .map(s -> s.getValue()) .collect(Collectors.toList())); - long eoscSubjectNumber = input - .getSubject() - .stream() - .filter(s -> s.getValue().equalsIgnoreCase("EOSC::RO-crate")) - .count(); -// if (eoscSubjectNumber > 1) { -// throw new CardinalityTooHighException( -// "EOSC IF in the result has cardinality greater than one. Change dump!"); -// } + if (Optional.ofNullable(input.getEoscifguidelines()).isPresent()) { - List gei = input.getEoscifguidelines(); - if (gei.size() > 1) { - throw new CardinalityTooHighException( - "EOSC IF in the result has cardinality greater than one. Change dump!"); - } - if (gei.size() == 1) { - EoscIfGuidelines ifra = gei.get(0); - ((EoscResult) out) - .setEoscIF( - EoscInteroperabilityFramework - .newInstance( - ifra.getCode(), ifra.getLabel(), ifra.getUrl(), - ifra.getSemanticRelation())); - - } - } - if (eoscSubjectNumber > 0 && Optional.ofNullable(((EoscResult) out).getEoscIF()).isPresent()) { - throw new CardinalityTooHighException( - "EOSC IF in the result has cardinality greater than one. Change dump!"); - } else { - if (eoscSubjectNumber > 0) { - StructuredProperty ifra = input - .getSubject() + ((EoscResult) out) + .setEoscIF(input.getEoscifguidelines() .stream() - .filter(s -> s.getValue().equalsIgnoreCase("EOSC::RO-crate")) - .findFirst() - .get(); - ((EoscResult) out) - .setEoscIF( - EoscInteroperabilityFramework - .newInstance( - ifra.getValue(), ifra.getValue(), "", - "compliesWith")); - } - + .map(eig -> EoscInteroperabilityFramework.newInstance(eig.getCode(), eig.getLabel(), eig.getUrl(), eig.getSemanticRelation())) + .collect(Collectors.toList())); } + } } out.setType(input.getResulttype().getClassid()); -// if (Constants.DUMPTYPE.EOSC.getType().equals(dumpType)) { -// if (Optional.ofNullable(input.getEoscifguidelines()).isPresent()) { -// List gei = input.getEoscifguidelines(); -// if (gei.size() > 1) { -// throw new CardinalityTooHighException( -// "EOSC IF in the result has cardinality greater than one. Change dump!"); -// } -// if (gei.size() == 1) { -// -// EoscIfGuidelines ifra = gei.get(0); -// ((EoscResult) out) -// .setEoscIF( -// EoscInteroperabilityFramework -// .newInstance( -// ifra.getCode(), ifra.getLabel(), ifra.getUrl(), -// ifra.getSemanticRelation())); -// -// } -// } -// } if (!Constants.DUMPTYPE.COMPLETE.getType().equals(dumpType)) { if (!Constants.DUMPTYPE.EOSC.getType().equals(dumpType)) { ((CommunityResult) out) diff --git a/dump/src/test/java/eu/dnetlib/dhp/oa/graph/dump/DumpJobTest.java b/dump/src/test/java/eu/dnetlib/dhp/oa/graph/dump/DumpJobTest.java index f770a2d..77bf857 100644 --- a/dump/src/test/java/eu/dnetlib/dhp/oa/graph/dump/DumpJobTest.java +++ b/dump/src/test/java/eu/dnetlib/dhp/oa/graph/dump/DumpJobTest.java @@ -921,10 +921,10 @@ public class DumpJobTest { Assertions.assertEquals(1, verificationDataset.filter("type = 'dataset'").count()); - Assertions.assertEquals(1, tmp.filter(d -> d.getEoscIF().getCode().equals("EOSC::Twitter Data")).count()); - Assertions.assertEquals(1, tmp.filter(d -> d.getEoscIF().getLabel().equals("EOSC::Twitter Data")).count()); - Assertions.assertEquals(1, tmp.filter(d -> d.getEoscIF().getUrl().equals("")).count()); - Assertions.assertEquals(1, tmp.filter(d -> d.getEoscIF().getSemanticRelation().equals("compliesWith")).count()); + Assertions.assertEquals(1, tmp.filter(d -> d.getEoscIF().stream().anyMatch(c -> c.getCode().equals("EOSC::Twitter Data"))).count()); + Assertions.assertEquals(1, tmp.filter(d -> d.getEoscIF().stream().anyMatch(c -> c.getLabel().equals("EOSC::Twitter Data"))).count()); + Assertions.assertEquals(1, tmp.filter(d -> d.getEoscIF().stream().anyMatch(c -> c.getUrl().equals(""))).count()); + Assertions.assertEquals(1, tmp.filter(d -> d.getEoscIF().stream().anyMatch(c -> c.getSemanticRelation().equals("compliesWith"))).count()); System.out.println(OBJECT_MAPPER.writeValueAsString(verificationDataset.first()));