Search in sources :

Example 91 with JsonValue

use of com.eclipsesource.json.JsonValue in project box-java-sdk by box.

the class BoxSignRequestPrefillTag method parseJSONMember.

/**
 * {@inheritDoc}
 */
@Override
void parseJSONMember(JsonObject.Member member) {
    JsonValue value = member.getValue();
    String memberName = member.getName();
    try {
        if ("document_tag_id".equals(memberName)) {
            this.documentTagId = value.asString();
        } else if ("text_value".equals(memberName)) {
            this.textValue = value.asString();
        } else if ("checkbox_value".equals(memberName)) {
            this.checkboxValue = value.asBoolean();
        } else if ("date_value".equals(memberName)) {
            this.dateValue = BoxDateFormat.parseDateOnly(value.asString());
        }
    } catch (Exception e) {
        throw new BoxDeserializationException(memberName, value.toString(), e);
    }
}
Also used : JsonValue(com.eclipsesource.json.JsonValue)

Example 92 with JsonValue

use of com.eclipsesource.json.JsonValue in project box-java-sdk by box.

the class BoxFileUploadSessionPart method parseJSONMember.

@Override
protected void parseJSONMember(JsonObject.Member member) {
    String memberName = member.getName();
    JsonValue value = member.getValue();
    if (memberName.equals("part_id")) {
        this.partId = value.asString();
    } else if (memberName.equals("offset")) {
        this.offset = Double.valueOf(value.toString()).longValue();
    } else if (memberName.equals("size")) {
        this.size = Double.valueOf(value.toString()).longValue();
    } else if (memberName.equals("sha1")) {
        this.sha1 = value.asString();
    }
}
Also used : JsonValue(com.eclipsesource.json.JsonValue)

Example 93 with JsonValue

use of com.eclipsesource.json.JsonValue in project box-java-sdk by box.

the class BoxFileVersion method parseJSON.

/**
 * Method used to update fields with values received from API.
 *
 * @param jsonObject JSON-encoded info about File Version object.
 */
private void parseJSON(JsonObject jsonObject) {
    for (JsonObject.Member member : jsonObject) {
        JsonValue value = member.getValue();
        if (value.isNull()) {
            continue;
        }
        try {
            String memberName = member.getName();
            if (memberName.equals("id")) {
                this.versionID = value.asString();
            } else if (memberName.equals("sha1")) {
                this.sha1 = value.asString();
            } else if (memberName.equals("name")) {
                this.name = value.asString();
            } else if (memberName.equals("size")) {
                this.size = Double.valueOf(value.toString()).longValue();
            } else if (memberName.equals("uploader_display_name")) {
                this.uploaderDisplayName = value.asString();
            } else if (memberName.equals("created_at")) {
                this.createdAt = BoxDateFormat.parse(value.asString());
            } else if (memberName.equals("modified_at")) {
                this.modifiedAt = BoxDateFormat.parse(value.asString());
            } else if (memberName.equals("trashed_at")) {
                this.trashedAt = BoxDateFormat.parse(value.asString());
            } else if (memberName.equals("trashed_by")) {
                JsonObject userJSON = value.asObject();
                String userID = userJSON.get("id").asString();
                BoxUser user = new BoxUser(getAPI(), userID);
                this.trashedBy = user.new Info(userJSON);
            } else if (memberName.equals("modified_by")) {
                JsonObject userJSON = value.asObject();
                String userID = userJSON.get("id").asString();
                BoxUser user = new BoxUser(getAPI(), userID);
                this.modifiedBy = user.new Info(userJSON);
            } else if (memberName.equals("restored_at")) {
                this.restoredAt = BoxDateFormat.parse(value.asString());
            } else if (memberName.equals("restored_by")) {
                JsonObject userJSON = value.asObject();
                String userID = userJSON.get("id").asString();
                BoxUser user = new BoxUser(getAPI(), userID);
                this.restoredBy = user.new Info(userJSON);
            } else if (memberName.equals("purged_at")) {
                this.purgedAt = BoxDateFormat.parse(value.asString());
            } else if (memberName.equals("version_number")) {
                this.versionNumber = Long.parseLong(value.asString());
            }
        } catch (ParseException e) {
            assert false : "A ParseException indicates a bug in the SDK.";
        }
    }
}
Also used : JsonValue(com.eclipsesource.json.JsonValue) JsonObject(com.eclipsesource.json.JsonObject) ParseException(java.text.ParseException)

Example 94 with JsonValue

use of com.eclipsesource.json.JsonValue in project box-java-sdk by box.

