Example usage for com.google.gson JsonObject addProperty

List of usage examples for com.google.gson JsonObject addProperty

Introduction

In this page you can find the example usage for com.google.gson JsonObject addProperty.

Prototype

public void addProperty(String property, Character value) 

Source Link

Document

Convenience method to add a char member.

Usage

From source file:com.basho.riakcs.client.impl.RiakCSClientImpl.java

License:Open Source License

public void addAdditionalACLToBucket(String bucketName, String emailAddress, Permission permission)
        throws RiakCSException {
    try {// w  w w . j  ava2s.com
        JsonObject oldACL = getACLForBucket(bucketName);

        JsonObject newGrant = new JsonObject();
        JsonObject grantee = new JsonObject();
        grantee.addProperty("emailAddress", emailAddress);
        newGrant.add("grantee", grantee);
        newGrant.addProperty("permission", permission.toString());

        oldACL.get("grantsList").getAsJsonArray().add(newGrant);

        addAdditionalACLImpl(bucketName, "", oldACL);

    } catch (Exception e) {
        throw new RiakCSException(e);
    }
}

From source file:com.basho.riakcs.client.impl.RiakCSClientImpl.java

License:Open Source License

public void addAdditionalACLToObject(String bucketName, String objectKey, String emailAddress,
        Permission permission) throws RiakCSException {
    try {//from  w  ww  .j  a va2s  .  com
        JsonObject oldACL = getACLForObject(bucketName, objectKey);

        JsonObject newGrant = new JsonObject();
        JsonObject grantee = new JsonObject();
        grantee.addProperty("emailAddress", emailAddress);
        newGrant.add("grantee", grantee);
        newGrant.addProperty("permission", permission.toString());

        oldACL.get("grantsList").getAsJsonArray().add(newGrant);

        addAdditionalACLImpl(bucketName, objectKey, oldACL);

    } catch (Exception e) {
        throw new RiakCSException(e);
    }
}

From source file:com.basho.riakcs.client.impl.RiakCSClientImpl.java

License:Open Source License

private JsonObject getAclImpl(String bucketName, String objectKey) throws Exception {
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("acl", null);

    CommunicationLayer comLayer = getCommunicationLayer();

    URL url = comLayer.generateCSUrl(bucketName, objectKey, parameters);
    HttpURLConnection conn = comLayer.makeCall(CommunicationLayer.HttpMethod.GET, url);

    Document xmlDoc = XMLUtils.parseToDocument(conn.getInputStream(), debugModeEnabled);
    JsonObject acl = new JsonObject();
    JsonArray grantsList = new JsonArray();

    for (Node grantNode : XMLUtils.xpathToNodeList("//Grant", xmlDoc)) {
        JsonObject grant = new JsonObject();
        grant.addProperty("permission", XMLUtils.xpathToContent("Permission", grantNode));

        String type = XMLUtils.xpathToContent("Grantee/@type", grantNode);

        JsonObject grantee = new JsonObject();
        grantee.addProperty("type", type);

        if (type.equals("Group")) {
            grantee.addProperty("uri", XMLUtils.xpathToContent("Grantee/URI", grantNode));
        } else {/*  w w w .  ja va 2 s .c  om*/
            grantee.addProperty("id", XMLUtils.xpathToContent("Grantee/ID", grantNode));
            grantee.addProperty("displayName", XMLUtils.xpathToContent("Grantee/DisplayName", grantNode));
        }
        grant.add("grantee", grantee);
        grantsList.add(grant);
    }
    acl.add("grantsList", grantsList);
    JsonObject owner = new JsonObject();
    owner.addProperty("id", XMLUtils.xpathToContent("//Owner/ID", xmlDoc));
    owner.addProperty("displayName", XMLUtils.xpathToContent("//Owner/DisplayName", xmlDoc));
    acl.add("owner", owner);
    return acl;
}

From source file:com.beanstream.api.PaymentsAPI.java

License:Open Source License

