use of org.talend.core.model.process.IProcess2 in project tdi-studio-se by Talend.
the class PropertyChangeCommand method execute.
@Override
public void execute() {
IElementParameter currentParam = elem.getElementParameter(propName);
changeMetadataCommands.clear();
oldElementValues.clear();
if (currentParam == null) {
return;
}
if (currentParam instanceof ElementParameter) {
((ElementParameter) currentParam).setTaggedValue(UpdatesConstants.CHANGED_BY_USER, true);
}
if (currentParam.isRepositoryValueUsed()) {
if (currentParam.getFieldType() == EParameterFieldType.MEMO_SQL) {
Object queryStoreValue = elem.getPropertyValue(EParameterName.QUERYSTORE_TYPE.getName());
if (!EmfComponent.BUILTIN.equals(queryStoreValue) || !EmfComponent.TNS_FILE.equals(queryStoreValue)) {
elem.setPropertyValue(EParameterName.QUERYSTORE_TYPE.getName(), EmfComponent.BUILTIN);
}
currentParam.setRepositoryValueUsed(false);
} else {
toUpdate = true;
Object value = elem.getPropertyValue(propName);
if (value == null || (!value.toString().endsWith("xsd") && !value.toString().endsWith("xsd\""))) {
elem.setPropertyValue(propertyTypeName, EmfComponent.BUILTIN);
}
for (IElementParameter param : elem.getElementParameters()) {
if (param.getRepositoryProperty() == null || param.getRepositoryProperty().equals(currentParam.getName())) {
param.setRepositoryValueUsed(false);
}
}
}
repositoryValueWasUsed = true;
} else {
repositoryValueWasUsed = false;
}
oldValue = elem.getPropertyValue(propName);
elem.setPropertyValue(propName, newValue);
if (currentParam.getFieldType().equals(EParameterFieldType.CONNECTION_LIST) && currentParam.getContext() != null && (elem instanceof Node)) {
String connParaname = currentParam.getContext() + ":" + currentParam.getName();
if (connParaname.equals(propName)) {
IConnection selectedConn = null;
for (IConnection conn : ((Node) elem).getIncomingConnections()) {
if (conn.getUniqueName().equals(newValue)) {
selectedConn = conn;
break;
}
}
if (selectedConn != null && getTakeSchema()) {
((Node) selectedConn.getSource()).takeSchemaFrom((Node) elem, currentParam.getContext());
}
}
}
if ("ELT_TABLE_NAME".equals(propName) || "ELT_SCHEMA_NAME".equals(propName)) {
//$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-1$
String oldELTValue = "";
//$NON-NLS-1$
String newELTValue = "";
String oldParamValue = TalendQuoteUtils.removeQuotes((String) oldValue);
String newParamValue = TalendQuoteUtils.removeQuotes((String) newValue);
if ("ELT_TABLE_NAME".equals(propName)) {
//$NON-NLS-1$
//$NON-NLS-1$
String schemaName = TalendQuoteUtils.removeQuotes((String) elem.getPropertyValue("ELT_SCHEMA_NAME"));
if (schemaName == null || "".equals(schemaName.trim())) {
//$NON-NLS-1$
oldELTValue = oldParamValue;
newELTValue = newParamValue;
} else {
//$NON-NLS-1$
oldELTValue = schemaName + "." + oldParamValue;
//$NON-NLS-1$
newELTValue = schemaName + "." + newParamValue;
}
} else {
//$NON-NLS-1$
String tableName = TalendQuoteUtils.removeQuotes((String) elem.getPropertyValue("ELT_TABLE_NAME"));
if (oldParamValue != null && !"".equals(oldParamValue.trim())) {
//$NON-NLS-1$
oldELTValue = oldParamValue + ".";
}
if (newParamValue != null && !"".equals(newParamValue.trim())) {
//$NON-NLS-1$
newELTValue = newParamValue + ".";
}
// $NON-NLS-1$
oldELTValue = oldELTValue + tableName;
// $NON-NLS-1$
newELTValue = newELTValue + tableName;
}
List<? extends IConnection> connections = ((Node) elem).getOutgoingConnections();
for (IConnection connection : connections) {
INode targetNode = connection.getTarget();
String componentName = targetNode.getComponent().getName();
if (componentName.matches("tELT.+Map")) {
//$NON-NLS-1$
if (GlobalServiceRegister.getDefault().isServiceRegistered(IDbMapDesignerService.class)) {
IDbMapDesignerService service = (IDbMapDesignerService) GlobalServiceRegister.getDefault().getService(IDbMapDesignerService.class);
updateELTMapComponentCommand = service.getUpdateELTMapComponentCommand(targetNode, connection, oldELTValue, newELTValue);
updateELTMapComponentCommand.execute();
}
}
}
}
// add for bug TDI-26632 by fwang in 11 July, 2013. can't edit parameters if use repository connection.
IElementParameter propertyTypeParam = elem.getElementParameter(EParameterName.PROPERTY_TYPE.getName());
IElementParameter repositoryTypeParam = elem.getElementParameter(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
if (("USE_EXISTING_CONNECTION").equals(propName) && elem instanceof Node && propertyTypeParam != null && "REPOSITORY".equals(propertyTypeParam.getValue()) && repositoryTypeParam != null && !("").equals(repositoryTypeParam.getValue())) {
Node node = (Node) elem;
for (IElementParameter param : node.getElementParameters()) {
String repositoryValue = param.getRepositoryValue();
if ((repositoryValue != null) && (!param.getName().equals(EParameterName.PROPERTY_TYPE.getName())) && param.getFieldType() != EParameterFieldType.MEMO_SQL && !("tMDMReceive".equals(node.getComponent().getName()) && "XPATH_PREFIX".equals(//$NON-NLS-1$ //$NON-NLS-2$
param.getRepositoryValue())) && !("tSAPOutput".equals(node.getComponent().getName()) && param.getName().equals(UpdatesConstants.MAPPING)) && !("tFileInputEBCDIC".equals(node.getComponent().getName()) && "DATA_FILE".equals(repositoryValue))) {
param.setRepositoryValueUsed(true);
if (!(EParameterName.DB_VERSION.getName()).equals(param.getName())) {
param.setReadOnly(true);
}
}
}
}
// feature 19312
if (propName.contains(EParameterName.USE_DYNAMIC_JOB.getName()) && newValue.equals(false)) {
IElementParameter processParam = elem.getElementParameter(EParameterName.PROCESS.getName());
IElementParameter processTypeParameter = elem.getElementParameter(EParameterName.PROCESS_TYPE_PROCESS.getName());
//$NON-NLS-1$
final String parentName = processParam.getName() + ":";
//$NON-NLS-1$
elem.setPropertyValue(parentName + processTypeParameter.getName(), "");
//$NON-NLS-1$
elem.setPropertyValue(processParam.getName(), "");
}
if (propName.contains(EParameterName.PROCESS_TYPE_PROCESS.getName())) {
boolean isSelectUseDynamic = false;
IElementParameter useDynamicJobParameter = elem.getElementParameter(EParameterName.USE_DYNAMIC_JOB.getName());
if (useDynamicJobParameter != null && useDynamicJobParameter instanceof IElementParameter) {
Object useDynamicJobValue = useDynamicJobParameter.getValue();
if (useDynamicJobValue != null && useDynamicJobValue instanceof Boolean) {
isSelectUseDynamic = (Boolean) useDynamicJobValue;
}
}
if (isSelectUseDynamic) {
StringBuffer labels = new StringBuffer("");
if (newValue != null) {
String[] strValues = newValue.toString().split(";");
for (int i = 0; i < strValues.length; i++) {
String strValue = strValues[i];
// newValue is the id of the job
ProcessItem processItem = ItemCacheManager.getProcessItem(strValue);
if (processItem != null) {
String label = processItem.getProperty().getLabel();
if (i > 0) {
labels.append(";");
}
labels.append(label);
}
}
}
currentParam.getParentParameter().setValue(labels.toString());
} else {
// newValue is the id of the job
ProcessItem processItem = ItemCacheManager.getProcessItem((String) newValue);
if (processItem != null) {
currentParam.getParentParameter().setValue(processItem.getProperty().getLabel());
}
}
}
if (propName.contains(EParameterName.PROCESS_TYPE_VERSION.getName())) {
// newValue is the id of the job
// hywang add for feature 6549
// 1.to see current component if is a jobletComponent by "elem"
boolean isJobletComponent = false;
// Node jobletNode = null;
IJobletProviderService service = null;
if (PluginChecker.isJobLetPluginLoaded()) {
service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
}
if (elem instanceof Node) {
// jobletNode = (Node) elem;
if (service != null) {
isJobletComponent = service.isJobletComponent((Node) elem);
}
}
if (isJobletComponent) {
// 2.if it is a jobletcomponent,reload the component by the version
String id = service.getJobletComponentItem((Node) elem).getId();
String version = (String) newValue;
IComponent newComponent = service.setPropertyForJobletComponent(id, version);
reloadNode((Node) elem, newComponent);
} else {
IElementParameter processIdParam = currentParam.getParentParameter().getChildParameters().get(EParameterName.PROCESS_TYPE_PROCESS.getName());
ProcessItem processItem = ItemCacheManager.getProcessItem((String) processIdParam.getValue(), (String) newValue);
if (processItem != null) {
currentParam.getParentParameter().setValue(processItem.getProperty().getLabel());
}
}
}
if (propName.contains(EParameterName.PROCESS_TYPE_CONTEXT.getName())) {
if (elem instanceof Node) {
Node node = (Node) elem;
List<IContext> listContext = node.getProcess().getContextManager().getListContext();
List<String> values = new ArrayList<String>();
for (IContext context : listContext) {
values.add(context.getName());
}
currentParam.setListItemsDisplayName(values.toArray(new String[0]));
currentParam.setListItemsValue(values.toArray(new String[0]));
currentParam.setValue(newValue);
}
}
if (propName.equals(EParameterName.VALIDATION_RULES.getName())) {
if (elem instanceof INode) {
ValidationRulesUtil.createRejectConnector((INode) elem);
ValidationRulesUtil.updateRejectMetatable((INode) elem, null);
if (newValue != null && (!(Boolean) newValue)) {
ValidationRulesUtil.removeRejectConnector((INode) elem);
ValidationRulesUtil.removeRejectConnection((INode) elem);
}
}
}
String dbType = "";
if (newValue instanceof String) {
dbType = (String) newValue;
}
IElementParameter schemaParameter = null;
if (propName.equals(EParameterName.DB_TYPE.getName())) {
IElementParameter elementParameter = elem.getElementParameter(EParameterName.DB_VERSION.getName());
schemaParameter = elem.getElementParameter(EParameterName.SCHEMA_DB.getName());
JobSettingVersionUtil.setDbVersion(elementParameter, dbType, true);
DesignerUtilities.setSchemaDB(schemaParameter, newValue);
} else if (propName.equals(JobSettingsConstants.getExtraParameterName(EParameterName.DB_TYPE.getName()))) {
IElementParameter elementParameter = elem.getElementParameter(JobSettingsConstants.getExtraParameterName(EParameterName.DB_VERSION.getName()));
schemaParameter = elem.getElementParameter(JobSettingsConstants.getExtraParameterName(EParameterName.SCHEMA_DB.getName()));
JobSettingVersionUtil.setDbVersion(elementParameter, dbType, true);
DesignerUtilities.setSchemaDB(schemaParameter, newValue);
}
// Some DB not need fill the schema parameter for the JobSetting View "Extra" ,"Stats&Logs"
if (schemaParameter != null && !schemaParameter.isShow(elem.getElementParameters()) && !schemaParameter.getValue().equals("")) {
schemaParameter.setValue("");
}
if (!toUpdate && (currentParam.getFieldType().equals(EParameterFieldType.RADIO) || currentParam.getFieldType().equals(EParameterFieldType.CLOSED_LIST) || currentParam.getFieldType().equals(EParameterFieldType.OPENED_LIST) || currentParam.getFieldType().equals(EParameterFieldType.CHECK) || currentParam.getFieldType().equals(EParameterFieldType.AS400_CHECK) || currentParam.getFieldType().equals(EParameterFieldType.COMPONENT_LIST))) {
toUpdate = false;
setDefaultValues(currentParam, elem);
}
if (currentParam.getName().equals(EParameterName.PROCESS_TYPE_PROCESS.getName())) {
toUpdate = true;
}
if (toUpdate) {
elem.setPropertyValue(updataComponentParamName, Boolean.TRUE);
}
// see bug 9151:100% CPU when typing text.
if (getNewValue() instanceof String && elem instanceof INode) {
INode curNode = (INode) elem;
String uniqueName = curNode.getUniqueName();
IProcess process = curNode.getProcess();
if (process != null && process instanceof IProcess2) {
IProcess2 process2 = (IProcess2) process;
List<? extends INode> generatingNodes = null;
if (process2.isProcessModified()) {
process2.setProcessModified(false);
generatingNodes = process2.getGeneratingNodes();
if (generatingNodes != null) {
for (INode genNode : new ArrayList<INode>(generatingNodes)) {
if (genNode.getUniqueName().equals(uniqueName)) {
IElementParameter genParam = genNode.getElementParameter(propName);
if (genParam != null) {
genParam.setValue(newValue);
break;
}
}
}
}
process2.setProcessModified(true);
codeViewUpdater.startIfExecutable(elem);
}
}
}
updateRelativeNodesIfNeeded(currentParam);
checkProcess.startIfExecutable(elem);
// See feature 3902
if (needUpdateMonitorConnection()) {
((Connection) elem).setMonitorConnection((Boolean) currentParam.getValue());
}
refreshMR(propName);
}
use of org.talend.core.model.process.IProcess2 in project tdi-studio-se by Talend.
the class ComponentChooseDialog method propaHadoopCfgChanges.
/**
* DOC ycbai Comment method "propaHadoopCfgChanges".
*
* <P>
* Propagate the changes from hadoop cluster to M/R process when drag&drop hadoop subnode from repository view to
* M/R process.
* </P>
*
* @param repositoryNode
*/
private void propaHadoopCfgChanges(IRepositoryNode repositoryNode) {
if (repositoryNode == null || repositoryNode.getObject() == null) {
return;
}
IHadoopClusterService hadoopClusterService = HadoopRepositoryUtil.getHadoopClusterService();
if (hadoopClusterService == null || !hadoopClusterService.isHadoopSubnode(repositoryNode)) {
return;
}
IProcess process = editor.getProcess();
if (!ComponentCategory.CATEGORY_4_MAPREDUCE.getName().equals(process.getComponentsType()) && !ComponentCategory.CATEGORY_4_SPARK.getName().equals(process.getComponentsType()) && !ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName().equals(process.getComponentsType())) {
return;
}
if ((process instanceof IProcess2) && (((IProcess2) process).getProperty().getItem() instanceof JobletProcessItem)) {
return;
}
Item subItem = repositoryNode.getObject().getProperty().getItem();
String propertyParamName = MR_PROPERTY_PREFIX + EParameterName.PROPERTY_TYPE.getName();
String propertyRepTypeParamName = MR_PROPERTY_PREFIX + EParameterName.REPOSITORY_PROPERTY_TYPE.getName();
IElementParameter propertyParam = process.getElementParameter(propertyParamName);
if (propertyParam == null) {
return;
}
String repositoryValue = propertyParam.getRepositoryValue();
if (repositoryValue == null) {
return;
}
//$NON-NLS-1$
String[] supportedRepositoryTypes = repositoryValue.split("\\|");
String repositoryType = hadoopClusterService.getRepositoryTypeOfHadoopSubItem(subItem);
if (!ArrayUtils.contains(supportedRepositoryTypes, repositoryType)) {
return;
}
Item hadoopClusterItem = hadoopClusterService.getHadoopClusterBySubitemId(new Project(ProjectManager.getInstance().getProject(subItem)), subItem.getProperty().getId());
String hadoopClusterId = hadoopClusterItem.getProperty().getId();
if (EmfComponent.REPOSITORY.equals(propertyParam.getValue())) {
// do nothing when select the same hadoop cluster.
String propertyId = (String) process.getElementParameter(propertyRepTypeParamName).getValue();
if (hadoopClusterId.equals(propertyId)) {
return;
}
}
Connection connection = ((ConnectionItem) subItem).getConnection();
if (hadoopClusterService.hasDiffsFromClusterToProcess(subItem, process)) {
boolean confirmUpdate = MessageDialog.openConfirm(editor.getSite().getShell(), //$NON-NLS-1$
Messages.getString("TalendEditorDropTargetListener.updateHadoopCfgDialog.title"), //$NON-NLS-1$
Messages.getString("TalendEditorDropTargetListener.updateHadoopCfgDialog.msg"));
if (confirmUpdate) {
// Update spark mode to YARN_CLIENT if repository
if (ComponentCategory.CATEGORY_4_SPARK.getName().equals(process.getComponentsType()) || ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName().equals(process.getComponentsType())) {
IElementParameter sparkLocalParam = process.getElementParameter(HadoopConstants.SPARK_LOCAL_MODE);
IElementParameter sparkParam = process.getElementParameter(HadoopConstants.SPARK_MODE);
if (sparkLocalParam != null && (Boolean) (sparkLocalParam.getValue())) {
sparkLocalParam.setValue(false);
}
if (sparkParam != null && !HadoopConstants.SPARK_MODE_YARN_CLIENT.equals(sparkParam.getValue())) {
sparkParam.setValue(HadoopConstants.SPARK_MODE_YARN_CLIENT);
}
}
propertyParam.setValue(EmfComponent.REPOSITORY);
ChangeValuesFromRepository command = new ChangeValuesFromRepository(process, connection, propertyRepTypeParamName, subItem.getProperty().getId());
execCommandStack(command);
}
}
}
use of org.talend.core.model.process.IProcess2 in project tdi-studio-se by Talend.
the class JavaProcessUtil method getNeededModules.
private static void getNeededModules(final IProcess process, boolean withChildrens, Set<ProcessItem> searchItems, List<ModuleNeeded> modulesNeeded, boolean forMR) {
IElementParameter headerParameter = process.getElementParameter(EParameterName.HEADER_LIBRARY.getName());
if (headerParameter != null) {
Object value = headerParameter.getValue();
if (value != null) {
String headerLibraries = (String) value;
if (headerLibraries.indexOf(File.separatorChar) > 0 && headerLibraries.length() > headerLibraries.lastIndexOf(File.separatorChar) + 1) {
String substring = headerLibraries.substring(headerLibraries.lastIndexOf(File.separatorChar) + 1);
if (!"".equals(substring)) {
//$NON-NLS-1$
modulesNeeded.add(getModuleValue(process, substring));
}
}
}
}
IElementParameter footerParameter = process.getElementParameter(EParameterName.FOOTER_LIBRARY.getName());
if (footerParameter != null) {
Object value = footerParameter.getValue();
if (value != null) {
String footerLibraries = (String) value;
if (footerLibraries.indexOf(File.separatorChar) > 0 && footerLibraries.length() > footerLibraries.lastIndexOf(File.separatorChar) + 1) {
String substring = footerLibraries.substring(footerLibraries.lastIndexOf(File.separatorChar) + 1);
if (!"".equals(substring)) {
//$NON-NLS-1$
modulesNeeded.add(getModuleValue(process, substring));
}
}
}
}
IElementParameter elementParameter = process.getElementParameter(EParameterName.DRIVER_JAR.getName());
if (elementParameter != null && elementParameter.getFieldType() == EParameterFieldType.TABLE) {
getModulesInTable(process, elementParameter, modulesNeeded);
}
if (process instanceof IProcess2) {
Item item = ((IProcess2) process).getProperty().getItem();
if (item instanceof ProcessItem) {
modulesNeeded.addAll(ModulesNeededProvider.getModulesNeededForProcess((ProcessItem) item, process));
}
}
if (ProcessUtils.isTestContainer(process)) {
// if it is a test container, add junit jars.
addJunitNeededModules(modulesNeeded);
}
String hadoopItemId = null;
List<? extends INode> nodeList = process.getGeneratingNodes();
for (INode node : nodeList) {
if (hadoopItemId == null) {
String itemId = getHadoopClusterItemId(node);
if (itemId != null) {
hadoopItemId = itemId;
}
}
if (process instanceof IProcess2) {
((IProcess2) node.getProcess()).setNeedLoadmodules(((IProcess2) process).isNeedLoadmodules());
}
Set<ModuleNeeded> nodeNeededModules = getNeededModules(node, searchItems, withChildrens, forMR);
if (nodeNeededModules != null) {
modulesNeeded.addAll(nodeNeededModules);
}
}
if (hadoopItemId == null) {
// Incase it is a bigdata process.
//$NON-NLS-1$
IElementParameter propertyParam = process.getElementParameter("MR_PROPERTY");
if (propertyParam != null) {
IElementParameter repositoryParam = propertyParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
if (repositoryParam != null) {
hadoopItemId = String.valueOf(repositoryParam.getValue());
}
}
}
if (hadoopItemId != null) {
useCustomConfsJarIfNeeded(modulesNeeded, hadoopItemId);
}
}
use of org.talend.core.model.process.IProcess2 in project tdi-studio-se by Talend.
the class SaveAsProcessWizard method performFinish.
@Override
public boolean performFinish() {
boolean ok = false;
try {
IProcess2 loadedProcess = jobEditorInput.getLoadedProcess();
ProcessType processType = loadedProcess.saveXmlFile();
isUpdate = isUpdate();
if (isUpdate) {
update(processType);
} else {
processItem.setProcess(processType);
property.setId(repositoryFactory.getNextId());
// don't need to add depended routines.
repositoryFactory.create(processItem, mainPage.getDestinationPath());
RelationshipItemBuilder.getInstance().addOrUpdateItem(processItem);
}
ok = true;
} catch (Exception e) {
MessageDialog.openError(getShell(), "Error", "Job could not be saved" + " : " + e.getMessage());
ExceptionHandler.process(e);
}
return ok;
}
use of org.talend.core.model.process.IProcess2 in project tdi-studio-se by Talend.
the class JavaProcessor method cleanBeforeGenerate.
@Override
public void cleanBeforeGenerate(int options) throws ProcessorException {
setDoClean(false);
if (this.getProcess().isNeedRegenerateCode() || this.getProcess() instanceof IProcess2 && ((IProcess2) this.getProcess()).isProcessModified()) {
// will do clean
setDoClean(true);
} else {
return;
}
// clean the generated java source codes.
if (BitwiseOptionUtils.containOption(options, CLEAN_JAVA_CODES)) {
IFolder javaCodeFolder = getCodeProject().getFolder(this.getSrcCodePath().removeLastSegments(1));
// cleanFolder(javaCodeFolder);
try {
if (javaCodeFolder != null) {
String processSourceFileName = null;
if (process != null) {
//$NON-NLS-1$
processSourceFileName = process.getName() + ".java";
}
for (IResource resource : javaCodeFolder.members()) {
if ("java".equals(resource.getFileExtension())) {
//$NON-NLS-1$
if (processSourceFileName != null && processSourceFileName.equals(resource.getName())) {
((IFile) resource).setContents(new ByteArrayInputStream(new byte[0]), true, false, null);
} else {
resource.delete(true, null);
}
} else {
resource.delete(true, null);
}
}
}
} catch (CoreException e) {
// do nothing
}
IFolder classCodeFolder = getCodeProject().getFolder(this.getCompiledCodePath().removeLastSegments(1));
cleanFolder(classCodeFolder);
}
// clean the context groups. Sometimes, if remove the context group, the context file be kept still.
if (BitwiseOptionUtils.containOption(options, CLEAN_CONTEXTS)) {
IFolder srcContextFolder = getCodeProject().getFolder(this.getSrcContextPath().removeLastSegments(1));
cleanFolder(srcContextFolder);
IFolder classContextFolder = getCodeProject().getFolder(this.getCompiledContextPath().removeLastSegments(1));
cleanFolder(classContextFolder);
}
// if test case, clean the data
if (BitwiseOptionUtils.containOption(options, CLEAN_DATA_SETS) && isTestJob) {
IFolder srcDatasetFolder = getCodeProject().getFolder(this.getSrcDataSetPath());
cleanFolder(srcDatasetFolder);
}
}
Aggregations