use of org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType in project tdi-studio-se by Talend.
the class FixUnevenItemContextParametersMigrationTask method execute.
@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
EList<ContextType> contexts = null;
String defualtGroupName = null;
if (item instanceof ProcessItem) {
// process, process_mr, process_storm, route, routelet.
ProcessItem processItem = (ProcessItem) item;
contexts = processItem.getProcess().getContext();
defualtGroupName = processItem.getProcess().getDefaultContext();
} else if (item instanceof JobletProcessItem) {
JobletProcessItem jobletItem = (JobletProcessItem) item;
contexts = jobletItem.getJobletProcess().getContext();
defualtGroupName = jobletItem.getJobletProcess().getDefaultContext();
} else if (item instanceof ContextItem) {
ContextItem contextItem = (ContextItem) item;
contexts = contextItem.getContext();
defualtGroupName = contextItem.getDefaultContext();
}
try {
ContextType defaultGroup = null;
for (ContextType context : contexts) {
if (context.getName().equals(defualtGroupName)) {
defaultGroup = context;
break;
}
}
if (defaultGroup == null && contexts.size() > 0) {
defaultGroup = contexts.get(0);
}
boolean contextChanged = false;
if (defaultGroup != null) {
Map<String, ContextParameterType> paramMap = new HashMap<String, ContextParameterType>();
List<String> paramNameList = new ArrayList<String>();
paramMap.putAll(collectDefaultGroupParams(defaultGroup, paramNameList));
for (ContextType context : contexts) {
if (context == defaultGroup) {
continue;
}
Map<String, ContextParameterType> otherGroupParam = collectDefaultGroupParams(context, paramNameList);
for (String paramName : otherGroupParam.keySet()) {
if (!paramMap.containsKey(paramName)) {
paramMap.put(paramName, otherGroupParam.get(paramName));
}
}
}
// make sure all groups have the same param list
for (ContextType context : contexts) {
EList<ContextParameterType> params = context.getContextParameter();
List<String> paramNames = new ArrayList<String>(paramNameList);
for (ContextParameterType param : params) {
if (paramNames.contains(param.getName())) {
paramNames.remove(param.getName());
}
}
if (!paramNames.isEmpty()) {
contextChanged = true;
for (String paramToAdd : paramNames) {
ContextParameterType toAdd = paramMap.get(paramToAdd);
context.getContextParameter().add(EcoreUtil.copy(toAdd));
}
}
}
// change param order if needed
for (ContextType context : contexts) {
EList<ContextParameterType> params = context.getContextParameter();
List<ContextParameterType> copyOfParam = new ArrayList<ContextParameterType>(params);
for (int i = 0; i < copyOfParam.size(); i++) {
ContextParameterType param = copyOfParam.get(i);
int indexOf = paramNameList.indexOf(param.getName());
if (i != indexOf) {
contextChanged = true;
params.remove(param);
params.add(indexOf, param);
}
}
}
// make sure params in different groups have the same repository id and type as default group
for (ContextType context : contexts) {
EList<ContextParameterType> params = context.getContextParameter();
for (ContextParameterType param : params) {
ContextParameterType paramDefault = paramMap.get(param.getName());
if (!paramDefault.getType().equals(param.getType())) {
contextChanged = true;
param.setType(paramDefault.getType());
}
if (paramDefault.getRepositoryContextId() == null && param.getRepositoryContextId() != null || (paramDefault.getRepositoryContextId() != null && !paramDefault.getRepositoryContextId().equals(param.getRepositoryContextId()))) {
contextChanged = true;
param.setRepositoryContextId(paramDefault.getRepositoryContextId());
}
}
}
}
if (contextChanged) {
ProxyRepositoryFactory.getInstance().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.ContextParameterType in project tdi-studio-se by Talend.
the class FixUnevenItemContextParametersMigrationTask method collectDefaultGroupParams.
private Map<String, ContextParameterType> collectDefaultGroupParams(ContextType contextType, List<String> paramNames) {
EList<ContextParameterType> params = contextType.getContextParameter();
Map<String, ContextParameterType> paramMap = new HashMap<String, ContextParameterType>();
for (ContextParameterType param : params) {
paramMap.put(param.getName(), param);
if (!paramNames.contains(param.getName())) {
paramNames.add(param.getName());
}
}
return paramMap;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType in project tdi-studio-se by Talend.
the class JSONFileStep3Form method getContextJSONPath.
/**
* getContextJSONPath.
*
* @return String
*/
private String getContextJSONPath(JSONFileConnection connection) {
//$NON-NLS-1$
String contextJSONPath = "";
if (ConnectionContextHelper.getContextTypeForContextMode(connection, connection.getContextName()) == null) {
return null;
}
EList eList = ConnectionContextHelper.getContextTypeForContextMode(connection, connection.getContextName()).getContextParameter();
for (int i = 0; i < eList.size(); i++) {
ContextParameterType parameterType = (ContextParameterType) eList.get(i);
if (parameterType.getPrompt().contains("JSONFilePath")) {
//$NON-NLS-1$
contextJSONPath = parameterType.getValue();
}
}
return contextJSONPath;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType in project tdi-studio-se by Talend.
the class UpdateContextParameterCommand method checkNewRepositoryParameters.
/**
* DOC hcw Comment method "checkAddedParameters".
*
* @param process
* @param names
*/
private void checkNewRepositoryParameters(IProcess2 process, Set<String> names) {
// add context in repository
ContextManagerHelper helper = new ContextManagerHelper(process.getContextManager());
Set<ContextItem> contextItemList = helper.getContextItems();
ContextItem item = (ContextItem) result.getParameter();
// this job contains the repository context group
if (contextItemList.contains(item)) {
ContextType contextType = getDefaultContextType(item);
for (String paramName : names) {
ContextParameterType contextParameterType = ContextUtils.getContextParameterTypeByName(contextType, paramName);
// check if there is a parameter with same name
// IContextParameter paramExisted = helper.getExistedContextParameter(contextParameterType.getName());
// if (paramExisted == null) {
helper.addContextParameterType(contextParameterType);
// }
}
}
ConnectionContextHelper.showContextGroupDialog(process, item, process.getContextManager(), names);
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType in project tdi-studio-se by Talend.
the class ReviseInvalidContextNamesMigrationTask method execute.
@Override
public ExecutionResult execute(Item item) {
boolean modified = false;
if (item instanceof ContextItem) {
ContextItem contextItem = (ContextItem) item;
List<ContextType> contextTypes = contextItem.getContext();
for (ContextType contextType : contextTypes) {
List<ContextParameterType> contextParameterTypes = contextType.getContextParameter();
for (ContextParameterType contextParameterType : contextParameterTypes) {
String name = contextParameterType.getName();
if (!ContextParameterUtils.isValidParameterName(name)) {
String newName = ContextParameterUtils.getValidParameterName(name);
contextParameterType.setName(newName);
modified = true;
}
}
}
}
if (modified) {
try {
ProxyRepositoryFactory.getInstance().save(item, true);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
return ExecutionResult.NOTHING_TO_DO;
}
Aggregations