Search in sources :

Example 11 with JSONArray

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

the class ComponentSearcher method getInstalledExtensions.

/**
     * Find Installed components.
     * 
     * @param version The tos version.
     * @param language The project language.
     * @return
     */
public static List<ComponentExtension> getInstalledExtensions(String version, ECodeLanguage language, String username, String passwordHash) {
    List<ComponentExtension> extensions = new ArrayList<ComponentExtension>();
    try {
        JSONArray extensionsJSONArray = ExchangeWebService.searchInstalledExtensionJSONArray(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"));
                    extension.setDateDownload(formatter.parse(extensionObj.getString("dateDownload")));
                    extension.setDownloadedVersion(extensionObj.getString("downloadedVersion"));
                    extension.setVersionExtension(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)

Example 12 with JSONArray

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

use of us.monoid.json.JSONArray 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 14 with JSONArray

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

the class TosTokenCollector method collectJobDetails.

/**
     * DOC nrousseau Comment method "collectJobDetails".
     * 
     * @param all
     * @param jobDetails
     * @throws JSONException
     */
private void collectJobDetails(List<IRepositoryViewObject> allRvo, JSONObject jobDetails) throws JSONException {
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    IWorkbenchWindow ww = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IEditorReference[] reference = new IEditorReference[0];
    if (ww != null) {
        IWorkbenchPage page = ww.getActivePage();
        reference = page.getEditorReferences();
    }
    List<IProcess2> processes = RepositoryPlugin.getDefault().getDesignerCoreService().getOpenedProcess(reference);
    Set<String> idsOpened = new HashSet<String>();
    for (IProcess2 process : processes) {
        idsOpened.add(process.getId());
    }
    JSONArray components = new JSONArray();
    int contextVarsNum = 0;
    int nbComponentsUsed = 0;
    for (IRepositoryViewObject rvo : allRvo) {
        Item item = rvo.getProperty().getItem();
        if (item instanceof ProcessItem) {
            ProcessType processType = ((ProcessItem) item).getProcess();
            for (NodeType node : (List<NodeType>) processType.getNode()) {
                JSONObject component_names = null;
                String componentName = node.getComponentName();
                int nbComp = 0;
                for (int i = 0; i < components.length(); i++) {
                    JSONObject temp = components.getJSONObject(i);
                    if (temp.get("component_name").equals(componentName)) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        nbComp = temp.getInt("count");
                        component_names = temp;
                        break;
                    }
                }
                if (component_names == null) {
                    component_names = new JSONObject();
                    components.put(component_names);
                }
                component_names.put("component_name", componentName);
                component_names.put("count", nbComp + 1);
                nbComponentsUsed++;
            }
            // context variable per job
            EList contexts = processType.getContext();
            if (contexts.size() > 0) {
                ContextType contextType = (ContextType) contexts.get(0);
                contextVarsNum += contextType.getContextParameter().size();
            }
        }
        if (factory.getStatus(item) != ERepositoryStatus.LOCK_BY_USER && !idsOpened.contains(item.getProperty().getId())) {
            // job is not locked and not opened by editor, so we can unload.
            if (item.getParent() instanceof FolderItem) {
                ((FolderItem) item.getParent()).getChildren().remove(item);
                item.setParent(null);
            }
            item.eResource().unload();
        }
    }
    jobDetails.put("components", components);
    jobDetails.put("nb.contextVars", contextVarsNum);
    jobDetails.put("nb.components", nbComponentsUsed);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) JSONArray(us.monoid.json.JSONArray) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) FolderItem(org.talend.core.model.properties.FolderItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) IEditorReference(org.eclipse.ui.IEditorReference) EList(org.eclipse.emf.common.util.EList) FolderItem(org.talend.core.model.properties.FolderItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JSONObject(us.monoid.json.JSONObject) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) HashSet(java.util.HashSet)

Example 15 with JSONArray

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

the class UserComponentsTokenCollector method collect.

/* (non-Javadoc)
     * @see org.talend.core.ui.token.AbstractTokenCollector#collect()
     */
@Override
public JSONObject collect() throws Exception {
    JSONObject object = new JSONObject();
    List<IComponent> customComponents = ComponentsFactoryProvider.getInstance().getCustomComponents();
    JSONArray customComponentsArray = new JSONArray();
    if (customComponents != null) {
        for (int i = 0; i < customComponents.size(); i++) {
            customComponentsArray.put(customComponents.get(i).getName());
        }
    }
    object.put(USER_COMPONENTS.getKey(), customComponentsArray);
    return object;
}
Also used : JSONObject(us.monoid.json.JSONObject) IComponent(org.talend.core.model.components.IComponent) JSONArray(us.monoid.json.JSONArray)

Aggregations

JSONArray (us.monoid.json.JSONArray)15 JSONObject (us.monoid.json.JSONObject)15 JSONException (us.monoid.json.JSONException)9 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)5 HashMap (java.util.HashMap)4 ComponentExtension (org.talend.designer.components.exchange.model.ComponentExtension)4 EList (org.eclipse.emf.common.util.EList)2 AvailableExtensionViewDetail (org.talend.designer.components.exchange.model.AvailableExtensionViewDetail)2 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 IEditorReference (org.eclipse.ui.IEditorReference)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 IComponent (org.talend.core.model.components.IComponent)1 IProcess2 (org.talend.core.model.process.IProcess2)1 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)1 FolderItem (org.talend.core.model.properties.FolderItem)1