Search in sources :

Example 1 with ITDQItemService

use of org.talend.core.ITDQItemService in project tdi-studio-se by Talend.

the class GenerateGrammarController method generateJavaFile.

/**
     * Generate java source file
     * 
     * DOC ytao Comment method "generateJavaFile".
     */
private void generateJavaFile() {
    Node node = (Node) elem;
    final String JOB_NAME = node.getProcess().getName().toLowerCase();
    final String COMPONENT_NAME = node.getUniqueName().toLowerCase();
    String javaClassName = StringUtils.capitalize(JOB_NAME) + StringUtils.capitalize(COMPONENT_NAME);
    ITDQItemService service = (ITDQItemService) GlobalServiceRegister.getDefault().getService(ITDQItemService.class);
    File fileCreated = null;
    try {
        fileCreated = service.fileCreatedInRoutines(node, javaClassName);
    } catch (Exception ex) {
        MessageDialog.openError(Display.getDefault().getActiveShell(), //$NON-NLS-1$
        Messages.getString("GenerateGrammarController.prompt"), ex.getMessage());
    }
    if (fileCreated == null) {
        return;
    }
    try {
        RoutineItem returnItem = persistInRoutine(new Path(JOB_NAME), fileCreated, javaClassName);
        addReferenceJavaFile(returnItem, true);
        // ADD (to line 292) xwang 2011-08-12 add routine dependency in job
        if (node.getProcess() instanceof org.talend.designer.core.ui.editor.process.Process) {
            RoutinesParameterType r = TalendFileFactory.eINSTANCE.createRoutinesParameterType();
            r.setId(returnItem.getProperty().getId());
            r.setName(returnItem.getProperty().getLabel());
            List<RoutinesParameterType> routines = new ArrayList<RoutinesParameterType>();
            routines.add(r);
            ((org.talend.designer.core.ui.editor.process.Process) node.getProcess()).addGeneratingRoutines(routines);
        }
        refreshProject();
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    // remove temporary files of grammar
    FilesUtils.removeFolder(new File(fileCreated.getParent()), true);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) RoutinesParameterType(org.talend.designer.core.model.utils.emf.talendfile.RoutinesParameterType) Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) RoutineItem(org.talend.core.model.properties.RoutineItem) SystemException(org.talend.commons.exception.SystemException) IOException(java.io.IOException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) ITDQItemService(org.talend.core.ITDQItemService)

Example 2 with ITDQItemService

use of org.talend.core.ITDQItemService in project tdi-studio-se by Talend.

the class BuildJobHandler method addDQDependencies.

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

Example 3 with ITDQItemService

use of org.talend.core.ITDQItemService in project tdi-studio-se by Talend.

the class JobScriptsManager method addDependencies.

/**
     * DOC qwei Comment method "addDepencies".
     */
