use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class ReplaceJavaKeywordsNameForContextMigrationTask method getReplacedNamesAndReplaceContextVars.
/**
*
* ggu Comment method "getReplacedNamesAndReplaceContextVars".
*
* get the replaced names, and replace the context variables at the same time.
*/
@SuppressWarnings("unchecked")
private Map<String, Map<String, String>> getReplacedNamesAndReplaceContextVars() {
// id to map(oldName to newName)
Map<String, Map<String, String>> contextIdNamesMap = new HashMap<String, Map<String, String>>();
List<ContextItem> allContextItem = ContextUtils.getAllContextItem();
if (allContextItem != null) {
for (ContextItem contextItem : allContextItem) {
boolean changed = false;
boolean first = true;
Set<String> varNames = null;
for (ContextType contextType : (List<ContextType>) contextItem.getContext()) {
if (first) {
varNames = ContextUtils.getContextVarNames(contextType);
}
// oldName to newName
Map<String, String> nameMap = new HashMap<String, String>();
final String contextId = contextItem.getProperty().getId();
for (ContextParameterType paramType : (List<ContextParameterType>) contextType.getContextParameter()) {
String oldName = paramType.getName();
if (first) {
if (ContextUtils.isJavaKeyWords(oldName)) {
// is java keywords
String newName = getNewName(varNames, oldName);
nameMap.put(newName, oldName);
paramType.setName(newName);
changed = true;
}
} else {
String newName = getContextNewNameFromMap(contextIdNamesMap, contextId, oldName);
if (newName != null) {
// is java keywords
paramType.setName(newName);
changed = true;
}
}
}
if (first && !nameMap.isEmpty()) {
contextIdNamesMap.put(contextId, nameMap);
}
first = false;
}
if (changed) {
// save
try {
factory.save(contextItem, true);
} catch (PersistenceException e) {
//
}
}
}
}
return contextIdNamesMap;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class ReplaceJavaKeywordsNameForContextMigrationTask method modifyJobContext.
/**
*
* ggu Comment method "modifyJobContext".
*
* this function will get the replaced variables map.
*/
@SuppressWarnings("unchecked")
private boolean modifyJobContext(Map<String, String> jobContextReplacedNamesMap, List<ContextType> contextTypeList) {
if (contextTypeList == null || contextTypeList.isEmpty()) {
return false;
}
boolean changed = false;
boolean first = true;
Set<String> varNames = null;
for (ContextType contextType : (List<ContextType>) contextTypeList) {
if (first) {
varNames = ContextUtils.getContextVarNames(contextType);
}
for (ContextParameterType paramType : (List<ContextParameterType>) contextType.getContextParameter()) {
final String oldName = paramType.getName();
final String sourceId = paramType.getRepositoryContextId();
if (first) {
if (ContextUtils.isJavaKeyWords(oldName)) {
// is java keywords
String newName = getNewName(varNames, oldName);
String tmpName = getContextNewNameFromMap(contextReplacedNamesMap, sourceId, oldName);
if (tmpName != null) {
// from repository context
newName = tmpName;
}
jobContextReplacedNamesMap.put(newName, oldName);
paramType.setName(newName);
changed = true;
}
} else {
String newName = getJobContextNewNameFromMap(jobContextReplacedNamesMap, oldName);
if (newName != null) {
// is key words
paramType.setName(newName);
changed = true;
}
}
}
}
return changed;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class FixUnevenItemContextParametersMigrationTaskTest method createContextType.
private ContextType createContextType(String contextName, String[] paramNames) {
ContextType context = TalendFileFactory.eINSTANCE.createContextType();
context.setName(contextName);
for (String paramName : paramNames) {
ContextParameterType param = TalendFileFactory.eINSTANCE.createContextParameterType();
param.setName(paramName);
param.setType("id_String");
context.getContextParameter().add(param);
}
return context;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class FixUnevenItemContextParametersMigrationTaskTest method testChangeParamList.
@Test
public void testChangeParamList() {
testItem.getProcess().setDefaultContext("Default");
String[] paramNames = new String[] { "new4", "new2", "new3" };
// default
ContextType defaultGroup = createContextType("Default", paramNames);
testItem.getProcess().getContext().add(defaultGroup);
// group1
paramNames = new String[] { "new5", "new2", "new1" };
ContextType group1 = createContextType("group1", paramNames);
testItem.getProcess().getContext().add(group1);
FixUnevenItemContextParametersMigrationTask migration = new FixUnevenItemContextParametersMigrationTask();
migration.execute(testItem);
Assert.assertEquals(((ContextParameterType) defaultGroup.getContextParameter().get(0)).getName(), "new4");
Assert.assertEquals(((ContextParameterType) defaultGroup.getContextParameter().get(1)).getName(), "new2");
Assert.assertEquals(((ContextParameterType) defaultGroup.getContextParameter().get(2)).getName(), "new3");
Assert.assertEquals(((ContextParameterType) defaultGroup.getContextParameter().get(3)).getName(), "new5");
Assert.assertEquals(((ContextParameterType) defaultGroup.getContextParameter().get(4)).getName(), "new1");
Assert.assertEquals(((ContextParameterType) group1.getContextParameter().get(0)).getName(), "new4");
Assert.assertEquals(((ContextParameterType) group1.getContextParameter().get(1)).getName(), "new2");
Assert.assertEquals(((ContextParameterType) group1.getContextParameter().get(2)).getName(), "new3");
Assert.assertEquals(((ContextParameterType) group1.getContextParameter().get(3)).getName(), "new5");
Assert.assertEquals(((ContextParameterType) group1.getContextParameter().get(4)).getName(), "new1");
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class UnifyPasswordEncryption4ParametersInJobMigrationTask method checkContext.
/**
*
* same as UnifyPasswordEncryption4ContextMigrationTask to change the encryption.
*/
@SuppressWarnings("deprecation")
protected boolean checkContext(Item item, ProcessType processType) throws Exception {
boolean modified = false;
// context
EList contextList = processType.getContext();
for (Object o : contextList) {
if (o instanceof ContextType) {
List<ContextParameterType> paramTypes = ((ContextType) o).getContextParameter();
if (paramTypes != null) {
for (ContextParameterType param : paramTypes) {
String value = param.getValue();
if (value != null && (PasswordEncryptUtil.isPasswordType(param.getType()) || PasswordEncryptUtil.isPasswordField(param.getName()))) {
try {
String rawPassword = PasswordEncryptUtil.decryptPassword(value);
param.setRawValue(rawPassword);
} catch (Exception e) {
param.setRawValue(value);
}
modified = true;
}
}
}
}
}
return modified;
}
Aggregations