Search in sources :

Example 6 with JobletProcessItem

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

the class ComponentChooseDialog method createNewComponent.

public void createNewComponent(DropTargetEvent event1) {
    boolean quickCreateInput = event1.detail == DND.DROP_LINK;
    boolean quickCreateOutput = event1.detail == DND.DROP_COPY;
    Iterator iterator = getSelection().iterator();
    List<TempStore> list = new ArrayList<TempStore>();
    List<IComponent> components = new ArrayList<IComponent>();
    while (iterator.hasNext()) {
        Object obj = iterator.next();
        if (obj instanceof RepositoryNode) {
            RepositoryNode sourceNode = (RepositoryNode) obj;
            if (equalsJobInCurrentEditor(sourceNode)) {
                continue;
            }
            Item item = sourceNode.getObject().getProperty().getItem();
            if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
                ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
                if (testContainerService != null && testContainerService.isTestContainerItem(item)) {
                    continue;
                }
            }
            ERepositoryObjectType type = sourceNode.getObjectType();
            if (!(item instanceof ConnectionItem) && !(item instanceof ProcessItem) && !(item instanceof JobletProcessItem) && !(item instanceof RulesItem) && !(item instanceof LinkRulesItem)) {
                // RulesItem
                return;
            }
            {
            /**
                     * Remove this limitation for feature: TDI-32362, I think it should be ok, don't know why adding
                     * this limitation to forbid to d&d salseforce connection, I keep those code in case this behavior
                     * will cause some bugs when d&d salseforce connection, then maybe need to review
                     */
            // if (item instanceof SalesforceSchemaConnectionItem && type ==
            // ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA) {
            // return;
            // }
            }
            TempStore store = new TempStore();
            store.seletetedNode = sourceNode;
            getAppropriateComponent(item, quickCreateInput, quickCreateOutput, store, type);
            if (store.component != null) {
                list.add(store);
            } else {
                MessageDialog.openInformation(editor.getEditorSite().getShell(), //$NON-NLS-1$
                Messages.getString("TalendEditorDropTargetListener.dngsupportdialog.title"), //$NON-NLS-1$
                Messages.getString("TalendEditorDropTargetListener.dngsupportdialog.content"));
            }
        }
        org.eclipse.swt.graphics.Point swtLocation = new org.eclipse.swt.graphics.Point(event1.x, event1.y);
        Canvas canvas = (Canvas) editor.getViewer().getControl();
        /*
             * translate to Canvas coordinate
             */
        swtLocation = canvas.toControl(swtLocation);
        org.eclipse.swt.graphics.Point size = canvas.getSize();
        /*
             * translate to Viewport coordinate with zoom
             */
        org.eclipse.draw2d.geometry.Point draw2dPosition = new org.eclipse.draw2d.geometry.Point(swtLocation.x, swtLocation.y);
        /*
             * calcule the view port position. Take into acounte the scroll position
             */
        ProcessPart part = (ProcessPart) editor.getViewer().getRootEditPart().getRoot().getChildren().get(0);
        IFigure targetFigure = part.getFigure();
        translateAbsolateToRelative(targetFigure, draw2dPosition);
        //$NON-NLS-1$
        String lastUniqname = "";
        // creates every node
        for (TempStore store : list) {
            RepositoryNode selectedNode = store.seletetedNode;
            IComponent element = store.component;
            if (!components.contains(element)) {
                components.add(element);
            }
            Node node = new Node(element);
            // for bug4564(metadata label format)
            // IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
            // if (preferenceStore.getBoolean(TalendDesignerPrefConstants.USE_REPOSITORY_NAME)) {
            // node.setPropertyValue(EParameterName.LABEL.getName(), selectedNode.getObject().getLabel());
            // }
            IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
            if (preferenceStore.getBoolean(TalendDesignerPrefConstants.USE_REPOSITORY_NAME)) {
                String LabelValue = null;
                RepositoryNode repositoryNode = null;
                repositoryNode = (RepositoryNode) getSelection().getFirstElement();
                // dnd a table
                IElementParameter dbTableParam = node.getElementParameterFromField(EParameterFieldType.DBTABLE);
                boolean hasDbTableField = dbTableParam != null;
                if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_TABLE && repositoryNode.getObject() != null && repositoryNode.getObject().getProperty().getItem() instanceof DatabaseConnectionItem && hasDbTableField) {
                    LabelValue = DesignerUtilities.getParameterVar(dbTableParam.getName());
                } else if (repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS || repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS_MR || repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS_STORM) {
                    // dnd a job
                    LabelValue = DesignerUtilities.getParameterVar(EParameterName.PROCESS);
                } else if (repositoryNode.getObjectType() == ERepositoryObjectType.JOBLET || repositoryNode.getObjectType() == ERepositoryObjectType.SPARK_JOBLET || repositoryNode.getObjectType() == ERepositoryObjectType.SPARK_STREAMING_JOBLET) {
                    LabelValue = element.getName();
                } else if (CorePlugin.getDefault().getDesignerCoreService().getPreferenceStore(TalendDesignerPrefConstants.DEFAULT_LABEL).equals(node.getPropertyValue(EParameterName.LABEL.getName()))) {
                    // dnd a default
                    LabelValue = selectedNode.getObject().getLabel();
                }
                if (LabelValue != null) {
                    node.setPropertyValue(EParameterName.LABEL.getName(), LabelValue);
                }
            }
            processSpecificDBTypeIfSameProduct(store.componentName, node);
            NodeContainer nc = ((Process) node.getProcess()).loadNodeContainer(node, false);
            ;
            // create component on link
            boolean executed = false;
            if (getSelection().size() == 1 && getTargetEditPart() instanceof SubjobContainerPart) {
                executed = createComponentOnLink(node, draw2dPosition);
            }
            if (!executed) {
                // create the node on the design sheet
                execCommandStack(new CreateNodeContainerCommand((Process) editor.getProcess(), nc, draw2dPosition));
            }
            // initialize the propertiesView
            CompoundCommand cc = new CompoundCommand();
            createRefreshingPropertiesCommand(cc, selectedNode, node);
            execCommandStack(cc);
            // for (Command command : commands) {
            // }
            propaHadoopCfgChanges(selectedNode);
            draw2dPosition = draw2dPosition.getCopy();
            draw2dPosition.x += TalendEditor.GRID_SIZE;
            draw2dPosition.y += TalendEditor.GRID_SIZE;
            node.checkNode();
            lastUniqname = node.getUniqueName();
        }
    // setselecte(part, lastUniqname);
    }