/**
 * Void the specified paymentId. Voids generally need to occur before end of
 * business on the same day that the transaction was processed. Voids are
 * used to cancel a transaction before the item is registered against a
 * customer credit card account. Card holders will never see a voided
 * transaction on their credit card statement. As a result, voids can only
 * be attempted on the same day as the original transaction. After the end
 * of day (roughly 11:59 PM EST/EDT), void requests will be rejected from
 * the API if attempted.//from w  w w  . j  a  va 2 s. c o  m
 *
 * @author Pedro Garcia
 * @param paymentId payment transaction id to void
 * @param amount the amount to avoid in this transaction
 * @return PaymentResponse as result you will received a payment response
 * with the same payment transaction id but with the type 'VP'
 * @throws BeanstreamApiException as a result of a business logic validation
 * or any other error @see
 */
public PaymentResponse voidPayment(String paymentId, double amount) throws BeanstreamApiException {

    Gateway.assertNotEmpty(paymentId, "invalid paymentId");
    String url = getVoidPaymentUrl(config.getPlatform(), config.getVersion(), paymentId);

    JsonObject voidRequest = new JsonObject();
    voidRequest.addProperty(MERCHANT_ID_PARAM, String.valueOf(config.getMerchantId()));
    voidRequest.addProperty(AMOUNT_PARAM, String.valueOf(amount));

    String response = connector.ProcessTransaction(HttpMethod.post, url, voidRequest);

    // parse the output and return a PaymentResponse
    return gson.fromJson(response, PaymentResponse.class);

}

From source file:com.beanstream.api.PaymentsAPI.java

License:Open Source License

/**
 * Push the actual payment through after a pre-authorization.
 * Convenience method if you don't want to supply the whole PaymentRequest.
 * //from  ww  w. j a v  a 2  s  .  co  m
 * @param paymentId of the pre-authorized transaction
 * @param amount final amount to be charged
 * @return the PaymentResponse for the final transaction
 * @throws BeanstreamApiException when not successful
 */
public PaymentResponse preAuthCompletion(String paymentId, double amount) throws BeanstreamApiException {

    Gateway.assertNotEmpty(paymentId, "Invalid Payment Id");

    String authorizePaymentUrl = getPreAuthCompletionsUrl(config.getPlatform(), config.getVersion(), paymentId);

    JsonObject authorizeRequest = new JsonObject();
    authorizeRequest.addProperty(MERCHANT_ID_PARAM, String.valueOf(config.getMerchantId()));
    authorizeRequest.addProperty(AMOUNT_PARAM, String.valueOf(amount));

    String response = connector.ProcessTransaction(HttpMethod.post, authorizePaymentUrl, authorizeRequest);

    return gson.fromJson(response, PaymentResponse.class);

}

From source file:com.beanstream.api.ProfilesAPI.java

License:Open Source License

/**
 * Updates the profile. You must first retrieve the profile using
 * ProfilesAPI.getProfileById(id)//from w  w  w  . ja v a2s  . c o  m
 * 
 * @param profile
 *            object to update
 * @return ProfileResponse if successful, an BeanstreamApiException if not.
 **/
public ProfileResponse updateProfile(PaymentProfile profile) throws BeanstreamApiException {
    Gateway.assertNotNull(profile, "profile to update is null");
    ProfilesUtils.validateProfileId(profile.getId());

    ProfilesUtils.validateBillingAddr(profile.getBilling());

    String url = PaymentsUrls.getProfilesUrl(config.getPlatform(), config.getVersion(), profile.getId());

    JsonObject req = new JsonObject();
    req.add("billing", gson.toJsonTree(profile.getBilling(), Address.class));
    req.add("custom", gson.toJsonTree(profile.getCustom(), CustomFields.class));
    req.addProperty("language", profile.getLanguage());
    req.addProperty("comments", profile.getComments());
    String response = connector.ProcessTransaction(HttpMethod.put, url, req);
    return gson.fromJson(response, ProfileResponse.class);
}

From source file:com.beanstream.requests.CriteriaSerializer.java

License:Open Source License

