Search in sources :

Example 1 with IModelValidateResult

use of org.talend.mdm.repository.core.service.IModelValidationService.IModelValidateResult in project tmdm-studio-se by Talend.

the class MDMValidationRunner method runInWorkspace.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.core.resources.WorkspaceJob#runInWorkspace(org.eclipse.core.runtime.IProgressMonitor)
     */
@SuppressWarnings({ "restriction", "hiding" })
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
    if (UIUtil.isWorkInUI() && lockDirtyDialog.needShowDialog()) {
        Display.getDefault().syncExec(new Runnable() {

            @Override
            public void run() {
                if (lockDirtyDialog.open() == IDialogConstants.CANCEL_ID) {
                    setReturnCode(IDialogConstants.CANCEL_ID);
                } else {
                    lockDirtyDialog.saveDirtyObjects();
                }
            }
        });
        if (getReturnCode() == IDialogConstants.CANCEL_ID) {
            setValidateResult(new MDMValidationService.ModelValidateResult());
            return Status.CANCEL_STATUS;
        }
    }
    final ValOperation vo = ValidationRunner.validate(toValidate, ValType.Manual, monitor, false);
    if (vo.isCanceled()) {
        setValidateResult(new MDMValidationService.ModelValidateResult());
        return Status.CANCEL_STATUS;
    }
    final ValidationResultSummary result = vo.getResult();
    final IModelValidateResult validateResult = new MDMValidationService.ModelValidateResult(viewObjMap);
    if (needShowValidationResults(result)) {
        final Set<IResource> resources = toValidate.values().iterator().next();
        Display.getDefault().syncExec(new Runnable() {

            @Override
            public void run() {
                ValidationResultDialog d = new ValidationResultDialog(new Shell(), result, validationPref, viewObjMap);
                int code = d.open();
                validateResult.setSelectedButton(code);
                setValidateResult(validateResult);
            }
        });
    } else {
        setValidateResult(validateResult);
        if (validateResult.hasErrOrWarning()) {
            int code = ValidationPreferenceService.getInstance().getDeployActionWhenValidateFail();
            validateResult.setSelectedButton(code);
        } else {
            validateResult.setSelectedButton(IModelValidationService.BUTTON_OK);
        }
    }
    activeProblemView(result);
    return Status.OK_STATUS;
}
Also used : ValidationResultSummary(org.eclipse.wst.validation.internal.ValidationResultSummary) IModelValidateResult(org.talend.mdm.repository.core.service.IModelValidationService.IModelValidateResult) IModelValidateResult(org.talend.mdm.repository.core.service.IModelValidationService.IModelValidateResult) Shell(org.eclipse.swt.widgets.Shell) ValidationResultDialog(org.talend.mdm.repository.ui.dialogs.ValidationResultDialog) ValOperation(org.eclipse.wst.validation.internal.ValOperation) IResource(org.eclipse.core.resources.IResource)

Example 2 with IModelValidateResult

use of org.talend.mdm.repository.core.service.IModelValidationService.IModelValidateResult in project tmdm-studio-se by Talend.

the class DeployServiceTest method testDeploy4params.

