use of org.talend.designer.core.model.utils.emf.talendfile.NodeType in project tdi-studio-se by Talend.
the class UpdateDbtypeOfCreateTableTask method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractJobMigrationTask#executeOnProcess(org.talend.core.model.properties.ProcessItem)
*/
@Override
public ExecutionResult execute(Item item) {
ProcessType processType = getProcessType(item);
if (getProject().getLanguage().equals(ECodeLanguage.JAVA) && processType != null) {
final Map<String, String> dbtypes = new HashMap<String, String>();
//$NON-NLS-1$ //$NON-NLS-2$
dbtypes.put("Access", "ACCESS");
//$NON-NLS-1$ //$NON-NLS-2$
dbtypes.put("AS400", "AS400");
//$NON-NLS-1$ //$NON-NLS-2$
dbtypes.put("DB2", "DB2");
//$NON-NLS-1$ //$NON-NLS-2$
dbtypes.put("FireBird", "FIREBIRD");
//$NON-NLS-1$ //$NON-NLS-2$
dbtypes.put("Hsql", "HSQLDB");
//$NON-NLS-1$ //$NON-NLS-2$
dbtypes.put("Informix", "INFORMIX");
//$NON-NLS-1$ //$NON-NLS-2$
dbtypes.put("Ingres", "INGRES");
//$NON-NLS-1$ //$NON-NLS-2$
dbtypes.put("Interbase", "INTERBASE");
//$NON-NLS-1$ //$NON-NLS-2$
dbtypes.put("JavaDb", "JAVADB");
//$NON-NLS-1$ //$NON-NLS-2$
dbtypes.put("MSSQLServer", "MSSQL");
//$NON-NLS-1$ //$NON-NLS-2$
dbtypes.put("Oracle", "DBORACLE");
//$NON-NLS-1$ //$NON-NLS-2$
dbtypes.put("Postgre", "POSTGRE");
//$NON-NLS-1$ //$NON-NLS-2$
dbtypes.put("SQLite", "SQLITE");
//$NON-NLS-1$ //$NON-NLS-2$
dbtypes.put("Sybase", "SYBASE");
//$NON-NLS-1$ //$NON-NLS-2$
dbtypes.put("ODBC", "ODBC");
//$NON-NLS-1$
final String name = "tCreateTable";
//$NON-NLS-1$
final String property = "DBTYPE";
IComponentFilter filert = new IComponentFilter() {
public boolean accept(NodeType node) {
boolean toReturn = (name == null ? true : acceptS(node));
if (toReturn) {
String pValue = ComponentUtilities.getNodePropertyValue(node, property);
toReturn = !dbtypes.values().contains(pValue);
}
return toReturn;
}
public boolean acceptS(NodeType node) {
return node.getComponentName().equals(name);
}
};
IComponentConversion conversion = new IComponentConversion() {
public void transform(NodeType node) {
String pValue = ComponentUtilities.getNodePropertyValue(node, property);
String value = dbtypes.get(pValue);
if (value != null) {
ComponentUtilities.setNodeValue(node, property, value);
} else {
//$NON-NLS-1$
ComponentUtilities.setNodeValue(node, property, "MYSQL");
}
}
};
List<IComponentConversion> cons = new ArrayList<IComponentConversion>();
cons.add(conversion);
try {
ModifyComponentsAction.searchAndModify(item, processType, filert, cons);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
} else {
// do nothing
return ExecutionResult.NOTHING_TO_DO;
}
}
use of org.talend.designer.core.model.utils.emf.talendfile.NodeType in project tdi-studio-se by Talend.
the class UnifyParameterOfDatastaxAndHectorForCassandra method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
final ProcessType processType = getProcessType(item);
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
String[] compNames = { "tCassandraInput", "tCassandraOutput", "tCassandraRow", "tCassandraLookupInput" };
IComponentConversion conversion = new IComponentConversion() {
@Override
public void transform(NodeType node) {
if (node == null) {
return;
}
//$NON-NLS-1$
ElementParameterType cf = ComponentUtilities.getNodeProperty(node, "TABLE");
if (cf != null) {
if (ComponentUtilities.getNodeProperty(node, "COLUMN_FAMILY") == null) {
//$NON-NLS-1$
//$NON-NLS-1$ //$NON-NLS-2$
ComponentUtilities.addNodeProperty(node, "COLUMN_FAMILY", "TEXT");
}
//$NON-NLS-1$
ComponentUtilities.getNodeProperty(node, "COLUMN_FAMILY").setValue(cf.getValue());
}
//$NON-NLS-1$
ElementParameterType actionForCF = ComponentUtilities.getNodeProperty(node, "TABLE_ACTION");
if (actionForCF != null) {
if (ComponentUtilities.getNodeProperty(node, "ACTION_ON_COLUMN_FAMILY") == null) {
//$NON-NLS-1$
//$NON-NLS-1$ //$NON-NLS-2$
ComponentUtilities.addNodeProperty(node, "ACTION_ON_COLUMN_FAMILY", "TEXT");
}
//$NON-NLS-1$
ComponentUtilities.getNodeProperty(node, "ACTION_ON_COLUMN_FAMILY").setValue(actionForCF.getValue());
}
}
};
for (String name : compNames) {
IComponentFilter filter = new NameComponentFilter(name);
try {
ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(conversion));
} catch (PersistenceException e) {
// TODO Auto-generated catch block
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
return ExecutionResult.SUCCESS_NO_ALERT;
}
use of org.talend.designer.core.model.utils.emf.talendfile.NodeType in project tdi-studio-se by Talend.
the class UpdateCheckResult method getCategory.
@Override
@SuppressWarnings("unchecked")
public String getCategory() {
String category = null;
if (getUpdateType() instanceof EUpdateItemType) {
switch((EUpdateItemType) getUpdateType()) {
case NODE_PROPERTY:
case NODE_SCHEMA:
case NODE_QUERY:
case NODE_VALIDATION_RULE:
case JOBLET_SCHEMA:
if (getUpdateObject() != null) {
if (getUpdateObject() instanceof Node) {
Node node = (Node) getUpdateObject();
if (node.getUniqueName().equals(node.getLabel())) {
category = node.getUniqueName();
} else {
category = node.getLabel() + UpdateManagerUtils.addBrackets(node.getUniqueName());
}
}
if (getUpdateObject() instanceof NodeType) {
NodeType node = (NodeType) getUpdateObject();
String uniqueName = null;
for (ElementParameterType param : (List<ElementParameterType>) node.getElementParameter()) {
if (EParameterName.UNIQUE_NAME.getName().equals(param.getName())) {
uniqueName = param.getValue();
break;
}
}
if (uniqueName != null) {
category = uniqueName;
}
}
}
break;
case JOB_PROPERTY_EXTRA:
case JOB_PROPERTY_STATS_LOGS:
case JOB_PROPERTY_HEADERFOOTER:
case JOB_PROPERTY_MAPREDUCE:
boolean isJoblet = false;
boolean isMR = false;
if (getUpdateObject() != null) {
if (getUpdateObject() instanceof org.talend.designer.core.ui.editor.process.Process) {
if (AbstractProcessProvider.isExtensionProcessForJoblet((IProcess) getUpdateObject())) {
isJoblet = true;
} else if (GlobalServiceRegister.getDefault().isServiceRegistered(IMRProcessService.class)) {
IMRProcessService mrProcessService = (IMRProcessService) GlobalServiceRegister.getDefault().getService(IMRProcessService.class);
org.talend.core.model.properties.Item item = ((org.talend.designer.core.ui.editor.process.Process) getUpdateObject()).getProperty().getItem();
isMR = mrProcessService.isMapReduceItem(item);
}
}
}
if (isMR) {
//
category = JobSettingsView.VIEW_NAME_BATCH;
} else if (isJoblet) {
// joblet
category = JobSettingsView.VIEW_NAME_JOBLET;
} else {
category = JobSettingsView.getViewNameLable();
}
break;
case JOB_PROPERTY_STORM:
boolean isStreaming = false;
if (getUpdateObject() != null && getUpdateObject() instanceof org.talend.designer.core.ui.editor.process.Process) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(IStormProcessService.class)) {
IStormProcessService streamingService = (IStormProcessService) GlobalServiceRegister.getDefault().getService(IStormProcessService.class);
org.talend.core.model.properties.Item item = ((org.talend.designer.core.ui.editor.process.Process) getUpdateObject()).getProperty().getItem();
isStreaming = streamingService.isStormItem(item);
}
}
if (isStreaming) {
//
category = JobSettingsView.VIEW_NAME_STREAMING;
} else {
category = JobSettingsView.getViewNameLable();
}
break;
case CONTEXT:
// case JOBLET_CONTEXT:
category = UpdatesConstants.CONTEXT;
break;
case CONTEXT_GROUP:
category = UpdatesConstants.CONTEXT_GROUP;
break;
case JOBLET_RENAMED:
case RELOAD:
case JUNIT_RELOAD:
if (getUpdateObject() != null && getUpdateObject() instanceof List) {
String display = UpdateManagerHelper.getCollectionsDisplay(getUpdateObject(), true);
if (display != null) {
category = display;
}
} else if (getParameter() != null && getParameter() instanceof PropertyChangeEvent) {
PropertyChangeEvent event = (PropertyChangeEvent) getParameter();
// reload all compoennts.
if (event.getSource() != null && !(event.getSource() instanceof IProcess)) {
category = UpdatesConstants.COMPONENT;
break;
}
} else {
category = UpdatesConstants.JOBLET;
}
break;
default:
}
} else {
category = UpdateManagerProviderDetector.INSTANCE.getDisplayCategory(this);
}
return category == null ? UpdatesConstants.EMPTY : category;
}
use of org.talend.designer.core.model.utils.emf.talendfile.NodeType in project tdi-studio-se by Talend.
the class UpdateContentProvider method getElements.
@Override
@SuppressWarnings("unchecked")
public Object[] getElements(Object inputElement) {
List<Job> jobs = new ArrayList<Job>();
if (inputElement instanceof Collection) {
for (UpdateResult result : (List<UpdateResult>) inputElement) {
String jobName = result.getJobInfor();
if (jobName == null) {
jobName = UpdatesConstants.EMPTY;
}
Job job = getJob(jobs, jobName);
if (job == null) {
job = new Job(jobName);
Object job2 = result.getJob();
if (job2 != null) {
if (job2 instanceof IProcess2) {
// ?? joblet
job.setJoblet(((IProcess2) job2).disableRunJobView());
job.setReadOnlyProcess(result.isReadOnlyProcess());
IProcess2 process = (IProcess2) job2;
org.talend.core.model.properties.Item processItem = process.getProperty().getItem();
job.setModelItem(processItem);
boolean isMRProcess = false;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IMRProcessService.class)) {
IMRProcessService mrProcessService = (IMRProcessService) GlobalServiceRegister.getDefault().getService(IMRProcessService.class);
isMRProcess = mrProcessService.isMapReduceItem(processItem);
}
boolean isStreamingProcess = false;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IStormProcessService.class)) {
IStormProcessService streamingService = (IStormProcessService) GlobalServiceRegister.getDefault().getService(IStormProcessService.class);
isStreamingProcess = streamingService.isStormItem(processItem);
}
if (isMRProcess) {
job.setMR(isMRProcess);
} else if (isStreamingProcess) {
job.setStreaming(isStreamingProcess);
} else if (processItem instanceof ProcessItem) {
job.setJoblet(false);
job.setMR(false);
job.setStreaming(false);
job.setSparkJoblet(false);
job.setSparkStreamingJoblet(false);
} else if (processItem instanceof JobletProcessItem) {
boolean isSpark = false;
boolean isSparkStreaming = false;
if (GlobalServiceRegister.getDefault().isServiceRegistered(ISparkJobletProviderService.class)) {
ISparkJobletProviderService sparkJobletService = (ISparkJobletProviderService) GlobalServiceRegister.getDefault().getService(ISparkJobletProviderService.class);
if (sparkJobletService != null && sparkJobletService.isSparkJobletItem(processItem)) {
isSpark = true;
}
}
if (GlobalServiceRegister.getDefault().isServiceRegistered(ISparkStreamingJobletProviderService.class)) {
ISparkStreamingJobletProviderService sparkStreamingJobletService = (ISparkStreamingJobletProviderService) GlobalServiceRegister.getDefault().getService(ISparkStreamingJobletProviderService.class);
if (sparkStreamingJobletService != null && sparkStreamingJobletService.isSparkStreamingJobletItem(processItem)) {
isSparkStreaming = true;
}
}
if (isSpark) {
job.setSparkJoblet(true);
job.setJoblet(false);
} else if (isSparkStreaming) {
job.setSparkStreamingJoblet(true);
job.setJoblet(false);
} else {
job.setJoblet(true);
}
}
}
} else {
String itemId = result.getObjectId();
if (itemId != null) {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
try {
IRepositoryViewObject repoViewObject = factory.getLastVersion(itemId);
if (repoViewObject != null) {
Property property = repoViewObject.getProperty();
if (property != null) {
job.setModelItem(property.getItem());
}
}
} catch (PersistenceException e) {
CommonExceptionHandler.process(e, Priority.WARN);
}
}
job.setJoblet(result.isJoblet());
job.setMR(result.isMR());
job.setStreaming(result.isStreaming());
job.setSparkJoblet(result.isSparkJoblet());
job.setSparkStreamingJoblet(result.isSparkStreamingJoblet());
}
jobs.add(job);
}
Category category = job.getCategory(result.getCategory());
if (category == null) {
category = new Category(job, result.getCategory());
// for icon
category.setType(result.getUpdateType());
if (result.getUpdateObject() instanceof Node) {
// for node icon
category.setNode(result.getUpdateObject());
}
if (result.getUpdateObject() instanceof NodeType) {
// for node icon
category.setNode(result.getUpdateObject());
}
if (result.getUpdateObject() instanceof List) {
// for node icon
List list = (List) result.getUpdateObject();
if (list.size() > 0) {
Object object = list.get(0);
if (object instanceof Node) {
category.setNode(object);
}
}
}
job.addCategory(category);
}
Item item = new Item(category, result);
category.addItem(item);
}
}
return jobs.toArray();
}
use of org.talend.designer.core.model.utils.emf.talendfile.NodeType in project tdi-studio-se by Talend.
the class TXMLMapChangeAllInOneValueMigrationTask method execute.
/*
* (non-Javadoc)
*
* @see
* org.talend.core.model.migration.TXMLMapChangeAllInOneValueMigrationTask
* (org .talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
IProxyRepositoryFactory factory = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
ProcessType processType = getProcessType(item);
boolean modified = false;
if (processType != null) {
for (Object obj : processType.getNode()) {
NodeType nodeType = (NodeType) obj;
if (nodeType.getComponentName().startsWith("tXMLMap")) {
XmlMapData xmlMapdata = (XmlMapData) nodeType.getNodeData();
EList<OutputXmlTree> outputTables = xmlMapdata.getOutputTrees();
EList<InputXmlTree> inputTables = xmlMapdata.getInputTrees();
boolean hasDocumentInTheMainInputTable = false;
for (InputXmlTree inputTable : inputTables) {
if (!(inputTable.isLookup())) {
for (TreeNode inputEntry : inputTable.getNodes()) {
if ("id_Document".equals(inputEntry.getType())) {
hasDocumentInTheMainInputTable = true;
}
}
}
}
if (hasDocumentInTheMainInputTable) {
for (OutputXmlTree outputTable : outputTables) {
for (TreeNode outputEntry : outputTable.getNodes()) {
if ("id_Document".equals(outputEntry.getType())) {
if (!outputTable.isAllInOne()) {
outputTable.setAllInOne(true);
modified = true;
break;
}
}
}
}
}
}
}
}
try {
if (modified) {
factory.save(item, true);
return ExecutionResult.SUCCESS_WITH_ALERT;
} else {
return ExecutionResult.SUCCESS_NO_ALERT;
}
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
Aggregations