Project

General

Profile

« Previous | Next » 

Revision 54958

Parsing Orcid records: fix parsing issue, add one more test

View differences:

ExternalRecordParser.java
147 147
            XPath xpath = xPathfactory.newXPath();
148 148

  
149 149
            NodeList nl;
150
            //worknl is the list with the works we search for
151
            //work:work-summary put-code="38396847"
152
            //*[name()='media:thumbnail']/*[name() = 'media:image']
153
            //[@put-code="+orcidwork+"]
154
            NodeList worknl = (NodeList) xpath.compile("//*[name()='work:work-summary']").evaluate(document,XPathConstants.NODESET);
155
            System.out.println(worknl.getLength());
156
            if (worknl.getLength() > 0) {
157
                //worknl contains at least one result
158
                // instantiate result
150
            System.out.println(orcidwork);
151
            NodeList worknl = (NodeList) xpath.compile("//*[name()='work:work-summary'][@put-code='"+orcidwork+"']").evaluate(document,XPathConstants.NODESET);
152
            for( int n = 0; n<worknl.getLength(); n++){
153
                String code = (String) xpath.compile("//*[name()='work:work-summary'][@put-code='"+orcidwork+"']/@put-code").evaluate(worknl.item(n), XPathConstants.STRING);
159 154
                result = new Result();
160 155
                result.setResultType(ClaimUtils.PUBLICATION);
161
                nl = (NodeList) xpath.compile("//*[name()='work:title']/*[name()='common:title']/text()").evaluate(document, XPathConstants.NODESET);
156
                nl = (NodeList) xpath.compile("//*[name()='work:work-summary'][@put-code='"+orcidwork+"']/*[name()='work:title']/*[name()='common:title']/text()").evaluate(worknl.item(n), XPathConstants.NODESET);
162 157
                if (nl.getLength() > 0) {
163 158
                    result.setTitle(nl.item(0).getNodeValue());
164 159
                }
165 160

  
166
                nl = (NodeList) xpath.compile("//*[name()='common:external-id']").evaluate(document, XPathConstants.NODESET);
161
                nl = (NodeList) xpath.compile("//*[name()='work:work-summary'][@put-code='"+orcidwork+"']//*[name()='common:external-id']").evaluate(worknl.item(n), XPathConstants.NODESET);
167 162
                for (int i = 0; i < nl.getLength(); i++) {
168 163
                    NodeList identifiersNl;
169 164
                    String type=null;
170 165
                    String id=null;
171
                    identifiersNl = (NodeList) xpath.compile("//*[name()='common:external-id-type']/text()").evaluate(nl.item(i), XPathConstants.NODESET);
166
                    identifiersNl = (NodeList) xpath.compile("//*[name()='work:work-summary'][@put-code='"+orcidwork+"']//*[name()='common:external-id-type']/text()").evaluate(nl.item(i), XPathConstants.NODESET);
172 167
                    if (identifiersNl.getLength() > 0) {
173 168
                        type=identifiersNl.item(0).getNodeValue();
174 169
                    }
175
                    identifiersNl = (NodeList) xpath.compile("//*[name()='common:external-id-value']/text()").evaluate(nl.item(i), XPathConstants.NODESET);
170
                    identifiersNl = (NodeList) xpath.compile("//*[name()='work:work-summary'][@put-code='"+orcidwork+"']//*[name()='common:external-id-value']/text()").evaluate(nl.item(i), XPathConstants.NODESET);
176 171
                    if (identifiersNl.getLength() > 0) {
177 172
                        id=identifiersNl.item(0).getNodeValue();
178 173
                    }
......
184 179

  
185 180
                }
186 181
                if(result.getExternalUrl()==null) {
187
                    nl = (NodeList) xpath.compile("//*[name()='common:source']/*[name()='common:source-client-id']/*[name()='common:uri']/text()").evaluate(document, XPathConstants.NODESET);
182
                    nl = (NodeList) xpath.compile("//*[name()='work:work-summary'][@put-code='"+orcidwork+"']//*[name()='common:source']/*[name()='common:source-client-id']/*[name()='common:uri']/text()").evaluate(document, XPathConstants.NODESET);
188 183
                    if (nl.getLength() > 0) {
189 184
                        result.setExternalUrl(nl.item(0).getNodeValue());
190 185
                    }
191 186
                }
192 187

  
193
                nl = (NodeList) xpath.compile("//*[name()='work:work-summary']").evaluate(document, XPathConstants.NODESET);
188
                nl = (NodeList) xpath.compile("//*[name()='work:work-summary'][@put-code='"+orcidwork+"']//*[name()='work:work-summary']").evaluate(document, XPathConstants.NODESET);
194 189
                for (int i = 0; i < nl.getLength(); i++) {
195 190
                    if(!worknl.item(0).isEqualNode(nl.item(i))) {
196 191
                        nl.item(i).getParentNode().removeChild(nl.item(i));

Also available in: Unified diff