Search in sources :

Example 16 with FolderItem

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

the class JobScriptsExportWizardPage method getProcessItem.

protected ProcessItem getProcessItem() {
    if ((processItem == null) && (nodes != null) && (nodes.length >= 1)) {
        IRepositoryViewObject repositoryObject = nodes[0].getObject();
        // add for bug TDI-20132
        List<IRepositoryNode> nodesChildren = nodes[0].getChildren();
        IRepositoryViewObject childObject = null;
        if ((nodesChildren != null) && (nodesChildren.size() >= 1)) {
            childObject = nodesChildren.get(0).getObject();
        }
        if (repositoryObject == null && childObject != null && childObject.getProperty().getItem() instanceof ProcessItem) {
            processItem = (ProcessItem) childObject.getProperty().getItem();
        }
        if (repositoryObject != null && repositoryObject.getProperty().getItem() instanceof ProcessItem) {
            processItem = (ProcessItem) repositoryObject.getProperty().getItem();
        } else if (repositoryObject != null && repositoryObject.getProperty().getItem() instanceof FolderItem) {
            processItem = getProcessItemIfSelectFolder(repositoryObject);
        }
    }
    return processItem;
}
Also used : FolderItem(org.talend.core.model.properties.FolderItem) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ProcessItem(org.talend.core.model.properties.ProcessItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 17 with FolderItem

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

the class RepositoryTypeProcessor method selectRepositoryNode.

@Override
protected boolean selectRepositoryNode(Viewer viewer, RepositoryNode parentNode, RepositoryNode node) {
    final String repositoryType = getRepositoryType();
    if (node == null) {
        return false;
    }
    if (node.getContentType() == ERepositoryObjectType.REFERENCED_PROJECTS) {
        return true;
    }
    // for sub folders
    if (node.getType() == ENodeType.STABLE_SYSTEM_FOLDER) {
        return false;
    }
    // for Db Connections
    if (node.getType() == ENodeType.SYSTEM_FOLDER) {
        return true;
    }
    // }
    IRepositoryViewObject object = node.getObject();
    if (object == null || object.getProperty().getItem() == null) {
        return false;
    }
    if (object instanceof MetadataTable) {
        return false;
    }
    Item item = object.getProperty().getItem();
    if (item instanceof FolderItem) {
        return true;
    }
    if (item instanceof ConnectionItem) {
        ConnectionItem connectionItem = (ConnectionItem) item;
        Connection connection = connectionItem.getConnection();
        // tAdvancedFileOutputXML
        if (repositoryType != null && repositoryType.equals(ERepositoryCategoryType.XMLOUTPUT.getName())) {
            if (connection instanceof XmlFileConnection && ((XmlFileConnection) connection).isInputModel()) {
                return false;
            }
        }
        if (repositoryType.startsWith(ERepositoryCategoryType.DATABASE.getName())) {
            //$NON-NLS-1$
            String currentDbType = (String) RepositoryToComponentProperty.getValue(connection, "TYPE", null);
            if (repositoryType.contains(":")) {
                // database //$NON-NLS-1$
                // is
                // specified
                // //$NON-NLS-1$
                //$NON-NLS-1$
                String neededDbType = repositoryType.substring(repositoryType.indexOf(":") + 1);
                if (hidenTypeSelection) {
                    return true;
                }
                if (!MetadataTalendType.sameDBProductType(neededDbType, currentDbType)) {
                    return false;
                }
            }
        }
    }
    if (repositoryType.startsWith(ERepositoryCategoryType.HEADERFOOTER.getName())) {
        if (item instanceof HeaderFooterConnectionItem) {
            HeaderFooterConnectionItem connectionItem = (HeaderFooterConnectionItem) item;
            HeaderFooterConnection connection = (HeaderFooterConnection) connectionItem.getConnection();
            boolean isHeader = connection.isIsHeader();
            if ((isHeader && isHeaderButton) || (!isHeader && !isHeaderButton)) {
                return true;
            } else {
                return false;
            }
        }
    }
    return true;
}
Also used : Item(org.talend.core.model.properties.Item) HeaderFooterConnectionItem(org.talend.core.model.properties.HeaderFooterConnectionItem) FolderItem(org.talend.core.model.properties.FolderItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) HeaderFooterConnectionItem(org.talend.core.model.properties.HeaderFooterConnectionItem) FolderItem(org.talend.core.model.properties.FolderItem) HeaderFooterConnectionItem(org.talend.core.model.properties.HeaderFooterConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MetadataTable(org.talend.core.model.metadata.MetadataTable) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) HeaderFooterConnection(org.talend.core.model.metadata.builder.connection.HeaderFooterConnection) HeaderFooterConnection(org.talend.core.model.metadata.builder.connection.HeaderFooterConnection)

Example 18 with FolderItem

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

the class ValidationRuleTypeProcessor method selectRepositoryNode.

@Override
protected boolean selectRepositoryNode(Viewer viewer, RepositoryNode parentNode, RepositoryNode node) {
    if (node.getContentType() == ERepositoryObjectType.REFERENCED_PROJECTS) {
        return true;
    }
    ProjectManager pManager = ProjectManager.getInstance();
    if (!pManager.isInCurrentMainProject(node)) {
        if (node.getType() == ENodeType.STABLE_SYSTEM_FOLDER) {
            return false;
        }
        if (node.getType() == ENodeType.SYSTEM_FOLDER) {
            return true;
        }
    }
    if (node.getType() == ENodeType.SYSTEM_FOLDER) {
        return true;
    }
    if (node.getObject() == null || node.getObject().getProperty().getItem() == null) {
        return false;
    }
    if (node.getObject() instanceof MetadataTable) {
        return false;
    }
    Item item = node.getObject().getProperty().getItem();
    if (item instanceof FolderItem) {
        return true;
    }
    if (node.getObjectType() == getType()) {
        return true;
    }
    return false;
}
Also used : FolderItem(org.talend.core.model.properties.FolderItem) Item(org.talend.core.model.properties.Item) FolderItem(org.talend.core.model.properties.FolderItem) MetadataTable(org.talend.core.model.metadata.MetadataTable) ProjectManager(org.talend.repository.ProjectManager)

Example 19 with FolderItem

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

the class TosTokenCollector method collectJobDetails.

/**
     * DOC nrousseau Comment method "collectJobDetails".
     * 
     * @param all
     * @param jobDetails
     * @throws JSONException
     */
private void collectJobDetails(List<IRepositoryViewObject> allRvo, JSONObject jobDetails) throws JSONException {
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    IWorkbenchWindow ww = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IEditorReference[] reference = new IEditorReference[0];
    if (ww != null) {
        IWorkbenchPage page = ww.getActivePage();
        reference = page.getEditorReferences();
    }
    List<IProcess2> processes = RepositoryPlugin.getDefault().getDesignerCoreService().getOpenedProcess(reference);
    Set<String> idsOpened = new HashSet<String>();
    for (IProcess2 process : processes) {
        idsOpened.add(process.getId());
    }
    JSONArray components = new JSONArray();
    int contextVarsNum = 0;
    int nbComponentsUsed = 0;
    for (IRepositoryViewObject rvo : allRvo) {
        Item item = rvo.getProperty().getItem();
        if (item instanceof ProcessItem) {
            ProcessType processType = ((ProcessItem) item).getProcess();
            for (NodeType node : (List<NodeType>) processType.getNode()) {
                JSONObject component_names = null;
                String componentName = node.getComponentName();
                int nbComp = 0;
                for (int i = 0; i < components.length(); i++) {
                    JSONObject temp = components.getJSONObject(i);
                    if (temp.get("component_name").equals(componentName)) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        nbComp = temp.getInt("count");
                        component_names = temp;
                        break;
                    }
                }
                if (component_names == null) {
                    component_names = new JSONObject();
                    components.put(component_names);
                }
                component_names.put("component_name", componentName);
                component_names.put("count", nbComp + 1);
                nbComponentsUsed++;
            }
            // context variable per job
            EList contexts = processType.getContext();
            if (contexts.size() > 0) {
                ContextType contextType = (ContextType) contexts.get(0);
                contextVarsNum += contextType.getContextParameter().size();
            }
        }
        if (factory.getStatus(item) != ERepositoryStatus.LOCK_BY_USER && !idsOpened.contains(item.getProperty().getId())) {
            // job is not locked and not opened by editor, so we can unload.
            if (item.getParent() instanceof FolderItem) {
                ((FolderItem) item.getParent()).getChildren().remove(item);
                item.setParent(null);
            }
            item.eResource().unload();
        }
    }
    jobDetails.put("components", components);
    jobDetails.put("nb.contextVars", contextVarsNum);
    jobDetails.put("nb.components", nbComponentsUsed);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) JSONArray(us.monoid.json.JSONArray) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) FolderItem(org.talend.core.model.properties.FolderItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) IEditorReference(org.eclipse.ui.IEditorReference) EList(org.eclipse.emf.common.util.EList) FolderItem(org.talend.core.model.properties.FolderItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JSONObject(us.monoid.json.JSONObject) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) HashSet(java.util.HashSet)

