use of org.talend.designer.core.model.utils.emf.talendfile.ColumnType in project tesb-studio-se by Talend.
the class FormContentTypeMigrationTask method updateFormContentTypeOf.
private boolean updateFormContentTypeOf(MetadataType metadataType, NodeType currentNode) {
boolean isChanged = false;
for (Object o : metadataType.getColumn()) {
if (!(o instanceof ColumnType)) {
continue;
}
ColumnType ct = (ColumnType) o;
// if it's body, then continue
if ("body".equals(ct.getName())) {
continue;
}
// if it's not form, then continue
String comment = ct.getComment();
if (!"form".equalsIgnoreCase(comment)) {
continue;
}
updateFormConsumeContentTypeFor(metadataType.getName(), currentNode);
isChanged = true;
}
return isChanged;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ColumnType 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.ColumnType 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;
}
}
use of org.talend.designer.core.model.utils.emf.talendfile.ColumnType in project tdi-studio-se by Talend.
the class MetadataEmfFactoryTest method testOriginalLengthValue.
@Test
public void testOriginalLengthValue() {
// OriginalLength of column is null.
IMetadataTable table = createTestTable();
factory.setMetadataTable(table);
MetadataType metadataType = factory.getMetadataType();
ColumnType col1 = (ColumnType) metadataType.getColumn().get(0);
assertEquals(-1, col1.getOriginalLength());
// OriginalLength of column is not null.
table = createTestTable();
table.getListColumns().get(0).setOriginalLength(10);
factory.setMetadataTable(table);
metadataType = factory.getMetadataType();
col1 = (ColumnType) metadataType.getColumn().get(0);
assertEquals(10, col1.getOriginalLength());
}
use of org.talend.designer.core.model.utils.emf.talendfile.ColumnType 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");
}
}
}
}
}
}
}
}
}
Aggregations