Search in sources :

Example 81 with Project

use of org.talend.core.model.general.Project in project tesb-studio-se by Talend.

the class RouteResourceUtil method getSourceFile.

/**
     * Get source file of Item.
     * 
     * @param item
     * @return
     */
public static IFile getSourceFile(RouteResourceItem item) {
    // the file may come from a reference project
    IFolder rrfolder = null;
    Resource eResource = item.eResource();
    if (eResource != null) {
        URI uri = eResource.getURI();
        if (uri != null && uri.isPlatformResource()) {
            String platformString = uri.toPlatformString(true);
            IContainer parentContainer = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(platformString)).getParent();
            if (parentContainer instanceof IFolder) {
                rrfolder = (IFolder) parentContainer;
            }
        }
    }
    if (rrfolder == null) {
        Project talendProject = ProjectManager.getInstance().getCurrentProject();
        String technicalLabel = talendProject.getTechnicalLabel();
        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(technicalLabel);
        String folderPath = item.getState().getPath();
        rrfolder = project.getFolder(RouteResourceItem.ROUTE_RESOURCES_FOLDER);
        if (folderPath != null && !folderPath.isEmpty()) {
            rrfolder = rrfolder.getFolder(folderPath);
        }
    }
    String itemName = item.getProperty().getLabel();
    String version = item.getProperty().getVersion();
    String fileExtension = item.getBindingExtension();
    String fileName = itemName + "_" + version + "." + fileExtension;
    IFile file = rrfolder.getFile(fileName);
    return file;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IFile(org.eclipse.core.resources.IFile) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) IContainer(org.eclipse.core.resources.IContainer) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 82 with Project

use of org.talend.core.model.general.Project in project tdi-studio-se by Talend.

the class ExpressionBuilderDialog method getExpressionStorePath.

/**
     * yzhang Comment method "getExpressionStorePath".
     * 
     * @return
     */
protected String getExpressionStorePath() {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    RepositoryContext repositoryContext = (RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY);
    Project project = repositoryContext.getProject();
    IProject p = root.getProject(project.getTechnicalLabel());
    // put to the temp folder
    String projectPath = p.getLocation().toPortableString() + File.separator + RepositoryConstants.TEMP_DIRECTORY;
    String configurationPath = projectPath + File.separator + ExpressionPersistance.CONFIGURATION_FOLDER_NAME;
    configurationPath = getValidFolderPath(configurationPath, 1);
    File configurationFolder = new File(configurationPath);
    if (!configurationFolder.exists()) {
        configurationFolder.mkdir();
    }
    String expressionPath = configurationPath + File.separator + ExpressionPersistance.EXPRESSION_FOLDER_NAME;
    expressionPath = getValidFolderPath(expressionPath, 1);
    File expressionFolder = new File(expressionPath);
    if (!expressionFolder.exists()) {
        expressionFolder.mkdir();
    }
    String jobName = "";
    if (component != null) {
        jobName = component.getProcess().getName();
    } else {
        jobName = "tXMLMap";
    }
    expressionPath = expressionPath + File.separator + jobName + XmlUtil.FILE_XML_SUFFIX;
    return expressionPath;
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) RepositoryContext(org.talend.core.context.RepositoryContext) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) File(java.io.File) IProject(org.eclipse.core.resources.IProject)

Example 83 with Project

use of org.talend.core.model.general.Project in project tdi-studio-se by Talend.

the class ChangeModelForRoutineParameterMigrationTask2 method execute.

