Search in sources :

Example 1 with IRepositoryNodeResourceProvider

use of org.talend.mdm.repository.core.IRepositoryNodeResourceProvider in project tmdm-studio-se by Talend.

the class RepositoryNodeConfigurationManager method getConfiguration.

public static IRepositoryNodeConfiguration getConfiguration(Item item) {
    EClass eClass = item.eClass();
    IRepositoryNodeConfiguration configuration = itemConfMap.get(eClass);
    if (configuration != null) {
        return configuration;
    }
    for (IRepositoryNodeConfiguration conf : getConfigurations()) {
        IRepositoryNodeResourceProvider resourceProvider = conf.getResourceProvider();
        if (resourceProvider != null) {
            if (resourceProvider.canHandleItem(item)) {
                if (!(item instanceof ContainerItem)) {
                    itemConfMap.put(eClass, conf);
                }
                return conf;
            }
        }
    }
    if (recycleBinNodeConfiguration.getResourceProvider().canHandleItem(item)) {
        return recycleBinNodeConfiguration;
    }
    return null;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IRepositoryNodeResourceProvider(org.talend.mdm.repository.core.IRepositoryNodeResourceProvider) ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) IRepositoryNodeConfiguration(org.talend.mdm.repository.core.IRepositoryNodeConfiguration)

Example 2 with IRepositoryNodeResourceProvider

use of org.talend.mdm.repository.core.IRepositoryNodeResourceProvider in project tmdm-studio-se by Talend.

the class RepositoryResourceUtil method createItem.

public static boolean createItem(Item item, String propLabel, String version, boolean pushCommandStack, boolean triggerEvent) {
    String name = propLabel;
    IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
    RepositoryContext context = factory.getRepositoryContext();
    Property prop = PropertiesFactory.eINSTANCE.createProperty();
    item.setProperty(prop);
    try {
        String nextId = factory.getNextId();
        Property property = item.getProperty();
        property.setId(nextId);
        property.setVersion(version);
        property.setAuthor(context.getUser());
        property.setLabel(propLabel);
        // 
        factory.create(item, new Path(item.getState().getPath()));
        item = assertItem(item);
        // 
        IRepositoryNodeConfiguration configuration = RepositoryNodeConfigurationManager.getConfiguration(item);
        if (configuration != null) {
            IRepositoryNodeResourceProvider resourceProvider = configuration.getResourceProvider();
            if (resourceProvider.needSaveReferenceFile()) {
                resourceProvider.handleReferenceFile(item);
            }
            factory.save(item, !triggerEvent);
            try {
                factory.unlock(item);
            } catch (LoginException e) {
                log.error(e.getMessage(), e);
            }
        }
        if (pushCommandStack) {
            CommandManager.getInstance().pushCommand(ICommand.CMD_ADD, nextId, name);
        }
        return true;
    } catch (PersistenceException e) {
        log.error(e.getMessage(), e);
    }
    return false;
}
Also used : Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) RepositoryContext(org.talend.core.context.RepositoryContext) IRepositoryNodeResourceProvider(org.talend.mdm.repository.core.IRepositoryNodeResourceProvider) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryNodeConfiguration(org.talend.mdm.repository.core.IRepositoryNodeConfiguration) LoginException(org.talend.commons.exception.LoginException) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 3 with IRepositoryNodeResourceProvider

use of org.talend.mdm.repository.core.IRepositoryNodeResourceProvider in project tmdm-studio-se by Talend.

the class AbstractSimpleAddActionTest method setUp.

