Search in sources :

Example 16 with JSONObject

use of us.monoid.json.JSONObject 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 17 with JSONObject

use of us.monoid.json.JSONObject in project tdi-studio-se by Talend.

the class ExchangeWebService method updateRevisionService.

/**
     * 
     * DOC hcyi Comment method "updateRevisionService".
     * 
     * @param idExtension
     * @param typeExtension
     * @param username
     * @param passwordHash
     * @param version
     * @param listVersionCompatibles
     * @param description
     * @param agreement
     * @return
     */
public static WebserviceStatus updateRevisionService(String idRevision, String typeExtension, String username, String passwordHash, String version, String listVersionCompatibles, String description, String agreement) {
    WebserviceStatus ws = new WebserviceStatus();
    ws.setResult(false);
    JSONObject tokenMessage = new JSONObject();
    try {
        tokenMessage.put("username", username);
        tokenMessage.put("passwordHash", passwordHash);
        tokenMessage.put("idRevision", idRevision);
        tokenMessage.put("typeExtension", typeExtension);
        tokenMessage.put("version", version == null ? "0.1" : version.replace(" ", "%20"));
        tokenMessage.put("listVersionCompatibles", listVersionCompatibles);
        tokenMessage.put("description", description == null ? "" : description.replace(" ", "%20"));
        tokenMessage.put("agreement", agreement);
        JSONObject token = new us.monoid.json.JSONObject();
        token.put("revision", tokenMessage);
        String u = exchangeWSServer + "publishExtension.php?data=" + token;
        JSONObject resultObj = readJsonFromUrl(u);
        //
        if (resultObj != null) {
            Object object = resultObj.get("result");
            if (object != null && object.equals("UPDATE OK")) {
                ws.setResult(true);
                //$NON-NLS-1$
                ws.setMessageException(Messages.getString("ExchangeWebService.updateRevisionSuccessful"));
            } 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;
}
Also used : JSONObject(us.monoid.json.JSONObject) JSONException(us.monoid.json.JSONException) JSONObject(us.monoid.json.JSONObject) IOException(java.io.IOException) JSONException(us.monoid.json.JSONException) IOException(java.io.IOException)

Example 18 with JSONObject

use of us.monoid.json.JSONObject in project tdi-studio-se by Talend.

the class ExchangeWebService method searchLastRevisionForExtensionService.

/**
     * 
     * DOC hcyi Comment method "searchLastRevisionForExtensionService".
     * 
     * @param idExtension
     * @param username
     * @param passwordHash
     * @return
     */
public static WebserviceStatus searchLastRevisionForExtensionService(String idExtension, 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);
        JSONObject token = new us.monoid.json.JSONObject();
        token.put("extension", tokenMessage);
        String u = exchangeWSServer + "modifyExtension.php?data=" + token;
        JSONObject answer = readJsonFromUrl(u);
        if (answer != null) {
            Object object = answer.get("lastRevision");
            if (object != null && !object.equals("")) {
                ws.setValue(object.toString());
                ws.setResult(true);
            }
        }
    } 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 : JSONObject(us.monoid.json.JSONObject) JSONException(us.monoid.json.JSONException) JSONObject(us.monoid.json.JSONObject) IOException(java.io.IOException) JSONException(us.monoid.json.JSONException) IOException(java.io.IOException)

Example 19 with JSONObject

use of us.monoid.json.JSONObject 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 20 with JSONObject

use of us.monoid.json.JSONObject 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)

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