@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
    try {
        List<String> possibleRoutines = new ArrayList<String>();
        List<String> routinesToAdd = new ArrayList<String>();
        String additionalString = LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA ? "." : "";
        IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        List<IRepositoryViewObject> routines = factory.getAll(ProjectManager.getInstance().getCurrentProject(), ERepositoryObjectType.ROUTINES);
        // always add the system, others must be checked
        for (IRepositoryViewObject object : routines) {
            if (((RoutineItem) object.getProperty().getItem()).isBuiltIn()) {
                routinesToAdd.add(object.getLabel());
            } else {
                possibleRoutines.add(object.getLabel());
            }
        }
        for (Project project : ProjectManager.getInstance().getAllReferencedProjects()) {
            List<IRepositoryViewObject> refRoutines = factory.getAll(project, ERepositoryObjectType.ROUTINES);
            for (IRepositoryViewObject object : refRoutines) {
                if (!((RoutineItem) object.getProperty().getItem()).isBuiltIn()) {
                    if (!possibleRoutines.contains(object.getLabel())) {
                        possibleRoutines.add(object.getLabel());
                        routines.add(object);
                    }
                }
            }
        }
        List<RoutinesParameterType> oldList = Collections.EMPTY_LIST;
        ProcessType processType = getProcessType(item);
        if (null != processType) {
            if (processType.getParameters() != null && processType.getParameters().getRoutinesParameter() == null) {
                ParametersType parameterType = TalendFileFactory.eINSTANCE.createParametersType();
                processType.setParameters(parameterType);
                if (item instanceof ProcessItem) {
                    routinesToAdd.addAll(possibleRoutines);
                    possibleRoutines.clear();
                }
            } else {
                if (processType.getParameters() == null) {
                    processType.setParameters(TalendFileFactory.eINSTANCE.createParametersType());
                }
                oldList = new ArrayList<RoutinesParameterType>(processType.getParameters().getRoutinesParameter());
                if (oldList.isEmpty() && item instanceof ProcessItem) {
                    routinesToAdd.addAll(possibleRoutines);
                    possibleRoutines.clear();
                }
                processType.getParameters().getRoutinesParameter().clear();
            }
            if (processType.getRoutinesDependencies() != null && !processType.getRoutinesDependencies().isEmpty()) {
                processType.getRoutinesDependencies().clear();
            }
            List<RoutinesParameterType> routinesDependencies = (List<RoutinesParameterType>) processType.getParameters().getRoutinesParameter();
            if (!possibleRoutines.isEmpty()) {
                // check possible routines to setup in process
                for (ElementParameterType param : (List<ElementParameterType>) processType.getParameters().getElementParameter()) {
                    for (String routine : possibleRoutines) {
                        if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue().contains(routine + additionalString)) {
                            routinesToAdd.add(routine);
                        }
                        for (ElementValueType elementValue : (List<ElementValueType>) param.getElementValue()) {
                            if (!routinesToAdd.contains(routine) && elementValue.getValue() != null && elementValue.getValue().contains(routine + additionalString)) {
                                routinesToAdd.add(routine);
                            }
                        }
                    }
                }
                // check possible routines to setup in nodes
                for (NodeType node : ((List<NodeType>) processType.getNode())) {
                    for (ElementParameterType param : (List<ElementParameterType>) node.getElementParameter()) {
                        for (String routine : possibleRoutines) {
                            if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue().contains(routine + additionalString)) {
                                routinesToAdd.add(routine);
                            }
                            for (ElementValueType elementValue : (List<ElementValueType>) param.getElementValue()) {
                                if (!routinesToAdd.contains(routine) && elementValue.getValue() != null && elementValue.getValue().contains(routine + additionalString)) {
                                    routinesToAdd.add(routine);
                                }
                            }
                        }
                    }
                }
                // check possible routines to setup in connections
                for (ConnectionType connection : ((List<ConnectionType>) processType.getConnection())) {
                    for (ElementParameterType param : (List<ElementParameterType>) connection.getElementParameter()) {
                        for (String routine : possibleRoutines) {
                            if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue().contains(routine + additionalString)) {
                                routinesToAdd.add(routine);
                            }
                            for (ElementValueType elementValue : (List<ElementValueType>) param.getElementValue()) {
                                if (!routinesToAdd.contains(routine) && elementValue.getValue() != null && elementValue.getValue().contains(routine + additionalString)) {
                                    routinesToAdd.add(routine);
                                }
                            }
                        }
                    }
                }
            }
            // just in case some routine dependencies exist before but are lost... (migration from 4.1.1 or 4.1.2)
            for (RoutinesParameterType routine : oldList) {
                if (!routinesToAdd.contains(routine.getName())) {
                    routinesDependencies.add(routine);
                }
            }
            for (IRepositoryViewObject object : routines) {
                if (routinesToAdd.contains(object.getLabel())) {
                    RoutinesParameterType routinesParameterType = TalendFileFactory.eINSTANCE.createRoutinesParameterType();
                    routinesParameterType.setId(object.getId());
                    routinesParameterType.setName(object.getLabel());
                    routinesDependencies.add(routinesParameterType);
                }
            }
            factory.save(item, true);
        }
        return ExecutionResult.SUCCESS_NO_ALERT;
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) RoutinesParameterType(org.talend.designer.core.model.utils.emf.talendfile.RoutinesParameterType) ArrayList(java.util.ArrayList) RoutineItem(org.talend.core.model.properties.RoutineItem) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) Project(org.talend.core.model.general.Project) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType) ProcessItem(org.talend.core.model.properties.ProcessItem) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ArrayList(java.util.ArrayList) List(java.util.List) ParametersType(org.talend.designer.core.model.utils.emf.talendfile.ParametersType) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 84 with Project

