Search in sources :

Example 1 with DataprofilerCoreException

use of org.talend.dataquality.exception.DataprofilerCoreException 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 2 with DataprofilerCoreException

use of org.talend.dataquality.exception.DataprofilerCoreException in project tdq-studio-se by Talend.

the class AbstractAnalysisMetadataPage method logSaved.

/**
 * log when analysis saved
 *
 * @param saved
 * @throws DataprofilerCoreException
 */
protected void logSaved(ReturnCode saved) throws DataprofilerCoreException {
    Analysis analysis = getCurrentModelElement();
    String urlString = analysis.eResource() != null ? (analysis.eResource().getURI().isFile() ? analysis.eResource().getURI().toFileString() : analysis.eResource().getURI().toString()) : PluginConstant.EMPTY_STRING;
    if (!saved.isOk()) {
        throw new DataprofilerCoreException(DefaultMessagesImpl.getString("ColumnMasterDetailsPage.problem", analysis.getName(), urlString, // $NON-NLS-1$
        saved.getMessage()));
    } else if (log.isDebugEnabled()) {
        // MOD yyi 2012-02-06 TDQ-4581:avoid the instantiation of the strings to optimize the performances.
        // $NON-NLS-1$
        doLog(log, Level.INFO, DefaultMessagesImpl.getString("ColumnMasterDetailsPage.success", urlString));
    }
}
Also used : DataprofilerCoreException(org.talend.dataquality.exception.DataprofilerCoreException) Analysis(org.talend.dataquality.analysis.Analysis)

Example 3 with DataprofilerCoreException

use of org.talend.dataquality.exception.DataprofilerCoreException in project tdq-studio-se by Talend.

the class PatternTestView method testRegularText.

/**
 * Test the text by the regular text of regularText.
 */
private void testRegularText() {
    // MOD qiongli 2011-1-7.Add java in Pattern Test View
    if (isJavaEngine) {
        String regexStr = regularText.getText();
        if (regexStr.length() >= 2 && regexStr.startsWith("'") && regexStr.endsWith("'")) {
            // $NON-NLS-1$ //$NON-NLS-2$
            regexStr = regexStr.substring(1, regexStr.length() - 1);
        }
        try {
            boolean flag = java.util.regex.Pattern.compile(regexStr).matcher(testText.getText()).find();
            if (flag) {
                emoticonLabel.setImage(ImageLib.getImage(ImageLib.CHECK_MARK_PNG));
                // $NON-NLS-1$
                resultLabel.setText(DefaultMessagesImpl.getString("PatternTestView.Match"));
                return;
            } else {
                emoticonLabel.setImage(ImageLib.getImage(ImageLib.RED_WARNING_PNG));
                // $NON-NLS-1$
                resultLabel.setText(DefaultMessagesImpl.getString("PatternTestView.nonMatch"));
                return;
            }
        } catch (java.util.regex.PatternSyntaxException e) {
            // TDQ-5650 show the error message if any exception
            emoticonLabel.setImage(ImageLib.getImage(ImageLib.ICON_ERROR_INFO));
            resultLabel.setText(e.getLocalizedMessage());
            return;
        }
    } else {
        for (IRepositoryNode connRepNode : listTdDataProviders) {
            ConnectionItem connItem = (ConnectionItem) connRepNode.getObject().getProperty().getItem();
            Connection tddataprovider = connItem.getConnection();
            if (tddataprovider.getName().equals(dbCombo.getText())) {
                DbmsLanguage createDbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(tddataprovider);
                String selectRegexpTestString = null;
                // MOD gdbu 2011-5-31 bug : 19119
                if (null != createDbmsLanguage) {
                    createDbmsLanguage.setRegularExpressionFunction(getFunctionName());
                    selectRegexpTestString = createDbmsLanguage.getSelectRegexpTestString(testText.getText(), regularText.getText());
                }
                // DbmsLanguage.regexLike().should return.
                if (selectRegexpTestString == null) {
                    MessageDialog.openInformation(new Shell(), // $NON-NLS-1$
                    DefaultMessagesImpl.getString("PatternTestView.NoSupportTitle"), // $NON-NLS-1$
                    DefaultMessagesImpl.getString("PatternTestView.NoSupportPatternTest"));
                    return;
                }
                TypedReturnCode<java.sql.Connection> rcConn = JavaSqlFactory.createConnection(tddataprovider);
                Statement createStatement = null;
                try {
                    if (!rcConn.isOk()) {
                        throw new DataprofilerCoreException(rcConn.getMessage());
                    }
                    java.sql.Connection connection = rcConn.getObject();
                    createStatement = connection.createStatement();
                    ResultSet resultSet = createStatement.executeQuery(selectRegexpTestString);
                    while (resultSet.next()) {
                        String okString = resultSet.getString(1);
                        // MOD msjian 2011-11-15 TDQ-3967: in the postgres db, the match return value is "t"
                        if (// $NON-NLS-1$
                        "1".equalsIgnoreCase(okString) || (createDbmsLanguage != null && (createDbmsLanguage.getDbmsName().equals(SupportDBUrlType.POSTGRESQLEFAULTURL.getLanguage()) && "t".equalsIgnoreCase(okString)))) {
                            // $NON-NLS-1$
                            // TDQ-3967 ~
                            emoticonLabel.setImage(ImageLib.getImage(ImageLib.CHECK_MARK_PNG));
                            // $NON-NLS-1$
                            resultLabel.setText(DefaultMessagesImpl.getString("PatternTestView.Match"));
                            return;
                        }
                    }
                    emoticonLabel.setImage(ImageLib.getImage(ImageLib.RED_WARNING_PNG));
                    // $NON-NLS-1$
                    resultLabel.setText(DefaultMessagesImpl.getString("PatternTestView.nonMatch"));
                    return;
                } catch (Exception exception) {
                    log.error(exception, exception);
                    // bug TDQ-2066-->TDQ-3594 for mysql
                    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                    MessageBoxExceptionHandler.process(exception, shell);
                    // ~
                    emoticonLabel.setImage(null);
                    return;
                } finally {
                    if (createStatement != null) {
                        try {
                            createStatement.close();
                        } catch (SQLException e) {
                        // do nothing until now
                        }
                    }
                    ConnectionUtils.closeConnection(rcConn.getObject());
                }
            }
        }
    }
    // $NON-NLS-1$
    MessageDialog.openWarning(new Shell(), "", NO_DATABASE_SELECTEDED);
}
Also used : DataprofilerCoreException(org.talend.dataquality.exception.DataprofilerCoreException) IRepositoryNode(org.talend.repository.model.IRepositoryNode) SQLException(java.sql.SQLException) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Statement(java.sql.Statement) Connection(org.talend.core.model.metadata.builder.connection.Connection) DataprofilerCoreException(org.talend.dataquality.exception.DataprofilerCoreException) SQLException(java.sql.SQLException) DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) Shell(org.eclipse.swt.widgets.Shell) ResultSet(java.sql.ResultSet)

