Search in sources :

Example 6 with JSONArray

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;
}
Also used : JSONObject(us.monoid.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(us.monoid.json.JSONArray) JSONException(us.monoid.json.JSONException) VersionRevision(org.talend.designer.components.exchange.model.VersionRevision) IOException(java.io.IOException) JSONException(us.monoid.json.JSONException) IOException(java.io.IOException)

Example 7 with JSONArray

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;
}
Also used : JSONObject(us.monoid.json.JSONObject) JSONArray(us.monoid.json.JSONArray) JSONException(us.monoid.json.JSONException) IOException(java.io.IOException)

Example 8 with JSONArray

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;
}
Also used : JSONObject(us.monoid.json.JSONObject) JSONArray(us.monoid.json.JSONArray) JSONException(us.monoid.json.JSONException) IOException(java.io.IOException)

Example 9 with JSONArray

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;
}
Also used : AvailableExtensionViewDetail(org.talend.designer.components.exchange.model.AvailableExtensionViewDetail) JSONObject(us.monoid.json.JSONObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONArray(us.monoid.json.JSONArray) ComponentExtension(org.talend.designer.components.exchange.model.ComponentExtension)

Example 10 with JSONArray

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;
}
Also used : AvailableExtensionViewDetail(org.talend.designer.components.exchange.model.AvailableExtensionViewDetail) JSONObject(us.monoid.json.JSONObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONArray(us.monoid.json.JSONArray) ComponentExtension(org.talend.designer.components.exchange.model.ComponentExtension)

Aggregations

JSONArray (us.monoid.json.JSONArray)15 JSONObject (us.monoid.json.JSONObject)15 JSONException (us.monoid.json.JSONException)9 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)5 HashMap (java.util.HashMap)4 ComponentExtension (org.talend.designer.components.exchange.model.ComponentExtension)4 EList (org.eclipse.emf.common.util.EList)2 AvailableExtensionViewDetail (org.talend.designer.components.exchange.model.AvailableExtensionViewDetail)2 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 IEditorReference (org.eclipse.ui.IEditorReference)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 IComponent (org.talend.core.model.components.IComponent)1 IProcess2 (org.talend.core.model.process.IProcess2)1 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)1 FolderItem (org.talend.core.model.properties.FolderItem)1