use of org.talend.core.model.general.Project in project tdi-studio-se by Talend.

the class SelectDeleteProjectDialog method createTreeViewer.

private void createTreeViewer(Composite parent) {
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginWidth = 0;
    layout.makeColumnsEqualWidth = false;
    parent.setLayout(layout);
    parent.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
    GridData listData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
    treeViewer = new ContainerCheckedTreeViewer(parent);
    treeViewer.getControl().setLayoutData(listData);
    // treeViewer.setContentProvider(getResourceProvider(IResource.FOLDER | IResource.PROJECT));
    treeViewer.setContentProvider(getResourceProvider(IResource.PROJECT));
    // treeViewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
    treeViewer.setLabelProvider(new LabelProvider() {

        @Override
        public final String getText(Object element) {
            // query the element for its label
            //$NON-NLS-1$
            String label = "";
            if (element instanceof IProject) {
                IProject project = (IProject) element;
                label = getLabel(project.getName());
            } else if (element instanceof IFolder) {
                IFolder folder = (IFolder) element;
                label = getLabel(folder.getName());
            }
            return label;
        }

        private String getLabel(String name) {
            List<Project> proItem = getProjectItem();
            for (int i = 0; i < proItem.size(); i++) {
                Project p = proItem.get(i);
                String proName = p.getTechnicalLabel();
                if (proName.equals(name)) {
                    return ProjectManager.getProjectDisplayLabel(p.getEmfProject());
                }
            }
            return name;
        }

        @Override
        public final Image getImage(Object element) {
            if (element instanceof IProject) {
                return ImageProvider.getImage(ERepositoryImages.PROJECT_ICON);
            } else if (element instanceof IFolder) {
                return ImageProvider.getImage(ERepositoryImages.FOLDER_ICON);
            }
            return null;
        }
    });
    treeViewer.setInput(projectItemList);
    treeViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
    addTreeListener();
    createButtons(parent);
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ContainerCheckedTreeViewer(org.eclipse.ui.dialogs.ContainerCheckedTreeViewer) ArrayList(java.util.ArrayList) List(java.util.List) Image(org.eclipse.swt.graphics.Image) LabelProvider(org.eclipse.jface.viewers.LabelProvider) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 85 with Project

use of org.talend.core.model.general.Project in project tdi-studio-se by Talend.

the class ExportProjectsAsAction method getProjectAndRelatedLinks.

/**
     * DOC bqian Comment method "getProjectAndRelatedLinks".
     * 
     * @return
     */
private Map<Project, List<LinkTargetStore>> getProjectAndRelatedLinks() {
    Map<Project, List<LinkTargetStore>> map = new HashMap<Project, List<LinkTargetStore>>();
    IProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
    try {
        // fix for bug 15454
        Project[] projects = repositoryFactory.readProject(true);
        for (Project project : projects) {
            IProject fsProject = ResourceModelUtils.getProject(project);
        // IFolder libJavaFolder = fsProject.getFolder(ExportProjectsAsAction.CODE);
        // if (libJavaFolder.exists()) {
        // List<LinkTargetStore> links = getLinksFromProject(project);
        // map.put(project, links);
        // }
        }
    } catch (Exception e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
    return map;
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) PersistenceException(org.talend.commons.exception.PersistenceException)

Aggregations

Project (org.talend.core.model.general.Project)94 PersistenceException (org.talend.commons.exception.PersistenceException)47 IProject (org.eclipse.core.resources.IProject)38 File (java.io.File)18 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)18 ArrayList (java.util.ArrayList)17 IOException (java.io.IOException)13 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)13 RepositoryContext (org.talend.core.context.RepositoryContext)12 Property (org.talend.core.model.properties.Property)12 CoreException (org.eclipse.core.runtime.CoreException)10 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)10 List (java.util.List)9 IFolder (org.eclipse.core.resources.IFolder)8 Path (org.eclipse.core.runtime.Path)8 SystemException (org.talend.commons.exception.SystemException)8 JSONException (org.talend.utils.json.JSONException)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 ConnectionBean (org.talend.core.model.general.ConnectionBean)7 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)7