Search in sources :

Example 31 with RepositoryObject

use of org.talend.core.model.repository.RepositoryObject in project tesb-studio-se by Talend.

the class JavaCamelJobScriptsExportWSAction method exportAllReferenceJobs.

private void exportAllReferenceJobs(String routeName, ProcessItem routeProcess) throws InvocationTargetException, InterruptedException {
    Set<String> jobPackageNames = new HashSet<String>();
    for (NodeType cTalendJob : EmfModelUtils.getComponentsByName(routeProcess, "cTalendJob")) {
        // $NON-NLS-1$
        String jobId = null;
        String jobVersion = null;
        String jobContext = null;
        for (Object o : cTalendJob.getElementParameter()) {
            if (!(o instanceof ElementParameterType)) {
                continue;
            }
            ElementParameterType ept = (ElementParameterType) o;
            String eptName = ept.getName();
            if ("FROM_EXTERNAL_JAR".equals(eptName) && "true".equals(ept.getValue())) {
                // $NON-NLS-1$
                break;
            }
            if ("SELECTED_JOB_NAME:PROCESS_TYPE_PROCESS".equals(eptName)) {
                // $NON-NLS-1$
                jobId = ept.getValue();
            } else if ("SELECTED_JOB_NAME:PROCESS_TYPE_VERSION".equals(eptName)) {
                // $NON-NLS-1$
                jobVersion = ept.getValue();
            } else if ("SELECTED_JOB_NAME:PROCESS_TYPE_CONTEXT".equals(eptName)) {
                // $NON-NLS-1$
                jobContext = ept.getValue();
            }
        }
        if (jobId == null || jobVersion == null) {
            continue;
        }
        IRepositoryViewObject repositoryObject;
        Project jobProject;
        try {
            repositoryObject = getJobRepositoryNode(jobId, ERepositoryObjectType.PROCESS);
            jobProject = getJobProject(jobId, ERepositoryObjectType.PROCESS);
        } catch (PersistenceException e) {
            throw new InvocationTargetException(e);
        }
        if (RelationshipItemBuilder.LATEST_VERSION.equals(jobVersion)) {
            jobVersion = repositoryObject.getVersion();
        }
        String jobName = repositoryObject.getProperty().getDisplayName();
        String jobBundleName = routeName + "_" + jobName;
        String jobBundleSymbolicName = jobBundleName;
        String jobPackageName = getJobPackageName(jobProject, jobName, jobVersion);
        if (!jobPackageNames.contains(jobPackageName)) {
            jobPackageNames.add(jobPackageName);
        }
        Project project = ProjectManager.getInstance().getCurrentProject();
        if (project != null) {
            String projectName = project.getLabel();
            if (projectName != null && projectName.length() > 0) {
                jobBundleSymbolicName = projectName.toLowerCase() + '.' + jobBundleSymbolicName;
            }
        }
        File jobFile;
        try {
            // $NON-NLS-1$
            jobFile = File.createTempFile("job", FileConstants.JAR_FILE_SUFFIX, new File(getTempDir()));
            addBuildArtifact(repositoryObject, "jar", jobFile);
        } catch (IOException e) {
            throw new InvocationTargetException(e);
        }
        String jobBundleVersion = buildBundleVersionForReferencedJob(routeProcess, jobId);
        String jobArtifactVersion = jobBundleVersion;
        String jobGroup = (String) routeProcess.getProperty().getAdditionalProperties().get(BUILD_FROM_COMMANDLINE_GROUP);
        if (jobGroup == null) {
            jobGroup = PomIdsHelper.getJobGroupId(routeProcess.getProperty());
        }
        BundleModel jobModel = new BundleModel(jobGroup, jobBundleName, jobBundleVersion, jobFile);
        if (featuresModel.getBundles().contains(jobModel)) {
            featuresModel.getBundles().remove(jobModel);
        }
        if (featuresModel.addBundle(jobModel)) {
            exportRouteUsedJobBundle(repositoryObject, jobFile, jobVersion, jobBundleName, jobBundleSymbolicName, jobArtifactVersion.replace("-", "."), getArtifactId(), version, jobContext);
        }
    }
    addJobPackageToOsgiImport(routeProcess, jobPackageNames);
}
Also used : BundleModel(org.talend.designer.publish.core.models.BundleModel) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) Project(org.talend.core.model.general.Project) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) CamelRepositoryNodeType(org.talend.camel.model.CamelRepositoryNodeType) ENodeType(org.talend.repository.model.IRepositoryNode.ENodeType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryObject(org.talend.core.model.repository.RepositoryObject) IRepositoryObject(org.talend.core.model.repository.IRepositoryObject) File(java.io.File) HashSet(java.util.HashSet)

Example 32 with RepositoryObject

use of org.talend.core.model.repository.RepositoryObject in project tesb-studio-se by Talend.

the class JavaCamelJobScriptsExportWSAction method getJobRepositoryNode.

private static IRepositoryViewObject getJobRepositoryNode(String jobId, ERepositoryObjectType type) throws PersistenceException {
    String projectLable = ProcessUtils.getProjectLabelFromItemId(jobId);
    List<IRepositoryViewObject> list = new ArrayList<>();
    List<Project> projects = ProjectManager.getInstance().getAllReferencedProjects();
    for (Project p : projects) {
        list.addAll(ProxyRepositoryFactory.getInstance().getAll(p, type));
    }
    list.addAll(ProxyRepositoryFactory.getInstance().getAll(type));
    for (IRepositoryViewObject job : list) {
        if (job.getId().equals(jobId)) {
            if (projectLable == null || StringUtils.equals(projectLable, job.getProjectLabel())) {
                return new RepositoryObject(job.getProperty());
            }
        }
    }
    return null;
}
Also used : Project(org.talend.core.model.general.Project) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) RepositoryObject(org.talend.core.model.repository.RepositoryObject) IRepositoryObject(org.talend.core.model.repository.IRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ArrayList(java.util.ArrayList)

Aggregations

RepositoryObject (org.talend.core.model.repository.RepositoryObject)32 RepositoryNode (org.talend.repository.model.RepositoryNode)11 Property (org.talend.core.model.properties.Property)10 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)9 IRepositoryNode (org.talend.repository.model.IRepositoryNode)9 TableItem (org.eclipse.swt.widgets.TableItem)5 PersistenceException (org.talend.commons.exception.PersistenceException)5 Item (org.talend.core.model.properties.Item)5 ArrayList (java.util.ArrayList)4 IPath (org.eclipse.core.runtime.IPath)4 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)4 IEditorPart (org.eclipse.ui.IEditorPart)4 IRepositoryObject (org.talend.core.model.repository.IRepositoryObject)4 ProjectRepositoryNode (org.talend.core.repository.model.ProjectRepositoryNode)4 IProjectRepositoryNode (org.talend.repository.model.nodes.IProjectRepositoryNode)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 ISelection (org.eclipse.jface.viewers.ISelection)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 WizardDialog (org.eclipse.jface.wizard.WizardDialog)3