Project

General

Profile

« Previous | Next » 

Revision 47503

Moving for Java8 installation

View differences:

modules/uoa-claims/claims-demo/src/test/java/eu/dnetlib/data/claims/migration/parser/ExternalParserTest.java
1
package eu.dnetlib.data.claims.migration.parser;
2

  
3
import eu.dnetlib.data.claims.migration.entity.Result;
4
import eu.dnetlib.data.claimsDemo.ClaimUtils;
5
import org.apache.log4j.BasicConfigurator;
6
import org.junit.Assert;
7
import org.junit.Before;
8
import org.junit.Test;
9

  
10
/**
11
 * Created by kiatrop on 23/2/2016.
12
 */
13
public class ExternalParserTest {
14

  
15

  
16
    @Before
17
    public void init() throws Exception {
18
        BasicConfigurator.configure();
19
    }
20
    private String crossrefJson = "{\"status\":\"ok\",\"message-type\":\"work-list\",\"message-version\":\"1.0.0\",\"message\":" +
21
            "{\"query\":{\"search-terms\":null,\"start-index\":0},\"items-per-page\":20,\"items\":[{\"indexed\":" +
22
            "{\"date-parts\":[[2015,12,28]], \"date-time\":\"2015-12-28T17:45:59Z\",\"timestamp\":1451324759779}," +
23
            "\"reference-count\":0,\"publisher\":\"Society for Neuroscience\", \"issue\":\"17\"," +
24
            "\"published-print\":{\"date-parts\":[[2012,4,25]]},\"DOI\":\"10.1523\\/jneurosci.2900-11.2012\"," +
25
            "\"type\":\"journal-article\",\"created\": {\"date-parts\":[[2012,4,25]]," +
26
            "\"date-time\":\"2012-04-25T16:38:54Z\",\"timestamp\":1335371934000},\"page\":\"5728-5736\"," +
27
            "\"source\":\"CrossRef\",\"title\":[\"Imaging Microglial\\/Macrophage Activation in Spinal Cords of " +
28
            "Experimental Autoimmune Encephalomyelitis Rats by Positron Emission Tomography Using the Mitochondrial " +
29
            "18 kDa Translocator Protein Radioligand [18F]DPA-714\"]," +
30
            "\"prefix\":\"http:\\/\\/id.crossref.org\\/prefix\\/10.1523\",\"volume\":\"32\",\"author\":" +
31
            "[{\"affiliation\":[],\"family\":\"Abourbeh\",\"given\":\"G.\"},{\"affiliation\":[],\"family\":\"Theze\"," +
32
            "\"given\":\"B.\"},{\"affiliation\":[],\"family\":\"Maroy\",\"given\":\"R.\"},{\"affiliation\":[],\"family\":" +
33
            "\"Dubois\",\"given\":\"A.\"},{\"affiliation\":[],\"family\":\"Brulon\",\"given\":\"V.\"}," +
34
            "{\"affiliation\":[],\"family\":\"Fontyn\",\"given\":\"Y.\"},{\"affiliation\":[],\"family\":\"Dolle\"," +
35
            "\"given\":\"F.\"},{\"affiliation\":[],\"family\":\"Tavitian\",\"given\":\"B.\"},{\"affiliation\":[]," +
36
            "\"family\":\"Boisgard\",\"given\":\"R.\"}],\"member\":\"http:\\/\\/id.crossref.org\\/member\\/393\"," +
37
            "\"published-online\":{\"date-parts\":[[2012,4,25]]},\"container-title\":[\"Journal of Neuroscience\"]," +
38
            "\"deposited\":{\"date-parts\":[[2014,2,27]],\"date-time\":\"2014-02-27T06:42:02Z\",\"timestamp\":1393483322000}," +
39
            "\"score\":1.0,\"subtitle\":[],\"issued\":{\"date-parts\":[[2012,4,25]]}," +
40
            "\"URL\":\"http:\\/\\/dx.doi.org\\/10.1523\\/jneurosci.2900-11.2012\",\"ISSN\":[\"0270-6474\",\"1529-2401\"]," +
41
            "\"subject\":[\"Neuroscience(all)\"]}],\"total-results\":1,\"facets\":{}}}" +
42
            "";
43

  
44

  
45
    @Test
46
    public void crossref2ResultTest(){
47
        Result result = ExternalRecordParser.crossref2Result(crossrefJson);
48

  
49
        Assert.assertNull(result.getAccessRights());
50
        Assert.assertNull(result.getBestLicense());
51
        Assert.assertEquals("openaire____::crossref", result.getCollectedFrom());
52
        Assert.assertEquals("10.1523/jneurosci.2900-11.2012", result.getDoi());
53
        Assert.assertNull(result.getOai());
54
        Assert.assertNotNull(result.getOpenaireId());//        Assert.assertNull(result.getOpenaireId());
55
        Assert.assertNull(result.getPmcid());
56
        Assert.assertEquals(ClaimUtils.PUBLICATION, result.getResultType());
57
        Assert.assertEquals("Imaging Microglial/Macrophage Activation in Spinal Cords of Experimental Autoimmune Encephalomyelitis Rats by Positron Emission Tomography Using the Mitochondrial 18 kDa Translocator Protein Radioligand [18F]DPA-714", result.getTitle());
58
        Assert.assertEquals("json", result.getRecordFormat());
59
        Assert.assertEquals("https://dx.doi.org/10.1523/jneurosci.2900-11.2012", result.getExternalUrl());
60
        Assert.assertNull(result.getEmbargoEndDate());
61
        Assert.assertNull(result.getOrcidworkid());
62

  
63
        Assert.assertEquals(9, result.getAuthors().size());
64
        Assert.assertEquals("G. Abourbeh", result.getAuthors().get(0+""));
65
        Assert.assertEquals("Y. Fontyn", result.getAuthors().get(5+""));
66
    }
67

  
68
    private String orcidXml = "<orcid-message xmlns=\"http://www.orcid.org/ns/orcid\">\n" +
69
            "    <message-version>1.1</message-version>\n" +
70
            "    <orcid-profile type=\"user\">\n" +
71
            "        <orcid-identifier>\n" +
72
            "            <uri>http://orcid.org/0000-0002-9414-646X</uri>\n" +
73
            "            <path>0000-0002-9414-646X</path>\n" +
74
            "            <host>orcid.org</host>\n" +
75
            "        </orcid-identifier>\n" +
76
            "        <orcid-preferences>\n" +
77
            "            <locale>es</locale>\n" +
78
            "        </orcid-preferences>\n" +
79
            "        <orcid-history>\n" +
80
            "            <creation-method>website</creation-method>\n" +
81
            "            <completion-date>2013-01-11T14:07:54.194Z</completion-date>\n" +
82
            "            <submission-date>2013-01-11T13:27:46.558Z</submission-date>\n" +
83
            "            <last-modified-date>2016-01-27T16:06:13.543Z</last-modified-date>\n" +
84
            "            <claimed>true</claimed>\n" +
85
            "        </orcid-history>\n" +
86
            "        <orcid-activities>\n" +
87
            "            <orcid-works>\n" +
88
            "                <orcid-work put-code=\"21755327\" visibility=\"public\">\n" +
89
            "                    <work-title>\n" +
90
            "                        <title>Providing Ubiquitous Positioning in Outdoor Environments</title>\n" +
91
            "                    </work-title>\n" +
92
            "                    <journal-title>2015 IEEE International Conference on Systems, Man, and Cybernetics</journal-title>\n" +
93
            "                    <work-citation>\n" +
94
            "                        <work-citation-type>bibtex</work-citation-type>\n" +
95
            "                        <citation>@inproceedings{Moreno_2015,doi = {10.1109/smc.2015.229},url = {http://dx.doi.org/10.1109/smc.2015.229},year = 2015,month = {oct},publisher = {Institute of Electrical {\\&amp;} Electronics Engineers ({IEEE})},author = {Daniel Moreno and Sergio F. Ochoa and Roc Meseguer},title = {Providing Ubiquitous Positioning in Outdoor Environments},booktitle = {2015 {IEEE} International Conference on Systems, Man, and Cybernetics}}</citation>\n" +
96
            "                    </work-citation>\n" +
97
            "                    <work-type>conference-paper</work-type>\n" +
98
            "                    <publication-date>\n" +
99
            "                        <year>2015</year>\n" +
100
            "                        <month>10</month>\n" +
101
            "                    </publication-date>\n" +
102
            "                    <work-external-identifiers>\n" +
103
            "                        <work-external-identifier>\n" +
104
            "                            <work-external-identifier-type>doi</work-external-identifier-type>\n" +
105
            "                            <work-external-identifier-id>10.1109/smc.2015.229</work-external-identifier-id>\n" +
106
            "                        </work-external-identifier>\n" +
107
            "                    </work-external-identifiers>\n" +
108
            "                    <work-contributors>\n" +
109
            "                        <contributor>\n" +
110
            "                            <credit-name visibility=\"public\">Daniel Moreno</credit-name>\n" +
111
            "                            <contributor-attributes>\n" +
112
            "                                <contributor-role>author</contributor-role>\n" +
113
            "                            </contributor-attributes>\n" +
114
            "                        </contributor>\n" +
115
            "                        <contributor>\n" +
116
            "                            <credit-name visibility=\"public\">Sergio F. Ochoa</credit-name>\n" +
117
            "                            <contributor-attributes>\n" +
118
            "                                <contributor-role>author</contributor-role>\n" +
119
            "                            </contributor-attributes>\n" +
120
            "                        </contributor>\n" +
121
            "                        <contributor>\n" +
122
            "                            <credit-name visibility=\"public\">Roc Meseguer</credit-name>\n" +
123
            "                            <contributor-attributes>\n" +
124
            "                                <contributor-role>author</contributor-role>\n" +
125
            "                            </contributor-attributes>\n" +
126
            "                        </contributor>\n" +
127
            "                    </work-contributors>\n" +
128
            "                    <work-source>\n" +
129
            "                        <uri>http://orcid.org/0000-0002-3054-1567</uri>\n" +
130
            "                        <path>0000-0002-3054-1567</path>\n" +
131
            "                        <host>orcid.org</host>\n" +
132
            "                    </work-source>\n" +
133
            "                </orcid-work>\n" +
134
            "                <orcid-work put-code=\"19191618\" visibility=\"public\">\n" +
135
            "                    <work-title>\n" +
136
            "                        <title>A Context-Aware Model to Provide Positioning in Disaster Relief Scenarios</title>\n" +
137
            "                    </work-title>\n" +
138
            "                    <journal-title>Sensors</journal-title>\n" +
139
            "                    <work-citation>\n" +
140
            "                        <work-citation-type>bibtex</work-citation-type>\n" +
141
            "                        <citation>@article{Moreno_2015,doi = {10.3390/s151025176},url = {http://dx.doi.org/10.3390/s151025176},year = 2015,month = {sep},publisher = {{MDPI} {AG}},volume = {15},number = {10},pages = {25176--25207},author = {Daniel Moreno and Sergio Ochoa and Roc Meseguer},title = {A Context-Aware Model to Provide Positioning in Disaster Relief Scenarios},journal = {Sensors}}</citation>\n" +
142
            "                    </work-citation>\n" +
143
            "                    <work-type>journal-article</work-type>\n" +
144
            "                    <publication-date>\n" +
145
            "                        <year>2015</year>\n" +
146
            "                        <month>09</month>\n" +
147
            "                    </publication-date>\n" +
148
            "                    <work-external-identifiers>\n" +
149
            "                        <work-external-identifier>\n" +
150
            "                            <work-external-identifier-type>doi</work-external-identifier-type>\n" +
151
            "                            <work-external-identifier-id>10.3390/s151025176</work-external-identifier-id>\n" +
152
            "                        </work-external-identifier>\n" +
153
            "                    </work-external-identifiers>\n" +
154
            "                    <work-contributors>\n" +
155
            "                        <contributor>\n" +
156
            "                            <credit-name visibility=\"public\">Daniel Moreno</credit-name>\n" +
157
            "                            <contributor-attributes>\n" +
158
            "                                <contributor-role>author</contributor-role>\n" +
159
            "                            </contributor-attributes>\n" +
160
            "                        </contributor>\n" +
161
            "                        <contributor>\n" +
162
            "                            <credit-name visibility=\"public\">Sergio Ochoa</credit-name>\n" +
163
            "                            <contributor-attributes>\n" +
164
            "                                <contributor-role>author</contributor-role>\n" +
165
            "                            </contributor-attributes>\n" +
166
            "                        </contributor>\n" +
167
            "                        <contributor>\n" +
168
            "                            <credit-name visibility=\"public\">Roc Meseguer</credit-name>\n" +
169
            "                            <contributor-attributes>\n" +
170
            "                                <contributor-role>author</contributor-role>\n" +
171
            "                            </contributor-attributes>\n" +
172
            "                        </contributor>\n" +
173
            "                    </work-contributors>\n" +
174
            "                    <work-source>\n" +
175
            "                        <uri>http://orcid.org/0000-0002-3054-1567</uri>\n" +
176
            "                        <path>0000-0002-3054-1567</path>\n" +
177
            "                        <host>orcid.org</host>\n" +
178
            "                    </work-source>\n" +
179
            "                </orcid-work>" +
180
            "</orcid-works></orcid-activities></orcid-profile></orcid-message>";
181

  
182
    @Test
183
    public void orcid2ResultTest() {
184
        Result result = ExternalRecordParser.orcid2Result(orcidXml, "0000-0002-9414-646X-21755327");
185

  
186
        Assert.assertNull(result.getAccessRights());
187
        Assert.assertNull(result.getBestLicense());
188
        Assert.assertEquals("openaire____::orcid", result.getCollectedFrom());
189
        Assert.assertEquals("10.1109/smc.2015.229", result.getDoi());
190
        Assert.assertEquals("0000-0002-9414-646X-21755327", result.getOrcidworkid());
191
        Assert.assertNull(result.getOai());
192
        Assert.assertNotNull(result.getOpenaireId());//        Assert.assertNull(result.getOpenaireId());
193
        Assert.assertNull(result.getPmcid());
194
        Assert.assertEquals(ClaimUtils.PUBLICATION, result.getResultType());
195
        Assert.assertEquals("Providing Ubiquitous Positioning in Outdoor Environments", result.getTitle());
196
        Assert.assertEquals("xml", result.getRecordFormat());
197
        Assert.assertEquals("https://dx.doi.org/10.1109/smc.2015.229", result.getExternalUrl());
198
        Assert.assertNull(result.getEmbargoEndDate());
199

  
200
    }
201

  
202

  
203
    private String dataciteXml = "<rdf:RDF\n" +
204
            "    xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n" +
205
            "    xmlns:owl=\"http://www.w3.org/2002/07/owl#\"\n" +
206
            "    xmlns:j.0=\"http://purl.org/dc/terms/\" > \n" +
207
            "  <rdf:Description rdf:about=\"http://dx.doi.org/10.5060/D4RN35SD/USGS85K1_041\">\n" +
208
            "    <j.0:creator>Krimmel, Robert</j.0:creator>\n" +
209
            "    <j.0:publisher>National Snow and Ice Data Center/World Data Center for Glaciology, Boulder</j.0:publisher>\n" +
210
            "    <j.0:title>Chocolate Glacier</j.0:title>\n" +
211
            "    <j.0:date>2008</j.0:date>\n" +
212
            "    <owl:sameAs>doi:10.5060/D4RN35SD/USGS85K1_041</owl:sameAs>\n" +
213
            "    <owl:sameAs>info:doi/10.5060/D4RN35SD/USGS85K1_041</owl:sameAs>\n" +
214
            "    <j.0:identifier>10.5060/D4RN35SD/USGS85K1_041</j.0:identifier>\n" +
215
            "  </rdf:Description>\n" +
216
            "</rdf:RDF>\n";
217

  
218
    private String dataciteJson = "{\"data\":{\"id\":\"https://doi.org/10.5281/ZENODO.54730\",\"type\":\"works\",\"attributes\":{\"doi\":\"10.5281/ZENODO.54730\",\"url\":null,\"author\":[{\"family\":\"Manola\",\"given\":\"Natalia\"}],\"title\":\"From Open Access to Open Science\",\"container-title\":\"Zenodo\",\"description\":\"Presentation given at the PASTEUR4OA conference - Green Light for Open Access: Aligning Europe’s OA Policies, Amsterdam, 17th-18th May 2016.\",\"resource-type-subtype\":\"Presentation\",\"data-center-id\":\"cern.zenodo\",\"member-id\":\"cern\",\"resource-type-id\":\"text\",\"version\":null,\"license\":\"https://creativecommons.org/licenses/by/4.0/\",\"schema-version\":\"3\",\"results\":[],\"related-identifiers\":[],\"published\":\"2016\",\"deposited\":\"2016-06-03T17:03:51Z\",\"updated\":\"2016-06-03T17:03:51Z\",\"media\":null,\"xml\":\"PHJlc291cmNlIHhtbG5zPSJodHRwOi8vZGF0YWNpdGUub3JnL3NjaGVtYS9rZXJuZWwtMyIgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYS1pbnN0YW5jZSIgeHNpOnNjaGVtYUxvY2F0aW9uPSJodHRwOi8vZGF0YWNpdGUub3JnL3NjaGVtYS9rZXJuZWwtMyBodHRwOi8vc2NoZW1hLmRhdGFjaXRlLm9yZy9tZXRhL2tlcm5lbC0zL21ldGFkYXRhLnhzZCI+CiAgPGlkZW50aWZpZXIgaWRlbnRpZmllclR5cGU9IkRPSSI+MTAuNTI4MS96ZW5vZG8uNTQ3MzA8L2lkZW50aWZpZXI+CiAgPGNyZWF0b3JzPgogICAgPGNyZWF0b3I+CiAgICAgIDxjcmVhdG9yTmFtZT5NYW5vbGEsIE5hdGFsaWEgPC9jcmVhdG9yTmFtZT4KICAgICAgPGFmZmlsaWF0aW9uPk9wZW5BSVJFPC9hZmZpbGlhdGlvbj4KICAgIDwvY3JlYXRvcj4KICA8L2NyZWF0b3JzPgogIDx0aXRsZXM+CiAgICA8dGl0bGU+RnJvbSBPcGVuIEFjY2VzcyB0byBPcGVuIFNjaWVuY2U8L3RpdGxlPgogIDwvdGl0bGVzPgogIDxwdWJsaXNoZXI+WmVub2RvPC9wdWJsaXNoZXI+CiAgPHB1YmxpY2F0aW9uWWVhcj4yMDE2PC9wdWJsaWNhdGlvblllYXI+CiAgPHN1YmplY3RzPgogICAgPHN1YmplY3Q+UEFTVEVVUjRPQTwvc3ViamVjdD4KICAgIDxzdWJqZWN0Pk9wZW4gQWNjZXNzPC9zdWJqZWN0PgogICAgPHN1YmplY3Q+UHJlc2VudGF0aW9uPC9zdWJqZWN0PgogIDwvc3ViamVjdHM+CiAgPGNvbnRyaWJ1dG9ycz4KICAgIDxjb250cmlidXRvciBjb250cmlidXRvclR5cGU9IkZ1bmRlciI+CiAgICAgIDxjb250cmlidXRvck5hbWU+RXVyb3BlYW4gQ29tbWlzc2lvbjwvY29udHJpYnV0b3JOYW1lPgogICAgICA8bmFtZUlkZW50aWZpZXIgbmFtZUlkZW50aWZpZXJTY2hlbWU9ImluZm8iPmluZm86ZXUtcmVwby9ncmFudEFncmVlbWVudC9FQy9GUDcvNjExNzQyPC9uYW1lSWRlbnRpZmllcj4KICAgIDwvY29udHJpYnV0b3I+CiAgPC9jb250cmlidXRvcnM+CiAgPGRhdGVzPgogICAgPGRhdGUgZGF0ZVR5cGU9Iklzc3VlZCI+MjAxNi0wNS0xODwvZGF0ZT4KICA8L2RhdGVzPgogIDxyZXNvdXJjZVR5cGUgcmVzb3VyY2VUeXBlR2VuZXJhbD0iVGV4dCI+UHJlc2VudGF0aW9uPC9yZXNvdXJjZVR5cGU+CiAgPGFsdGVybmF0ZUlkZW50aWZpZXJzPgogICAgPGFsdGVybmF0ZUlkZW50aWZpZXIgYWx0ZXJuYXRlSWRlbnRpZmllclR5cGU9IlVSTCI+aHR0cDovL3plbm9kby5vcmcvcmVjb3JkLzU0NzMwPC9hbHRlcm5hdGVJZGVudGlmaWVyPgogICAgPGFsdGVybmF0ZUlkZW50aWZpZXIgYWx0ZXJuYXRlSWRlbnRpZmllclR5cGU9IlVSTCI+aHR0cDovL3d3dy5wYXN0ZXVyNG9hLmV1L3NpdGVzL3Bhc3RldXI0b2EvZmlsZXMvZ2VuZXJpYy9OYXRhbGlhJTIwTWFub2xhJTIwUERGLnBkZjwvYWx0ZXJuYXRlSWRlbnRpZmllcj4KICA8L2FsdGVybmF0ZUlkZW50aWZpZXJzPgogIDxyZWxhdGVkSWRlbnRpZmllcnM+CiAgICA8cmVsYXRlZElkZW50aWZpZXIgcmVsYXRpb25UeXBlPSJIYXNQYXJ0IiByZWxhdGVkSWRlbnRpZmllclR5cGU9IlVSTCI+aHR0cHM6Ly96ZW5vZG8ub3JnL3JlY29yZC81NDczMC9maWxlcy8xOF9OYXRhbGlhX01hbm9sYV9QREYucGRmPC9yZWxhdGVkSWRlbnRpZmllcj4KICA8L3JlbGF0ZWRJZGVudGlmaWVycz4KICA8cmlnaHRzTGlzdD4KICAgIDxyaWdodHMgcmlnaHRzVVJJPSJpbmZvOmV1LXJlcG8vc2VtYW50aWNzL29wZW5BY2Nlc3MiPk9wZW4gQWNjZXNzPC9yaWdodHM+CiAgICA8cmlnaHRzIHJpZ2h0c1VSST0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbGljZW5zZXMvYnkvNC4wLyI+Q3JlYXRpdmUgQ29tbW9ucyBBdHRyaWJ1dGlvbiA0LjAgSW50ZXJuYXRpb25hbDwvcmlnaHRzPgogIDwvcmlnaHRzTGlzdD4KICA8ZGVzY3JpcHRpb25zPgogICAgPGRlc2NyaXB0aW9uIGRlc2NyaXB0aW9uVHlwZT0iQWJzdHJhY3QiPiZsdDtwJmd0O1ByZXNlbnRhdGlvbiBnaXZlbiBhdCB0aGUgUEFTVEVVUjRPQSBjb25mZXJlbmNlIC0mYW1wO25ic3A7R3JlZW4gTGlnaHQgZm9yIE9wZW4gQWNjZXNzOiBBbGlnbmluZyBFdXJvcGUmYW1wO3JzcXVvO3MgT0EgUG9saWNpZXMsIEFtc3RlcmRhbSwgMTd0aC0xOHRoIE1heSAyMDE2LiZsdDsvcCZndDs8L2Rlc2NyaXB0aW9uPgogIDwvZGVzY3JpcHRpb25zPgo8L3Jlc291cmNlPgo=\"},\"relationships\":{\"data-center\":{\"meta\":{}},\"member\":{\"meta\":{}},\"resource-type\":{\"meta\":{}}}}}";
219

  
220
    @Test
221
    public void datacite2ResultTest() {
222
        Result result = ExternalRecordParser.datacite2Result(dataciteXml);
223

  
224
        Assert.assertNull(result.getAccessRights());
225
        Assert.assertNull(result.getBestLicense());
226
        Assert.assertEquals("openaire____::datacite", result.getCollectedFrom());
227
        Assert.assertEquals("10.5060/D4RN35SD/USGS85K1_041", result.getDoi());
228
        Assert.assertNull(result.getOrcidworkid());
229
        Assert.assertNull(result.getOai());
230
        Assert.assertNotNull(result.getOpenaireId());//        Assert.assertNull(result.getOpenaireId());
231
        Assert.assertNull(result.getPmcid());
232
        Assert.assertEquals(ClaimUtils.DATASET, result.getResultType());
233
        Assert.assertEquals("Chocolate Glacier", result.getTitle());
234
        Assert.assertEquals("xml", result.getRecordFormat());
235
        Assert.assertEquals("http://dx.doi.org/10.5060/D4RN35SD/USGS85K1_041", result.getExternalUrl());
236
        Assert.assertNull(result.getEmbargoEndDate());
237

  
238
    }
239

  
240
    @Test
241
    public void dataciteJsonResultTest() {
242
        Result result = ExternalRecordParser.dataciteJson2Result(dataciteJson);
243

  
244
        Assert.assertNull(result.getAccessRights());
245
        Assert.assertNull(result.getBestLicense());
246
        Assert.assertEquals("openaire____::datacite", result.getCollectedFrom());
247
        Assert.assertEquals("10.5281/ZENODO.54730", result.getDoi());
248
        Assert.assertNull(result.getOrcidworkid());
249
        Assert.assertNull(result.getOai());
250
        Assert.assertNotNull(result.getOpenaireId());//        Assert.assertNull(result.getOpenaireId());
251
        Assert.assertNull(result.getPmcid());
252
        Assert.assertEquals(ClaimUtils.DATASET, result.getResultType());
253
        Assert.assertEquals("From Open Access to Open Science", result.getTitle());
254
        Assert.assertEquals("json", result.getRecordFormat());
255
        Assert.assertEquals("https://dx.doi.org/10.5281/ZENODO.54730", result.getExternalUrl());
256
        Assert.assertNull(result.getEmbargoEndDate());
257

  
258
    }
259
}
modules/uoa-claims/claims-demo/src/test/java/eu/dnetlib/data/claims/migration/parser/OafParserTest.java
1
package eu.dnetlib.data.claims.migration.parser;
2

  
3
import eu.dnetlib.data.claims.migration.entity.Result;
4
import eu.dnetlib.data.claimsDemo.ClaimUtils;
5
import eu.dnetlib.data.claims.migration.entity.Project;
6
import org.apache.log4j.BasicConfigurator;
7
import org.junit.Assert;
8
import org.junit.Before;
9
import org.junit.Test;
10
import org.xml.sax.SAXException;
11

  
12
import javax.xml.parsers.ParserConfigurationException;
13
import javax.xml.transform.TransformerException;
14
import javax.xml.xpath.XPathExpressionException;
15
import java.io.IOException;
16

  
17
/**
18
 * Created by kiatrop on 22/2/2016.
19
 */
