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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations