Search in sources :

Example 11 with ProcessItem

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

the class HTMLDocGenerator method generateContextInfo.

/**
     * DOC YeXiaowei Comment method "generateContextInfo".
     * 
     * @return
     */
private void generateContextInfo(final Item item, final Element element) {
    EList contexts = null;
    if (item instanceof ProcessItem) {
        contexts = ((ProcessItem) item).getProcess().getContext();
    } else if (item instanceof JobletProcessItem) {
        contexts = ((JobletProcessItem) item).getJobletProcess().getContext();
    }
    if (contexts == null || contexts.isEmpty()) {
        return;
    }
    // Context root //$NON-NLS-1$
    Element contextListElement = DocumentHelper.createElement("contextList");
    for (int i = 0, n = contexts.size(); i < n; i++) {
        // export single context infomation
        //$NON-NLS-1$
        Element contextElement = DocumentHelper.createElement("context");
        ContextType context = (ContextType) contexts.get(i);
        // Attributes
        //$NON-NLS-1$
        contextElement.addAttribute("name", HTMLDocUtils.checkString(context.getName()));
        IProxyRepositoryFactory repositoryFactory = CorePlugin.getDefault().getProxyRepositoryFactory();
        // Context parameters as children
        EList params = context.getContextParameter();
        if (params != null && !params.isEmpty()) {
            for (int j = 0, k = params.size(); j < k; j++) {
                /*
                     * <contextParameter comment="Give server name" name="server" prompt="Default Server "
                     * promptNeeded="false" repositoryContextId="_crJMkCCQEd2Oweh7yRMWjQ" type=""
                     * value="'192.168.0.109'"/>
                     */
                ContextParameterType param = (ContextParameterType) params.get(j);
                //$NON-NLS-1$
                Element contextParamElement = DocumentHelper.createElement("contextParameter");
                //$NON-NLS-1$
                contextParamElement.addAttribute("name", HTMLDocUtils.checkString(param.getName()));
                //$NON-NLS-1$
                contextParamElement.addAttribute("prompt", HTMLDocUtils.checkString(param.getPrompt()));
                contextParamElement.addAttribute("promptNeeded", HTMLDocUtils.checkString(Boolean.toString(//$NON-NLS-1$
                param.isPromptNeeded())));
                //$NON-NLS-1$
                contextParamElement.addAttribute("type", HTMLDocUtils.checkString(param.getType()));
                //$NON-NLS-1$ 
                contextParamElement.addAttribute("value", ParameterValueUtil.getValue4Doc(param));
                // replace repository id with context label
                if (param.getRepositoryContextId() != null) {
                    ContextItem contextItem = ContextUtils.getContextItemById2(param.getRepositoryContextId());
                    if (contextItem != null) {
                        // bug 5978: repository link to context item might be lost.
                        String label = contextItem.getProperty().getLabel();
                        //$NON-NLS-1$
                        contextParamElement.addAttribute("source", HTMLDocUtils.checkString(label));
                    }
                }
                contextElement.add(contextParamElement);
            }
        }
        contextListElement.add(contextElement);
    }
    element.add(contextListElement);
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ContextItem(org.talend.core.model.properties.ContextItem) EList(org.eclipse.emf.common.util.EList) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) Element(org.dom4j.Element) Point(org.eclipse.draw2d.geometry.Point) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 12 with ProcessItem

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

the class HTMLDocGenerator method handleXMLFile.

/**
     * Generates the xml file base on an instance of <code>ExportFileResource</code> and the temporary folder path.
     * 
     * @param resource
     * @param tempFolderPath
     * @param version
     */
