Search in sources :

Example 96 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class AnalysisExecutorHelper method check.

/**
 * Method "check" checks that the analysis can be run.
 *
 * @param analysis the analysis to prepare
 * @return true if ok.
 */
public static ReturnCode check(Analysis analysis) {
    ReturnCode rc = new ReturnCode(Boolean.TRUE);
    // --- check existence of context
    AnalysisContext context = analysis.getContext();
    if (context == null) {
        // $NON-NLS-1$
        rc.setMessage(Messages.getString("AnalysisExecutor.ContextNull", analysis.getName()));
        rc.setOk(Boolean.FALSE);
        return rc;
    }
    // --- check that there exists at least on element to analyze
    if (context.getAnalysedElements().size() == 0) {
        // $NON-NLS-1$
        rc.setMessage(Messages.getString("ColumnAnalysisExecutor.AnalysisHaveAtLeastOneColumn"));
        rc.setOk(Boolean.FALSE);
        return rc;
    }
    // --- check that the connection has been set
    DataManager connection = context.getConnection();
    if (connection == null) {
        // $NON-NLS-1$
        rc.setMessage(Messages.getString("AnalysisExecutor.NoConnectionFound", analysis.getName()));
        rc.setOk(Boolean.FALSE);
        return rc;
    }
    if (log.isInfoEnabled()) {
        if (SoftwaredeploymentPackage.eINSTANCE.getDataProvider().isInstance(connection)) {
            // MOD 20130225 TDQ-6632 the name of the item should be given (not the pathname)
            // $NON-NLS-1$
            log.info(Messages.getString("AnalysisExecutor.CONNECTIONTO", connection.getName()));
        }
    }
    AnalysisResult results = analysis.getResults();
    if (results == null) {
        // $NON-NLS-1$
        rc.setMessage(Messages.getString("AnalysisExecutor.AnalysisnotNotPrepareCorrect", analysis.getName()));
        rc.setOk(Boolean.FALSE);
        return rc;
    }
    // --- check the the dependeny files are exists ADDED mzhao TDQ-10428---
    rc = checkDependentFiles(analysis);
    return rc;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult)

Example 97 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class AnalysisExecutorHelper method checkDependentFiles.

/**
 * Check the dependent file's existance. <br>
 * 1. If exist, do "hot" content copy from dependent file to built-in. <br>
 * 2. If not exist 1) built-in content is not empty, do nothing, 2) built-in content is empty, ReturnCode = false
 * and return. <br>
 * 3. Load indicator from built-in content.
 *
 * @param analysis
 * @return
 */
private static ReturnCode checkDependentFiles(Analysis analysis) {
    ReturnCode rc = new ReturnCode(Boolean.TRUE);
    List<Indicator> indicators = analysis.getResults().getIndicators();
    if (indicators.size() == 0) {
        rc.setOk(false);
        // $NON-NLS-1$
        rc.setMessage(Messages.getString("AnalysisExecutor.AnalysisNoIndicators", analysis.getName()));
        return rc;
    }
    // Loop indicators , check the dependeny file's existence.
    for (Indicator indicator : indicators) {
        if (indicator.getBuiltInIndicatorDefinition() != null) {
            // Built-in indicator already exist.
            continue;
        }
        // check pattern matching indicator
        rc = checkPatternMatchingIndicator(indicator);
        if (!rc.isOk()) {
            break;
        }
        // Check Indicators
        rc = checkIndicator(indicator);
        if (!rc.isOk()) {
            break;
        }
    }
    return rc;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) AllMatchIndicator(org.talend.dataquality.indicators.columnset.AllMatchIndicator) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) CompositeIndicator(org.talend.dataquality.indicators.CompositeIndicator)

Example 98 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class AnalysisExecutorHelper method checkIndicatorWithChild.

/**
 * DOC zhao Comment method "checkIndicatorWithChild".
 *
 * @param indicator
 * @return
 */