Example 20 with FolderItem

use of org.talend.core.model.properties.FolderItem in project tmdm-studio-se by Talend.

the class RemoveFromRepositoryActionTest method doRunTest.

@Test
public void doRunTest() throws Exception {
    PowerMockito.mockStatic(MDMWorbenchPlugin.class);
    when(MDMWorbenchPlugin.getImageDescriptor(anyString())).thenReturn(mock(ImageDescriptor.class));
    RemoveFromRepositoryAction removeAction = new RemoveFromRepositoryAction();
    RemoveFromRepositoryAction removeActionM = PowerMockito.spy(removeAction);
    CommonViewer commonViewerM = mock(CommonViewer.class);
    // $NON-NLS-1$
    Whitebox.setInternalState(removeActionM, "commonViewer", commonViewerM);
    // $NON-NLS-1$
    PowerMockito.doReturn(true).when(removeActionM, "confirm", 2);
    // $NON-NLS-1$
    PowerMockito.doNothing().when(removeActionM, "warn");
    // mock a mdm repositoryViewObject
    IRepositoryViewObject objectRVO = mock(IRepositoryViewObject.class);
    MDMServerObjectItem mdmItemM = mock(MDMServerObjectItem.class);
    Property propertyM = mock(Property.class);
    when(objectRVO.getProperty()).thenReturn(propertyM);
    when(propertyM.getItem()).thenReturn(mdmItemM);
    // mock a FolderRepositoryObject
    FolderRepositoryObject folderRO = mock(FolderRepositoryObject.class);
    Property foldePropertyM = mock(Property.class);
    ContainerItem containerItem = mock(ContainerItem.class);
    when(folderRO.getProperty()).thenReturn(foldePropertyM);
    when(foldePropertyM.getItem()).thenReturn(containerItem);
    ItemState itemState = mock(ItemState.class);
    when(containerItem.getState()).thenReturn(itemState);
    // $NON-NLS-1$
    when(itemState.getPath()).thenReturn("");
    PowerMockito.mockStatic(RepositoryNodeProviderRegistryReader.class);
    RepositoryNodeProviderRegistryReader reader = mock(RepositoryNodeProviderRegistryReader.class);
    PowerMockito.when(RepositoryNodeProviderRegistryReader.getInstance()).thenReturn(reader);
    ERepositoryObjectType typeM = ERepositoryObjectType.PROCESS;
    when(containerItem.getRepObjType()).thenReturn(typeM);
    MDMServerObject mdmServerObjectM = mock(MDMServerObject.class);
    when(mdmItemM.getMDMServerObject()).thenReturn(mdmServerObjectM);
    Shell shellM = mock(Shell.class);
    Control controlM = mock(Control.class);
    when(commonViewerM.getControl()).thenReturn(controlM);
    when(controlM.getShell()).thenReturn(shellM);
    List<Object> selectedObjects = new ArrayList<Object>();
    selectedObjects.add(objectRVO);
    selectedObjects.add(folderRO);
    when(removeActionM.getSelectedObject()).thenReturn(selectedObjects);
    // $NON-NLS-1$
    Whitebox.setInternalState(removeActionM, "lockedObjs", Collections.EMPTY_LIST);
    PowerMockito.mockStatic(MessageDialog.class);
    when(MessageDialog.openConfirm((Shell) anyObject(), anyString(), anyString())).thenReturn(true);
    PowerMockito.mockStatic(RepositoryResourceUtil.class);
    when(RepositoryResourceUtil.isOpenedInEditor((IRepositoryViewObject) anyObject())).thenReturn(null);
    when(RepositoryResourceUtil.hasContainerItem(anyObject(), eq(FolderType.FOLDER_LITERAL))).thenReturn(true);
    PowerMockito.mockStatic(ContainerCacheService.class);
    FolderItem folderItemM = mock(FolderItem.class);
    when(repositoryFactory.getFolderItem(eq(projectM), eq(typeM), (IPath) anyObject())).thenReturn(folderItemM);
    when(folderItemM.getState()).thenReturn(itemState);
    removeActionM.doRun();
}
Also used : ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) CommonViewer(org.eclipse.ui.navigator.CommonViewer) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) ArrayList(java.util.ArrayList) FolderRepositoryObject(org.talend.mdm.repository.models.FolderRepositoryObject) RepositoryNodeProviderRegistryReader(org.talend.core.model.repository.RepositoryNodeProviderRegistryReader) Shell(org.eclipse.swt.widgets.Shell) Control(org.eclipse.swt.widgets.Control) FolderItem(org.talend.core.model.properties.FolderItem) ItemState(org.talend.core.model.properties.ItemState) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) FolderRepositoryObject(org.talend.mdm.repository.models.FolderRepositoryObject) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Property(org.talend.core.model.properties.Property) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

FolderItem (org.talend.core.model.properties.FolderItem)35 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)17 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)16 Item (org.talend.core.model.properties.Item)15 IFolder (org.eclipse.core.resources.IFolder)10 Folder (org.talend.core.model.repository.Folder)10 MetadataTable (org.talend.core.model.metadata.MetadataTable)7 Property (org.talend.core.model.properties.Property)6 ArrayList (java.util.ArrayList)5 IPath (org.eclipse.core.runtime.IPath)5 Path (org.eclipse.core.runtime.Path)5 PersistenceException (org.talend.commons.exception.PersistenceException)5 IFile (org.eclipse.core.resources.IFile)4 IProject (org.eclipse.core.resources.IProject)4 ConnectionItem (org.talend.core.model.properties.ConnectionItem)4 ProcessItem (org.talend.core.model.properties.ProcessItem)4 RepositoryViewObject (org.talend.core.model.repository.RepositoryViewObject)4 ContainerItem (org.talend.mdm.repository.model.mdmproperties.ContainerItem)4 URL (java.net.URL)3 EObject (org.eclipse.emf.ecore.EObject)3