cleaning wf: bestaccessrights defaults to [UNKNOWN, not available] when the instance level access rights cannot be mapped to a value known in the dnet:access_modes vocabulary

This commit is contained in:
Claudio Atzori 2024-12-12 15:26:09 +01:00
parent 0b5f2ebd89
commit a1d795d3b7
2 changed files with 32 additions and 30 deletions

View File

@ -652,15 +652,11 @@ public class GraphCleaningFunctions extends CleaningFunctions {
if (Objects.isNull(r.getBestaccessright()) if (Objects.isNull(r.getBestaccessright())
|| StringUtils.isBlank(r.getBestaccessright().getClassid())) { || StringUtils.isBlank(r.getBestaccessright().getClassid())) {
Qualifier bestaccessrights = OafMapperUtils.createBestAccessRights(r.getInstance()); Qualifier bestaccessrights = OafMapperUtils.createBestAccessRights(r.getInstance());
if (Objects.isNull(bestaccessrights)) { if (!vocs.termExists(ModelConstants.DNET_ACCESS_MODES, bestaccessrights.getClassid())) {
r bestaccessrights.setClassid(UNKNOWN);
.setBestaccessright( bestaccessrights.setClassname(NOT_AVAILABLE);
qualifier(
ModelConstants.UNKNOWN, ModelConstants.NOT_AVAILABLE,
ModelConstants.DNET_ACCESS_MODES));
} else {
r.setBestaccessright(bestaccessrights);
} }
r.setBestaccessright(bestaccessrights);
} }
if (Objects.nonNull(r.getAuthor())) { if (Objects.nonNull(r.getAuthor())) {
r r

View File

@ -14,6 +14,7 @@ import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import eu.dnetlib.dhp.schema.common.AccessRightComparator; import eu.dnetlib.dhp.schema.common.AccessRightComparator;
import eu.dnetlib.dhp.schema.common.ModelConstants;
import eu.dnetlib.dhp.schema.oaf.*; import eu.dnetlib.dhp.schema.oaf.*;
public class OafMapperUtils { public class OafMapperUtils {
@ -365,31 +366,36 @@ public class OafMapperUtils {
} }
protected static Qualifier getBestAccessRights(final List<Instance> instanceList) { protected static Qualifier getBestAccessRights(final List<Instance> instanceList) {
if (instanceList != null) { return Optional
final Optional<AccessRight> min = instanceList .ofNullable(instanceList)
.stream() .map(list -> {
.map(Instance::getAccessright) Optional<AccessRight> min = list
.min(new AccessRightComparator<>()); .stream()
.map(Instance::getAccessright)
.min(new AccessRightComparator<>());
final Qualifier rights = min.map(OafMapperUtils::qualifier).orElseGet(Qualifier::new); final Qualifier rights = min.map(OafMapperUtils::qualifier).orElseGet(Qualifier::new);
if (StringUtils.isBlank(rights.getClassid())) { if (StringUtils.isBlank(rights.getClassid())) {
rights.setClassid(UNKNOWN); rights.setClassid(UNKNOWN);
} }
if (StringUtils.isBlank(rights.getClassname()) if (StringUtils.isBlank(rights.getClassname())
|| UNKNOWN.equalsIgnoreCase(rights.getClassname())) { || UNKNOWN.equalsIgnoreCase(rights.getClassname())) {
rights.setClassname(NOT_AVAILABLE); rights.setClassname(NOT_AVAILABLE);
} }
if (StringUtils.isBlank(rights.getSchemeid())) { if (StringUtils.isBlank(rights.getSchemeid())) {
rights.setSchemeid(DNET_ACCESS_MODES); rights.setSchemeid(DNET_ACCESS_MODES);
} }
if (StringUtils.isBlank(rights.getSchemename())) { if (StringUtils.isBlank(rights.getSchemename())) {
rights.setSchemename(DNET_ACCESS_MODES); rights.setSchemename(DNET_ACCESS_MODES);
} }
return rights; return rights;
} })
return null; .orElse(
qualifier(
ModelConstants.UNKNOWN, ModelConstants.NOT_AVAILABLE,
ModelConstants.DNET_ACCESS_MODES, DNET_ACCESS_MODES));
} }
public static KeyValue newKeyValueInstance(String key, String value, DataInfo dataInfo) { public static KeyValue newKeyValueInstance(String key, String value, DataInfo dataInfo) {