use of org.talend.designer.core.model.utils.emf.talendfile.MetadataType in project tdi-studio-se by Talend.
the class AddDdColumnMigrationTask method removeDbColumn.
private void removeDbColumn(Item item) throws PersistenceException {
ProcessType processType = getProcessType(item);
if (processType == null) {
return;
}
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
boolean modified = false;
for (Object o : processType.getNode()) {
NodeType node = (NodeType) o;
for (Object o2 : node.getMetadata()) {
MetadataType metadata = (MetadataType) o2;
for (Object o3 : metadata.getColumn()) {
ColumnType column = (ColumnType) o3;
if (column.getOriginalDbColumnName() != null) {
column.setOriginalDbColumnName(null);
modified = true;
}
}
}
}
if (modified) {
factory.save(item, true);
}
}
use of org.talend.designer.core.model.utils.emf.talendfile.MetadataType in project tdi-studio-se by Talend.
the class RenameCustomerColumnOftGenKey method changeCustomerColumn.
private void changeCustomerColumn(Item item) throws PersistenceException {
ProcessType processType = getProcessType(item);
if (processType == null) {
return;
}
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
boolean modified = false;
for (Object o : processType.getNode()) {
NodeType node = (NodeType) o;
for (Object o2 : node.getMetadata()) {
MetadataType metadata = (MetadataType) o2;
for (Object o3 : metadata.getColumn()) {
ColumnType column = (ColumnType) o3;
if ("T_WINDOW_KEY".equals(column.getName())) {
column.setName("T_GEN_KEY");
modified = true;
}
}
}
}
if (modified) {
factory.save(item, true);
}
}
use of org.talend.designer.core.model.utils.emf.talendfile.MetadataType in project tdi-studio-se by Talend.
the class FixWrongDbTypesMigrationTask 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);
if (processType == null) {
return ExecutionResult.NOTHING_TO_DO;
}
boolean modified = false;
for (Object nodeTypeObject : processType.getNode()) {
NodeType nodeType = (NodeType) nodeTypeObject;
IComponent component = ComponentsFactoryProvider.getInstance().get(nodeType.getComponentName(), ComponentCategory.CATEGORY_4_DI.getName());
if (component == null) {
// in case original component doesn't exist here
continue;
}
FakeNode fNode = new FakeNode(component);
IElementParameter mappingParameter = fNode.getElementParameterFromField(EParameterFieldType.MAPPING_TYPE);
if (mappingParameter != null && mappingParameter.getValue() != null) {
String mappingParameterValue = (String) mappingParameter.getValue();
MappingTypeRetriever mtr = MetadataTalendType.getMappingTypeRetriever(mappingParameterValue);
if (mtr == null) {
continue;
}
for (Object metadataObject : nodeType.getMetadata()) {
MetadataType metadataType = (MetadataType) metadataObject;
for (Object columnObject : metadataType.getColumn()) {
ColumnType columnType = (ColumnType) columnObject;
if (columnType.getSourceType() != null && !"".equals(columnType.getSourceType())) {
if (mtr.isAdvicedTalendToDbType(columnType.getType(), columnType.getSourceType())) {
// correct type already, no need to do anything
continue;
}
List<MappingType> advicedTalendToDbTypes = mtr.getAdvicedTalendToDbTypes(columnType.getType());
if (advicedTalendToDbTypes == null) {
continue;
}
String dbType = columnType.getSourceType();
for (MappingType type : advicedTalendToDbTypes) {
if (type.getDbType().equalsIgnoreCase(dbType)) {
columnType.setSourceType(type.getDbType());
modified = true;
break;
}
}
}
}
}
}
}
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 AddSchemaDefaultValue4tFileInputDelimited method execute.
@Override
public ExecutionResult execute(Item item) {
ProcessType processType = getProcessType(item);
IComponentFilter filter = new NameComponentFilter("tFileInputDelimited");
try {
ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(new IComponentConversion() {
public void transform(NodeType node) {
EList<EObject> list = node.eContents();
for (EObject object : list) {
if (object instanceof MetadataType) {
MetadataType flow = (MetadataType) object;
if ("FLOW".equalsIgnoreCase(flow.getConnector())) {
Iterator<?> columns = flow.getColumn().iterator();
while (columns.hasNext()) {
Object outColumn = columns.next();
if (outColumn instanceof ColumnType) {
ColumnType column = ((ColumnType) outColumn);
JavaType javaType = JavaTypesManager.getJavaTypeFromId(column.getType());
boolean isJavaPrimitiveType = JavaTypesManager.isJavaPrimitiveType(javaType, column.isNullable());
if (isJavaPrimitiveType && (column.getDefaultValue() == null || column.getDefaultValue().isEmpty())) {
String defaultValue = JavaTypesManager.getDefaultValueFromJavaType(javaType.getPrimitiveClass().getSimpleName(), null);
if (defaultValue != null) {
column.setDefaultValue(defaultValue);
}
}
}
}
}
}
}
}
}));
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
return ExecutionResult.SUCCESS_NO_ALERT;
}
use of org.talend.designer.core.model.utils.emf.talendfile.MetadataType in project tdi-studio-se by Talend.
the class ReplaceMultiFlowBytReplicateMigrationTask method createNodeType.
/**
* DOC nrousseau Comment method "createNodeType".
*
* @param processType
* @param replicatePos
* @param nodeTypeSource
* @param sourceName
* @param nodeConnector
* @param connections
* @param fileFact
* @return
*/
private String createNodeType(ProcessType processType, Point replicatePos, NodeType nodeTypeSource, String sourceName, INodeConnector nodeConnector, List<ConnectionType> connections, TalendFileFactory fileFact) {
NodeType nodeType = fileFact.createNodeType();
//$NON-NLS-1$
String uniqueName = ComponentUtilities.generateUniqueNodeName("tReplicate", processType);
ElementParameterType elemParam = fileFact.createElementParameterType();
//$NON-NLS-1$
elemParam.setField("TEXT");
//$NON-NLS-1$
elemParam.setName("UNIQUE_NAME");
elemParam.setValue(uniqueName);
nodeType.getElementParameter().add(elemParam);
ComponentUtilities.setNodeUniqueName(nodeType, uniqueName);
//$NON-NLS-1$
nodeType.setComponentName("tReplicate");
for (ConnectionType connectionType : connections) {
//$NON-NLS-1$
connectionType.setConnectorName("FLOW");
connectionType.setSource(uniqueName);
connectionType.setMetaname(uniqueName);
}
nodeType.setPosX(replicatePos.x);
nodeType.setPosY(replicatePos.y);
nodeType.setSizeX(GRID_SIZE);
nodeType.setSizeY(GRID_SIZE);
if (nodeTypeSource.getMetadata().size() != 0) {
MetadataType metadataTypeSource = null;
for (Object oMetadataType : nodeTypeSource.getMetadata()) {
MetadataType metadataType = (MetadataType) oMetadataType;
if ((metadataType.getConnector() != null && metadataType.getConnector().equals(nodeConnector.getName())) || metadataType.getName().equals(sourceName)) {
metadataTypeSource = metadataType;
}
}
if (metadataTypeSource != null) {
MetadataType newMetadataType = fileFact.createMetadataType();
newMetadataType.setComment(metadataTypeSource.getComment());
//$NON-NLS-1$
newMetadataType.setConnector("FLOW");
newMetadataType.setName(uniqueName);
for (Object oColumn : metadataTypeSource.getColumn()) {
ColumnType columnType = (ColumnType) oColumn;
ColumnType newColumnType = fileFact.createColumnType();
newColumnType.setComment(columnType.getComment());
newColumnType.setDefaultValue(columnType.getDefaultValue());
if (columnType.isSetKey()) {
newColumnType.setKey(columnType.isKey());
}
if (columnType.isSetLength()) {
newColumnType.setLength(columnType.getLength());
}
newColumnType.setName(columnType.getName());
if (columnType.isSetNullable()) {
newColumnType.setNullable(columnType.isNullable());
}
newColumnType.setOriginalDbColumnName(columnType.getOriginalDbColumnName());
newColumnType.setPattern(columnType.getPattern());
if (columnType.isSetPrecision()) {
newColumnType.setPrecision(columnType.getPrecision());
}
newColumnType.setSourceType(columnType.getSourceType());
newColumnType.setType(columnType.getType());
newMetadataType.getColumn().add(newColumnType);
}
nodeType.getMetadata().add(newMetadataType);
}
}
processType.getNode().add(nodeType);
return uniqueName;
}
Aggregations