@Test
public void testDeploy4params() {
    MDMServerDef mockServerDef = PowerMockito.mock(MDMServerDef.class);
    List<IRepositoryViewObject> viewObjs = new ArrayList<IRepositoryViewObject>();
    int defaultCmdType = ICommand.CMD_MODIFY;
    boolean removeLocked = true;
    int selectedButton = IModelValidationService.BUTTON_CANCEL;
    IModelValidateResult mockValidateResult = PowerMockito.mock(IModelValidateResult.class);
    DeployService mockDeployService = PowerMockito.mock(DeployService.class);
    PowerMockito.when(mockDeployService.deploy(any(MDMServerDef.class), anyListOf(IRepositoryViewObject.class), eq(defaultCmdType), eq(removeLocked))).thenCallRealMethod();
    IRepositoryViewObject mockViewObj = PowerMockito.mock(IRepositoryViewObject.class);
    viewObjs.add(mockViewObj);
    PowerMockito.mockStatic(RepositoryResourceUtil.class);
    PowerMockito.mockStatic(ConsistencyService.class);
    try {
        // check selection of cancel for validating model
        PowerMockito.when(mockValidateResult.getSelectedButton()).thenReturn(selectedButton);
        PowerMockito.when(mockDeployService.validateModel(anyListOf(IRepositoryViewObject.class))).thenReturn(mockValidateResult);
        IStatus deployStatus = mockDeployService.deploy(mockServerDef, viewObjs, defaultCmdType, removeLocked);
        assertEquals(Status.CANCEL_STATUS, deployStatus);
        verify(mockDeployService).validateModel(viewObjs);
        // check selection of ok for validating model
        selectedButton = IModelValidationService.BUTTON_OK;
        List<IRepositoryViewObject> invalidViewObjs = new ArrayList<IRepositoryViewObject>();
        IRepositoryViewObject mockInvalidViewObj = PowerMockito.mock(IRepositoryViewObject.class);
        invalidViewObjs.add(mockInvalidViewObj);
        PowerMockito.when(mockValidateResult.getSelectedButton()).thenReturn(selectedButton);
        PowerMockito.when(mockValidateResult.getValidObjects(eq(selectedButton))).thenReturn(viewObjs);
        PowerMockito.when(mockValidateResult.getInvalidObjects(eq(selectedButton))).thenReturn(invalidViewObjs);
        PowerMockito.when(mockDeployService.validateModel(anyListOf(IRepositoryViewObject.class))).thenReturn(mockValidateResult);
        // // check consistency null and cancel
        PowerMockito.mockStatic(ConsistencyService.class);
        ConsistencyService mockConsistencyService = PowerMockito.mock(ConsistencyService.class);
        PowerMockito.when(ConsistencyService.getInstance()).thenReturn(mockConsistencyService);
        // 
        ConsistencyCheckResult mockConsistencyCheckResult = null;
        PowerMockito.when(mockConsistencyService.checkConsistency(any(MDMServerDef.class), anyListOf(IRepositoryViewObject.class))).thenReturn(mockConsistencyCheckResult);
        deployStatus = mockDeployService.deploy(mockServerDef, viewObjs, defaultCmdType, removeLocked);
        assertEquals(Status.CANCEL_STATUS, deployStatus);
        // 
        mockConsistencyCheckResult = PowerMockito.mock(ConsistencyCheckResult.class);
        PowerMockito.when(mockConsistencyCheckResult.isCanceled()).thenReturn(true);
        PowerMockito.when(mockConsistencyService.checkConsistency(any(MDMServerDef.class), anyListOf(IRepositoryViewObject.class))).thenReturn(mockConsistencyCheckResult);
        deployStatus = mockDeployService.deploy(mockServerDef, viewObjs, defaultCmdType, removeLocked);
        assertEquals(Status.CANCEL_STATUS, deployStatus);
        // // check without impact dialog
        PowerMockito.when(mockConsistencyCheckResult.isCanceled()).thenReturn(false);
        PowerMockito.when(mockConsistencyCheckResult.getToDeployObjects()).thenReturn(viewObjs);
        List<AbstractDeployCommand> deployCommands = new ArrayList<AbstractDeployCommand>();
        deployCommands.add(PowerMockito.mock(AbstractDeployCommand.class));
        PowerMockito.when(mockDeployService.runCommands(anyListOf(AbstractDeployCommand.class), any(MDMServerDef.class))).thenReturn(Status.OK_STATUS);
        PowerMockito.mockStatic(CommandManager.class);
        CommandManager mockCommandManager = PowerMockito.mock(CommandManager.class);
        PowerMockito.when(CommandManager.getInstance()).thenReturn(mockCommandManager);
        PowerMockito.when(mockCommandManager.getDeployCommands(anyListOf(IRepositoryViewObject.class), anyInt())).thenReturn(deployCommands);
        PowerMockito.mockStatic(UIUtil.class);
        PowerMockito.when(UIUtil.isWorkInUI()).thenReturn(false);
        deployStatus = mockDeployService.deploy(mockServerDef, viewObjs, defaultCmdType, removeLocked);
        assertEquals(Status.OK_STATUS, deployStatus);
        verify(mockDeployService, atLeastOnce()).runCommands(deployCommands, mockServerDef);
        verify(mockDeployService, atLeastOnce()).updateServerConsistencyStatus(mockServerDef, Status.OK_STATUS);
        verify(mockDeployService, atLeastOnce()).generateValidationFailedDeployStatus(Status.OK_STATUS, invalidViewObjs);
        // // check with normal executed impact dialog
        PowerMockito.when(UIUtil.isWorkInUI()).thenReturn(true);
        PowerMockito.mockStatic(ModelImpactAnalyseService.class);
        deployStatus = mockDeployService.deploy(mockServerDef, viewObjs, defaultCmdType, removeLocked);
        assertEquals(Status.OK_STATUS, deployStatus);
        PowerMockito.verifyStatic();
        ModelImpactAnalyseService.analyzeCommandImpact(mockServerDef, deployCommands);
        // // check with interrupted impact dialog
        PowerMockito.when(ModelImpactAnalyseService.analyzeCommandImpact(any(MDMServerDef.class), anyListOf(AbstractDeployCommand.class))).thenThrow(new InterruptedException());
        deployStatus = mockDeployService.deploy(mockServerDef, viewObjs, defaultCmdType, removeLocked);
        assertEquals(Status.CANCEL_STATUS, deployStatus);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : IModelValidateResult(org.talend.mdm.repository.core.service.IModelValidationService.IModelValidateResult) IStatus(org.eclipse.core.runtime.IStatus) ArrayList(java.util.ArrayList) CommandManager(org.talend.mdm.repository.core.command.CommandManager) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ConsistencyCheckResult(org.talend.mdm.repository.core.service.ConsistencyService.ConsistencyCheckResult) AbstractDeployCommand(org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with IModelValidateResult

use of org.talend.mdm.repository.core.service.IModelValidationService.IModelValidateResult in project tmdm-studio-se by Talend.

the class DeployAllAction method runWithType.

public void runWithType(ERepositoryObjectType type) {
    DeployAllDialog dialog = new DeployAllDialog(getShell(), type);
    if (dialog.open() == IDialogConstants.OK_ID) {
        List<AbstractDeployCommand> selectededCommands = dialog.getSelectedCommands();
        if (selectededCommands.size() >= 0) {
            DeployService deployService = DeployService.getInstance();
            deployViewObject = deployService.getDeployViewObject(selectededCommands);
            // validate object
            IModelValidateResult validateResult = deployService.validateModel(deployViewObject);
            int selectedButton = validateResult.getSelectedButton();
            if (selectedButton == IModelValidationService.BUTTON_CANCEL) {
                return;
            }
            List<IRepositoryViewObject> validObjects = validateResult.getValidObjects(selectedButton);
            List<IRepositoryViewObject> invalidObjects = validateResult.getInvalidObjects(selectedButton);
            // 
            MDMServerDef serverDef = dialog.getServerDef();
            try {
                // consistency check
                ConsistencyCheckResult consistencyCheckResult = deployService.checkConsistency(serverDef, validObjects, selectededCommands);
                if (consistencyCheckResult.isCanceled()) {
                    return;
                } else {
                    validObjects = consistencyCheckResult.getToDeployObjects();
                }
                deployService.removeInvalidCommands(invalidObjects, selectededCommands);
                deployService.removeInvalidCommands(consistencyCheckResult.getToSkipObjects(), selectededCommands);
                // save editors
                LockedDirtyObjectDialog lockDirtyDialog = new LockedDirtyObjectDialog(getShell(), Messages.AbstractDeployAction_promptToSaveEditors, validObjects);
                if (lockDirtyDialog.needShowDialog() && lockDirtyDialog.open() == IDialogConstants.CANCEL_ID) {
                    return;
                }
                lockDirtyDialog.saveDirtyObjects();
                // insert impact dialog
                List<AbstractDeployCommand> canceledCommandAfterImpactAnalysis = new LinkedList<AbstractDeployCommand>(selectededCommands);
                try {
                    Map<IRepositoryViewObject, ImpactOperation> analyzeModelImpact = ModelImpactAnalyseService.analyzeCommandImpact(serverDef, selectededCommands);
                    Map<IRepositoryViewObject, ICommandParameter> paramMap = null;
                    if (analyzeModelImpact != null) {
                        ModelImpactAnalyseService.shrinkDeployCommands(analyzeModelImpact, selectededCommands);
                        paramMap = ModelImpactAnalyseService.convertToParameters(analyzeModelImpact);
                        CommandManager.getInstance().attachParameterToCommand(selectededCommands, paramMap);
                    }
                    canceledCommandAfterImpactAnalysis.removeAll(selectededCommands);
                } catch (InterruptedException ex) {
                    return;
                }
                IStatus status = deployService.runCommands(selectededCommands, serverDef);
                // update consistency value
                try {
                    deployService.updateServerConsistencyStatus(serverDef, status);
                } catch (XtentisException e) {
                    log.error(e.getMessage(), e);
                } catch (WebServiceException e) {
                    log.error(e.getMessage(), e);
                }
                // add canceled object to status
                deployService.generateValidationFailedDeployStatus(status, invalidObjects);
                deployService.generateConsistencyCancelDeployStatus(status, consistencyCheckResult.getToSkipObjects().toArray(new IRepositoryViewObject[0]));
                for (AbstractDeployCommand cmd : canceledCommandAfterImpactAnalysis) {
                    deployService.generateConsistencyCancelDeployStatus(status, cmd.getViewObject());
                }
                // 
                updateChangedStatus(status);
                if (status.isMultiStatus()) {
                    showDeployStatus(status);
                }
                updateLastServer(status, new NullProgressMonitor());
            } catch (Exception e) {
                String url = // $NON-NLS-1$
                serverDef.getProtocol() + serverDef.getHost() + ":" + serverDef.getPort() + serverDef.getPath();
                String title = Messages.bind(Messages.Server_cannot_connected, url);
                MessageDialog.openError(getShell(), title, Messages.AbstractDataClusterAction_ConnectFailed);
            }
        }
    }
}
Also used : IModelValidateResult(org.talend.mdm.repository.core.service.IModelValidationService.IModelValidateResult) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) WebServiceException(javax.xml.ws.WebServiceException) ImpactOperation(org.talend.mdm.repository.core.service.ModelImpactAnalyseService.ImpactOperation) ICommandParameter(org.talend.mdm.repository.core.command.param.ICommandParameter) DeployService(org.talend.mdm.repository.core.service.DeployService) DeployAllDialog(org.talend.mdm.repository.ui.dialogs.deploy.DeployAllDialog) LinkedList(java.util.LinkedList) XtentisException(com.amalto.workbench.utils.XtentisException) WebServiceException(javax.xml.ws.WebServiceException) LockedDirtyObjectDialog(org.talend.mdm.repository.ui.dialogs.lock.LockedDirtyObjectDialog) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ConsistencyCheckResult(org.talend.mdm.repository.core.service.ConsistencyService.ConsistencyCheckResult) AbstractDeployCommand(org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef) XtentisException(com.amalto.workbench.utils.XtentisException)

Example 4 with IModelValidateResult

use of org.talend.mdm.repository.core.service.IModelValidationService.IModelValidateResult in project tmdm-studio-se by Talend.

the class DeployService method deploy.

public IStatus deploy(MDMServerDef serverDef, List<IRepositoryViewObject> viewObjs, int defaultCmdType, boolean removeLocked) {
    if (removeLocked) {
        removeLockedViewObj(viewObjs);
    }
    IModelValidateResult validateResult = validateModel(viewObjs);
    int selectedButton = validateResult.getSelectedButton();
    if (selectedButton == IModelValidationService.BUTTON_CANCEL) {
        return Status.CANCEL_STATUS;
    }
    List<IRepositoryViewObject> validObjects = validateResult.getValidObjects(selectedButton);
    List<IRepositoryViewObject> invalidObjects = validateResult.getInvalidObjects(selectedButton);
    try {
        // consistency check
        ConsistencyCheckResult consistencyCheckResult = ConsistencyService.getInstance().checkConsistency(serverDef, validObjects);
        if (consistencyCheckResult == null || consistencyCheckResult.isCanceled()) {
            return Status.CANCEL_STATUS;
        }
        validObjects = consistencyCheckResult.getToDeployObjects();
        // 
        CommandManager manager = CommandManager.getInstance();
        List<AbstractDeployCommand> commands = manager.getDeployCommands(validObjects, defaultCmdType);
        // insert impact dialog
        List<AbstractDeployCommand> canceledCommandAfterImpactAnalysis = new LinkedList<AbstractDeployCommand>(commands);
        if (UIUtil.isWorkInUI()) {
            try {
                Map<IRepositoryViewObject, ImpactOperation> analyzeModelImpact = ModelImpactAnalyseService.analyzeCommandImpact(serverDef, commands);
                Map<IRepositoryViewObject, ICommandParameter> paramMap = null;
                if (analyzeModelImpact != null) {
                    ModelImpactAnalyseService.shrinkDeployCommands(analyzeModelImpact, commands);
                    paramMap = ModelImpactAnalyseService.convertToParameters(analyzeModelImpact);
                    manager.attachParameterToCommand(commands, paramMap);
                }
                canceledCommandAfterImpactAnalysis.removeAll(commands);
            } catch (InterruptedException ex) {
                return Status.CANCEL_STATUS;
            }
        }
        IStatus mainStatus = runCommands(commands, serverDef);
        // update consistency value
        try {
            updateServerConsistencyStatus(serverDef, mainStatus);
        } catch (XtentisException e) {
            log.error(e.getMessage(), e);
        } catch (WebServiceException e) {
            log.error(e.getMessage(), e);
        }
        // 
        generateValidationFailedDeployStatus(mainStatus, invalidObjects);
        if (UIUtil.isWorkInUI()) {
            generateConsistencyCancelDeployStatus(mainStatus, consistencyCheckResult.getToSkipObjects().toArray(new IRepositoryViewObject[0]));
            for (AbstractDeployCommand cmd : canceledCommandAfterImpactAnalysis) {
                generateConsistencyCancelDeployStatus(mainStatus, cmd.getViewObject());
            }
        }
        return mainStatus;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        String url = // $NON-NLS-1$
        serverDef.getProtocol() + serverDef.getHost() + ":" + serverDef.getPort() + serverDef.getPath();
        String title = Messages.bind(Messages.Server_cannot_connected, url);
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title, Messages.AbstractDataClusterAction_ConnectFailed);
        return Status.CANCEL_STATUS;
    }
}
Also used : IModelValidateResult(org.talend.mdm.repository.core.service.IModelValidationService.IModelValidateResult) IStatus(org.eclipse.core.runtime.IStatus) WebServiceException(javax.xml.ws.WebServiceException) ImpactOperation(org.talend.mdm.repository.core.service.ModelImpactAnalyseService.ImpactOperation) ICommandParameter(org.talend.mdm.repository.core.command.param.ICommandParameter) LinkedList(java.util.LinkedList) XtentisException(com.amalto.workbench.utils.XtentisException) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebServiceException(javax.xml.ws.WebServiceException) CommandManager(org.talend.mdm.repository.core.command.CommandManager) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ConsistencyCheckResult(org.talend.mdm.repository.core.service.ConsistencyService.ConsistencyCheckResult) AbstractDeployCommand(org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand) XtentisException(com.amalto.workbench.utils.XtentisException)

Example 5 with IModelValidateResult

use of org.talend.mdm.repository.core.service.IModelValidationService.IModelValidateResult in project tmdm-studio-se by Talend.

the class DeployService method validateModel.

public IModelValidateResult validateModel(List<IRepositoryViewObject> viewObjs) {
    IModelValidationService service = (IModelValidationService) GlobalServiceRegister.getDefault().getService(IModelValidationService.class);
    IModelValidateResult validateResult = service.validate(viewObjs, IModelValidationService.VALIDATE_BEFORE_DEPLOY, false);
    return validateResult;
}
Also used : IModelValidateResult(org.talend.mdm.repository.core.service.IModelValidationService.IModelValidateResult)

Aggregations

IModelValidateResult (org.talend.mdm.repository.core.service.IModelValidationService.IModelValidateResult)5 IStatus (org.eclipse.core.runtime.IStatus)3 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)3 AbstractDeployCommand (org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand)3 ConsistencyCheckResult (org.talend.mdm.repository.core.service.ConsistencyService.ConsistencyCheckResult)3 XtentisException (com.amalto.workbench.utils.XtentisException)2 LinkedList (java.util.LinkedList)2 WebServiceException (javax.xml.ws.WebServiceException)2 CommandManager (org.talend.mdm.repository.core.command.CommandManager)2 ICommandParameter (org.talend.mdm.repository.core.command.param.ICommandParameter)2 ImpactOperation (org.talend.mdm.repository.core.service.ModelImpactAnalyseService.ImpactOperation)2 MDMServerDef (org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 IResource (org.eclipse.core.resources.IResource)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Shell (org.eclipse.swt.widgets.Shell)1 ValOperation (org.eclipse.wst.validation.internal.ValOperation)1 ValidationResultSummary (org.eclipse.wst.validation.internal.ValidationResultSummary)1 Test (org.junit.Test)1