use of us.monoid.json.JSONArray 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;
}
use of us.monoid.json.JSONArray in project tdi-studio-se by Talend.
the class ExchangeWebService method searchInstalledExtensionJSONArray.
/**
*
* DOC hcyi Comment method "searchInstalledExtensionJSONArray".
*
* @return
*/
public static JSONArray searchInstalledExtensionJSONArray(String username, String passwordHash) {
JSONObject tokenMessage = new JSONObject();
JSONArray o = null;
try {
tokenMessage.put("username", username);
tokenMessage.put("passwordHash", passwordHash);
JSONObject token = new us.monoid.json.JSONObject();
token.put("installedExtension", tokenMessage);
String u = exchangeWSServer + "installedExtension.php?data=" + token;
JSONObject answer = readJsonFromUrl(u);
if (answer != null) {
JSONObject p = (JSONObject) answer.get("listInstalledExtension");
o = p.getJSONArray("extensions");
}
} catch (JSONException e) {
//
} catch (IOException e) {
e.printStackTrace();
}
return o;
}
use of us.monoid.json.JSONArray in project tdi-studio-se by Talend.
the class ExchangeWebService method searchContributedExtensionJSONArray.
/**
*
* DOC hcyi Comment method "searchContributedExtensionJSONArray".
*
* @return
*/
public static JSONArray searchContributedExtensionJSONArray(String username, String passwordHash) {
JSONObject tokenMessage = new JSONObject();
JSONArray o = null;
try {
tokenMessage.put("username", username);
tokenMessage.put("passwordHash", passwordHash);
JSONObject token = new us.monoid.json.JSONObject();
token.put("contributedExtension", tokenMessage);
String u = exchangeWSServer + "contributedExtension.php?data=" + token;
JSONObject answer = readJsonFromUrl(u);
if (answer != null) {
JSONObject p = (JSONObject) answer.get("listContributedExtension");
o = p.getJSONArray("extensions");
}
} catch (JSONException e) {
//
} catch (IOException e) {
e.printStackTrace();
}
return o;
}
use of us.monoid.json.JSONArray in project tdi-studio-se by Talend.
the class ComponentSearcher method getAvailableExtensionViewDetail.
public static ComponentExtension getAvailableExtensionViewDetail(String idExtension, String typeExtension) {
ComponentExtension extension = null;
try {
JSONObject extensionJSONObject = ExchangeWebService.searchExtensionViewDetail(idExtension, typeExtension);
Map<String, ComponentExtension> extensionsMap = new HashMap<String, ComponentExtension>();
extension = extensionsMap.get(extensionJSONObject.getString("label"));
if (extension == null) {
extension = ExchangeFactory.eINSTANCE.createComponentExtension();
extension.setIdExtension(extensionJSONObject.getString("idExtension"));
extension.setLabel(extensionJSONObject.getString("label"));
extension.setLastVersionAvailable(extensionJSONObject.getString("lastVersionAvailable"));
extension.setPublicationDate(formatter.parse(extensionJSONObject.getString("publicationDate")));
extension.setDescription(extensionJSONObject.getString("description"));
extension.setRate(extensionJSONObject.getString("rate"));
extension.setAuthor(extensionJSONObject.getString("author"));
//
List<AvailableExtensionViewDetail> reviews = new ArrayList<AvailableExtensionViewDetail>();
JSONArray o = extensionJSONObject.getJSONArray("Reviews");
int size = o.length();
for (int i = 0; i < size; i++) {
JSONObject review = o.getJSONObject(i);
AvailableExtensionViewDetail extensionViewDetail = ExchangeFactory.eINSTANCE.createAvailableExtensionViewDetail();
extensionViewDetail.setAuthor(review.getString("author"));
extensionViewDetail.setTitle(review.getString("title"));
extensionViewDetail.setComment(review.getString("comment"));
extensionViewDetail.setReviewrate(review.getString("rate"));
reviews.add(extensionViewDetail);
}
extensionsMap.put(extension.getIdExtension(), extension);
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
return extension;
}
use of us.monoid.json.JSONArray in project tdi-studio-se by Talend.
the class ComponentSearcher method getAvailableComponentExtensions.
/**
* Find available components.
*
* @param version The tos version.
* @param language The project language.
* @return
*/
public static List<ComponentExtension> getAvailableComponentExtensions(String typeExtensionTemp, String versionStudioTemp, ECodeLanguage language, String category) {
List<ComponentExtension> extensions = new ArrayList<ComponentExtension>();
try {
JSONArray extensionsJSONArray = ExchangeWebService.searchExtensionJSONArray(typeExtensionTemp, versionStudioTemp, category);
if (extensionsJSONArray != null) {
int size = extensionsJSONArray.length();
for (int i = 0; i < size; i++) {
JSONObject extensionObj = extensionsJSONArray.getJSONObject(i);
Map<String, ComponentExtension> extensionsMap = new HashMap<String, ComponentExtension>();
ComponentExtension extension = extensionsMap.get(extensionObj.getString("label"));
if (extension == null) {
extension = ExchangeFactory.eINSTANCE.createComponentExtension();
//
JSONObject extensionsViewDetailObj = ExchangeWebService.searchExtensionViewDetail(extensionObj.getString("idExtension"), "tos");
extension.setIdExtension(extensionObj.getString("idExtension"));
extension.setLabel(extensionObj.getString("label"));
extension.setAuthor(extensionObj.getString("author"));
extension.setRate(extensionObj.getString("rate"));
extension.setTypeExtension(extensionObj.getString("typeExtension"));
extension.setVersionExtension(extensionObj.getString("versionExtension"));
if (extensionsViewDetailObj.length() > 0) {
extension.setLastVersionAvailable(extensionsViewDetailObj.getString("lastVersionAvailable"));
extension.setPublicationDate(formatter.parse(extensionsViewDetailObj.getString("publicationDate")));
extension.setDescription(extensionsViewDetailObj.getString("description"));
//
List<AvailableExtensionViewDetail> reviews = new ArrayList<AvailableExtensionViewDetail>();
if ((extensionsViewDetailObj.get("reviews")) != null && (extensionsViewDetailObj.get("reviews") instanceof JSONArray)) {
JSONArray o = extensionsViewDetailObj.getJSONArray("reviews");
int sumRate = 0;
int sizeDetail = o.length();
for (int j = 0; j < sizeDetail; j++) {
JSONObject review = o.getJSONObject(j);
AvailableExtensionViewDetail extensionViewDetail = ExchangeFactory.eINSTANCE.createAvailableExtensionViewDetail();
extensionViewDetail.setAuthor(review.getString("author"));
extensionViewDetail.setTitle(review.getString("title"));
extensionViewDetail.setComment(review.getString("comment"));
extensionViewDetail.setReviewrate(review.getString("rate"));
reviews.add(extensionViewDetail);
sumRate = sumRate + Integer.parseInt(review.getString("rate"));
}
//
if (sizeDetail > 0 && sumRate > 0) {
int im = sumRate / sizeDetail;
extension.setRate(im + "");
}
}
extension.getReviews().addAll((Collection<? extends AvailableExtensionViewDetail>) reviews);
}
extensionsMap.put(extension.getIdExtension(), extension);
extensions.add(extension);
}
}
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
return extensions;
}
Aggregations