Search in sources :

Example 1 with JSONObject

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

the class JobVMArgumentsUtil method writeString.

public String writeString(List<String> items) {
    JSONObject root = new JSONObject();
    JSONArray args = new JSONArray();
    int size = items.size();
    for (int i = 0; i < size; i++) {
        String vm = items.get(i).trim();
        args.put(vm);
    }
    try {
        //$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 2 with JSONObject

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

the class ExportJobTokenCollector method collect.

/* (non-Javadoc)
     * @see org.talend.core.ui.token.AbstractTokenCollector#collect()
     */
@Override
public JSONObject collect() throws Exception {
    JSONObject object = new JSONObject();
    int num = RepositoryPlugin.getDefault().getPreferenceStore().getInt(TOS_COUNT_JOB_EXPORTS.getPrefKey());
    object.put(TOS_COUNT_JOB_EXPORTS.getKey(), num);
    return object;
}
Also used : JSONObject(us.monoid.json.JSONObject)

Example 3 with JSONObject

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

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

Example 5 with JSONObject

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

the class TosTokenCollector method collect.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.ui.token.AbstractTokenCollector#collect()
     */
@Override
public JSONObject collect() throws Exception {
    JSONObject finalToken = new JSONObject();
    JSONObject mergedData = new JSONObject();
    IPreferenceStore preferenceStore = RepositoryPlugin.getDefault().getPreferenceStore();
    String records = preferenceStore.getString(PREF_TOS_JOBS_RECORDS);
    JSONObject allProjectRecords = null;
    try {
        // reset
        allProjectRecords = new JSONObject(records);
    } catch (Exception e) {
        // the value is not set, or is empty
        allProjectRecords = new JSONObject();
    }
    Iterator<String> keys = allProjectRecords.keys();
    JSONObject projectTypes = new JSONObject();
    while (keys.hasNext()) {
        String projectName = keys.next();
        JSONObject object = (JSONObject) allProjectRecords.get(projectName);
        if (object != null) {
            TokenInforUtil.mergeJSON(object, mergedData);
            if (object.has(TYPE.getKey())) {
                String type = object.getString(TYPE.getKey());
                // count the number of project for each type
                if (!projectTypes.has(type)) {
                    projectTypes.put(type, 1);
                } else {
                    int nb = projectTypes.getInt(type);
                    nb++;
                    projectTypes.put(type, nb);
                }
            }
        }
    }
    if (mergedData.has(PROJECTS.getKey())) {
        finalToken.put(PROJECTS_REPOSITORY.getKey(), mergedData.get(PROJECTS.getKey()));
    }
    finalToken.put("projects.type", projectTypes);
    return finalToken;
}
Also used : 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