Search in sources :

Example 46 with ProcessItem

use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.

the class AddContextCommentValueMigrationTask method execute.

@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
    EList<ContextType> contexts = null;
    if (item instanceof ProcessItem) {
        // process, process_mr, process_storm, route, routelet.
        ProcessItem processItem = (ProcessItem) item;
        contexts = processItem.getProcess().getContext();
    } else if (item instanceof JobletProcessItem) {
        JobletProcessItem jobletItem = (JobletProcessItem) item;
        contexts = jobletItem.getJobletProcess().getContext();
    } else if (item instanceof ContextItem) {
        ContextItem contextItem = (ContextItem) item;
        contexts = contextItem.getContext();
    }
    // 2 kinds of situation should be excluded before doing migration to the old context:
    // 1.has null, 2.all same comment values;
    // 1 is from 6.1.0 release and 5.6.2 patched TPS-1109, all null comment value will set to "".
    // for repository context in job, won't change anything because the repository context has been fixed
    // the update action will execute when opening job.
    boolean hasNull = false, isSame = true;
    if (contexts != null && contexts.size() > 1) {
        List<String> firstComments = new ArrayList<String>();
        for (int x = 0; x < contexts.size(); x++) {
            List<ContextParameterType> contextParams = contexts.get(x).getContextParameter();
            for (int y = 0; y < contextParams.size(); y++) {
                ContextParameterType param = contextParams.get(y);
                boolean isBuiltin = param.getRepositoryContextId() == null;
                String comment = param.getComment();
                if (comment == null) {
                    if (isBuiltin) {
                        //$NON-NLS-1$
                        param.setComment("");
                        hasNull = true;
                    }
                    continue;
                }
                // comments to show in old item before 5.6.1 are always in the first group.
                if (x == 0) {
                    if (!isBuiltin) {
                        //$NON-NLS-1$
                        firstComments.add("NOT_BUILTIN");
                    } else {
                        firstComments.add(comment);
                    }
                    continue;
                }
                if (isBuiltin && !comment.equals(firstComments.get(y))) {
                    isSame = false;
                }
            }
        }
        try {
            if (hasNull) {
                ProxyRepositoryFactory.getInstance().save(item, true);
                return ExecutionResult.SUCCESS_NO_ALERT;
            }
            if (!isSame) {
                for (int x = 1; x < contexts.size(); x++) {
                    List<ContextParameterType> contextParams = contexts.get(x).getContextParameter();
                    for (int y = 0; y < contextParams.size(); y++) {
                        ContextParameterType param = contextParams.get(y);
                        String comment = param.getComment();
                        if (param.getRepositoryContextId() == null && !firstComments.get(y).equals(comment)) {
                            if (!firstComments.get(y).equals("NOT_BUILTIN")) {
                                //$NON-NLS-1$
                                param.setComment(firstComments.get(y));
                            }
                        }
                    }
                }
                ProxyRepositoryFactory.getInstance().save(item, true);
                return ExecutionResult.SUCCESS_NO_ALERT;
            }
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ContextItem(org.talend.core.model.properties.ContextItem) ArrayList(java.util.ArrayList) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) PersistenceException(org.talend.commons.exception.PersistenceException) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 47 with ProcessItem

use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.

the class AddMomInputToComponentsListMigrationTask method getFirstMomInput.

private String getFirstMomInput(Item item) {
    // TODO Auto-generated method stub
    if (item instanceof ProcessItem) {
        ProcessType processType = ((ProcessItem) item).getProcess();
        for (Object o : processType.getNode()) {
            if (o instanceof NodeType) {
                NodeType currentNode = (NodeType) o;
                if ("tMomInput".equals(currentNode.getComponentName())) {
                    EList elements = currentNode.getElementParameter();
                    Iterator iterator = elements.iterator();
                    while (iterator.hasNext()) {
                        ElementParameterType elementParameter = (ElementParameterType) iterator.next();
                        if ("UNIQUE_NAME".equals(elementParameter.getName())) {
                            return elementParameter.getValue();
                        }
                    }
                }
            }
        }
    }
    return "";
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) EList(org.eclipse.emf.common.util.EList) ProcessItem(org.talend.core.model.properties.ProcessItem) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) Iterator(java.util.Iterator)

