[EOSC DUMP] added modification for the usage stats. To be used when the usagecounts will be inserted in the result
This commit is contained in:
parent
258a04f68a
commit
6366ed5890
|
@ -7,11 +7,14 @@ import java.util.stream.Collectors;
|
|||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.spark.api.java.function.FilterFunction;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import eu.dnetlib.dhp.eosc.model.EoscInteroperabilityFramework;
|
||||
import eu.dnetlib.dhp.eosc.model.EoscResult;
|
||||
import eu.dnetlib.dhp.eosc.model.Indicator;
|
||||
import eu.dnetlib.dhp.eosc.model.UsageCounts;
|
||||
import eu.dnetlib.dhp.oa.graph.dump.exceptions.CardinalityTooHighException;
|
||||
import eu.dnetlib.dhp.oa.graph.dump.exceptions.NoAvailableEntityTypeException;
|
||||
import eu.dnetlib.dhp.oa.model.*;
|
||||
|
@ -53,6 +56,28 @@ 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(
|
||||
|
@ -61,15 +86,15 @@ public class ResultMapper implements Serializable {
|
|||
// I do not map Access Right UNKNOWN or OTHER
|
||||
|
||||
Optional<eu.dnetlib.dhp.schema.oaf.Qualifier> oar = Optional.ofNullable(input.getBestaccessright());
|
||||
if (oar.isPresent() && Constants.accessRightsCoarMap.containsKey(oar.get().getClassid())) {
|
||||
String code = Constants.accessRightsCoarMap.get(oar.get().getClassid());
|
||||
if (oar.isPresent() && Constants.ACCESS_RIGHTS_COAR_MAP.containsKey(oar.get().getClassid())) {
|
||||
String code = Constants.ACCESS_RIGHTS_COAR_MAP.get(oar.get().getClassid());
|
||||
out
|
||||
.setBestaccessright(
|
||||
|
||||
BestAccessRight
|
||||
.newInstance(
|
||||
code,
|
||||
Constants.coarCodeLabelMap.get(code),
|
||||
Constants.COAR_CODE_LABEL_MAP.get(code),
|
||||
Constants.COAR_ACCESS_RIGHT_SCHEMA));
|
||||
}
|
||||
|
||||
|
@ -232,7 +257,6 @@ public class ResultMapper implements Serializable {
|
|||
|
||||
out.setSubjects(subjectList);
|
||||
} else {
|
||||
|
||||
if (Optional.ofNullable(input.getSubject()).isPresent()) {
|
||||
((EoscResult) out).setSubject(createSubjectMap(input));
|
||||
((EoscResult) out)
|
||||
|
@ -250,23 +274,45 @@ public class ResultMapper implements Serializable {
|
|||
.stream()
|
||||
.filter(s -> s.getValue().equalsIgnoreCase("EOSC::RO-crate"))
|
||||
.count();
|
||||
if (eoscSubjectNumber > 1) {
|
||||
// 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<EoscIfGuidelines> 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!");
|
||||
}
|
||||
if (eoscSubjectNumber == 1) {
|
||||
StructuredProperty ifra = input
|
||||
.getSubject()
|
||||
.stream()
|
||||
.filter(s -> s.getValue().equalsIgnoreCase("EOSC::RO-crate"))
|
||||
.findFirst()
|
||||
.get();
|
||||
((EoscResult) out)
|
||||
.setEoscIF(
|
||||
EoscInteroperabilityFramework
|
||||
.newInstance(
|
||||
ifra.getValue(), ifra.getValue(), "",
|
||||
"compliesWith"));
|
||||
} else {
|
||||
if (eoscSubjectNumber > 0) {
|
||||
StructuredProperty ifra = input
|
||||
.getSubject()
|
||||
.stream()
|
||||
.filter(s -> s.getValue().equalsIgnoreCase("EOSC::RO-crate"))
|
||||
.findFirst()
|
||||
.get();
|
||||
((EoscResult) out)
|
||||
.setEoscIF(
|
||||
EoscInteroperabilityFramework
|
||||
.newInstance(
|
||||
ifra.getValue(), ifra.getValue(), "",
|
||||
"compliesWith"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -274,26 +320,26 @@ public class ResultMapper implements Serializable {
|
|||
|
||||
out.setType(input.getResulttype().getClassid());
|
||||
|
||||
if (Constants.DUMPTYPE.EOSC.getType().equals(dumpType)) {
|
||||
if (Optional.ofNullable(input.getEoscifguidelines()).isPresent()) {
|
||||
List<EoscIfGuidelines> 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.EOSC.getType().equals(dumpType)) {
|
||||
// if (Optional.ofNullable(input.getEoscifguidelines()).isPresent()) {
|
||||
// List<EoscIfGuidelines> 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)
|
||||
|
@ -535,15 +581,15 @@ public class ResultMapper implements Serializable {
|
|||
private static <I extends Instance> void setCommonValue(eu.dnetlib.dhp.schema.oaf.Instance i, I instance) {
|
||||
Optional<eu.dnetlib.dhp.schema.oaf.AccessRight> opAr = Optional.ofNullable(i.getAccessright());
|
||||
|
||||
if (opAr.isPresent() && Constants.accessRightsCoarMap.containsKey(opAr.get().getClassid())) {
|
||||
String code = Constants.accessRightsCoarMap.get(opAr.get().getClassid());
|
||||
if (opAr.isPresent() && Constants.ACCESS_RIGHTS_COAR_MAP.containsKey(opAr.get().getClassid())) {
|
||||
String code = Constants.ACCESS_RIGHTS_COAR_MAP.get(opAr.get().getClassid());
|
||||
|
||||
instance
|
||||
.setAccessright(
|
||||
AccessRight
|
||||
.newInstance(
|
||||
code,
|
||||
Constants.coarCodeLabelMap.get(code),
|
||||
Constants.COAR_CODE_LABEL_MAP.get(code),
|
||||
Constants.COAR_ACCESS_RIGHT_SCHEMA));
|
||||
|
||||
Optional<List<eu.dnetlib.dhp.schema.oaf.Measure>> mes = Optional.ofNullable(i.getMeasures());
|
||||
|
|
Loading…
Reference in New Issue