Skip to content

Commit cec3657

Browse files
committed
Merge branch 'master' into issue-469-continuous-throttling
2 parents 8674035 + 6cb761d commit cec3657

File tree

54 files changed

+3059
-935
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3059
-935
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ sudo: false
44
jdk:
55
- openjdk8
66
- openjdk11
7+
- openjdk13
8+
- openjdk14
79

810
script:
911
- mvn test jacoco:report

RELEASE-NOTES.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Wikidata Toolkit Release Notes
22
==============================
33

4+
Version 0.11.1
5+
--------------
6+
7+
Bug fixes:
8+
* Fixes API connection bug due to lower-case set-cookie header sent from Wikidata
9+
* Upgrades dependencies to latest version
410

511
Version 0.11.0
612
--------------

pom.xml

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>org.wikidata.wdtk</groupId>
77
<artifactId>wdtk-parent</artifactId>
8-
<version>0.11.0</version>
8+
<version>0.11.1</version>
99
<packaging>pom</packaging>
1010

1111
<name>Wikidata Toolkit</name>
@@ -72,17 +72,17 @@
7272

7373
<properties>
7474
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
75-
<apacheCommonsCompressVersion>1.19</apacheCommonsCompressVersion>
76-
<apacheCommonsLangVersion>3.9</apacheCommonsLangVersion>
77-
<apacheHttpVersion>4.5.10</apacheHttpVersion>
78-
<commonsCliVersion>1.4</commonsCliVersion>
79-
<ini4JVersion>0.5.4</ini4JVersion>
80-
<jacksonVersion>2.9.10</jacksonVersion>
81-
<junitVersion>4.12</junitVersion>
75+
<apacheCommonsCompressVersion>1.20</apacheCommonsCompressVersion>
76+
<apacheCommonsLangVersion>3.10</apacheCommonsLangVersion>
77+
<apacheCommonsIOVersion>2.6</apacheCommonsIOVersion>
78+
<jacksonVersion>2.10.3</jacksonVersion>
79+
<junitVersion>4.13</junitVersion>
8280
<mockitoVersion>1.10.19</mockitoVersion>
83-
<rdf4jVersion>3.0.1</rdf4jVersion>
84-
<slf4jVersion>1.7.28</slf4jVersion>
81+
<rdf4jVersion>3.1.3</rdf4jVersion>
82+
<slf4jVersion>1.7.30</slf4jVersion>
8583
<threetenVersion>1.5.0</threetenVersion>
84+
<okhttpSignpostVersion>1.1.0</okhttpSignpostVersion>
85+
<okhttpVersion>4.2.2</okhttpVersion>
8686
</properties>
8787

8888
<dependencies>
@@ -191,7 +191,7 @@
191191
<dependency>
192192
<groupId>javax.xml.bind</groupId>
193193
<artifactId>jaxb-api</artifactId>
194-
<version>2.2.3</version>
194+
<version>2.3.1</version>
195195
</dependency>
196196
</dependencies>
197197
</plugin>

wdtk-datamodel/pom.xml

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.wikidata.wdtk</groupId>
77
<artifactId>wdtk-parent</artifactId>
8-
<version>0.11.0</version>
8+
<version>0.11.1</version>
99
</parent>
1010

1111
<artifactId>wdtk-datamodel</artifactId>
@@ -46,6 +46,12 @@
4646
<artifactId>threeten-extra</artifactId>
4747
<version>${threetenVersion}</version>
4848
</dependency>
49+
<dependency>
50+
<groupId>commons-io</groupId>
51+
<artifactId>commons-io</artifactId>
52+
<version>${apacheCommonsIOVersion}</version>
53+
<scope>test</scope>
54+
</dependency>
4955
</dependencies>
5056

5157
<build>

wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/Datamodel.java

