use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class UpdateJobletContextInJobMigrationTask method execute.
@Override
public ExecutionResult execute(Item item) {
if (item instanceof ProcessItem) {
ProcessItem processItem = (ProcessItem) item;
List<ContextType> contexts = processItem.getProcess().getContext();
if (contexts.size() > 1) {
boolean isModified = false;
for (ContextType context1 : contexts) {
List<ContextParameterType> params1 = context1.getContextParameter();
for (ContextParameterType param1 : params1) {
String id = param1.getRepositoryContextId();
if (id != null) {
for (ContextType context2 : contexts) {
if (context2 != context1) {
List<ContextParameterType> params2 = context2.getContextParameter();
for (ContextParameterType param2 : params2) {
if (param2.getName().equals(param1.getName()) && param2.getRepositoryContextId() == null) {
param2.setRepositoryContextId(id);
isModified = true;
break;
}
}
}
}
}
}
}
if (isModified) {
try {
ProxyRepositoryFactory.getInstance().save(item, true);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
return ExecutionResult.SUCCESS_NO_ALERT;
}
}
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class UnifyPasswordEncryption4ContextMigrationTask method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org .talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
if (item instanceof ContextItem) {
List<ContextType> contextTypeList = ((ContextItem) item).getContext();
boolean modify = false;
if (contextTypeList != null) {
for (ContextType type : contextTypeList) {
List<ContextParameterType> paramTypes = type.getContextParameter();
if (paramTypes != null) {
for (ContextParameterType param : paramTypes) {
try {
String value = param.getValue();
if (value != null && PasswordEncryptUtil.isPasswordType(param.getType())) {
String rawPassword = PasswordEncryptUtil.decryptPassword(value);
param.setRawValue(rawPassword);
modify = true;
}
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
}
}
}
if (modify) {
try {
factory.save(item, true);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
}
return ExecutionResult.NOTHING_TO_DO;
}
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);
}
Aggregations