Example 48 with ProcessItem

use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.

the class RemoveDuplicatedContextGroupMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    List<?> contexts = null;
    if (item instanceof ProcessItem) {
        // process, process_mr, process_storm, route, routelet.
        ProcessItem processItem = (ProcessItem) item;
        contexts = processItem.getProcess().getContext();
    } else if (item instanceof JobletProcessItem) {
        JobletProcessItem jobletItem = (JobletProcessItem) item;
        contexts = jobletItem.getJobletProcess().getContext();
    }
    Set<String> nameSet = new HashSet<String>();
    Iterator<?> iterator = contexts.listIterator();
    int count = 0;
    while (iterator.hasNext()) {
        Object obj = iterator.next();
        if (obj instanceof ContextType) {
            ContextType context = (ContextType) obj;
            if (nameSet.contains(context.getName())) {
                iterator.remove();
                count++;
            } else {
                nameSet.add(context.getName());
            }
        }
    }
    if (count > 0) {
        try {
            ProxyRepositoryFactory.getInstance().save(item, true);
            return ExecutionResult.SUCCESS_NO_ALERT;
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    } else {
        return ExecutionResult.NOTHING_TO_DO;
    }
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) PersistenceException(org.talend.commons.exception.PersistenceException) HashSet(java.util.HashSet)

Example 49 with ProcessItem

use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.

the class BuildJobHandler method addDQDependencies.