20
public class OafParserTest {
21

  
22
    @Before()
23
    public void init(){
24
        BasicConfigurator.configure();
25
    }
26

  
27
    private String publicationOaf = "<response>\n" +
28
            "\t  <header>\n" +
29
            "\t\t    <query>(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (objidentifier exact od______2806::d19b8560e0c4ce1f25dd9d661f4b2b46)</query>\n" +
30
            "\t\t\t\t  <locale>en_GB</locale>\t\n" +
31
            "\t\t\t\t\t<size>10</size>\n" +
32
            "\t\t\t   <page>1</page>\n" +
33
            "\t\t\t   <total>1</total>\n" +
34
            "\t\t\t\t\t</header>\n" +
35
            "\t  <results>\n" +
36
            "\t\t\t\t\t\t\t\t\t<result xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
37
            "              xmlns:dri=\"http://www.driver-repository.eu/namespace/dri\"\n" +
38
            "              xmlns:oaf=\"http://namespace.openaire.eu/oaf\">\n" +
39
            "         <header>\n" +
40
            "            <dri:objIdentifier>od______2806::d19b8560e0c4ce1f25dd9d661f4b2b46</dri:objIdentifier>\n" +
41
            "            <dri:dateOfCollection>2016-02-02T08:07:14Z</dri:dateOfCollection>\n" +
42
             "         </header>\n" +
43
            "         <metadata>\n" +
44
            "            <oaf:entity xsi:schemaLocation=\"http://namespace.openaire.eu/oaf https://www.openaire.eu/schema/0.3/oaf-0.3.xsd\">\n" +
45
            "\t\t             <oaf:result>\n" +
46
            "                  <title classid=\"main title\" classname=\"main title\" schemeid=\"dnet:dataCite_title\"\n" +
47
            "                         schemename=\"dnet:dataCite_title\">ПОСТКОНВЕРСИОННАЯ АСИСТОЛИЯ ЖЕЛУДОЧКОВ СЕРДЦА У БОЛЬНЫХ ИНФАРКТОМ МИОКАРДА И ВОЗМОЖНОСТИ ЕЕ ПРОФИЛАКТИКИ</title>\n" +
48
            "                  <dateofacceptance>2010-01-01</dateofacceptance>\n" +
49
            "                  <resulttype classid=\"publication\" classname=\"publication\" schemeid=\"dnet:result_typologies\"\n" +
50
            "                              schemename=\"dnet:result_typologies\"/>\n" +
51
            "                  <country classid=\"\" classname=\"\" schemeid=\"\" schemename=\"\"/>\n" +
52
            "                  <relevantdate classid=\"\" classname=\"\" schemeid=\"\" schemename=\"\"/>\n" +
53
            "                  <embargoenddate>2099-12-31</embargoenddate>\n" +
54
            "                  <originalId>oai:cyberleninka.ru:article/5969541</originalId>\n" +
55
            "                  <collectedfrom name=\"CyberLeninka - Russian open access scientific library\"\n" +
56
            "                                 id=\"opendoar____::c0f971d8cd24364f2029fcb9ac7b71f5\"/>\n" +
57
            "                  <pid classid=\"oai\" classname=\"oai\" schemeid=\"dnet:pid_types\"\n" +
58
            "                       schemename=\"dnet:pid_types\">oai:cyberleninka.ru:article/5969541</pid>\n" +
59
            "                  <pid classid=\"pmc\" classname=\"pmc\" schemeid=\"dnet:pid_types\"\n" +
60
            "                       schemename=\"dnet:pid_types\">pmc_test</pid>\n" +
61
            "                  <pid classid=\"orcidworkid\" classname=\"orcidworkid\" schemeid=\"dnet:pid_types\"\n" +
62
            "                       schemename=\"dnet:pid_types\">orcidworkid_test</pid>\n" +
63
    "                  <bestlicense classid=\"EMBARGO\" classname=\"Open Access\" schemeid=\"dnet:access_modes\"\n" +
64
            "                               schemename=\"dnet:access_modes\"/>\n" +
65
            "\t\t                <children>\n" +
66
            "\t\t\t                  <instance id=\"opendoar____::c0f971d8cd24364f2029fcb9ac7b71f5\">\n" +
67
            "\t\t\t                     <licence classid=\"EMBARGO\" classname=\"Open Access\" schemeid=\"dnet:access_modes\"\n" +
68
            "                                 schemename=\"dnet:access_modes\"/>\n" +
69
            "                        <instancetype classid=\"0001\" classname=\"Article\" schemeid=\"dnet:publication_resource\"\n" +
70
            "                                      schemename=\"dnet:publication_resource\"/>\n" +
71
            "                        <hostedby name=\"CyberLeninka - Russian open access scientific library\"\n" +
72
            "                                  id=\"opendoar____::c0f971d8cd24364f2029fcb9ac7b71f5\"/>\n" +
73
            "\t\t\t\t                    <webresource>\n" +
74
            "\t\t\t\t                       <url>http://cyberleninka.ru/article/n/postkonversionnaya-asistoliya-zheludochkov-serdtsa-u-bolnyh-infarktom-miokarda-i-vozmozhnosti-ee-profilaktiki</url>\n" +
75
            "\t\t\t\t                    </webresource>\n" +
76
            "\t\t\t\t                    <webresource>\n" +
77
            "\t\t\t\t                       <url>http://cyberleninka.ru/article_covers/5969541.png</url>\n" +
78
            "\t\t\t\t                    </webresource>\n" +
79
            "\t\t\t                  </instance>\n" +
80
            "\t\t                </children>\n" +
81
            "\t\t             </oaf:result>\n" +
82
            "            </oaf:entity>\n" +
83
            "         </metadata>\n" +
84
            "      </result>\n" +
85
            "\t\t\t\t\t\t</results>\n" +
86
            "\t  <browseResults>\n" +
87
            "\t\t\t</browseResults>\n" +
88
            "</response>";
89

  
90

  
91

  
92
    /*
93
            "\t\t                <children>\n" +
94
            "\t\t\t                  <instance id=\"opendoar____::c0f971d8cd24364f2029fcb9ac7b71f5\">\n" +
95
            "\t\t\t                     <licence classid=\"CLOSED\" classname=\"Open Access\" schemeid=\"dnet:access_modes\"\n" +
96
            "                                 schemename=\"dnet:access_modes\"/>\n" +
97
            "                        <instancetype classid=\"0001\" classname=\"Article\" schemeid=\"dnet:publication_resource\"\n" +
98
            "                                      schemename=\"dnet:publication_resource\"/>\n" +
99
            "                        <hostedby name=\"CyberLeninka - Russian open access scientific library\"\n" +
100
            "                                  id=\"opendoar____::c0f971d8cd24364f2029fcb9ac7b71f5\"/>\n" +
101
            "\t\t\t\t                    <webresource>\n" +
102
            "\t\t\t\t                       <url>h CLOSED_ACCESS_URL</url>\n" +
103
            "\t\t\t\t                    </webresource>\n" +
104
            "\t\t\t\t                    <webresource>\n" +
105
            "\t\t\t\t                       <url>http://cyberleninka.ru/article_covers/5969541.png</url>\n" +
106
            "\t\t\t\t                    </webresource>\n" +
107
            "\t\t\t                  </instance>\n" +
108
            "\t\t                </children>\n" +
109
 */
110
    @Test
111
    public void oaf2PublicationTest() throws Exception, ParserConfigurationException, SAXException, XPathExpressionException, IOException, TransformerException {
112
        Result result = OafParser.oaf2Result(publicationOaf);
113
        System.out.println(result.getExternalUrl());
114
        Assert.assertNull(result.getAccessRights());
115
        Assert.assertEquals("EMBARGO",result.getBestLicense());
116
        Assert.assertEquals("infrastruct_::openaire", result.getCollectedFrom());
117
        Assert.assertNull(result.getDoi());
118
        Assert.assertEquals("oai:cyberleninka.ru:article/5969541",result.getOai());
119
        Assert.assertEquals("od______2806::d19b8560e0c4ce1f25dd9d661f4b2b46",result.getOpenaireId());
120
        Assert.assertEquals("pmc_test",result.getPmcid());
121
        Assert.assertEquals(ClaimUtils.PUBLICATION, result.getResultType());
122
        Assert.assertEquals("ПОСТКОНВЕРСИОННАЯ АСИСТОЛИЯ ЖЕЛУДОЧКОВ СЕРДЦА У БОЛЬНЫХ ИНФАРКТОМ МИОКАРДА И ВОЗМОЖНОСТИ ЕЕ ПРОФИЛАКТИКИ",result.getTitle());
123
        Assert.assertEquals("xml", result.getRecordFormat());
124

  
125
        Assert.assertEquals("http://cyberleninka.ru/article/n/postkonversionnaya-asistoliya-zheludochkov-serdtsa-u-bolnyh-infarktom-miokarda-i-vozmozhnosti-ee-profilaktiki", result.getExternalUrl());
126
        Assert.assertEquals("2099-12-31",result.getEmbargoEndDate());
127
        Assert.assertEquals("orcidworkid_test", result.getOrcidworkid());
128

  
129
    }
130
    private String publicationOpenAccessUrl = "<response>\n" +
131
            "\t  <header>\n" +
132
            "\t\t    <query>(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (objidentifier exact od______2806::d19b8560e0c4ce1f25dd9d661f4b2b46)</query>\n" +
133
            "\t\t\t\t  <locale>en_GB</locale>\t\n" +
134
            "\t\t\t\t\t<size>10</size>\n" +
135
            "\t\t\t   <page>1</page>\n" +
136
            "\t\t\t   <total>1</total>\n" +
137
            "\t\t\t\t\t</header>\n" +
138
            "\t  <results>\n" +
139
            "\t\t\t\t\t\t\t\t\t<result xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
140
            "              xmlns:dri=\"http://www.driver-repository.eu/namespace/dri\"\n" +
141
            "              xmlns:oaf=\"http://namespace.openaire.eu/oaf\">\n" +
142
            "         <header>\n" +
143
            "            <dri:objIdentifier>od______2806::d19b8560e0c4ce1f25dd9d661f4b2b46</dri:objIdentifier>\n" +
144
            "            <dri:dateOfCollection>2016-02-02T08:07:14Z</dri:dateOfCollection>\n" +
145
            "         </header>\n" +
146
            "         <metadata>\n" +
147
            "            <oaf:entity xsi:schemaLocation=\"http://namespace.openaire.eu/oaf https://www.openaire.eu/schema/0.3/oaf-0.3.xsd\">\n" +
148
            "\t\t             <oaf:result>\n" +
149
            "                  <title classid=\"main title\" classname=\"main title\" schemeid=\"dnet:dataCite_title\"\n" +
150
            "                         schemename=\"dnet:dataCite_title\">ПОСТКОНВЕРСИОННАЯ АСИСТОЛИЯ ЖЕЛУДОЧКОВ СЕРДЦА У БОЛЬНЫХ ИНФАРКТОМ МИОКАРДА И ВОЗМОЖНОСТИ ЕЕ ПРОФИЛАКТИКИ</title>\n" +
151
            "                  <dateofacceptance>2010-01-01</dateofacceptance>\n" +
152
            "                  <resulttype classid=\"publication\" classname=\"publication\" schemeid=\"dnet:result_typologies\"\n" +
153
            "                              schemename=\"dnet:result_typologies\"/>\n" +
154
            "                  <country classid=\"\" classname=\"\" schemeid=\"\" schemename=\"\"/>\n" +
155
            "                  <relevantdate classid=\"\" classname=\"\" schemeid=\"\" schemename=\"\"/>\n" +
156
            "                  <embargoenddate>2099-12-31</embargoenddate>\n" +
157
            "                  <originalId>oai:cyberleninka.ru:article/5969541</originalId>\n" +
158
            "                  <collectedfrom name=\"CyberLeninka - Russian open access scientific library\"\n" +
159
            "                                 id=\"opendoar____::c0f971d8cd24364f2029fcb9ac7b71f5\"/>\n" +
160
            "                  <pid classid=\"oai\" classname=\"oai\" schemeid=\"dnet:pid_types\"\n" +
161
            "                       schemename=\"dnet:pid_types\">oai:cyberleninka.ru:article/5969541</pid>\n" +
162
            "                  <pid classid=\"pmc\" classname=\"pmc\" schemeid=\"dnet:pid_types\"\n" +
163
            "                       schemename=\"dnet:pid_types\">pmc_test</pid>\n" +
164
            "                  <pid classid=\"orcidworkid\" classname=\"orcidworkid\" schemeid=\"dnet:pid_types\"\n" +
165
            "                       schemename=\"dnet:pid_types\">orcidworkid_test</pid>\n" +
166
            "                  <bestlicense classid=\"EMBARGO\" classname=\"Open Access\" schemeid=\"dnet:access_modes\"\n" +
167
            "                               schemename=\"dnet:access_modes\"/>\n" +
168
            "\t\t                <children>\n" +
169
            "\t\t\t                  <instance id=\"opendoar____::c0f971d8cd24364f2029fcb9ac7b71f5\">\n" +
170
            "\t\t\t                     <licence classid=\"CLOSED\" classname=\"Open Access\" schemeid=\"dnet:access_modes\"\n" +
171
            "                                 schemename=\"dnet:access_modes\"/>\n" +
172
            "                        <instancetype classid=\"0001\" classname=\"Article\" schemeid=\"dnet:publication_resource\"\n" +
173
            "                                      schemename=\"dnet:publication_resource\"/>\n" +
174
            "                        <hostedby name=\"CyberLeninka - Russian open access scientific library\"\n" +
175
            "                                  id=\"opendoar____::c0f971d8cd24364f2029fcb9ac7b71f5\"/>\n" +
176
            "\t\t\t\t                    <webresource>\n" +
177
            "\t\t\t\t                       <url>http://CLOSED_ACCESS_URL</url>\n" +
178
            "\t\t\t\t                    </webresource>\n" +
179
            "\t\t\t\t                    <webresource>\n" +
180
            "\t\t\t\t                       <url>http://cyberleninka.ru/article_covers/5969541.png</url>\n" +
181
            "\t\t\t\t                    </webresource>\n" +
182
            "\t\t\t                  </instance>\n" +
183
            "\t\t                </children>\n" +
184
            "\t\t                <children>\n" +
185
            "\t\t\t                  <instance id=\"opendoar____::c0f971d8cd24364f2029fcb9ac7b71f5\">\n" +
186
            "\t\t\t                     <licence classid=\"EMBARGO\" classname=\"Open Access\" schemeid=\"dnet:access_modes\"\n" +
187
            "                                 schemename=\"dnet:access_modes\"/>\n" +
188
            "                        <instancetype classid=\"0001\" classname=\"Article\" schemeid=\"dnet:publication_resource\"\n" +
189
            "                                      schemename=\"dnet:publication_resource\"/>\n" +
190
            "                        <hostedby name=\"CyberLeninka - Russian open access scientific library\"\n" +
191
            "                                  id=\"opendoar____::c0f971d8cd24364f2029fcb9ac7b71f5\"/>\n" +
192
            "\t\t\t\t                    <webresource>\n" +
193
            "\t\t\t\t                       <url>http://cyberleninka.ru/article/n/postkonversionnaya-asistoliya-zheludochkov-serdtsa-u-bolnyh-infarktom-miokarda-i-vozmozhnosti-ee-profilaktiki</url>\n" +
194
            "\t\t\t\t                    </webresource>\n" +
195
            "\t\t\t\t                    <webresource>\n" +
196
            "\t\t\t\t                       <url>http://cyberleninka.ru/article_covers/5969541.png</url>\n" +
197
            "\t\t\t\t                    </webresource>\n" +
198
            "\t\t\t                  </instance>\n" +
199
            "\t\t                </children>\n" +
200

  
201

  
202

  
203
            "\t\t             </oaf:result>\n" +
204
            "            </oaf:entity>\n" +
205
            "         </metadata>\n" +
206
            "      </result>\n" +
207
            "\t\t\t\t\t\t</results>\n" +
208
            "\t  <browseResults>\n" +
209
            "\t\t\t</browseResults>\n" +
210
            "</response>";
211
/*
212
In this test, the oaf xml has multiple urls. The method should get the first "more" open Access with the following order (Open Access,Embargo, Closed )
213
 */
214
    @Test
215
    public void oaf2PublicationOpenAccessUrlTest() throws Exception, ParserConfigurationException, SAXException, XPathExpressionException, IOException, TransformerException {
216
        Result result = OafParser.oaf2Result(publicationOpenAccessUrl);
217
        System.out.println(result.getExternalUrl());
218
        Assert.assertNull(result.getAccessRights());
219
        Assert.assertEquals("EMBARGO",result.getBestLicense());
220
        Assert.assertEquals("infrastruct_::openaire", result.getCollectedFrom());
221
        Assert.assertNull(result.getDoi());
222
        Assert.assertEquals("oai:cyberleninka.ru:article/5969541",result.getOai());
223
        Assert.assertEquals("od______2806::d19b8560e0c4ce1f25dd9d661f4b2b46",result.getOpenaireId());
224
        Assert.assertEquals("pmc_test",result.getPmcid());
225
        Assert.assertEquals(ClaimUtils.PUBLICATION, result.getResultType());
226
        Assert.assertEquals("ПОСТКОНВЕРСИОННАЯ АСИСТОЛИЯ ЖЕЛУДОЧКОВ СЕРДЦА У БОЛЬНЫХ ИНФАРКТОМ МИОКАРДА И ВОЗМОЖНОСТИ ЕЕ ПРОФИЛАКТИКИ",result.getTitle());
227
        Assert.assertEquals("xml", result.getRecordFormat());
228

  
229
        Assert.assertEquals("http://cyberleninka.ru/article/n/postkonversionnaya-asistoliya-zheludochkov-serdtsa-u-bolnyh-infarktom-miokarda-i-vozmozhnosti-ee-profilaktiki", result.getExternalUrl());
230
        Assert.assertEquals("2099-12-31",result.getEmbargoEndDate());
231
        Assert.assertEquals("orcidworkid_test", result.getOrcidworkid());
232

  
233
    }
234
    private String publicationWithDoiOaf = "<response>\n" +
235
            "\t  <header>\n" +
236
            "\t\t    <query>(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (objidentifier exact od______2806::d19b8560e0c4ce1f25dd9d661f4b2b46)</query>\n" +
237
            "\t\t\t\t  <locale>en_GB</locale>\t\n" +
238
            "\t\t\t\t\t<size>10</size>\n" +
239
            "\t\t\t   <page>1</page>\n" +
240
            "\t\t\t   <total>1</total>\n" +
241
            "\t\t\t\t\t</header>\n" +
242
            "\t  <results>\n" +
243
            "\t\t\t\t\t\t\t\t\t<result xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
244
            "              xmlns:dri=\"http://www.driver-repository.eu/namespace/dri\"\n" +
245
            "              xmlns:oaf=\"http://namespace.openaire.eu/oaf\">\n" +
246
            "         <header>\n" +
247
            "            <dri:objIdentifier>od______2806::d19b8560e0c4ce1f25dd9d661f4b2b46</dri:objIdentifier>\n" +
248
            "            <dri:dateOfCollection>2016-02-02T08:07:14Z</dri:dateOfCollection>\n" +
249
            "         </header>\n" +
250
            "         <metadata>\n" +
251
            "            <oaf:entity xsi:schemaLocation=\"http://namespace.openaire.eu/oaf https://www.openaire.eu/schema/0.3/oaf-0.3.xsd\">\n" +
252
            "\t\t             <oaf:result>\n" +
253
            "                  <title classid=\"main title\" classname=\"main title\" schemeid=\"dnet:dataCite_title\"\n" +
254
            "                         schemename=\"dnet:dataCite_title\">ПОСТКОНВЕРСИОННАЯ АСИСТОЛИЯ ЖЕЛУДОЧКОВ СЕРДЦА У БОЛЬНЫХ ИНФАРКТОМ МИОКАРДА И ВОЗМОЖНОСТИ ЕЕ ПРОФИЛАКТИКИ</title>\n" +
255
            "                  <dateofacceptance>2010-01-01</dateofacceptance>\n" +
256
            "                  <resulttype classid=\"publication\" classname=\"publication\" schemeid=\"dnet:result_typologies\"\n" +
257
            "                              schemename=\"dnet:result_typologies\"/>\n" +
258
            "                  <country classid=\"\" classname=\"\" schemeid=\"\" schemename=\"\"/>\n" +
259
            "                  <relevantdate classid=\"\" classname=\"\" schemeid=\"\" schemename=\"\"/>\n" +
260
            "                  <embargoenddate>2099-12-31</embargoenddate>\n" +
261
            "                  <originalId>oai:cyberleninka.ru:article/5969541</originalId>\n" +
262
            "                  <collectedfrom name=\"CyberLeninka - Russian open access scientific library\"\n" +
263
            "                                 id=\"opendoar____::c0f971d8cd24364f2029fcb9ac7b71f5\"/>\n" +
264
            "                  <pid classid=\"doi\" classname=\"doi\" schemeid=\"dnet:pid_types\"\n" +
265
            "                       schemename=\"dnet:pid_types\">doi_test</pid>\n" +
266
            "                  <pid classid=\"oai\" classname=\"oai\" schemeid=\"dnet:pid_types\"\n" +
267
            "                       schemename=\"dnet:pid_types\">oai:cyberleninka.ru:article/5969541</pid>\n" +
268
            "                  <pid classid=\"pmc\" classname=\"pmc\" schemeid=\"dnet:pid_types\"\n" +
269
            "                       schemename=\"dnet:pid_types\">pmc_test</pid>\n" +
270
            "                  <pid classid=\"orcidworkid\" classname=\"orcidworkid\" schemeid=\"dnet:pid_types\"\n" +
271
            "                       schemename=\"dnet:pid_types\">orcidworkid_test</pid>\n" +
272
            "                  <bestlicense classid=\"EMBARGO\" classname=\"Open Access\" schemeid=\"dnet:access_modes\"\n" +
273
            "                               schemename=\"dnet:access_modes\"/>\n" +
274
            "\t\t                <children>\n" +
275
            "\t\t\t                  <instance id=\"opendoar____::c0f971d8cd24364f2029fcb9ac7b71f5\">\n" +
276
            "\t\t\t                     <licence classid=\"EMBARGO\" classname=\"Open Access\" schemeid=\"dnet:access_modes\"\n" +
277
            "                                 schemename=\"dnet:access_modes\"/>\n" +
278
            "                        <instancetype classid=\"0001\" classname=\"Article\" schemeid=\"dnet:publication_resource\"\n" +
279
            "                                      schemename=\"dnet:publication_resource\"/>\n" +
280
            "                        <hostedby name=\"CyberLeninka - Russian open access scientific library\"\n" +
281
            "                                  id=\"opendoar____::c0f971d8cd24364f2029fcb9ac7b71f5\"/>\n" +
282
            "\t\t\t\t                    <webresource>\n" +
283
            "\t\t\t\t                       <url>http://cyberleninka.ru/article/n/postkonversionnaya-asistoliya-zheludochkov-serdtsa-u-bolnyh-infarktom-miokarda-i-vozmozhnosti-ee-profilaktiki</url>\n" +
284
            "\t\t\t\t                    </webresource>\n" +
285
            "\t\t\t\t                    <webresource>\n" +
286
            "\t\t\t\t                       <url>http://cyberleninka.ru/article_covers/5969541.png</url>\n" +
287
            "\t\t\t\t                    </webresource>\n" +
288
            "\t\t\t                  </instance>\n" +
289
            "\t\t                </children>\n" +
290
            "\t\t             </oaf:result>\n" +
291
            "            </oaf:entity>\n" +
292
            "         </metadata>\n" +
293
            "      </result>\n" +
294
            "\t\t\t\t\t\t</results>\n" +
295
            "\t  <browseResults>\n" +
296
            "\t\t\t</browseResults>\n" +
297
            "</response>";
298
    @Test
299
    public void oafWithDoi2PublicationTest() throws Exception, ParserConfigurationException, SAXException, XPathExpressionException, IOException, TransformerException {
300
        Result result = OafParser.oaf2Result(publicationWithDoiOaf);
301
        Assert.assertNull(result.getAccessRights());
302
        Assert.assertEquals("EMBARGO",result.getBestLicense());
303
        Assert.assertEquals("infrastruct_::openaire", result.getCollectedFrom());
304
        Assert.assertNotNull(result.getDoi());
305
        Assert.assertEquals("oai:cyberleninka.ru:article/5969541",result.getOai());
306
        Assert.assertEquals("od______2806::d19b8560e0c4ce1f25dd9d661f4b2b46",result.getOpenaireId());
307
        Assert.assertEquals("pmc_test",result.getPmcid());
308
        Assert.assertEquals(ClaimUtils.PUBLICATION, result.getResultType());
309
        Assert.assertEquals("ПОСТКОНВЕРСИОННАЯ АСИСТОЛИЯ ЖЕЛУДОЧКОВ СЕРДЦА У БОЛЬНЫХ ИНФАРКТОМ МИОКАРДА И ВОЗМОЖНОСТИ ЕЕ ПРОФИЛАКТИКИ",result.getTitle());
310

  
311
        Assert.assertEquals("http://dx.doi.org/doi_test", result.getExternalUrl());
312
        Assert.assertEquals("2099-12-31",result.getEmbargoEndDate());
313
        Assert.assertEquals("orcidworkid_test", result.getOrcidworkid());
314
        Assert.assertEquals("doi_test", result.getDoi());
315

  
316

  
317
    }
318
    private String datasetOaf = "<response>\n" +
319
            "\t  <header>\n" +
320
            "\t\t    <query>(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (objidentifier exact od______2806::d19b8560e0c4ce1f25dd9d661f4b2b46)</query>\n" +
321
            "\t\t\t\t  <locale>en_GB</locale>\t\n" +
322
            "\t\t\t\t\t<size>10</size>\n" +
323
            "\t\t\t   <page>1</page>\n" +
324
            "\t\t\t   <total>1</total>\n" +
325
            "\t\t\t\t\t</header>\n" +
326
            "\t  <results>\n" +
327
            "\t\t\t\t\t\t\t\t\t<result xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
328
            "              xmlns:dri=\"http://www.driver-repository.eu/namespace/dri\"\n" +
329
            "              xmlns:oaf=\"http://namespace.openaire.eu/oaf\">\n" +
330
            "         <header>\n" +
331
            "            <dri:objIdentifier>od______2806::d19b8560e0c4ce1f25dd9d661f4b2b46</dri:objIdentifier>\n" +
332
            "            <dri:dateOfCollection>2016-02-02T08:07:14Z</dri:dateOfCollection>\n" +
333
            "         </header>\n" +
334
            "         <metadata>\n" +
335
            "            <oaf:entity xsi:schemaLocation=\"http://namespace.openaire.eu/oaf https://www.openaire.eu/schema/0.3/oaf-0.3.xsd\">\n" +
336
            "\t\t             <oaf:result>\n" +
337
            "                  <title classid=\"main title\" classname=\"main title\" schemeid=\"dnet:dataCite_title\"\n" +
338
            "                         schemename=\"dnet:dataCite_title\">ПОСТКОНВЕРСИОННАЯ АСИСТОЛИЯ ЖЕЛУДОЧКОВ СЕРДЦА У БОЛЬНЫХ ИНФАРКТОМ МИОКАРДА И ВОЗМОЖНОСТИ ЕЕ ПРОФИЛАКТИКИ</title>\n" +
339
            "                  <dateofacceptance>2010-01-01</dateofacceptance>\n" +
340
            "                  <resulttype classid=\"dataset\" classname=\"dataset\" schemeid=\"dnet:result_typologies\"\n" +
341
            "                              schemename=\"dnet:result_typologies\"/>\n" +
342
            "                  <country classid=\"\" classname=\"\" schemeid=\"\" schemename=\"\"/>\n" +
343
            "                  <relevantdate classid=\"\" classname=\"\" schemeid=\"\" schemename=\"\"/>\n" +
344
            "                  <embargoenddate>2099-12-31</embargoenddate>\n" +
345
            "                  <originalId>oai:cyberleninka.ru:article/5969541</originalId>\n" +
346
            "                  <collectedfrom name=\"CyberLeninka - Russian open access scientific library\"\n" +
347
            "                                 id=\"opendoar____::c0f971d8cd24364f2029fcb9ac7b71f5\"/>\n" +
348
            "                  <pid classid=\"oai\" classname=\"oai\" schemeid=\"dnet:pid_types\"\n" +
349
            "                       schemename=\"dnet:pid_types\">oai:cyberleninka.ru:article/5969541</pid>\n" +
350
            "                  <pid classid=\"doi\" classname=\"doi\" schemeid=\"dnet:pid_types\"\n" +
351
            "                       schemename=\"dnet:pid_types\">doi_test</pid>\n" +
352
            "                  <pid classid=\"pmc\" classname=\"pmc\" schemeid=\"dnet:pid_types\"\n" +
353
            "                       schemename=\"dnet:pid_types\">pmc_test</pid>\n" +
354
            "                  <pid classid=\"orcidworkid\" classname=\"orcidworkid\" schemeid=\"dnet:pid_types\"\n" +
355
            "                       schemename=\"dnet:pid_types\">orcidworkid_test</pid>\n" +
356
            "                  <bestlicense classid=\"EMBARGO\" classname=\"Open Access\" schemeid=\"dnet:access_modes\"\n" +
357
            "                               schemename=\"dnet:access_modes\"/>\n" +
358
            "\t\t                <children>\n" +
359
            "\t\t\t                  <instance id=\"opendoar____::c0f971d8cd24364f2029fcb9ac7b71f5\">\n" +
360
            "\t\t\t                     <licence classid=\"OPEN\" classname=\"Open Access\" schemeid=\"dnet:access_modes\"\n" +
361
            "                                 schemename=\"dnet:access_modes\"/>\n" +
362
            "                        <instancetype classid=\"0001\" classname=\"Article\" schemeid=\"dnet:publication_resource\"\n" +
363
            "                                      schemename=\"dnet:publication_resource\"/>\n" +
364
            "                        <hostedby name=\"CyberLeninka - Russian open access scientific library\"\n" +
365
            "                                  id=\"opendoar____::c0f971d8cd24364f2029fcb9ac7b71f5\"/>\n" +
366
            "\t\t\t\t                    <webresource>\n" +
367
            "\t\t\t\t                       <url>http://cyberleninka.ru/article/n/postkonversionnaya-asistoliya-zheludochkov-serdtsa-u-bolnyh-infarktom-miokarda-i-vozmozhnosti-ee-profilaktiki</url>\n" +
368
            "\t\t\t\t                    </webresource>\n" +
369
            "\t\t\t\t                    <webresource>\n" +
370
            "\t\t\t\t                       <url>http://cyberleninka.ru/article_covers/5969541.png</url>\n" +
371
            "\t\t\t\t                    </webresource>\n" +
372
            "\t\t\t                  </instance>\n" +
373
            "\t\t                </children>\n" +
374
            "\t\t             </oaf:result>\n" +
375
            "            </oaf:entity>\n" +
376
            "         </metadata>\n" +
377
            "      </result>\n" +
378
            "\t\t\t\t\t\t</results>\n" +
379
            "\t  <browseResults>\n" +
380
            "\t\t\t</browseResults>\n" +
381
            "</response>";
382

  
383

  
384
    @Test
385
    public void oaf2DatasetTest() throws Exception, ParserConfigurationException, SAXException, XPathExpressionException, IOException, TransformerException {
386
        Result result = OafParser.oaf2Result(datasetOaf);
387

  
388
        Assert.assertNull(result.getAccessRights());
389
        Assert.assertEquals("EMBARGO",result.getBestLicense());
390
        Assert.assertEquals("infrastruct_::openaire", result.getCollectedFrom());
391
        Assert.assertEquals("oai:cyberleninka.ru:article/5969541",result.getOai());
392
        Assert.assertEquals("od______2806::d19b8560e0c4ce1f25dd9d661f4b2b46",result.getOpenaireId());
393
        Assert.assertEquals("pmc_test",result.getPmcid());
394
        Assert.assertEquals(ClaimUtils.DATASET, result.getResultType());
395
        Assert.assertEquals("ПОСТКОНВЕРСИОННАЯ АСИСТОЛИЯ ЖЕЛУДОЧКОВ СЕРДЦА У БОЛЬНЫХ ИНФАРКТОМ МИОКАРДА И ВОЗМОЖНОСТИ ЕЕ ПРОФИЛАКТИКИ",result.getTitle());
396
        Assert.assertEquals("xml", result.getRecordFormat());
397

  
398
        Assert.assertEquals("http://dx.doi.org/doi_test", result.getExternalUrl());
399
        Assert.assertEquals("2099-12-31",result.getEmbargoEndDate());
400
        Assert.assertEquals("orcidworkid_test", result.getOrcidworkid());
401
        Assert.assertEquals("doi_test", result.getDoi());
402

  
403
    }
404

  
405

  
406

  
407
    private String projectOaf = "<response>\n" +
408
            "\t  <header>\n" +
409
            "\t\t    <query>((deletedbyinference = false) AND (oaftype exact project)) and (projectcode exact 314867)</query>\n" +
410
            "\t\t\t\t  <locale>en_GB</locale>\t\n" +
411
            "\t\t\t\t\t<size>10</size>\n" +
412
            "\t\t\t   <page>1</page>\n" +
413
            "\t\t\t   <total>1</total>\n" +
414
            "\t\t\t\t\t</header>\n" +
415
            "\t  <results>\n" +
416
            "\t\t\t\t\t\t\t\t\t<result xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
417
            "              xmlns:dri=\"http://www.driver-repository.eu/namespace/dri\"\n" +
418
            "              xmlns:oaf=\"http://namespace.openaire.eu/oaf\">\n" +
419
            "         <header>\n" +
420
            "            <dri:objIdentifier>corda_______::073d0a668885f9e7292a5d9c323e4a20</dri:objIdentifier>\n" +
421
            "            <dri:dateOfCollection>2015-08-24</dri:dateOfCollection>\n" +
422
            "            <counters>\n" +
423
            "\t              <counter_participation value=\"8\"/>\n" +
424
            "               <counter_contactPerson value=\"1\"/>\n" +
425
            "\t           </counters>\n" +
426
            "         </header>\n" +
427
            "         <metadata>\n" +
428
            "            <oaf:entity xsi:schemaLocation=\"http://namespace.openaire.eu/oaf https://www.openaire.eu/schema/0.3/oaf-0.3.xsd\">\n" +
429
            "\t\t             <oaf:project>\n" +
430
            "\t\t\t               <code>314867</code>\n" +
431
            "                  <acronym>ADAW</acronym>\n" +
432
            "                  <title>Saponification pre-treatment and biosensors based control system for slaughterhouse waste anaerobic digestion improvement</title>\n" +
433
            "                  <startdate>2013-03-01</startdate>\n" +
434
            "                  <enddate>2015-02-28</enddate>\n" +
435
            "                  <callidentifier>FP7-SME-2012</callidentifier>\n" +
436
            "                  <ecsc39>false</ecsc39>\n" +
437
            "                  <oamandatepublications>false</oamandatepublications>\n" +
438
            "                  <contracttype classid=\"BSG\" classname=\"Research for the benefit of specific groups\"\n" +
439
            "                                schemeid=\"ec:FP7contractTypes\"\n" +
440
            "                                schemename=\"ec:FP7contractTypes\"/>\n" +
441
            "                  <fundingtree>\n" +
442
            "                     <funder>\n" +
443
            "                        <id>ec__________::EC</id>\n" +
444
            "                        <shortname>EC</shortname>\n" +
445
            "                        <name>European Commission</name>\n" +
446
            "                        <jurisdiction>EU</jurisdiction>\n" +
447
            "                     </funder>\n" +
448
            "                     <funding_level_2>\n" +
449
            "                        <id>ec__________::EC::FP7::SP4::SME</id>\n" +
450
            "                        <description>Research for the benefit of SMEs</description>\n" +
451
            "                        <name>SME</name>\n" +
452
            "                        <class>ec:program</class>\n" +
453
            "                        <parent>\n" +
454
            "                           <funding_level_1>\n" +
455
            "                              <id>ec__________::EC::FP7::SP4</id>\n" +
456
            "                              <description>SP4-Capacities</description>\n" +
457
            "                              <name>SP4</name>\n" +
458
            "                              <class>ec:specificprogram</class>\n" +
459
            "                              <parent>\n" +
460
            "                                 <funding_level_0>\n" +
461
            "                                    <id>ec__________::EC::FP7</id>\n" +
462
            "                                    <description>SEVENTH FRAMEWORK PROGRAMME</description>\n" +
463
            "                                    <name>FP7</name>\n" +
464
            "                                    <parent/>\n" +
465
            "                                    <class>ec:frameworkprogram</class>\n" +
466
            "                                 </funding_level_0>\n" +
467
            "                              </parent>\n" +
468
            "                           </funding_level_1>\n" +
469
            "                        </parent>\n" +
470
            "                     </funding_level_2>\n" +
471
            "                  </fundingtree>\n" +
472
            "                  <websiteurl/>\n" +
473
            "                  <keywords/>\n" +
474
            "                  <duration/>\n" +
475
            "                  <ecarticle29_3/>\n" +
476
            "                  <subjects classid=\"\" classname=\"\" schemeid=\"\" schemename=\"\"/>\n" +
477
            "                  <originalId>corda_______::314867</originalId>\n" +
478
            "                  <collectedfrom name=\"CORDA - COmmon Research DAta Warehouse\"\n" +
479
            "                                 id=\"openaire____::b30dac7baac631f3da7c2bb18dd9891f\"/>\n" +
480
            "                  <pid classid=\"\" classname=\"\" schemeid=\"\" schemename=\"\"/>\n" +
481
            "                  <datainfo>\n" +
482
            "                     <inferred>false</inferred>\n" +
483
            "                     <deletedbyinference>false</deletedbyinference>\n" +
484
            "                     <trust>0.9</trust>\n" +
485
            "                     <inferenceprovenance/>\n" +
486
            "                     <provenanceaction classid=\"sysimport:crosswalk:entityregistry\"\n" +
487
            "                                       classname=\"sysimport:crosswalk:entityregistry\"\n" +
488
            "                                       schemeid=\"dnet:provenanceActions\"\n" +
489
            "                                       schemename=\"dnet:provenanceActions\"/>\n" +
490
            "                  </datainfo>\n" +
491
            "\t\t                <rels>\n" +
492
                                    "<rel inferred=\"true\" trust=\"0.9\" inferenceprovenance=\"\" provenanceaction=\"UNKNOWN\"><to class=\"hasContact\" scheme=\"dnet:project_person_relations\" type=\"person\">dedup_wf_001::2b56ecf626015b620e97915cb0686ca1</to><fax> </fax><email>email@gmail.com</email><phone> </phone><fullname>Contact, Name</fullname></rel>" +
493
            "\t\t                </rels>\n" +
494
            "\t\t                <children>\n" +
495
            "\t\t  </children>\n" +
496
            "\t\t             </oaf:project>\n" +
497
            "\n" +
498
            "            </oaf:entity>\n" +
499
            "         </metadata>\n" +
500
            "      </result>\n" +
501
            "\t\t\t\t\t\t</results>\n" +
502
            "\t  <browseResults>\n" +
503
            "\t\t\t</browseResults>\n" +
504
            "</response>";
505

  
506

  
507

  
508
    @Test
509
    public void oaf2ProjectTest() throws Exception {
510
        Project project = OafParser.oaf2Project(projectOaf);
511

  
512
        Assert.assertEquals("corda_______::073d0a668885f9e7292a5d9c323e4a20", project.getOpenaireId());
513
        Assert.assertEquals("ADAW", project.getAcronym());
514
        Assert.assertEquals("ec__________::EC", project.getFunderId());
515
        Assert.assertEquals("EC", project.getFunderShortName());
516
        Assert.assertEquals("European Commission", project.getFunderName());
517
        Assert.assertEquals("Saponification pre-treatment and biosensors based control system for slaughterhouse waste anaerobic digestion improvement", project.getName());
518
        Assert.assertEquals(1, project.getContactEmails().size());
519
        Assert.assertEquals("email@gmail.com", project.getContactEmails().get(0));
520
    }
521

  
522

  
523
}
modules/uoa-claims/claims-demo/src/test/java/eu/dnetlib/data/claims/migration/parser/DMFParserTest.java
1
package eu.dnetlib.data.claims.migration.parser;
2

  
3
import eu.dnetlib.data.claims.migration.entity.Context;
4
import eu.dnetlib.data.claims.migration.entity.Result;
5
import eu.dnetlib.data.claims.migration.handler.DMFContextHandler;
6
import org.junit.Assert;
7
import org.junit.Test;
8
import org.xml.sax.SAXException;
9

  
10
import javax.xml.parsers.ParserConfigurationException;
11
import javax.xml.xpath.XPathExpressionException;
12
import java.io.IOException;
13

  
14
/**
15
 * Created by kiatrop on 23/2/2016.
16
 */
