use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdi-studio-se by Talend.
the class MdmConceptMigrationTask 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 MDMConnectionItem) {
boolean modify = false;
MDMConnectionItem mdmConnItem = (MDMConnectionItem) item;
if (mdmConnItem.getConnection() instanceof MDMConnection) {
MDMConnection mdmConnection = (MDMConnection) mdmConnItem.getConnection();
final EList<Concept> schemas = mdmConnection.getSchemas();
for (Concept concept : schemas) {
if (!concept.isInputModel()) {
concept.setConceptType(MdmConceptType.OUTPUT);
modify = true;
}
}
}
if (modify) {
try {
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
factory.save(item, true);
return ExecutionResult.SUCCESS_WITH_ALERT;
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.core.repository.model.ProxyRepositoryFactory 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;
}
use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdi-studio-se by Talend.
the class ConnectionAddUniqueNameMigrationTask method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
try {
uniqueConnectionNameList.clear();
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
ProcessType processType = getProcessType(item);
boolean modified = false;
if (processType != null) {
for (Object o : processType.getConnection()) {
ConnectionType currentConnection = (ConnectionType) o;
ElementParameterType uniqueNameParam = null;
for (Object paramObject : currentConnection.getElementParameter()) {
ElementParameterType paramType = (ElementParameterType) paramObject;
if (UNIQUE_NAME.equals(paramType.getName())) {
uniqueNameParam = paramType;
}
}
if (uniqueNameParam == null) {
uniqueNameParam = TalendFileFactory.eINSTANCE.createElementParameterType();
uniqueNameParam.setName("UNIQUE_NAME");
uniqueNameParam.setField(EParameterFieldType.TEXT.getName());
uniqueNameParam.setContextMode(false);
currentConnection.getElementParameter().add(uniqueNameParam);
}
String value = uniqueNameParam.getValue();
String baseName = "";
if (value == null || "".equals(value)) {
modified = true;
EConnectionType connectionType = EConnectionType.getTypeFromId(currentConnection.getLineStyle());
if (connectionType.hasConnectionCategory(IConnectionCategory.UNIQUE_NAME) && connectionType.hasConnectionCategory(IConnectionCategory.FLOW)) {
baseName = null;
} else if (connectionType.equals(EConnectionType.ITERATE)) {
baseName = "iterate";
} else if (connectionType.equals(EConnectionType.TABLE)) {
baseName = null;
} else if (connectionType.equals(EConnectionType.SYNCHRONIZE) || connectionType.equals(EConnectionType.PARALLELIZE)) {
baseName = null;
} else {
baseName = connectionType.getDefaultLinkName();
}
String uniqueName = "";
if (connectionType.equals(EConnectionType.TABLE)) {
uniqueName = currentConnection.getMetaname();
} else {
uniqueName = currentConnection.getLabel();
}
if (baseName != null && !"".equals(baseName)) {
uniqueName = generateUniqueConnectionName(baseName);
}
uniqueNameParam.setValue(uniqueName);
uniqueConnectionNameList.add(uniqueName);
}
}
}
if (modified) {
factory.save(item, true);
return ExecutionResult.SUCCESS_WITH_ALERT;
} else {
return ExecutionResult.SUCCESS_NO_ALERT;
}
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdi-studio-se by Talend.
the class JSONConnectionContextHelper method getRepositoryContext.
private static ISelection getRepositoryContext(final String contextNameOrId, boolean isId) {
if (contextNameOrId == null || "".equals(contextNameOrId.trim())) {
//$NON-NLS-1$
return null;
}
if (isId && RepositoryNode.NO_ID.equals(contextNameOrId.trim())) {
return null;
}
IRepositoryViewObject contextObject = null;
try {
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
List<IRepositoryViewObject> contextObjectList = factory.getAll(ERepositoryObjectType.CONTEXT, true);
if (contextObjectList != null) {
for (IRepositoryViewObject object : contextObjectList) {
Item item = object.getProperty().getItem();
if (item != null && item instanceof ContextItem) {
String itemNameOrId = null;
if (isId) {
itemNameOrId = item.getProperty().getId();
} else {
itemNameOrId = item.getProperty().getLabel();
}
if (contextNameOrId.equals(itemNameOrId)) {
contextObject = object;
break;
}
}
}
}
} catch (PersistenceException e) {
//
}
StructuredSelection selection = new StructuredSelection();
if (contextObject != null) {
RepositoryNode repositoryNode = RepositoryNodeUtilities.getRepositoryNode(contextObject);
if (repositoryNode != null) {
selection = new StructuredSelection(repositoryNode);
}
}
return selection;
}
use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdi-studio-se by Talend.
the class RenametForCurrentIterationMigrationTask method convertItem.
private boolean convertItem(Item item, ProcessType processType) throws PersistenceException {
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
boolean modified = false;
ECodeLanguage language = getProject().getLanguage();
EList node = processType.getNode();
for (Object n : node) {
NodeType type = (NodeType) n;
EList elementParameterList = type.getElementParameter();
for (Object elem : elementParameterList) {
ElementParameterType elemType = (ElementParameterType) elem;
if (!elemType.getField().equals("CHECK")) {
//$NON-NLS-1$
if (language.equals(ECodeLanguage.JAVA)) {
if (elemType.getValue() != null && elemType.getValue().contains(TFOR) && elemType.getValue().contains(CURRENT_ITER)) {
elemType.setValue(elemType.getValue().replaceAll(CURRENT_ITER, CURRENT_VALUE));
}
}
if (elemType.getValue() != null && elemType.getValue().contains(TFOR)) {
elemType.setValue(elemType.getValue().replaceAll(TFOR, TLOOP));
modified = true;
}
// for table
EList elemValue = elemType.getElementValue();
for (Object elemV : elemValue) {
ElementValueType elemVal = (ElementValueType) elemV;
if (language.equals(ECodeLanguage.JAVA)) {
if (elemVal.getValue() != null && elemVal.getValue().contains(TFOR) && elemVal.getValue().contains(CURRENT_ITER)) {
elemVal.setValue(elemVal.getValue().replaceAll(CURRENT_ITER, CURRENT_VALUE));
}
}
if (elemVal.getValue() != null && elemVal.getValue().contains(TFOR)) {
elemVal.setValue(elemVal.getValue().replaceAll(TFOR, TLOOP));
modified = true;
}
}
}
}
}
if (modified) {
factory.save(item, true);
}
return modified;
}
Aggregations