protected void addDependencies(ExportFileResource[] allResources, ProcessItem processItem, Boolean needDependencies, ExportFileResource resource) {
    if (!needDependencies) {
        return;
    }
    // export current job's dependencies.
    if (!exportCaculatedItems.contains(processItem)) {
        BuildExportManager.getInstance().exportDependencies(resource, processItem);
        exportCaculatedItems.add(processItem);
    }
    Collection<IRepositoryViewObject> allDependencies = ProcessUtils.getAllProcessDependencies(Arrays.asList(new Item[] { processItem }), false);
    ITransformService tdmService = null;
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ITransformService.class)) {
        tdmService = (ITransformService) GlobalServiceRegister.getDefault().getService(ITransformService.class);
    }
    try {
        for (IRepositoryViewObject object : allDependencies) {
            Item item = object.getProperty().getItem();
            ERepositoryObjectType itemType = ERepositoryObjectType.getItemType(item);
            IPath typeFolderPath = new Path(ERepositoryObjectType.getFolderName(itemType));
            String itemName = item.getProperty().getLabel();
            String itemVersion = item.getProperty().getVersion();
            String itemPath = item.getState().getPath();
            //$NON-NLS-1$ //$NON-NLS-2$
            itemPath = (itemPath == null || itemPath.equals("")) ? "" : itemPath;
            IPath projectRootPath = getCorrespondingProjectRootPath(item);
            String projectName = getCorrespondingProjectName(item);
            String relativePath = JOB_ITEMS_FOLDER_NAME + PATH_SEPARATOR + projectName;
            // add .settings/com.oaklandsw.base.projectProps for tdm
            if (tdmService != null && !exportCaculatedProject.contains(projectName) && tdmService.isTransformItem(item)) {
                IPath propsPath = getCorrespondingProjectRootPath(item).append(FileConstants.TDM_PROPS_PATH);
                String propsRelativePath = relativePath;
                propsRelativePath = propsRelativePath + PATH_SEPARATOR + FileConstants.TDM_PROPS_FOLDER;
                resource.addResource(propsRelativePath, propsPath.toFile().toURL());
            }
            // project file
            IPath projectFilePath = getCorrespondingProjectRootPath(item).append(FileConstants.LOCAL_PROJECT_FILENAME);
            checkAndAddProjectResource(allResources, resource, relativePath, FileLocator.toFileURL(projectFilePath.toFile().toURL()));
            // export simple file
            if (projectRootPath != null && item.getProperty() instanceof FakePropertyImpl) {
                String basePath = relativePath + PATH_SEPARATOR + typeFolderPath.toString();
                FakePropertyImpl fakeProperty = (FakePropertyImpl) item.getProperty();
                IPath relativeItemPath = fakeProperty.getItemPath();
                IPath absItemPath = projectRootPath.removeLastSegments(1).append(relativeItemPath.makeRelative());
                resource.addResource(basePath, absItemPath.toFile().toURL());
                continue;
            }
            IPath itemFilePath;
            String itemVersionString = (itemVersion == null) ? "" : "_" + itemVersion;
            if (itemPath.startsWith(typeFolderPath.toString())) {
                itemPath = itemPath.substring(typeFolderPath.toString().length());
            }
            if (item.getFileExtension() == null || "".equals(item.getFileExtension())) {
                //$NON-NLS-1$
                itemFilePath = projectRootPath.append(typeFolderPath).append(itemPath).append(itemName + (item.isNeedVersion() ? itemVersionString : "") + "." + //$NON-NLS-1$ 
                FileConstants.ITEM_EXTENSION);
            } else {
                itemFilePath = projectRootPath.append(typeFolderPath).append(itemPath).append(//$NON-NLS-1$ 
                itemName + (item.isNeedVersion() ? itemVersionString : "") + "." + item.getFileExtension());
            }
            IPath propertiesFilePath = projectRootPath.append(typeFolderPath).append(itemPath).append(//$NON-NLS-1$ 
            itemName + itemVersionString + "." + FileConstants.PROPERTIES_EXTENSION);
            List<URL> metadataNameFileUrls = new ArrayList<URL>();
            File itemFile = itemFilePath.toFile();
            if (itemFile.exists()) {
                metadataNameFileUrls.add(FileLocator.toFileURL(itemFile.toURI().toURL()));
            } else {
                ExceptionHandler.log(Messages.getString("JobScriptsManager.ResourceNotFoundForExport", itemFilePath));
            }
            File propertiesFile = propertiesFilePath.toFile();
            if (propertiesFile.exists()) {
                metadataNameFileUrls.add(FileLocator.toFileURL(propertiesFile.toURI().toURL()));
            } else {
                ExceptionHandler.log(Messages.getString("JobScriptsManager.ResourceNotFoundForExport", propertiesFilePath));
            }
            String basePath = relativePath + PATH_SEPARATOR + typeFolderPath.toString();
            if (itemPath != null && !"".equals(itemPath)) {
                //$NON-NLS-1$
                basePath = basePath + PATH_SEPARATOR + itemPath;
            }
            resource.addResources(basePath, metadataNameFileUrls);
            // children dependencies
            if (!exportCaculatedItems.contains(item)) {
                BuildExportManager.getInstance().exportDependencies(resource, item);
                exportCaculatedItems.add(item);
            }
        }
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQItemService.class)) {
            ITDQItemService tdqItemService = (ITDQItemService) GlobalServiceRegister.getDefault().getService(ITDQItemService.class);
            if (tdqItemService != null && tdqItemService.hasProcessItemDependencies(Arrays.asList(new Item[] { processItem }))) {
                // add .Talend.definition file
                //$NON-NLS-1$
                String defIdxFolderName = "TDQ_Libraries";
                //$NON-NLS-1$
                String defIdxFileName = ".Talend.definition";
                IProject project = ReponsitoryContextBridge.getRootProject();
                IFile defIdxFile = project.getFile(defIdxFolderName + PATH_SEPARATOR + defIdxFileName);
                if (defIdxFile.exists()) {
                    String defIdxBasePath = JOB_ITEMS_FOLDER_NAME + PATH_SEPARATOR + project.getName().toLowerCase() + PATH_SEPARATOR + defIdxFolderName;
                    List<URL> defIdxUrls = new ArrayList<URL>();
                    defIdxUrls.add(project.getLocation().makeAbsolute().append(defIdxFolderName).append(defIdxFileName).toFile().toURI().toURL());
                    resource.addResources(defIdxBasePath, defIdxUrls);
                }
                // add report header image & template files
                //$NON-NLS-1$
                String reportingBundlePath = PluginChecker.getBundlePath("org.talend.dataquality.reporting");
                List<URL> reportResourceUrls = new ArrayList<URL>();
                //$NON-NLS-1$
                File imageFolder = new File(reportingBundlePath + PATH_SEPARATOR + "images");
                if (imageFolder.exists()) {
                    reportResourceUrls.add(imageFolder.toURI().toURL());
                }
                //$NON-NLS-1$ 
                File templateFolder = new File(reportingBundlePath + PATH_SEPARATOR + "reports");
                if (templateFolder.exists() && templateFolder.isDirectory()) {
                    reportResourceUrls.add(templateFolder.toURI().toURL());
                }
                // include all added resources
                resource.addResources(JOB_ITEMS_FOLDER_NAME + PATH_SEPARATOR, reportResourceUrls);
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ITransformService(org.talend.core.service.ITransformService) FakePropertyImpl(org.talend.core.model.repository.FakePropertyImpl) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) URL(java.net.URL) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) ProcessorException(org.talend.designer.runprocess.ProcessorException) IOException(java.io.IOException) Item(org.talend.core.model.properties.Item) ProcessItem(org.talend.core.model.properties.ProcessItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IFile(org.eclipse.core.resources.IFile) File(java.io.File) ITDQItemService(org.talend.core.ITDQItemService)

Aggregations

File (java.io.File)3 IFile (org.eclipse.core.resources.IFile)3 IPath (org.eclipse.core.runtime.IPath)3 Path (org.eclipse.core.runtime.Path)3 ITDQItemService (org.talend.core.ITDQItemService)3 IOException (java.io.IOException)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 IProject (org.eclipse.core.resources.IProject)2 Item (org.talend.core.model.properties.Item)2 ProcessItem (org.talend.core.model.properties.ProcessItem)2 IFolder (org.eclipse.core.resources.IFolder)1 CoreException (org.eclipse.core.runtime.CoreException)1 SystemException (org.talend.commons.exception.SystemException)1 Project (org.talend.core.model.properties.Project)1 RoutineItem (org.talend.core.model.properties.RoutineItem)1 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)1 FakePropertyImpl (org.talend.core.model.repository.FakePropertyImpl)1 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)1 ITransformService (org.talend.core.service.ITransformService)1