17
public class DMFParserTest {
18

  
19
    private String publicationDmf= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
20
            "<record xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:prov=\"http://www.openarchives.org/OAI/2.0/provenance\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:dri=\"http://www.driver-repository.eu/namespace/dri\" xmlns:dr=\"http://www.driver-repository.eu/namespace/dr\" xmlns:oaf=\"http://namespace.openaire.eu/oaf\">\n" +
21
            "  <header xmlns=\"http://namespace.openaire.eu/\">\n" +
22
            "    <dri:objIdentifier>crossref____::47593e13b24bcdd0f3d5573499f1d3a9</dri:objIdentifier>\n" +
23
            "    <dri:recordIdentifier>10.1088/0004-637X/761/1/34</dri:recordIdentifier>\n" +
24
            "    <dri:dateOfCollection></dri:dateOfCollection>\n" +
25
            "    <dri:mdFormat></dri:mdFormat>\n" +
26
            "    <dri:mdFormatInterpretation></dri:mdFormatInterpretation>\n" +
27
            "    <dri:repositoryId></dri:repositoryId>\n" +
28
            "    <dr:objectIdentifier></dr:objectIdentifier>\n" +
29
            "    <dr:dateOfCollection>2014-10-10T14:59:49+00:00</dr:dateOfCollection>\n" +
30
            "    <oaf:datasourceprefix>crossref____</oaf:datasourceprefix>\n" +
31
            "  </header>\n" +
32
            "  <metadata xmlns=\"http://namespace.openaire.eu/\">\n" +
33
            "      <dc:dateAccepted>2012-01-01T00:00:00Z</dc:dateAccepted>\n" +
34
            "             <dc:identifier>http://stacks.iop.org/0004-637X/761/i=1/a=34?key=crossref.d14dae8ac205453af63561a69c108e13</dc:identifier>\n" +
35
            "          <dc:title>A THREE-DIMENSIONAL VIEW OF THE REMNANT OF NOVA PERSEI 1901 (GK Per)</dc:title>\n" +
36
            "             <oaf:collectedDatasourceid>openaire____::crossref</oaf:collectedDatasourceid>\n" +
37
            "       <oaf:accessrights></oaf:accessrights>\n" +
38
            "       <oaf:hostedBy name=\"Unknown Repository\" id=\"openaire____::1256f046-bf1f-4afc-8b47-d0b147148b18\"/>\n" +
39
            "    <oaf:collectedFrom name=\"Crossref\" id=\"openaire____::crossref\" />\n" +
40
            "          \n" +
41
            "     <dc:creator>Liimets, T.</dc:creator>\n" +
42
            "     <dc:creator>Corradi, R. L. M.</dc:creator>\n" +
43
            "     <dc:creator>Santander-Garc&#237;a, M.</dc:creator>\n" +
44
            "     <dc:creator>Villaver, E.</dc:creator>\n" +
45
            "     <dc:creator>Rodr&#237;guez-Gil, P.</dc:creator>\n" +
46
            "     <dc:creator>Verro, K.</dc:creator>\n" +
47
            "     <dc:creator>Kolka, I.</dc:creator>\n" +
48
            " \n" +
49
            "        <dc:identifier identifierType=\"doi\">10.1088/0004-637X/761/1/34</dc:identifier>\n" +
50
            //"        <dr:CobjIdentifier>10.1088/0004-637X/761/1/34</dr:CobjIdentifier>\n" +
51
            "       <dc:identifier identifierType=\"orcidworkid\">0000-0002-1112-1292-12694010</dc:identifier>\n" +
52
            //"        <dr:CobjIdentifier>0000-0002-1112-1292-12694010</dr:CobjIdentifier>" +
53
            "  </metadata>\n" +
54
            "</record>";
55

  
56
    @Test
57
    public void dmf2PublicationTest() throws IOException, SAXException, ParserConfigurationException {
58
        Result result = DMFParser.dmf2Result(publicationDmf);
59

  
60
        Assert.assertNull(result.getAccessRights());
61
        Assert.assertNull(result.getBestLicense());
62
        Assert.assertEquals("openaire____::crossref", result.getCollectedFrom());
63
        Assert.assertEquals("10.1088/0004-637X/761/1/34", result.getDoi());
64
        Assert.assertEquals("0000-0002-1112-1292-12694010", result.getOrcidworkid());
65
        Assert.assertNull(result.getOai());
66
        Assert.assertEquals("crossref____::47593e13b24bcdd0f3d5573499f1d3a9", result.getOpenaireId());
67
        Assert.assertNull(result.getPmcid());
68
        Assert.assertEquals("A THREE-DIMENSIONAL VIEW OF THE REMNANT OF NOVA PERSEI 1901 (GK Per)", result.getTitle());
69
        Assert.assertEquals("xml", result.getRecordFormat());
70
        Assert.assertEquals("http://dx.doi.org/10.1088/0004-637X/761/1/34", result.getExternalUrl());
71
        Assert.assertNull(result.getEmbargoEndDate());
72

  
73
    }
74

  
75
    private  String contextDmf = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
76
            "<record xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:prov=\"http://www.openarchives.org/OAI/2.0/provenance\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:dri=\"http://www.driver-repository.eu/namespace/dri\" xmlns:dr=\"http://www.driver-repository.eu/namespace/dr\" xmlns:oaf=\"http://namespace.openaire.eu/oaf\">\n" +
77
            "  <header xmlns=\"http://namespace.openaire.eu/\">\n" +
78
            "    <dri:objIdentifier>od______1031::ec6940963d90d1e275970ed2a0ac2508</dri:objIdentifier>\n" +
79
            "    <dri:recordIdentifier>od______1031::ec6940963d90d1e275970ed2a0ac2508</dri:recordIdentifier>\n" +
80
            "    <dri:dateOfCollection></dri:dateOfCollection>\n" +
81
            "    <dri:mdFormat></dri:mdFormat>\n" +
82
            "    <dri:mdFormatInterpretation></dri:mdFormatInterpretation>\n" +
83
            "    <dri:repositoryId></dri:repositoryId>\n" +
84
            "    <dr:objectIdentifier></dr:objectIdentifier>\n" +
85
            "    <dr:dateOfCollection>2015-01-22T11:40:51+00:00</dr:dateOfCollection>\n" +
86
            "    <oaf:datasourceprefix>openaire____</oaf:datasourceprefix>\n" +
87
            "  </header>\n" +
88
            "  <metadata xmlns=\"http://namespace.openaire.eu/\">\n" +
89
            "                     <oaf:collectedDatasourceid></oaf:collectedDatasourceid>\n" +
90
            "          <oaf:hostedBy name=\"\" id=\"\"/>\n" +
91
            "    <oaf:collectedFrom name=\"\" id=\"\" />\n" +
92
            "          \n" +
93
            "     <oaf:concept id=\"egi::country::gr\" />\n" +
94
            "\n" +
95
            "\n" +
96
            "\n" +
97
            "  </metadata>\n" +
98
            "</record>";
99

  
100
    @Test
101
    public void dmf2ContextTest() throws IOException, SAXException, ParserConfigurationException, XPathExpressionException {
102
        DMFParser dmfParser= new DMFParser();
103
        DMFContextHandler dmfContextHandler = new DMFContextHandler();
104
        Context context = dmfContextHandler.extractContextFromDMF(contextDmf);
105

  
106
        Assert.assertEquals("egi::country::gr", context.getOpenaireId());
107
        Assert.assertEquals("EGI> EGI Countries> Greece", context.getTitle());
108
    }
109

  
110
}
modules/uoa-claims/claims-demo/src/test/java/eu/dnetlib/data/claims/migration/parser/RelationParserTest.java
1
package eu.dnetlib.data.claims.migration.parser;
2

  
3
import eu.dnetlib.data.claims.migration.entity.Relation;
4
import eu.dnetlib.data.claimsDemo.ClaimUtils;
5
import org.junit.Assert;
6
import org.junit.Test;
7

  
8
/**
9
 * Created by kiatrop on 9/2/2016.
10
 */