@Before
public void setUp() throws Exception {
    ResourceBundle rb = mock(ResourceBundle.class);
    // $NON-NLS-1$
    stub(method(ResourceBundle.class, "getBundle", String.class)).toReturn(rb);
    PowerMockito.mockStatic(JFaceResources.class);
    ImageRegistry registry = mock(ImageRegistry.class);
    when(JFaceResources.getImageRegistry()).thenReturn(registry);
    PowerMockito.mockStatic(CoreRuntimePlugin.class);
    CoreRuntimePlugin coreRuntimePlugin = mock(CoreRuntimePlugin.class);
    when(CoreRuntimePlugin.getInstance()).thenReturn(coreRuntimePlugin);
    IProxyRepositoryFactory repositoryFactory = mock(IProxyRepositoryFactory.class);
    when(CoreRuntimePlugin.getInstance().getProxyRepositoryFactory()).thenReturn(repositoryFactory);
    RepositoryContext ontextMock = mock(RepositoryContext.class);
    when(repositoryFactory.getRepositoryContext()).thenReturn(ontextMock);
    PowerMockito.mockStatic(ProjectManager.class);
    ProjectManager pmMock = mock(ProjectManager.class);
    Project pMock = mock(Project.class);
    User userMock = mock(User.class);
    // $NON-NLS-1$
    when(userMock.getLogin()).thenReturn("a@b.cn");
    when(pMock.getAuthor()).thenReturn(userMock);
    when(pmMock.getCurrentProject()).thenReturn(pMock);
    when(ProjectManager.getInstance()).thenReturn(pmMock);
    when(ontextMock.getUser()).thenReturn(userMock);
    IRepositoryResourceUtilExAdapter mockAdapter = PowerMockito.mock(IRepositoryResourceUtilExAdapter.class);
    PowerMockito.mockStatic(ExAdapterManager.class);
    PowerMockito.when(ExAdapterManager.getAdapter(new RepositoryResourceUtil(), IRepositoryResourceUtilExAdapter.class)).thenReturn(mockAdapter);
    RecycleBinNodeConfiguration recycleBinNodeConfiguration = mock(RecycleBinNodeConfiguration.class);
    PowerMockito.whenNew(RecycleBinNodeConfiguration.class).withNoArguments().thenReturn(recycleBinNodeConfiguration);
    PowerMockito.mockStatic(ProxyRepositoryFactory.class);
    ProxyRepositoryFactory proxyRepositoryFactory = mock(ProxyRepositoryFactory.class);
    when(ProxyRepositoryFactory.getInstance()).thenReturn(proxyRepositoryFactory);
    IRepositoryFactory repositoryFactoryMock = mock(IRepositoryFactory.class);
    when(proxyRepositoryFactory.getRepositoryFactoryFromProvider()).thenReturn(repositoryFactoryMock);
    XmiResourceManager xmiResourceManager = mock(XmiResourceManager.class);
    when(repositoryFactoryMock.getResourceManager()).thenReturn(xmiResourceManager);
    PowerMockito.mockStatic(RepositoryNodeConfigurationManager.class);
    IRepositoryNodeConfiguration rncMock = mock(IRepositoryNodeConfiguration.class);
    when(RepositoryNodeConfigurationManager.getConfiguration((Item) anyObject())).thenReturn(rncMock);
    IRepositoryNodeResourceProvider resourceProviderM = mock(IRepositoryNodeResourceProvider.class);
    when(rncMock.getResourceProvider()).thenReturn(resourceProviderM);
    when(resourceProviderM.needSaveReferenceFile()).thenReturn(true);
    when(repositoryFactory.isEditableAndLockIfPossible((Item) anyObject())).thenReturn(true);
}
Also used : RepositoryContext(org.talend.core.context.RepositoryContext) IRepositoryFactory(org.talend.core.repository.model.IRepositoryFactory) User(org.talend.core.model.properties.User) RecycleBinNodeConfiguration(org.talend.mdm.repository.core.impl.recyclebin.RecycleBinNodeConfiguration) IRepositoryResourceUtilExAdapter(org.talend.mdm.repository.utils.IRepositoryResourceUtilExAdapter) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) ProjectManager(org.talend.repository.ProjectManager) Project(org.talend.core.model.general.Project) ImageRegistry(org.eclipse.jface.resource.ImageRegistry) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IRepositoryNodeResourceProvider(org.talend.mdm.repository.core.IRepositoryNodeResourceProvider) IRepositoryNodeConfiguration(org.talend.mdm.repository.core.IRepositoryNodeConfiguration) ResourceBundle(java.util.ResourceBundle) RepositoryResourceUtil(org.talend.mdm.repository.utils.RepositoryResourceUtil) CoreRuntimePlugin(org.talend.core.runtime.CoreRuntimePlugin) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) Before(org.junit.Before)