private void handleXMLFile(ExportFileResource resource, String tempFolderPath, String... version) throws Exception {
    Item item = resource.getItem();
    // Check if generate Job Extra / Stats&Logs Setting Info
    if (item instanceof ProcessItem) {
        if (GlobalServiceRegister.getDefault().isServiceRegistered(IMRProcessService.class)) {
            IMRProcessService mrProcessService = (IMRProcessService) GlobalServiceRegister.getDefault().getService(IMRProcessService.class);
            generateExtraSetting = !mrProcessService.isMapReduceItem(item);
            generateStatsLogsSetting = generateExtraSetting;
        } else if (isRouteProcess(item)) {
            generateStatsLogsSetting = generateExtraSetting = !isRouteProcess(item);
        }
    } else if (item instanceof JobletProcessItem) {
        generateStatsLogsSetting = false;
    }
    targetConnectionMap = new HashMap<String, List>();
    sourceConnectionMap = new HashMap<String, List>();
    getSourceAndTargetConnection(item);
    Document document = DocumentHelper.createDocument();
    Element projectElement = generateProjectInfo(document);
    Element jobElement = generateJobInfo(item, projectElement, version);
    // This two element see feature 4162
    generateContextInfo(item, jobElement);
    generateJobSettingInfo(item, jobElement);
    List<List> allList = seperateNodes(item);
    if (allList == null || allList.size() != 3) {
        return;
    }
    List<INode> allComponentsList = allList.get(0);
    List<INode> internalNodeComponentsList = allList.get(1);
    List<INode> externalNodeComponentsList = allList.get(2);
    if (allComponentsList.size() > 0) {
        // Generates information for 'Component List' part in exported HTML file.
        generateAllComponentsSummaryInfo(item, jobElement, allComponentsList);
    }
    //$NON-NLS-1$
    Element internalNodeElement = jobElement.addElement("internalNodeComponents");
    //$NON-NLS-1$
    Element externalNodeElement = jobElement.addElement("externalNodeComponents");
    if (internalNodeComponentsList.size() > 0) {
        InternalNodeComponentHandler internalNodeComponentHandler = new InternalNodeComponentHandler(this.picFilePathMap, internalNodeElement, internalNodeComponentsList, this.sourceConnectionMap, this.targetConnectionMap, this.designerCoreService, this.repositoryConnectionItemMap, this.repositoryDBIdAndNameMap, externalNodeHTMLMap);
        // Generates internal node components information.
        internalNodeComponentHandler.generateComponentInfo();
    }
    if (externalNodeComponentsList.size() > 0) {
        ExternalNodeComponentHandler externalNodeComponentHandler = new ExternalNodeComponentHandler(this.picFilePathMap, externalNodeElement, externalNodeComponentsList, this.sourceConnectionMap, this.targetConnectionMap, this.designerCoreService, this.repositoryConnectionItemMap, this.repositoryDBIdAndNameMap, externalNodeHTMLMap);
        // Generates external node components(tMap etc.) information.
        externalNodeComponentHandler.generateComponentInfo();
    }
    // Generates all connection information(include internal node and external node).
    EList connectionList = null;
    if (item instanceof ProcessItem) {
        connectionList = ((ProcessItem) item).getProcess().getConnection();
    } else if (item instanceof JobletProcessItem) {
        connectionList = (((JobletProcessItem) item).getJobletProcess().getConnection());
    }
    if (connectionList != null && connectionList.size() != 0) {
        generateConnectionsInfo(jobElement, connectionList);
    }
    //$NON-NLS-1$
    String versionPath = "_";
    if (version != null && version.length == 1) {
        versionPath = versionPath + version[0];
    } else {
        versionPath = versionPath + item.getProperty().getVersion();
    }
    String filePath = tempFolderPath + File.separatorChar + item.getProperty().getLabel() + versionPath + IHTMLDocConstants.XML_FILE_SUFFIX;
    // This element see feature 4382
    if (item instanceof ProcessItem) {
        generateSourceCodeInfo((ProcessItem) item, jobElement);
    }
    XMLHandler.generateXMLFile(tempFolderPath, filePath, document);
}
Also used : INode(org.talend.core.model.process.INode) InternalNodeComponentHandler(org.talend.core.ui.documentation.generation.InternalNodeComponentHandler) IMRProcessService(org.talend.core.service.IMRProcessService) Element(org.dom4j.Element) Document(org.dom4j.Document) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) EList(org.eclipse.emf.common.util.EList) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ExternalNodeComponentHandler(org.talend.core.ui.documentation.generation.ExternalNodeComponentHandler) 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)

Example 13 with ProcessItem

use of org.talend.core.model.properties.ProcessItem 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 14 with ProcessItem

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

the class GenerateDocAsHTMLWizardPage method addTreeNode.

private void addTreeNode(RepositoryNode node, String path, List<ExportFileResource> list) {
    if (node != null && node.getType() == ENodeType.REPOSITORY_ELEMENT) {
        IRepositoryViewObject repositoryObject = node.getObject();
        if (repositoryObject.getProperty().getItem() instanceof ProcessItem) {
            ProcessItem processItem = (ProcessItem) repositoryObject.getProperty().getItem();
            ExportFileResource resource = new ExportFileResource(processItem, path);
            resource.setNode(node);
            list.add(resource);
        }
    }
    Object[] nodes = node.getChildren().toArray();
    if (nodes.length <= 0) {
        return;
    }
    for (Object node2 : nodes) {
        addTreeNode((RepositoryNode) node2, //$NON-NLS-1$
        path + "/" + ((RepositoryNode) node2).getProperties(EProperties.LABEL).toString(), list);
    }
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) ExportFileResource(org.talend.repository.documentation.ExportFileResource) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 15 with ProcessItem

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

the class TalendImportUtil method openJobs.

private static void openJobs(List<IRepositoryNode> nodes) {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    for (IRepositoryNode node : nodes) {
        Property property = node.getObject().getProperty();
        if (property != null) {
            Item item = property.getItem();
            if (!(item instanceof ProcessItem)) {
                continue;
            }
            try {
                ProcessItem processItem = (ProcessItem) item;
                final JobEditorInput fileEditorInput = getEditorInput(processItem);
                // checkUnLoadedNodeForProcess(fileEditorInput);
                final IEditorPart editorPart = page.findEditor(fileEditorInput);
                if (editorPart == null) {
                    fileEditorInput.setRepositoryNode(node);
                    page.openEditor(fileEditorInput, getEditorId(), true);
                } else {
                    ((AbstractMultiPageTalendEditor) editorPart).setReadOnly(fileEditorInput.setForceReadOnly(false));
                    page.activate(editorPart);
                }
            } catch (Throwable e) {
                CommonExceptionHandler.process(e);
            }
        }
    }
}
Also used : JobEditorInput(org.talend.core.ui.editor.JobEditorInput) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) ImportItem(org.talend.repository.items.importexport.handlers.model.ImportItem) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ProcessItem(org.talend.core.model.properties.ProcessItem) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) Property(org.talend.core.model.properties.Property)

Aggregations

ProcessItem (org.talend.core.model.properties.ProcessItem)191 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)58 PersistenceException (org.talend.commons.exception.PersistenceException)56 ArrayList (java.util.ArrayList)45 Item (org.talend.core.model.properties.Item)43 Property (org.talend.core.model.properties.Property)43 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)37 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)29 IProcess2 (org.talend.core.model.process.IProcess2)25 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)25 IProcess (org.talend.core.model.process.IProcess)24 ExportFileResource (org.talend.repository.documentation.ExportFileResource)24 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)24 File (java.io.File)23 INode (org.talend.core.model.process.INode)23 IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)22 IOException (java.io.IOException)21 IFile (org.eclipse.core.resources.IFile)20 List (java.util.List)19 EList (org.eclipse.emf.common.util.EList)19