Search in sources :

Example 11 with AbstractDeployCommand

use of org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand in project tmdm-studio-se by Talend.

the class AbstractInteractiveHandlerTest method testDeploy.

@Test
public void testDeploy() {
    MDMServerObject mockServerObject = PowerMockito.mock(MDMServerObject.class);
    MDMServerObjectItem mockServerObjectItem = PowerMockito.mock(MDMServerObjectItem.class);
    PowerMockito.when(mockServerObjectItem.getMDMServerObject()).thenReturn(mockServerObject);
    Property mockProperty = PowerMockito.mock(Property.class);
    PowerMockito.when(mockProperty.getItem()).thenReturn(mockServerObjectItem);
    IRepositoryViewObject mockViewObj = PowerMockito.mock(IRepositoryViewObject.class);
    PowerMockito.when(mockViewObj.getProperty()).thenReturn(mockProperty);
    AbstractDeployCommand mockDeployCommand = PowerMockito.mock(AbstractDeployCommand.class);
    PowerMockito.when(mockDeployCommand.getViewObject()).thenReturn(mockViewObj);
    AbstractInteractiveHandler mockInteractiveHandler = PowerMockito.mock(AbstractInteractiveHandler.class);
    try {
        PowerMockito.when(mockInteractiveHandler.deploy(any(AbstractDeployCommand.class))).thenCallRealMethod();
        PowerMockito.when(mockInteractiveHandler.doDeployWSObject(any(TMDMService.class), any())).thenReturn(true);
        TMDMService mockService = PowerMockito.mock(TMDMService.class);
        // $NON-NLS-1$
        PowerMockito.when(mockInteractiveHandler, "getService", any(MDMServerDef.class)).thenReturn(mockService);
        Object mockWsObj = new Object();
        PowerMockito.when(mockInteractiveHandler.convert(any(Item.class), any(MDMServerObject.class))).thenReturn(mockWsObj);
        boolean deployed = mockInteractiveHandler.deploy(mockDeployCommand);
        assertTrue(deployed);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : Item(org.talend.core.model.properties.Item) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) TMDMService(com.amalto.workbench.webservices.TMDMService) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) AbstractDeployCommand(org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Property(org.talend.core.model.properties.Property) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) Test(org.junit.Test)

Example 12 with AbstractDeployCommand

use of org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand in project tmdm-studio-se by Talend.

the class DeployAllDialog method createDialogArea.

