handle missing instance.pid during bulk cleaning

This commit is contained in:
Claudio Atzori 2021-03-23 09:28:58 +01:00
parent c73072079d
commit 431cbe9955
2 changed files with 17 additions and 12 deletions

View File

@ -149,17 +149,21 @@ public class CleaningFunctions {
if (Objects.nonNull(r.getInstance())) { if (Objects.nonNull(r.getInstance())) {
for (Instance i : r.getInstance()) { for (Instance i : r.getInstance()) {
final Set<StructuredProperty> pids = Sets.newHashSet(i.getPid()); Optional
i .ofNullable(i.getPid())
.setAlternateIdentifier( .ifPresent(pid -> {
Optional final Set<StructuredProperty> pids = Sets.newHashSet(i.getPid());
.ofNullable(i.getAlternateIdentifier()) i
.map( .setAlternateIdentifier(
altId -> altId Optional
.stream() .ofNullable(i.getAlternateIdentifier())
.filter(p -> !pids.contains(p)) .map(
.collect(Collectors.toList())) altId -> altId
.orElse(Lists.newArrayList())); .stream()
.filter(p -> !pids.contains(p))
.collect(Collectors.toList()))
.orElse(Lists.newArrayList()));
});
if (Objects.isNull(i.getAccessright()) || StringUtils.isBlank(i.getAccessright().getClassid())) { if (Objects.isNull(i.getAccessright()) || StringUtils.isBlank(i.getAccessright().getClassid())) {
i i

View File

@ -19,6 +19,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.dhp.common.vocabulary.VocabularyGroup; import eu.dnetlib.dhp.common.vocabulary.VocabularyGroup;
import eu.dnetlib.dhp.schema.common.ModelConstants;
import eu.dnetlib.dhp.schema.oaf.*; import eu.dnetlib.dhp.schema.oaf.*;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
@ -78,7 +79,7 @@ public class CleaningFunctionTest {
assertEquals("CLOSED", p_out.getInstance().get(0).getAccessright().getClassid()); assertEquals("CLOSED", p_out.getInstance().get(0).getAccessright().getClassid());
assertEquals("Closed Access", p_out.getInstance().get(0).getAccessright().getClassname()); assertEquals("Closed Access", p_out.getInstance().get(0).getAccessright().getClassname());
Set<String> pidTerms = vocabularies.getTerms("dnet:pid_types"); Set<String> pidTerms = vocabularies.getTerms(ModelConstants.DNET_PID_TYPES);
assertTrue( assertTrue(
p_out p_out
.getPid() .getPid()