Search in sources :

Example 1 with WSDigest

use of com.amalto.workbench.webservices.WSDigest in project tmdm-studio-se by Talend.

the class ConsistencyConflictDialog method getCompareResult.

private CompareResultEnum getCompareResult(IRepositoryViewObject viewObj) {
    CompareResultEnum result = compareResultMap.get(viewObj);
    if (result == null) {
        ERepositoryObjectType viewType = viewObj.getRepositoryObjectType();
        if (viewType == IServerObjectRepositoryType.TYPE_RESOURCE || viewType == IServerObjectRepositoryType.TYPE_JOB || viewType == IServerObjectRepositoryType.TYPE_WORKFLOW) {
            result = CompareResultEnum.NOT_SUPPORT;
        } else {
            WSDigest dt = viewObjMap.get(viewObj);
            if (dt == null) {
                result = CompareResultEnum.NOT_EXIST_IN_SERVER;
            } else {
                Item item = viewObj.getProperty().getItem();
                ConsistencyService service = ConsistencyService.getInstance();
                String ld = service.getLocalDigestValue(item);
                String cd = service.getCurrentDigestValue(item);
                String rd = dt.getDigestValue();
                result = service.getCompareResult(cd, ld, rd);
            }
        }
        compareResultMap.put(viewObj, result);
    }
    return result;
}
Also used : Item(org.talend.core.model.properties.Item) TreeItem(org.eclipse.swt.widgets.TreeItem) CompareResultEnum(org.talend.mdm.repository.core.service.ConsistencyService.CompareResultEnum) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) WSDigest(com.amalto.workbench.webservices.WSDigest) ConsistencyService(org.talend.mdm.repository.core.service.ConsistencyService)

Example 2 with WSDigest

use of com.amalto.workbench.webservices.WSDigest in project tmdm-studio-se by Talend.

the class ConsistencyService method queryServerDigestValue.

public <T> Map<T, WSDigest> queryServerDigestValue(MDMServerDef serverDef, Collection<T> objs) throws XtentisException {
    Map<T, WSDigest> result = new LinkedHashMap<T, WSDigest>();
    TMDMService service = RepositoryWebServiceAdapter.getMDMService(serverDef);
    if (isSupportConsistency(service)) {
        for (T obj : objs) {
            String type = null;
            String objectName = null;
            if (obj instanceof IRepositoryViewObject) {
                IRepositoryViewObject viewObj = (IRepositoryViewObject) obj;
                type = viewObj.getRepositoryObjectType().getKey();
                objectName = viewObj.getLabel();
            } else if (obj instanceof TreeObject) {
                TreeObject treeObj = (TreeObject) obj;
                ERepositoryObjectType repositoryObjectType = RepositoryQueryService.getRepositoryObjectType(treeObj.getType());
                if (repositoryObjectType != null) {
                    type = repositoryObjectType.getKey();
                    objectName = getObjectName(treeObj);
                }
            }
            if (type != null && objectName != null) {
                WSDigest digest = service.getDigest(new WSDigestKey(objectName, type));
                result.put(obj, digest);
            }
        }
    }
    return result;
}
Also used : TMDMService(com.amalto.workbench.webservices.TMDMService) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) WSDigestKey(com.amalto.workbench.webservices.WSDigestKey) TreeObject(com.amalto.workbench.models.TreeObject) WSDigest(com.amalto.workbench.webservices.WSDigest) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with WSDigest

use of com.amalto.workbench.webservices.WSDigest in project tmdm-studio-se by Talend.

the class ConsistencyService method getConflictCount.

private int getConflictCount(Map<IRepositoryViewObject, WSDigest> map) {
    int total = 0;
    for (IRepositoryViewObject viewObj : map.keySet()) {
        WSDigest digestTime = map.get(viewObj);
        if (digestTime == null) {
            continue;
        }
        String rd = digestTime.getDigestValue();
        if (digestTime != null && rd != null) {
            Item item = viewObj.getProperty().getItem();
            String ld = getLocalDigestValue(item);
            String cd = getCurrentDigestValue(item);
            CompareResultEnum result = getCompareResult(cd, ld, rd);
            if (result == CompareResultEnum.CONFLICT || result == CompareResultEnum.POTENTIAL_CONFLICT) {
                total++;
            }
        }
    }
    return total;
}
Also used : ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) Item(org.talend.core.model.properties.Item) ProcessItem(org.talend.core.model.properties.ProcessItem) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) WSDigest(com.amalto.workbench.webservices.WSDigest)

Example 4 with WSDigest

use of com.amalto.workbench.webservices.WSDigest in project tmdm-studio-se by Talend.

the class TreeObjectCheckTreeViewer method initConsistencyData.

