use of us.monoid.json.JSONObject 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;
}
use of us.monoid.json.JSONObject in project tdi-studio-se by Talend.
the class ComponentSearcher method getInstalledExtensions.
/**
* Find Installed components.
*
* @param version The tos version.
* @param language The project language.
* @return
*/
public static List<ComponentExtension> getInstalledExtensions(String version, ECodeLanguage language, String username, String passwordHash) {
List<ComponentExtension> extensions = new ArrayList<ComponentExtension>();
try {
JSONArray extensionsJSONArray = ExchangeWebService.searchInstalledExtensionJSONArray(username, passwordHash);
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("name"));
if (extension == null) {
extension = ExchangeFactory.eINSTANCE.createComponentExtension();
//
extension.setIdExtension(extensionObj.getString("idExtension"));
extension.setTypeExtension(extensionObj.getString("typeExtension"));
extension.setLabel(extensionObj.getString("name"));
extension.setDateDownload(formatter.parse(extensionObj.getString("dateDownload")));
extension.setDownloadedVersion(extensionObj.getString("downloadedVersion"));
extension.setVersionExtension(extensionObj.getString("lastVersion"));
extensionsMap.put(extension.getIdExtension(), extension);
extensions.add(extension);
}
}
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
return extensions;
}
use of us.monoid.json.JSONObject in project tbd-studio-se by Talend.
the class HadoopClusterTokenCollector method getTokenDetailsForCurrentProject.
@Override
protected JSONObject getTokenDetailsForCurrentProject() throws Exception {
JSONObject typesHadoop = new JSONObject();
for (IRepositoryViewObject rvo : ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.getType(HADOOPCLUSTER))) {
HadoopClusterConnectionItem item = (HadoopClusterConnectionItem) rvo.getProperty().getItem();
HadoopClusterConnection connection = (HadoopClusterConnection) item.getConnection();
// $NON-NLS-1$
String distrib = connection.getDistribution() + "/" + connection.getDfVersion();
int nbDbTypes = 1;
if (typesHadoop.has(distrib)) {
nbDbTypes = typesHadoop.getInt(distrib);
nbDbTypes++;
}
typesHadoop.put(distrib, nbDbTypes);
}
JSONObject hadoopCluster = new JSONObject();
JSONObject types = new JSONObject();
types.put("types", typesHadoop);
hadoopCluster.put(HADOOPCLUSTER, types);
return hadoopCluster;
}
use of us.monoid.json.JSONObject in project tdi-studio-se by Talend.
the class ExchangeWebService method insertionExtensionService.
/**
*
* DOC hcyi Comment method "insertionExtensionService".
*
* @param typeExtension
* @param username
* @param passwordHash
* @param category
* @param name
* @param description
* @return
*/
public static WebserviceStatus insertionExtensionService(String typeExtension, String username, String passwordHash, String category, String name, String description) {
WebserviceStatus ws = new WebserviceStatus();
ws.setResult(false);
Resty r = new Resty();
JSONObject tokenMessage = new JSONObject();
try {
tokenMessage.put("username", username);
tokenMessage.put("passwordHash", passwordHash);
tokenMessage.put("typeExtension", typeExtension);
tokenMessage.put("category", category);
tokenMessage.put("name", name);
tokenMessage.put("description", description);
JSONObject token = new us.monoid.json.JSONObject();
token.put("newExtension", tokenMessage);
AbstractContent ac = Resty.content(token);
MultipartContent mpc = Resty.form(new FormData("data", ac));
TextResource textResult = r.text(exchangeWSServer + "publishExtension.php", mpc);
JSONObject resultObject = new JSONObject(textResult.toString());
JSONObject object = (JSONObject) resultObject.get("resultNewExtension");
String idExtension = object.getString("idExtension");
//
ws.setValue(idExtension);
ws.setResult(true);
//$NON-NLS-1$
ws.setMessageException(Messages.getString("ExchangeWebService.insertionExtensionSuccessful"));
} 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 insertionRevisionService.
/**
*
* DOC hcyi Comment method "insertionRevisionService".
*
* @param idExtension
* @param typeExtension
* @param username
* @param passwordHash
* @param version
* @param listVersionCompatibles
* @param filename
* @param content
* @param description
* @param agreement
* @return
*/
public static WebserviceStatus insertionRevisionService(String idExtension, String typeExtension, String username, String passwordHash, String version, String listVersionCompatibles, String filename, String content, String description, String agreement) {
byte[] fileBytes = null;
try {
File f = new File(filename);
if (f != null) {
FileInputStream fis = new FileInputStream(f);
if (fis != null) {
int len = fis.available();
fileBytes = new byte[len];
fis.read(fileBytes);
}
}
} catch (Exception e) {
//
}
WebserviceStatus ws = new WebserviceStatus();
ws.setResult(false);
Resty r = new Resty();
JSONObject tokenMessage = new JSONObject();
try {
tokenMessage.put("username", username);
tokenMessage.put("passwordHash", passwordHash);
tokenMessage.put("idExtension", idExtension);
tokenMessage.put("typeExtension", typeExtension);
tokenMessage.put("version", version);
tokenMessage.put("versionCompatibles", listVersionCompatibles);
tokenMessage.put("filename", new Path(filename).lastSegment());
tokenMessage.put("content", asHex(fileBytes));
tokenMessage.put("description", description == null ? "" : description.replace(" ", "%20"));
tokenMessage.put("agreement", agreement);
JSONObject token = new us.monoid.json.JSONObject();
token.put("newRevision", tokenMessage);
AbstractContent ac = Resty.content(token);
MultipartContent mpc = Resty.form(new FormData("data", ac));
TextResource textResult = r.text(exchangeWSServer + "addRevision.php", mpc);
JSONObject resultObject = new JSONObject(textResult.toString());
JSONObject result = (JSONObject) resultObject.get("resultNewRevision");
String idRevision = result.getString("idRevision");
//
ws.setValue(idRevision);
ws.setResult(true);
//$NON-NLS-1$
ws.setMessageException(Messages.getString("ExchangeWebService.insertionRevisionSuccessful"));
} catch (JSONException e) {
ws.setMessageException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
ws.setMessageException(e.getMessage());
}
return ws;
}
Aggregations