use of org.talend.designer.core.model.utils.emf.talendfile.AbstractExternalData in project tdi-studio-se by Talend.
the class DBMapSplitTableConstraintFiltersMigrationTask method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
IProxyRepositoryFactory factory = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
ProcessType processType = getProcessType(item);
boolean modified = false;
if (processType != null) {
for (Object obj : processType.getNode()) {
NodeType nodeType = (NodeType) obj;
AbstractExternalData externalData = nodeType.getNodeData();
if (externalData instanceof DBMapData) {
DBMapData mapperData = (DBMapData) externalData;
for (OutputTable pTable : mapperData.getOutputTables()) {
int i = 0;
List<FilterEntry> needSplitFilters = new ArrayList<FilterEntry>();
List<FilterEntry> newFilters = new ArrayList<FilterEntry>();
for (FilterEntry pFilter : pTable.getFilterEntries()) {
String expression = pFilter.getExpression();
if (expression != null && !expression.trim().isEmpty()) {
if (!DbGenerationManager.containWith(expression, DbMapSqlConstants.GROUP_BY_PATTERN, false) && !DbGenerationManager.containWith(expression, DbMapSqlConstants.ORDER_BY_PATTERN, false)) {
continue;
} else {
// can not split the clause directly here, because clause like this(a = b GROUP BY
// c) will be put at
// the end of where clause
needSplitFilters.add(pFilter);
}
}
}
if (!needSplitFilters.isEmpty()) {
EList<FilterEntry> entryList = pTable.getFilterEntries();
for (FilterEntry pFilter : needSplitFilters) {
String expression = pFilter.getExpression().trim();
int splitIndex = firstIndexInString(expression, DbMapSqlConstants.GROUP_BY_PATTERN);
int orderIndex = firstIndexInString(expression, DbMapSqlConstants.ORDER_BY_PATTERN);
if (splitIndex < 0 || (0 <= orderIndex && orderIndex < splitIndex)) {
splitIndex = orderIndex;
}
if (splitIndex == 0) {
// keep the order of "GROUP BY" and "ORDER BY"
pFilter.setFilterKind(FilterTableEntry.OTHER_FILTER);
entryList.remove(pFilter);
newFilters.add(pFilter);
} else {
String whereClause = expression.substring(0, splitIndex);
if (//$NON-NLS-1$
!DbGenerationManager.containWith(expression, DbMapSqlConstants.OR + "\\b", true) && !DbGenerationManager.containWith(expression, DbMapSqlConstants.AND + "\\b", true)) {
//$NON-NLS-1$
//$NON-NLS-1$
whereClause = DbMapSqlConstants.AND + " " + whereClause;
}
pFilter.setExpression(whereClause);
FilterEntry tFilter = DbmapFactory.eINSTANCE.createFilterEntry();
//$NON-NLS-1$
tFilter.setName("newFilterSplited" + ++i);
tFilter.setExpression(expression.substring(splitIndex).trim());
tFilter.setFilterKind(FilterTableEntry.OTHER_FILTER);
entryList.remove(pFilter);
entryList.add(pFilter);
newFilters.add(tFilter);
}
modified = true;
}
if (!newFilters.isEmpty()) {
pTable.getFilterEntries().addAll(newFilters);
modified = true;
}
}
}
}
}
}
try {
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.designer.core.model.utils.emf.talendfile.AbstractExternalData in project tdi-studio-se by Talend.
the class DbMapService method updateEMFDBMapData.
@Override
public void updateEMFDBMapData(NodeType nodeType, String oldValue, String newValue) {
AbstractExternalData nodeData = nodeType.getNodeData();
if (nodeData instanceof DBMapData) {
DBMapData dbMapData = (DBMapData) nodeData;
for (InputTable input : dbMapData.getInputTables()) {
if (input.getName().equals(oldValue) || input.getTableName().equals(oldValue)) {
input.setName(newValue);
input.setTableName(newValue);
}
}
for (OutputTable output : dbMapData.getOutputTables()) {
List<DBMapperTableEntry> entries = output.getDBMapperTableEntries();
for (DBMapperTableEntry entry : entries) {
String expression = entry.getExpression();
if (expression != null && !"".equals(expression.trim())) {
//$NON-NLS-1$
//$NON-NLS-1$
int index = expression.lastIndexOf(".");
// at least "a.b"
if (index > 0) {
String connectionName = expression.substring(0, index);
if (oldValue.equals(connectionName)) {
entry.setExpression(newValue + expression.substring(index, expression.length()));
}
}
}
}
}
}
}
use of org.talend.designer.core.model.utils.emf.talendfile.AbstractExternalData in project tdi-studio-se by Talend.
the class MapperSchemaTypeItemRelationshipHandler method collect.
/*
* (non-Javadoc)
*
* @see
* org.talend.core.model.relationship.AbstractItemRelationshipHandler#collect(org.talend.core.model.properties.Item)
*/
@Override
protected Set<Relation> collect(Item baseItem) {
ProcessType processType = getProcessType(baseItem);
if (processType == null) {
return Collections.emptySet();
}
Set<Relation> relationSet = new HashSet<Relation>();
// handle tMap schema relations...
if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerMapperService.class)) {
IDesignerMapperService service = (IDesignerMapperService) GlobalServiceRegister.getDefault().getService(IDesignerMapperService.class);
for (Object o : processType.getNode()) {
if (o instanceof NodeType) {
NodeType currentNode = (NodeType) o;
AbstractExternalData nodeData = currentNode.getNodeData();
if (nodeData != null) {
List<String> schemaIds = service.getRepositorySchemaIds(nodeData);
if (schemaIds != null && schemaIds.size() > 0) {
for (String schemaId : schemaIds) {
Relation addedRelation = new Relation();
addedRelation.setId(schemaId);
addedRelation.setType(RelationshipItemBuilder.SCHEMA_RELATION);
addedRelation.setVersion(RelationshipItemBuilder.LATEST_VERSION);
relationSet.add(addedRelation);
}
}
}
}
}
}
return relationSet;
}
use of org.talend.designer.core.model.utils.emf.talendfile.AbstractExternalData in project tdi-studio-se by Talend.
the class XmlMapService method checkXMLMapDifferents.
/*
* (non-Javadoc)
*
* @see org.talend.core.service.IXmlMapService#checkXMLMapDifferents(org.talend.core.model.process.INode,
* org.talend.core.model.process.INode)
*/
@Override
public boolean checkXMLMapDifferents(INode testNode, INode originalNode) {
AbstractExternalData oriExternalData = originalNode.getExternalNode().getExternalEmfData();
AbstractExternalData testExternalData = testNode.getExternalNode().getExternalEmfData();
if (oriExternalData == null && testExternalData == null) {
return false;
}
if (oriExternalData == null || testExternalData == null) {
return true;
}
if (!(oriExternalData instanceof XmlMapData) || !(testExternalData instanceof XmlMapData)) {
return false;
}
Map<String, String> inputConnNameMap = getInputConnectionNameMap(testNode);
XmlMapData oriXmlData = (XmlMapData) oriExternalData;
XmlMapData testXmlData = (XmlMapData) testExternalData;
EList<InputXmlTree> oriInputs = oriXmlData.getInputTrees();
EList<OutputXmlTree> oriOutputs = oriXmlData.getOutputTrees();
EList<VarTable> oriVars = oriXmlData.getVarTables();
EList<InputXmlTree> testInputs = testXmlData.getInputTrees();
EList<OutputXmlTree> testOutputs = testXmlData.getOutputTrees();
EList<VarTable> testVars = testXmlData.getVarTables();
if (oriInputs.size() != testInputs.size()) {
return true;
}
if (oriOutputs.size() != testOutputs.size()) {
return true;
}
if (oriVars.size() != testVars.size()) {
return true;
}
for (InputXmlTree oriInput : oriInputs) {
String oriName = oriInput.getName();
InputXmlTree testInput = null;
for (InputXmlTree input : testInputs) {
if (input.getName().equals(oriName)) {
testInput = input;
break;
}
}
if (testInput == null) {
testInput = getInputXmlTree(testNode, testInputs, oriName);
}
if (testInput == null) {
return true;
}
if (oriInput.isActivateExpressionFilter() != testInput.isActivateExpressionFilter()) {
return true;
}
if (oriInput.getExpressionFilter() != testInput.getExpressionFilter()) {
return true;
}
if (oriInput.isMinimized() != testInput.isMinimized()) {
return true;
}
if (oriInput.isActivateCondensedTool() != testInput.isActivateCondensedTool()) {
return true;
}
EList<TreeNode> oriEntrys = oriInput.getNodes();
EList<TreeNode> testEntrys = testInput.getNodes();
if (oriEntrys.size() != testEntrys.size()) {
return true;
}
for (TreeNode oriEntry : oriEntrys) {
String oriEntryName = oriEntry.getName();
boolean found = false;
for (TreeNode testEntry : testEntrys) {
if (oriEntryName.equals(testEntry.getName())) {
found = true;
if (checkExpression(oriEntry.getExpression(), testEntry.getExpression(), inputConnNameMap)) {
return true;
}
break;
}
}
if (!found) {
return true;
}
}
}
for (OutputXmlTree oriOutput : oriOutputs) {
String oriName = oriOutput.getName();
OutputXmlTree testOutput = null;
for (OutputXmlTree output : testOutputs) {
if (output.getName().equals(oriName)) {
testOutput = output;
break;
}
}
if (testOutput == null) {
testOutput = getOutputXmlTree(testNode, testOutputs, oriName);
}
if (testOutput == null) {
return true;
}
if (oriOutput.isActivateExpressionFilter() != testOutput.isActivateExpressionFilter()) {
return true;
}
if (oriOutput.getExpressionFilter() != testOutput.getExpressionFilter()) {
return true;
}
if (oriOutput.isMinimized() != testOutput.isMinimized()) {
return true;
}
if (oriOutput.isActivateCondensedTool() != testOutput.isActivateCondensedTool()) {
return true;
}
EList<OutputTreeNode> oriEntrys = oriOutput.getNodes();
EList<OutputTreeNode> testEntrys = testOutput.getNodes();
if (oriEntrys.size() != testEntrys.size()) {
return true;
}
for (OutputTreeNode oriEntry : oriEntrys) {
String oriEntryName = oriEntry.getName();
boolean found = false;
for (OutputTreeNode testEntry : testEntrys) {
if (oriEntryName.equals(testEntry.getName())) {
found = true;
if (found) {
if (checkChildOutputTreeNode(oriEntry, testEntry, inputConnNameMap)) {
return true;
}
}
break;
}
}
if (!found) {
return true;
}
}
}
for (VarTable oriVar : oriVars) {
String oriName = oriVar.getName();
VarTable testVar = null;
for (VarTable var : testVars) {
if (var.getName().equals(oriName)) {
testVar = var;
break;
}
}
if (testVar == null) {
return true;
}
if (oriVar.isMinimized() != testVar.isMinimized()) {
return true;
}
EList<VarNode> oriEntrys = oriVar.getNodes();
EList<VarNode> testEntrys = testVar.getNodes();
if (oriEntrys.size() != testEntrys.size()) {
return true;
}
for (VarNode oriEntry : oriEntrys) {
String oriEntryName = oriEntry.getName();
boolean found = false;
for (VarNode testEntry : testEntrys) {
if (oriEntryName.equals(testEntry.getName())) {
found = true;
if (checkExpression(oriEntry.getExpression(), testEntry.getExpression(), inputConnNameMap)) {
return true;
}
}
}
if (!found) {
return true;
}
}
}
return false;
}
Aggregations