use of org.talend.designer.core.model.utils.emf.talendfile.MetadataType in project tesb-studio-se by Talend.
the class ConsumerFaultResponseMigrationTask method addMoreFaultResponseMessage.
private void addMoreFaultResponseMessage(Item item) throws PersistenceException {
if (item instanceof ProcessItem) {
ProcessType processType = ((ProcessItem) item).getProcess();
for (Object o : processType.getNode()) {
if (o instanceof NodeType) {
NodeType currentNode = (NodeType) o;
if ("tESBConsumer".equals(currentNode.getComponentName())) {
Iterator<?> iterator = currentNode.getMetadata().iterator();
while (iterator.hasNext()) {
MetadataType metadataType = (MetadataType) iterator.next();
if ("FAULT".equals(metadataType.getConnector())) {
EList<?> column = metadataType.getColumn();
addColumn(column, faultActor);
addColumn(column, faultCode);
addColumn(column, faultNode);
addColumn(column, faultRole);
}
}
}
}
}
FACTORY.save(item, true);
}
}
use of org.talend.designer.core.model.utils.emf.talendfile.MetadataType in project tdi-studio-se by Talend.
the class NewComponentFrameworkMigrationTask method execute.
@Override
public ExecutionResult execute(final Item item) {
final ProcessType processType = getProcessType(item);
ComponentCategory category = ComponentCategory.getComponentCategoryFromItem(item);
Properties props = getPropertiesFromFile();
IComponentConversion conversion = new IComponentConversion() {
@Override
public void transform(NodeType nodeType) {
if (nodeType == null || props == null) {
return;
}
boolean modified = false;
Map<String, String> schemaParamMap = new HashMap<>();
String currComponentName = nodeType.getComponentName();
String newComponentName = props.getProperty(currComponentName);
nodeType.setComponentName(newComponentName);
IComponent component = ComponentsFactoryProvider.getInstance().get(newComponentName, category.getName());
ComponentProperties compProperties = ComponentsUtils.getComponentProperties(newComponentName);
FakeNode fNode = new FakeNode(component);
for (IElementParameter param : fNode.getElementParameters()) {
if (param instanceof GenericElementParameter) {
String paramName = param.getName();
NamedThing currNamedThing = ComponentsUtils.getGenericSchemaElement(compProperties, paramName);
String oldParamName = props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName);
if (oldParamName != null && !(oldParamName = oldParamName.trim()).isEmpty()) {
if (currNamedThing instanceof Property && (GenericTypeUtils.isSchemaType((Property<?>) currNamedThing))) {
schemaParamMap.put(paramName, props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName + IGenericConstants.EXP_SEPARATOR + "connector"));
}
ElementParameterType paramType = getParameterType(nodeType, oldParamName);
if (paramType != null) {
if (currNamedThing instanceof ComponentReferenceProperties) {
ComponentReferenceProperties refProps = (ComponentReferenceProperties) currNamedThing;
refProps.referenceType.setValue(ComponentReferenceProperties.ReferenceType.COMPONENT_INSTANCE);
refProps.componentInstanceId.setStoredValue(ParameterUtilTool.convertParameterValue(paramType));
refProps.componentInstanceId.setTaggedValue(IGenericConstants.ADD_QUOTES, true);
} else {
processMappedElementParameter(props, nodeType, (GenericElementParameter) param, paramType, currNamedThing);
}
ParameterUtilTool.removeParameterType(nodeType, paramType);
modified = true;
}
if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
//$NON-NLS-1$
String schemaTypeName = ":" + EParameterName.SCHEMA_TYPE.getName();
//$NON-NLS-1$
String repSchemaTypeName = ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
paramType = getParameterType(nodeType, oldParamName + schemaTypeName);
if (paramType != null) {
paramType.setName(param.getName() + schemaTypeName);
}
paramType = getParameterType(nodeType, oldParamName + repSchemaTypeName);
if (paramType != null) {
paramType.setName(param.getName() + repSchemaTypeName);
}
}
} else {
processUnmappedElementParameter(props, nodeType, (GenericElementParameter) param, currNamedThing);
}
} else {
if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
String paramName = param.getName();
schemaParamMap.put(paramName, props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName + IGenericConstants.EXP_SEPARATOR + "connector"));
String oldParamName = props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName);
//$NON-NLS-1$
String schemaTypeName = ":" + EParameterName.SCHEMA_TYPE.getName();
//$NON-NLS-1$
String repSchemaTypeName = ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
ElementParameterType paramType = getParameterType(nodeType, oldParamName + schemaTypeName);
if (paramType != null) {
paramType.setName(param.getName() + schemaTypeName);
}
paramType = getParameterType(nodeType, oldParamName + repSchemaTypeName);
if (paramType != null) {
paramType.setName(param.getName() + repSchemaTypeName);
}
}
}
}
// Migrate schemas
Map<String, MetadataType> metadatasMap = new HashMap<>();
EList<MetadataType> metadatas = nodeType.getMetadata();
for (MetadataType metadataType : metadatas) {
metadatasMap.put(metadataType.getConnector(), metadataType);
}
Iterator<Entry<String, String>> schemaParamIter = schemaParamMap.entrySet().iterator();
//$NON-NLS-1$
String uniqueName = ParameterUtilTool.getParameterValue(nodeType, "UNIQUE_NAME");
while (schemaParamIter.hasNext()) {
Entry<String, String> schemaParamEntry = schemaParamIter.next();
String newParamName = schemaParamEntry.getKey();
String connectorMapping = schemaParamEntry.getValue();
//$NON-NLS-1$
String oldConnector = connectorMapping.split("->")[0];
//$NON-NLS-1$
String newConnector = connectorMapping.split("->")[1];
MetadataType metadataType = metadatasMap.get(oldConnector);
if (metadataType != null) {
metadataType.setConnector(newConnector);
MetadataEmfFactory factory = new MetadataEmfFactory();
factory.setMetadataType(metadataType);
IMetadataTable metadataTable = factory.getMetadataTable();
Schema schema = SchemaUtils.convertTalendSchemaIntoComponentSchema(ConvertionHelper.convert(metadataTable));
compProperties.setValue(newParamName, schema);
}
if (!oldConnector.equals(newConnector)) {
// if connector was changed, we should update the connections
for (Object connectionObj : processType.getConnection()) {
if (connectionObj instanceof ConnectionType) {
ConnectionType connectionType = (ConnectionType) connectionObj;
if (connectionType.getSource().equals(uniqueName) && connectionType.getConnectorName().equals(oldConnector)) {
connectionType.setConnectorName(newConnector);
}
}
}
}
}
for (Object connectionObj : processType.getConnection()) {
ConnectionType connection = (ConnectionType) connectionObj;
if (connection.getSource() != null && connection.getSource().equals(uniqueName)) {
if (EConnectionType.FLOW_MAIN.getName().equals(connection.getConnectorName())) {
connection.setConnectorName(Connector.MAIN_NAME);
}
}
}
if (modified) {
String serializedProperties = compProperties.toSerialized();
if (serializedProperties != null) {
ElementParameterType pType = //$NON-NLS-1$
ParameterUtilTool.createParameterType(//$NON-NLS-1$
null, //$NON-NLS-1$
"PROPERTIES", serializedProperties);
nodeType.getElementParameter().add(pType);
}
}
}
};
if (processType != null) {
boolean modified = false;
for (Object obj : processType.getNode()) {
if (obj != null && obj instanceof NodeType) {
String componentName = ((NodeType) obj).getComponentName();
String newComponentName = props.getProperty(componentName);
if (newComponentName == null) {
continue;
}
IComponentFilter filter = new NameComponentFilter(componentName);
modified = ModifyComponentsAction.searchAndModify((NodeType) obj, filter, Arrays.<IComponentConversion>asList(conversion)) || modified;
}
}
if (modified) {
try {
ProxyRepositoryFactory.getInstance().save(item, true);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.designer.core.model.utils.emf.talendfile.MetadataType in project tdi-studio-se by Talend.
the class RenameFieldNameFortLineChart method renameField.
private void renameField(Item item) {
ProcessType processType = getProcessType(item);
String uniqueComponentName = null;
// search tLineChart components
for (Object o : processType.getNode()) {
if (o instanceof NodeType) {
NodeType currentNode = (NodeType) o;
String currentNodeName = currentNode.getComponentName();
if ("tLineChart".equals(currentNodeName)) {
if (currentNode.getMetadata().size() > 0) {
for (Object e : currentNode.getElementParameter()) {
ElementParameterType p = (ElementParameterType) e;
if ("UNIQUE_NAME".equals(p.getName())) {
uniqueComponentName = p.getValue();
listComponent.add(uniqueComponentName);
}
}
}
}
}
}
// end search
searchSourceComponents(item);
// correct the word
for (Object o : processType.getNode()) {
if (o instanceof NodeType) {
NodeType currentNode = (NodeType) o;
for (MetadataType metadata : (EList<MetadataType>) currentNode.getMetadata()) {
for (Object e : currentNode.getElementParameter()) {
ElementParameterType p = (ElementParameterType) e;
if ("UNIQUE_NAME".equals(p.getName())) {
uniqueComponentName = p.getValue();
if (listComponent.contains(uniqueComponentName)) {
EList<ColumnType> columns = metadata.getColumn();
for (ColumnType column : columns) {
if ("serie".equals(column.getName())) {
column.setName("series");
}
}
}
}
}
}
}
}
}
use of org.talend.designer.core.model.utils.emf.talendfile.MetadataType in project tdi-studio-se by Talend.
the class AddWebServiceOutputTableMigrationTask method addNewColumn.
private void addNewColumn(Item item) {
// TODO Auto-generated method stub
boolean isUpdate = false;
MetadataType metadata;
ProcessType processType = getProcessType(item);
TalendFileFactory fileFact = TalendFileFactory.eINSTANCE;
String webServiceComponentName = "";
NodeType webServiceNode = null;
for (Object o : processType.getNode()) {
if (o instanceof NodeType) {
NodeType currentNode = (NodeType) o;
if ("tWebService".equals(currentNode.getComponentName())) {
webServiceNode = currentNode;
if (currentNode.getMetadata().size() == 1) {
isUpdate = true;
for (Object e : currentNode.getElementParameter()) {
ElementParameterType p = (ElementParameterType) e;
if ("UNIQUE_NAME".equals(p.getName())) {
webServiceComponentName = p.getValue();
MetadataType newMetadata = (MetadataType) currentNode.getMetadata().get(0);
newMetadata.getColumn().clear();
}
}
}
}
}
}
if (isUpdate) {
String name = "";
String webSourceName = "";
String webserviceOutNaame = "";
for (Object o : processType.getConnection()) {
if (o instanceof ConnectionType) {
ConnectionType currentConnection = (ConnectionType) o;
if ("FLOW".equals(currentConnection.getConnectorName()) && currentConnection.getTarget().equals(webServiceComponentName)) {
webSourceName = currentConnection.getSource();
} else if ("FLOW".equals(currentConnection.getConnectorName()) && currentConnection.getSource().equals(webServiceComponentName)) {
webserviceOutNaame = currentConnection.getTarget();
currentConnection.setConnectorName("OUTPUT");
currentConnection.setMetaname("OUTPUT");
}
}
}
for (Object o : processType.getNode()) {
if (o instanceof NodeType) {
NodeType currentNode = (NodeType) o;
for (Object e : currentNode.getElementParameter()) {
ElementParameterType p = (ElementParameterType) e;
if ("UNIQUE_NAME".equals(p.getName()) && webSourceName.equals(p.getValue())) {
MetadataType newMetadata = (MetadataType) currentNode.getMetadata().get(0);
metadata = ((MetadataType) webServiceNode.getMetadata().get(0));
EList<ColumnType> list = newMetadata.getColumn();
for (int i = 0; i < list.size(); i++) {
ColumnType in = (ColumnType) list.get(i);
ColumnType out = fileFact.createColumnType();
out.setComment(in.getComment());
out.setKey(in.isKey());
out.setNullable(in.isNullable());
if (String.valueOf(in.getLength()).equals("0")) {
out.unsetLength();
} else {
out.setLength(in.getLength());
}
out.setName(in.getName());
if (String.valueOf(in.getPrecision()).equals("0")) {
out.unsetPrecision();
} else {
out.setPrecision(in.getPrecision());
}
if (!in.getName().equals(in.getOriginalDbColumnName())) {
out.setOriginalDbColumnName(in.getOriginalDbColumnName());
}
out.setType(in.getType());
out.setSourceType(in.getSourceType());
out.setPattern(in.getPattern());
out.setDefaultValue(in.getDefaultValue());
metadata.getColumn().add(out);
}
} else if ("UNIQUE_NAME".equals(p.getName()) && webserviceOutNaame.equals(p.getValue())) {
MetadataType newMetadata = fileFact.createMetadataType();
metadata = ((MetadataType) currentNode.getMetadata().get(0));
name = metadata.getName();
EList<ColumnType> list = metadata.getColumn();
newMetadata.setName("OUTPUT");
newMetadata.setConnector("OUTPUT");
for (int i = 0; i < list.size(); i++) {
ColumnType in = (ColumnType) list.get(i);
ColumnType out = fileFact.createColumnType();
out.setComment(in.getComment());
out.setKey(in.isKey());
out.setNullable(in.isNullable());
if (String.valueOf(in.getLength()).equals("0")) {
out.unsetLength();
} else {
out.setLength(in.getLength());
}
out.setName(in.getName());
if (String.valueOf(in.getPrecision()).equals("0")) {
out.unsetPrecision();
} else {
out.setPrecision(in.getPrecision());
}
if (!in.getName().equals(in.getOriginalDbColumnName())) {
out.setOriginalDbColumnName(in.getOriginalDbColumnName());
}
out.setType(in.getType());
out.setSourceType(in.getSourceType());
out.setPattern(in.getPattern());
out.setDefaultValue(in.getDefaultValue());
newMetadata.getColumn().add(out);
webServiceNode.getMetadata().add(newMetadata);
}
}
}
}
}
}
if (isUpdate) {
try {
FACTORY.save(item, true);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
}
use of org.talend.designer.core.model.utils.emf.talendfile.MetadataType in project tdi-studio-se by Talend.
the class UpgradetDenormalizeMigrationTask method execute.
public ExecutionResult execute(Item item) {
ProcessType processType = getProcessType(item);
if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
return ExecutionResult.NOTHING_TO_DO;
}
try {
//$NON-NLS-1$
IComponentFilter filter1 = new NameComponentFilter("tDenormalize");
IComponentConversion conversion = new IComponentConversion() {
public void transform(NodeType node) {
List<ElementValueType> values = new ArrayList<ElementValueType>();
TalendFileFactory fileFact = TalendFileFactory.eINSTANCE;
MetadataType object = (MetadataType) node.getMetadata().get(0);
//$NON-NLS-1$
String delimiterValue = ComponentUtilities.getNodePropertyValue(node, "DELIMITER");
//$NON-NLS-1$
String mergeValue = ComponentUtilities.getNodePropertyValue(node, "MERGE");
//$NON-NLS-1$
ElementParameterType p = ComponentUtilities.getNodeProperty(node, "GROUPS");
if (p != null) {
EList<ElementValueType> es = p.getElementValue();
List<String> groups = new ArrayList<String>();
for (ElementValueType e : es) {
if (e.getElementRef().equals("INPUT_COLUMN")) {
//$NON-NLS-1$
groups.add(e.getValue());
}
}
for (Object o : object.getColumn()) {
ColumnType tagada = (ColumnType) o;
if (groups.contains(tagada.getName())) {
continue;
}
ElementValueType elementValue = fileFact.createElementValueType();
//$NON-NLS-1$
elementValue.setElementRef("INPUT_COLUMN");
elementValue.setValue(tagada.getName());
values.add(elementValue);
ElementValueType elementValue2 = fileFact.createElementValueType();
//$NON-NLS-1$
elementValue2.setElementRef("DELIMITER");
elementValue2.setValue(delimiterValue);
values.add(elementValue2);
ElementValueType elementValue3 = fileFact.createElementValueType();
//$NON-NLS-1$
elementValue3.setElementRef("MERGE");
elementValue3.setValue(mergeValue);
values.add(elementValue3);
}
//$NON-NLS-1$ //$NON-NLS-2$
ComponentUtilities.addNodeProperty(node, "DENORMALIZE_COLUMNS", "TABLE");
//$NON-NLS-1$
ComponentUtilities.setNodeProperty(node, "DENORMALIZE_COLUMNS", values);
//$NON-NLS-1$
ComponentUtilities.removeNodeProperty(node, "DELIMITER");
//$NON-NLS-1$
ComponentUtilities.removeNodeProperty(node, "MERGE");
//$NON-NLS-1$
ComponentUtilities.removeNodeProperty(node, "GROUPS");
}
}
};
ModifyComponentsAction.searchAndModify(item, processType, filter1, Arrays.<IComponentConversion>asList(conversion));
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
Aggregations