List of usage examples for org.json.simple JSONObject containsKey
boolean containsKey(Object key);
From source file:org.wso2.carbon.apimgt.rest.api.publisher.v1.utils.mappings.APIMappingUtil.java
/** * This method converts endpointconfig json string to corresponding APIEndpointDTO objects * * @param endpointConfig string//ww w. jav a2s . com * @return APIEndpointDTO List of apiEndpointDTO */ public static List<APIEndpointDTO> getAPIEndpointDTOFromEndpointConfig(String endpointConfig) throws ParseException { //todo improve to support multiple endpoints. List<APIEndpointDTO> apiEndpointDTOList = new ArrayList<>(); if (endpointConfig != null) { JSONParser parser = new JSONParser(); JSONObject endpointConfigJson = (JSONObject) parser.parse(endpointConfig); String endpointProtocolType = (String) endpointConfigJson .get(APIConstants.API_ENDPOINT_CONFIG_PROTOCOL_TYPE); if (endpointConfigJson.containsKey(APIConstants.API_DATA_PRODUCTION_ENDPOINTS) && isEndpointURLNonEmpty(endpointConfigJson.get(APIConstants.API_DATA_PRODUCTION_ENDPOINTS))) { JSONObject prodEPConfig = (JSONObject) endpointConfigJson .get(APIConstants.API_DATA_PRODUCTION_ENDPOINTS); APIEndpointDTO apiEndpointDTO = convertToAPIEndpointDTO(APIConstants.API_DATA_PRODUCTION_ENDPOINTS, prodEPConfig, endpointProtocolType); apiEndpointDTOList.add(apiEndpointDTO); } if (endpointConfigJson.containsKey(APIConstants.API_DATA_SANDBOX_ENDPOINTS) && isEndpointURLNonEmpty(endpointConfigJson.get(APIConstants.API_DATA_SANDBOX_ENDPOINTS))) { JSONObject sandboxEPConfig = (JSONObject) endpointConfigJson .get(APIConstants.API_DATA_SANDBOX_ENDPOINTS); APIEndpointDTO apiEndpointDTO = convertToAPIEndpointDTO(APIConstants.API_DATA_SANDBOX_ENDPOINTS, sandboxEPConfig, endpointProtocolType); apiEndpointDTOList.add(apiEndpointDTO); } } return apiEndpointDTOList; }
From source file:org.wso2.carbon.apimgt.swagger.migration.utils.ResourceUtil.java
/** * Modify the resource in registry location '1.2' to be compatible with the * AM 1.8. add the/*from www . java 2 s . co m*/ * parameters to operations element, add 'nickname' variable and the * 'basePath' variable * * @param resource * resource inside the 1.2 location * @param allParameters * map containing all the parameters extracted from api-doc * containing * resources for swagger 1.1 * @param allOperations * @param basePath * base path for the resource * @return modified resource for the api */ public static String getUpdatedSwagger12Resource(JSONObject resource, Map<String, JSONArray> allParameters, Map<String, JSONObject> allOperations, String basePath) { JSONArray apis = (JSONArray) resource.get(Constants.API_DOC_12_APIS); for (int i = 0; i < apis.size(); i++) { JSONObject apiInfo = (JSONObject) apis.get(i); String path = (String) apiInfo.get(Constants.API_DOC_12_PATH); JSONArray operations = (JSONArray) apiInfo.get(Constants.API_DOC_12_OPERATIONS); for (int j = 0; j < operations.size(); j++) { JSONObject operation = (JSONObject) operations.get(j); String method = (String) operation.get(Constants.API_DOC_12_METHOD); // nickname is method name + "_" + path without starting "/" // symbol String nickname = method.toLowerCase() + "_" + path.substring(1); // add nickname variable operation.put(Constants.API_DOC_12_NICKNAME, nickname); String key = path + "_" + method.toLowerCase(); JSONArray parameters = new JSONArray(); if (allParameters.containsKey(key)) { parameters = allParameters.get(key); //setting the 'type' to 'string' if this variable is missing for (int m = 0; m < parameters.size(); m++) { JSONObject para = (JSONObject) parameters.get(m); if (!para.containsKey("type")) { para.put("type", "string"); } } } else { parameters = getDefaultParameters(); } //if there are parameters already in this JSONArray existingParams = (JSONArray) operation.get(Constants.API_DOC_12_PARAMETERS); if (existingParams.isEmpty()) { JSONParser parser = new JSONParser(); if (path.contains("{")) { List<String> urlParams = ResourceUtil.getURLTempateParams(path); for (String p : urlParams) { try { JSONObject paramObj = (JSONObject) parser .parse(Constants.DEFAULT_PARAM_FOR_URL_TEMPLATE); paramObj.put("name", p); parameters.add(paramObj); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } // add parameters array operation.put(Constants.API_DOC_12_PARAMETERS, parameters); } else { for (int k = 0; k < existingParams.size(); k++) { parameters.add(existingParams.get(k)); } operation.put(Constants.API_DOC_12_PARAMETERS, parameters); } //updating the resource description and nickname using values in the swagger 1.1 doc if (allOperations.containsKey(key)) { //update info related to object JSONObject operationObj11 = allOperations.get(key); //add summery if (operationObj11.containsKey("summary")) { operation.put("summary", (String) operationObj11.get("summery")); } } } } // add basePath variable resource.put(Constants.API_DOC_12_BASE_PATH, basePath); return resource.toJSONString(); }
From source file:org.wso2.carbon.apimgt.swagger.migration.utils.ResourceUtil.java
/** * @param resource api-doc related to 1.1 definition * @param allParameters12 map containing all the parameters extracted * from each resource of swagger 1.2 * @return JSON string of the updated Swagger 1.1 definition */// www. j a va 2s . co m public static String getUpdatedSwagger11Resource(JSONObject resource, Map<String, JSONArray> allParameters12) { log.info("===================== getUpdatedSwagger11Resource ========================="); String resourcePath = (String) resource.get(Constants.API_DOC_11_RESOURCE_PATH); String apiVersion = (String) resource.get(Constants.API_DOC_11_API_VERSION); String resourcePathPrefix = resourcePath + "/" + apiVersion; log.info("resourcePath for 1.1 : " + resourcePath); log.info("apiVersion : " + apiVersion); log.info("resourcePathPrefix : " + resourcePathPrefix); JSONArray apis = (JSONArray) resource.get(Constants.API_DOC_11_APIS); for (Object api : apis) { JSONObject apiInfo = (JSONObject) api; log.info("\n\napiInfo : " + apiInfo.toJSONString()); String path = (String) apiInfo.get(Constants.API_DOC_11_PATH); path = path.substring(resourcePathPrefix.length()); JSONArray operations = (JSONArray) apiInfo.get(Constants.API_DOC_11_OPERATIONS); log.info("\n\noperations : " + operations.toJSONString()); for (Object operation1 : operations) { JSONObject operation = (JSONObject) operation1; log.info("\n\noperation : " + operation); String method = (String) operation.get(Constants.API_DOC_11_METHOD); String key = path + "_" + method.toLowerCase(); log.info("\nkey : " + key); //if there are parameters already in this JSONArray existingParams = (JSONArray) operation.get(Constants.API_DOC_11_PARAMETERS); log.info("\nexistingParams : " + existingParams); //maintain the list of original parameters to avoid duplicates JSONArray originalParams = existingParams; JSONArray parameters; if (allParameters12.containsKey(key)) { log.info("\nallParameters12.containsKey(key) : " + key); parameters = allParameters12.get(key); log.info("\nparameters : " + parameters.toJSONString()); //setting the 'type' to 'string' if this variable is missing for (int m = 0; m < parameters.size(); m++) { JSONObject para = (JSONObject) parameters.get(m); log.info("\n\npara : " + para.toJSONString()); if (noSuchParameter(originalParams, (String) para.get(Constants.API_DOC_11_PARAM_NAME), (String) para.get(Constants.API_DOC_11_PARAM_TYPE))) { log.info("\nnoSuchParameter"); String dataType = ""; if (para.containsKey(Constants.API_DOC_12_DATA_TYPE)) { log.info("\npara.containsKey(Constants.API_DOC_12_DATA_TYPE)"); dataType = (String) para.get(Constants.API_DOC_12_DATA_TYPE); } log.info("\ndataType : " + dataType); para.put(Constants.API_DOC_11_DATA_TYPE, dataType); para.remove(Constants.API_DOC_12_DATA_TYPE); existingParams.add(existingParams.size(), para); } } } log.info("\nexistingParams after loop : " + existingParams); operation.put(Constants.API_DOC_12_PARAMETERS, existingParams); } } return resource.toJSONString(); }
From source file:org.wso2.carbon.appmgt.impl.utils.AppManagerUtil.java
public static boolean isSandboxEndpointsExists(WebApp api) { JSONParser parser = new JSONParser(); JSONObject config = null; try {/*w w w.j a va 2 s .co m*/ config = (JSONObject) parser.parse(api.getEndpointConfig()); if (config.containsKey("sandbox_endpoints")) { return true; } } catch (ParseException e) { log.error("Unable to parse endpoint config JSON", e); } catch (ClassCastException e) { log.error("Unable to parse endpoint config JSON", e); } return false; }
From source file:org.wso2.carbon.appmgt.impl.utils.AppManagerUtil.java
public static boolean isProductionEndpointsExists(WebApp api) { JSONParser parser = new JSONParser(); JSONObject config = null; try {//www . jav a 2s. co m config = (JSONObject) parser.parse(api.getEndpointConfig()); if (config.containsKey("production_endpoints")) { return true; } } catch (ParseException e) { log.error("Unable to parse endpoint config JSON", e); } catch (ClassCastException e) { log.error("Unable to parse endpoint config JSON", e); } return false; }
From source file:org.wso2.carbon.dashboard.migratetool.DSMigrationTool.java
/** * update the blocks section of dashboard json in order to compatible with carbon-dashboards version 1.0.15+ * * @param blocksArray blocks array dashboard json */// w w w .j a v a 2 s .c o m protected void updateDashboardBlocks(JSONArray blocksArray) { JSONObject block = null; long col; long row; long size_y; long size_x; for (int i = 0; i < blocksArray.size(); i++) { block = (JSONObject) blocksArray.get(i); if (block.containsKey("col")) { col = (Long) block.get("col"); block.put("x", col - 1); block.remove("col"); } if (block.containsKey("row")) { row = (Long) block.get("row"); block.put("y", row - 1); block.remove("row"); } if (block.containsKey("size_x")) { size_x = (Long) block.get("size_x"); block.put("width", size_x); block.remove("size_x"); } if (block.containsKey("size_y")) { size_y = (Long) block.get("size_y"); block.put("height", size_y); block.remove("size_y"); } } }
From source file:org.wso2.carbon.device.mgt.output.adapter.http.HTTPEventAdapter.java
@Override public void publish(Object message, Map<String, String> dynamicProperties) { //Load dynamic properties String url = dynamicProperties.get(HTTPEventAdapterConstants.ADAPTER_MESSAGE_URL); Map<String, String> headers = this .extractHeaders(dynamicProperties.get(HTTPEventAdapterConstants.ADAPTER_HEADERS)); String payload = message.toString(); if ("true".equals(dynamicProperties.get(HTTPEventAdapterConstants.ADAPTER_MESSAGE_URL_TEMPLATED))) { contentType = "application/json"; payload = payload.replace("'", "\\\""); try {/* w ww. ja v a2 s .co m*/ JSONParser jsonParser = new JSONParser(); JSONObject jsonPayload = (JSONObject) jsonParser.parse(payload); List<String> matchList = new ArrayList<>(); Pattern regex = Pattern.compile("\\{(.*?)\\}"); Matcher regexMatcher = regex.matcher(url); while (regexMatcher.find()) {//Finds Matching Pattern in String matchList.add(regexMatcher.group(1));//Fetching Group from String } for (String str : matchList) { if (jsonPayload.containsKey(str)) { url = url.replace("{" + str + "}", jsonPayload.get(str).toString()); } } if (log.isDebugEnabled()) { log.debug("Modified url: " + url); } } catch (ParseException e) { log.error("Unable to parse request body to Json.", e); } } try { executorService.submit(new HTTPSender(url, payload, headers, httpClient)); } catch (RejectedExecutionException e) { EventAdapterUtil.logAndDrop(eventAdapterConfiguration.getName(), message, "Job queue is full", e, log, tenantId); } }
From source file:org.wso2.developerstudio.datamapper.diagram.tree.generator.SchemaTransformer.java
/** * generate the schema recursively//from w w w.ja v a 2s. c o m * * @param treeNodeModel * @param parent * @param root */ @SuppressWarnings("unchecked") private void recursiveSchemaGenerator(TreeNodeImpl treeNodeModel, JSONObject parent, JSONObject root) { if (treeNodeModel != null) { EList<Element> elemList = treeNodeModel.getElement(); EList<TreeNode> nodeList = treeNodeModel.getNode(); for (TreeNode node : nodeList) { String name = node.getName(); String schemaType = getPropertyKeyValuePairforTreeNode(node, JSON_SCHEMA_TYPE); String schemaArrayItemsID = getPropertyKeyValuePairforTreeNode(node, JSON_SCHEMA_ARRAY_ITEMS_ID); String schemaArrayItemsType = getPropertyKeyValuePairforTreeNode(node, JSON_SCHEMA_ARRAY_ITEMS_TYPE); String schemaID = getPropertyKeyValuePairforTreeNode(node, JSON_SCHEMA_ID); String attributeID = getPropertyKeyValuePairforTreeNode(node, JSON_SCHEMA_ATTRIBUTE_ID); String attributeType = getPropertyKeyValuePairforTreeNode(node, JSON_SCHEMA_ATTRIBUTE_TYPE); String propertiesId = getPropertyKeyValuePairforTreeNode(node, JSON_SCHEMA_PROPERTIES_ID); String objectValueBlockType = getPropertyKeyValuePairforTreeNode(node, JSON_SCHEMA_OBJECT_VALUE_TYPE); String objectElementIdentifier = getPropertyKeyValuePairforTreeNode(node, JSON_SCHEMA_OBJECT_ELEMENT_IDENTIFIERS_URL); String objectAddedAttributeID = getPropertyKeyValuePairforTreeNode(node, JSON_SCHEMA_ADDED_ATTRIBUTE_ID); String objectAddedAttributeType = getPropertyKeyValuePairforTreeNode(node, JSON_SCHEMA_ADDED_ATTRIBUTE_TYPE); String arrayValueBlockType = getPropertyKeyValuePairforTreeNode(node, JSON_SCHEMA_ARRAY_ITEMS_VALUE_TYPE); if (schemaType != null && schemaType.equals(JSON_SCHEMA_OBJECT)) { JSONObject nodeObject = new JSONObject(); JSONObject propertiesObject = new JSONObject(); JSONObject attributeObject = new JSONObject(); JSONObject valueObject = new JSONObject(); // Check if there are attributes in the child nodes of an // object when creating the tree by hand addedObjectHasAttributes = checkForAttributes(node); // Check if there are properties in the child nodes of an // object when creating the tree by hand addedObjectHasProperties = checkForProperties(node); // Check if there are namespaces in the object when creating // the tree by hand addedObjectNamespaces = checkValueFromPropertyKeyValuePair(node, JSON_SCHEMA_OBJECT_NAMESPACES); // Check if there are element identifiers in the object when creating // the tree by hand addedObjectElementIdentifiers = checkValueFromPropertyKeyValuePair(node, JSON_SCHEMA_OBJECT_ELEMENT_IDENTIFIERS); // If the iteration happens not because of attributes ( // properties), then // handle the other elements the object if (!hasAttributes) { insetIDAndTypeForJsonObject(node, nodeObject); // If object contains a value block then handle it ( // when generating and creating tree) if (objectValueBlockType != null) { valueObject.put(JSON_SCHEMA_TYPE, objectValueBlockType); nodeObject.put(JSON_SCHEMA_VALUE, valueObject); } //If an object doesn't contain properties, then avoid serializing the properties field EList<TreeNode> childList = node.getNode(); if (childList.size() > 0) { nodeObject.put(JSON_SCHEMA_PROPERTIES, propertiesObject); } parent.put(node.getName(), nodeObject); insertRequiredArray(nodeObject, node, false); // Handles attributes if (attributeID != null && attributeType != null) { hasAttributes = true; nodeObject.put(JSON_SCHEMA_ATTRIBUTES, attributeObject); parent.put(node.getName(), nodeObject); recursiveSchemaGenerator((TreeNodeImpl) node, nodeObject, root); hasAttributes = false; } // Handle properties when creating tree by hand if (addedObjectHasProperties) { // Fixing DEVTOOLESB-154 if (((TreeNodeImpl) node).getNode().size() > 0) { nodeObject.put(JSON_SCHEMA_PROPERTIES, propertiesObject); } } if (StringUtils.isNotEmpty(addedObjectNamespaces)) { // If namespaces are available when creating the // tree by hand then add those to the root elements if (!namespaceList.contains(addedObjectNamespaces)) { namespaceList.add(addedObjectNamespaces); } } if (StringUtils.isNotEmpty(objectElementIdentifier)) { // If element identifiers are available when creating the // tree by hand then add those to the root elements if (!namespaceList.contains(objectElementIdentifier)) { namespaceList.add(objectElementIdentifier); } } if (StringUtils.isNotEmpty(addedObjectElementIdentifiers)) { // If element identifiers are available when creating the // tree by hand then add those to the root elements if (!elementIdentifierList.contains(addedObjectElementIdentifiers)) { elementIdentifierList.add(addedObjectElementIdentifiers); } } // Handle attributes when creating tree by hand if (addedObjectHasAttributes) { // Fixing DEVTOOLESB-154 if (((TreeNodeImpl) node).getNode().size() > 0) { hasAttributes = true; nodeObject.put(JSON_SCHEMA_ATTRIBUTES, attributeObject); parent.put(node.getName(), nodeObject); recursiveSchemaGenerator((TreeNodeImpl) node, nodeObject, root); hasAttributes = false; } } recursiveSchemaGenerator((TreeNodeImpl) node, propertiesObject, root); } } else if (schemaType != null && schemaType.equals(JSON_SCHEMA_ARRAY)) { JSONObject arrayObject = new JSONObject(); JSONObject itemsObject = new JSONObject(); JSONArray arrayItemsObject = new JSONArray(); JSONObject attributeObject = new JSONObject(); JSONObject itemProperties = new JSONObject(); JSONObject valueObject = new JSONObject(); // Check if there are attributes in the child nodes of the // array when creating the tree by hand addedObjectHasAttributes = checkForAttributes(node); // Check if there are properties in the child nodes of the // array when creating the tree by hand addedObjectHasProperties = checkForProperties(node); // Check if there are namespaces in the array when creating // the tree by hand addedObjectNamespaces = checkValueFromPropertyKeyValuePair(node, JSON_SCHEMA_ARRAY_NAMESPACES); // Check if there are element identifiers in the array when creating // the tree by hand addedObjectElementIdentifiers = checkValueFromPropertyKeyValuePair(node, JSON_SCHEMA_ARRAY_ELEMENT_IDENTIFIERS); String arrayElementIdentifier = getPropertyKeyValuePairforTreeNode(node, JSON_SCHEMA_ARRAY_ELEMENT_IDENTIFIERS_URL); // If the iteration happens not because of attributes ( // properties), then // handle the other elements in the array if (!hasAttributes) { insetIDAndTypeForJsonObject(node, arrayObject); if (schemaArrayItemsID != null) { itemProperties.put(JSON_SCHEMA_ID, schemaArrayItemsID.replace("\\", "")); } if (schemaArrayItemsType != null) { itemProperties.put(JSON_SCHEMA_TYPE, schemaArrayItemsType); } insertRequiredArray(arrayObject, node, false); insertRequiredArray(itemProperties, node, true); parent.put(node.getName(), arrayObject); if (itemProperties.size() > 0) { arrayItemsObject.add(itemProperties); } arrayObject.put(JSON_SCHEMA_ITEMS, arrayItemsObject); if (((TreeNodeImpl) node).getNode().size() > 0) { // Handle properties in array //if (propertiesId != null) { itemProperties.put(JSON_SCHEMA_PROPERTIES, itemsObject); recursiveSchemaGenerator((TreeNodeImpl) node, itemsObject, root); //} // Handle attributes in array if (attributeID != null && attributeType != null) { hasAttributes = true; itemProperties.put(JSON_SCHEMA_ATTRIBUTES, attributeObject); recursiveSchemaGenerator((TreeNodeImpl) node, attributeObject, root); hasAttributes = false; } // handle value block ( when generating and creating // tree) if (arrayValueBlockType != null) { valueObject.put(JSON_SCHEMA_TYPE, arrayValueBlockType); itemProperties.put(JSON_SCHEMA_VALUE, valueObject); } /* * Handle type in items block based on the value * block when creating tree by hand "items": [{ * "id": "http://wso2jsonschema.org/phone/0", * "type": "object", "value":{ "type": "number" }, * "properties": { "ext": { "id": * "http://wso2jsonschema.org/phone/0/ext", "type": * "number" } }]} */ if (addedObjectHasAttributes || addedObjectHasProperties) { itemProperties.put(JSON_SCHEMA_TYPE, JSON_SCHEMA_OBJECT); } if (StringUtils.isNotEmpty(addedObjectNamespaces)) { // If namespaces are available when creating the // tree by hand then add those to the root // elements if (!namespaceList.contains(addedObjectNamespaces)) { namespaceList.add(addedObjectNamespaces); } } if (StringUtils.isNotEmpty(arrayElementIdentifier)) { // If identifiers are available when creating the // tree by hand then add those to the root // elements if (!namespaceList.contains(arrayElementIdentifier)) { namespaceList.add(arrayElementIdentifier); } } if (StringUtils.isNotEmpty(addedObjectElementIdentifiers)) { // If element identifiers are available when creating the // tree by hand then add those to the root // elements if (!elementIdentifierList.contains(addedObjectElementIdentifiers)) { elementIdentifierList.add(addedObjectElementIdentifiers); } } // Handle properties when creating tree by hand if (addedObjectHasProperties) { itemProperties.put(JSON_SCHEMA_PROPERTIES, itemsObject); recursiveSchemaGenerator((TreeNodeImpl) node, itemsObject, root); } // Handle attributes when creating tree by hand if (addedObjectHasAttributes) { hasAttributes = true; itemProperties.put(JSON_SCHEMA_ATTRIBUTES, attributeObject); recursiveSchemaGenerator((TreeNodeImpl) node, attributeObject, root); hasAttributes = false; } } else { /* * If array item doesn't contain attributes or * properties then set the user entered type as the * item's type "items": [{ "id": * "http://wso2jsonschema.org/phone/phone", "type" * :"number" }] */ if (!itemProperties.containsKey(JSON_SCHEMA_TYPE)) { itemProperties.put(JSON_SCHEMA_TYPE, arrayValueBlockType); } if (StringUtils.isNotEmpty(addedObjectNamespaces)) { // If namespaces are available when creating the // tree by hand then add those to the root // elements if (!namespaceList.contains(addedObjectNamespaces)) { namespaceList.add(addedObjectNamespaces); } } if (StringUtils.isNotEmpty(addedObjectElementIdentifiers)) { // If element identifiers are available when creating the // tree by hand then add those to the root // elements if (!elementIdentifierList.contains(addedObjectElementIdentifiers)) { elementIdentifierList.add(addedObjectElementIdentifiers); } } if (StringUtils.isNotEmpty(arrayElementIdentifier)) { // If identifiers are available when creating the // tree by hand then add those to the root // elements if (!namespaceList.contains(arrayElementIdentifier)) { namespaceList.add(arrayElementIdentifier); } } } } } else if (schemaType != null) { String fieldElementIdentifier = getPropertyKeyValuePairforTreeNode(node, JSON_SCHEMA_FIELD_ELEMENT_IDENTIFIERS_URL); // Adds attributes if (hasAttributes) { JSONObject elemObject = null; //If the attribute is an element identifier then set the id and type if (objectAddedAttributeID != null && objectAddedAttributeType != null) { elemObject = new JSONObject(); elemObject.put(JSON_SCHEMA_ID, objectAddedAttributeID); elemObject.put(JSON_SCHEMA_TYPE, objectAddedAttributeType); } else { elemObject = createElementObject(schemaID); elemObject.put(JSON_SCHEMA_TYPE, schemaType); } // ignore other elements comes from attribute iteration if (name.startsWith(PREFIX)) { // Check if there are namespaces in the attributes // when creating the tree by hand addedObjectNamespaces = checkValueFromPropertyKeyValuePair(node, JSON_SCHEMA_ATTRIBUTE_NAMESPACES); if (StringUtils.isNotEmpty(addedObjectNamespaces)) { // If namespaces are available add those to the // root elements if (!namespaceList.contains(addedObjectNamespaces)) { namespaceList.add(addedObjectNamespaces); } } if (StringUtils.isNotEmpty(fieldElementIdentifier)) { // If identifiers are available when creating the // tree by hand then add those to the root // elements if (!namespaceList.contains(fieldElementIdentifier)) { namespaceList.add(fieldElementIdentifier); } } addedObjectElementIdentifiers = checkValueFromPropertyKeyValuePair(node, JSON_SCHEMA_FIELD_ELEMENT_IDENTIFIERS); if (StringUtils.isNotEmpty(addedObjectElementIdentifiers)) { // If element identifiers are available when creating the // tree by hand then add those to the root // elements if (!elementIdentifierList.contains(addedObjectElementIdentifiers)) { elementIdentifierList.add(addedObjectElementIdentifiers); } } // Removes the @prefix String nodeName = node.getName().substring(1); if (((JSONObject) parent.get(JSON_SCHEMA_ATTRIBUTES)) != null) { ((JSONObject) parent.get(JSON_SCHEMA_ATTRIBUTES)).put(nodeName, elemObject); } else { parent.put(nodeName, elemObject); } } } else { JSONObject elemObject = createElementObject(schemaID); elemObject.put(JSON_SCHEMA_TYPE, schemaType); // ignore attributes comes with property iteration if (!name.startsWith(PREFIX)) { // Check if there are namespaces in the fields when // creating the tree by hand addedObjectNamespaces = checkValueFromPropertyKeyValuePair(node, JSON_SCHEMA_FIELD_NAMESPACES); if (StringUtils.isNotEmpty(addedObjectNamespaces)) { // If namespaces are available add those to the // root elements if (!namespaceList.contains(addedObjectNamespaces)) { namespaceList.add(addedObjectNamespaces); } } addedObjectElementIdentifiers = checkValueFromPropertyKeyValuePair(node, JSON_SCHEMA_FIELD_ELEMENT_IDENTIFIERS); if (StringUtils.isNotEmpty(addedObjectElementIdentifiers)) { // If element identifiers are available when creating the // tree by hand then add those to the root // elements if (!elementIdentifierList.contains(addedObjectElementIdentifiers)) { elementIdentifierList.add(addedObjectElementIdentifiers); } } if (StringUtils.isNotEmpty(fieldElementIdentifier)) { // If identifiers are available when creating the // tree by hand then add those to the root // elements if (!namespaceList.contains(fieldElementIdentifier)) { namespaceList.add(fieldElementIdentifier); } } parent.put(name, elemObject); if (node.getNode() != null) { // check if it contains attributes object if (((TreeNodeImpl) node).getNode().size() > 0) { JSONObject attributesObject = new JSONObject(); hasAttributes = true; elemObject.put(JSON_SCHEMA_ATTRIBUTES, attributesObject); recursiveSchemaGenerator((TreeNodeImpl) node, elemObject, root); hasAttributes = false; } } } } } } for (Element elem : elemList) { String schemaType = getPropertyKeyValuePairforElements(elem, JSON_SCHEMA_TYPE); String schemaID = getPropertyKeyValuePairforElements(elem, JSON_SCHEMA_ID); if (schemaType != null) { JSONObject elemObject = createElementObject(schemaID); elemObject.put(JSON_SCHEMA_TYPE, schemaType); parent.put(elem.getName(), elemObject); } } } }
From source file:org.wwscc.storage.SQLDataInterface.java
@Override public Map<String, Set<String>> getCarAttributes() { try {/* www. j a v a2 s. c o m*/ Map<String, Set<String>> ret = new HashMap<String, Set<String>>(); HashSet<String> make = new HashSet<String>(); HashSet<String> model = new HashSet<String>(); HashSet<String> color = new HashSet<String>(); ResultSet rs = executeSelect("select attr from cars", null); while (rs.next()) { JSONObject attr = (JSONObject) new JSONParser().parse(rs.getString("attr")); if (attr.containsKey("make")) make.add((String) attr.get("make")); if (attr.containsKey("model")) model.add((String) attr.get("model")); if (attr.containsKey("color")) color.add((String) attr.get("color")); } ret.put("make", make); ret.put("model", model); ret.put("color", color); return ret; } catch (Exception ioe) { logError("getCarAttributes", ioe); return null; } }
From source file:ovh.tgrhavoc.aibot.auth.YggdrasilAuthService.java
private void checkError(JSONObject response) throws AuthenticationException { if (response.containsKey("error")) { String error = (String) response.get("error"); String errorMessage = (String) response.get("errorMessage"); if (response.containsKey("cause")) { String errorCause = (String) response.get("cause"); throw new YggdrasilAuthenticationException(error, errorMessage, errorCause); } else//from ww w .jav a 2s . com throw new YggdrasilAuthenticationException(error, errorMessage); } }