use of org.talend.repository.model.json.JSONFileNode in project tdi-studio-se by Talend.
the class JSONFileOutputStep3Form method createMetadataColumn.
private List<MetadataColumn> createMetadataColumn(EList list) {
List<MetadataColumn> columnList = new ArrayList<MetadataColumn>();
if (list.size() == 0) {
return columnList;
}
for (int i = 0; i < list.size(); i++) {
JSONFileNode node = (JSONFileNode) list.get(i);
String label = node.getRelatedColumn();
if (label != null && !label.equals("")) {
MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
metadataColumn.setLabel(label);
metadataColumn.setOriginalField(label);
String type = node.getType();
if (type != null) {
metadataColumn.setTalendType(type);
}
columnList.add(metadataColumn);
}
}
return columnList;
}
use of org.talend.repository.model.json.JSONFileNode in project tdi-studio-se by Talend.
the class AbstractJSONFileStepForm method getDefaultRootNode.
protected ATreeNode getDefaultRootNode(List<ATreeNode> rootNodes) {
if (rootNodes != null && rootNodes.size() > 0) {
EList<JSONFileNode> root = getConnection().getRoot();
JSONFileNode selectedNode = null;
if (root != null && root.size() > 0) {
selectedNode = root.get(0);
} else {
EList<JSONFileNode> loop = getConnection().getLoop();
if (loop != null && loop.size() > 0) {
selectedNode = loop.get(0);
}
}
if (selectedNode != null) {
String JSONPath = selectedNode.getJSONPath();
if (JSONPath != null && JSONPath.length() > 0) {
JSONPath = JSONPath.substring(JSONPath.lastIndexOf("/") + 1);
for (int i = 0; i < rootNodes.size(); i++) {
ATreeNode node = rootNodes.get(i);
if (JSONPath.equals(node.getValue())) {
return node;
}
}
}
}
}
return null;
}
use of org.talend.repository.model.json.JSONFileNode in project tdi-studio-se by Talend.
the class AbstractJSONFileStepForm method tableLoader.
protected void tableLoader(Element element, String parentPath, List<JSONFileNode> table, String defaultValue) {
JSONFileNode JSONFileNode = JsonFactory.eINSTANCE.createJSONFileNode();
String currentPath = parentPath + "/" + element.getLabel();
JSONFileNode.setJSONPath(currentPath);
JSONFileNode.setRelatedColumn(element.getColumnLabel());
JSONFileNode.setAttribute(element.isMain() ? "main" : "branch");
JSONFileNode.setDefaultValue(defaultValue);
JSONFileNode.setType(element.getDataType());
JSONFileNode.setOrder(getNodeOrder(element));
table.add(JSONFileNode);
for (FOXTreeNode att : element.getAttributeChildren()) {
JSONFileNode = JsonFactory.eINSTANCE.createJSONFileNode();
JSONFileNode.setJSONPath(att.getLabel());
JSONFileNode.setRelatedColumn(att.getColumnLabel());
JSONFileNode.setAttribute("attri");
JSONFileNode.setDefaultValue(att.getDefaultValue());
JSONFileNode.setType(att.getDataType());
JSONFileNode.setOrder(getNodeOrder(att));
table.add(JSONFileNode);
}
for (FOXTreeNode att : element.getNameSpaceChildren()) {
JSONFileNode = JsonFactory.eINSTANCE.createJSONFileNode();
JSONFileNode.setJSONPath(att.getLabel());
JSONFileNode.setRelatedColumn(att.getColumnLabel());
JSONFileNode.setAttribute("ns");
JSONFileNode.setDefaultValue(att.getDefaultValue());
JSONFileNode.setType(att.getDataType());
JSONFileNode.setOrder(getNodeOrder(att));
table.add(JSONFileNode);
}
List<FOXTreeNode> children = element.getElementChildren();
for (FOXTreeNode child : children) {
if (!child.isGroup() && !child.isLoop()) {
tableLoader((Element) child, currentPath, table, child.getDefaultValue());
}
}
}
use of org.talend.repository.model.json.JSONFileNode in project tdi-studio-se by Talend.
the class JSONDragAndDropHandler method getOutputJSONValue.
private List<Map<String, String>> getOutputJSONValue(EList list) {
List<Map<String, String>> newList = new ArrayList<Map<String, String>>();
for (int i = 0; i < list.size(); i++) {
Map<String, String> map = new HashMap<String, String>();
JSONFileNode node = (JSONFileNode) list.get(i);
String defaultValue = node.getDefaultValue();
if (defaultValue == null) {
//$NON-NLS-1$
defaultValue = "";
}
map.put("VALUE", defaultValue);
map.put("ORDER", String.valueOf(node.getOrder()));
map.put("PATH", node.getJSONPath());
map.put("ATTRIBUTE", node.getAttribute());
map.put("COLUMN", node.getRelatedColumn());
newList.add(map);
}
return newList;
}
use of org.talend.repository.model.json.JSONFileNode in project tdi-studio-se by Talend.
the class JSONFileOutputStep2Form method initJSONTreeData.
private void initJSONTreeData() {
treeData.clear();
// metadataColumnList.clear();
EList root = getConnection().getRoot();
EList loop = getConnection().getLoop();
EList group = getConnection().getGroup();
// initialMetadataColumn();
FOXTreeNode rootNode = null;
FOXTreeNode current = null;
FOXTreeNode temp = null;
FOXTreeNode mainNode = null;
String mainPath = null;
String currentPath = null;
String defaultValue = null;
int nodeOrder = 0;
boolean haveOrder = true;
// build root tree
for (int i = 0; i < root.size(); i++) {
JSONFileNode node = (JSONFileNode) root.get(i);
String newPath = node.getJSONPath();
defaultValue = node.getDefaultValue();
String type = node.getType();
String orderValue = String.valueOf(node.getOrder());
if (orderValue == null || "".equals(orderValue)) {
haveOrder = false;
}
if (haveOrder) {
nodeOrder = node.getOrder();
}
if (node.getAttribute().equals("attri")) {
temp = new Attribute(newPath);
temp.setDefaultValue(defaultValue);
temp.setAttribute(true);
temp.setDataType(type);
current.addChild(temp);
} else if (node.getAttribute().equals("ns")) {
temp = new NameSpaceNode(newPath);
temp.setDefaultValue(defaultValue);
temp.setNameSpace(true);
temp.setDataType(type);
current.addChild(temp);
} else {
temp = this.addElement(current, currentPath, newPath, defaultValue);
temp.setDataType(type);
if (rootNode == null) {
rootNode = temp;
}
if (node.getAttribute().equals("main")) {
temp.setMain(true);
mainNode = temp;
mainPath = newPath;
}
current = temp;
currentPath = newPath;
}
if (haveOrder) {
temp.setOrder(nodeOrder);
}
String columnName = node.getRelatedColumn();
if (columnName != null && columnName.length() > 0) {
temp.setColumn(getColumn(columnName));
}
}
// build group tree
current = mainNode;
currentPath = mainPath;
boolean isFirst = true;
for (int i = 0; i < group.size(); i++) {
JSONFileNode node = (JSONFileNode) group.get(i);
String newPath = node.getJSONPath();
defaultValue = node.getDefaultValue();
String type = node.getType();
String orderValue = String.valueOf(node.getOrder());
if (orderValue == null || "".equals(orderValue)) {
haveOrder = false;
}
if (haveOrder) {
nodeOrder = node.getOrder();
}
if (node.getAttribute().equals("attri")) {
temp = new Attribute(newPath);
temp.setDefaultValue(defaultValue);
temp.setAttribute(true);
temp.setDataType(type);
current.addChild(temp);
} else if (node.getAttribute().equals("ns")) {
temp = new NameSpaceNode(newPath);
temp.setDefaultValue(defaultValue);
temp.setNameSpace(true);
temp.setDataType(type);
current.addChild(temp);
} else {
temp = this.addElement(current, currentPath, newPath, defaultValue);
temp.setDataType(type);
if (node.getAttribute().equals("main")) {
temp.setMain(true);
mainNode = temp;
mainPath = newPath;
}
if (isFirst) {
temp.setGroup(true);
isFirst = false;
}
current = temp;
currentPath = newPath;
}
if (haveOrder) {
temp.setOrder(nodeOrder);
}
String columnName = node.getRelatedColumn();
if (columnName != null && columnName.length() > 0) {
temp.setColumn(getColumn(columnName));
}
}
// build loop tree
current = mainNode;
currentPath = mainPath;
isFirst = true;
for (int i = 0; i < loop.size(); i++) {
JSONFileNode node = (JSONFileNode) loop.get(i);
String newPath = node.getJSONPath();
defaultValue = node.getDefaultValue();
String type = node.getType();
String orderValue = String.valueOf(node.getOrder());
if (orderValue == null || "".equals(orderValue)) {
haveOrder = false;
}
if (haveOrder) {
nodeOrder = node.getOrder();
}
if (node.getAttribute().equals("attri")) {
temp = new Attribute(newPath);
temp.setDefaultValue(defaultValue);
temp.setAttribute(true);
temp.setDataType(type);
temp.setDataType(type);
current.addChild(temp);
} else if (node.getAttribute().equals("ns")) {
temp = new NameSpaceNode(newPath);
temp.setDefaultValue(defaultValue);
temp.setNameSpace(true);
temp.setDataType(type);
current.addChild(temp);
} else {
temp = this.addElement(current, currentPath, newPath, defaultValue);
temp.setDataType(type);
// fix for TDI-18802 , if root node is loop
if (rootNode == null) {
rootNode = temp;
}
if (node.getAttribute().equals("main")) {
temp.setMain(true);
mainNode = temp;
mainPath = newPath;
}
if (isFirst) {
temp.setLoop(true);
isFirst = false;
}
current = temp;
currentPath = newPath;
}
if (haveOrder) {
temp.setOrder(nodeOrder);
}
String columnName = node.getRelatedColumn();
if (columnName != null && columnName.length() > 0) {
temp.setColumn(getColumn(columnName));
}
}
if (rootNode == null) {
rootNode = new Element("rootTag");
}
rootNode.setParent(null);
if (haveOrder) {
orderNode(rootNode);
}
treeData.add(rootNode);
}
Aggregations