use of org.talend.core.model.process.EParameterFieldType in project tdi-studio-se by Talend.
the class EncryptPasswordInComponentsMigrationTask method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
ProcessType processType = getProcessType(item);
try {
boolean modified = false;
ComponentCategory category = ComponentCategory.getComponentCategoryFromItem(item);
for (Object nodeObjectType : processType.getNode()) {
NodeType nodeType = (NodeType) nodeObjectType;
IComponent component = ComponentsFactoryProvider.getInstance().get(nodeType.getComponentName(), category.getName());
if (component == null) {
continue;
}
FakeNode fNode = new FakeNode(component);
for (Object paramObjectType : nodeType.getElementParameter()) {
ElementParameterType param = (ElementParameterType) paramObjectType;
IElementParameter paramFromEmf = fNode.getElementParameter(param.getName());
if (paramFromEmf == null) {
// might be some deprecated / removed parameter.
continue;
}
EParameterFieldType paramFromComponent = paramFromEmf.getFieldType();
if (EParameterFieldType.PASSWORD == paramFromComponent && param.getValue() != null) {
boolean encrypted = true;
try {
int ind = param.getValue().lastIndexOf(PasswordEncryptUtil.ENCRYPT_KEY);
if (ind == -1) {
encrypted = false;
} else {
String value = new StringBuilder(param.getValue()).replace(ind, ind + PasswordEncryptUtil.ENCRYPT_KEY.length(), "").toString();
PasswordEncryptUtil.decryptPassword(value);
}
} catch (Exception e) {
encrypted = false;
}
if (!encrypted) {
param.setValue(PasswordEncryptUtil.encryptPassword(param.getValue()) + PasswordEncryptUtil.ENCRYPT_KEY);
modified = true;
}
}
}
}
if (modified) {
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
factory.save(item, true);
}
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
return ExecutionResult.SUCCESS_NO_ALERT;
}
Aggregations