avoid NPEs merging XMLInstance(s)

This commit is contained in:
Claudio Atzori 2021-12-13 13:27:20 +01:00
parent 5e17247bb6
commit 98eb292c59
1 changed files with 40 additions and 33 deletions

View File

@ -1,22 +1,24 @@
package eu.dnetlib.dhp.oa.provision.utils; package eu.dnetlib.dhp.oa.provision.utils;
import com.fasterxml.jackson.databind.ObjectMapper; import static eu.dnetlib.dhp.oa.provision.utils.GraphMappingUtils.authorPidTypes;
import com.google.common.base.Joiner; import static eu.dnetlib.dhp.oa.provision.utils.GraphMappingUtils.getRelDescriptor;
import com.google.common.base.Splitter; import static org.apache.commons.lang3.StringUtils.isNotBlank;
import com.google.common.collect.Lists; import static org.apache.commons.lang3.StringUtils.substringBefore;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import java.io.IOException;
import com.mycila.xmltool.XMLDoc; import java.io.Serializable;
import com.mycila.xmltool.XMLTag; import java.io.StringReader;
import eu.dnetlib.dhp.oa.provision.model.JoinedEntity; import java.io.StringWriter;
import eu.dnetlib.dhp.oa.provision.model.RelatedEntity; import java.net.URL;
import eu.dnetlib.dhp.oa.provision.model.RelatedEntityWrapper; import java.util.*;
import eu.dnetlib.dhp.oa.provision.model.XmlInstance; import java.util.stream.Collectors;
import eu.dnetlib.dhp.schema.common.*; import java.util.stream.Stream;
import eu.dnetlib.dhp.schema.oaf.Result;
import eu.dnetlib.dhp.schema.oaf.*; import javax.xml.transform.*;
import eu.dnetlib.dhp.schema.oaf.utils.IdentifierFactory; import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
@ -29,22 +31,23 @@ import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader; import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter; import org.dom4j.io.XMLWriter;
import javax.xml.transform.*; import com.fasterxml.jackson.databind.ObjectMapper;
import javax.xml.transform.dom.DOMSource; import com.google.common.base.Joiner;
import javax.xml.transform.stream.StreamResult; import com.google.common.base.Splitter;
import java.io.IOException; import com.google.common.collect.Lists;
import java.io.Serializable; import com.google.common.collect.Maps;
import java.io.StringReader; import com.google.common.collect.Sets;
import java.io.StringWriter; import com.mycila.xmltool.XMLDoc;
import java.net.URL; import com.mycila.xmltool.XMLTag;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static eu.dnetlib.dhp.oa.provision.utils.GraphMappingUtils.authorPidTypes; import eu.dnetlib.dhp.oa.provision.model.JoinedEntity;
import static eu.dnetlib.dhp.oa.provision.utils.GraphMappingUtils.getRelDescriptor; import eu.dnetlib.dhp.oa.provision.model.RelatedEntity;
import static org.apache.commons.lang3.StringUtils.isNotBlank; import eu.dnetlib.dhp.oa.provision.model.RelatedEntityWrapper;
import static org.apache.commons.lang3.StringUtils.substringBefore; import eu.dnetlib.dhp.oa.provision.model.XmlInstance;
import eu.dnetlib.dhp.schema.common.*;
import eu.dnetlib.dhp.schema.oaf.*;
import eu.dnetlib.dhp.schema.oaf.Result;
import eu.dnetlib.dhp.schema.oaf.utils.IdentifierFactory;
public class XmlRecordFactory implements Serializable { public class XmlRecordFactory implements Serializable {
@ -1314,8 +1317,6 @@ public class XmlRecordFactory implements Serializable {
instance.getCollectedfrom().add(i.getCollectedfrom()); instance.getCollectedfrom().add(i.getCollectedfrom());
instance.getHostedby().add(i.getHostedby()); instance.getHostedby().add(i.getHostedby());
instance.getInstancetype().add(i.getInstancetype()); instance.getInstancetype().add(i.getInstancetype());
instance.getPid().addAll(i.getPid());
instance.getAlternateIdentifier().addAll(i.getAlternateIdentifier());
instance.getRefereed().add(i.getRefereed()); instance.getRefereed().add(i.getRefereed());
instance instance
.setProcessingchargeamount( .setProcessingchargeamount(
@ -1323,6 +1324,12 @@ public class XmlRecordFactory implements Serializable {
instance instance
.setProcessingchargecurrency( .setProcessingchargecurrency(
Optional.ofNullable(i.getProcessingchargecurrency()).map(c -> c.getValue()).orElse(null)); Optional.ofNullable(i.getProcessingchargecurrency()).map(c -> c.getValue()).orElse(null));
Optional
.ofNullable(i.getPid())
.ifPresent(pid -> instance.getPid().addAll(pid));
Optional
.ofNullable(i.getAlternateIdentifier())
.ifPresent(altId -> instance.getAlternateIdentifier().addAll(altId));
Optional Optional
.ofNullable(i.getDateofacceptance()) .ofNullable(i.getDateofacceptance())
.ifPresent(d -> instance.getDateofacceptance().add(d.getValue())); .ifPresent(d -> instance.getDateofacceptance().add(d.getValue()));