Search in sources :

Example 96 with Project

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

the class HadoopClusterRepositoryContentHandler method addNode.

@Override
public void addNode(ERepositoryObjectType type, RepositoryNode parentNode, IRepositoryViewObject repositoryObject, RepositoryNode node) {
    if (type == HadoopClusterRepositoryNodeType.HADOOPCLUSTER) {
        Project project = new Project(ProjectManager.getInstance().getProject(node.getObject().getProperty()));
        for (IHadoopSubnodeRepositoryContentHandler handler : HadoopSubnodeRepositoryContentManager.getHandlers()) {
            handler.addNode(project, node);
        }
        addHadoopDBNode(project, node);
    }
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project)

Example 97 with Project

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

the class HadoopClusterService method getHadoopClusterItemById.

@Override
public Item getHadoopClusterItemById(String id) {
    HadoopClusterConnectionItem connectionItem = HCRepositoryUtil.getRelativeHadoopClusterItem(id);
    if (connectionItem == null) {
        // In case it is a hadoopsubconnection.
        connectionItem = HCRepositoryUtil.getHadoopClusterItemBySubitemId(id);
        if (connectionItem == null) {
            Item item = HCRepositoryUtil.getRelativeItem(id);
            if (item != null) {
                Project project = new Project(ProjectManager.getInstance().getProject(item.getProperty()));
                connectionItem = HCRepositoryUtil.getHadoopClusterItemBySubitemId(project, id);
            }
        }
    }
    return connectionItem;
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) HadoopClusterConnectionItem(org.talend.repository.model.hadoopcluster.HadoopClusterConnectionItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) HadoopSubConnectionItem(org.talend.repository.model.hadoopcluster.HadoopSubConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Project(org.talend.core.model.general.Project) HadoopClusterConnectionItem(org.talend.repository.model.hadoopcluster.HadoopClusterConnectionItem)

Example 98 with Project

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

the class HadoopConfsUtils method getConfsTempFolder.

private static String getConfsTempFolder(String subFolderName) {
    Project project = ProjectManager.getInstance().getCurrentProject();
    String tmpFolder;
    try {
        IProject physProject = ResourceModelUtils.getProject(project);
        // $NON-NLS-1$
        tmpFolder = physProject.getFolder("temp").getLocation().toPortableString();
    } catch (Exception e) {
        // $NON-NLS-1$
        tmpFolder = System.getProperty("user.dir");
    }
    tmpFolder = tmpFolder + File.separator + CONFS_FOLDER;
    File confFolder = new File(tmpFolder + File.separator + subFolderName);
    if (!confFolder.exists()) {
        confFolder.mkdirs();
    } else {
        FilesUtils.emptyFolder(confFolder);
    }
    return confFolder.getAbsolutePath();
}
Also used : Project(org.talend.core.model.general.Project) IProject(org.eclipse.core.resources.IProject) File(java.io.File) IProject(org.eclipse.core.resources.IProject) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 99 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 100 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)

Aggregations

Project (org.talend.core.model.general.Project)173 IProject (org.eclipse.core.resources.IProject)84 PersistenceException (org.talend.commons.exception.PersistenceException)76 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)36 ArrayList (java.util.ArrayList)26 File (java.io.File)24 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)24 IFolder (org.eclipse.core.resources.IFolder)23 Property (org.talend.core.model.properties.Property)21 IOException (java.io.IOException)20 Path (org.eclipse.core.runtime.Path)19 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)19 IPath (org.eclipse.core.runtime.IPath)18 CoreException (org.eclipse.core.runtime.CoreException)16 RepositoryContext (org.talend.core.context.RepositoryContext)16 Item (org.talend.core.model.properties.Item)15 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)14 IFile (org.eclipse.core.resources.IFile)13 User (org.talend.core.model.properties.User)13 ProjectManager (org.talend.repository.ProjectManager)13