Search in sources :

Example 21 with FolderRepositoryObject

use of org.talend.mdm.repository.models.FolderRepositoryObject in project tmdm-studio-se by Talend.

the class TreeViewerListener method treeExpanded.

@Override
public void treeExpanded(TreeExpansionEvent event) {
    Object element = event.getElement();
    if (element instanceof FolderRepositoryObject) {
        FolderRepositoryObject fro = (FolderRepositoryObject) element;
        String path = fro.getPath();
        if (!path.isEmpty()) {
            TreeItem item = getObject(viewer.getTree(), event.getElement());
            if (item != null) {
                item.setImage(ImageProvider.getImage(ECoreImage.FOLDER_OPEN_ICON));
            }
        }
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) FolderRepositoryObject(org.talend.mdm.repository.models.FolderRepositoryObject) FolderRepositoryObject(org.talend.mdm.repository.models.FolderRepositoryObject)

Example 22 with FolderRepositoryObject

use of org.talend.mdm.repository.models.FolderRepositoryObject in project tmdm-studio-se by Talend.

the class ContainerCacheServiceTest method testRemoveContainer.

@Test
public void testRemoveContainer() {
    // $NON-NLS-1$
    String path = "/path";
    // $NON-NLS-1$
    String propId = "propertyId";
    ERepositoryObjectType repObjType = IServerObjectRepositoryType.TYPE_DATAMODEL;
    IRepositoryViewObject mockChildRpViewObj = PowerMockito.mock(IRepositoryViewObject.class);
    Property mockProperty = PowerMockito.mock(Property.class);
    PowerMockito.when(mockProperty.getId()).thenReturn(propId);
    PowerMockito.when(mockChildRpViewObj.getId()).thenReturn(propId);
    PowerMockito.when(mockChildRpViewObj.getProperty()).thenReturn(mockProperty);
    ContainerCacheService.put(mockChildRpViewObj);
    // container item
    ItemState mockState = PowerMockito.mock(ItemState.class);
    PowerMockito.when(mockState.getPath()).thenReturn(path);
    ContainerItem mockContainerItem = PowerMockito.mock(ContainerItem.class);
    PowerMockito.when(mockContainerItem.getState()).thenReturn(mockState);
    PowerMockito.when(mockContainerItem.getRepObjType()).thenReturn(repObjType);
    FolderRepositoryObject mockFolderRepoObj = PowerMockito.mock(FolderRepositoryObject.class);
    List<IRepositoryViewObject> children = new ArrayList<IRepositoryViewObject>();
    children.add(mockChildRpViewObj);
    children = spy(children);
    PowerMockito.when(mockFolderRepoObj.getChildren()).thenReturn(children);
    Property mockFolderProperty = PowerMockito.mock(Property.class);
    PowerMockito.when(mockFolderProperty.getItem()).thenReturn(mockContainerItem);
    PowerMockito.when(mockFolderRepoObj.getProperty()).thenReturn(mockFolderProperty);
    ContainerCacheService.putContainer(mockFolderRepoObj);
    // 
    ContainerCacheService.removeContainer(repObjType, path);
    assertNull(ContainerCacheService.get(repObjType, path));
    assertNull(ContainerCacheService.get(mockProperty));
}
Also used : ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) ItemState(org.talend.core.model.properties.ItemState) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ArrayList(java.util.ArrayList) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Property(org.talend.core.model.properties.Property) FolderRepositoryObject(org.talend.mdm.repository.models.FolderRepositoryObject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 23 with FolderRepositoryObject

use of org.talend.mdm.repository.models.FolderRepositoryObject 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)

Example 24 with FolderRepositoryObject

use of org.talend.mdm.repository.models.FolderRepositoryObject in project tmdm-studio-se by Talend.

the class RepositoryResourceUtilTest method testCreateDeletedFolderViewObject.

@Test
public void testCreateDeletedFolderViewObject() throws Exception {
    ERepositoryObjectType type = null;
    String path = "mocked_path";
    String folderName = "folderName";
    List<IRepositoryViewObject> children = new ArrayList<IRepositoryViewObject>();
    List<IRepositoryViewObject> spychildren = PowerMockito.spy(children);
    StubFolderRepositoryObject mockParentFolderObject = mock(StubFolderRepositoryObject.class);
    when(mockParentFolderObject.getChildren()).thenReturn(spychildren);
    PowerMockito.mockStatic(ContainerCacheService.class);
    PowerMockito.doNothing().when(ContainerCacheService.class, "putContainer", Mockito.any(IRepositoryViewObject.class));
    FolderRepositoryObject deletedFolderViewObject = RepositoryResourceUtil.createDeletedFolderViewObject(type, path, folderName, mockParentFolderObject);
    assertNotNull(deletedFolderViewObject);
}
Also used : IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ArrayList(java.util.ArrayList) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) FolderRepositoryObject(org.talend.mdm.repository.models.FolderRepositoryObject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 25 with FolderRepositoryObject

use of org.talend.mdm.repository.models.FolderRepositoryObject in project tmdm-studio-se by Talend.

the class AbstractRemoveCommandStackAction method removeFolderObject.

private void removeFolderObject(FolderRepositoryObject viewObj) {
    Project project = ProjectManager.getInstance().getCurrentProject();
    ContainerItem containerItem = (ContainerItem) viewObj.getProperty().getItem();
    String path = containerItem.getState().getPath();
    ERepositoryObjectType repObjType = containerItem.getRepObjType();
    // ContainerCacheService.removeContainer(repObjType, path);
    for (IRepositoryViewObject childObj : viewObj.getChildren()) {
        if (childObj instanceof FolderRepositoryObject) {
            removeFolderObject((FolderRepositoryObject) childObj);
        } else {
            removeServerObject(childObj);
        }
    }
    try {
        factory.deleteFolder(project, repObjType, new Path(path), false);
    } catch (PersistenceException e) {
        log.error(e.getMessage(), e);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) Project(org.talend.core.model.general.Project) ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) FolderRepositoryObject(org.talend.mdm.repository.models.FolderRepositoryObject)

Aggregations

FolderRepositoryObject (org.talend.mdm.repository.models.FolderRepositoryObject)37 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)32 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)16 ContainerItem (org.talend.mdm.repository.model.mdmproperties.ContainerItem)14 ArrayList (java.util.ArrayList)7 Item (org.talend.core.model.properties.Item)7 Property (org.talend.core.model.properties.Property)7 PersistenceException (org.talend.commons.exception.PersistenceException)6 ItemState (org.talend.core.model.properties.ItemState)6 TreeItem (org.eclipse.swt.widgets.TreeItem)5 LinkedList (java.util.LinkedList)4 Project (org.talend.core.model.general.Project)4 RepositoryViewObject (org.talend.core.model.repository.RepositoryViewObject)4 IProject (org.eclipse.core.resources.IProject)3 Path (org.eclipse.core.runtime.Path)3 FolderItem (org.talend.core.model.properties.FolderItem)3 WSRootRepositoryObject (org.talend.mdm.repository.models.WSRootRepositoryObject)3 List (java.util.List)2 Matcher (java.util.regex.Matcher)2 IFolder (org.eclipse.core.resources.IFolder)2