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