use of org.talend.designer.core.model.utils.emf.talendfile.ConnectionType in project tesb-studio-se by Talend.
the class CamelFeatureUtil method addConnectionsSpecialFeatures.
private static void addConnectionsSpecialFeatures(Collection<FeatureModel> features, ProcessType processType) {
EList<?> connections = processType.getConnection();
Iterator<?> iterator = connections.iterator();
while (iterator.hasNext()) {
Object next = iterator.next();
if (!(next instanceof ConnectionType)) {
continue;
}
ConnectionType con = (ConnectionType) next;
if (!EConnectionType.ROUTE_WHEN.getName().equals(con.getConnectorName())) {
continue;
}
EList<?> elementParameters = con.getElementParameter();
Iterator<?> paraIter = elementParameters.iterator();
while (paraIter.hasNext()) {
Object paraNext = paraIter.next();
if (!(paraNext instanceof ElementParameterType)) {
continue;
}
ElementParameterType ept = (ElementParameterType) paraNext;
if (!EParameterName.ROUTETYPE.getName().equals(ept.getName())) {
continue;
}
// "python", "ruby", "simple", "spel", "sql", "xpath", "xquery" };
if ("groovy".equals(ept.getValue())) {
features.add(FEATURE_CAMEL_GROOVY);
} else if ("javaScript".equals(ept.getValue())) {
features.add(FEATURE_CAMEL_SCRIPT);
features.add(FEATURE_CAMEL_SCRIPT_JAVASCRIPT);
}
}
}
}
use of org.talend.designer.core.model.utils.emf.talendfile.ConnectionType in project tdi-studio-se by Talend.
the class ChangeModelForRoutineParameterMigrationTask2 method execute.
@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
try {
List<String> possibleRoutines = new ArrayList<String>();
List<String> routinesToAdd = new ArrayList<String>();
String additionalString = LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA ? "." : "";
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
List<IRepositoryViewObject> routines = factory.getAll(ProjectManager.getInstance().getCurrentProject(), ERepositoryObjectType.ROUTINES);
// always add the system, others must be checked
for (IRepositoryViewObject object : routines) {
if (((RoutineItem) object.getProperty().getItem()).isBuiltIn()) {
routinesToAdd.add(object.getLabel());
} else {
possibleRoutines.add(object.getLabel());
}
}
for (Project project : ProjectManager.getInstance().getAllReferencedProjects()) {
List<IRepositoryViewObject> refRoutines = factory.getAll(project, ERepositoryObjectType.ROUTINES);
for (IRepositoryViewObject object : refRoutines) {
if (!((RoutineItem) object.getProperty().getItem()).isBuiltIn()) {
if (!possibleRoutines.contains(object.getLabel())) {
possibleRoutines.add(object.getLabel());
routines.add(object);
}
}
}
}
List<RoutinesParameterType> oldList = Collections.EMPTY_LIST;
ProcessType processType = getProcessType(item);
if (null != processType) {
if (processType.getParameters() != null && processType.getParameters().getRoutinesParameter() == null) {
ParametersType parameterType = TalendFileFactory.eINSTANCE.createParametersType();
processType.setParameters(parameterType);
if (item instanceof ProcessItem) {
routinesToAdd.addAll(possibleRoutines);
possibleRoutines.clear();
}
} else {
if (processType.getParameters() == null) {
processType.setParameters(TalendFileFactory.eINSTANCE.createParametersType());
}
oldList = new ArrayList<RoutinesParameterType>(processType.getParameters().getRoutinesParameter());
if (oldList.isEmpty() && item instanceof ProcessItem) {
routinesToAdd.addAll(possibleRoutines);
possibleRoutines.clear();
}
processType.getParameters().getRoutinesParameter().clear();
}
if (processType.getRoutinesDependencies() != null && !processType.getRoutinesDependencies().isEmpty()) {
processType.getRoutinesDependencies().clear();
}
List<RoutinesParameterType> routinesDependencies = (List<RoutinesParameterType>) processType.getParameters().getRoutinesParameter();
if (!possibleRoutines.isEmpty()) {
// check possible routines to setup in process
for (ElementParameterType param : (List<ElementParameterType>) processType.getParameters().getElementParameter()) {
for (String routine : possibleRoutines) {
if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue().contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
for (ElementValueType elementValue : (List<ElementValueType>) param.getElementValue()) {
if (!routinesToAdd.contains(routine) && elementValue.getValue() != null && elementValue.getValue().contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
}
}
}
// check possible routines to setup in nodes
for (NodeType node : ((List<NodeType>) processType.getNode())) {
for (ElementParameterType param : (List<ElementParameterType>) node.getElementParameter()) {
for (String routine : possibleRoutines) {
if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue().contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
for (ElementValueType elementValue : (List<ElementValueType>) param.getElementValue()) {
if (!routinesToAdd.contains(routine) && elementValue.getValue() != null && elementValue.getValue().contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
}
}
}
}
// check possible routines to setup in connections
for (ConnectionType connection : ((List<ConnectionType>) processType.getConnection())) {
for (ElementParameterType param : (List<ElementParameterType>) connection.getElementParameter()) {
for (String routine : possibleRoutines) {
if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue().contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
for (ElementValueType elementValue : (List<ElementValueType>) param.getElementValue()) {
if (!routinesToAdd.contains(routine) && elementValue.getValue() != null && elementValue.getValue().contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
}
}
}
}
}
// just in case some routine dependencies exist before but are lost... (migration from 4.1.1 or 4.1.2)
for (RoutinesParameterType routine : oldList) {
if (!routinesToAdd.contains(routine.getName())) {
routinesDependencies.add(routine);
}
}
for (IRepositoryViewObject object : routines) {
if (routinesToAdd.contains(object.getLabel())) {
RoutinesParameterType routinesParameterType = TalendFileFactory.eINSTANCE.createRoutinesParameterType();
routinesParameterType.setId(object.getId());
routinesParameterType.setName(object.getLabel());
routinesDependencies.add(routinesParameterType);
}
}
factory.save(item, true);
}
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
use of org.talend.designer.core.model.utils.emf.talendfile.ConnectionType in project tdi-studio-se by Talend.
the class ChangeReturnTypeOfServerAliveResult 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();
EList connections = processType.getConnection();
for (Object n : node) {
NodeType type = (NodeType) n;
EList elementParameterList = type.getElementParameter();
for (Object elem : elementParameterList) {
ElementParameterType elemType = (ElementParameterType) elem;
if (language.equals(ECodeLanguage.JAVA)) {
if (elemType.getValue() != null && elemType.getValue().contains("tServerAlive")) {
//$NON-NLS-1$
Matcher match = PATTERN_GET.matcher(elemType.getValue());
String replace = getReplaceValue(match);
if (replace != null && replace.length() > 0) {
elemType.setValue(replace);
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("tServerAlive")) {
//$NON-NLS-1$
Matcher match = PATTERN_GET.matcher(elemVal.getValue());
String replace = getReplaceValue(match);
if (replace != null && replace.length() > 0) {
elemVal.setValue(replace);
modified = true;
}
}
}
}
}
}
// the links
for (Object n : connections) {
ConnectionType type = (ConnectionType) n;
EList elementParameterList = type.getElementParameter();
for (Object elem : elementParameterList) {
ElementParameterType elemType = (ElementParameterType) elem;
if (language.equals(ECodeLanguage.JAVA)) {
if (elemType.getValue() != null && elemType.getValue().contains("tServerAlive")) {
//$NON-NLS-1$
Matcher match = PATTERN_GET.matcher(elemType.getValue());
String replace = getReplaceValue(match);
if (replace != null && replace.length() > 0) {
elemType.setValue(replace);
modified = true;
}
}
}
}
}
if (modified) {
factory.save(item, true);
}
return modified;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ConnectionType in project tdi-studio-se by Talend.
the class ChangeUniqRowLinksMigrationTask method replaceConnections.
public boolean replaceConnections(Item item) throws PersistenceException {
ProcessType processType = getProcessType(item);
if (processType == null) {
return false;
}
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
boolean replaceDone = false;
boolean modified = false;
for (Object o : processType.getConnection()) {
ConnectionType currentConnection = (ConnectionType) o;
// output of the tUniqRow, set the connector name to UNIQUE.
if (((currentConnection.getConnectorName() == null) || STANDARD_CONNECTOR_NAME.equals(currentConnection.getConnectorName())) && sourceComeFromtUniqRow(processType, currentConnection.getSource())) {
currentConnection.setConnectorName(NEW_CONNECTOR_NAME);
modified = true;
}
}
if (modified) {
factory.save(item, true);
replaceDone = true;
}
return replaceDone;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ConnectionType in project tesb-studio-se by Talend.
the class DisconnectErroHandlerMigrationTask method disconnectErrorHandler.
private void disconnectErrorHandler(CamelProcessItem item) throws PersistenceException {
ProcessType processType = item.getProcess();
/*
* find all cErrorHandler components first
* and if none, then return
*/
List<String> errorHandlerIds = findAllErrorHandlerIds(processType);
if (errorHandlerIds == null || errorHandlerIds.size() == 0) {
return;
}
/*
* if a cErrorHandler has output connection but no input connection,
* then the output connection should be removed.
*/
/*
* store all connections whose target is a cErrorHandler
*/
Map<String, ConnectionType> inputMap = new HashMap<String, ConnectionType>();
/*
* store all connections whose source is a cErrorHandler
*/
Map<String, ConnectionType> outputMap = new HashMap<String, ConnectionType>();
EList connection = processType.getConnection();
for (Object o : connection) {
if (!(o instanceof ConnectionType)) {
continue;
}
ConnectionType ct = (ConnectionType) o;
String source = ct.getSource();
String target = ct.getTarget();
for (String id : errorHandlerIds) {
/*
* if source of connection is a cErrorHandler
*/
if (id.equals(source)) {
ConnectionType connectionType = inputMap.get(id);
/*
* if the cErrorHandler doesn't find an Incoming connection yet
* then store it.
*/
if (connectionType == null) {
outputMap.put(id, ct);
} else /*
* if find an Incoming connection
* then remove it from input map
*/
{
inputMap.remove(id);
}
} else /*
* if target of connection is a cErrorHandler
*/
if (id.equals(target)) {
ConnectionType connectionType = outputMap.get(id);
/*
* if the cErrorHandler doesn't find an Outgoing connection yet
* then store it.
*/
if (connectionType == null) {
inputMap.put(id, ct);
} else {
/*
* if find an outgoing connection
* then remove it from output map
*/
outputMap.remove(id);
}
}
}
}
/*
* if outgoing map is not empty, then the connection should be
* removed
*/
if (!outputMap.isEmpty()) {
Set<String> keySet = outputMap.keySet();
Iterator<String> iterator = keySet.iterator();
while (iterator.hasNext()) {
String next = iterator.next();
ConnectionType connectionType = outputMap.get(next);
connection.remove(connectionType);
}
FACTORY.save(item, true);
}
}
Aggregations