private static ReturnCode checkIndicatorWithChild(Indicator indicator) {
    ReturnCode rc = new ReturnCode(Boolean.TRUE);
    if (indicator.getBuiltInIndicatorDefinition() != null) {
        return rc;
    }
    // Get indicator definition from dependent file
    IndicatorDefinition dependentDefinition = indicator.getIndicatorDefinition();
    if (isDependentFileExist(dependentDefinition)) {
        IndicatorDefinition deepCopiedDefinition;
        if (dependentDefinition instanceof WhereRule) {
            deepCopiedDefinition = copyWhereRule((WhereRule) dependentDefinition);
        } else {
            deepCopiedDefinition = EObjectHelper.deepCopy(dependentDefinition);
        }
        // Hot copy to built-in definition.
        deepCopiedDefinition.getSupplierDependency().clear();
        // TDQ-10737 Because 'BuiltInIndicatorDefinition' is a containment reference, need to Clear these 3 non-containment
        // reference list
        deepCopiedDefinition.getCategories().clear();
        deepCopiedDefinition.getAggregatedDefinitions().clear();
        deepCopiedDefinition.getSubCategories().clear();
        indicator.setBuiltInIndicatorDefinition(deepCopiedDefinition);
        EMFUtil.saveResource(indicator.eResource());
    } else {
        IndicatorDefinition builtInDefinition = indicator.getBuiltInIndicatorDefinition();
        if (builtInDefinition == null) {
            // $NON-NLS-1$
            rc.setMessage(Messages.getString("AnalysisExecutor.BuiltInNoIndicators"));
            rc.setOk(false);
            return rc;
        } else {
            indicator.setIndicatorDefinition(null);
        }
    }
    return rc;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) WhereRule(org.talend.dataquality.rules.WhereRule) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Example 99 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ResourceService method initResourcePersistence.

/**
 * DOC bzhou Comment method "initResourcePersistence".
 */
public static ReturnCode initResourcePersistence() {
    ReturnCode rc = new ReturnCode();
    try {
        IPath[] allPathes = EResourceConstant.getPathes();
        if (allPathes != null) {
            for (IPath path : allPathes) {
                IFolder folder = ResourceManager.getRootProject().getFolder(path);
                if (folder.exists()) {
                    QualifiedName[] qualifications = EResourceConstant.findQualificationsByPath(path.toString());
                    for (QualifiedName qualification : qualifications) {
                        if (qualification == ResourceConstant.READONLY) {
                            setReadOnlyProperty(folder);
                        }
                        if (qualification == ResourceConstant.NO_SUBFOLDER) {
                            setNoSubFolderProperty(folder);
                        }
                    }
                }
            }
        }
        rc.setOk(true);
    } catch (CoreException e) {
        rc.setOk(false);
        rc.setMessage(e.getMessage());
    }
    return rc;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) QualifiedName(org.eclipse.core.runtime.QualifiedName) IFolder(org.eclipse.core.resources.IFolder)

