use of org.talend.designer.core.model.utils.emf.talendfile.ColumnType 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.ColumnType 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.ColumnType 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.ColumnType in project tdi-studio-se by Talend.
the class MetadataEmfFactory method setMetadataTypeCommon.
@SuppressWarnings("unchecked")
private void setMetadataTypeCommon(final MetadataType metadataType) {
this.metadataType = metadataType;
IMetadataColumn metaCol;
ColumnType colType;
EList listColType;
List<IMetadataColumn> listMetadataColumn;
metadataTable.setComment(metadataType.getComment());
metadataTable.setTableName(metadataType.getName());
metadataTable.setLabel(metadataType.getLabel());
metadataTable.setTableType(metadataType.getType());
EMap<String, String> properties = metadataType.getAdditionalProperties();
if (properties != null) {
for (Map.Entry<String, String> entry : properties.entrySet()) {
metadataTable.getAdditionalProperties().put(entry.getKey(), entry.getValue());
}
}
if (metadataType.getConnector() != null) {
metadataTable.setAttachedConnector(metadataType.getConnector());
} else {
metadataTable.setAttachedConnector(EConnectionType.FLOW_MAIN.getName());
}
listColType = metadataType.getColumn();
listMetadataColumn = new ArrayList<IMetadataColumn>();
for (int i = 0; i < listColType.size(); i++) {
colType = (ColumnType) listColType.get(i);
metaCol = new MetadataColumn();
metaCol.setComment(colType.getComment());
metaCol.setKey(colType.isKey());
metaCol.setNullable(colType.isNullable());
if (colType.getLength() >= 0) {
metaCol.setLength(new Integer(colType.getLength()));
} else {
metaCol.setLength(null);
}
if (colType.getOriginalLength() >= 0) {
metaCol.setOriginalLength(new Integer(colType.getOriginalLength()));
} else {
metaCol.setOriginalLength(null);
}
if (colType.getAdditionalField().size() > 0) {
Iterator it = colType.getAdditionalField().keySet().iterator();
while (it.hasNext()) {
String key = (String) it.next();
metaCol.getAdditionalField().put(key, (String) colType.getAdditionalField().get(key));
}
}
metaCol.setLabel(colType.getName());
if (colType.getPrecision() >= 0) {
metaCol.setPrecision(new Integer(colType.getPrecision()));
} else {
metaCol.setPrecision(null);
}
metaCol.setTalendType(colType.getType());
metaCol.setType(colType.getSourceType());
metaCol.setPattern(colType.getPattern());
metaCol.setDefault(colType.getDefaultValue());
metaCol.setRelatedEntity(colType.getRelatedEntity());
metaCol.setRelationshipType(colType.getRelationshipType());
if (colType.getOriginalDbColumnName() == null) {
metaCol.setOriginalDbColumnName(colType.getName());
} else {
metaCol.setOriginalDbColumnName(colType.getOriginalDbColumnName());
}
metaCol.setUsefulColumn(colType.isUsefulColumn());
listMetadataColumn.add(metaCol);
}
metadataTable.setListColumns(listMetadataColumn);
List<String> columnNames = new ArrayList<String>();
for (IMetadataColumn column : listMetadataColumn) {
columnNames.add(column.getLabel());
}
metadataTable.setOriginalColumns(columnNames);
}
use of org.talend.designer.core.model.utils.emf.talendfile.ColumnType in project tdi-studio-se by Talend.
the class MetadataEmfFactory method setMetadataTable.
@SuppressWarnings("unchecked")
public void setMetadataTable(final IMetadataTable metadataTable) {
this.metadataTable = metadataTable;
TalendFileFactory fileFact = TalendFileFactory.eINSTANCE;
metadataType = fileFact.createMetadataType();
IMetadataColumn metaCol;
ColumnType colType;
EList listColType;
metadataType.setComment(metadataTable.getComment());
metadataType.setName(metadataTable.getTableName());
metadataType.setLabel(metadataTable.getLabel());
metadataType.setConnector(metadataTable.getAttachedConnector());
metadataType.setType(metadataTable.getTableType());
metadataType.getAdditionalProperties().putAll(metadataTable.getAdditionalProperties());
listColType = metadataType.getColumn();
if (metadataTable.getListColumns(true) != null) {
for (int i = 0; i < metadataTable.getListColumns(true).size(); i++) {
metaCol = metadataTable.getListColumns(true).get(i);
colType = fileFact.createColumnType();
colType.setComment(metaCol.getComment());
colType.setKey(metaCol.isKey());
colType.setNullable(metaCol.isNullable());
if (metaCol.getLength() == null || metaCol.getLength().intValue() < 0) {
colType.setLength(-1);
// colType.unsetLength();
} else {
colType.setLength(metaCol.getLength());
}
if (metaCol.getOriginalLength() != null) {
colType.setOriginalLength(metaCol.getOriginalLength());
} else {
colType.setOriginalLength(-1);
}
if (metaCol.getAdditionalField().size() > 0) {
for (String key : metaCol.getAdditionalField().keySet()) {
colType.getAdditionalField().put(key, metaCol.getAdditionalField().get(key));
}
}
colType.setName(metaCol.getLabel());
if (metaCol.getPrecision() == null || metaCol.getPrecision().intValue() < 0) {
colType.setPrecision(-1);
// colType.unsetPrecision();
} else {
colType.setPrecision(metaCol.getPrecision());
}
if (!metaCol.getLabel().equals(metaCol.getOriginalDbColumnName())) {
colType.setOriginalDbColumnName(metaCol.getOriginalDbColumnName());
}
colType.setType(metaCol.getTalendType());
colType.setSourceType(metaCol.getType());
colType.setPattern(metaCol.getPattern());
colType.setDefaultValue(metaCol.getDefault());
if (PluginChecker.isDatacertPluginLoaded()) {
colType.setRelatedEntity(metaCol.getRelatedEntity());
colType.setRelationshipType(metaCol.getRelationshipType());
}
colType.setUsefulColumn(metaCol.isUsefulColumn());
listColType.add(colType);
}
}
}
Aggregations