Project

General

Profile

« Previous | Next » 

Revision 50647

merged r50646 : using misc-utils escaper instead of the one provided by velocity, which is old and does not support all XML entities.

View differences:

modules/dnet-openaireplus-workflows/branches/solr7/src/test/java/eu/dnetlib/msro/openaireplus/api/objects/ResultEntryTest.java
9 9
import com.google.gson.Gson;
10 10
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
11 11
import eu.dnetlib.msro.rmi.MSROException;
12
import org.apache.commons.lang3.StringEscapeUtils;
12 13
import org.apache.velocity.app.VelocityEngine;
13 14
import org.dom4j.Document;
14 15
import org.dom4j.io.OutputFormat;
......
122 123

  
123 124
	@Test
124 125
	public void testAsIndexRecord_json() throws Exception {
125
		final ResultEntry pub = (new Gson()).fromJson(new InputStreamReader(getClass().getResourceAsStream("test_record.json")), ResultEntry.class);
126
		testAsIndexRecord_json("test_record.json");
126 127

  
127
		final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd");
128

  
129
		final Document doc = (new SAXReader()).read(new StringReader(xml));
130

  
131
		final OutputFormat format = OutputFormat.createPrettyPrint();
132

  
133
		final XMLWriter writer = new XMLWriter(System.out, format);
134

  
135
		writer.write(doc);
136

  
137
		/* writer.close(); */
138

  
139 128
	}
140 129

  
141 130
	@Test
142 131
	public void testAsIndexRecord_json_with_greek_chars() throws Exception {
143 132

  
144
		final ResultEntry pub =
145
				(new Gson()).fromJson(new InputStreamReader(getClass().getResourceAsStream("test_record_with_greek_chars.json")), ResultEntry.class);
133
		testAsIndexRecord_json("test_record_with_greek_chars.json");
146 134

  
147
		final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd");
148

  
149
		final Document doc = (new SAXReader()).read(new StringReader(xml));
150

  
151
		final OutputFormat format = OutputFormat.createPrettyPrint();
152

  
153
		final XMLWriter writer = new XMLWriter(System.out, format);
154

  
155
		writer.write(doc);
156

  
157
		/* writer.close(); */
158

  
159 135
	}
160 136

  
161 137
	@Test
162 138
	public void testAsIndexRecord_openaireId() throws Exception {
163 139

  
164
		final ResultEntry pub =
165
				(new Gson()).fromJson(new InputStreamReader(getClass().getResourceAsStream("test_record_openaireId.json")), ResultEntry.class);
140
		testAsIndexRecord_json("test_record_openaireId.json");
166 141

  
167
		final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd");
142
	}
168 143

  
169
		final Document doc = (new SAXReader()).read(new StringReader(xml));
144
	@Test(expected = MSROException.class)
145
	public void testAsIndexRecord_wrongOpenaireId() throws Exception {
170 146

  
171
		final OutputFormat format = OutputFormat.createPrettyPrint();
147
		testAsIndexRecord_json("test_record_wrong_openaireId.json");
172 148

  
173
		final XMLWriter writer = new XMLWriter(System.out, format);
149
	}
174 150

  
175
		writer.write(doc);
151
	@Test
152
	public void testAsIndexRecord_json_zenodo() throws Exception {
176 153

  
177
		/* writer.close(); */
154
		testAsIndexRecord_json("test_zenodo.json");
178 155

  
179 156
	}
180 157

  
181
	@Test(expected = MSROException.class)
