Example usage for org.json.simple JSONObject put

List of usage examples for org.json.simple JSONObject put

Introduction

In this page you can find the example usage for org.json.simple JSONObject put.

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:com.raphfrk.craftproxyclient.net.auth.AuthManager.java

@SuppressWarnings("unchecked")
public static JSONObject authAccessToken(String email, String password) {

    String clientToken = null;/*from   w  ww . j  a  v  a 2 s .  com*/

    JSONObject fileObj = readAccessToken();

    if (fileObj != null) {
        clientToken = (String) fileObj.get("clientToken");
    }

    if (clientToken == null) {
        byte[] arr = new byte[32];
        Crypt.getBytes(arr);
        clientToken = UUID.nameUUIDFromBytes(arr).toString();
    }

    JSONObject obj = new JSONObject();

    JSONObject agent = new JSONObject();
    agent.put("name", "Minecraft");
    agent.put("version", 1);

    obj.put("agent", agent);

    obj.put("username", email);
    obj.put("password", password);
    obj.put("clientToken", clientToken);

    JSONObject reply = sendRequest(obj, "authenticate");

    if (reply == null) {
        return null;
    }

    JSONObject stripped = stripLoginDetails(reply, true);
    if (stripped == null) {
        return null;
    }

    writeAccessToken(stripped);

    AuthManager.loginDetails = stripped;

    return reply;
}

From source file:com.raphfrk.craftproxyclient.net.auth.AuthManager.java

@SuppressWarnings("unchecked")
private static JSONObject stripLoginDetails(JSONObject obj, boolean includeUsername) {
    if (obj == null) {
        return null;
    }/*from  ww  w.j  a v a  2 s .com*/
    String clientToken = (String) obj.get("clientToken");
    String accessToken = (String) obj.get("accessToken");

    if (clientToken == null || accessToken == null) {
        return null;
    }

    JSONObject selectedProfile = (JSONObject) obj.get("selectedProfile");

    if (selectedProfile == null) {
        return null;
    }

    String username = (String) selectedProfile.get("name");
    if (username == null) {
        return null;
    }

    String id = (String) selectedProfile.get("id");
    if (id == null) {
        return null;
    }

    JSONObject stripped = new JSONObject();

    stripped.put("accessToken", accessToken);
    stripped.put("clientToken", clientToken);

    if (includeUsername) {
        JSONObject selectedProfileNew = new JSONObject();
        selectedProfileNew.put("name", username);
        selectedProfileNew.put("id", id);

        stripped.put("selectedProfile", selectedProfileNew);
    }
    return stripped;

}

From source file:com.fujitsu.dc.test.jersey.box.odatacol.schema.complextypeproperty.ComplexTypePropertyUtils.java

/**
 * ComplexTypeProperty?./*from   w ww .  j a v a2  s.  c  o  m*/
 * @param cell ??
 * @param box ??
 * @param collection ??
 * @param srcComplexTypePropertyName ?ComplexTypeProperty??
 * @param srcComplexTypeName ?ComplexType??
 * @param complexTypePropertyName ??ComplexTypeProperty??
 * @param complexTypeName ??ComplexType??
 * @param type Property?Type
 * @param nullable Property?Nullable
 * @param defaultValue Property?DefaultValue
 * @param collectionKind Property?collectionKind
 * @return ?
 */
@SuppressWarnings("unchecked")
public static DcResponse update(String cell, String box, String collection, String srcComplexTypePropertyName,
        String srcComplexTypeName, String complexTypePropertyName, String complexTypeName, String type,
        Boolean nullable, Object defaultValue, String collectionKind) {

    // ???
    JSONObject body = new JSONObject();
    body.put("Name", complexTypePropertyName);
    body.put("_ComplexType.Name", complexTypeName);
    body.put("Type", type);
    body.put("Nullable", nullable);
    body.put("DefaultValue", defaultValue);
    body.put("CollectionKind", collectionKind);

    return update(cell, box, collection, srcComplexTypePropertyName, srcComplexTypeName, body);

}

From source file:io.personium.test.jersey.box.odatacol.schema.complextypeproperty.ComplexTypePropertyUtils.java

/**
 * ComplexTypeProperty?./*from w ww .  j av a 2 s.com*/
 * @param cell ??
 * @param box ??
 * @param collection ??
 * @param srcComplexTypePropertyName ?ComplexTypeProperty??
 * @param srcComplexTypeName ?ComplexType??
 * @param complexTypePropertyName ??ComplexTypeProperty??
 * @param complexTypeName ??ComplexType??
 * @param type Property?Type
 * @param nullable Property?Nullable
 * @param defaultValue Property?DefaultValue
 * @param collectionKind Property?collectionKind
 * @return ?
 */