Example 100 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ReloadDatabaseAction method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
public void run() {
    returnCode = new ReturnCode(true);
    if (!isSupport()) {
        // $NON-NLS-1$
        returnCode.setReturnCode(Messages.getString("ReloadDatabaseAction.NotSupportMessage"), false);
        return;
    }
    // MOD TDQ-7528 20130627 yyin: if needCompare=false,no need to popup select compare dialog
    if (this.needCompare) {
        // popup a dialog to warn the user better do the compare before the reload, and provide two buttons:
        // if the user click the compare button, the compare will be executed.
        // if the user click the reload button, the reload will continue.
        // $NON-NLS-1$
        String[] dialogButtonLabels = { Messages.getString("ReloadDatabaseAction.ReloadLabel") };
        MessageDialog dialog = new MessageDialog(CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.getString("ReloadDatabaseAction.ReloadLabel"), null, Messages.getString("ReloadDatabaseAction.IsContinue"), 3, dialogButtonLabels, // $NON-NLS-1$ //$NON-NLS-2$
        SWT.NONE);
        int open = dialog.open();
        // when click close, do nothing.
        if (open == -1) {
            return;
        }
    // when click compare
    // if (open == 0) {
    // // go to compare instead of reloading now
    // new PopComparisonUIAction(selectedObject, Messages.getString("ReloadDatabaseAction.CompareLabel")).run();//$NON-NLS-1$
    // returnCode.setReturnCode(Messages.getString("ReloadDatabaseAction.IsContinue"), false);//$NON-NLS-1$
    // return;
    // }// ~
    }
    Connection conn = getConnection();
    List<ModelElement> dependencyClients = EObjectHelper.getDependencyClients(conn);
    if (!(dependencyClients == null || dependencyClients.isEmpty())) {
        int isOk = DeleteModelElementConfirmDialog.showElementImpactConfirmDialog(null, new ModelElement[] { conn }, // $NON-NLS-1$
        DefaultMessagesImpl.getString("TOPRepositoryService.dependcyTile"), // $NON-NLS-1$
        DefaultMessagesImpl.getString("TOPRepositoryService.dependcyMessage", conn.getLabel()));
        if (isOk != Dialog.OK) {
            // $NON-NLS-1$
            returnCode.setReturnCode("The user canceled the operation!", false);
            return;
        }
    }
    IRunnableWithProgress op = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            final IComparisonLevel creatComparisonLevel = ComparisonLevelFactory.creatComparisonLevel(selectedObject);
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    try {
                        Connection oldDataProvider = creatComparisonLevel.reloadCurrentLevelElement();
                        // MOD mzhao 2009-07-13 bug 7454 Impact existing analysis.
                        // MOD qiongli 2011-9-8,move method 'impactExistingAnalyses(...)' to class WorkbenchUtils
                        // update the sql explore.
                        Property property = PropertyHelper.getProperty(oldDataProvider);
                        if (property != null) {
                            Item newItem = property.getItem();
                            if (newItem != null) {
                                CWMPlugin.getDefault().updateConnetionAliasByName(oldDataProvider, oldDataProvider.getLabel());
                            }
                        }
                        // update the related analyses.
                        WorkbenchUtils.impactExistingAnalyses(oldDataProvider);
                        // Update software system.
                        updateSoftwareSystem(oldDataProvider);
                    } catch (ReloadCompareException e) {
                        // $NON-NLS-1$
                        MessageUI.openError(Messages.getString("ReloadDatabaseAction.Error", e.getMessage()));
                        log.error(e, e);
                        returnCode.setReturnCode(e.getMessage(), false);
                    } catch (PartInitException e) {
                        log.error(e, e);
                        returnCode.setReturnCode(e.getMessage(), false);
                    }
                }
            });
        }
    };
    try {
        ProgressUI.popProgressDialog(op);
        CorePlugin.getDefault().refreshDQView(selectedObject);
    } catch (InvocationTargetException e) {
        // $NON-NLS-1$
        MessageUI.openError(Messages.getString("ReloadDatabaseAction.checkConnectionFailured", e.getCause().getMessage()));
        log.error(e, e);
    } catch (InterruptedException e) {
        log.error(e, e);
    }
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) ReloadCompareException(org.talend.cwm.compare.exception.ReloadCompareException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Item(org.talend.core.model.properties.Item) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) PartInitException(org.eclipse.ui.PartInitException) Property(org.talend.core.model.properties.Property) IComparisonLevel(org.talend.cwm.compare.factory.IComparisonLevel)

Aggregations

ReturnCode (org.talend.utils.sugars.ReturnCode)175 ArrayList (java.util.ArrayList)42 TypedReturnCode (org.talend.utils.sugars.TypedReturnCode)42 Test (org.junit.Test)29 File (java.io.File)26 Connection (org.talend.core.model.metadata.builder.connection.Connection)26 Indicator (org.talend.dataquality.indicators.Indicator)25 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)20 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)18 Analysis (org.talend.dataquality.analysis.Analysis)18 Property (org.talend.core.model.properties.Property)17 IFile (org.eclipse.core.resources.IFile)16 IRepositoryNode (org.talend.repository.model.IRepositoryNode)16 IFolder (org.eclipse.core.resources.IFolder)15 SQLException (java.sql.SQLException)14 PersistenceException (org.talend.commons.exception.PersistenceException)11 TdColumn (org.talend.cwm.relational.TdColumn)11 IOException (java.io.IOException)10 EObject (org.eclipse.emf.ecore.EObject)10 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)10