Search in sources :

Example 21 with JSONObject

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;
}
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 22 with JSONObject

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;
}
Also used : 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 23 with JSONObject

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;
}
Also used : JSONObject(us.monoid.json.JSONObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) HadoopClusterConnection(org.talend.repository.model.hadoopcluster.HadoopClusterConnection) HadoopClusterConnectionItem(org.talend.repository.model.hadoopcluster.HadoopClusterConnectionItem)

Example 24 with JSONObject

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;
}
Also used : FormData(us.monoid.web.FormData) TextResource(us.monoid.web.TextResource) JSONObject(us.monoid.json.JSONObject) AbstractContent(us.monoid.web.AbstractContent) Resty(us.monoid.web.Resty) JSONException(us.monoid.json.JSONException) MultipartContent(us.monoid.web.mime.MultipartContent) IOException(java.io.IOException) JSONException(us.monoid.json.JSONException) IOException(java.io.IOException)

Example 25 with JSONObject

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;
}
Also used : Path(org.eclipse.core.runtime.Path) FormData(us.monoid.web.FormData) TextResource(us.monoid.web.TextResource) AbstractContent(us.monoid.web.AbstractContent) JSONException(us.monoid.json.JSONException) MultipartContent(us.monoid.web.mime.MultipartContent) FileInputStream(java.io.FileInputStream) JSONException(us.monoid.json.JSONException) IOException(java.io.IOException) JSONObject(us.monoid.json.JSONObject) Resty(us.monoid.web.Resty) File(java.io.File)

Aggregations

JSONObject (us.monoid.json.JSONObject)32 JSONException (us.monoid.json.JSONException)23 IOException (java.io.IOException)16 JSONArray (us.monoid.json.JSONArray)15 ArrayList (java.util.ArrayList)9 AbstractContent (us.monoid.web.AbstractContent)5 FormData (us.monoid.web.FormData)5 Resty (us.monoid.web.Resty)5 TextResource (us.monoid.web.TextResource)5 MultipartContent (us.monoid.web.mime.MultipartContent)5 HashMap (java.util.HashMap)4 ComponentExtension (org.talend.designer.components.exchange.model.ComponentExtension)4 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)3 PersistenceException (org.talend.commons.exception.PersistenceException)3 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)3 FileInputStream (java.io.FileInputStream)2 EList (org.eclipse.emf.common.util.EList)2 Project (org.talend.core.model.general.Project)2 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)2 RoutineItem (org.talend.core.model.properties.RoutineItem)2