Search in sources :

Example 1 with ProcessType

use of org.talend.designer.core.model.utils.emf.talendfile.ProcessType 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 ProcessType

use of org.talend.designer.core.model.utils.emf.talendfile.ProcessType 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 3 with ProcessType

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

the class AddConnectorNameInConnections method addConnectorName.

/**
     * DOC nrousseau Comment method "addConnectorName".
     * 
     * @param item
     * @return
     */
private boolean addConnectorName(Item item) throws PersistenceException {
    ProcessType processType = getProcessType(item);
    if (processType == null) {
        return false;
    }
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean modified = false;
    for (Object o : processType.getConnection()) {
        ConnectionType currentConnection = (ConnectionType) o;
        if (currentConnection.getConnectorName() == null) {
            EConnectionType connectionType = EConnectionType.getTypeFromId(currentConnection.getLineStyle());
            currentConnection.setConnectorName(connectionType.getName());
            modified = true;
        }
    }
    if (modified) {
        factory.save(item, true);
    }
    return modified;
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) EConnectionType(org.talend.core.model.process.EConnectionType) EConnectionType(org.talend.core.model.process.EConnectionType)

Example 4 with ProcessType

use of org.talend.designer.core.model.utils.emf.talendfile.ProcessType 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 ProcessType

use of org.talend.designer.core.model.utils.emf.talendfile.ProcessType 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

ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)244 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)157 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)155 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)153 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)145 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)115 PersistenceException (org.talend.commons.exception.PersistenceException)109 ProcessItem (org.talend.core.model.properties.ProcessItem)29 ArrayList (java.util.ArrayList)24 EList (org.eclipse.emf.common.util.EList)23 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)22 List (java.util.List)18 ElementValueType (org.talend.designer.core.model.utils.emf.talendfile.ElementValueType)16 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)14 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)14 RenameComponentConversion (org.talend.core.model.components.conversions.RenameComponentConversion)12 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)12 ParametersType (org.talend.designer.core.model.utils.emf.talendfile.ParametersType)12 HashMap (java.util.HashMap)10 IComponent (org.talend.core.model.components.IComponent)10