use of org.talend.core.model.metadata.types.JavaType 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.types.JavaType in project tdi-studio-se by Talend.
the class JavaXMLConfigWizardPage method loadAttrsInfo.
/*
* (non-Javadoc)
*
* @see org.talend.componentdesigner.ui.wizard.creatcomponent.AbstractXMLConfigPage#loadAttrsInfo()
*/
@Override
protected void loadAttrsInfo() {
super.loadAttrsInfo();
// available TYPE values are different between LANGUAGES
String[] valuesArray = null;
List<String> javaTypesArray = new ArrayList<String>();
for (JavaType javaType : JavaTypesManager.getJavaTypes()) {
javaTypesArray.add(javaType.getId());
}
valuesArray = javaTypesArray.toArray(new String[0]);
//$NON-NLS-1$
attrsAvailableValuesMap.put("TYPE", valuesArray);
}
use of org.talend.core.model.metadata.types.JavaType in project tdi-studio-se by Talend.
the class GenericContextUtil method createContextParameters.
public static List<IContextParameter> createContextParameters(String prefixName, Connection connection, Set<IConnParamName> paramSet) {
List<IContextParameter> varList = new ArrayList<>();
if (connection instanceof GenericConnection) {
GenericConnection conn = (GenericConnection) connection;
if (conn == null || prefixName == null || paramSet == null || paramSet.isEmpty()) {
return Collections.emptyList();
}
String paramPrefix = prefixName + ConnectionContextHelper.LINE;
String paramName = null;
for (IConnParamName param : paramSet) {
if (param instanceof GenericConnParamName) {
GenericConnParamName connParamName = (GenericConnParamName) param;
String name = connParamName.getName();
ComponentProperties componentProperties = getComponentProperties((GenericConnection) connection);
Property<?> property = componentProperties.getValuedProperty(name);
paramName = paramPrefix + connParamName.getContextVar();
JavaType type = JavaTypesManager.STRING;
if (property.isFlag(Property.Flags.ENCRYPT)) {
type = JavaTypesManager.PASSWORD;
}
if (GenericTypeUtils.isIntegerType(property)) {
type = JavaTypesManager.INTEGER;
}
String value = property == null || property.getValue() == null ? null : StringEscapeUtils.escapeJava(String.valueOf(property.getValue()));
ConnectionContextHelper.createParameters(varList, paramName, value, type);
}
}
}
return varList;
}
use of org.talend.core.model.metadata.types.JavaType in project tdi-studio-se by Talend.
the class VirtualRowGeneratorNode method getArray.
/**
* yzhang Comment method "initArray".
*/
private Object getArray() {
List<Map<String, String>> map = new ArrayList<Map<String, String>>();
MetadataTable table = (MetadataTable) this.getMetadataList().get(0);
for (IMetadataColumn col : table.getListColumns()) {
VirtualMetadataColumn ext = (VirtualMetadataColumn) col;
Map<String, String> value = new HashMap<String, String>();
value.put(RowGeneratorComponent.COLUMN_NAME, ext.getLabel());
List<Variable> variables = ExpressionBuilderDialog.getTestComposite().getVariableList();
String expression = ExpressionBuilderDialog.getExpressionComposite().getExpression();
// modify for bug 9471
try {
for (Variable varible : variables) {
if (valueContains(expression, varible.getName())) {
Integer.parseInt(varible.getValue());
}
}
for (Variable var : variables) {
String talendType = var.getTalendType();
JavaType javaTypeFromId = JavaTypesManager.getJavaTypeFromId(talendType);
String label = null;
String value2 = var.getValue();
if (javaTypeFromId != null) {
label = javaTypeFromId.getLabel();
if ("BigDecimal".equals(label)) {
//$NON-NLS-1$
//$NON-NLS-1$//$NON-NLS-1$
value2 = " new BigDecimal(" + value2 + ")";
}
}
expression = renameValues(expression, var.getName(), value2);
}
} catch (NumberFormatException e1) {
for (Variable var : variables) {
//$NON-NLS-1$ //$NON-NLS-2$
expression = renameValues(expression, var.getName(), "\"" + var.getValue() + "\"");
}
}
//$NON-NLS-1$//$NON-NLS-1$
value.put(RowGeneratorComponent.ARRAY, "\"\"+(" + expression + ")+\"\"");
map.add(value);
}
return map;
}
use of org.talend.core.model.metadata.types.JavaType in project tdi-studio-se by Talend.
the class DirectEditCommand method execute.
@Override
public void execute() {
try {
if (model != null) {
if (DirectEditType.EXPRESSION.equals(type)) {
List<TableEntryLocation> matchedLocations = expressionManager.parseTableEntryLocation((String) newValue);
EList<? extends INodeConnection> connections = null;
if (model instanceof OutputTreeNode || model instanceof VarNode) {
connections = model.getIncomingConnections();
} else if (model instanceof TreeNode) {
connections = ((TreeNode) model).getLookupIncomingConnections();
}
List usefullConnections = new ArrayList();
mapperData = XmlMapUtil.getXmlMapData(model);
if (!matchedLocations.isEmpty()) {
for (int i = 0; i < matchedLocations.size(); i++) {
TableEntryLocation currentLocation = matchedLocations.get(i);
boolean found = false;
for (INodeConnection conn : connections) {
TableEntryLocation sourceLocation = null;
if (conn.getSource() instanceof TreeNode) {
sourceLocation = expressionManager.parseTableEntryLocation(XmlMapUtil.convertToExpression(((TreeNode) conn.getSource()).getXpath())).get(0);
} else if (conn.getSource() instanceof VarNode) {
VarNode varNode = (VarNode) conn.getSource();
sourceLocation = new TableEntryLocation(((VarTable) varNode.eContainer()).getName(), varNode.getName());
}
if (currentLocation.equals(sourceLocation)) {
found = true;
usefullConnections.add(conn);
break;
}
}
if (!found) {
if (mapperData != null) {
String convertToXpath = XmlMapUtil.convertToXpath(currentLocation.toString());
boolean findFromVar = false;
if (model instanceof OutputTreeNode) {
findFromVar = true;
}
AbstractNode sourceNode = findConnectionSource(mapperData, currentLocation, XmlMapUtil.getXPathLength(convertToXpath), findFromVar);
if (sourceNode != null) {
INodeConnection connection = null;
if (model instanceof OutputTreeNode || model instanceof VarNode) {
connection = XmlmapFactory.eINSTANCE.createConnection();
sourceNode.getOutgoingConnections().add((Connection) connection);
model.getIncomingConnections().add((Connection) connection);
} else if (model instanceof TreeNode && sourceNode instanceof TreeNode) {
TreeNode source = (TreeNode) sourceNode;
connection = XmlmapFactory.eINSTANCE.createLookupConnection();
source.getLookupOutgoingConnections().add((LookupConnection) connection);
((TreeNode) model).getLookupIncomingConnections().add((LookupConnection) connection);
}
//
// if (model instanceof OutputTreeNode && sourceNode instanceof TreeNode) {
// createInputLoopTable((TreeNode) sourceNode, (OutputTreeNode) model);
// }
connection.setSource(sourceNode);
connection.setTarget(model);
mapperData.getConnections().add(connection);
usefullConnections.add(connection);
}
}
}
}
} else {
if (!connections.isEmpty()) {
if (model instanceof OutputTreeNode || model instanceof VarNode) {
XmlMapUtil.detachConnectionsSouce(model, mapperData, false);
model.getIncomingConnections().clear();
} else if (model instanceof TreeNode) {
XmlMapUtil.detachLookupSource((TreeNode) model, mapperData);
((TreeNode) model).getLookupIncomingConnections().clear();
}
}
}
List<INodeConnection> copyOfConnections = new ArrayList<INodeConnection>(connections);
copyOfConnections.removeAll(usefullConnections);
if (model instanceof OutputTreeNode || model instanceof VarNode) {
for (INodeConnection connection : copyOfConnections) {
if (connection.getSource() != null) {
if (connection.getSource().getOutgoingConnections().contains(connection)) {
connection.getSource().getOutgoingConnections().remove(connection);
mapperData.getConnections().remove(connection);
}
}
}
model.getIncomingConnections().removeAll(copyOfConnections);
} else if (model instanceof TreeNode) {
for (INodeConnection connection : copyOfConnections) {
if (connection.getSource() != null) {
if (((TreeNode) connection.getSource()).getLookupOutgoingConnections().contains(connection)) {
((TreeNode) connection.getSource()).getLookupOutgoingConnections().remove(connection);
mapperData.getConnections().remove(connection);
}
}
}
((TreeNode) model).getLookupIncomingConnections().removeAll(copyOfConnections);
}
if (model instanceof OutputTreeNode) {
OutputTreeNode outModel = (OutputTreeNode) model;
if (NodeType.NAME_SPACE.equals(outModel.getNodeType()) && outModel.getExpression() != null && !"".equals(model.getExpression())) {
outModel.setDefaultValue("");
}
}
model.setExpression((String) newValue);
} else if (DirectEditType.VAR_NODE_TYPE.equals(type)) {
VarNode varModel = (VarNode) model;
JavaType javaTypeFromLabel = JavaTypesManager.getJavaTypeFromLabel((String) newValue);
if (javaTypeFromLabel == null) {
javaTypeFromLabel = JavaTypesManager.getDefaultJavaType();
}
varModel.setType(javaTypeFromLabel.getId());
} else if (DirectEditType.NODE_NAME.equals(type)) {
if (model instanceof VarNode) {
List<VarNode> children = new ArrayList<VarNode>();
children.addAll(((VarTable) model.eContainer()).getNodes());
children.remove(model);
String message = XmlMapUtil.isValidColumnName(children, (String) newValue);
if (message != null) {
MessageDialog.openError(null, "Error", message);
return;
}
String oldName = model.getName();
String oldExpression = XmlMapUtil.VAR_TABLE_NAME + XmlMapUtil.EXPRESSION_SEPARATOR + oldName;
model.setName((String) newValue);
String newExpression = XmlMapUtil.VAR_TABLE_NAME + XmlMapUtil.EXPRESSION_SEPARATOR + model.getName();
XmlMapUtil.updateTargetExpression(model, oldExpression, newExpression, expressionManager);
} else if (model instanceof GlobalMapNode) {
model.setName((String) newValue);
}
}
}
} catch (PatternSyntaxException ex) {
// Syntax error in the regular expression
}
}
Aggregations