Example 4 with IRepositoryNodeResourceProvider

use of org.talend.mdm.repository.core.IRepositoryNodeResourceProvider in project tmdm-studio-se by Talend.

the class RemoveFromRepositoryActionTest method setUp.

@Before
public void setUp() throws Exception {
    ResourceBundle rb = mock(ResourceBundle.class);
    // $NON-NLS-1$
    stub(method(ResourceBundle.class, "getBundle", String.class)).toReturn(rb);
    PowerMockito.mockStatic(JFaceResources.class);
    ImageRegistry registry = mock(ImageRegistry.class);
    when(JFaceResources.getImageRegistry()).thenReturn(registry);
    PowerMockito.mockStatic(DefaultMessagesImpl.class);
    // $NON-NLS-1$
    when(DefaultMessagesImpl.getString(anyString())).thenReturn("anyString()");
    IRepositoryResourceUtilExAdapter mockAdapter = PowerMockito.mock(IRepositoryResourceUtilExAdapter.class);
    PowerMockito.mockStatic(ExAdapterManager.class);
    PowerMockito.when(ExAdapterManager.getAdapter(new RepositoryResourceUtil(), IRepositoryResourceUtilExAdapter.class)).thenReturn(mockAdapter);
    PowerMockito.mockStatic(CoreRuntimePlugin.class);
    CoreRuntimePlugin coreRuntimePlugin = mock(CoreRuntimePlugin.class);
    when(CoreRuntimePlugin.getInstance()).thenReturn(coreRuntimePlugin);
    RepositoryContext contextMock = mock(RepositoryContext.class);
    PowerMockito.mockStatic(ProjectManager.class);
    ProjectManager pmMock = mock(ProjectManager.class);
    projectM = mock(Project.class);
    User userMock = mock(User.class);
    // $NON-NLS-1$
    when(userMock.getLogin()).thenReturn("a@b.cn");
    when(projectM.getAuthor()).thenReturn(userMock);
    when(pmMock.getCurrentProject()).thenReturn(projectM);
    when(ProjectManager.getInstance()).thenReturn(pmMock);
    when(contextMock.getUser()).thenReturn(userMock);
    repositoryFactory = mock(ProxyRepositoryFactory.class);
    RecycleBinNodeConfiguration recycleBinNodeConfiguration = mock(RecycleBinNodeConfiguration.class);
    PowerMockito.whenNew(RecycleBinNodeConfiguration.class).withNoArguments().thenReturn(recycleBinNodeConfiguration);
    // $NON-NLS-1$
    stub(method(ProxyRepositoryFactory.class, "getInstance")).toReturn(repositoryFactory);
    when(CoreRuntimePlugin.getInstance().getProxyRepositoryFactory()).thenReturn(repositoryFactory);
    IRepositoryFactory repositoryFactoryMock = mock(IRepositoryFactory.class);
    when(repositoryFactory.getRepositoryFactoryFromProvider()).thenReturn(repositoryFactoryMock);
    XmiResourceManager xmiResourceManager = mock(XmiResourceManager.class);
    when(repositoryFactoryMock.getResourceManager()).thenReturn(xmiResourceManager);
    PowerMockito.mockStatic(RepositoryNodeConfigurationManager.class);
    IRepositoryNodeConfiguration rncMock = mock(IRepositoryNodeConfiguration.class);
    when(RepositoryNodeConfigurationManager.getConfiguration((Item) anyObject())).thenReturn(rncMock);
    IRepositoryNodeResourceProvider resourceProviderM = mock(IRepositoryNodeResourceProvider.class);
    when(rncMock.getResourceProvider()).thenReturn(resourceProviderM);
    when(resourceProviderM.needSaveReferenceFile()).thenReturn(true);
    when(repositoryFactory.getRepositoryContext()).thenReturn(contextMock);
    when(repositoryFactory.isEditableAndLockIfPossible((Item) anyObject())).thenReturn(true);
}
Also used : RepositoryContext(org.talend.core.context.RepositoryContext) IRepositoryFactory(org.talend.core.repository.model.IRepositoryFactory) User(org.talend.core.model.properties.User) RecycleBinNodeConfiguration(org.talend.mdm.repository.core.impl.recyclebin.RecycleBinNodeConfiguration) IRepositoryResourceUtilExAdapter(org.talend.mdm.repository.utils.IRepositoryResourceUtilExAdapter) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) ProjectManager(org.talend.repository.ProjectManager) Project(org.talend.core.model.general.Project) ImageRegistry(org.eclipse.jface.resource.ImageRegistry) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IRepositoryNodeResourceProvider(org.talend.mdm.repository.core.IRepositoryNodeResourceProvider) IRepositoryNodeConfiguration(org.talend.mdm.repository.core.IRepositoryNodeConfiguration) ResourceBundle(java.util.ResourceBundle) RepositoryResourceUtil(org.talend.mdm.repository.utils.RepositoryResourceUtil) CoreRuntimePlugin(org.talend.core.runtime.CoreRuntimePlugin) Before(org.junit.Before)

