use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class ProcessController method updateContextList.
/**
*
* ggu Comment method "updateContextList".
*
* @param processParam
*/
private void updateContextList(IElementParameter processParam) {
if (processParam == null || (processParam.getFieldType() != EParameterFieldType.PROCESS_TYPE && processParam.getFieldType() != EParameterFieldType.ROUTE_INPUT_PROCESS_TYPE)) {
return;
}
// for context type
List<String> contextNameList = new ArrayList<String>();
List<String> contextValueList = new ArrayList<String>();
// for version type
List<String> versionNameList = new ArrayList<String>();
List<String> versionValueList = new ArrayList<String>();
versionNameList.add(ItemCacheManager.LATEST_VERSION);
versionValueList.add(ItemCacheManager.LATEST_VERSION);
IElementParameter jobNameParam = processParam.getChildParameters().get(EParameterName.PROCESS_TYPE_PROCESS.getName());
// feature 19312
Item item = null;
StringBuffer labels = new StringBuffer("");
List<IRepositoryViewObject> allVersion = new ArrayList<IRepositoryViewObject>();
final String strJobId = (String) jobNameParam.getValue();
String[] strJobIds = strJobId.split(ProcessController.COMMA);
for (int i = 0; i < strJobIds.length; i++) {
String id = strJobIds[i];
if (StringUtils.isNotEmpty(id)) {
allVersion = ProcessorUtilities.getAllVersionObjectById(id);
// IRepositoryObject lastVersionObject = null;
String label = null;
if (allVersion != null) {
String oldVersion = null;
for (IRepositoryViewObject obj : allVersion) {
String version = obj.getVersion();
if (oldVersion == null) {
oldVersion = version;
}
if (VersionUtils.compareTo(version, oldVersion) >= 0) {
item = obj.getProperty().getItem();
// lastVersionObject = obj;
}
oldVersion = version;
versionNameList.add(version);
versionValueList.add(version);
}
label = item.getProperty().getLabel();
if (i > 0) {
labels.append(ProcessController.COMMA);
}
labels.append(label);
// IPath path = RepositoryNodeUtilities.getPath(lastVersionObject);
// if (path != null) {
// label = path.toString() + IPath.SEPARATOR + label;
// }
} else {
// FIXME TUP-5524, don't set empty, keep the id value instead.
// final String parentName = processParam.getName() + ":"; //$NON-NLS-1$
// if (elem != null) {
// // can be called in multi-thread, dispose method may be already called before executing this
// method
//elem.setPropertyValue(parentName + jobNameParam.getName(), ""); //$NON-NLS-1$
// }
}
}
}
jobNameParam.setLabelFromRepository(labels.toString());
// set default context
String defalutValue = null;
if (item != null && item instanceof ProcessItem) {
for (Object o : ((ProcessItem) item).getProcess().getContext()) {
if (o instanceof ContextType) {
ContextType context = (ContextType) o;
contextNameList.add(context.getName());
contextValueList.add(context.getName());
}
}
defalutValue = ((ProcessItem) item).getProcess().getDefaultContext();
}
setProcessTypeRelatedValues(processParam, contextNameList, contextValueList, EParameterName.PROCESS_TYPE_CONTEXT.getName(), defalutValue);
setProcessTypeRelatedValues(processParam, versionNameList, versionValueList, EParameterName.PROCESS_TYPE_VERSION.getName(), null);
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class ExportProcessorHelper method exportJob.
public String exportJob(Processor processor, int statisticsPort, int tracePort, String watchParam, String log4jLevel, final IProgressMonitor progressMonitor) throws ProcessorException {
ProcessItem processItem = (ProcessItem) processor.getProperty().getItem();
processName = processor.getProperty().getLabel();
//$NON-NLS-1$
File archiveFile = new File(getTmpExportFolder(), "remote_run_export-" + processName + FileExtensions.ZIP_FILE_SUFFIX);
Properties prop = new Properties();
if (watchParam != null) {
prop.setProperty(TalendProcessArgumentConstant.ARG_ENABLE_WATCH, watchParam);
}
// FIXME, maybe should try another way. it's not good, I think.
// update directly the .item (without save it) in case of prompt
// then the generation will be correct automatically in the .properties
IContext context = processor.getContext();
if (context != null) {
List<IContextParameter> contextParameterList = context.getContextParameterList();
if (contextParameterList != null && contextParameterList.size() > 0) {
for (IContextParameter contextParameter : contextParameterList) {
if (!contextParameter.isPromptNeeded()) {
continue;
}
for (Object curCType : processItem.getProcess().getContext()) {
ContextType cType = (ContextType) curCType;
if (context.getName().equals(cType.getName())) {
for (Object curParam : cType.getContextParameter()) {
ContextParameterType cParamType = (ContextParameterType) curParam;
if (contextParameter.getName().equals(cParamType.getName())) {
cParamType.setRawValue(contextParameter.getValue());
}
}
}
}
}
}
}
export(progressMonitor, processItem, ERepositoryObjectType.getItemType(processItem), processor.getContext().getName(), archiveFile.toString(), log4jLevel, false, statisticsPort, tracePort, prop);
return archiveFile.toString();
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class EncryptDbPasswordMigrationTask method encryptContextPassword.
/**
* DOC chuang Comment method "encryptContextPassword".
*
* @param item
* @param contextTypeList
* @return
*/
private ExecutionResult encryptContextPassword(Item item, List<ContextType> contextTypeList) {
boolean modify = false;
if (contextTypeList != null) {
for (ContextType type : contextTypeList) {
List<ContextParameterType> paramTypes = type.getContextParameter();
if (paramTypes != null) {
for (ContextParameterType param : paramTypes) {
try {
// before migration task, the value should be raw. so keep it.
if (param.getValue() != null && PasswordEncryptUtil.isPasswordType(param.getType())) {
encryptPassword(param);
modify = true;
}
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
}
}
}
if (modify) {
try {
factory.save(item, true);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
return ExecutionResult.SUCCESS_NO_ALERT;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType 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 org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class ExportJobUtil method getJobContextValues.
/**
* DOC zli Comment method "getJobContextValues".
*
* @param processItem
* @param contextName
* @return
*/
@SuppressWarnings("rawtypes")
public static List<ContextParameterType> getJobContextValues(ProcessItem processItem, String contextName) {
if (contextName == null) {
return null;
}
// else do next line
List<ContextParameterType> list = new ArrayList<ContextParameterType>();
EList contexts = ((ProcessTypeImpl) processItem.getProcess()).getContext();
for (int i = 0; i < contexts.size(); i++) {
Object object = contexts.get(i);
if (object instanceof ContextType) {
ContextType contextType = (ContextType) object;
if (contextName.equals(contextType.getName())) {
EList contextParameter = contextType.getContextParameter();
for (int j = 0; j < contextParameter.size(); j++) {
Object object2 = contextParameter.get(j);
if (object2 instanceof ContextParameterType) {
ContextParameterType contextParameterType = (ContextParameterType) object2;
list.add(contextParameterType);
}
}
return list;
}
}
}
return null;
}
Aggregations