Search in sources :

Example 6 with JSONException

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

the class ExchangeWebService method searchCategoryExtensionJSONArray.

/**
     * 
     * DOC hcyi Comment method "searchCategoryExtensionJSONArray".
     * 
     * @param typeExtension
     * @return
     */
public static List<Category> searchCategoryExtensionJSONArray(String typeExtension) {
    List<Category> fCategorys = new ArrayList<Category>();
    JSONObject tokenMessage = new JSONObject();
    try {
        tokenMessage.put("typeExtension", typeExtension);
        JSONObject token = new us.monoid.json.JSONObject();
        token.put("extension", tokenMessage);
        String u = exchangeWSServer + "listCategoryExtension.php?data=" + token;
        JSONObject resultObj = readJsonFromUrl(u);
        if (resultObj != null) {
            JSONObject p = (JSONObject) resultObj.get("listCategory");
            JSONArray resultArry = p.getJSONArray("category");
            if (resultArry != null) {
                for (int i = 0; i < resultArry.length(); i++) {
                    JSONObject extensionObj = resultArry.getJSONObject(i);
                    if (extensionObj != null) {
                        Category fCategory = ExchangeFactory.eINSTANCE.createCategory();
                        fCategory.setCategoryId(extensionObj.getString("id_category"));
                        fCategory.setCategoryName(extensionObj.getString("name"));
                        fCategorys.add(fCategory);
                    }
                }
            }
        }
    } catch (JSONException e) {
    //
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return fCategorys;
}
Also used : Category(org.talend.designer.components.exchange.model.Category) JSONObject(us.monoid.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(us.monoid.json.JSONArray) JSONException(us.monoid.json.JSONException) IOException(java.io.IOException) JSONException(us.monoid.json.JSONException) IOException(java.io.IOException)

Example 7 with JSONException

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

the class ExchangeWebService method deleteExtensionService.

/**
     * 
     * DOC hcyi Comment method "deleteExtensionService".
     * 
     * @param idExtension
     * @param typeExtension
     * @param username
     * @param passwordHash
     * @return
     */
public static WebserviceStatus deleteExtensionService(String idExtension, String typeExtension, 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);
        tokenMessage.put("typeExtension", typeExtension);
        JSONObject token = new us.monoid.json.JSONObject();
        token.put("extension", tokenMessage);
        String u = exchangeWSServer + "deleteExtension.php?data=" + token;
        JSONObject result = readJsonFromUrl(u);
        //
        if (result != null) {
            Object object = result.get("result");
            if (object != null && object.equals("DELETE OK")) {
                ws.setResult(true);
                //$NON-NLS-1$
                ws.setMessageException(Messages.getString("ExchangeWebService.deleteExtensionSuccessful"));
            } 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 8 with JSONException

use of us.monoid.json.JSONException 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 9 with JSONException

use of us.monoid.json.JSONException 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 10 with JSONException

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

Aggregations

JSONException (us.monoid.json.JSONException)20 JSONObject (us.monoid.json.JSONObject)20 IOException (java.io.IOException)15 JSONArray (us.monoid.json.JSONArray)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 ArrayList (java.util.ArrayList)4 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 Path (org.eclipse.core.runtime.Path)1 EList (org.eclipse.emf.common.util.EList)1 PersistenceException (org.talend.commons.exception.PersistenceException)1 Project (org.talend.core.model.general.Project)1 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)1 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)1 RoutineItem (org.talend.core.model.properties.RoutineItem)1 SQLPatternItem (org.talend.core.model.properties.SQLPatternItem)1