Search in sources :

Example 1 with NodeType

use of org.talend.designer.core.model.utils.emf.talendfile.NodeType 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);
            }
        }
    }
}
Also used : RootPaletteItem(org.talend.repository.preference.palettesettings.RootPaletteItem) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) IPaletteItem(org.talend.core.ui.component.preference.provider.IPaletteItem) ComponentPaletteItem(org.talend.repository.preference.palettesettings.ComponentPaletteItem) FolderPaletteItem(org.talend.repository.preference.palettesettings.FolderPaletteItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) IComponent(org.talend.core.model.components.IComponent) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) List(java.util.List) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 2 with NodeType

use of org.talend.designer.core.model.utils.emf.talendfile.NodeType in project tdi-studio-se by Talend.

the class OpenExistVersionProcessAction method checkUnLoadedNodeForProcess.

private void checkUnLoadedNodeForProcess(JobEditorInput fileEditorInput) {
    if (fileEditorInput == null || fileEditorInput.getLoadedProcess() == null) {
        return;
    }
    IProcess2 loadedProcess = fileEditorInput.getLoadedProcess();
    List<NodeType> unloadedNode = loadedProcess.getUnloadedNode();
    if (unloadedNode != null && !unloadedNode.isEmpty()) {
        String message = "Some Component are not loaded:\n";
        for (int i = 0; i < unloadedNode.size(); i++) {
            message = message + unloadedNode.get(i).getComponentName() + "\n";
        }
        if (!CommonsPlugin.isHeadless() && PlatformUI.isWorkbenchRunning()) {
            Display display = Display.getCurrent();
            if (display == null) {
                display = Display.getDefault();
            }
            if (display != null) {
                final Display tmpDis = display;
                final String tmpMess = message;
                display.syncExec(new Runnable() {

                    @Override
                    public void run() {
                        Shell shell = null;
                        final IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                        if (activeWorkbenchWindow != null) {
                            shell = activeWorkbenchWindow.getShell();
                        } else {
                            if (tmpDis != null) {
                                shell = tmpDis.getActiveShell();
                            } else {
                                shell = new Shell();
                            }
                        }
                        MessageDialog.openWarning(shell, "Warning", tmpMess);
                    }
                });
            }
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Shell(org.eclipse.swt.widgets.Shell) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IProcess2(org.talend.core.model.process.IProcess2) Display(org.eclipse.swt.widgets.Display)

Example 3 with NodeType

use of org.talend.designer.core.model.utils.emf.talendfile.NodeType in project tdi-studio-se by Talend.

the class HTMLDocGenerator method generateDocumentation.

/*
     * This method is used for generating HTML file base on an instance of <code>ExportFileResource</code> (non-Javadoc)
     * 
     * @see
     * org.talend.repository.documentation.generation.IDocumentationGenerator#generateDocumentation(org.talend.repository
     * .documentation.ExportFileResource, java.lang.String, java.lang.String[])
     */
@Override
public void generateDocumentation(ExportFileResource resource, String targetPath, String... jobVersion) throws Exception {
    // Store all pictures' path.
    List<URL> picList = new ArrayList<URL>(5);
    String jobName = resource.getItem().getProperty().getLabel();
    String jobPath = resource.getItem().getProperty().getItem().getState().getPath();
    // Used for generating/updating all jobs' documentaiton only.
    String typePath = new Path(this.repositoryObjectType.getFolder()).lastSegment();
    if (jobName != null && !(jobName).equals(typePath.toLowerCase()) && targetPath.endsWith(typePath.toLowerCase())) {
        targetPath = targetPath + IPath.SEPARATOR + jobPath + IPath.SEPARATOR + jobName;
    }
    //$NON-NLS-1$
    String version = "";
    // Checks if the job's version is specified, see it on "Export documentation" Dialog:
    if (jobVersion != null && jobVersion.length == 1) {
        version = jobVersion[0];
    } else {
        version = resource.getItem().getProperty().getVersion();
    }
    //$NON-NLS-1$
    targetPath = targetPath + "_" + version;
    File file = new File(targetPath);
    // Delete if folde is existing.
    if (file.exists()) {
        FilesUtils.removeFolder(file, true);
    }
    file.mkdirs();
    handleXMLFile(resource, targetPath, jobVersion);
    String picFolderPath = checkPicDirIsExists(resource, targetPath);
    // Gets the "org.talend.repository" plug-in:
    //$NON-NLS-1$
    final Bundle b = Platform.getBundle("org.talend.repository");
    final URL xslFileUrl = FileLocator.toFileURL(FileLocator.find(b, new Path(IHTMLDocConstants.MAIN_XSL_FILE_PATH), null));
    // final URL logoFileUrl = FileLocator.toFileURL(FileLocator.find(b,
    // new Path(IHTMLDocConstants.LOGO_FILE_PATH), null));
    File logoFile = new File(picFolderPath + File.separatorChar + IHTMLDocConstants.TALEND_LOGO_FILE_NAME);
    saveLogoImage(SWT.IMAGE_JPEG, logoFile);
    String xslFilePath = xslFileUrl.getPath();
    // String logoFilePath = logoFileUrl.getPath();
    // FileCopyUtils.copy(logoFilePath, picFolderPath + File.separatorChar
    // + IHTMLDocConstants.TALEND_LOGO_FILE_NAME);
    // if set css file in preference.
    boolean isCheck = CorePlugin.getDefault().getPreferenceStore().getBoolean(ITalendCorePrefConstants.USE_CSS_TEMPLATE);
    String cssFile = CorePlugin.getDefault().getPreferenceStore().getString(ITalendCorePrefConstants.CSS_FILE_PATH);
    String temXslPath = null;
    if (isCheck && cssFile != null && !cssFile.equals("")) {
        //$NON-NLS-1$
        String tempFolderPath = checkTempDirIsExists(resource);
        temXslPath = tempFolderPath + File.separator + (new File(xslFilePath)).getName();
        File temXslFile = new File(temXslPath);
        if (temXslFile.exists()) {
            temXslFile.delete();
        }
        generateXslFile(xslFilePath, temXslPath, cssFile, null);
    }
    // if no new xls generated, use default xsl
    if (temXslPath != null) {
        File temFile = new File(temXslPath);
        if (!temFile.exists()) {
            temXslPath = xslFilePath;
        }
    } else {
        temXslPath = xslFilePath;
    }
    picList.add(logoFile.toURL());
    // Property property = item.getProperty();
    // String jobName = property.getLabel();
    // String jobVersion = property.getVersion();
    byte[] innerContent = null;
    ProcessType processType = null;
    if (resource.getItem() instanceof ProcessItem) {
        processType = ((ProcessItem) resource.getItem()).getProcess();
        //$NON-NLS-1$
        innerContent = (byte[]) processType.getScreenshots().get("process");
    } else if (resource.getItem() instanceof JobletProcessItem) {
        processType = ((JobletProcessItem) resource.getItem()).getJobletProcess();
        //$NON-NLS-1$
        innerContent = (byte[]) processType.getScreenshots().get("process");
        ;
    }
    if (innerContent != null) {
        //$NON-NLS-1$
        String picName = jobName + "_" + version + IHTMLDocConstants.JOB_PREVIEW_PIC_SUFFIX;
        ImageUtils.save(innerContent, picFolderPath + File.separatorChar + picName, SWT.IMAGE_PNG);
        picList.add(new File(picFolderPath + File.separatorChar + picName).toURL());
        // need to generate another pic for pdf
        ByteArrayInputStream bais = new ByteArrayInputStream(innerContent);
        Image pdfImage = new Image(null, bais);
        int width = pdfImage.getImageData().width;
        int percent = 22 * 32 * 100 / width;
        //$NON-NLS-1$
        ImageUtils.save(//$NON-NLS-1$
        ImageUtils.scale(pdfImage, percent), //$NON-NLS-1$
        picFolderPath + File.separatorChar + "pdf_" + picName, SWT.IMAGE_PNG);
        //$NON-NLS-1$
        picList.add(new File(picFolderPath + File.separatorChar + "pdf_" + picName).toURL());
        pdfImage.dispose();
    }
    if (processType != null) {
        for (NodeType node : (List<NodeType>) processType.getNode()) {
            //$NON-NLS-1$
            String uniqueName = "";
            for (Object o : node.getElementParameter()) {
                if (o instanceof ElementParameterType) {
                    if ("UNIQUE_NAME".equals(((ElementParameterType) o).getName())) {
                        //$NON-NLS-1$
                        uniqueName = ((ElementParameterType) o).getValue();
                        break;
                    }
                }
            }
            byte[] screenshot = (byte[]) processType.getScreenshots().get(uniqueName);
            if (screenshot != null && screenshot.length != 0) {
                String picName = IHTMLDocConstants.EXTERNAL_NODE_PREVIEW + uniqueName + IHTMLDocConstants.JOB_PREVIEW_PIC_SUFFIX;
                ImageUtils.save(screenshot, picFolderPath + File.separatorChar + picName, SWT.IMAGE_PNG);
                picList.add(new File(picFolderPath + File.separatorChar + picName).toURL());
                // need to generate externalNode pic for pdf
                ByteArrayInputStream bais = new ByteArrayInputStream(screenshot);
                Image pdfImage = new Image(null, bais);
                int width = pdfImage.getImageData().width;
                int percent = 22 * 32 * 100 / width;
                //$NON-NLS-1$
                ImageUtils.save(//$NON-NLS-1$
                ImageUtils.scale(pdfImage, percent), //$NON-NLS-1$
                picFolderPath + File.separatorChar + "pdf_" + picName, SWT.IMAGE_PNG);
                picList.add(new File(picFolderPath + File.separatorChar + picName).toURL());
                pdfImage.dispose();
            }
        }
    }
    Set keySet = picFilePathMap.keySet();
    for (Object key : keySet) {
        String value = picFilePathMap.get(key);
        FileCopyUtils.copy(value, picFolderPath + File.separatorChar + key);
        picList.add(new File(picFolderPath + File.separatorChar + key).toURL());
    }
    //$NON-NLS-1$
    List<URL> resultFiles = parseXml2HtmlPdf(targetPath, jobName + "_" + version, temXslPath);
    resource.addResources(resultFiles);
    resource.addResources(IHTMLDocConstants.PIC_FOLDER_NAME, picList);
    HTMLDocUtils.deleteTempFiles();
    // List<URL> externalList = getExternalHtmlPath();
    // resource.addResources(IHTMLDocConstants.EXTERNAL_FOLDER_NAME, externalList);
    targetConnectionMap = null;
    sourceConnectionMap = null;
}
Also used : Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) Set(java.util.Set) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) URL(java.net.URL) Point(org.eclipse.draw2d.geometry.Point) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ByteArrayInputStream(java.io.ByteArrayInputStream) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) CSSRuleList(org.w3c.dom.css.CSSRuleList) ArrayList(java.util.ArrayList) List(java.util.List) NodeList(org.w3c.dom.NodeList) EList(org.eclipse.emf.common.util.EList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 4 with NodeType

use of org.talend.designer.core.model.utils.emf.talendfile.NodeType in project tdi-studio-se by Talend.

the class ActivateQueryLogging method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    List<String> filterList = Arrays.asList("tELTTeradataMap", "tTeradataConnection", "tTeradataInput", "tTeradataOutput", "tTeradataRow");
    IComponentConversion correctBatchModeForDBComponents = new IComponentConversion() {

        public void transform(NodeType node) {
            ElementParameterType queryBand = ComponentUtilities.getNodeProperty(node, "QUERY_BAND");
            ElementParameterType activateQueryLogging = ComponentUtilities.getNodeProperty(node, "ACTIVATE_QUERY_LOGGING");
            if (activateQueryLogging == null) {
                ComponentUtilities.addNodeProperty(node, "ACTIVATE_QUERY_LOGGING", "CHECK");
                if (queryBand != null) {
                    boolean queryBandActived = "true".equalsIgnoreCase(queryBand.getValue());
                    if (queryBandActived) {
                        ComponentUtilities.getNodeProperty(node, "ACTIVATE_QUERY_LOGGING").setValue("true");
                    }
                }
            }
        }
    };
    for (String componentName : filterList) {
        IComponentFilter filter = new NameComponentFilter(componentName);
        try {
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(correctBatchModeForDBComponents));
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) PersistenceException(org.talend.commons.exception.PersistenceException) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 5 with NodeType

use of org.talend.designer.core.model.utils.emf.talendfile.NodeType in project tdi-studio-se by Talend.

the class AddNewIgnoreNullSettingForTMicrosoftCrmOutputTask method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    String componentName = "tMicrosoftCrmOutput";
    try {
        IComponentFilter filter = new NameComponentFilter(componentName);
        ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(new IComponentConversion() {

            @Override
            public void transform(NodeType node) {
                if (ComponentUtilities.getNodeProperty(node, "IGNORE_NULL") == null && ComponentUtilities.getNodeProperty(node, "MS_CRM_VERSION") == null) {
                    ComponentUtilities.addNodeProperty(node, "IGNORE_NULL", "CHECK");
                    ComponentUtilities.getNodeProperty(node, "IGNORE_NULL").setValue("true");
                }
            }
        }));
        return ExecutionResult.SUCCESS_NO_ALERT;
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Aggregations

NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)198 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)157 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)127 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)112 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)111 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)110 PersistenceException (org.talend.commons.exception.PersistenceException)93 ProcessItem (org.talend.core.model.properties.ProcessItem)25 ArrayList (java.util.ArrayList)24 EList (org.eclipse.emf.common.util.EList)23 ElementValueType (org.talend.designer.core.model.utils.emf.talendfile.ElementValueType)21 List (java.util.List)20 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)19 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)18 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)13 MetadataType (org.talend.designer.core.model.utils.emf.talendfile.MetadataType)13 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)13 IComponent (org.talend.core.model.components.IComponent)10 ColumnType (org.talend.designer.core.model.utils.emf.talendfile.ColumnType)9 Property (org.talend.core.model.properties.Property)8