// Shell shell = Display.getCurrent().getActiveShell();
// ModulesInstallerUtil.installModules(new Shell(shell), components);
}
Also used : IComponent(org.talend.core.model.components.IComponent) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EbcdicConnectionItem(org.talend.core.model.properties.EbcdicConnectionItem) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) HL7FileNode(org.talend.core.model.metadata.builder.connection.HL7FileNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) XMLFileNode(org.talend.core.model.metadata.builder.connection.XMLFileNode) MapperExternalNode(org.talend.core.model.process.node.MapperExternalNode) ArrayList(java.util.ArrayList) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) IProcess(org.talend.core.model.process.IProcess) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) RulesItem(org.talend.core.model.properties.RulesItem) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EbcdicConnectionItem(org.talend.core.model.properties.EbcdicConnectionItem) RulesItem(org.talend.core.model.properties.RulesItem) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) FileItem(org.talend.core.model.properties.FileItem) CreateNodeContainerCommand(org.talend.designer.core.ui.editor.cmd.CreateNodeContainerCommand) Iterator(java.util.Iterator) IElementParameter(org.talend.core.model.process.IElementParameter) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IFigure(org.eclipse.draw2d.IFigure) Point(org.eclipse.draw2d.geometry.Point) Canvas(org.eclipse.swt.widgets.Canvas) Point(org.eclipse.draw2d.geometry.Point) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ITestContainerProviderService(org.talend.core.ui.ITestContainerProviderService) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) SAPFunctionRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPFunctionRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) SalesforceModuleRepositoryObject(org.talend.core.repository.model.repositoryObject.SalesforceModuleRepositoryObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) SAPIDocRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPIDocRepositoryObject) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 7 with JobletProcessItem

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

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

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

use of org.talend.core.model.properties.JobletProcessItem 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)

Aggregations

JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)40 ProcessItem (org.talend.core.model.properties.ProcessItem)30 Item (org.talend.core.model.properties.Item)21 PersistenceException (org.talend.commons.exception.PersistenceException)18 ArrayList (java.util.ArrayList)17 IProcess2 (org.talend.core.model.process.IProcess2)13 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)12 List (java.util.List)11 EList (org.eclipse.emf.common.util.EList)11 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)10 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)9 INode (org.talend.core.model.process.INode)8 ContextItem (org.talend.core.model.properties.ContextItem)8 Point (org.eclipse.draw2d.geometry.Point)7 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)7 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 JobletProcess (org.talend.designer.joblet.model.JobletProcess)6 IOException (java.io.IOException)5 CoreException (org.eclipse.core.runtime.CoreException)5