use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class UIManager method autoMap.
/**
*
* DOC xzhang Comment method "autoMap".
*/
public void autoMap() {
FOXTreeNode root = this.foxManager.getTreeData().get(0);
List<FOXTreeNode> mappableNodes = new ArrayList<FOXTreeNode>();
getMappableNode((Element) root, mappableNodes);
List<IMetadataColumn> schemaData = this.foxManager.getSchemaData();
for (IMetadataColumn column : schemaData) {
for (FOXTreeNode node : mappableNodes) {
if (node.getLabel().equals(column.getLabel())) {
node.setDefaultValue(null);
node.setColumn(column);
break;
}
}
}
this.foxUI.refreshXMLViewer(root);
this.foxUI.redrawLinkers();
}
use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class RowGeneratorComponent method sameMetadataFunctionsAs.
/*
* add for bug TDI-26458 by fwang at 24 June,2013, need check update for functions.
*/
private boolean sameMetadataFunctionsAs(IMetadataTable metaTable) {
List<IMetadataColumn> metaTables = metaTable.getListColumns();
for (IMetadataColumn metaColum : metaTables) {
if (!(metaColum instanceof MetadataColumnExt)) {
break;
}
MetadataColumnExt metaColumExt = (MetadataColumnExt) metaColum;
String functionValue = FunctionManagerExt.getOneColData(metaColumExt);
for (Map<String, Object> map : getMapList()) {
if (metaColumExt.getLabel().equals(map.get(COLUMN_NAME)) && !functionValue.equals(map.get(ARRAY))) {
return false;
}
}
}
return true;
}
use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class RowGeneratorComponentDocumentation method generateColumnInfo.
/**
* Administrator Comment method "generateColumnInfo".
*
* @param externalNodeElement
*/
private void generateColumnInfo(Element externalNodeElement) {
for (IMetadataTable metadataTable : this.metadataListOut) {
// rowGeneratorMain.getGeneratorUI().convert(metadataTable);
for (IMetadataColumn tempColumn : metadataTable.getListColumns()) {
MetadataColumnExt column = (MetadataColumnExt) tempColumn;
//$NON-NLS-1$
Element columnElement = externalNodeElement.addElement("column");
//$NON-NLS-1$
columnElement.addAttribute("name", HTMLDocUtils.checkString(column.getLabel()));
//$NON-NLS-1$
columnElement.addAttribute("key", String.valueOf(column.isKey()));
String type = HTMLDocUtils.checkString(column.getTalendType());
if (LanguageManager.getCurrentLanguage().equals(ECodeLanguage.JAVA)) {
type = JavaTypesManager.getTypeToGenerate(column.getTalendType(), column.isNullable());
}
//$NON-NLS-1$
columnElement.addAttribute("type", type);
//$NON-NLS-1$
columnElement.addAttribute("nullable", String.valueOf(column.isNullable()));
String length;
if ((column.getLength() == null) || (column.getLength() == 0)) {
//$NON-NLS-1$
length = "";
} else {
length = String.valueOf(column.getLength());
}
//$NON-NLS-1$
columnElement.addAttribute("length", length);
String precision;
if ((column.getPrecision() == null) || (column.getPrecision() == 0)) {
//$NON-NLS-1$
precision = "";
} else {
precision = String.valueOf(column.getPrecision());
}
//$NON-NLS-1$
columnElement.addAttribute("precision", precision);
//$NON-NLS-1$
columnElement.addAttribute("default", HTMLDocUtils.checkString(column.getDefault()));
//$NON-NLS-1$
columnElement.addAttribute("comment", HTMLDocUtils.checkString(column.getComment()));
//$NON-NLS-1$
String functionName = "";
if (column.getFunction() != null) {
functionName = column.getFunction().getName();
}
//$NON-NLS-1$
columnElement.addAttribute("functions", HTMLDocUtils.checkString(functionName));
//$NON-NLS-1$
columnElement.addAttribute("parameters", HTMLDocUtils.checkString(column.getParameter()));
// columnElement.addAttribute("preview",
// HTMLDocUtils.checkString(column.getPreview()));
}
}
}
use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class RetrieveSchemaHelper method retrieveSchemasCommand.
public static Command retrieveSchemasCommand(Node node) {
IElementParameter param = node.getElementParameter("SCHEMA");
IMetadataTable inputMeta = node.getMetadataFromConnector("FLOW");
IMetadataTable inputMetaCopy = inputMeta.clone(true);
IElementParameter outParam = node.getElementParameter("SCHEMA_OUT");
IMetadataTable outputMeta = node.getMetadataFromConnector(outParam.getContext());
IMetadataTable outputMetaCopy = outputMeta.clone(true);
File xmlFile = new File(TalendTextUtils.removeQuotes(node.getElementParameter("PATH_JOBDEF").getValue().toString()));
if (!xmlFile.exists())
try {
xmlFile.createNewFile();
} catch (IOException e1) {
ExceptionHandler.process(e1);
}
SAXReader saxReader = new SAXReader();
Document document;
AutoApi a = null;
try {
// get the schema file from server
a = new AutoApi();
String hostName = TalendTextUtils.removeQuotes(node.getElementParameter("HOSTNAME").getValue().toString());
int port = Integer.parseInt(TalendTextUtils.removeQuotes(node.getElementParameter("PORT").getValue().toString()));
String mandant = TalendTextUtils.removeQuotes(node.getElementParameter("MANDANT").getValue().toString());
String userName = TalendTextUtils.removeQuotes(node.getElementParameter("USERNAME").getValue().toString());
String passWord = TalendTextUtils.removeQuotes(node.getElementParameter("PASSWORD").getValue().toString());
String jobDir = TalendTextUtils.removeQuotes(node.getElementParameter("JOB_DIR").getValue().toString());
String jobName = TalendTextUtils.removeQuotes(node.getElementParameter("JOB_NAME").getValue().toString());
String jobDef = TalendTextUtils.removeQuotes(node.getElementParameter("PATH_JOBDEF").getValue().toString());
a.openConnection(hostName, port, mandant, userName, passWord);
a.getJobDefinitionFile(jobDir, jobName, jobDef);
document = saxReader.read(xmlFile);
List inputList = document.selectNodes("//Job//Lines//Line//Steps//Input//Sources//Source//Format//Fields//Field");
List inputMetaColumnList = new ArrayList<MetadataColumn>();
for (int i = 0; i < inputList.size(); i++) {
IMetadataColumn imc = new MetadataColumn();
DefaultElement de = (DefaultElement) inputList.get(i);
Element nameElement = de.element("Name");
imc.setLabel(nameElement.getData().toString());
Element lengthElement = de.element("Length");
if (!"".equals(lengthElement.getData().toString()) && !"0".equals(lengthElement.getData().toString())) {
imc.setLength(Integer.parseInt(lengthElement.getData().toString()));
}
Element typeElement = de.element("Type");
JavaType javaType = JavaTypesManager.getJavaTypeFromName(typeElement.getData().toString());
if (javaType != null) {
imc.setTalendType(javaType.getId());
} else {
imc.setTalendType(JavaTypesManager.STRING.getId());
}
inputMetaColumnList.add(imc);
}
inputMetaCopy.setListColumns(inputMetaColumnList);
List outputList = document.selectNodes("//Job//Lines//Line//Steps//Output//Targets//Target//Format//Fields//Field");
List outputMetaColumnList = new ArrayList<MetadataColumn>();
for (int i = 0; i < outputList.size(); i++) {
IMetadataColumn imc = new MetadataColumn();
DefaultElement de = (DefaultElement) outputList.get(i);
Element nameElement = de.element("Name");
imc.setLabel(nameElement.getData().toString());
Element lengthElement = de.element("Length");
if (!"".equals(lengthElement.getData().toString()) && !"0".equals(lengthElement.getData().toString())) {
imc.setLength(Integer.parseInt(lengthElement.getData().toString()));
}
Element typeElement = de.element("Type");
JavaType javaType = JavaTypesManager.getJavaTypeFromName(typeElement.getData().toString());
if (javaType != null) {
imc.setTalendType(javaType.getId());
} else {
imc.setTalendType(JavaTypesManager.STRING.getId());
}
outputMetaColumnList.add(imc);
}
outputMetaCopy.setListColumns(outputMetaColumnList);
// set advanced setting info
DefaultElement de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//Record//FieldSeparator");
int separator = Integer.parseInt(de.getData().toString());
node.getElementParameter("IN_FIELD_SEP").setValue(TalendTextUtils.addQuotes(new Character((char) separator).toString()));
de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//Record//HeaderRecordCount");
node.getElementParameter("IN_HEADER_COUNT").setValue(de.getData().toString());
de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//FileLocation//Directory");
node.getElementParameter("IN_DIR").setValue(TalendTextUtils.addQuotes(de.getData().toString()));
de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//FileLocation//FileName");
node.getElementParameter("IN_FILENAME").setValue(TalendTextUtils.addQuotes(de.getData().toString()));
de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//FileLocation");
node.getElementParameter("IN_MODE").setValue(de.attribute("Mode").getValue());
de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//Record//FieldSeparator");
separator = Integer.parseInt(de.getData().toString());
node.getElementParameter("OUT_FIELD_SEP").setValue(TalendTextUtils.addQuotes(new Character((char) separator).toString()));
de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//Record//HeaderRecordCount");
node.getElementParameter("OUT_HEADER_COUNT").setValue(de.getData().toString());
de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//FileLocation//Directory");
node.getElementParameter("OUT_DIR").setValue(TalendTextUtils.addQuotes(de.getData().toString()));
de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//FileLocation//FileName");
node.getElementParameter("OUT_FILENAME").setValue(TalendTextUtils.addQuotes(de.getData().toString()));
de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//FileLocation");
node.getElementParameter("OUT_MODE").setValue(de.attribute("Mode").getValue());
} catch (Exception e) {
ExceptionHandler.process(e);
} finally {
try {
a.closeConnection();
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
CompoundCommand cc = new CompoundCommand();
cc.add(new ChangeMetadataCommand(node, param, inputMeta, inputMetaCopy));
cc.add(new ChangeMetadataCommand(node, param, outputMeta, outputMetaCopy));
return cc;
}
use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class SapSchemaTypeController method copySchemaFromChildJob.
/**
* DOC hcw Comment method "copySchemaFromChildJob".
*
* @param runJobNode
* @param item
*/
private void copySchemaFromChildJob(Node runJobNode, final Item item) {
// 0004322: tRunJob can import the tBufferOutput schema from the son job
if (runJobNode != null && item instanceof ProcessItem) {
IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
IProcess process = service.getProcessFromProcessItem((ProcessItem) item);
List<? extends INode> graphicalNodes = process.getGraphicalNodes();
for (INode node : graphicalNodes) {
if ((node != null) && node.getComponent().getName().equals("tBufferOutput")) {
//$NON-NLS-1$
List<IMetadataTable> list = node.getMetadataList();
if (list.size() > 0) {
List<IMetadataTable> metadata = runJobNode.getMetadataList();
if (metadata.size() == 0) {
metadata.add(list.get(0).clone());
} else {
IMetadataTable table = metadata.get(0);
// clear schema of tRunJob, so we will replace with schema of tBufferOutput
table.getListColumns().clear();
List<IMetadataColumn> columns = list.get(0).getListColumns();
for (IMetadataColumn col : columns) {
table.getListColumns().add(col.clone());
}
}
// skip other tBufferOutput component
break;
}
}
}
}
}
Aggregations