List of usage examples for org.json JSONArray get
public Object get(int index) throws JSONException
From source file:org.protorabbit.json.DefaultSerializer.java
public Object deSerialize(String jsonText, Class<?> targetClass) { if (jsonText == null) { return null; }//from ww w. j a v a 2 s . com // check for array jsonText = jsonText.trim(); if (jsonText.startsWith("[")) { try { JSONArray ja = new JSONArray(jsonText); List<Object> jal = new ArrayList<Object>(); for (int i = 0; i < ja.length(); i++) { try { Object jao = ja.get(i); Object targetObject = targetClass.newInstance(); deSerialize(jao, targetObject); jal.add(targetObject); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return jal; } catch (JSONException jex) { throw new RuntimeException("Error Parsing JSON:" + jex); } // check for object } else if (jsonText.startsWith("{")) { try { Object o = targetClass.newInstance(); deSerialize(jsonText, o); return o; } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } else { throw new RuntimeException("Error : Can only deserialize JSON objects or JSON arrays"); } return null; }
From source file:org.hyperledger.common.Base58Test.java
@Test public void base58encode() throws IOException, JSONException, HyperLedgerException { JSONArray testData = readObjectArray(BASE58_ENCODE); for (int i = 0; i < testData.length(); ++i) { JSONArray test = testData.getJSONArray(i); assertTrue(ByteUtils.toBase58(ByteUtils.fromHex(test.getString(0))).equals(test.get(1))); assertTrue(ByteUtils.toHex(ByteUtils.fromBase58(test.getString(1))).equals(test.get(0))); }//from ww w . j a va 2 s .c om }
From source file:com.maya.portAuthority.googleMaps.Instructions.java
/** * Receives a JSONObject and returns a Direction * /*w w w . j a va 2 s . c o m*/ * @param jsonObject * @return The Direction retrieved by the JSON Object */ public static List<Direction> parse(JSONObject jsonObject) throws Exception { List<Direction> directionsList = null; // returned direction Direction currentGDirection = null; // current direction List<Legs> legsList = null; // legs Legs currentLeg = null; // current leg List<Path> pathsList = null;// paths Path currentPath = null;// current path // JSON parts: JSONArray routes = null; JSONObject route = null; JSONObject bound = null; JSONArray legs = null; JSONObject leg = null; JSONArray steps = null; JSONObject step = null; String polyline = ""; try { routes = jsonObject.getJSONArray("routes"); LOGGER.info("routes found : " + routes.length()); directionsList = new ArrayList<Direction>(); // traverse routes for (int i = 0; i < routes.length(); i++) { route = (JSONObject) routes.get(i); legs = route.getJSONArray("legs"); LOGGER.info("route[" + i + "]contains " + legs.length() + " legs"); // traverse legs legsList = new ArrayList<Legs>(); for (int j = 0; j < legs.length(); j++) { leg = (JSONObject) legs.get(j); steps = leg.getJSONArray("steps"); LOGGER.info("route[" + i + "]:leg[" + j + "] contains " + steps.length() + " steps"); // traverse all steps pathsList = new ArrayList<Path>(); for (int k = 0; k < steps.length(); k++) { step = (JSONObject) steps.get(k); polyline = (String) ((JSONObject) (step).get("polyline")).get("points"); // Build the List of GDPoint that define the path List<Point> list = decodePoly(polyline); // Create the GDPath currentPath = new Path(list); currentPath.setDistance(((JSONObject) step.get("distance")).getInt("value")); currentPath.setDuration(((JSONObject) step.get("duration")).getInt("value")); currentPath.setHtmlText(step.getString("html_instructions")); currentPath.setTravelMode(step.getString("travel_mode")); LOGGER.info("routes[" + i + "]:legs[" + j + "]:Step[" + k + "] contains " + list.size() + " points"); // Add it to the list of Path of the Direction pathsList.add(currentPath); } // currentLeg = new Legs(pathsList); currentLeg.setDistance(((JSONObject) leg.get("distance")).getInt("value")); currentLeg.setmDuration(((JSONObject) leg.get("duration")).getInt("value")); currentLeg.setEndAddr(leg.getString("end_address")); currentLeg.setStartAddr(leg.getString("start_address")); legsList.add(currentLeg); LOGGER.info("Added a new Path and paths size is : " + pathsList.size()); } // Build the GDirection using the paths found currentGDirection = new Direction(legsList); bound = (JSONObject) route.get("bounds"); currentGDirection .setNorthEastBound(new Location(((JSONObject) bound.get("northeast")).getDouble("lat"), ((JSONObject) bound.get("northeast")).getDouble("lng"))); currentGDirection .setmSouthWestBound(new Location(((JSONObject) bound.get("southwest")).getDouble("lat"), ((JSONObject) bound.get("southwest")).getDouble("lng"))); currentGDirection.setCopyrights(route.getString("copyrights")); directionsList.add(currentGDirection); } } catch (JSONException e) { LOGGER.error("Parsing JSon from GoogleDirection Api failed, see stack trace below:", e); throw new Exception("Parsing JSon from GoogleDirection Api failed"); } catch (Exception e) { LOGGER.error("Parsing JSon from GoogleDirection Api failed, see stack trace below:", e); throw new Exception("Parsing JSon from GoogleDirection Api failed"); } return directionsList; }
From source file:org.araqne.confdb.file.Importer.java
private Object parse(JSONArray jsonarray) throws IOException { List<Object> list = new ArrayList<Object>(); for (int i = 0; i < jsonarray.length(); i++) { try {/*from ww w . ja v a2 s . com*/ Object o = jsonarray.get(i); if (o == JSONObject.NULL) list.add(null); else if (o instanceof JSONArray) list.add(parse((JSONArray) o)); else if (o instanceof JSONObject) list.add(parse((JSONObject) o)); else list.add(o); } catch (JSONException e) { logger.error("araqne confdb: cannot parse json", e); throw new IOException(e); } } return list; }
From source file:edu.asu.msse.sgowdru.moviemediaplayerrpc.SearchMovie.java
boolean isMovieInRPC(String searchString) { JSONArray arr; boolean isInRPC = false; try {/*from www .j a v a 2 s .c o m*/ //Call async method to retrieve the movie list names and check in the movie list MethodInformation mi = new MethodInformation("http://10.0.2.2:8080/", "getTitles", new String[] {}); JSONObject ac = new AsyncCollectionConnect().execute(mi).get(); arr = (JSONArray) ac.get("result"); //Check if the list has our movie name and set flag for (int i = 0; i < arr.length(); i++) { System.out.println(arr.get(i)); String mv = (String) arr.get(i); if (mv.equalsIgnoreCase(searchString)) { isInRPC = true; break; } } } catch (Exception ex) { android.util.Log.w(this.getClass().getSimpleName(), "Exception creating adapter: " + ex.getMessage()); } return isInRPC; }
From source file:org.eclipse.orion.server.tests.servlets.git.GitLogTest.java
@Test public void testLogWithTag() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); IPath[] clonePaths = createTestProjects(workspaceLocation); for (IPath clonePath : clonePaths) { // clone a repo JSONObject clone = clone(clonePath); String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION); // get project metadata WebRequest request = getGetRequest(cloneContentLocation); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject project = new JSONObject(response.getText()); JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT); String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD); JSONArray commitsArray = log(gitHeadUri); assertEquals(1, commitsArray.length()); String commitUri = commitsArray.getJSONObject(0).getString(ProtocolConstants.KEY_LOCATION); JSONObject updatedCommit = tag(commitUri, "tag"); JSONArray tagsArray = updatedCommit.getJSONArray(GitConstants.KEY_TAGS); assertEquals(1, tagsArray.length()); assertEquals(Constants.R_TAGS + "tag", tagsArray.getJSONObject(0).get(ProtocolConstants.KEY_FULL_NAME)); commitsArray = log(gitHeadUri);/*from www. j ava 2s.c o m*/ assertEquals(1, commitsArray.length()); tagsArray = commitsArray.getJSONObject(0).getJSONArray(GitConstants.KEY_TAGS); assertEquals(1, tagsArray.length()); assertEquals(Constants.R_TAGS + "tag", tagsArray.getJSONObject(0).get(ProtocolConstants.KEY_FULL_NAME)); } }
From source file:org.eclipse.orion.server.tests.servlets.git.GitLogTest.java
@Test public void testLogWithBranch() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); IPath[] clonePaths = createTestProjects(workspaceLocation); for (IPath clonePath : clonePaths) { // clone a repo JSONObject clone = clone(clonePath); String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION); String branchesLocation = clone.getString(GitConstants.KEY_BRANCH); // get project metadata WebRequest request = getGetRequest(cloneContentLocation); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject project = new JSONObject(response.getText()); JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT); String gitCommitUri = gitSection.getString(GitConstants.KEY_COMMIT); JSONArray commitsArray = log(gitCommitUri); assertEquals(1, commitsArray.length()); branch(branchesLocation, "branch"); commitsArray = log(gitCommitUri); assertEquals(1, commitsArray.length()); JSONArray branchesArray = commitsArray.getJSONObject(0).getJSONArray(GitConstants.KEY_BRANCHES); assertEquals(3, branchesArray.length()); assertEquals(Constants.R_HEADS + "branch", branchesArray.getJSONObject(0).get(ProtocolConstants.KEY_FULL_NAME)); assertEquals(Constants.R_HEADS + Constants.MASTER, branchesArray.getJSONObject(1).get(ProtocolConstants.KEY_FULL_NAME)); assertEquals(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + Constants.MASTER, branchesArray.getJSONObject(2).get(ProtocolConstants.KEY_FULL_NAME)); }//from ww w . j ava 2 s.c o m }
From source file:org.eclipse.orion.server.tests.servlets.git.GitLogTest.java
@Test public void testLogAllBranches() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); IPath[] clonePaths = createTestProjects(workspaceLocation); for (IPath clonePath : clonePaths) { // clone a repo JSONObject clone = clone(clonePath); String cloneLocation = clone.getString(ProtocolConstants.KEY_LOCATION); String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION); String branchesLocation = clone.getString(GitConstants.KEY_BRANCH); String gitCommitUri = clone.getString(GitConstants.KEY_COMMIT); // get project metadata WebRequest request = getGetRequest(cloneContentLocation); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject project = new JSONObject(response.getText()); JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT); String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD); // create branch final String newBranchName = "branch"; branch(branchesLocation, newBranchName); // modify JSONObject testTxt = getChild(project, "test.txt"); modifyFile(testTxt, "first change"); addFile(testTxt);// w ww .j ava 2 s .c o m // commit1 Thread.sleep(1000); // TODO: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=370696#c1 request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "commit1", false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // checkout "branch" checkoutBranch(cloneLocation, newBranchName); // modify again modifyFile(testTxt, "second change"); addFile(testTxt); // commit2 Thread.sleep(1000); // TODO: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=370696#c1 request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "commit2", false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // get standard log for HEAD - only init and commit2 should be visible JSONArray commitsArray = log(gitHeadUri); assertEquals(2, commitsArray.length()); JSONObject commit = commitsArray.getJSONObject(0); assertEquals("commit2", commit.get(GitConstants.KEY_COMMIT_MESSAGE)); commit = commitsArray.getJSONObject(1); assertEquals("Initial commit", commit.get(GitConstants.KEY_COMMIT_MESSAGE)); // get log for all branches - all 3 commits should be listed commitsArray = log(gitCommitUri); assertEquals(3, commitsArray.length()); commit = commitsArray.getJSONObject(0); assertEquals("commit2", commit.get(GitConstants.KEY_COMMIT_MESSAGE)); JSONArray branchesArray = commit.getJSONArray(GitConstants.KEY_BRANCHES); assertEquals(1, branchesArray.length()); assertEquals(Constants.R_HEADS + newBranchName, branchesArray.getJSONObject(0).get(ProtocolConstants.KEY_FULL_NAME)); commit = commitsArray.getJSONObject(1); assertEquals("commit1", commit.get(GitConstants.KEY_COMMIT_MESSAGE)); branchesArray = commit.getJSONArray(GitConstants.KEY_BRANCHES); assertEquals(1, branchesArray.length()); assertEquals(Constants.R_HEADS + Constants.MASTER, branchesArray.getJSONObject(0).get(ProtocolConstants.KEY_FULL_NAME)); commit = commitsArray.getJSONObject(2); assertEquals("Initial commit", commit.get(GitConstants.KEY_COMMIT_MESSAGE)); branchesArray = commit.getJSONArray(GitConstants.KEY_BRANCHES); assertEquals(1, branchesArray.length()); assertEquals(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + Constants.MASTER, branchesArray.getJSONObject(0).get(ProtocolConstants.KEY_FULL_NAME)); } }
From source file:com.roiland.crm.sm.core.service.impl.ProjectAPIImpl.java
/** * @see com.roiland.crm.core.service.ProjectAPI#createProject(java.lang.String, java.lang.String, com.roiland.crm.core.model.Project, com.roiland.crm.core.model.TracePlan) *//*from www .j av a2s .c om*/ @Override public Boolean createProject(String userID, String dealerOrgID, Project project, TracePlan tracePlan) throws ResponseException { try { if (userID == null || dealerOrgID == null) { throw new ResponseException("userID or dealerOrgID is null."); } JSONObject params = new JSONObject(); params.put("userID", userID); params.put("dealerOrgID", dealerOrgID); //?? Log.d(tag, "createProject() >> customerID ================== " + project.getCustomer().getCustomerID()); params.put("customerID", project.getCustomer().getCustomerID()); params.put("custName", project.getCustomer().getCustName()); params.put("custFromCode", StringUtils.convertNull(project.getCustomer().getCustFromCode())); params.put("custTypeCode", StringUtils.convertNull(project.getCustomer().getCustTypeCode())); params.put("infoFromCode", StringUtils.convertNull(project.getCustomer().getInfoFromCode())); params.put("collectFromCode", StringUtils.convertNull(project.getCustomer().getCollectFromCode())); params.put("custMobile", StringUtils.convertNull(project.getCustomer().getCustMobile())); params.put("custOtherPhone", StringUtils.convertNull(project.getCustomer().getCustOtherPhone())); params.put("genderCode", StringUtils.convertNull(project.getCustomer().getGenderCode())); params.put("birthday", StringUtils.isEmpty(project.getCustomer().getBirthday()) ? "" : Long.parseLong(project.getCustomer().getBirthday())); params.put("idTypeCode", StringUtils.convertNull(project.getCustomer().getIdTypeCode())); params.put("idNumber", StringUtils.convertNull(project.getCustomer().getIdNumber())); params.put("provinceCode", StringUtils.convertNull(project.getCustomer().getProvinceCode())); params.put("cityCode", StringUtils.convertNull(project.getCustomer().getCityCode())); params.put("districtCode", StringUtils.convertNull(project.getCustomer().getDistrictCode())); params.put("qq", StringUtils.convertNull(project.getCustomer().getQq())); params.put("address", StringUtils.convertNull(project.getCustomer().getAddress())); params.put("postcode", StringUtils.convertNull(project.getCustomer().getPostcode())); params.put("email", StringUtils.convertNull(project.getCustomer().getEmail())); params.put("convContactTime", StringUtils.convertNull(project.getCustomer().getConvContactTime())); params.put("convContactTimeCode", StringUtils.convertNull(project.getCustomer().getConvContactTimeCode())); params.put("expectContactWayCode", StringUtils.convertNull(project.getCustomer().getExpectContactWayCode())); params.put("fax", StringUtils.convertNull(project.getCustomer().getFax())); params.put("existingCarCode", StringUtils.convertNull(project.getCustomer().getExistingCarCode())); params.put("existingCar", StringUtils.convertNull(project.getCustomer().getExistingCar())); params.put("existingCarBrand", StringUtils.convertNull(project.getCustomer().getExistingCarBrand())); params.put("industryCode", StringUtils.convertNull(project.getCustomer().getIndustryCode())); params.put("positionCode", StringUtils.convertNull(project.getCustomer().getPositionCode())); params.put("educationCode", StringUtils.convertNull(project.getCustomer().getEducationCode())); params.put("industry", StringUtils.convertNull(project.getCustomer().getIndustry())); params.put("position", StringUtils.convertNull(project.getCustomer().getPosition())); params.put("education", StringUtils.convertNull(project.getCustomer().getEducation())); params.put("custInterestCode1", StringUtils.convertNull(project.getCustomer().getCustInterestCode1())); params.put("custInterestCode2", StringUtils.convertNull(project.getCustomer().getCustInterestCode2())); params.put("custInterestCode3", StringUtils.convertNull(project.getCustomer().getCustInterestCode3())); params.put("existLisenPlate", StringUtils.convertNull(project.getCustomer().getExistLisenPlate())); params.put("enterpTypeCode", StringUtils.convertNull(project.getCustomer().getEnterpTypeCode())); params.put("enterpPeopleCountCode", StringUtils.convertNull(project.getCustomer().getEnterpPeopleCountCode())); params.put("registeredCapitalCode", StringUtils.convertNull(project.getCustomer().getRegisteredCapitalCode())); params.put("compeCarModelCode", project.getCustomer().getCompeCarModelCode()); params.put("rebuyStoreCustTag", project.getCustomer().getRebuyStoreCustTag()); params.put("rebuyOnlineCustTag", project.getCustomer().getRebuyOnlineCustTag()); params.put("changeCustTag", project.getCustomer().getChangeCustTag()); params.put("loanCustTag", project.getCustomer().getLoanCustTag()); params.put("headerQuartCustTag", project.getCustomer().getHeaderQuartCustTag()); params.put("regularCustTag", project.getCustomer().getRegularCustTag()); params.put("regularCustCode", StringUtils.convertNull(project.getCustomer().getRegularCustCode())); params.put("regularCust", StringUtils.convertNull(project.getCustomer().getRegularCust())); params.put("bigCustTag", project.getCustomer().getBigCustTag()); params.put("bigCusts", StringUtils.convertNull(project.getCustomer().getBigCusts())); params.put("bigCustsCode", StringUtils.convertNull(project.getCustomer().getBigCustsCode())); params.put("custComment", StringUtils.convertNull(project.getCustomer().getCustComment())); params.put("dormancy", (project.getCustomer().getDormancy() != null ? project.getCustomer().getDormancy() : false)); params.put("updateCustInfo", project.getCustomer().isUpdateCustInfo()); params.put("brandCode", StringUtils.convertNull(project.getPurchaseCarIntention().getBrandCode())); params.put("modelCode", StringUtils.convertNull(project.getPurchaseCarIntention().getModelCode())); params.put("outsideColorCode", StringUtils.convertNull(project.getPurchaseCarIntention().getOutsideColorCode())); params.put("insideColorCode", StringUtils.convertNull(project.getPurchaseCarIntention().getInsideColorCode())); params.put("insideColorCheck", project.getPurchaseCarIntention().isInsideColorCheck()); params.put("carConfigurationCode", StringUtils.convertNull(project.getPurchaseCarIntention().getCarConfigurationCode())); params.put("salesQuote", "".equals(project.getPurchaseCarIntention().getSalesQuote()) ? null : project.getPurchaseCarIntention().getSalesQuote()); params.put("dealPriceInterval", StringUtils.convertNull(project.getPurchaseCarIntention().getDealPriceInterval())); params.put("dealPriceIntervalCode", StringUtils.convertNull(project.getPurchaseCarIntention().getDealPriceIntervalCode())); params.put("payment", StringUtils.convertNull(project.getPurchaseCarIntention().getPayment())); params.put("paymentCode", StringUtils.convertNull(project.getPurchaseCarIntention().getPaymentCode())); params.put("preorderCount", StringUtils.isEmpty(project.getPurchaseCarIntention().getPreorderCount()) ? 1 : Integer.parseInt(project.getPurchaseCarIntention().getPreorderCount())); params.put("preorderDate", project.getPurchaseCarIntention().getPreorderDate()); params.put("flowStatusCode", StringUtils.convertNull(project.getPurchaseCarIntention().getFlowStatusCode())); params.put("flowStatus", StringUtils.convertNull(project.getPurchaseCarIntention().getFlowStatus())); params.put("dealPossibility", StringUtils.convertNull(project.getPurchaseCarIntention().getDealPossibility())); params.put("purchMotivationCode", "".equals(project.getPurchaseCarIntention().getPurchMotivationCode()) ? null : project.getPurchaseCarIntention().getPurchMotivationCode()); params.put("chassisNo", StringUtils.convertNull(project.getPurchaseCarIntention().getChassisNo())); params.put("engineNo", StringUtils.convertNull(project.getPurchaseCarIntention().getEngineNo())); params.put("licensePlate", StringUtils.convertNull(project.getPurchaseCarIntention().getLicensePlate())); params.put("licensePropCode", StringUtils.convertNull(project.getPurchaseCarIntention().getLicensePropCode())); params.put("licenseProp", StringUtils.convertNull(project.getPurchaseCarIntention().getLicenseProp())); params.put("pickupDate", parsingLong(project.getPurchaseCarIntention().getPickupDate())); if (parsingLong(project.getPurchaseCarIntention().getPickupDate()) == 0) params.put("pickupDate", null); else params.put("pickupDate", parsingLong(project.getPurchaseCarIntention().getPickupDate())); params.put("preorderTag", Boolean.parseBoolean(project.getPurchaseCarIntention().getPreorderTag())); params.put("giveupTag", project.getPurchaseCarIntention().isGiveupTag() != null ? project.getPurchaseCarIntention().isGiveupTag() : null); params.put("giveupReason", StringUtils.convertNull(project.getPurchaseCarIntention().getGiveupReason())); params.put("giveupReasonCode", StringUtils.convertNull(project.getPurchaseCarIntention().getGiveupReasonCode())); params.put("invoiceTitle", StringUtils.convertNull(project.getPurchaseCarIntention().getInvoiceTitle())); params.put("projectComment", StringUtils.convertNull(project.getPurchaseCarIntention().getProjectComment())); params.put("isInsideColorCheck", project.getPurchaseCarIntention().isInsideColorCheck() != null ? project.getPurchaseCarIntention().isInsideColorCheck() ? "1" : "0" : "0"); params.put("abandonFlag", project.getPurchaseCarIntention().getAbandonFlag() != null ? project.getPurchaseCarIntention().getAbandonFlag() : "0"); if (tracePlan != null) { params.put("activityTypeCode", tracePlan.getActivityTypeCode()); params.put("executeTime", tracePlan.getExecuteTime()); params.put("executeStatus", tracePlan.getExecuteStatus()); params.put("executeStatusCode", tracePlan.getExecuteStatusCode()); params.put("activityContent", StringUtils.convertNull(tracePlan.getActivityContent())); params.put("contactResultCode", StringUtils.convertNull(tracePlan.getContactResultCode())); params.put("custFeedback", StringUtils.convertNull(tracePlan.getCustFeedback())); params.put("collcustomerId", tracePlan.getCollcustomerId()); } RLHttpResponse response = getHttpClient() .executePostJSON(getURLAddress(URLContact.METHOD_CREATE_PROJECT), params, null); if (response.isSuccess()) { String data = getSimpleString(response); JSONObject result = new JSONObject(data); String node = null; String error = null; JSONArray nodeArray = result.names(); if (nodeArray != null) { for (int i = 0; i < nodeArray.length(); i++) { node = nodeArray.get(i).toString(); if (node.equalsIgnoreCase("success")) { Boolean success = Boolean.parseBoolean(result.getString("success")); if (success) { project.setProjectID(result.getString("projectID")); project.getCustomer().setProjectID(result.getString("projectID")); project.getCustomer().setCustomerID(result.getString("customerID")); return true; } } else if (node.equalsIgnoreCase("validate_error")) { error = parsingValidation(result.getJSONObject(node)); throw new ResponseException(error); } } } } throw new ResponseException(500); } catch (IOException e) { Log.e(tag, "Connection network error.", e); throw new ResponseException(e); } catch (JSONException e) { Log.e(tag, "Parsing data error.", e); throw new ResponseException(e); } }
From source file:com.roiland.crm.sm.core.service.impl.ProjectAPIImpl.java
/** * @see com.roiland.crm.core.service.ProjectAPI#updateProjectInfo(java.lang.String, java.lang.String, com.roiland.crm.core.model.Project) *//* www. j ava 2s .c o m*/ @Override public Boolean updateProjectInfo(String userID, String dealerOrgID, Project project) throws ResponseException { try { if (userID == null || dealerOrgID == null) { throw new ResponseException("userID or dealerOrgID is null."); } JSONObject params = new JSONObject(); params.put("userID", userID); params.put("dealerOrgID", dealerOrgID); params.put("projectID", project.getCustomer().getProjectID()); params.put("customerID", project.getCustomer().getCustomerID()); params.put("custName", project.getCustomer().getCustName()); params.put("custFromCode", project.getCustomer().getCustFromCode()); params.put("custTypeCode", project.getCustomer().getCustTypeCode()); params.put("infoFromCode", project.getCustomer().getInfoFromCode()); params.put("collectFromCode", project.getCustomer().getCollectFromCode()); params.put("custMobile", project.getCustomer().getCustMobile()); params.put("custOtherPhone", project.getCustomer().getCustOtherPhone()); params.put("genderCode", project.getCustomer().getGenderCode()); Log.d(tag, "updateProjectInfo() >> birthday ================== " + project.getCustomer().getBirthday()); params.put("birthday", StringUtils.isEmpty(project.getCustomer().getBirthday()) ? "" : Long.parseLong(project.getCustomer().getBirthday())); params.put("idTypeCode", project.getCustomer().getIdTypeCode()); params.put("idNumber", project.getCustomer().getIdNumber()); params.put("provinceCode", project.getCustomer().getProvinceCode()); params.put("cityCode", project.getCustomer().getCityCode()); params.put("districtCode", project.getCustomer().getDistrictCode()); params.put("qq", project.getCustomer().getQq()); params.put("address", project.getCustomer().getAddress()); params.put("postcode", project.getCustomer().getPostcode()); params.put("email", project.getCustomer().getEmail()); params.put("convContactTime", project.getCustomer().getConvContactTime()); params.put("convContactTimeCode", project.getCustomer().getConvContactTimeCode()); params.put("expectContactWayCode", project.getCustomer().getExpectContactWayCode()); params.put("fax", project.getCustomer().getFax()); params.put("existingCarCode", project.getCustomer().getExistingCarCode()); params.put("existingCar", project.getCustomer().getExistingCar()); params.put("existingCarBrand", project.getCustomer().getExistingCarBrand()); params.put("industryCode", project.getCustomer().getIndustryCode()); params.put("positionCode", project.getCustomer().getPositionCode()); params.put("educationCode", project.getCustomer().getEducationCode()); params.put("industry", project.getCustomer().getIndustry()); params.put("position", project.getCustomer().getPosition()); params.put("education", project.getCustomer().getEducation()); params.put("custInterestCode1", project.getCustomer().getCustInterestCode1()); params.put("custInterestCode2", project.getCustomer().getCustInterestCode2()); params.put("custInterestCode3", project.getCustomer().getCustInterestCode3()); params.put("existLisenPlate", project.getCustomer().getExistLisenPlate()); params.put("enterpTypeCode", project.getCustomer().getEnterpTypeCode()); params.put("enterpPeopleCountCode", project.getCustomer().getEnterpPeopleCountCode()); params.put("registeredCapitalCode", project.getCustomer().getRegisteredCapitalCode()); params.put("compeCarModelCode", project.getCustomer().getCompeCarModelCode()); params.put("rebuyStoreCustTag", project.getCustomer().getRebuyStoreCustTag()); params.put("rebuyOnlineCustTag", project.getCustomer().getRebuyOnlineCustTag()); params.put("changeCustTag", project.getCustomer().getChangeCustTag()); params.put("loanCustTag", project.getCustomer().getLoanCustTag()); params.put("headerQuartCustTag", project.getCustomer().getHeaderQuartCustTag()); params.put("regularCustTag", project.getCustomer().getRegularCustTag()); params.put("regularCustCode", StringUtils.convertNull(project.getCustomer().getRegularCustCode())); params.put("regularCust", StringUtils.convertNull(project.getCustomer().getRegularCust())); params.put("bigCustTag", project.getCustomer().getBigCustTag()); params.put("bigCusts", project.getCustomer().getBigCusts()); params.put("bigCustsCode", project.getCustomer().getBigCustsCode()); params.put("custComment", project.getCustomer().getCustComment()); params.put("dormancy", (project.getCustomer().getDormancy() != null ? project.getCustomer().getDormancy() : false)); params.put("brandCode", project.getPurchaseCarIntention().getBrandCode()); params.put("modelCode", project.getPurchaseCarIntention().getModelCode()); params.put("outsideColorCode", project.getPurchaseCarIntention().getOutsideColorCode()); params.put("insideColorCode", project.getPurchaseCarIntention().getInsideColorCode()); params.put("insideColorCheck", project.getPurchaseCarIntention().isInsideColorCheck() ? true : false); params.put("carConfigurationCode", project.getPurchaseCarIntention().getCarConfigurationCode()); params.put("salesQuote", "".equals(project.getPurchaseCarIntention().getSalesQuote()) ? null : project.getPurchaseCarIntention().getSalesQuote()); params.put("dealPriceInterval", project.getPurchaseCarIntention().getDealPriceInterval()); params.put("dealPriceIntervalCode", project.getPurchaseCarIntention().getDealPriceIntervalCode()); params.put("payment", project.getPurchaseCarIntention().getPayment()); params.put("paymentCode", project.getPurchaseCarIntention().getPaymentCode()); params.put("preorderCount", StringUtils.isEmpty(project.getPurchaseCarIntention().getPreorderCount()) ? 1 : Integer.parseInt(project.getPurchaseCarIntention().getPreorderCount())); params.put("preorderDate", project.getPurchaseCarIntention().getPreorderDate()); params.put("flowStatusCode", project.getPurchaseCarIntention().getFlowStatusCode()); params.put("flowStatus", project.getPurchaseCarIntention().getFlowStatus()); params.put("dealPossibility", project.getPurchaseCarIntention().getDealPossibility()); params.put("purchMotivationCode", "".equals(project.getPurchaseCarIntention().getPurchMotivationCode()) ? null : project.getPurchaseCarIntention().getPurchMotivationCode()); params.put("chassisNo", project.getPurchaseCarIntention().getChassisNo()); params.put("engineNo", project.getPurchaseCarIntention().getEngineNo()); params.put("licensePlate", project.getPurchaseCarIntention().getLicensePlate()); params.put("licensePropCode", project.getPurchaseCarIntention().getLicensePropCode()); params.put("licenseProp", project.getPurchaseCarIntention().getLicenseProp()); params.put("pickupDate", parsingLong(project.getPurchaseCarIntention().getPickupDate())); if (parsingLong(project.getPurchaseCarIntention().getPickupDate()) == 0) params.put("pickupDate", "null"); else params.put("pickupDate", parsingLong(project.getPurchaseCarIntention().getPickupDate())); params.put("preorderTag", Boolean.parseBoolean(project.getPurchaseCarIntention().getPreorderTag())); params.put("giveupTag", project.getPurchaseCarIntention().isGiveupTag() != null ? project.getPurchaseCarIntention().isGiveupTag() : false); params.put("giveupReason", project.getPurchaseCarIntention().getGiveupReason()); params.put("giveupReasonCode", project.getPurchaseCarIntention().getGiveupReasonCode()); params.put("invoiceTitle", project.getPurchaseCarIntention().getInvoiceTitle()); params.put("projectComment", project.getPurchaseCarIntention().getProjectComment()); params.put("isInsideColorCheck", project.getPurchaseCarIntention().isInsideColorCheck() != null ? project.getPurchaseCarIntention().isInsideColorCheck() ? "1" : "0" : "0"); RLHttpResponse response = getHttpClient() .executePostJSON((getURLAddress(URLContact.METHOD_UPDATE_PROJECT_INFO)), params, null); if (response.isSuccess()) { String data = getSimpleString(response); JSONObject result = new JSONObject(data); String node = null; String error = null; JSONArray nodeArray = result.names(); if (nodeArray != null) { for (int i = 0; i < nodeArray.length(); i++) { node = nodeArray.get(i).toString(); if (node.equalsIgnoreCase("success")) { Boolean success = Boolean.parseBoolean(result.getString("success")); if (success) { return true; } } else if (node.equalsIgnoreCase("validate_error")) { error = parsingValidation(result.getJSONObject(node)); throw new ResponseException(error); } } } } throw new ResponseException(500); } catch (IOException e) { Log.e(tag, "Connection network error.", e); throw new ResponseException(e); } catch (JSONException e) { Log.e(tag, "Parsing data error.", e); throw new ResponseException(e); } }