11
public class RelationParserTest {
12

  
13
    private final String projectResultXml =
14
            "<RELATIONS>" +
15
                    "<RELATION type='resultProject' source='50|od______2367::63368dc45b69d3eac6bf94b0181b4e64' target='40|corda_______::fe4cbcc8f465c016c034a4f93965074c' />" +
16
                    "</RELATIONS>";
17

  
18
    private final String publicationDatasetXml =
19
            "<RELATIONS>" +
20
                    "<RELATION type='resultResult_publicationdataset_isRelatedTo' source='50|dedup_wf_001::f81ff2795647ddd5756b046c026e22ec' target='50|datacite____::6302a4307468b410343413c04b11453b' />" +
21
                    "</RELATIONS>";
22

  
23
    private final String datasetPublicationXml =
24
            "<RELATIONS>" +
25
                    "<RELATION type='resultResult_datasetpublication_isRelatedTo' source='50|r37b0ad08687::f016cea0f48814bea455804017883872' target='50|crossref____::68178723a3e54b2ab18acb8e2859ddaf' />" +
26
                    "</RELATIONS>";
27

  
28

  
29
    @Test
30
    public void xml2Relation_projectResult_test() {
31
        Relation relation = RelationParser.xml2Relation(projectResultXml);
32
        Assert.assertEquals(relation.getSourceId(), "corda_______::fe4cbcc8f465c016c034a4f93965074c");
33
        Assert.assertEquals(relation.getSourceType(), ClaimUtils.PROJECT);
34
        Assert.assertEquals(relation.getTargetId(), "od______2367::63368dc45b69d3eac6bf94b0181b4e64");
35
        Assert.assertEquals(relation.getTargetType(), ClaimUtils.PUBLICATION);
36
    }
37

  
38
    @Test
39
    public void xml2Relation_publicationDataset_test() {
40
        Relation relation = RelationParser.xml2Relation(publicationDatasetXml);
41
        Assert.assertEquals(relation.getSourceId(), "datacite____::6302a4307468b410343413c04b11453b");
42
        Assert.assertEquals(relation.getSourceType(), ClaimUtils.DATASET);
43
        Assert.assertEquals(relation.getTargetId(), "dedup_wf_001::f81ff2795647ddd5756b046c026e22ec");
44
        Assert.assertEquals(relation.getTargetType(), ClaimUtils.PUBLICATION);
45
    }
46

  
47
    @Test
48
    public void xml2Relation_datasetPublication_test() {
49
        Relation relation = RelationParser.xml2Relation(datasetPublicationXml);
50
        Assert.assertEquals(relation.getSourceId(), "crossref____::68178723a3e54b2ab18acb8e2859ddaf");
51
        Assert.assertEquals(relation.getSourceType(), ClaimUtils.PUBLICATION);
52
        Assert.assertEquals(relation.getTargetId(), "r37b0ad08687::f016cea0f48814bea455804017883872");
53
        Assert.assertEquals(relation.getTargetType(), ClaimUtils.DATASET);
54
    }
55

  
56
}
modules/uoa-claims/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/ClaimValidationException.java
1
package eu.dnetlib.data.claims.migration;
2

  
3
/**
4
 * Created by kiatrop on 21/4/2016.
5
 */
