Search in sources :

Example 21 with MDMServerObject

use of org.talend.mdm.repository.model.mdmserverobject.MDMServerObject in project tmdm-studio-se by Talend.

the class RenameObjectActionTest method doRunTest.

@Test
public void doRunTest() throws Exception {
    RenameObjectAction renameAction = new RenameObjectAction();
    RenameObjectAction renameActionM = PowerMockito.spy(renameAction);
    CommonViewer commonViewerM = mock(CommonViewer.class);
    // $NON-NLS-1$
    Whitebox.setInternalState(renameActionM, "commonViewer", commonViewerM);
    // mock a mdm repositoryViewObject
    IRepositoryViewObject objectRVO = mock(IRepositoryViewObject.class);
    IRepositoryViewObject parentRVO = mock(IRepositoryViewObject.class);
    MDMServerObjectItem mdmItemM = mock(MDMServerObjectItem.class);
    ContainerItem parentItemM = mock(ContainerItem.class);
    Property propertyM = mock(Property.class);
    Property parentPropertyM = mock(Property.class);
    // $NON-NLS-1$
    String name = "mockName";
    MDMServerObject mdmServerObjectM = mock(MDMServerObject.class);
    when(mdmServerObjectM.getName()).thenReturn(name);
    ItemState itemStateM = mock(ItemState.class);
    // 
    when(objectRVO.getProperty()).thenReturn(propertyM);
    when(propertyM.getItem()).thenReturn(mdmItemM);
    when(mdmItemM.getMDMServerObject()).thenReturn(mdmServerObjectM);
    when(mdmItemM.getState()).thenReturn(itemStateM);
    // $NON-NLS-1$
    when(itemStateM.getPath()).thenReturn("");
    // 
    when(parentRVO.getProperty()).thenReturn(parentPropertyM);
    when(parentPropertyM.getItem()).thenReturn(parentItemM);
    // 
    PowerMockito.mockStatic(RepositoryNodeProviderRegistryReader.class);
    RepositoryNodeProviderRegistryReader reader = mock(RepositoryNodeProviderRegistryReader.class);
    PowerMockito.when(RepositoryNodeProviderRegistryReader.getInstance()).thenReturn(reader);
    ERepositoryObjectType typeM = ERepositoryObjectType.PROCESS;
    when(resourceProviderM.getRepositoryObjectType(mdmItemM)).thenReturn(typeM);
    // $NON-NLS-1$ //$NON-NLS-2$
    PowerMockito.doReturn("NewName").when(renameActionM, "showRenameDlg", typeM, parentItemM, name);
    // 
    PowerMockito.mockStatic(ContainerCacheService.class);
    // $NON-NLS-1$
    when(ContainerCacheService.get(eq(typeM), eq(""))).thenReturn(parentRVO);
    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);
    // 
    when(renameActionM.getSelectedObject()).thenReturn(selectedObjects);
    InputDialog inputDialogM = mock(InputDialog.class);
    PowerMockito.whenNew(InputDialog.class).withArguments(eq(shellM), anyString(), anyString(), anyString(), anyObject()).thenReturn(inputDialogM);
    when(inputDialogM.open()).thenReturn(IDialogConstants.OK_ID);
    // $NON-NLS-1$
    when(inputDialogM.getValue()).thenReturn("NewName");
    renameActionM.doRun();
}
Also used : ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) InputDialog(org.eclipse.jface.dialogs.InputDialog) CommonViewer(org.eclipse.ui.navigator.CommonViewer) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) ArrayList(java.util.ArrayList) RepositoryNodeProviderRegistryReader(org.talend.core.model.repository.RepositoryNodeProviderRegistryReader) Shell(org.eclipse.swt.widgets.Shell) Control(org.eclipse.swt.widgets.Control) ItemState(org.talend.core.model.properties.ItemState) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) 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 22 with MDMServerObject

