use of org.wikidata.query.rdf.tool.wikibase.EditRequest.Label in project wikidata-query-rdf by wikimedia.
the class WikibaseRepository method setLabel.
/**
* Edits or creates a page by setting a label. Used for testing.
*
* @param entityId id of the entity - if null then the entity will be
* created new
* @param type type of entity to create or edit
* @param label label of the page to create
* @param language language of the label to add
* @return the entityId
* @throws RetryableException thrown if there is an error communicating with
* wikibase
*/
@SuppressWarnings("unchecked")
public String setLabel(String entityId, String type, String label, String language) throws RetryableException {
String datatype = type.equals("property") ? "string" : null;
EditRequest data = new EditRequest(datatype, ImmutableMap.of(language, new Label(language, label)));
try {
URI uri = uris.edit(entityId, type, mapper.writeValueAsString(data));
log.debug("Editing entity using {}", uri);
EditResponse result = checkApi(getJson(postWithToken(uri), EditResponse.class));
return result.getEntity().getId();
} catch (IOException e) {
throw new RetryableException("Error adding page", e);
}
}
Aggregations