6
public class ClaimValidationException extends Exception {
7

  
8
    public ClaimValidationException() {
9
        super();
10
    }
11

  
12
    public ClaimValidationException(String message, Throwable cause) {
13
        super(message, cause);
14
    }
15

  
16
    public ClaimValidationException(String message) {
17
        super(message);
18
    }
19

  
20
    public ClaimValidationException(Throwable cause) {
21
        super(cause);
22
    }
23

  
24
}
modules/uoa-claims/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Test.java
1
package eu.dnetlib.data.claims.migration;
2

  
3
import eu.dnetlib.data.claims.migration.entity.Project;
4
import eu.dnetlib.data.claims.migration.entity.Result;
5

  
6
import java.util.Calendar;
7

  
8
public class Test {
9

  
10
	public static void main(String[] args) {
11

  
12
		ClaimGenerics<Object, Result> claim = new ClaimGenerics<Object, Result>();
13
		claim.setDate(Calendar.getInstance().getTime());
14
		claim.setId("claimId");
15
		claim.setUserMail("claim mail");
16
		Project project = new Project();
17
		project.setFunderName("EC");
18
		project.setOpenaireId("openaireID1234");
19
		project.setName("PrTitle");
20
		Result result = new Result();
21
		result.setAccessRights("accessRights");
22
		result.setCollectedFrom("collectedFrom");
23
		result.setExternalUrl("external_url");
24
		result.setOpenaireId("openaire_id");
25
		result.setTitle("title");
26
		result.setResultType("type");
27
		result.setMetadataRecord("xmlString");
28
		claim.setBody(project);
29
		claim.setTarget(result);
30
		System.out.println("test");
31
		System.out.println(JsonldBuilder.toJsonld(claim));
32

  
33
	}
34

  
35

  
36
}
modules/uoa-claims/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/ClaimValidation.java
1
package eu.dnetlib.data.claims.migration;
2

  
3
import eu.dnetlib.data.claims.migration.entity.*;
4
import eu.dnetlib.data.claimsDemo.ClaimUtils;
5
import org.apache.log4j.Logger;
6

  
7
import java.io.BufferedWriter;
8
import java.io.FileWriter;
9
import java.io.PrintWriter;
10

  
11
/**
12
 * Created by argirok on 21/1/2016.
13
 */
