Project

General

Profile

« Previous | Next » 

Revision 49332

minor

View differences:

DMFResolverParser.java
6 6
import com.ximpleware.VTDNav;
7 7
import eu.dnetlib.data.transform.VtdUtilityParser;
8 8
import eu.dnetlib.data.transform.VtdUtilityParser.Node;
9
import eu.dnetlib.miscutils.collections.Pair;
9 10
import eu.dnetlib.pid.resolver.model.*;
11
import eu.dnetlib.pid.resolver.parser.AbstractResolverParser;
10 12
import eu.dnetlib.wds.resolver.WDSObjectRelation;
11 13
import eu.dnetlib.wds.resolver.WDSResolvedObject;
14
import eu.dnetlib.wds.utils.WDSUtils;
15
import org.apache.commons.lang3.StringUtils;
12 16
import org.apache.commons.logging.Log;
13 17
import org.apache.commons.logging.LogFactory;
14 18

  
15 19
import java.util.ArrayList;
16 20
import java.util.Arrays;
17 21
import java.util.List;
22
import java.util.stream.Collectors;
18 23

  
19 24
/**
20 25
 * Created by sandro on 9/13/16.
......
39 44
            final String datasourcePrefix = VtdUtilityParser.getSingleValue(ap, vn, "//dri:datasourceprefix");
40 45
            ap.declareXPathNameSpace("oaf", "http://namespace.dnet.eu/oaf");
41 46

  
42
            final String completionStatus = VtdUtilityParser.getSingleValue(ap, vn, "//oaf:completionStatus");
43
            final String provisionMode = VtdUtilityParser.getSingleValue(ap, vn, "//oaf:provisionMode");
47
            final ObjectProvenance provenance = new ObjectProvenance();
48
            provenance.setDatasourceId(WDSUtils.getIdFromDataSourcePrefix(datasourcePrefix));
49
            provenance.setDatasource(WDSUtils.getNameFromDataSourcePrefix(datasourcePrefix));
50
            parsedObject.setDatasourceProvenance(Arrays.asList(provenance));
44 51

  
45 52
            final String publisher = VtdUtilityParser.getSingleValue(ap, vn, "//*[local-name()='resource']/*[local-name()='publisher']");
46 53

  
54
            if (StringUtils.isNotEmpty(publisher))
55
                parsedObject.setPublisher(publisher);
56

  
47 57
            final List<Node> identifierType =
48 58
                    VtdUtilityParser.getTextValuesWithAttributes(ap, vn, "//*[local-name()='resource']/*[local-name()='identifier']", Lists.newArrayList("identifierType"));
49 59

  
50
            if (identifierType != null && identifierType.size() > 0) {
60
            if (extractIdentifier(parsedObject, identifierType)) return null;
51 61

  
52
                final Node result = identifierType.get(0);
53
                parsedObject.setPid(result.getTextValue());
54
                parsedObject.setPidType(result.getAttributes().get("identifierType"));
55
            } else {
56
                log.debug("Error on parsing record the identifier should not null ");
57
                return null;
58
            }
59

  
60 62
            final List<Node> relations =
61 63
                    VtdUtilityParser.getTextValuesWithAttributes(ap, vn, "//*[local-name()='resource']//*[local-name()='relatedIdentifier']", Arrays.asList("relatedIdentifierType", "relationType", "inverseRelationType"));
62 64

  
......
68 70
                    final String relatedIdentifierType = relationMap.getAttributes().get("relatedIdentifierType");
69 71
                    final String relatedPid = relationMap.getTextValue();
70 72
                    final WDSObjectRelation currentRelation = new WDSObjectRelation();
71
                    currentRelation.setTargetPID(new PID(relatedPid, relatedIdentifierType));
73
                    currentRelation.setTargetPID(inferPid(new PID(relatedPid, relatedIdentifierType)));
72 74
                    currentRelation.setRelationSemantics(relationType);
73 75
                    currentRelation.setInverseRelation(inverseRelationType);
74 76
                    relationsResult.add(currentRelation);
......
78 80

  
79 81
            final List<Node> subjects = VtdUtilityParser.getTextValuesWithAttributes(ap, vn, "//*[local-name()='resource']//*[local-name()='subject']", Arrays.asList("subjectScheme"));
80 82

  
81
            if (subjects != null && subjects.size() > 0) {
82
                final List<SubjectType> subjectResult = new ArrayList<>();
83
                subjects.forEach(subjectMap -> {
84
                    final SubjectType subject = new SubjectType(subjectMap.getAttributes().get("subjectScheme"), subjectMap.getTextValue());
85
                    subjectResult.add(subject);
86
                });
87
                parsedObject.setSubjects(subjectResult);
88
            }
83
            extractSubject(parsedObject, subjects);
89 84

  
90 85

  
91 86
            final List<String> creators = VtdUtilityParser.getTextValue(ap, vn, "//*[local-name()='resource']//*[local-name()='creator']/*[local-name()='creatorName']");
......
96 91
            if (titles != null && titles.size() > 0) {
97 92
                parsedObject.setTitles(titles);
98 93
            }
94
            final List<String> descriptions = VtdUtilityParser.getTextValue(ap, vn, "//*[local-name()='resource']//*[local-name()='description']");
95
            if (descriptions != null && descriptions.size() > 0) {
99 96

  
97

  
98
                parsedObject.setDescriptions(descriptions.stream().map(it -> new Pair<>("unknwonw", it)).collect(Collectors.toList()));
99
            }
100

  
100 101
            List<Node> resourceTypeGeneral = VtdUtilityParser.getTextValuesWithAttributes(ap, vn, "//*[local-name()='resource']/*[local-name()='resourceType']", Arrays.asList("resourceTypeGeneral"));
101 102

  
102 103

  

Also available in: Unified diff