Search in sources :

Example 6 with ReturnCode

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

the class ColumnAnalysisDetailsPage method canSave.

@Override
public ReturnCode canSave() {
    // MOD by gdbu 2011-3-21 bug 19179
    ReturnCode canModRetCode = super.canSave();
    if (!canModRetCode.isOk()) {
        return canModRetCode;
    }
    // ~19179
    List<ModelElement> analyzedElement = new ArrayList<ModelElement>();
    for (ModelElementIndicator modelElementIndicator : treeViewer.getModelElementIndicator()) {
        IRepositoryViewObject modelElementRepositoryObj = modelElementIndicator.getModelElementRepositoryNode().getObject();
        if (modelElementRepositoryObj instanceof MetadataColumnRepositoryObject) {
            analyzedElement.add(((MetadataColumnRepositoryObject) modelElementRepositoryObj).getTdColumn());
        }
    }
    if (!analyzedElement.isEmpty()) {
        if (!ModelElementHelper.isFromSameTable(analyzedElement) && !"".equals(dataFilterComp.getDataFilterString())) {
            // $NON-NLS-1$
            return new ReturnCode(DefaultMessagesImpl.getString("ColumnMasterDetailsPage.CannotCreatAnalysis"), false);
        }
    }
    if (!this.isValidateRowCount()) {
        // $NON-NLS-1$
        return new ReturnCode(DefaultMessagesImpl.getString("MatchMasterDetailsPage.LoadedRowCountError"), false);
    }
    return new ReturnCode(true);
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) ReturnCode(org.talend.utils.sugars.ReturnCode) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator)

Example 7 with ReturnCode

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

the class ColumnSetAnalysisDetailsPage method canSave.

@Override
public ReturnCode canSave() {
    // MOD by gdbu 2011-3-21 bug 19179
    ReturnCode canModRetCode = super.canSave();
    if (!canModRetCode.isOk()) {
        return canModRetCode;
    }
    // ~19179
    String message = null;
    List<IRepositoryNode> columnSetMultiValueList = this.treeViewer.getColumnSetMultiValueList();
    // MOD yyi 2011-02-16 17871:delimitefile
    List<ModelElement> columnList = new ArrayList<ModelElement>();
    // MOD klliu 2001-03-28 19464 filter column from same table
    Set<EObject> nodeTypeName = new HashSet<EObject>();
    for (IRepositoryNode rd : columnSetMultiValueList) {
        ModelElement modelElementFromRepositoryNode = RepositoryNodeHelper.getModelElementFromRepositoryNode(rd);
        EObject eContainer = modelElementFromRepositoryNode.eContainer();
        nodeTypeName.add(eContainer);
        columnList.add(RepositoryNodeHelper.getModelElementFromRepositoryNode(rd));
    }
    if (nodeTypeName.size() > 1) {
        // $NON-NLS-1$
        return new ReturnCode(DefaultMessagesImpl.getString("ColumnSetMasterPage.CannotCreateAnalysis"), false);
    }
    if (!columnSetMultiValueList.isEmpty()) {
        // MOD klliu bug 19464,file delimit connection does not need to check from one table.
        if (columnList.get(0) instanceof TdColumn) {
            if (!ModelElementHelper.isFromSameTable(columnList)) {
                // $NON-NLS-1$
                message = DefaultMessagesImpl.getString("ColumnSetMasterPage.CannotCreateAnalysis");
            }
        } else if (columnList.get(0) instanceof MetadataColumn) {
            if (!isFromSameTableByDFColumn(columnSetMultiValueList)) {
                // $NON-NLS-1$
                message = DefaultMessagesImpl.getString("ColumnSetMasterPage.CannotCreateAnalysis");
            }
        }
    }
    if (message == null) {
        resetResultPageData();
        return new ReturnCode(true);
    }
    return new ReturnCode(message, false);
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) ReturnCode(org.talend.utils.sugars.ReturnCode) TdColumn(org.talend.cwm.relational.TdColumn) IRepositoryNode(org.talend.repository.model.IRepositoryNode) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 8 with ReturnCode

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

the class AbstractAnalysisMetadataPage method doSave.

