Search in sources :

Example 11 with JSONException

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

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

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

the class ResetVMArgumentMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    ParametersType parameters = processType.getParameters();
    if (parameters == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    try {
        EList listParamType = parameters.getElementParameter();
        for (int j = 0; j < listParamType.size(); j++) {
            ElementParameterType pType = (ElementParameterType) listParamType.get(j);
            if (pType.getName().equals("JOB_RUN_VM_ARGUMENTS")) {
                //$NON-NLS-1$
                String value = pType.getValue().trim();
                if (value != null && value.length() > 0 && !isJson(value)) {
                    try {
                        JSONObject root = new JSONObject();
                        JSONArray args = new JSONArray();
                        //$NON-NLS-1$
                        String[] vms = value.split(" ");
                        for (String vm : vms) {
                            args.put(vm);
                        }
                        //$NON-NLS-1$
                        root.put("JOB_RUN_VM_ARGUMENTS", args);
                        pType.setValue(root.toString());
                        factory.save(item, true);
                        break;
                    } catch (JSONException e) {
                        ExceptionHandler.process(e);
                        return ExecutionResult.FAILURE;
                    }
                }
            }
        }
        return ExecutionResult.SUCCESS_WITH_ALERT;
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) EList(org.eclipse.emf.common.util.EList) JSONObject(us.monoid.json.JSONObject) JSONArray(us.monoid.json.JSONArray) JSONException(us.monoid.json.JSONException) ParametersType(org.talend.designer.core.model.utils.emf.talendfile.ParametersType) JSONException(us.monoid.json.JSONException)

Example 14 with JSONException

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

the class RunProcessPreferenceInitializer method defaultVM.

private String defaultVM() {
    JSONObject root = new JSONObject();
    try {
        JSONArray args = new JSONArray();
        //$NON-NLS-1$
        args.put("-Xms256M");
        //$NON-NLS-1$
        args.put("-Xmx1024M");
        //$NON-NLS-1$
        root.put("JOB_RUN_VM_ARGUMENTS", args);
    } catch (JSONException e) {
        ExceptionHandler.process(e);
    }
    return root.toString();
}
Also used : JSONObject(us.monoid.json.JSONObject) JSONArray(us.monoid.json.JSONArray) JSONException(us.monoid.json.JSONException)

Example 15 with JSONException

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

the class TosTokenCollector method collectProjectDetails.

private JSONObject collectProjectDetails() throws PersistenceException, JSONException {
    JSONObject jObject = new JSONObject();
    Project currentProject = ProjectManager.getInstance().getCurrentProject();
    final IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    JSONObject repoStats = new JSONObject();
    // metadata
    for (DynaEnum type : ERepositoryObjectType.values()) {
        if (type instanceof ERepositoryObjectType && ((ERepositoryObjectType) type).isResourceItem()) {
            try {
                List<IRepositoryViewObject> all = factory.getAll(currentProject, (ERepositoryObjectType) type);
                int nb = all.size();
                if (ERepositoryObjectType.TDQ_INDICATOR_ELEMENT.equals(type) || ERepositoryObjectType.TDQ_PATTERN_ELEMENT.equals(type) || ERepositoryObjectType.TDQ_RULES.equals(type) || "TDQ_SOURCE_FILE_ELEMENT".equals(type.getType())) {
                    //$NON-NLS-1$
                    continue;
                }
                if (ERepositoryObjectType.ROUTINES.equals(type)) {
                    nb = 0;
                    List<IRepositoryViewObject> newList = new ArrayList<IRepositoryViewObject>();
                    for (IRepositoryViewObject object : all) {
                        RoutineItem rItem = (RoutineItem) object.getProperty().getItem();
                        if (!rItem.isBuiltIn()) {
                            nb++;
                            newList.add(object);
                        }
                    }
                    all = newList;
                }
                if (ERepositoryObjectType.SQLPATTERNS.equals(type)) {
                    nb = 0;
                    for (IRepositoryViewObject object : all) {
                        SQLPatternItem spItem = (SQLPatternItem) object.getProperty().getItem();
                        if (!spItem.isSystem()) {
                            nb++;
                        }
                    }
                }
                if ("MDM.DataModel".equals(type.getType())) {
                    //$NON-NLS-1$
                    nb = 0;
                    for (IRepositoryViewObject object : all) {
                        String path = object.getProperty().getItem().getState().getPath();
                        if (!"System".equals(path)) {
                            //$NON-NLS-1$
                            nb++;
                        }
                    }
                }
                if (nb > 0) {
                    JSONObject typeStats = new JSONObject();
                    //$NON-NLS-1$
                    typeStats.put("nb", nb);
                    if (ERepositoryObjectType.getAllTypesOfProcess().contains(type)) {
                        JSONObject jobDetails = new JSONObject();
                        collectJobDetails(all, jobDetails);
                        //$NON-NLS-1$
                        typeStats.put("details", jobDetails);
                    }
                    if (ERepositoryObjectType.ROUTINES.equals(type) || //$NON-NLS-1$
                    ((ERepositoryObjectType) type).getFolder().startsWith("metadata/") || ERepositoryObjectType.CONTEXT.equals(type) || type.equals(ERepositoryObjectType.JOBLET)) {
                        int nbUsed = 0;
                        for (IRepositoryViewObject object : all) {
                            List<Relation> relations = RelationshipItemBuilder.getInstance().getItemsHaveRelationWith(object.getId());
                            relations.addAll(RelationshipItemBuilder.getInstance().getItemsHaveRelationWith(object.getLabel()));
                            if (relations.size() > 0) {
                                nbUsed++;
                            }
                        }
                        //$NON-NLS-1$
                        typeStats.put("nb.used", nbUsed);
                    }
                    if (ERepositoryObjectType.METADATA_CONNECTIONS.equals(type)) {
                        JSONObject objects = new JSONObject();
                        for (IRepositoryViewObject object : all) {
                            DatabaseConnectionItem item = (DatabaseConnectionItem) object.getProperty().getItem();
                            String dbType = ((DatabaseConnection) item.getConnection()).getDatabaseType();
                            int nbDbTypes = 1;
                            if (objects.has(dbType)) {
                                nbDbTypes = objects.getInt(dbType);
                                nbDbTypes++;
                            }
                            objects.put(dbType, nbDbTypes);
                        }
                        //$NON-NLS-1$
                        typeStats.put("types", objects);
                    }
                    repoStats.put(type.getType(), typeStats);
                }
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
        }
    }
    //$NON-NLS-1$
    jObject.put(PROJECTS.getKey(), repoStats);
    jObject.put(TYPE.getKey(), ProjectManager.getInstance().getProjectType(currentProject));
    int nbRef = ProjectManager.getInstance().getAllReferencedProjects().size();
    if (nbRef > 0) {
        jObject.put("nb.refProjects", nbRef);
    }
    return jObject;
}
Also used : DynaEnum(org.talend.core.model.repository.DynaEnum) ArrayList(java.util.ArrayList) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) JSONException(us.monoid.json.JSONException) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) Project(org.talend.core.model.general.Project) Relation(org.talend.core.model.relationship.Relation) JSONObject(us.monoid.json.JSONObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

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