/**
 * Create contents of the dialog.
 *
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
    mainContainer = (Composite) super.createDialogArea(parent);
    GridLayout mainContainerLayout = (GridLayout) mainContainer.getLayout();
    mainContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    mainContainerLayout.numColumns = 2;
    Label lblNewLabel_selserver = new Label(mainContainer, SWT.NONE);
    lblNewLabel_selserver.setText(Messages.DeployAllDialog_label_selectserver);
    lblNewLabel_selserver.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
    errorLabel = new Label(mainContainer, SWT.NONE);
    errorLabelLayoutData = new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1);
    errorLabelLayoutData.exclude = true;
    errorLabel.setLayoutData(errorLabelLayoutData);
    errorLabel.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
    comboViewer = new ComboViewer(mainContainer, SWT.DROP_DOWN | SWT.READ_ONLY);
    Combo combo = comboViewer.getCombo();
    GridData data = new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1);
    combo.setLayoutData(data);
    comboViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            MDMServerDef serverDef = (MDMServerDef) element;
            // $NON-NLS-1$ //$NON-NLS-2$;
            return serverDef.getName() + " (" + serverDef.getHost() + ")";
        }
    });
    comboViewer.setContentProvider(new ArrayContentProvider());
    Label emptyLabel = new Label(mainContainer, SWT.NONE);
    GridData emptydata = new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1);
    emptydata.widthHint = 98;
    emptyLabel.setLayoutData(emptydata);
    List<MDMServerDef> allServerDefs = ServerDefService.getAllServerDefs();
    comboViewer.setInput(allServerDefs);
    comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            serverDef = (MDMServerDef) ((IStructuredSelection) comboViewer.getSelection()).getFirstElement();
            treeViewer.updateCurrentServerDef(null, serverDef);
            updateErrorMsgArea(treeViewer.isServerOk());
        }
    });
    final Button reconciliationBun = new Button(mainContainer, SWT.CHECK);
    reconciliationBun.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            treeViewer.enableReconciliation(reconciliationBun.getSelection());
        }
    });
    reconciliationBun.setText(Messages.DeployAllDialog_reconciliation);
    reconciliationBun.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
    Composite container = new Composite(mainContainer, SWT.BORDER);
    container.setLayout(new GridLayout(2, false));
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    Label lblNewLabel = new Label(container, SWT.NONE);
    lblNewLabel.setText(Messages.DeployAllDialog_label);
    new Label(container, SWT.NONE);
    List<AbstractDeployCommand> commands = CommandManager.getInstance().getAllDeployCommands();
    treeViewer = new RepositoryViewObjectCheckedWidget(container, initType, commands);
    treeViewer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3));
    Button selAllButton = new Button(container, SWT.NONE);
    selAllButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            treeViewer.selectAll(true);
        }
    });
    selAllButton.setText(Messages.DeployAllDialog_selectAll);
    Button deselAllBun = new Button(container, SWT.NONE);
    deselAllBun.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
    deselAllBun.setText(Messages.DeployAllDialog_deselectAll);
    deselAllBun.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            treeViewer.selectAll(false);
        }
    });
    Button skipDeployedBun = new Button(container, SWT.NONE);
    skipDeployedBun.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
    skipDeployedBun.setText(Messages.DeployAllDialog_skipDeployed);
    skipDeployedBun.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            treeViewer.skipDeployedObjects();
        }
    });
    initComboSelect();
    return container;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) RepositoryViewObjectCheckedWidget(org.talend.mdm.repository.ui.widgets.RepositoryViewObjectCheckedWidget) GridLayout(org.eclipse.swt.layout.GridLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) AbstractDeployCommand(org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand) LabelProvider(org.eclipse.jface.viewers.LabelProvider) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)

Example 13 with AbstractDeployCommand

use of org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand in project tmdm-studio-se by Talend.

the class ModelImpactAnalyseService method shrinkDeployCommands.

public static void shrinkDeployCommands(Map<IRepositoryViewObject, ImpactOperation> impactResult, List<AbstractDeployCommand> commands) {
    Set<IRepositoryViewObject> toRemoveKeys = new HashSet<IRepositoryViewObject>();
    Iterator<AbstractDeployCommand> il = commands.iterator();
    while (il.hasNext()) {
        AbstractDeployCommand cmd = il.next();
        IRepositoryViewObject viewObject = cmd.getViewObject();
        if (viewObject != null) {
            ERepositoryObjectType type = viewObject.getRepositoryObjectType();
            if (type == IServerObjectRepositoryType.TYPE_DATAMODEL) {
                ImpactOperation operation = impactResult.get(viewObject);
                if (operation == ImpactOperation.CANCEL) {
                    il.remove();
                    toRemoveKeys.add(viewObject);
                }
            } else if (type == IServerObjectRepositoryType.TYPE_MATCH_RULE_MAPINFO || type == IServerObjectRepositoryType.TYPE_TDS) {
                String label = viewObject.getLabel();
                for (IRepositoryViewObject modelViewObj : impactResult.keySet()) {
                    if (modelViewObj.getLabel().equals(label)) {
                        ImpactOperation operation = impactResult.get(modelViewObj);
                        if (operation == ImpactOperation.CANCEL) {
                            il.remove();
                        }
                    }
                }
            }
        }
    }
    for (IRepositoryViewObject key : toRemoveKeys) {
        impactResult.remove(key);
    }
}
Also used : IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) AbstractDeployCommand(org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) HashSet(java.util.HashSet)

Example 14 with AbstractDeployCommand

use of org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand in project tmdm-studio-se by Talend.

the class RemoveFromServerAction method doRun.

protected void doRun() {
    SelectServerDefDialog dialog = new SelectServerDefDialog(getShell());
    if (dialog.open() == IDialogConstants.OK_ID) {
        // save editors
        LockedDirtyObjectDialog lockDirtyDialog = new LockedDirtyObjectDialog(getShell(), Messages.AbstractDeployAction_promptToSaveEditors, getSelectedRepositoryViewObject());
        if (lockDirtyDialog.needShowDialog() && lockDirtyDialog.open() == IDialogConstants.CANCEL_ID) {
            return;
        }
        lockDirtyDialog.saveDirtyObjects();
        // remove
        MDMServerDef serverDef = dialog.getSelectedServerDef();
        List<AbstractDeployCommand> commands = new LinkedList<AbstractDeployCommand>();
        CommandManager commandManager = CommandManager.getInstance();
        for (Object obj : getSelectedObject()) {
            IRepositoryViewObject viewObj = (IRepositoryViewObject) obj;
            ICommand deleteCommand = commandManager.getNewCommand(ICommand.CMD_DELETE);
            deleteCommand.init(viewObj);
            commands.add((AbstractDeployCommand) deleteCommand);
        }
        // 
        IStatus status = DeployService.getInstance().runCommands(commands, serverDef);
        if (status.isMultiStatus()) {
            showDeployStatus(status);
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) CommandManager(org.talend.mdm.repository.core.command.CommandManager) ICommand(org.talend.mdm.repository.core.command.ICommand) LockedDirtyObjectDialog(org.talend.mdm.repository.ui.dialogs.lock.LockedDirtyObjectDialog) SelectServerDefDialog(org.talend.mdm.workbench.serverexplorer.ui.dialogs.SelectServerDefDialog) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) AbstractDeployCommand(org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef) LinkedList(java.util.LinkedList)

Example 15 with AbstractDeployCommand

use of org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand 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)

Aggregations

AbstractDeployCommand (org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand)21 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)16 CommandManager (org.talend.mdm.repository.core.command.CommandManager)8 IStatus (org.eclipse.core.runtime.IStatus)7 MDMServerDef (org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)7 ArrayList (java.util.ArrayList)6 LinkedList (java.util.LinkedList)6 ICommand (org.talend.mdm.repository.core.command.ICommand)6 ICommandParameter (org.talend.mdm.repository.core.command.param.ICommandParameter)5 ImpactOperation (org.talend.mdm.repository.core.service.ModelImpactAnalyseService.ImpactOperation)4 Test (org.junit.Test)3 ConsistencyCheckResult (org.talend.mdm.repository.core.service.ConsistencyService.ConsistencyCheckResult)3 IModelValidateResult (org.talend.mdm.repository.core.service.IModelValidationService.IModelValidateResult)3 XtentisException (com.amalto.workbench.utils.XtentisException)2 HashSet (java.util.HashSet)2 WebServiceException (javax.xml.ws.WebServiceException)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Property (org.talend.core.model.properties.Property)2 CommandStack (org.talend.mdm.repository.core.command.CommandStack)2