use of us.monoid.json.JSONObject in project tdi-studio-se by Talend.
the class ExchangeWebService method insertReviewService.
/**
*
* DOC hcyi Comment method "insertReviewService".
*
* @param idExtension
* @param typeExtension
* @param username
* @param passwordHash
* @param title
* @param description
* @param userRating
* @return
*/
public static WebserviceStatus insertReviewService(String idExtension, String typeExtension, String username, String passwordHash, String title, String description, String userRating) {
WebserviceStatus ws = new WebserviceStatus();
ws.setResult(false);
Resty r = new Resty();
JSONObject tokenMessage = new JSONObject();
try {
tokenMessage.put("typeExtension", typeExtension);
tokenMessage.put("idExtension", idExtension);
tokenMessage.put("username", username);
tokenMessage.put("passwordHash", passwordHash);
tokenMessage.put("title", title);
tokenMessage.put("description", description);
tokenMessage.put("userRating", userRating);
JSONObject token = new us.monoid.json.JSONObject();
token.put("review", tokenMessage);
AbstractContent ac = Resty.content(token);
MultipartContent mpc = Resty.form(new FormData("data", ac));
TextResource textResult = r.text(exchangeWSServer + "downloadedExtension.php", mpc);
JSONObject resultObject = new JSONObject(textResult.toString());
//
Object object = resultObject.get("result");
if (object != null && object.equals("INSERT OK")) {
ws.setResult(true);
//$NON-NLS-1$
ws.setMessageException(Messages.getString("ExchangeWebService.insertReviewSuccessful"));
} else {
ws.setMessageException(object.toString());
}
} catch (JSONException e) {
ws.setMessageException(e.getMessage());
} catch (IOException e) {
e.printStackTrace();
ws.setMessageException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
ws.setMessageException(e.getMessage());
}
return ws;
}
use of us.monoid.json.JSONObject in project tdi-studio-se by Talend.
the class ExchangeWebService method searchCategoryExtensionJSONArray.
/**
*
* DOC hcyi Comment method "searchCategoryExtensionJSONArray".
*
* @param typeExtension
* @return
*/
public static List<Category> searchCategoryExtensionJSONArray(String typeExtension) {
List<Category> fCategorys = new ArrayList<Category>();
JSONObject tokenMessage = new JSONObject();
try {
tokenMessage.put("typeExtension", typeExtension);
JSONObject token = new us.monoid.json.JSONObject();
token.put("extension", tokenMessage);
String u = exchangeWSServer + "listCategoryExtension.php?data=" + token;
JSONObject resultObj = readJsonFromUrl(u);
if (resultObj != null) {
JSONObject p = (JSONObject) resultObj.get("listCategory");
JSONArray resultArry = p.getJSONArray("category");
if (resultArry != null) {
for (int i = 0; i < resultArry.length(); i++) {
JSONObject extensionObj = resultArry.getJSONObject(i);
if (extensionObj != null) {
Category fCategory = ExchangeFactory.eINSTANCE.createCategory();
fCategory.setCategoryId(extensionObj.getString("id_category"));
fCategory.setCategoryName(extensionObj.getString("name"));
fCategorys.add(fCategory);
}
}
}
}
} catch (JSONException e) {
//
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return fCategorys;
}
use of us.monoid.json.JSONObject in project tdi-studio-se by Talend.
the class ExchangeWebService method deleteExtensionService.
/**
*
* DOC hcyi Comment method "deleteExtensionService".
*
* @param idExtension
* @param typeExtension
* @param username
* @param passwordHash
* @return
*/
public static WebserviceStatus deleteExtensionService(String idExtension, String typeExtension, String username, String passwordHash) {
WebserviceStatus ws = new WebserviceStatus();
ws.setResult(false);
JSONObject tokenMessage = new JSONObject();
try {
tokenMessage.put("username", username);
tokenMessage.put("passwordHash", passwordHash);
tokenMessage.put("idExtension", idExtension);
tokenMessage.put("typeExtension", typeExtension);
JSONObject token = new us.monoid.json.JSONObject();
token.put("extension", tokenMessage);
String u = exchangeWSServer + "deleteExtension.php?data=" + token;
JSONObject result = readJsonFromUrl(u);
//
if (result != null) {
Object object = result.get("result");
if (object != null && object.equals("DELETE OK")) {
ws.setResult(true);
//$NON-NLS-1$
ws.setMessageException(Messages.getString("ExchangeWebService.deleteExtensionSuccessful"));
} else {
ws.setMessageException(object.toString());
}
}
} catch (JSONException e) {
//
ws.setMessageException(e.getMessage());
} catch (IOException e) {
e.printStackTrace();
ws.setMessageException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
ws.setMessageException(e.getMessage());
}
return ws;
}
use of us.monoid.json.JSONObject in project tdi-studio-se by Talend.
the class ExchangeWebService method readJsonFromUrl.
public static JSONObject readJsonFromUrl(String url) throws IOException {
InputStream is = new URL(url).openStream();
String jsonText = "";
JSONObject json = null;
try {
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
jsonText = readAll(rd);
json = new JSONObject(jsonText);
} catch (Exception e) {
System.out.println(jsonText);
} finally {
is.close();
}
return json;
}
use of us.monoid.json.JSONObject in project tdi-studio-se by Talend.
the class ExchangeWebService method searchVersionRevisionJSONArray.
/**
*
* DOC hcyi Comment method "searchVersionRevisionJSONArray".
*
* @param typeExtension
* @return
*/
public static List<VersionRevision> searchVersionRevisionJSONArray(String typeExtension) {
List<VersionRevision> fVersionRevisions = new ArrayList<VersionRevision>();
JSONObject tokenMessage = new JSONObject();
try {
tokenMessage.put("typeExtension", typeExtension);
JSONObject token = new us.monoid.json.JSONObject();
token.put("extension", tokenMessage);
String u = exchangeWSServer + "listVersionRevision.php?data=" + token;
JSONObject resultObj = readJsonFromUrl(u);
if (resultObj != null) {
JSONObject p = (JSONObject) resultObj.get("listVersion");
JSONArray resultArry = p.getJSONArray("version");
if (resultArry != null) {
for (int i = 0; i < resultArry.length(); i++) {
JSONObject extensionObj = resultArry.getJSONObject(i);
if (extensionObj != null) {
VersionRevision versionRevision = ExchangeFactory.eINSTANCE.createVersionRevision();
versionRevision.setVersionId(extensionObj.getString("id_version"));
versionRevision.setVersionName(extensionObj.getString("version"));
fVersionRevisions.add(versionRevision);
}
}
}
}
} catch (JSONException e) {
//
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return fVersionRevisions;
}
Aggregations