private void addDQDependencies(IFolder parentFolder, List<Item> items) throws Exception {
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQItemService.class)) {
        ITDQItemService tdqItemService = (ITDQItemService) GlobalServiceRegister.getDefault().getService(ITDQItemService.class);
        for (Item item : items) {
            if (tdqItemService != null && tdqItemService.hasProcessItemDependencies(Arrays.asList(new Item[] { item }))) {
                setNeedItemDependencies(true);
                // add .Talend.definition file
                //$NON-NLS-1$
                String defIdxFolderName = "TDQ_Libraries";
                //$NON-NLS-1$
                String defIdxFileName = ".Talend.definition";
                Project pro = getProject(processItem);
                IFolder itemsProjectFolder = parentFolder.getFolder(pro.getTechnicalLabel().toLowerCase());
                File itemsFolderDir = new File(parentFolder.getLocation().toFile().getAbsolutePath());
                IProject project = ReponsitoryContextBridge.getRootProject();
                String defIdxRelativePath = defIdxFolderName + PATH_SEPARATOR + defIdxFileName;
                IFile defIdxFile = project.getFile(defIdxRelativePath);
                if (defIdxFile.exists()) {
                    File defIdxFileSource = new File(project.getLocation().makeAbsolute().append(defIdxFolderName).append(defIdxFileName).toFile().toURI());
                    File defIdxFileTarget = new File(itemsProjectFolder.getFile(defIdxRelativePath).getLocation().toFile().getAbsolutePath());
                    FilesUtils.copyFile(defIdxFileSource, defIdxFileTarget);
                }
                // add report header image & template files
                //$NON-NLS-1$
                String reportingBundlePath = PluginChecker.getBundlePath("org.talend.dataquality.reporting");
                //$NON-NLS-1$
                File imageFolder = new File(reportingBundlePath + PATH_SEPARATOR + "images");
                if (imageFolder.exists()) {
                    FilesUtils.copyDirectory(imageFolder, itemsFolderDir);
                }
                //$NON-NLS-1$ 
                File templateFolder = new File(reportingBundlePath + PATH_SEPARATOR + "reports");
                if (templateFolder.exists() && templateFolder.isDirectory()) {
                    FilesUtils.copyDirectory(templateFolder, itemsFolderDir);
                }
            }
        }
        // maven command 'include-survivorship-rules' to export.
        if (!isOptionChoosed(ExportChoice.needJobItem)) {
            ExportFileResource resouece = new ExportFileResource();
            BuildExportManager.getInstance().exportDependencies(resouece, processItem);
            if (!resouece.getAllResources().isEmpty()) {
                final Iterator<String> relativepath = resouece.getRelativePathList().iterator();
                //$NON-NLS-1$
                String pathStr = "metadata/survivorship";
                IFolder targetFolder = talendProcessJavaProject.getResourcesFolder();
                if (targetFolder.exists()) {
                    IFolder survFolder = targetFolder.getFolder(new Path(pathStr));
                    // only copy self job rules, clear the 'survivorship' folder before copy.
                    if (survFolder.exists()) {
                        survFolder.delete(true, null);
                    }
                    while (relativepath.hasNext()) {
                        String relativePath = relativepath.next();
                        Set<URL> sources = resouece.getResourcesByRelativePath(relativePath);
                        for (URL sourceUrl : sources) {
                            File currentResource = new File(org.talend.commons.utils.io.FilesUtils.getFileRealPath(sourceUrl.getPath()));
                            if (currentResource.exists()) {
                                FilesUtils.copyDirectory(currentResource, new File(targetFolder.getLocation().toPortableString() + File.separator + pathStr));
                            }
                        }
                    }
                }
            }
            parentFolder.refreshLocal(IResource.DEPTH_INFINITE, null);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IProject(org.eclipse.core.resources.IProject) URL(java.net.URL) Item(org.talend.core.model.properties.Item) ProcessItem(org.talend.core.model.properties.ProcessItem) Project(org.talend.core.model.properties.Project) IProject(org.eclipse.core.resources.IProject) ExportFileResource(org.talend.repository.documentation.ExportFileResource) IFile(org.eclipse.core.resources.IFile) File(java.io.File) ITDQItemService(org.talend.core.ITDQItemService) IFolder(org.eclipse.core.resources.IFolder)

Example 50 with ProcessItem

use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.

the class BuildJobHandler method generateTestReports.

@Override
public void generateTestReports(IProgressMonitor monitor) throws Exception {
    if (!isOptionChoosed(ExportChoice.includeTestSource)) {
        return;
    }
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
        ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
        if (testContainerService != null) {
            List<IFile> reports = new ArrayList<IFile>();
            List<ProcessItem> testsItems = testContainerService.getAllTestContainers(processItem);
            for (ProcessItem testItem : testsItems) {
                List<IFile> testReportFiles = testContainerService.getTestReportFiles(testItem);
                if (testReportFiles.size() > 0) {
                    reports.add(testReportFiles.get(0));
                }
            }
            IFolder testsFolder = talendProcessJavaProject.getTestsFolder();
            talendProcessJavaProject.cleanFolder(monitor, testsFolder);
            IFolder parentFolder = talendProcessJavaProject.createSubFolder(monitor, testsFolder, processItem.getProperty().getLabel());
            for (IFile report : reports) {
                report.copy(parentFolder.getFile(report.getName()).getFullPath(), true, monitor);
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ProcessItem(org.talend.core.model.properties.ProcessItem) ArrayList(java.util.ArrayList) ITestContainerProviderService(org.talend.core.ui.ITestContainerProviderService) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

ProcessItem (org.talend.core.model.properties.ProcessItem)160 PersistenceException (org.talend.commons.exception.PersistenceException)49 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)49 ArrayList (java.util.ArrayList)44 Item (org.talend.core.model.properties.Item)40 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)37 Property (org.talend.core.model.properties.Property)30 IProcess2 (org.talend.core.model.process.IProcess2)24 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)24 IProcess (org.talend.core.model.process.IProcess)23 File (java.io.File)22 IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)21 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)21 ExportFileResource (org.talend.repository.documentation.ExportFileResource)21 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)21 IOException (java.io.IOException)20 INode (org.talend.core.model.process.INode)20 List (java.util.List)19 EList (org.eclipse.emf.common.util.EList)19 ProcessorException (org.talend.designer.runprocess.ProcessorException)17