use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.
the class PaletteSettingPage method getComponentsInStatsLogsAndImplicit.
private Set<IComponent> getComponentsInStatsLogsAndImplicit(List parameters) {
Set<IComponent> components = new HashSet<IComponent>();
for (Object obj : parameters) {
String paramName = null;
Object value = null;
if (obj instanceof ElementParameterType) {
ElementParameterType param = (ElementParameterType) obj;
paramName = param.getName();
value = param.getValue();
}
if (value == null) {
continue;
}
if ("ON_STATCATCHER_FLAG".equals(paramName)) {
//$NON-NLS-1$
//$NON-NLS-1$
addComponent(components, "tStatCatcher", value);
} else if ("ON_METERCATCHER_FLAG".equals(paramName)) {
//$NON-NLS-1$
//$NON-NLS-1$
addComponent(components, "tFlowMeterCatcher", value);
} else if ("ON_LOGCATCHER_FLAG".equals(paramName)) {
//$NON-NLS-1$
//$NON-NLS-1$
addComponent(components, "tLogCatcher", value);
} else if ("ON_CONSOLE_FLAG".equals(paramName)) {
//$NON-NLS-1$
//$NON-NLS-1$
addComponent(components, "tLogRow", value);
} else if ("ON_FILES_FLAG".equals(paramName)) {
//$NON-NLS-1$
//$NON-NLS-1$
addComponent(components, "tFileOutputDelimited", value);
} else if ("ON_DATABASE_FLAG".equals(paramName)) {
//$NON-NLS-1$
//$NON-NLS-1$
String usedDatabase = getUsedDatabase(parameters, "DB_TYPE");
if (usedDatabase != null) {
addComponent(components, usedDatabase, value);
}
} else if ("IMPLICIT_TCONTEXTLOAD".equals(paramName)) {
//$NON-NLS-1$
//$NON-NLS-1$
addComponent(components, "tContextLoad", value);
} else if ("FROM_FILE_FLAG_IMPLICIT_CONTEXT".equals(paramName)) {
//$NON-NLS-1$
//$NON-NLS-1$
addComponent(components, "tFileInputDelimited", value);
} else if ("FROM_DATABASE_FLAG_IMPLICIT_CONTEXT".equals(paramName)) {
//$NON-NLS-1$
//$NON-NLS-1$
String usedDatabase = getUsedDatabase(parameters, "DB_TYPE_IMPLICIT_CONTEXT");
if (usedDatabase != null) {
addComponent(components, usedDatabase, value);
}
}
}
return components;
}
use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.
the class PaletteSettingPage method addUsedComponents.
private void addUsedComponents(Set<IComponent> components, List<IRepositoryViewObject> allProcess, ComponentCategory category) {
for (IRepositoryViewObject object : allProcess) {
Item item = object.getProperty().getItem();
List parameters = null;
ProcessType processType = null;
if (item instanceof ProcessItem) {
processType = ((ProcessItem) item).getProcess();
} else if (item instanceof JobletProcessItem) {
processType = ((JobletProcessItem) item).getJobletProcess();
}
if (processType != null) {
for (Object oNode : processType.getNode()) {
NodeType node = (NodeType) oNode;
IComponent component = ComponentsFactoryProvider.getInstance().get(node.getComponentName(), category.getName());
if (component != null && component.getComponentType() == EComponentType.EMF) {
components.add(component);
}
}
if (processType.getParameters() != null) {
// occurs actually only in joblets
parameters = processType.getParameters().getElementParameter();
}
}
if (parameters != null) {
// used in stats&log and implicite
Set<IComponent> inStatsLogsAndImplicit = getComponentsInStatsLogsAndImplicit(parameters);
if (inStatsLogsAndImplicit != null) {
components.addAll(inStatsLogsAndImplicit);
}
}
}
}
use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.
the class PaletteSettingPage method getComponentsUsedInProject.
public Set<IComponent> getComponentsUsedInProject(Project project) {
if (componentsUsed != null) {
return componentsUsed;
}
componentsUsed = new HashSet<IComponent>();
IProxyRepositoryFactory repositoryFactory = CoreUIPlugin.getDefault().getProxyRepositoryFactory();
try {
ERepositoryObjectType jobType = ERepositoryObjectType.PROCESS;
if (jobType != null) {
List<IRepositoryViewObject> allProcess = repositoryFactory.getAll(project, jobType, true);
addUsedComponents(componentsUsed, allProcess, ComponentCategory.CATEGORY_4_DI);
}
ERepositoryObjectType jobletType = ERepositoryObjectType.JOBLET;
if (jobletType != null) {
List<IRepositoryViewObject> allJoblet = repositoryFactory.getAll(project, jobletType, true);
addUsedComponents(componentsUsed, allJoblet, ComponentCategory.CATEGORY_4_DI);
}
ERepositoryObjectType routeType = ERepositoryObjectType.PROCESS_ROUTE;
if (routeType != null) {
List<IRepositoryViewObject> allRoutes = repositoryFactory.getAll(project, routeType, true);
addUsedComponents(componentsUsed, allRoutes, ComponentCategory.CATEGORY_4_CAMEL);
}
//$NON-NLS-1$
ERepositoryObjectType mrType = ERepositoryObjectType.valueOf("PROCESS_MR");
if (mrType != null) {
List<IRepositoryViewObject> allMr = repositoryFactory.getAll(project, mrType, true);
addUsedComponents(componentsUsed, allMr, ComponentCategory.CATEGORY_4_MAPREDUCE);
addUsedComponents(componentsUsed, allMr, ComponentCategory.CATEGORY_4_SPARK);
}
//$NON-NLS-1$
ERepositoryObjectType stormType = ERepositoryObjectType.valueOf("PROCESS_STORM");
if (stormType != null) {
List<IRepositoryViewObject> allStorm = repositoryFactory.getAll(project, stormType, true);
addUsedComponents(componentsUsed, allStorm, ComponentCategory.CATEGORY_4_STORM);
addUsedComponents(componentsUsed, allStorm, ComponentCategory.CATEGORY_4_SPARKSTREAMING);
}
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
if (testContainerService != null) {
ERepositoryObjectType testCaseType = testContainerService.getTestCaseObjectType();
if (testCaseType != null) {
List<IRepositoryViewObject> allTestCase = repositoryFactory.getAll(project, testCaseType, true);
addUsedComponents(componentsUsed, allTestCase, ComponentCategory.CATEGORY_4_SPARK);
addUsedComponents(componentsUsed, allTestCase, ComponentCategory.CATEGORY_4_DI);
}
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
return componentsUsed;
}
use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.
the class CustomComponentSettingPage method finish.
private void finish(IProgressMonitor... monitorWrap) {
IProgressMonitor monitor = null;
if (monitorWrap != null && monitorWrap.length == 1) {
monitor = monitorWrap[0];
}
final IProxyRepositoryFactory prf = CorePlugin.getDefault().getProxyRepositoryFactory();
if (PluginChecker.isSVNProviderPluginLoaded() && (!sharedAdded.isEmpty() || !backAdded.isEmpty())) {
RepositoryWorkUnit repositoryWorkUnit = new RepositoryWorkUnit("Update custom components") {
@Override
public void run() throws PersistenceException {
final IWorkspaceRunnable op = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor subMonitor) throws CoreException {
ISVNProviderService service = (ISVNProviderService) GlobalServiceRegister.getDefault().getService(ISVNProviderService.class);
String projectLabel = pro.getTechnicalLabel();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject eclipseProject = workspace.getRoot().getProject(projectLabel);
String targetRoot = eclipseProject.getLocation().toString() + "/" + ERepositoryObjectType.getFolderName(ERepositoryObjectType.COMPONENTS);
File componentFolder = new File(targetRoot);
URL url = null;
try {
if (!componentFolder.exists()) {
FilesUtils.createFoldersIfNotExists(targetRoot, false);
}
Bundle b = Platform.getBundle(IComponentsFactory.COMPONENTS_LOCATION);
url = FileLocator.toFileURL(FileLocator.find(b, new Path(""), null));
String sourceRoot = url.getFile();
// delete share
for (IComponent component : backAdded.keySet()) {
String componentFullPath = targetRoot + File.separator + component.getName();
if (service.isSVNProject(pro)) {
service.svnEclipseHandlerDelete(eclipseProject, pro, componentFullPath);
if (subMonitor != null) {
subMonitor.worked(10);
}
} else {
File file = new File(componentFullPath);
if (file != null && file.exists()) {
org.talend.utils.io.FilesUtils.deleteFolder(file, true);
}
}
}
if (!backAdded.isEmpty()) {
getCustomComponentSettings().removeAll(backAdded.values());
}
FileFilter ff = new FileFilter() {
@Override
public boolean accept(File pathname) {
if (FilesUtils.isSVNFolder(pathname)) {
return false;
}
return true;
}
};
// share
for (IComponent component : sharedAdded.keySet()) {
String sourcePath = sourceRoot + component.getPathSource() + File.separator + component.getName();
File sourceFile = new File(sourcePath);
String targetPath = targetRoot + File.separatorChar + component.getName();
File targetFile = new File(targetPath);
FilesUtils.copyFolder(sourceFile, targetFile, true, ff, null, true, false);
if (subMonitor != null) {
subMonitor.worked(10);
}
}
} catch (Exception e) {
resetCustomComponentSetting();
ExceptionHandler.process(e);
}
try {
prf.saveProject(pro);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
try {
eclipseProject.refreshLocal(IResource.DEPTH_INFINITE, subMonitor);
} catch (CoreException e1) {
ExceptionHandler.process(e1);
}
}
};
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
// the update the project files need to be done in the workspace runnable to avoid all
// notification
// of changes before the end of the modifications.
workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
} catch (CoreException e) {
throw new PersistenceException(e.getCause());
}
}
};
repositoryWorkUnit.setRefreshRepository(false);
repositoryWorkUnit.setForceTransaction(true);
prf.executeRepositoryWorkUnit(repositoryWorkUnit);
try {
repositoryWorkUnit.throwPersistenceExceptionIfAny();
} catch (PersistenceException e) {
e.printStackTrace();
}
}
if (monitor != null) {
monitor.done();
}
// refresh again after the gui closed .
try {
String projectLabel = pro.getTechnicalLabel();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject eclipseProject = workspace.getRoot().getProject(projectLabel);
eclipseProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
} catch (CoreException e1) {
ExceptionHandler.process(e1);
}
}
use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.
the class JobletContainer method refreshJobletNodes.
public void refreshJobletNodes(boolean update, boolean coll) {
if (this.node.isJoblet()) {
if (!coll || update) {
boolean componentUpdated = false;
IComponent oldComponent = node.getComponent();
if (GlobalServiceRegister.getDefault().isServiceRegistered(IJobletProviderService.class)) {
IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
IComponent newComponent = service.getUpdatedJobletComponent(oldComponent);
if (oldComponent != newComponent) {
node.setComponent(newComponent);
componentUpdated = true;
}
}
JobletUtil util = new JobletUtil();
IProcess jobletProcess = this.getNode().getComponent().getProcess();
Set<IConnection> conns = new HashSet<IConnection>();
List<? extends INode> jobletNodes = jobletProcess.getGraphicalNodes();
boolean lockByOther = false;
if (jobletProcess instanceof IProcess2) {
lockByOther = util.lockByOthers(((IProcess2) jobletProcess).getProperty().getItem());
}
Map<String, List<? extends IElementParameter>> paraMap = new HashMap<String, List<? extends IElementParameter>>();
// List<NodeContainer> temList = new ArrayList<NodeContainer>(nodeContainers);
if (!componentUpdated) {
for (NodeContainer nc : nodeContainers) {
if (this.node.getProcess() instanceof IProcess2) {
if (!update) {
paraMap.put(nc.getNode().getJoblet_unique_name(), nc.getNode().getElementParameters());
}
((IProcess2) this.node.getProcess()).removeUniqueNodeName(nc.getNode().getUniqueName());
}
}
}
nodeContainers.clear();
jobletElements.clear();
// boolean canRemove = false;
for (INode inode : jobletNodes) {
// canAdd = util.canAdd(temList, inode);
if ((inode instanceof Node)) {
Node temNode = (Node) inode;
// if (canAdd) {
conns.addAll(temNode.getIncomingConnections());
conns.addAll(temNode.getOutgoingConnections());
Node jnode = util.cloneNode(temNode, this.node.getProcess(), paraMap, lockByOther);
if (!this.node.isActivate()) {
jnode.setActivate(this.node.isActivate());
}
NodeContainer nodeContainer = util.cloneNodeContainer(temNode.getNodeContainer(), jnode);
jnode.setJobletnode(this.node);
jnode.setJoblet_unique_name(temNode.getUniqueName());
this.nodeContainers.add(nodeContainer);
this.jobletElements.add(jnode);
this.jobletElements.add(jnode.getNodeLabel());
this.jobletElements.add(jnode.getNodeError());
this.jobletElements.add(jnode.getNodeProgressBar());
// } else if (update) {
// for (NodeContainer nodeC : nodeContainers) {
// if (nodeC.getNode().getJoblet_unique_name().equals(temNode.getUniqueName())) {
// util.updateNode(nodeC.getNode(), temNode);
// break;
// }
// }
// }
}
}
// }
for (IConnection con : conns) {
String sourceName = con.getSource().getUniqueName();
String targetName = con.getTarget().getUniqueName();
Node sourceNode = null;
Node targetNode = null;
for (NodeContainer nodeC : nodeContainers) {
Node connNode = nodeC.getNode();
if (connNode.getJoblet_unique_name().equals(sourceName)) {
sourceNode = connNode;
}
if (connNode.getJoblet_unique_name().equals(targetName)) {
targetNode = connNode;
}
if (sourceNode != null && targetNode != null) {
util.cloneConnection(con, sourceNode, targetNode);
break;
}
}
}
}
} else if (this.node.isMapReduceStart()) {
Integer mrGroupId = node.getMrGroupId();
List<? extends INode> mapReduceNodes = this.node.getProcess().getGraphicalNodes();
List<Node> nodeList = new ArrayList<Node>();
if (node.getNodeContainer().getSubjobContainer() != null && node.getNodeContainer().getSubjobContainer().isCollapsed()) {
nodeList.add(node);
} else {
for (INode inode : mapReduceNodes) {
if ((inode instanceof Node)) {
Node temNode = (Node) inode;
if (temNode.getMrGroupId() != null && mrGroupId != null && temNode.getMrGroupId().equals(mrGroupId)) {
nodeList.add(temNode);
}
}
}
}
nodeContainers.clear();
jobletElements.clear();
for (Node inode : nodeList) {
if (!inode.isActivate()) {
continue;
}
NodeContainer nodeContainer = inode.getNodeContainer();
// inode.setJoblet_unique_name(inode.getUniqueName());
if (nodeContainer instanceof JobletContainer) {
((JobletContainer) nodeContainer).setMrStartContainer(this);
}
this.nodeContainers.add(nodeContainer);
this.jobletElements.add(inode);
this.jobletElements.add(inode.getNodeLabel());
this.jobletElements.add(inode.getNodeError());
this.jobletElements.add(inode.getNodeProgressBar());
}
}
}
Aggregations