@Override
public JsonElement serialize(Criteria criteria, Type type, JsonSerializationContext jsc) {

    JsonObject json = new JsonObject();
    json.addProperty("field", criteria.getField().ordinal() + 1); // increase by 1
    try {/*  w  w  w . j  av a  2 s .c  o  m*/
        String operator = criteria.getOperator().toString();
        if (operator.equals(Operators.StartWith.toString()))
            operator = "START%20WITH"; // add a space
        else if (operator.equals(Operators.Equals.toString()))
            operator = URLEncoder.encode("=", "UTF-8");
        else if (operator.equals(Operators.GreaterThan.toString()))
            operator = URLEncoder.encode(">", "UTF-8");
        else if (operator.equals(Operators.GreaterThanEqual.toString()))
            operator = URLEncoder.encode(">=", "UTF-8");
        else if (operator.equals(Operators.LessThan.toString()))
            operator = URLEncoder.encode("<", "UTF-8");
        else if (operator.equals(Operators.LessThanEqual.toString()))
            operator = URLEncoder.encode("<=", "UTF-8");

        json.addProperty("operator", operator);
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(CriteriaSerializer.class.getName()).log(Level.SEVERE, "Wrong encoding scheme!", ex);
    }
    json.addProperty("value", criteria.getValue());

    return json;
}

From source file:com.bekwam.resignator.model.ConfigurationJSONAdapter.java

License:Apache License

@Override
public JsonElement serialize(Configuration configuration, Type type,
        JsonSerializationContext jsonSerializationContext) {

    if (logger.isDebugEnabled()) {
        logger.debug("[SERIALIZE]");
    }/*from   w  ww.j a v a2 s .  c o  m*/

    String ap = configuration.getActiveProfile().orElse("");
    String jdkHome = configuration.getJDKHome().orElse("");
    JsonArray profiles = serializeProfiles(configuration.getProfiles());
    String hp = configuration.getHashedPassword().orElse("");
    String lud = "";
    if (configuration.getLastUpdatedDateTime().isPresent()) {

        lud = configuration.getLastUpdatedDateTime().get().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
    }

    JsonObject root = new JsonObject();
    root.addProperty("activeProfile", ap);
    root.addProperty("jdkHome", jdkHome);
    root.addProperty("hashedPassword", hp);
    root.addProperty("lastUpdatedDate", lud);

    if (logger.isDebugEnabled()) {
        logger.debug("[SERIALIZE] ap={}, jdkHome={}, hp empty?={}, lastUpdatedDate={}", ap, jdkHome,
                StringUtils.isEmpty(hp), lud);
    }

    root.add("recentProfiles", serializeRecentProfiles(configuration.getRecentProfiles()));
    root.add("profiles", profiles);

    return root;
}

From source file:com.bekwam.resignator.model.ConfigurationJSONAdapter.java

License:Apache License

private JsonArray serializeProfiles(List<Profile> profiles) {
    JsonArray ps = new JsonArray();

    for (Profile p : profiles) {

        JsonObject profileObj = new JsonObject();

        profileObj.addProperty("profileName", p.getProfileName());
        profileObj.addProperty("replaceSignatures", p.getReplaceSignatures());
        profileObj.addProperty("argsType", String.valueOf(p.getArgsType()));

        if (p.getSourceFile().isPresent()) {
            SourceFile sf = p.getSourceFile().get();
            JsonObject sfObj = new JsonObject();
            sfObj.addProperty("fileName", sf.getFileName());
            profileObj.add("sourceFile", sfObj);
        }/*from   w  w w  .  j  av a 2 s  . co  m*/

        if (p.getTargetFile().isPresent()) {
            TargetFile tf = p.getTargetFile().get();
            JsonObject tfObj = new JsonObject();
            tfObj.addProperty("fileName", tf.getFileName());
            profileObj.add("targetFile", tfObj);
        }

        if (p.getJarsignerConfig().isPresent()) {
            JarsignerConfig jc = p.getJarsignerConfig().get();
            JsonObject jcObj = new JsonObject();
            jcObj.addProperty("alias", jc.getAlias());

            //
            // #1 storepass and keypass become temporary fields while the encrypted fields
            // are persisted
            //

            jcObj.addProperty("storepass", jc.getEncryptedStorepass());
            jcObj.addProperty("keypass", jc.getEncryptedKeypass());

            jcObj.addProperty("keystore", jc.getKeystore());
            jcObj.addProperty("verbose", jc.getVerbose());
            profileObj.add("jarsignerConfig", jcObj);
        }

        ps.add(profileObj);
    }

    return ps;
}