use of org.talend.designer.core.model.utils.emf.talendfile.TalendFileFactory in project tdi-studio-se by Talend.
the class ImportProjectSettings method updateProjectSettings.
public void updateProjectSettings() throws ParserConfigurationException, SAXException, IOException {
if (this.path == null) {
return;
}
File file = new File(path);
org.talend.core.model.properties.Project project = pro.getEmfProject();
final DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
DocumentBuilder analyseur = fabrique.newDocumentBuilder();
analyseur.setErrorHandler(new ErrorHandler() {
@Override
public void error(final SAXParseException exception) throws SAXException {
throw exception;
}
@Override
public void fatalError(final SAXParseException exception) throws SAXException {
throw exception;
}
@Override
public void warning(final SAXParseException exception) throws SAXException {
throw exception;
}
});
final Document document = analyseur.parse(file);
// PTODO, if need, get the version from the imported file.
// NodeList exportParametersNodes = document.getElementsByTagName("exportParameters");
// String importStudioVersion=null;
//$NON-NLS-1$
final NodeList nodes = document.getElementsByTagName("exportParameter");
List addedComponentSetting = new ArrayList();
List technical = project.getTechnicalStatus();
List documentation = project.getDocumentationStatus();
technical.clear();
documentation.clear();
for (int i = 0; i < nodes.getLength(); i++) {
final Node node = nodes.item(i);
final NamedNodeMap attrMap = node.getAttributes();
//$NON-NLS-1$
final Node typeAttr = attrMap.getNamedItem("type");
if ("technicalStatus".equals(typeAttr.getTextContent())) {
//$NON-NLS-1$
//$NON-NLS-1$
updateStatus(node, attrMap, technical, "technicalStatus");
} else if ("documentationStatus".equals(typeAttr.getTextContent())) {
//$NON-NLS-1$
//$NON-NLS-1$
updateStatus(node, attrMap, documentation, "documentationStatus");
} else if ("security".equals(typeAttr.getTextContent())) {
//$NON-NLS-1$
project.isHidePassword();
project.setHidePassword(Boolean.valueOf(node.getTextContent()));
} else if ("statAndLogs".equals(typeAttr.getTextContent())) {
//$NON-NLS-1$
if (project.getStatAndLogsSettings() == null) {
TalendFileFactory talendF = TalendFileFactory.eINSTANCE;
StatAndLogsSettings stats = PropertiesFactory.eINSTANCE.createStatAndLogsSettings();
project.setStatAndLogsSettings(stats);
stats.setParameters(talendF.createParametersType());
}
List statAndLogs = project.getStatAndLogsSettings().getParameters().getElementParameter();
updateParameters(node, attrMap, statAndLogs);
} else if ("implicitContext".equals(typeAttr.getTextContent())) {
//$NON-NLS-1$
if (project.getImplicitContextSettings() == null) {
TalendFileFactory talendF = TalendFileFactory.eINSTANCE;
ImplicitContextSettings implicit = PropertiesFactory.eINSTANCE.createImplicitContextSettings();
project.setImplicitContextSettings(implicit);
implicit.setParameters(talendF.createParametersType());
}
List implicitContexts = project.getImplicitContextSettings().getParameters().getElementParameter();
updateParameters(node, attrMap, implicitContexts);
} else if ("palette".equals(typeAttr.getTextContent())) {
//$NON-NLS-1$
List componentSettings = project.getComponentsSettings();
boolean existed = false;
//$NON-NLS-1$
String name = attrMap.getNamedItem("name").getTextContent();
//$NON-NLS-1$
final Node familyAttr = attrMap.getNamedItem("family");
Boolean hide = Boolean.valueOf(node.getTextContent());
for (Object obj : componentSettings) {
ComponentSetting setting = (ComponentSetting) obj;
if (setting.getName().equals(name)) {
if (familyAttr != null && familyAttr.getTextContent().equals(setting.getFamily())) {
existed = true;
setting.setHidden(hide);
}
}
}
if (!existed && familyAttr != null) {
ComponentSetting setting = PropertiesFactory.eINSTANCE.createComponentSetting();
setting.setFamily(familyAttr.getTextContent());
setting.setName(name);
setting.setHidden(hide);
addedComponentSetting.add(setting);
}
}
}
project.getComponentsSettings().addAll(addedComponentSetting);
}
use of org.talend.designer.core.model.utils.emf.talendfile.TalendFileFactory 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.TalendFileFactory 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;
}
}
Aggregations