@Override
public void doSave(IProgressMonitor monitor) {
    ReturnCode rc = canSave();
    if (!rc.isOk()) {
        // MOD yyi 2012-02-29 TDQ-3605 Pop an error if rc is not ok.
        MessageDialogWithToggle.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DefaultMessagesImpl.getString("AbstractAnalysisMetadataPage.SaveAnalysis"), // $NON-NLS-1$
        rc.getMessage());
        return;
    } else if (!checkWhithspace()) {
        MessageDialogWithToggle.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DefaultMessagesImpl.getString("AbstractAnalysisMetadataPage.SaveAnalysis"), // $NON-NLS-1$ //$NON-NLS-2$
        DefaultMessagesImpl.getString("AbstractMetadataFormPage.whitespace"));
    } else {
        super.doSave(monitor);
        try {
            // SaveContext
            saveContext();
            saveAnalysis();
            this.isDirty = false;
            // MOD qiongli bug 0012766,2010-5-31:After change to another connection
            // which has same columns with before,the editor should not
            // dirty.
            ((AnalysisEditor) this.getEditor()).firePropertyChange(IEditorPart.PROP_DIRTY);
            this.updateAnalysisConnectionVersionInfo();
        } catch (DataprofilerCoreException e) {
            MessageDialogWithToggle.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DefaultMessagesImpl.getString("AbstractAnalysisMetadataPage.SaveAnalysis"), // $NON-NLS-1$
            e.getMessage());
            ExceptionHandler.process(e, Level.ERROR);
        }
    }
}
Also used : DataprofilerCoreException(org.talend.dataquality.exception.DataprofilerCoreException) ReturnCode(org.talend.utils.sugars.ReturnCode)

Example 9 with ReturnCode

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

the class AbstractMetadataFormPage method canModifyName.

/**
 * check if the nameText is a dupilcate name.
 *
 * @return
 */
protected ReturnCode canModifyName(ERepositoryObjectType objectType) {
    String elementName = this.nameText.getText();
    Property oldProperty = null;
    oldProperty = getProperty();
    ReturnCode ret = new ReturnCode();
    if (oldProperty == null || objectType == null) {
        return ret;
    }
    if (PluginConstant.EMPTY_STRING.equals(elementName.trim())) {
        this.nameText.setText(oldProperty.getDisplayName());
        // $NON-NLS-1$
        String NAMECONNOTBEEMPTY = DefaultMessagesImpl.getString("AbstractMetadataFormPage.nameCannotBeEmpty");
        ret.setReturnCode(NAMECONNOTBEEMPTY, false);
        return ret;
    }
    // MOD qiongli 2012-2-14 TDQ-4539.compare the name with all items of the specified type.
    boolean exist = PropertyHelper.existDuplicateName(elementName, oldProperty.getDisplayName(), objectType);
    if (exist) {
        Property duplicateObject = PropertyHelper.getDuplicateObject(elementName, objectType);
        IPath path = PropertyHelper.getItemPath(duplicateObject);
        if (duplicateObject.getItem().getState().isDeleted()) {
            // "/S/TDQ_Data Profiling/Reports/s_0.1.rep" to "/S/Recycle Bin/s_0.1.rep"
            // $NON-NLS-1$
            path = new Path(path.segment(0)).append(new Path("Recycle Bin")).append(path.lastSegment());
        }
        ret.setReturnCode(DefaultMessagesImpl.getString("UIMessages.ItemExistsErrorWithParameter", elementName, path.toOSString()), // $NON-NLS-1$
        false);
        return ret;
    }
    return ret;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ReturnCode(org.talend.utils.sugars.ReturnCode) IPath(org.eclipse.core.runtime.IPath) Property(org.talend.core.model.properties.Property)

Example 10 with ReturnCode

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

the class AbstractFilterMetadataPage method saveAnalysis.

@Override
public void saveAnalysis() throws DataprofilerCoreException {
    // ADD xqliu 2010-01-04 bug 10190
    if (isConnectionAnalysis()) {
        // MOD zshen 2010-03-19 bug 12041
        AnalysisHelper.setReloadDatabases(getCurrentModelElement(), reloadDatabasesBtn.getSelection());
    }
    // ~
    EList<Domain> dataFilters = getCurrentModelElement().getParameters().getDataFilter();
    if (!this.tableFilterText.getText().equals(DomainHelper.getTablePattern(dataFilters))) {
        DomainHelper.setDataFilterTablePattern(dataFilters, tableFilterText.getText());
        latestTableFilterValue = this.tableFilterText.getText();
    }
    if (!this.viewFilterText.getText().equals(DomainHelper.getViewPattern(dataFilters))) {
        DomainHelper.setDataFilterViewPattern(dataFilters, viewFilterText.getText());
        latestViewFilterValue = this.viewFilterText.getText();
    }
    // save the number of connections per analysis
    this.saveNumberOfConnectionsPerAnalysis();
    // 2011.1.12 MOD by zhsne to unify anlysis and connection id when saving.
    this.nameText.setText(getCurrentModelElement().getName());
    // ~
    // MOD yyi 2012-02-08 TDQ-4621:Explicitly set true for updating dependencies.
    ReturnCode saved = ElementWriterFactory.getInstance().createAnalysisWrite().save(getCurrentRepNode().getObject().getProperty().getItem(), true);
    // MOD yyi 2012-02-03 TDQ-3602:Avoid to rewriting all analyzes after saving, no reason to update all analyzes
    // which is depended in the referred connection.
    // Extract saving log function.
    // @see org.talend.dataprofiler.core.ui.editor.analysis.AbstractAnalysisMetadataPage#logSaved(ReturnCode)
    logSaved(saved);
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) Domain(org.talend.dataquality.domain.Domain)

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