the class BoxLock method parseJSONMember.

@Override
protected void parseJSONMember(JsonObject.Member member) {
    super.parseJSONMember(member);
    String memberName = member.getName();
    JsonValue value = member.getValue();
    try {
        if (memberName.equals("type")) {
            this.type = value.asString();
        } else if (memberName.equals("expires_at")) {
            this.expiresAt = BoxDateFormat.parse(value.asString());
        } else if (memberName.equals("is_download_prevented")) {
            this.isDownloadPrevented = value.asBoolean();
        } else if (memberName.equals("created_by")) {
            JsonObject userJSON = value.asObject();
            if (this.createdBy == null) {
                String userID = userJSON.get("id").asString();
                BoxUser user = new BoxUser(this.api, userID);
                this.createdBy = user.new Info(userJSON);
            } else {
                this.createdBy.update(userJSON);
            }
        } else if (memberName.equals("created_at")) {
            this.createdAt = BoxDateFormat.parse(value.asString());
        } else if (memberName.equals("id")) {
            this.id = value.toString();
        }
    } catch (Exception e) {
        throw new BoxDeserializationException(memberName, value.toString(), e);
    }
}
Also used : JsonValue(com.eclipsesource.json.JsonValue) JsonObject(com.eclipsesource.json.JsonObject)

Example 95 with JsonValue

use of com.eclipsesource.json.JsonValue in project box-java-sdk by box.

the class BoxMetadataQueryItem method parseJSONMember.

@Override
protected void parseJSONMember(JsonObject.Member member) {
    super.parseJSONMember(member);
    String memberName = member.getName();
    JsonValue value = member.getValue();
    if (memberName.equals("item")) {
        String id = value.asObject().get("id").asString();
        String type = value.asObject().get("type").asString();
        this.item = new BoxFile(this.api, id).new Info(value.asObject());
        if (type.equals("folder")) {
            BoxFolder folder = new BoxFolder(this.api, id);
            this.item = folder.new Info(value.asObject());
        } else if (type.equals("file")) {
            BoxFile file = new BoxFile(this.api, id);
            this.item = file.new Info(value.asObject());
        } else if (type.equals("web_link")) {
            BoxWebLink link = new BoxWebLink(this.api, id);
            this.item = link.new Info(value.asObject());
        } else {
            assert false : "Unsupported item type: " + type;
            throw new BoxAPIException("Unsupported item type: " + type);
        }
    } else if (memberName.equals("metadata")) {
        this.metadata = new HashMap<String, ArrayList<Metadata>>();
        JsonObject metadataObject = value.asObject();
        for (JsonObject.Member enterprise : metadataObject) {
            String enterpriseName = enterprise.getName();
            JsonObject templates = enterprise.getValue().asObject();
            ArrayList<Metadata> enterpriseMetadataArray = new ArrayList<Metadata>();
            for (JsonObject.Member template : templates) {
                String templateName = template.getName();
                JsonObject templateValue = template.getValue().asObject();
                Metadata metadataOfTemplate = new Metadata(templateValue);
                metadataOfTemplate.add("/$scope", enterpriseName);
                metadataOfTemplate.add("/$template", templateName);
                enterpriseMetadataArray.add(metadataOfTemplate);
            }
            this.metadata.put(enterpriseName, enterpriseMetadataArray);
        }
    }
}
Also used : HashMap(java.util.HashMap) JsonValue(com.eclipsesource.json.JsonValue) ArrayList(java.util.ArrayList) JsonObject(com.eclipsesource.json.JsonObject)

Aggregations

JsonValue (com.eclipsesource.json.JsonValue)147 JsonObject (com.eclipsesource.json.JsonObject)74 JsonArray (com.eclipsesource.json.JsonArray)43 Test (org.junit.Test)38 ArrayList (java.util.ArrayList)26 URL (java.net.URL)21 HashMap (java.util.HashMap)10 IOException (java.io.IOException)9 Member (com.eclipsesource.json.JsonObject.Member)6 ParseException (com.eclipsesource.json.ParseException)4 File (java.io.File)4 MalformedURLException (java.net.MalformedURLException)4 InetSocketAddress (java.net.InetSocketAddress)3 Collection (java.util.Collection)3 Map (java.util.Map)3 WebTarget (javax.ws.rs.client.WebTarget)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 JsonUtil.getString (com.hazelcast.util.JsonUtil.getString)2 WalletCallException (com.vaklinov.zcashui.ZCashClientCaller.WalletCallException)2 FileInputStream (java.io.FileInputStream)2