use of org.talend.mdm.repository.model.mdmserverobject.MDMServerObject in project tmdm-studio-se by Talend.

the class Bean2EObjUtilTest method testWrapEObjWithTreeObject1Args.

/**
 * test wrapEObjWithTreeObject with one input parameter
 */
@Test
public void testWrapEObjWithTreeObject1Args() {
    EObject eobj = null;
    Bean2EObjUtil util = Bean2EObjUtil.getInstance();
    TreeObject treeObject = util.wrapEObjWithTreeObject(eobj);
    assertNull(treeObject);
    MDMServerObject mdmServerObject = PowerMockito.mock(MDMServerObject.class);
    when(mdmServerObject.getName()).thenReturn("name");
    when(mdmServerObject.getType()).thenReturn(2);
    eobj = mdmServerObject;
    treeObject = util.wrapEObjWithTreeObject(eobj);
    assertNotNull(treeObject);
    Mockito.verify(mdmServerObject, Mockito.atLeastOnce()).getName();
    Mockito.verify(mdmServerObject, Mockito.atLeastOnce()).getType();
    assertEquals("name", treeObject.getName());
    assertEquals(2, treeObject.getType());
}
Also used : EObject(org.eclipse.emf.ecore.EObject) TreeObject(com.amalto.workbench.models.TreeObject) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 23 with MDMServerObject

use of org.talend.mdm.repository.model.mdmserverobject.MDMServerObject in project tmdm-studio-se by Talend.

the class RenameProcessAction method renameProcessObject.

private void renameProcessObject(IRepositoryViewObject viewObj) {
    MDMServerObjectItem item = (MDMServerObjectItem) viewObj.getProperty().getItem();
    MDMServerObject serverObject = item.getMDMServerObject();
    int type = getType(item);
    if (serverObject != null) {
        String oldName = serverObject.getName();
        RenameProcessDialog dialog = getRenameDialog(getSite(), oldName, type, getInputValidator());
        int returnCode = dialog.open();
        if (returnCode == Window.OK) {
            IProxyRepositoryFactory factory = getFactory();
            String newName = dialog.getValue();
            transformPath(viewObj, newName);
            try {
                if (factory.isEditableAndLockIfPossible(item)) {
                    serverObject.setName(newName);
                    viewObj.getProperty().setLabel(newName);
                    viewObj.getProperty().setDisplayName(newName);
                    factory.save(item, false);
                    MDMServerDef lastServerDef = RepositoryResourceUtil.getLastServerDef(item);
                    if (lastServerDef != null) {
                        CommandManager.getInstance().pushCommand(ICommand.CMD_RENAME, viewObj.getId(), new String[] { oldName, newName });
                    }
                }
                commonViewer.refresh(viewObj);
            } catch (PersistenceException e) {
                log.error(e.getMessage(), e);
            } finally {
                try {
                    factory.unlock(item);
                } catch (PersistenceException e) {
                    log.error(e.getMessage(), e);
                } catch (LoginException e) {
                    log.error(e.getMessage(), e);
                }
            }
        }
    }
}
Also used : MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)

Example 24 with MDMServerObject

use of org.talend.mdm.repository.model.mdmserverobject.MDMServerObject in project tmdm-studio-se by Talend.

the class XObjectEditor2 method saveResourceToRepository.

private boolean saveResourceToRepository() {
    XObjectEditorInput2 editorInput = (XObjectEditorInput2) this.getEditorInput();
    TreeObject xobject = (TreeObject) editorInput.getModel();
    IRepositoryViewObject viewObject = editorInput.getViewObject();
    IRepositoryViewObject refreshViewObject = RepositoryResourceUtil.assertViewObject(viewObject);
    if (viewObject != refreshViewObject) {
        editorInput.updateViewObject(refreshViewObject);
    }
    MDMServerObjectItem serverObjectItem = (MDMServerObjectItem) editorInput.getInputItem();
    MDMServerObject serverObject = serverObjectItem.getMDMServerObject();
    EObject eObj = Bean2EObjUtil.getInstance().convertFromBean2EObj(xobject.getWsObject(), serverObject);
    if (eObj != null) {
        IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
        try {
            factory.save(serverObjectItem);
            // TODO should call the following,but the page in editor has many call to remote webService ,it will
            // search ServerRoot which cause a NPE
            // xobject.fireEvent(IXObjectModelListener.SAVE, xobject.getParent(), xobject);
            editorDirtyStateChanged();
            refreshDirtyCue();
            DeployService deployService = DeployService.getInstance();
            if (deployService.isAutoDeploy()) {
                autoDeployProcess(deployService);
            } else {
                MDMServerDef lastServerDef = RepositoryResourceUtil.getLastServerDef(serverObjectItem);
                if (lastServerDef != null) {
                    CommandManager.getInstance().pushCommand(ICommand.CMD_MODIFY, editorInput.getViewObject());
                }
            }
            return true;
        } catch (PersistenceException e) {
            log.error(e.getMessage(), e);
        }
    }
    return false;
}
Also used : MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) EObject(org.eclipse.emf.ecore.EObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) TreeObject(com.amalto.workbench.models.TreeObject) DeployService(org.talend.mdm.repository.core.service.DeployService) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)

Example 25 with MDMServerObject

use of org.talend.mdm.repository.model.mdmserverobject.MDMServerObject in project tmdm-studio-se by Talend.

the class MDMServiceConfigrationMainPage method setForConfigureContent.

@Override
protected void setForConfigureContent(String serviceName) {
    try {
        if (serviceName != null && !"".equals(serviceName)) {
            // $NON-NLS-1$
            document = getServiceDocument(serviceName.trim());
            XObjectEditorInput2 editorInput = (XObjectEditorInput2) getEditorInput();
            MDMServerObjectItem serverObjectItem = (MDMServerObjectItem) editorInput.getInputItem();
            MDMServerObject serverObject = serverObjectItem.getMDMServerObject();
            String configContent = null;
            if (serverObject instanceof WSServiceConfigurationE) {
                WSServiceConfigurationE object = (WSServiceConfigurationE) serverObject;
                for (WSServicePutConfigurationE config : object.getServicePutConfigurations()) {
                    if (config.getJndiName().equals(serviceName.trim())) {
                        configContent = config.getConfiguration();
                    }
                }
            }
            serviceConfigurationsText.setText(configContent);
            // $NON-NLS-1$
            errorLabel.setText("");
        }
    } catch (WebServiceException e1) {
        log.error(e1.getMessage(), e1);
    }
}
Also used : WSServicePutConfigurationE(org.talend.mdm.repository.model.mdmserverobject.WSServicePutConfigurationE) WebServiceException(javax.xml.ws.WebServiceException) WSServiceConfigurationE(org.talend.mdm.repository.model.mdmserverobject.WSServiceConfigurationE) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject)

Aggregations

MDMServerObject (org.talend.mdm.repository.model.mdmserverobject.MDMServerObject)37 MDMServerObjectItem (org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem)33 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)19 Item (org.talend.core.model.properties.Item)13 TreeObject (com.amalto.workbench.models.TreeObject)11 Property (org.talend.core.model.properties.Property)11 PersistenceException (org.talend.commons.exception.PersistenceException)9 Test (org.junit.Test)7 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)7 MDMServerDef (org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)7 ContainerItem (org.talend.mdm.repository.model.mdmproperties.ContainerItem)7 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 LoginException (org.talend.commons.exception.LoginException)6 EObject (org.eclipse.emf.ecore.EObject)5 ArrayList (java.util.ArrayList)4 FolderItem (org.talend.core.model.properties.FolderItem)4 TMDMService (com.amalto.workbench.webservices.TMDMService)3 LinkedList (java.util.LinkedList)3 ItemState (org.talend.core.model.properties.ItemState)3