+36
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,34 @@ public static MonolingualTextValue makeMonolingualTextValue(String text,
380380
* @param unit
381381
* the unit identifier to use for this quantity
382382
* @return a {@link QuantityValue} corresponding to the input
383+
* @deprecated Use {@link #makeQuantityValue(BigDecimal, BigDecimal, BigDecimal, ItemIdValue)}
383384
*/
385+
@Deprecated
384386
public static QuantityValue makeQuantityValue(BigDecimal numericValue,
385387
BigDecimal lowerBound, BigDecimal upperBound, String unit) {
386388
return factory.getQuantityValue(numericValue, lowerBound, upperBound,
387389
unit);
388390
}
389391

392+
/**
393+
* Creates a {@link QuantityValue}.
394+
*
395+
* @param numericValue
396+
* the numeric value of this quantity
397+
* @param lowerBound
398+
* the lower bound of the numeric value of this quantity
399+
* @param upperBound
400+
* the upper bound of the numeric value of this quantity
401+
* @param unit
402+
* the unit identifier to use for this quantity
403+
* @return a {@link QuantityValue} corresponding to the input
404+
*/
405+
public static QuantityValue makeQuantityValue(BigDecimal numericValue,
406+
BigDecimal lowerBound, BigDecimal upperBound, ItemIdValue unit) {
407+
return factory.getQuantityValue(numericValue, lowerBound, upperBound,
408+
unit.getIri());
409+
}
410+
390411
/**
391412
* Creates a {@link QuantityValue} without bounds.
392413
*
@@ -395,11 +416,26 @@ public static QuantityValue makeQuantityValue(BigDecimal numericValue,
395416
* @param unit
396417
* the unit identifier to use for this quantity
397418
* @return a {@link QuantityValue} corresponding to the input
419+
* @deprecated Use {@link #makeQuantityValue(BigDecimal, ItemIdValue)}
398420
*/
421+
@Deprecated
399422
public static QuantityValue makeQuantityValue(BigDecimal numericValue, String unit) {
400423
return factory.getQuantityValue(numericValue, unit);
401424
}
402425

426+
/**
427+
* Creates a {@link QuantityValue} without bounds.
428+
*
429+
* @param numericValue
430+
* the numeric value of this quantity
431+
* @param unit
432+
* the unit identifier to use for this quantity
433+
* @return a {@link QuantityValue} corresponding to the input
434+
*/
435+
public static QuantityValue makeQuantityValue(BigDecimal numericValue, ItemIdValue unit) {
436+
return factory.getQuantityValue(numericValue, unit.getIri());
437+
}
438+
403439
/**
404440
* Creates a {@link QuantityValue} with an empty unit.
405441
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package org.wikidata.wdtk.datamodel.helpers;
2+
3+
/*-
4+
* #%L
5+
* Wikidata Toolkit Data Model
6+
* %%
7+
* Copyright (C) 2014 - 2020 Wikidata Toolkit Developers
8+
* %%
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* #L%
21+
*/
22+
23+
import java.io.IOException;
24+
25+
import com.fasterxml.jackson.databind.ObjectReader;
26+
import org.wikidata.wdtk.datamodel.implementation.*;
27+
import org.wikidata.wdtk.datamodel.interfaces.*;
28+
29+
import com.fasterxml.jackson.databind.DeserializationFeature;
30+
31+
/**
32+
* Helper to deserialize datamodel objects from their
33+
* JSON representation.
34+
*
35+
* We accept empty arrays as empty maps since there has
36+
* been a confusion in the past between the two:
37+
* https://phabricator.wikimedia.org/T138104
38+
*
39+
* @author Antonin Delpeuch
40+
*/
41+
public class JsonDeserializer {
42+
43+
private ObjectReader entityDocumentReader;
44+
private ObjectReader itemReader;
45+
private ObjectReader propertyReader;
46+
private ObjectReader lexemeReader;
47+
private ObjectReader mediaInfoReader;
48+
private ObjectReader entityRedirectReader;
49+
50+
/**
51+
* Constructs a new JSON deserializer for the
52+
* designated site.
53+
*
54+
* @param siteIri
55+
* Root IRI of the site to deserialize for
56+
*/
57+
public JsonDeserializer(String siteIri) {
58+
DatamodelMapper mapper = new DatamodelMapper(siteIri);
59+
entityDocumentReader = mapper.readerFor(EntityDocumentImpl.class)
60+
.with(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT);
61+
itemReader = mapper.readerFor(ItemDocumentImpl.class)
62+
.with(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT);
63+
propertyReader = mapper.readerFor(PropertyDocumentImpl.class)
64+
.with(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT);
65+
lexemeReader = mapper.readerFor(LexemeDocumentImpl.class)
66+
.with(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT);
67+
mediaInfoReader = mapper.readerFor(MediaInfoDocumentImpl.class)
68+
.with(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT);
69+
entityRedirectReader = mapper.readerFor(EntityRedirectDocumentImpl.class)
70+
.with(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT);
71+
}
72+
73+
/**
74+
* Deserializes a JSON string into an {@class ItemDocument}.
75+
* @throws IOException
76+
if the JSON payload is invalid
77+
*/
78+
public ItemDocument deserializeItemDocument(String json) throws IOException {
79+
return itemReader.readValue(json);
80+
}
81+
82+
/**
83+
* Deserializes a JSON string into a {@class PropertyDocument}.
84+
* @throws IOException
85+
if the JSON payload is invalid
86+
*/
87+
public PropertyDocument deserializePropertyDocument(String json) throws IOException {
88+
return propertyReader.readValue(json);
89+
}
90+
91+
/**
92+
* Deserializes a JSON string into a {@class LexemeDocument}.
93+
* @throws IOException
94+
if the JSON payload is invalid
95+
*/
96+
public LexemeDocument deserializeLexemeDocument(String json) throws IOException {
97+
return lexemeReader.readValue(json);
98+
}
99+
100+
/**
101+
* Deserializes a JSON string into a {@class MediaInfoDocument}.
102+
* @throws IOException
103+
if the JSON payload is invalid
104+
*/
105+
public MediaInfoDocument deserializeMediaInfoDocument(String json) throws IOException {
106+
return mediaInfoReader.readValue(json);
107+
}
108+
109+
/**
110+
* Deserializes a JSON string into a {@class EntityDocument}.
111+
* @throws IOException
112+
if the JSON payload is invalid
113+
*/
114+
public EntityDocument deserializeEntityDocument(String json) throws IOException {
115+
return entityDocumentReader.readValue(json);
116+
}
117+
118+
/**
119+
* Deserializes a JSON string into a {@class EntityRedirectDocument}.
120+
* @throws IOException
121+
if the JSON payload is invalid
122+
*/
123+
public EntityRedirectDocument deserializeEntityRedirectDocument(String json) throws IOException {
124+
return entityRedirectReader.readValue(json);
125+
}
126+
}

wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/JsonSerializer.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@
2626

2727
import org.slf4j.Logger;
2828
import org.slf4j.LoggerFactory;
29-
import org.wikidata.wdtk.datamodel.interfaces.*;
29+
import org.wikidata.wdtk.datamodel.interfaces.EntityDocument;
30+
import org.wikidata.wdtk.datamodel.interfaces.EntityDocumentDumpProcessor;
31+
import org.wikidata.wdtk.datamodel.interfaces.ItemDocument;
32+
import org.wikidata.wdtk.datamodel.interfaces.LexemeDocument;
33+
import org.wikidata.wdtk.datamodel.interfaces.MediaInfoDocument;
34+
import org.wikidata.wdtk.datamodel.interfaces.PropertyDocument;
35+
import org.wikidata.wdtk.datamodel.interfaces.Statement;
3036

3137
import com.fasterxml.jackson.core.JsonGenerator;
3238
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -232,5 +238,4 @@ protected static String jacksonObjectToString(Object object) {
232238
return null;
233239
}
234240
}
235-
236241
}

wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/EntityIdValueImpl.java

+26-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.annotation.*;
44
import org.apache.commons.lang3.Validate;
5+
import org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue;
56
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
67

78
/*
@@ -120,7 +121,7 @@ protected EntityIdValueImpl(
120121
* if the id is invalid
121122
*/
122123
public static EntityIdValue fromId(String id, String siteIri) {
123-
switch (guessEntityTypeFromId(id)) {
124+
switch (guessEntityTypeFromId(id, true)) {
124125
case EntityIdValueImpl.JSON_ENTITY_TYPE_ITEM:
125126
return new ItemIdValueImpl(id, siteIri);
126127
case EntityIdValueImpl.JSON_ENTITY_TYPE_PROPERTY:
@@ -139,37 +140,51 @@ public static EntityIdValue fromId(String id, String siteIri) {
139140
}
140141

141142
/**
142-
* RReturns the entity type of the id like "item" or "property"
143+
* Returns the entity type of the id like "item" or "property"
143144
*
144145
* @param id
145146
* the identifier of the entity, such as "Q42"
147+
* @param returnJsonEntity
148+
* returns JSON entity types when set to true
146149
* @throws IllegalArgumentException
147150
* if the id is invalid
148151
*/
149-
static String guessEntityTypeFromId(String id) {
152+
static String guessEntityTypeFromId(String id, boolean returnJsonEntity) {
150153
if(id.isEmpty()) {
151154
throw new IllegalArgumentException("Entity ids should not be empty.");
152155
}
153156
switch (id.charAt(0)) {
154157
case 'L':
155158
if(id.contains("-F")) {
156-
return JSON_ENTITY_TYPE_FORM;
159+
return returnJsonEntity ? JSON_ENTITY_TYPE_FORM : DatatypeIdValue.DT_FORM;
157160
} else if(id.contains("-S")) {
158-
return JSON_ENTITY_TYPE_SENSE;
161+
return returnJsonEntity ? JSON_ENTITY_TYPE_SENSE : DatatypeIdValue.DT_SENSE;
159162
} else {
160-
return JSON_ENTITY_TYPE_LEXEME;
163+
return returnJsonEntity ? JSON_ENTITY_TYPE_LEXEME : DatatypeIdValue.DT_LEXEME;
161164
}
162165
case 'M':
163-
return JSON_ENTITY_TYPE_MEDIA_INFO;
166+
return returnJsonEntity ? JSON_ENTITY_TYPE_MEDIA_INFO : DatatypeIdValue.DT_MEDIA_INFO;
164167
case 'P':
165-
return JSON_ENTITY_TYPE_PROPERTY;
168+
return returnJsonEntity ? JSON_ENTITY_TYPE_PROPERTY : DatatypeIdValue.DT_PROPERTY;
166169
case 'Q':
167-
return JSON_ENTITY_TYPE_ITEM;
170+
return returnJsonEntity ? JSON_ENTITY_TYPE_ITEM : DatatypeIdValue.DT_ITEM;
168171
default:
169172
throw new IllegalArgumentException("Entity id \"" + id + "\" is not supported.");
170173
}
171174
}
172175

176+
/**
177+
* Returns the entity type of the id like "item" or "property"
178+
*
179+
* @param id
180+
* the identifier of the entity, such as "Q42"
181+
* @throws IllegalArgumentException
182+
* if the id is invalid
183+
*/
184+
public static String guessEntityTypeFromId(String id){
185+
return guessEntityTypeFromId(id, false);
186+
}
187+
173188
/**
174189
* Returns the inner value helper object. Only for use by Jackson during
175190
* serialization.
@@ -226,7 +241,7 @@ static class JacksonInnerEntityId {
226241

227242
JacksonInnerEntityId(String id) {
228243
this.id = id;
229-
entityType = guessEntityTypeFromId(id);
244+
entityType = guessEntityTypeFromId(id, true);
230245
numericId = buildNumericId(id);
231246
}
232247

@@ -251,7 +266,7 @@ static class JacksonInnerEntityId {
251266
} else {
252267
this.id = id;
253268
if(entityType == null || numericId == 0) {
254-
this.entityType = guessEntityTypeFromId(id);
269+
this.entityType = guessEntityTypeFromId(id, true);
255270
this.numericId = buildNumericId(id);
256271
} else if(!id.equals(buildIdFromNumericId(entityType, numericId))) {
257272
throw new IllegalArgumentException("Numerical id is different from the string id");

0 commit comments

Comments
 (0)