@SuppressWarnings("unchecked")
public static PersoniumResponse update(String cell, String box, String collection,
        String srcComplexTypePropertyName, String srcComplexTypeName, String complexTypePropertyName,
        String complexTypeName, String type, Boolean nullable, Object defaultValue, String collectionKind) {

    // ???
    JSONObject body = new JSONObject();
    body.put("Name", complexTypePropertyName);
    body.put("_ComplexType.Name", complexTypeName);
    body.put("Type", type);
    body.put("Nullable", nullable);
    body.put("DefaultValue", defaultValue);
    body.put("CollectionKind", collectionKind);

    return update(cell, box, collection, srcComplexTypePropertyName, srcComplexTypeName, body);

}

From source file:gov.nih.nci.rembrandt.web.ajax.DynamicListHelper.java

public static String getGeneAliasesList(String commaGenes) {
    //accepts a single gene, or a comma delim list of strings
    JSONArray aliases = new JSONArray();
    commaGenes = commaGenes.replace(" ", "");
    List<String> geneList = Arrays.asList(commaGenes.split(","));
    try {/* ww  w . j a  v  a2 s . c o  m*/
        Map<String, List<AllGeneAliasLookup>> validMap = DataValidator.searchGeneKeyWordList(geneList);
        if (validMap != null) {
            for (String symbol : geneList) {
                JSONObject a = new JSONObject();
                a.put("original", symbol);

                if (DataValidator.isGeneSymbolFound(symbol)) {
                    //valid, no aliases
                    a.put("status", "valid");
                } else {
                    List<AllGeneAliasLookup> allGeneAliasLookupList = validMap.get(symbol);
                    if (allGeneAliasLookupList != null) {
                        JSONArray ala = new JSONArray();
                        a.put("status", "hasAliases");
                        for (AllGeneAliasLookup allGeneAliasLookup : allGeneAliasLookupList) {
                            JSONObject alo = new JSONObject();
                            alo.put("symbol",
                                    (allGeneAliasLookup.getApprovedSymbol() != null)
                                            ? allGeneAliasLookup.getApprovedSymbol()
                                            : "N/A");
                            alo.put("name",
                                    (allGeneAliasLookup.getApprovedName() != null)
                                            ? allGeneAliasLookup.getApprovedName()
                                            : "N/A");
                            alo.put("alias",
                                    (allGeneAliasLookup.getAlias() != null) ? allGeneAliasLookup.getAlias()
                                            : "N/A");
                            ala.add(alo);
                        }
                        a.put("aliases", ala);
                    } else { //no symbol found
                        a.put("status", "invalid");
                        //                     System.out.println("Symbol:"+symbol+"\t"+ "Invalid symbol or not in the database."+"\n");   
                    }
                }
                aliases.add(a);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return aliases.toString();
}

From source file:agileinterop.AgileInterop.java

private static JSONObject getRelatedPSRs(String body) throws APIException, ParseException {
    // Parse body as JSON
    JSONParser parser = new JSONParser();
    JSONArray jsonBody = (JSONArray) parser.parse(body);

    Map<String, List<String>> data = new HashMap<>();

    for (Object psrNumber : jsonBody) {
        List<String> relatedPSRNumbers = Agile.getRelatedPSRs((String) psrNumber);
        data.put((String) psrNumber, relatedPSRNumbers);
    }//from   www.  jav  a2 s. co m

    JSONObject obj = new JSONObject();
    obj.put("data", data);
    return obj;
}

From source file:com.fujitsu.dc.test.jersey.box.odatacol.schema.complextypeproperty.ComplexTypePropertyUtils.java

/**
 * ComplexTypeProperty?./*www .j  av a2s .c  o m*/
 * @param cell ??
 * @param box ??
 * @param collection ??
 * @param srcComplexTypePropertyName ?ComplexTypeProperty??
 * @param srcComplexTypeName ?ComplexType??
 * @param complexTypePropertyName ??ComplexTypeProperty??
 * @param complexTypeName ??ComplexType??
 * @param type Property?Type
 * @param nullable Property?Nullable
 * @param defaultValue Property?DefaultValue
 * @param collectionKind Property?collectionKind
 * @return ?
 */
@SuppressWarnings("unchecked")
public static DcResponse create(String cell, String box, String collection, String srcComplexTypePropertyName,
        String srcComplexTypeName, String complexTypePropertyName, String complexTypeName, String type,
        Boolean nullable, Object defaultValue, String collectionKind) {

    // ???
    JSONObject body = new JSONObject();
    body.put("Name", complexTypePropertyName);
    body.put("_ComplexType.Name", complexTypeName);
    body.put("Type", type);
    body.put("Nullable", nullable);
    body.put("DefaultValue", defaultValue);
    body.put("CollectionKind", collectionKind);

    // 
    DcRequest req = DcRequest.post(UrlUtils.complexTypeProperty(cell, box, collection, null, null));
    req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
    req.addStringBody(body.toJSONString());

    // 
    return AbstractCase.request(req);
}

From source file:com.fujitsu.dc.test.jersey.box.odatacol.schema.complextypeproperty.ComplexTypePropertyUtils.java

/**
 * ComplexTypePropertyComplexType??NP??.
 * @param token /*from   www  .  j  a  v  a 2 s .c  o m*/
 * @param cell ??
 * @param box ??
 * @param collection ??
 * @param complexTypeName complexType??
 * @param complexTypePropertyName complexTypePropertyName??
 * @param type ComplexTypeProperty?Type
 * @param nullable ComplexTypeProperty?Nullable
 * @param defaultValue ComplexTypeProperty?DefaultValue
 * @param collectionKind ComplexTypeProperty?collectionKind
 * @param code ??
 * @return ?
 */
@SuppressWarnings("unchecked")
public static TResponse createViaComplexTypePropertyNP(String token, String cell, String box, String collection,
        String complexTypeName, String complexTypePropertyName, String type, Boolean nullable,
        String defaultValue, String collectionKind, int code) {

    // ???
    JSONObject body = new JSONObject();
    body.put("Name", complexTypePropertyName);
    body.put("_ComplexType.Name", complexTypeName);
    body.put("Type", type);
    body.put("Nullable", nullable);
    body.put("DefaultValue", defaultValue);
    body.put("CollectionKind", collectionKind);

    TResponse res = Http.request("box/odatacol/schema/createViaNP.txt").with("cell", cell).with("box", box)
            .with("collection", collection).with("accept", MediaType.APPLICATION_JSON)
            .with("contentType", MediaType.APPLICATION_JSON).with("token", DcCoreConfig.getMasterToken())
            .with("entityType", "ComplexType").with("id", complexTypeName)
            .with("navPropName", "_ComplexTypeProperty").with("body", body.toJSONString()).returns()
            .statusCode(code).debug();
    return res;
}

From source file:io.personium.test.jersey.box.odatacol.schema.complextypeproperty.ComplexTypePropertyUtils.java

/**
 * ComplexTypePropertyComplexType??NP??.
 * @param token /*  w w  w.j av a2 s.  c  o m*/
 * @param cell ??
 * @param box ??
 * @param collection ??
 * @param complexTypeName complexType??
 * @param complexTypePropertyName complexTypePropertyName??
 * @param type ComplexTypeProperty?Type
 * @param nullable ComplexTypeProperty?Nullable
 * @param defaultValue ComplexTypeProperty?DefaultValue
 * @param collectionKind ComplexTypeProperty?collectionKind
 * @param code ??
 * @return ?
 */
@SuppressWarnings("unchecked")
public static TResponse createViaComplexTypePropertyNP(String token, String cell, String box, String collection,
        String complexTypeName, String complexTypePropertyName, String type, Boolean nullable,
        String defaultValue, String collectionKind, int code) {

    // ???
    JSONObject body = new JSONObject();
    body.put("Name", complexTypePropertyName);
    body.put("_ComplexType.Name", complexTypeName);
    body.put("Type", type);
    body.put("Nullable", nullable);
    body.put("DefaultValue", defaultValue);
    body.put("CollectionKind", collectionKind);

    TResponse res = Http.request("box/odatacol/schema/createViaNP.txt").with("cell", cell).with("box", box)
            .with("collection", collection).with("accept", MediaType.APPLICATION_JSON)
            .with("contentType", MediaType.APPLICATION_JSON).with("token", PersoniumUnitConfig.getMasterToken())
            .with("entityType", "ComplexType").with("id", complexTypeName)
            .with("navPropName", "_ComplexTypeProperty").with("body", body.toJSONString()).returns()
            .statusCode(code).debug();
    return res;
}

From source file:io.personium.test.jersey.box.odatacol.schema.complextypeproperty.ComplexTypePropertyUtils.java

/**
 * ComplexTypeProperty?.//from  w  w w .j av  a  2s  .  c om
 * @param cell ??
 * @param box ??
 * @param collection ??
 * @param srcComplexTypePropertyName ?ComplexTypeProperty??
 * @param srcComplexTypeName ?ComplexType??
 * @param complexTypePropertyName ??ComplexTypeProperty??
 * @param complexTypeName ??ComplexType??
 * @param type Property?Type
 * @param nullable Property?Nullable
 * @param defaultValue Property?DefaultValue
 * @param collectionKind Property?collectionKind
 * @return ?
 */
@SuppressWarnings("unchecked")
public static PersoniumResponse create(String cell, String box, String collection,
        String srcComplexTypePropertyName, String srcComplexTypeName, String complexTypePropertyName,
        String complexTypeName, String type, Boolean nullable, Object defaultValue, String collectionKind) {

    // ???
    JSONObject body = new JSONObject();
    body.put("Name", complexTypePropertyName);
    body.put("_ComplexType.Name", complexTypeName);
    body.put("Type", type);
    body.put("Nullable", nullable);
    body.put("DefaultValue", defaultValue);
    body.put("CollectionKind", collectionKind);

    // 
    PersoniumRequest req = PersoniumRequest
            .post(UrlUtils.complexTypeProperty(cell, box, collection, null, null));
    req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
    req.addStringBody(body.toJSONString());

    // 
    return AbstractCase.request(req);
}