private Map<TreeObject, ConsistencyData> initConsistencyData(MDMServerDef serverDef, List<TreeObject> treeObjs) {
    Map<TreeObject, ConsistencyData> map = new HashMap<TreeObject, ConsistencyData>();
    try {
        ConsistencyService consistencyService = ConsistencyService.getInstance();
        Map<TreeObject, WSDigest> serverDigestValues = consistencyService.queryServerDigestValue(serverDef, treeObjs);
        if (treeObjs.size() > 0 && serverDigestValues.isEmpty()) {
            return map;
        }
        for (TreeObject treeObject : treeObjs) {
            ConsistencyData consistencyData = new ConsistencyData();
            WSDigest serverDigestTime = serverDigestValues.get(treeObject);
            consistencyData.setServerDigestTime(serverDigestTime);
            String objName = getTreeObjectName(treeObject);
            ERepositoryObjectType viewType = RepositoryQueryService.getRepositoryObjectType(treeObject.getType());
            if (viewType == null) {
                continue;
            }
            if (viewType == IServerObjectRepositoryType.TYPE_RESOURCE || viewType == IServerObjectRepositoryType.TYPE_JOB || viewType == IServerObjectRepositoryType.TYPE_WORKFLOW) {
                consistencyData.setCompareResult(CompareResultEnum.NOT_SUPPORT);
            } else {
                IRepositoryViewObject viewObj = RepositoryResourceUtil.findViewObjectByName(viewType, objName);
                if (viewObj == null) {
                    consistencyData.setCompareResult(CompareResultEnum.NOT_EXIST_IN_LOCAL);
                } else {
                    consistencyService.updateCurrentDigestValue(viewObj);
                    Item item = viewObj.getProperty().getItem();
                    String ld = consistencyService.getLocalDigestValue(item);
                    String cd = consistencyService.getCurrentDigestValue(item);
                    long localTimestamp = consistencyService.getLocalTimestamp(item);
                    // key
                    String type = viewObj.getRepositoryObjectType().getKey();
                    String objectName = viewObj.getLabel();
                    WSDigestKey key = new WSDigestKey(objectName, type);
                    consistencyData.setLocalDigestTime(new WSDigest(ld, localTimestamp, key));
                    // init compare result;
                    CompareResultEnum result;
                    if (serverDigestTime == null || serverDigestTime.getDigestValue() == null) {
                        result = CompareResultEnum.NOT_EXIST_IN_SERVER;
                    } else {
                        String rd = serverDigestTime.getDigestValue();
                        result = consistencyService.getCompareResult(cd, ld, rd);
                    }
                    consistencyData.setCompareResult(result);
                }
            }
            map.put(treeObject, consistencyData);
        }
    } catch (WebServiceException e) {
        log.error(e.getMessage(), e);
    } catch (XtentisException e) {
        log.error(e.getMessage(), e);
    }
    return map;
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) HashMap(java.util.HashMap) WSDigestKey(com.amalto.workbench.webservices.WSDigestKey) WSDigest(com.amalto.workbench.webservices.WSDigest) ConsistencyService(org.talend.mdm.repository.core.service.ConsistencyService) Item(org.talend.core.model.properties.Item) TreeItem(org.eclipse.swt.widgets.TreeItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) TreeObject(com.amalto.workbench.models.TreeObject) CompareResultEnum(org.talend.mdm.repository.core.service.ConsistencyService.CompareResultEnum) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) ConsistencyData(org.talend.mdm.repository.core.service.ConsistencyService.ConsistencyData) XtentisException(com.amalto.workbench.utils.XtentisException)

Example 5 with WSDigest

use of com.amalto.workbench.webservices.WSDigest 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)

Aggregations

WSDigest (com.amalto.workbench.webservices.WSDigest)8 Item (org.talend.core.model.properties.Item)6 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)6 WSDigestKey (com.amalto.workbench.webservices.WSDigestKey)5 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)5 TreeObject (com.amalto.workbench.models.TreeObject)3 TMDMService (com.amalto.workbench.webservices.TMDMService)3 TreeItem (org.eclipse.swt.widgets.TreeItem)3 ProcessItem (org.talend.core.model.properties.ProcessItem)3 ReferenceFileItem (org.talend.core.model.properties.ReferenceFileItem)3 ConsistencyService (org.talend.mdm.repository.core.service.ConsistencyService)3 CompareResultEnum (org.talend.mdm.repository.core.service.ConsistencyService.CompareResultEnum)3 MDMServerObjectItem (org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem)3 XtentisException (com.amalto.workbench.utils.XtentisException)2 WebServiceException (javax.xml.ws.WebServiceException)2 ConsistencyData (org.talend.mdm.repository.core.service.ConsistencyService.ConsistencyData)2 WSLong (com.amalto.workbench.webservices.WSLong)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1