Example #1
0
        internal static Snak newFromArray(JsonObject data)
        {
            if (data.get("snaktype") == null || data.get("property") == null)
            {
                throw new ArgumentException("Invalid Snak serialization", "data");
            }
            var dataValue = data.get("datavalue");

            if (dataValue != null)
            {
                return(new Snak(
                           data.get("snaktype").asString(),
                           EntityId.newFromPrefixedId(data.get("property").asString()),
                           DataValueFactory.newFromArray(dataValue.asObject())
                           ));
            }
            else
            {
                return(new Snak(
                           data.get("snaktype").asString(),
                           EntityId.newFromPrefixedId(data.get("property").asString()),
                           null
                           ));
            }
        }
Example #2
0
 public void save(string summary)
 {
     if (!this.changes.isEmpty())
     {
         if (this.changes.get("mainsnak") != null)
         {
             JsonObject change = this.changes.get("mainsnak").asObject();
             if (change.get("snaktype") == null || change.get("property") == null)
             {
                 throw new Exception("The main snak does not have required data");
             }
             DataValue  value = change.get("datavalue") == null ? null : DataValueFactory.newFromArray(change.get("datavalue").asObject());
             JsonObject result;
             if (this.id == null)
             {
                 result = this.entity.api.createClaim(this.entity.id.getPrefixedId(), change.get("snaktype").asString(), change.get("property").asString(), value, this.entity.lastRevisionId, summary);
             }
             else
             {
                 result = this.entity.api.setClaimValue(this.id, change.get("snaktype").asString(), value, this.entity.lastRevisionId, summary);
             }
             this.updateDataFromResult(result);
             this.changes.removeAt("mainsnak");
         }
     }
 }