Search in sources :

Example 26 with MDMServerDef

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;
}
Also used : Item(org.talend.core.model.properties.Item) WSResourceItem(org.talend.mdm.repository.model.mdmproperties.WSResourceItem) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)

Example 27 with MDMServerDef

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]);
}
Also used : Item(org.talend.core.model.properties.Item) JobInfo(com.amalto.workbench.utils.JobInfo) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Property(org.talend.core.model.properties.Property) LinkedList(java.util.LinkedList) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)

Example 28 with MDMServerDef

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;
}
Also used : WSMDMConfig(com.amalto.workbench.webservices.WSMDMConfig) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)

Example 29 with MDMServerDef

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);
    }
}
Also used : TMDMService(com.amalto.workbench.webservices.TMDMService) WSDigestKey(com.amalto.workbench.webservices.WSDigestKey) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) TreeObject(com.amalto.workbench.models.TreeObject) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) WSDigest(com.amalto.workbench.webservices.WSDigest) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 30 with MDMServerDef

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);
    }
}
Also used : HashMap(java.util.HashMap) ImpactOperation(org.talend.mdm.repository.core.service.ModelImpactAnalyseService.ImpactOperation) ArrayList(java.util.ArrayList) CommandManager(org.talend.mdm.repository.core.command.CommandManager) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) AbstractDeployCommand(org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand) Property(org.talend.core.model.properties.Property) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

MDMServerDef (org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)66 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)36 SelectServerDefDialog (org.talend.mdm.workbench.serverexplorer.ui.dialogs.SelectServerDefDialog)15 Item (org.talend.core.model.properties.Item)11 MDMServerDefItem (org.talend.mdm.repository.model.mdmproperties.MDMServerDefItem)10 MDMServerObjectItem (org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem)10 IStatus (org.eclipse.core.runtime.IStatus)8 MDMServerObject (org.talend.mdm.repository.model.mdmserverobject.MDMServerObject)8 PersistenceException (org.talend.commons.exception.PersistenceException)7 AbstractDeployCommand (org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand)7 TMDMService (com.amalto.workbench.webservices.TMDMService)6 CommandManager (org.talend.mdm.repository.core.command.CommandManager)6 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)6 TreeObject (com.amalto.workbench.models.TreeObject)5 XtentisException (com.amalto.workbench.utils.XtentisException)5 ArrayList (java.util.ArrayList)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 LinkedList (java.util.LinkedList)4