Search in sources :

Example 26 with JSONObject

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

the class ExchangeWebService method downloadingExtensionService.

/**
     * 
     * DOC hcyi Comment method "downloadingExtensionService".
     * 
     * @param idExtension
     * @param typeExtension
     * @param username
     * @param passwordHash
     * @return
     */
public static WebserviceStatus downloadingExtensionService(String idExtension, String typeExtension, String username, String passwordHash) {
    WebserviceStatus ws = new WebserviceStatus();
    ws.setResult(false);
    JSONObject tokenMessage = new JSONObject();
    try {
        tokenMessage.put("typeExtension", typeExtension);
        tokenMessage.put("idExtension", idExtension);
        tokenMessage.put("username", username);
        tokenMessage.put("passwordHash", passwordHash);
        JSONObject token = new us.monoid.json.JSONObject();
        token.put("downloadedExtension", tokenMessage);
        String u = exchangeWSServer + "downloadedExtension.php?data=" + token;
        JSONObject answer = readJsonFromUrl(u);
        if (answer != null) {
            JSONObject resultObj = (JSONObject) answer.get("resultDownloadExtension");
            String linkDownload = resultObj.getString("linkDownload");
            //
            ws.setValue(linkDownload);
            ws.setResult(true);
            //$NON-NLS-1$
            ws.setMessageException(Messages.getString("ExchangeWebService.downloadingExtensionSuccessful"));
        }
    } 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) IOException(java.io.IOException) JSONException(us.monoid.json.JSONException) IOException(java.io.IOException)

Example 27 with JSONObject

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

the class RunProcessTokenCollector method collect.

/* (non-Javadoc)
     * @see org.talend.core.ui.token.AbstractTokenCollector#collect()
     */
@Override
public JSONObject collect() throws Exception {
    JSONObject object = new JSONObject();
    IPreferenceStore preferenceStore = RunProcessPlugin.getDefault().getPreferenceStore();
    int numRun = preferenceStore.getInt(TOS_COUNT_RUNS.getPrefKey());
    object.put(TOS_COUNT_RUNS.getKey(), numRun);
    int numDebugRun = preferenceStore.getInt(TOS_COUNT_DEBUG_RUNS.getPrefKey());
    object.put(TOS_COUNT_DEBUG_RUNS.getKey(), numDebugRun);
    return object;
}
Also used : JSONObject(us.monoid.json.JSONObject) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 28 with JSONObject

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

the class ComponentSearcher method getContributedExtensions.

/**
     * Find Contributed components.
     * 
     * @param version The tos version.
     * @param language The project language.
     * @return
     */
public static List<ComponentExtension> getContributedExtensions(String version, ECodeLanguage language, String username, String passwordHash) {
    List<ComponentExtension> extensions = new ArrayList<ComponentExtension>();
    try {
        JSONArray extensionsJSONArray = ExchangeWebService.searchContributedExtensionJSONArray(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"));
                    if (extensionObj.getString("dateExtension") != null && !"".equals(extensionObj.getString("dateExtension"))) {
                        extension.setPublicationDate(formatter.parse(extensionObj.getString("dateExtension")));
                    } else {
                        extension.setPublicationDate(formatter.parse(formatter.format(new Date())));
                    }
                    extension.setLastVersionAvailable(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) Date(java.util.Date)

Example 29 with JSONObject

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

the class JobVMArgumentsUtil method readString.

public List<String> readString(String stringList) {
    if (stringList == null || "".equals(stringList)) {
        //$NON-NLS-1$        
        return EMPTY_STRING_LIST;
    }
    ArrayList<String> result = new ArrayList<String>(50);
    try {
        JSONObject root = new JSONObject(stringList);
        //$NON-NLS-1$
        Object obj = root.get("JOB_RUN_VM_ARGUMENTS");
        if (obj != null && (obj instanceof JSONArray)) {
            JSONArray array = (JSONArray) obj;
            for (int i = 0; i < array.length(); i++) {
                result.add((String) array.get(i));
            }
        }
    } catch (JSONException e) {
        ExceptionHandler.process(e);
    }
    return result;
}
Also used : JSONObject(us.monoid.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(us.monoid.json.JSONArray) JSONException(us.monoid.json.JSONException) JSONObject(us.monoid.json.JSONObject)

Example 30 with JSONObject

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

the class TosTokenCollector method priorCollect.

@Override
public void priorCollect() throws Exception {
    // for all projects
    JSONObject allProjectRecords = null;
    IPreferenceStore preferenceStore = RepositoryPlugin.getDefault().getPreferenceStore();
    String records = preferenceStore.getString(PREF_TOS_JOBS_RECORDS);
    try {
        // reset
        allProjectRecords = new JSONObject(records);
    } catch (Exception e) {
        // the value is not set, or is empty
        allProjectRecords = new JSONObject();
    }
    JSONObject currentProjectObject = collectProjectDetails();
    Project currentProject = ProjectManager.getInstance().getCurrentProject();
    allProjectRecords.put(currentProject.getTechnicalLabel(), currentProjectObject);
    //
    preferenceStore.setValue(PREF_TOS_JOBS_RECORDS, allProjectRecords.toString());
}
Also used : Project(org.talend.core.model.general.Project) JSONObject(us.monoid.json.JSONObject) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) JSONException(us.monoid.json.JSONException) PersistenceException(org.talend.commons.exception.PersistenceException)

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