Search in sources :

Example 26 with MDMServerObjectItem

use of org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem 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 27 with MDMServerObjectItem

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

the class RenameViewAction method moveToAnotherNode.

public void moveToAnotherNode(IRepositoryViewObject parent, IRepositoryViewObject viewObj) {
    MDMServerObjectItem item = (MDMServerObjectItem) viewObj.getProperty().getItem();
    waitSomeTime(viewObj);
    IProxyRepositoryFactory factory = getFactory();
    try {
        if (factory.isEditableAndLockIfPossible(item)) {
            String path = item.getState().getPath();
            IPath ipath = new Path(path);
            factory.moveObject(viewObj, ipath);
            IRepositoryViewObject iRepositoryViewObject = ContainerCacheService.get(viewObj.getRepositoryObjectType(), path);
            commonViewer.refresh(iRepositoryViewObject);
            commonViewer.refresh(parent);
        }
    } catch (PersistenceException e) {
        log.error(e.getMessage(), e);
    } catch (BusinessException 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 : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) BusinessException(org.talend.commons.exception.BusinessException) IPath(org.eclipse.core.runtime.IPath) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 28 with MDMServerObjectItem

use of org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem 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 29 with MDMServerObjectItem

use of org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem 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 30 with MDMServerObjectItem

use of org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem 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

MDMServerObjectItem (org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem)50 MDMServerObject (org.talend.mdm.repository.model.mdmserverobject.MDMServerObject)33 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)28 Item (org.talend.core.model.properties.Item)22 Property (org.talend.core.model.properties.Property)15 PersistenceException (org.talend.commons.exception.PersistenceException)13 ContainerItem (org.talend.mdm.repository.model.mdmproperties.ContainerItem)12 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)11 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)10 LoginException (org.talend.commons.exception.LoginException)9 MDMServerDef (org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)9 TreeObject (com.amalto.workbench.models.TreeObject)7 Test (org.junit.Test)7 TMDMService (com.amalto.workbench.webservices.TMDMService)6 LinkedList (java.util.LinkedList)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 BusinessException (org.talend.commons.exception.BusinessException)5 FolderItem (org.talend.core.model.properties.FolderItem)5 ProcessItem (org.talend.core.model.properties.ProcessItem)5 ArrayList (java.util.ArrayList)4