Example 5 with IRepositoryNodeResourceProvider

use of org.talend.mdm.repository.core.IRepositoryNodeResourceProvider in project tmdm-studio-se by Talend.

the class RepositoryResourceUtilTest method testGetCategoryViewObject.

/**
 * Test for: getCategoryViewObject(IRepositoryNodeConfiguration conf)
 */
@Test
public void testGetCategoryViewObject() throws Exception {
    IRepositoryNodeConfiguration mockConfiguration = mock(IRepositoryNodeConfiguration.class);
    IRepositoryNodeResourceProvider mockResourceProvider = mock(IRepositoryNodeResourceProvider.class);
    when(mockConfiguration.getResourceProvider()).thenReturn(mockResourceProvider);
    ERepositoryObjectType mockType = mock(ERepositoryObjectType.class);
    when(mockConfiguration.getResourceProvider().getRepositoryObjectType(Mockito.any(Item.class))).thenReturn(mockType);
    IRepositoryNodeLabelProvider mockLabelProvider = mock(IRepositoryNodeLabelProvider.class);
    when(mockConfiguration.getLabelProvider()).thenReturn(mockLabelProvider);
    when(mockLabelProvider.getCategoryLabel(Mockito.any(ERepositoryObjectType.class))).thenReturn("anystring");
    PowerMockito.mockStatic(ContainerCacheService.class);
    PowerMockito.doNothing().when(ContainerCacheService.class, "putContainer", Mockito.any(IRepositoryViewObject.class));
    IRepositoryViewObject categoryViewObject = RepositoryResourceUtil.getCategoryViewObject(mockConfiguration);
    assertNotNull(categoryViewObject);
}
Also used : Item(org.talend.core.model.properties.Item) ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) IRepositoryNodeResourceProvider(org.talend.mdm.repository.core.IRepositoryNodeResourceProvider) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IRepositoryNodeConfiguration(org.talend.mdm.repository.core.IRepositoryNodeConfiguration) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IRepositoryNodeLabelProvider(org.talend.mdm.repository.core.IRepositoryNodeLabelProvider) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

IRepositoryNodeConfiguration (org.talend.mdm.repository.core.IRepositoryNodeConfiguration)8 IRepositoryNodeResourceProvider (org.talend.mdm.repository.core.IRepositoryNodeResourceProvider)8 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)6 RepositoryContext (org.talend.core.context.RepositoryContext)4 RecycleBinNodeConfiguration (org.talend.mdm.repository.core.impl.recyclebin.RecycleBinNodeConfiguration)4 ContainerItem (org.talend.mdm.repository.model.mdmproperties.ContainerItem)4 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Item (org.talend.core.model.properties.Item)3 User (org.talend.core.model.properties.User)3 ResourceBundle (java.util.ResourceBundle)2 IPath (org.eclipse.core.runtime.IPath)2 ImageRegistry (org.eclipse.jface.resource.ImageRegistry)2 Before (org.junit.Before)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 Project (org.talend.core.model.general.Project)2 Property (org.talend.core.model.properties.Property)2 IRepositoryFactory (org.talend.core.repository.model.IRepositoryFactory)2 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)2 XmiResourceManager (org.talend.core.repository.utils.XmiResourceManager)2