use of org.talend.mdm.repository.model.mdmmetadata.MDMServerDef in project tmdm-studio-se by Talend.
the class MdmPropertiesWizard method performFinish.
@Override
public boolean performFinish() {
if (alreadyEditedByUser) {
return false;
}
IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
Item item = object.getProperty().getItem();
String newName = object.getLabel();
MDMServerObject serverObject = ((MDMServerObjectItem) item).getMDMServerObject();
if (serverObject != null) {
String oldName = serverObject.getName();
try {
if (newName != null && factory.isEditableAndLockIfPossible(item)) {
serverObject.setName(newName);
item = RepositoryResourceUtil.assertItem(item);
factory.save(item, false);
MDMServerDef lastServerDef = RepositoryResourceUtil.getLastServerDef(item);
if (!oldName.equals(newName) && lastServerDef != null) {
CommandManager.getInstance().pushCommand(ICommand.CMD_RENAME, object.getId(), new String[] { oldName, newName });
}
}
} catch (PersistenceException e) {
MessageBoxExceptionHandler.process(e);
return false;
} finally {
try {
factory.unlock(item);
} catch (PersistenceException e) {
MessageBoxExceptionHandler.process(e);
return false;
} catch (LoginException e) {
MessageBoxExceptionHandler.process(e);
return false;
}
}
}
return true;
}
use of org.talend.mdm.repository.model.mdmmetadata.MDMServerDef in project tmdm-studio-se by Talend.
the class RepositoryJobInfoHolder method getExternalInfo.
@Override
public JobInfo[] getExternalInfo() {
List<JobInfo> results = new LinkedList<JobInfo>();
List<IRepositoryViewObject> viewObjs = RepositoryResourceUtil.findAllViewObjects(ERepositoryObjectType.PROCESS);
for (IRepositoryViewObject viewObj : viewObjs) {
Property prop = viewObj.getProperty();
String path = null;
if (prop != null) {
Item item = prop.getItem();
if (item != null) {
path = item.getState().getPath();
}
}
MDMServerDef serverDef = RepositoryResourceUtil.getLastServerDef(viewObj);
String lastServerName = (serverDef != null) ? serverDef.getName() : null;
// the suffix should be "war" or "zip", now use "" to replace
// $NON-NLS-1$
JobInfo jobInfo = new JobInfo(prop.getLabel(), prop.getVersion(), "", path, lastServerName);
results.add(jobInfo);
}
return results.toArray(new JobInfo[0]);
}
use of org.talend.mdm.repository.model.mdmmetadata.MDMServerDef in project tmdm-studio-se by Talend.
the class RepositoryMDMServerInfoHolder method getExternalInfo.
@Override
public WSMDMConfig[] getExternalInfo() {
List<MDMServerDef> allServerDefs = ServerDefService.getAllServerDefs(true);
WSMDMConfig[] configs = new WSMDMConfig[allServerDefs.size()];
int i = 0;
for (MDMServerDef def : allServerDefs) {
configs[i] = new WSMDMConfig();
configs[i].setServerName(def.getHost());
configs[i].setServerPort(def.getPort());
configs[i].setUserName(def.getUser());
configs[i].setPassword(def.getPasswd());
configs[i].setXdbID(def.getName());
i++;
}
return configs;
}
use of org.talend.mdm.repository.model.mdmmetadata.MDMServerDef in project tmdm-studio-se by Talend.
the class ConsistencyServiceTest method testQueryServerDigestValue.
@Test
public void testQueryServerDigestValue() {
MDMServerDef serverDef = MdmmetadataFactory.eINSTANCE.createMDMServerDef();
serverDef.setAlgorithm(PasswordUtil.ALGORITHM_COMMON_V2);
// $NON-NLS-1$
String url = "http://localhost:8180/talendmdm/service/soap?wsdl";
serverDef.parse(url);
serverDef.setUrl(url);
// $NON-NLS-1$
serverDef.setName("MyServer");
// $NON-NLS-1$
serverDef.setUser("admin");
// $NON-NLS-1$
serverDef.setPasswd("talend");
// $NON-NLS-1$
String label = "Product";
ERepositoryObjectType type = IServerObjectRepositoryType.TYPE_DATAMODEL;
try {
WSDigest mockDigest = PowerMockito.mock(WSDigest.class);
TMDMService mockService = PowerMockito.mock(TMDMService.class);
PowerMockito.when(mockService.getDigest(Mockito.any(WSDigestKey.class))).thenReturn(mockDigest);
PowerMockito.mockStatic(RepositoryWebServiceAdapter.class);
PowerMockito.when(RepositoryWebServiceAdapter.getMDMService(serverDef)).thenReturn(mockService);
// IRepositoryViewObject
IRepositoryViewObject mockViewObj = PowerMockito.mock(IRepositoryViewObject.class);
PowerMockito.when(mockViewObj.getLabel()).thenReturn(label);
PowerMockito.when(mockViewObj.getRepositoryObjectType()).thenReturn(type);
// /////////
Map<IRepositoryViewObject, WSDigest> queryServerDigestValue = ConsistencyService.getInstance().queryServerDigestValue(serverDef, Collections.singleton(mockViewObj));
assertNotNull(queryServerDigestValue);
assertTrue(queryServerDigestValue.size() == 1);
assertEquals(mockViewObj, queryServerDigestValue.keySet().iterator().next());
assertEquals(mockDigest, queryServerDigestValue.values().iterator().next());
// TreeObject
TreeObject mockTreeObj = PowerMockito.mock(TreeObject.class);
PowerMockito.when(mockTreeObj.getDisplayName()).thenReturn(label);
PowerMockito.when(mockTreeObj.getType()).thenReturn(1);
PowerMockito.mockStatic(RepositoryQueryService.class);
PowerMockito.when(RepositoryQueryService.getRepositoryObjectType(anyInt())).thenReturn(type);
ConsistencyService mockCService = PowerMockito.mock(ConsistencyService.class);
// $NON-NLS-1$
PowerMockito.when(mockCService, "getObjectName", any(TreeObject.class)).thenReturn(label);
// $NON-NLS-1$
PowerMockito.when(mockCService, "isSupportConsistency", any(TMDMService.class)).thenReturn(true);
PowerMockito.when(mockCService.queryServerDigestValue(any(MDMServerDef.class), anySetOf(TreeObject.class))).thenCallRealMethod();
Map<TreeObject, WSDigest> serverDigestValue = mockCService.queryServerDigestValue(serverDef, Collections.singleton(mockTreeObj));
assertNotNull(serverDigestValue);
assertTrue(serverDigestValue.size() >= 0);
if (serverDigestValue.size() > 0) {
assertEquals(mockTreeObj, serverDigestValue.keySet().iterator().next());
assertEquals(mockDigest, serverDigestValue.values().iterator().next());
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of org.talend.mdm.repository.model.mdmmetadata.MDMServerDef in project tmdm-studio-se by Talend.
the class DeployServiceTest method testDeployAnotherVersion.
@Test
public void testDeployAnotherVersion() {
try {
MDMServerDef mockServerDef = PowerMockito.mock(MDMServerDef.class);
IRepositoryViewObject mockViewObj = PowerMockito.mock(IRepositoryViewObject.class);
Property mockProperty = PowerMockito.mock(Property.class);
PowerMockito.when(mockViewObj.getProperty()).thenReturn(mockProperty);
List<IRepositoryViewObject> repositoryViewObjs = new ArrayList<IRepositoryViewObject>(Arrays.asList(mockViewObj));
PowerMockito.mockStatic(CommandManager.class);
CommandManager mockCommandManager = PowerMockito.mock(CommandManager.class);
PowerMockito.when(CommandManager.getInstance()).thenReturn(mockCommandManager);
List<AbstractDeployCommand> deployCommands = new ArrayList<AbstractDeployCommand>();
deployCommands.add(PowerMockito.mock(AbstractDeployCommand.class));
PowerMockito.when(mockCommandManager.getDeployCommandsWithoutHistory(anyListOf(IRepositoryViewObject.class))).thenReturn(deployCommands);
PowerMockito.mockStatic(ModelImpactAnalyseService.class);
DeployService mockDeployService = PowerMockito.mock(DeployService.class);
PowerMockito.when(mockDeployService.deployAnotherVersion(any(MDMServerDef.class), anyListOf(IRepositoryViewObject.class))).thenCallRealMethod();
// //
mockDeployService.deployAnotherVersion(mockServerDef, repositoryViewObjs);
// //
Mockito.verify(mockDeployService).runCommands(deployCommands, mockServerDef);
PowerMockito.verifyStatic();
ModelImpactAnalyseService.analyzeCommandImpact(any(MDMServerDef.class), anyListOf(AbstractDeployCommand.class));
// ---------
Map<IRepositoryViewObject, ImpactOperation> analyzeModelImpact = new HashMap<IRepositoryViewObject, ModelImpactAnalyseService.ImpactOperation>();
ImpactOperation mockImpactOperation = PowerMockito.mock(ImpactOperation.class);
analyzeModelImpact.put(mockViewObj, mockImpactOperation);
PowerMockito.when(ModelImpactAnalyseService.analyzeCommandImpact(any(MDMServerDef.class), anyListOf(AbstractDeployCommand.class))).thenReturn(analyzeModelImpact);
// //
mockDeployService.deployAnotherVersion(mockServerDef, repositoryViewObjs);
// //
Mockito.verify(mockDeployService, times(2)).runCommands(deployCommands, mockServerDef);
PowerMockito.verifyStatic(times(2));
ModelImpactAnalyseService.analyzeCommandImpact(any(MDMServerDef.class), anyListOf(AbstractDeployCommand.class));
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
Aggregations