Example 4 with DataprofilerCoreException

use of org.talend.dataquality.exception.DataprofilerCoreException in project tdq-studio-se by Talend.

the class ConnectionInfoPage method saveConnectionInfo.

private void saveConnectionInfo() throws DataprofilerCoreException {
    Connection connection = getCurrentModelElement();
    if (connection == null) {
        return;
    }
    ConnectionUtils.checkUsernameBeforeSaveConnection4Sqlite(connection);
    ConnectionItem connectionItem = (ConnectionItem) this.getCurrentRepNode().getObject().getProperty().getItem();
    ReturnCode returnCode = ElementWriterFactory.getInstance().createDataProviderWriter().save(connectionItem, true);
    if (returnCode.isOk()) {
        if (log.isDebugEnabled()) {
            // $NON-NLS-1$ //$NON-NLS-2$
            log.debug("Saved in  " + connection.eResource().getURI().toFileString() + " successful");
        }
    } else {
        throw new DataprofilerCoreException(DefaultMessagesImpl.getString("ConnectionInfoPage.ProblemSavingFile", connection.eResource().getURI().toFileString(), // $NON-NLS-1$
        returnCode.getMessage()));
    }
}
Also used : DataprofilerCoreException(org.talend.dataquality.exception.DataprofilerCoreException) ReturnCode(org.talend.utils.sugars.ReturnCode) ConnectionItem(org.talend.core.model.properties.ConnectionItem) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection)

Aggregations

DataprofilerCoreException (org.talend.dataquality.exception.DataprofilerCoreException)4 Connection (org.talend.core.model.metadata.builder.connection.Connection)2 ConnectionItem (org.talend.core.model.properties.ConnectionItem)2 ReturnCode (org.talend.utils.sugars.ReturnCode)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 Shell (org.eclipse.swt.widgets.Shell)1 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)1 Analysis (org.talend.dataquality.analysis.Analysis)1 DbmsLanguage (org.talend.dq.dbms.DbmsLanguage)1 IRepositoryNode (org.talend.repository.model.IRepositoryNode)1