Search in sources :

Example 1 with Label

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);
    }
}
Also used : RetryableException(org.wikidata.query.rdf.tool.exception.RetryableException) Label(org.wikidata.query.rdf.tool.wikibase.EditRequest.Label) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) URI(java.net.URI)

Aggregations

IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 URI (java.net.URI)1 RetryableException (org.wikidata.query.rdf.tool.exception.RetryableException)1 Label (org.wikidata.query.rdf.tool.wikibase.EditRequest.Label)1