14
public class ClaimValidation {
15
    private PrintWriter out;
16
    String pathToSaveReport = null;
17

  
18
    private static Logger logger = Logger.getLogger(ClaimValidation.class);
19

  
20
    /*
21
    Claim:
22
    Mandatory Fields : id, sourceType,targetType, User e-mail, Date, Target, Source
23

  
24
    */
25
    public  boolean validateClaim(Claim claim){
26
        logger.info("Validating...");
27
        boolean isValid=true;
28
        try {
29
            out = new PrintWriter(new BufferedWriter(new FileWriter(pathToSaveReport+"/validationFile.txt", true)));
30

  
31
        } catch (Exception e) {
32
            out = null;
33
            logger.error("Couldn't write to file " + "validationFile.txt", e);
34
        }
35

  
36
              if(claim==null){
37
                isValid=false;
38
                if(out!=null) {
39
                    out.println("Claim invalid (null)...");
40
                }
41
                logger.warn("Claim invalid (null)...");
42
//            }else if(claim.getId()==null||claim.getId().isEmpty()){
43
//                isValid=false;
44
//                 out.println("Claim invalid  (id)..." );
45
             }else if(claim.getTargetType()==null||claim.getTargetType().isEmpty()){
46
                isValid=false;
47
                if(out!=null) {
48
                    out.println("Claim invalid (target type): " + claim.getId());
49
                }
50
                logger.warn("Claim invalid (target type): "+claim.getId());
51

  
52
            }else if(claim.getSourceType()==null||claim.getSourceType().isEmpty()){
53
                isValid=false;
54
                if(out!=null) {
55
                    out.println("Claim invalid (source type): " + claim.getId());
56
                }
57
                logger.warn("Claim invalid (source type): "+claim.getId());
58

  
59
            }else if(claim.getDate()==null){
60
                isValid=false;
61
                if(out!=null) {
62
                    out.println("Claim invalid (date): " + claim.getId());
63
                }
64
                logger.warn("Claim invalid (date): "+claim.getId());
65

  
66
            }else if(claim.getUserMail()==null||claim.getUserMail().isEmpty()){
67
                isValid=false;
68
                 if(out!=null) {
69
                     out.println("Claim invalid (mail): " + claim.getId());
70
                 }
71
                logger.warn("Claim invalid (mail): "+claim.getId());
72

  
73
            }else if(claim.getSource()==null || claim.getTarget()==null){
74
                isValid=false;
75
                 if(out!=null) {
76
                     out.println("Result invalid : " + claim.getId());
77
                 }
78
                logger.warn("Result invalid : "+claim.getId());
79

  
80
            }else if(claim.getSource()==null || claim.getTarget()==null){
81
                isValid=false;
82
                 if(out!=null) {
83
                     out.println("Result invalid : " + claim.getId());
84
                 }
85
                logger.warn("Result invalid : "+claim.getId());
86

  
87
            }else if(claim.getSource().getOpenaireId()!=null && claim.getTarget().getOpenaireId()!=null && claim.getSource().getOpenaireId().equals(claim.getTarget().getOpenaireId())){
88
                isValid=false;
89
                 if(out!=null) {
90
                     out.println("Claim invalid (source == target): " + claim.getId());
91
                 }
92
                logger.warn("Claim invalid (source == target): "+claim.getId());
93

  
94
            }else{
95
                boolean sourceIsValid=validateByType(claim.getSource(),claim.getSourceType(),claim.getId());
96
                boolean targetIsValid=validateByType(claim.getTarget(),claim.getTargetType(),claim.getId());
97
                isValid= isValid&&sourceIsValid&&targetIsValid;
98
                 if(!isValid){
99
                     if(out!=null) {
100
                         out.println("Claim invalid (source /target): " + claim.getId() + "\n");
101
                     }
102
                     logger.warn("Claim invalid (source /target): "+claim.getId()+"\n");
103
                 }
104
            }
105
            if(out!=null) {
106
                out.close();
107
            }
108

  
109
        return isValid;
110
    }
111
    /*
112
    Project:
113
    Mandatory Fields : id, type, Collected from
114

  
115
     */
116
    public  boolean validateResult(Result result, String claimId){
117
        boolean isValid=true;
118
            if(result==null){
119
                isValid=false;
120
                out.println("Result invalid (null): - claimId:"+claimId);
121
//            }else if(result.getOpenaireId()==null||result.getOpenaireId().isEmpty()){
122
//                isValid=false;
123
//                out.println("Result invalid (Id): - claimId:"+claimId);
124
            }else if(result.getResultType()==null||result.getResultType().isEmpty()){
125
                isValid=false;
126
                out.println("Result invalid (Type): "+result.getOpenaireId()+"- claimId:"+claimId);
127
            }/*
128
            //http://services.openaire.eu:8380/search/search?action=search&sTransformer=results_openaire&query=%28%28%28deletedbyinference+%3D+false%29+AND+%28oaftype+exact+result%29%29+and+%28%28resulttypeid+exact+publication%29+or+%28resulttypeid+exact+dataset%29%29%29+and+%28%28objIdentifier+
129
            //exact+od______1389%3A%3A6ba133c8460d5a67dfb18f34cc5303fb%29+or+%28resultdupid+exact+od______1389%3A%3A6ba133c8460d5a67dfb18f34cc5303fb%29%29&size=10&locale=en_GB
130
            //There are resuts with no title
131
            //so I am
132
            else if(result.getTitle()==null||result.getTitle().isEmpty()){
133
                isValid=false;
134
                out.println("Result invalid (title): "+result.getOpenaireId()+"- claimId:"+claimId);
135
            }*/else if(result.getCollectedFrom()==null||result.getCollectedFrom().isEmpty()){
136
                isValid=false;
137
                out.println("Result invalid (collectedFrom) : "+result.getOpenaireId()+"- claimId:"+claimId);
138
            }else if (result.getCollectedFrom().equals(ClaimUtils.COLLECTED_FROM_OPENAIRE) && result.getOpenaireId()==null) {
139
                isValid = false;
140
                out.println("Result invalid (Openaire - no id): - claimId:" + claimId);
141
            }else if ((result.getCollectedFrom().equals(ClaimUtils.COLLECTED_FROM_DATACITE)|| result.getCollectedFrom().equals(ClaimUtils.COLLECTED_FROM_CROSSREF) ) && result.getDoi()==null) {
142
                isValid = false;
143
                out.println("Result invalid (Crossref/Datacite - no doi): - claimId:" + claimId);
144
            }else if (result.getCollectedFrom().equals(ClaimUtils.COLLECTED_FROM_ORCID) && result.getOrcidworkid()==null) {
145
                isValid = false;
146
                out.println("Result invalid (Orcid - no work id): - claimId:" + claimId);
147
            }
148

  
149
        return isValid;
150
    }
151
    /*
152
    Project:
153
    Mandatory Fields : id, name
154

  
155
     */
156
    public  boolean validateProject(Project project, String claimId){
157
        boolean isValid=true;
158
             if(project==null){
159
                isValid=false;
160
                out.println("Project invalid (null): - claimId:"+claimId);
161
            }else if(project.getOpenaireId()==null||project.getOpenaireId().isEmpty()){
162
                isValid=false;
163
                out.println("Project invalid (id): - claimId:"+claimId);
164
            }else if((project.getName()==null||project.getName().isEmpty())&&(project.getAcronym()==null||project.getAcronym().isEmpty())){
165
                isValid=false;
166
                out.println("Project invalid (name/acronym): "+project.getOpenaireId()+"- claimId:"+claimId);
167
            }else if(project.getFunderId()==null||project.getFunderId().isEmpty()){
168
                isValid=false;
169
                out.println("Project invalid (funder id): "+project.getOpenaireId()+"- claimId:"+claimId);
170
            }
171
            else if(project.getFunderName()==null||project.getFunderName().isEmpty()){
172
                isValid=false;
173
                out.println("Project invalid (funder name): "+project.getOpenaireId()+"- claimId:"+claimId);
174
            }
175

  
176
        return isValid;
177
    }
178
    /*
179
    Context:
180
    Mandatory Fields : id, title
181

  
182
     */
183
    public  boolean validateContext(Context context, String claimId){
184
        boolean isValid=true;
185
            if(context==null){
186
                isValid=false;
187
                out.println("Context invalid (null): - claimId:"+claimId);
188
            }else if(context.getOpenaireId()==null||context.getOpenaireId().isEmpty()){
189
                isValid=false;
190
                out.println("Context invalid (id): - claimId:"+claimId);
191
            }/*
192
            //This is commented since There isn't a way to fill this field right now.
193
            else if(context.getTitle()==null||context.getTitle().isEmpty()){
194
                isValid=false;
195
                out.println("Context invalid : "+context.getOpenaireId()+"- claimId:"+claimId);
196
            }*/
197
        return isValid;
198
    }
199
    private boolean validateByType(OpenaireEntity entity,String type , String claimId ){
200
        //TODO add more types (e.g. patends) when they are available
201
        if(type.equals(ClaimUtils.PUBLICATION)||type.equals(ClaimUtils.DATASET)){
202
            return validateResult((Result)entity,claimId);
203
        } else if(type.equals(ClaimUtils.CONTEXT)){
204
            return validateContext((Context)entity,claimId);
205
        }else if(type.equals(ClaimUtils.PROJECT)){
206
            return validateProject((Project)entity,claimId);
207
        }else{
208
            if(entity.getOpenaireId()!=null){
209
                out.println("Entity invalid type ("+type+"):"+entity.getOpenaireId()+" - claimId:"+claimId);
210
            }else {
211
                out.println("Entity invalid type (" + type + "): - claimId:" + claimId);
212
            }
213
        }
214
        return false;
215
    }
216

  
217
    public static boolean validateCollectedFrom(String collectedFrom) throws ClaimValidationException {
218
        //TODO add more collected from when they are available
219
        if (collectedFrom==null || collectedFrom.isEmpty()) {
220
            logger.error("CollectedFrom field of source and/or target is null or empty");
221
            throw new ClaimValidationException("CollectedFrom field of source and/or target cannot be empty.");
222

  
223
        } else if (!collectedFrom.equals(ClaimUtils.OPENAIRE) &&
224
                !collectedFrom.equals(ClaimUtils.DATACITE) &&
225
                !collectedFrom.equals(ClaimUtils.CROSSREF) &&
226
                !collectedFrom.equals(ClaimUtils.ORCID)) {
227
            logger.error("CollectedFrom field of source and/or target is invalid. Value is:"+collectedFrom);
228
            throw new ClaimValidationException("CollectedFrom field of source and/or target is invalid. The allowed " +
229
                    "types are: " + ClaimUtils.OPENAIRE + ", " + ClaimUtils.DATACITE
230
                    + ", " + ClaimUtils.CROSSREF + ", " + ClaimUtils.ORCID +".");
231

  
232

  
233
        }
234

  
235
        return true;
236
    }
237

  
238
    public static boolean validateType(String type)  throws ClaimValidationException {
239
        if (type == null || type.isEmpty()) {
240
            throw new ClaimValidationException("The type of source and/or target cannot be empty.");
241

  
242
        } else if (!type.equals(ClaimUtils.PUBLICATION) && !type.equals(ClaimUtils.DATASET) &&
243
                !type.equals(ClaimUtils.CONTEXT) && !type.equals(ClaimUtils.PROJECT)) {
244
            throw new ClaimValidationException("The given type is invalid. The allowed types are: " +
245
                    ClaimUtils.PUBLICATION + ", " + ClaimUtils.DATASET + ", " + ClaimUtils.CONTEXT + ", " +
246
                    ClaimUtils.PROJECT);
247
        }
248

  
249
        return true;
250
    }
251

  
252
//    /*
253
//   Checks if the doi is valid. If it is not  then replaces the existing  DOI with the valid one.
254
//    */
255
//    public static void checkForDOI(Result r) throws Exception {
256
//        if(r.getDOI()==null){
257
//            return ;
258
//        }
259
//         String validDOI=isValidDoi(r.getDOI());
260
//        if(!validDOI.equals(r.getDOI())){
261
//            if(r.getMetadataRecord()!=null) {
262
//                r.setMetadataRecord(r.getMetadataRecord().replace(r.getDOI(), validDOI));
263
//            }
264
//            if(r.getExternalUrl()!=null){
265
//                r.setExternalUrl(r.getExternalUrl().replace(r.getDOI(), validDOI));
266
//            }
267
//            r.setDoi(validDOI);
268
//        }
269
//    }
270
//    public static String isValidDoi(String doi) throws Exception {
271
//        if(doi==null){
272
//            return null;
273
//        }
274
//        try{
275
//            PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("invalid_dois.txt", true)));
276
//            boolean valid=SearchUtils.isDoiValid(doi);
277
//            if(!valid&&(doi.length() - (doi.replace("_", "")).length() > 1)){
278
//                String transformDoi = doi.replace("_", "-");
279
//                valid=SearchUtils.isDoiValid(transformDoi);
280
//                if(valid){
281
//                    Date date= new java.util.Date();
282
//                    out.println(new Timestamp(date.getTime())+" - Invalid doi: "+doi+" replaced with : "+transformDoi);
283
//                    doi=transformDoi;
284
//                }
285
//            }else if(!valid&&(doi.length() - (doi.replace("_", "")).length() == 1)) {
286
//                String transformDoi = doi.replace("_", "-");
287
//                valid=SearchUtils.isDoiValid(transformDoi);
288
//                if(valid){
289
//                    Date date= new java.util.Date();
290
//                    out.println(new Timestamp(date.getTime())+" - Invalid doi: "+doi+" replaced with : "+transformDoi);
291
//                    doi = transformDoi;
292
//                }
293
//            }else if(!valid) {
294
//                String transformDoi =doi.replaceAll("\\p{C}", "");
295
//                valid=SearchUtils.isDoiValid(transformDoi);
296
//                if(valid){
297
//                    Date date= new java.util.Date();
298
//                    out.println(new Timestamp(date.getTime())+" - Invalid doi: "+doi+" replaced with (zero-width-char): "+transformDoi);
299
//                    doi = transformDoi;
300
//                }
301
//            }
302
//            out.close();
303
//        }catch (IOException e) {
304
//            e.printStackTrace();
305
//            System.err.println("Couldn't write to file " + "invalid_dois.txt");
306
//        }
307
//        return doi;
308
//    }
309

  
310

  
311
    public String getPathToSaveReport() {
312
        return pathToSaveReport;
313
    }
314

  
315
    public void setPathToSaveReport(String pathToSaveReport) {
316
        this.pathToSaveReport = pathToSaveReport;
317
    }
318
}
modules/uoa-claims/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/JsonldBuilder.java
1
package eu.dnetlib.data.claims.migration;
2
import java.util.ArrayList;
3
import java.util.List;
4

  
5
import com.google.gson.*;
6
import eu.dnetlib.data.claims.migration.entity.Claim;
7
import eu.dnetlib.data.claims.migration.entity.Result;
8
import org.springframework.web.client.RestTemplate;
9

  
10
import javax.lang.model.type.ArrayType;
11

  
12
public class JsonldBuilder {
13
	
14
	public static String toJsonld(ClaimGenerics<Object, Result> claim) {
15
		Gson gson = new GsonBuilder().setPrettyPrinting().create();
16
		
17
		String retString = gson.toJson(claim);
18
		
19
	/*	final String uri = "http://localhost:9090/oa/buildAndInsertClaim";
20
		 
21
	 
22
	    RestTemplate restTemplate = new RestTemplate();
23
	    String result = restTemplate.postForObject( uri, retString, String.class);
24
	 
25
	    System.out.println(result);
26
	*/	
27
		return retString;
28
//		JsonParser parser = new JsonParser();
29
//		JsonObject obj = parser.parse(retString).getAsJsonObject();
30
//		obj.addProperty("@context", "https://dl.dropboxusercontent.com/u/19168406/oa-openaire.jsonld");
31
//		obj.addProperty("@type", "oa:Annotation");
32
//		return  gson.toJson(obj).toString();
33
	}
34
    public static String toJsonld(Claim claim) {
35
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
36
        String retString = gson.toJson(claim);
37
        return retString;
38
    }
39
    public static String toJsonld(List<Claim> claims) {
40

  
41
        GsonBuilder gsonBuilder = new GsonBuilder();
42
        gsonBuilder.setPrettyPrinting();
43
        gsonBuilder.setDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
44
        Gson gson =gsonBuilder.create();
45

  
46
         String retString = gson.toJson(claims);
47
        return retString;
48
    }
49

  
50
	public static void bulkLoad(List<String> claims) {
51
		
52
		final String uri = "http://localhost:9090/oa/insertClaim";
53
		RestTemplate restTemplate = new RestTemplate();
54
		 
55
		int counter = 0;
56
		
57
		List<String> claimsBatch = new ArrayList<String>();
58
		for (String claim : claims) {
59
			counter ++;
60
			claimsBatch.add(claim);
61
			if (counter % 50 == 0) {
62
				String result = restTemplate.postForObject( uri, "{\"@graph\" : "+claimsBatch.toString()+"}", String.class);
63
				claimsBatch.clear();
64
				System.out.println(result);
65
			}
66
		}
67
		
68
		if (!claimsBatch.isEmpty()) {
69
			String result = restTemplate.postForObject( uri, "{\"@graph\" : "+claimsBatch.toString()+"}", String.class);
70
			claimsBatch.clear();
71
			System.out.println(result);
72
		}
73
	 
74
		
75
//		JsonParser parser = new JsonParser();
76
//		JsonObject obj = parser.parse(retString).getAsJsonObject();
77
//		obj.addProperty("@context", "https://dl.dropboxusercontent.com/u/19168406/oa-openaire.jsonld");
78
//		obj.addProperty("@type", "oa:Annotation");
79
//		return  gson.toJson(obj).toString();
80
	}
81

  
82
}
modules/uoa-claims/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/ClaimGenerics.java
1
package  eu.dnetlib.data.claims.migration;
2

  
3
import com.google.gson.annotations.SerializedName;
4

  
5
import java.util.Date;
6

  
7
public class ClaimGenerics<S extends Object, T extends Object> {
8

  
9
	@SerializedName("@context")
10
	private final String context = "https://dl.dropboxusercontent.com/u/19168406/oa-openaire.jsonld";
11

  
12
	@SerializedName("@type")
13
	private final String type = "oa:Annotation";
14
			
15
	@SerializedName("@id")
16
	private String id;
17
	
18
	@SerializedName("annotatedBy")
19
	private Person person = new Person();
20

  
21
	private Date date;
22
    private String sourceType;
23
    private String targetType;
24

  
25
	@SerializedName("hasTarget")
26
	private T target;
27
	@SerializedName("hasSource")
28
	private S body;
29
	
30
	public T getTarget() {
31
		return target;
32
	}
33

  
34
	public void setTarget(T target) {
35
		this.target = target;
36
	}
37

  
38
	public S getBody() {
39
		return body;
40
	}
41

  
42
	public void setBody(S body) {
43
		this.body = body;
44
	}
45

  
46
	public String getId() {
47
		return id;
48
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff