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();
}
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);
}
}
}
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);
}
}
}
}
}
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;
}
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);
}
}
Aggregations