182
	public void testAsIndexRecord_wrongOpenaireId() throws Exception {
183

  
158
	private void testAsIndexRecord_json(final String filename) throws Exception {
184 159
		final ResultEntry pub =
185
				(new Gson()).fromJson(new InputStreamReader(getClass().getResourceAsStream("test_record_wrong_openaireId.json")), ResultEntry.class);
160
				(new Gson()).fromJson(new InputStreamReader(getClass().getResourceAsStream(filename)), ResultEntry.class);
186 161

  
187 162
		final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd");
163
		System.out.println(xml);
188 164

  
189 165
		final Document doc = (new SAXReader()).read(new StringReader(xml));
190 166

  
......
195 171
		writer.write(doc);
196 172

  
197 173
		/* writer.close(); */
174
	}
198 175

  
176
	@Test
177
	public void testEscapeUnicode(){
178
		String unicodeTxt = "i.e. closed curves of the form $t\ud835\udfc4 [0,2\u03c0] \u21a6 (\\cos t)u + (\\sin t)v$ for suitable orthogonal vectors $u$";
179
		System.out.println(StringEscapeUtils.escapeXml11(unicodeTxt));
199 180
	}
200 181

  
201 182

  
modules/dnet-openaireplus-workflows/branches/solr7/src/test/resources/eu/dnetlib/msro/openaireplus/api/objects/test_zenodo.json
1
{
2
  "authors":[
3
	"Alouges, Fran\u00e7ois",
4
	"Di Fratta, Giovanni"
5
  ],
6
  "collectedFromId":"opendoar____::2659",
7
  "description":"The paper is about the parking 3-sphere swimmer ($\\text{sPr}_3$). This is a low-Reynolds number model swimmer composed of three balls of equal radii. The three balls can move along three horizontal axes (supported in the same plane) that mutually meet at the center of $\\text{sPr}_3$ with angles of $120^{\u2218}$ . The governing dynamical system is introduced and the implications of its geometric symmetries revealed. It is then shown that, in the first order range of small strokes, optimal periodic strokes are ellipses embedded in 3d space, i.e. closed curves of the form $t\ud835\udfc4 [0,2\u03c0] \u21a6 (\\cos t)u + (\\sin t)v$ for suitable orthogonal vectors $u$ and $v$ of $\u211d^3$. A simple analytic expression for the vectors $u$ and $v$ is derived. The results of the paper are used in a second article where the real physical dynamics of $\\text{sPr}_3$ is analyzed in the asymptotic range of very long arms. ; Comment: 17 pages, 4 figures",
8
  "hostedById":"opendoar____::2659",
9
  "licenseCode":"OPEN",
10
  "originalId":"oai:zenodo.org:996201",
11
  "pids":[
12
	{
13
	  "type":"oai",
14
	  "value":"oai:zenodo.org:996201"
15
	},
16
	{
17
	  "type":"doi",
18
	  "value":"10.5281/zenodo.996201"
19
	}
20
  ],
21
  "publisher":"Zenodo",
22
  "resourceType":"0020",
23
  "title":"Parking 3-sphere swimmer. I. Energy minimizing strokes",
24
  "type":"publication",
25
  "url":"https://zenodo.org/record/996201"
26
}
modules/dnet-openaireplus-workflows/branches/solr7/src/main/java/eu/dnetlib/msro/openaireplus/api/objects/ResultEntry.java
9 9
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
10 10
import eu.dnetlib.miscutils.datetime.DateUtils;
11 11
import eu.dnetlib.miscutils.functional.hash.Hashing;
12
import eu.dnetlib.miscutils.functional.string.EscapeXml;
12 13
import eu.dnetlib.msro.openaireplus.api.OpenAIRESubmitterUtils;
13 14
import eu.dnetlib.msro.rmi.MSROException;
14 15
import io.swagger.annotations.ApiModelProperty;
......
16 17
import org.apache.commons.logging.Log;
17 18
import org.apache.commons.logging.LogFactory;
18 19
import org.apache.velocity.app.VelocityEngine;
19
import org.apache.velocity.tools.generic.EscapeTool;
20 20
import org.springframework.ui.velocity.VelocityEngineUtils;
21 21

  
22 22
/**
......
228 228
		}
229 229

  
230 230
		final Map<String, Object> model = new HashMap<String, Object>();
231
		model.put("esc", new EscapeTool());
231
		model.put("esc", new EscapeXml());
232 232
		model.put("util", new OpenAIRESubmitterUtils());
233 233
		model.put("pub", this);
234 234
		model.put("objIdentifier", getOpenaireId());
modules/dnet-openaireplus-workflows/branches/solr7/src/main/resources/eu/dnetlib/msro/openaireplus/api/indexRecord.xml.vm
2 2

  
3 3
<!--
4 4
#macro(context $ctx)
5
        <$!ctx.elem id="$!esc.xml($!ctx.id)" label="$!esc.xml($contexts.get($!ctx.id))" #if($!ctx.isRoot()) type="community"#end>
5
        <$!ctx.elem id="$!esc.evaluate($!ctx.id)" label="$!esc.evaluate($contexts.get($!ctx.id))" #if($!ctx.isRoot()) type="community"#end>
6 6
	#foreach($child in $!ctx.children)#context($child)#end
7 7
        </$!ctx.elem>
8 8
#end
......
11 11
<record xmlns:dri="http://www.driver-repository.eu/namespace/dri" xmlns:oaf="http://namespace.openaire.eu/oaf">
12 12
	<result>
13 13
		<header>
14
			<dri:objIdentifier>$!esc.xml($!objIdentifier)</dri:objIdentifier>
15
			<dri:dateOfCollection>$!esc.xml($!dateOfCollection)</dri:dateOfCollection>
14
			<dri:objIdentifier>$!esc.evaluate($!objIdentifier)</dri:objIdentifier>
15
			<dri:dateOfCollection>$!esc.evaluate($!dateOfCollection)</dri:dateOfCollection>
16 16
			<dri:status>under curation</dri:status>
17 17
			<counters/>
18 18
		</header>
......
20 20
			<oaf:entity schemaLocation="http://namespace.openaire.eu/oaf $!oafSchemaLocation">
21 21
				<oaf:result>
22 22
					<title classid="main title" classname="main title" schemeid="dnet:dataCite_title" schemename="dnet:dataCite_title">
23
						$!esc.xml($!pub.title)
23
						$!esc.evaluate($!pub.title)
24 24
					</title>
25 25
					<dateofacceptance/>
26
					<resulttype classid="$!esc.xml($!pub.type)" classname="$!esc.xml($!resultTypes.get($!pub.type))" schemeid="dnet:result_typologies" schemename="dnet:result_typologies"/>
27
					<language classid="$!esc.xml($!pub.language)" classname="$!esc.xml($!languages.get($!pub.language))" schemeid="dnet:languages"
26
					<resulttype classid="$!esc.evaluate($!pub.type)" classname="$!esc.evaluate($!resultTypes.get($!pub.type))" schemeid="dnet:result_typologies" schemename="dnet:result_typologies"/>
27
					<language classid="$!esc.evaluate($!pub.language)" classname="$!esc.evaluate($!languages.get($!pub.language))" schemeid="dnet:languages"
28 28
					          schemename="dnet:languages"/>
29 29
					<description>
30
						$!esc.xml($!pub.description)
30
						$!esc.evaluate($!pub.description)
31 31
					</description>
32 32
					<country classid="" classname="" schemeid="" schemename=""/>
33 33
					<subject classid="" classname="" schemeid="" schemename=""/>
34 34
					<relevantdate classid="" classname="" schemeid="" schemename=""/>
35
					<publisher>$!esc.xml($!pub.publisher)</publisher>
36
					<embargoenddate>$!esc.xml($!pub.embargoEndDate)</embargoenddate>
35
					<publisher>$!esc.evaluate($!pub.publisher)</publisher>
36
					<embargoenddate>$!esc.evaluate($!pub.embargoEndDate)</embargoenddate>
37 37
					<source/>
38 38
					<fulltext/>
39 39
					<format/>
......
44 44
					<version/>
45 45
					<lastmetadataupdate/>
46 46
					<metadataversionnumber/>
47
					<originalId>$!esc.xml($!pub.originalId)</originalId>
48
					<collectedfrom name="$!esc.xml($!collectedFrom.name)" id="$!esc.xml($!collectedFrom.calculateOpenaireId())"/>
47
					<originalId>$!esc.evaluate($!pub.originalId)</originalId>
48
					<collectedfrom name="$!esc.evaluate($!collectedFrom.name)" id="$!esc.evaluate($!collectedFrom.calculateOpenaireId())"/>
49 49

  
50 50
					#foreach($pid in $!pub.pids)
51
						<pid classid="$!esc.xml($!pid.type)" classname="$!esc.xml($!pidTypes.get($!pid.type))" schemeid="dnet:pid_types"
52
						     schemename="dnet:pid_types">$!esc.xml($pid.value)</pid>
51
						<pid classid="$!esc.evaluate($!pid.type)" classname="$!esc.evaluate($!pidTypes.get($!pid.type))" schemeid="dnet:pid_types"
52
						     schemename="dnet:pid_types">$!esc.evaluate($pid.value)</pid>
53 53
					#end
54 54

  
55
					<bestlicense classid="$!esc.xml($!pub.licenseCode)" classname="$!esc.xml($!licenses.get($!pub.licenseCode))"
55
					<bestlicense classid="$!esc.evaluate($!pub.licenseCode)" classname="$!esc.evaluate($!licenses.get($!pub.licenseCode))"
56 56
					             schemeid="dnet:access_modes" schemename="dnet:access_modes"/>
57 57

  
58 58
					#foreach($ctx in $util.processContexts($!pub.contexts))
......
79 79

  
80 80
							#set( $info = $!util.calculateProjectInfo($!link) )
81 81
							<rel inferred="false" trust="0.9" inferenceprovenance="" provenanceaction="user:claim:search">
82
								<to class="isProducedBy" scheme="dnet:result_project_relations" type="project">$!esc.xml($!info.id)</to>
83
								<code>$!esc.xml($!info.code)</code>
84
								<acronym>$!esc.xml($!info.acronym)</acronym>
85
								<title>$!esc.xml($!info.title)</title>
82
								<to class="isProducedBy" scheme="dnet:result_project_relations" type="project">$!esc.evaluate($!info.id)</to>
83
								<code>$!esc.evaluate($!info.code)</code>
84
								<acronym>$!esc.evaluate($!info.acronym)</acronym>
85
								<title>$!esc.evaluate($!info.title)</title>
86 86
								<contracttype classid="" classname="" schemeid="" schemename=""/>
87 87

  
88 88
								<funding>
89
									<funder id="$!esc.xml($!info.funderId)"
90
									        shortname="$!esc.xml($!info.funderShortName)"
91
									        name="$!esc.xml($!info.funderName)"
92
									        jurisdiction="$!esc.xml($!info.jurisdiction)"/>
93
									<funding_level_0 name="$!esc.xml($!info.fundingName)">$!esc.xml($!info.fundingId)</funding_level_0>
89
									<funder id="$!esc.evaluate($!info.funderId)"
90
									        shortname="$!esc.evaluate($!info.funderShortName)"
91
									        name="$!esc.evaluate($!info.funderName)"
92
									        jurisdiction="$!esc.evaluate($!info.jurisdiction)"/>
93
									<funding_level_0 name="$!esc.evaluate($!info.fundingName)">$!esc.evaluate($!info.fundingId)</funding_level_0>
94 94
								</funding>
95 95
							</rel>
96 96
						#end
97 97

  
98 98
					</rels>
99 99
					<children>
100
						<instance id="$!esc.xml($!objIdentifier)">
100
						<instance id="$!esc.evaluate($!objIdentifier)">
101 101

  
102
							<licence classid="$!esc.xml($!pub.licenseCode)" classname="$!esc.xml($licenses.get($!pub.licenseCode))"
102
							<licence classid="$!esc.evaluate($!pub.licenseCode)" classname="$!esc.evaluate($licenses.get($!pub.licenseCode))"
103 103
							         schemeid="dnet:access_modes" schemename="dnet:access_modes"/>
104 104

  
105
							<instancetype classid="$!esc.xml($!pub.resourceType)" classname="$!esc.xml($resourceTypes.get($!pub.resourceType))"
105
							<instancetype classid="$!esc.evaluate($!pub.resourceType)" classname="$!esc.evaluate($resourceTypes.get($!pub.resourceType))"
106 106
							              schemeid="dnet:publication_resource" schemename="dnet:publication_resource"/>
107
							<hostedby name="$!esc.xml($!hostedBy.name)" id="$!esc.xml($!hostedBy.calculateOpenaireId())"/>
107
							<hostedby name="$!esc.evaluate($!hostedBy.name)" id="$!esc.evaluate($!hostedBy.calculateOpenaireId())"/>
108 108
							<webresource>
109
								<url>$!esc.xml($!pub.url)</url>
109
								<url>$!esc.evaluate($!pub.url)</url>
110 110
							</webresource>
111 111
						</instance>
112 112
					</children>
modules/dnet-openaireplus-workflows/branches/solr7/pom.xml
165 165
			<artifactId>commons-dbcp2</artifactId>
166 166
			<version>2.1.1</version>
167 167
		</dependency>
168

  
169
		<dependency>
170
			<groupId>eu.dnetlib</groupId>
171
			<artifactId>cnr-misc-utils</artifactId>
172
			<version>[1.0.5, 2.0.0)</version>
173
		</dependency>
168 174
	</dependencies>
169 175

  
170 176
	<properties>

Also available in: Unified diff