Search in sources :

Example 56 with ReturnCode

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

the class AnalysisExecutorSelector method executeAnalysis.

/**
 * DOC xqliu Comment method "executeAnalysis".
 *
 * @param analysis
 * @param monitor
 * @return
 * @deprecated use {@link #executeAnalysis(TDQAnalysisItem, IProgressMonitor)} instead.
 */
@Deprecated
public static ReturnCode executeAnalysis(final Analysis analysis, IProgressMonitor monitor) {
    IAnalysisExecutor analysisExecutor = getAnalysisExecutor(analysis);
    if (analysisExecutor != null) {
        // MOD xqliu 2009-02-09 bug 6237
        analysisExecutor.setMonitor(monitor);
        ReturnCode execute = analysisExecutor.execute(analysis);
        // save analysis.
        if (Platform.isRunning()) {
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    AnaResourceFileHelper.getInstance().save(analysis);
                }
            });
        }
        return execute;
    }
    // $NON-NLS-1$
    return new ReturnCode(Messages.getString("AnalysisExecutorSelector.NotFindHowExecute", analysis.getName()), false);
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode)

Example 57 with ReturnCode

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

the class DatabaseSQLExecutor method executeQuery.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.cwm.db.connection.ISQLExecutor#executeQuery(orgomg.cwm.foundation.softwaredeployment.DataManager,
     * java.util.List, java.lang.String, org.talend.dataquality.analysis.SampleDataShowWay)
     */
public List<Object[]> executeQuery(DataManager connection, List<ModelElement> analysedElements, String where) throws SQLException {
    getDataFromTable().clear();
    try {
        beginQuery();
    } catch (Exception e1) {
        log.error(e1.getMessage(), e1);
        return getDataFromTable();
    }
    int columnListSize = analysedElements.size();
    TypedReturnCode<java.sql.Connection> sqlconnection = getSQLConnection(connection);
    Statement statement = null;
    ResultSet resultSet = null;
    try {
        statement = sqlconnection.getObject().createStatement();
        statement.execute(createSqlStatement(connection, analysedElements, where));
        resultSet = statement.getResultSet();
        while (resultSet.next()) {
            Object[] oneRow = new Object[columnListSize];
            // --- for each column
            for (int i = 0; i < columnListSize; i++) {
                // --- get content of column
                oneRow[i] = ResultSetUtils.getBigObject(resultSet, i + 1);
            }
            handleRow(oneRow);
        }
    } catch (Exception e) {
        log.error(e, e);
        if (SQLException.class.isInstance(e)) {
            throw (SQLException) e;
        }
    } finally {
        if (resultSet != null) {
            resultSet.close();
        }
        if (statement != null) {
            statement.close();
        }
        ReturnCode closed = ConnectionUtils.closeConnection(sqlconnection.getObject());
        if (!closed.isOk()) {
            log.error(closed.getMessage());
        }
    }
    try {
        endQuery();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return getDataFromTable();
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(org.talend.core.model.metadata.builder.connection.Connection) ResultSet(java.sql.ResultSet) SQLException(java.sql.SQLException)

Example 58 with ReturnCode

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

the class AbstractWizard method checkMetadata.

public ReturnCode checkMetadata() {
    String elementName = getParameter().getName();
    IFolder folderResource = getParameter().getFolderProvider().getFolderResource();
    if (elementName == null || folderResource == null) {
        // $NON-NLS-1$
        return new ReturnCode("", false);
    } else {
        Collection<ModelElement> modelElements = new ArrayList<ModelElement>();
        switch(getParameter().getParamType()) {
            case ANALYSIS:
                modelElements.addAll(AnaResourceFileHelper.getInstance().getAllElement(folderResource));
                break;
            case REPORT:
                modelElements.addAll(RepResourceFileHelper.getInstance().getAllElement(folderResource));
                break;
            case PATTERN:
                modelElements.addAll(PatternResourceFileHelper.getInstance().getAllElement(folderResource));
                break;
            case CONNECTION:
                List<Connection> conns = new ArrayList<Connection>();
                try {
                    for (ConnectionItem connItem : ProxyRepositoryFactory.getInstance().getMetadataConnectionsItem()) {
                        conns.add(connItem.getConnection());
                    }
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
                modelElements.addAll(conns);
                break;
            case DQRULE:
                modelElements.addAll(DQRuleResourceFileHelper.getInstance().getAllElement(folderResource));
                break;
            case UDINDICATOR:
                modelElements.addAll(IndicatorResourceFileHelper.getInstance().getAllElement(folderResource));
                break;
            default:
                break;
        }
        if (!modelElements.isEmpty()) {
            for (ModelElement element : modelElements) {
                String theElementName = element.getName();
                if (theElementName == null) {
                    if (element instanceof Connection) {
                    // MOD klliu 2011-04-18 get repository Object label
                    // theElementName =RepositoryNodeHelper.recursiveFind(element).getObject().getLabel();
                    }
                }
                if (elementName.equals(theElementName)) {
                    // MOD xqliu 2010-09-21 bug 15762
                    return new ReturnCode(UIMessages.MSG_ANALYSIS_SAME_NAME, false);
                // if (!MessageUI.openConfirm(UIMessages.MSG_ANALYSIS_SAME_NAME)) {
                // getParameter().setName(elementName + DateFormatUtils.format(new Date(), "yyyyMMddHHmmss")); //$NON-NLS-1$
                // }
                // break;
                // ~ 15762
                }
            }
        }
    }
    return new ReturnCode(true);
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ArrayList(java.util.ArrayList) Connection(org.talend.core.model.metadata.builder.connection.Connection) PersistenceException(org.talend.commons.exception.PersistenceException) IFolder(org.eclipse.core.resources.IFolder)

Example 59 with ReturnCode

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

the class FolderWizard method performFinish.

/**
 * @see org.eclipse.jface.wizard.Wizard#performFinish()
 */
@Override
public boolean performFinish() {
    final ReturnCode returncode = new ReturnCode(true);
    RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>(// $NON-NLS-1$
    DefaultMessagesImpl.getString("FolderWizard.newFolder")) {

        @Override
        protected void run() throws LoginException, PersistenceException {
            String folderName = mainPage.getName();
            if (defaultLabel == null) {
                IRepositoryNode currentSelectionNode = CorePlugin.getDefault().getCurrentSelectionNode();
                IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
                IFolder newFolder = folder.getFolder(folderName);
                try {
                    if (ResourceManager.getConnectionFolder().getFullPath().isPrefixOf(folder.getFullPath())) {
                        // when create folder under dbconnections
                        ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.METADATA_CONNECTIONS, path.makeRelativeTo(ResourceManager.getConnectionFolder().getFullPath()), folderName);
                    } else {
                        // when create folder under other nodes
                        newFolder.create(false, true, null);
                    }
                    // do refresh
                    folder.refreshLocal(IResource.DEPTH_INFINITE, null);
                    DQRespositoryView findView = CorePlugin.getDefault().getRepositoryView();
                    if (findView != null) {
                        findView.getCommonViewer().setExpandedState(newFolder, true);
                        findView.getCommonViewer().refresh(currentSelectionNode);
                    }
                    // list .
                    if (DQRepositoryNode.isOnFilterring()) {
                        RepositoryNodeHelper.fillTreeList(null);
                        RepositoryNodeHelper.setFilteredNode(RepositoryNodeHelper.getRootNode(ERepositoryObjectType.TDQ_DATA_PROFILING, true));
                    }
                } catch (CoreException e) {
                    // $NON-NLS-1$
                    MessageDialog.openError(// $NON-NLS-1$
                    getShell(), // $NON-NLS-1$
                    DefaultMessagesImpl.getString("FolderWizard.error"), // $NON-NLS-1$
                    DefaultMessagesImpl.getString("FolderWizard.folderCreatedError"));
                    ExceptionHandler.process(e);
                    returncode.setOk(false);
                    return;
                }
            }
        }
    };
    workUnit.setAvoidUnloadResources(true);
    ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(workUnit);
    return returncode.isOk();
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) CoreException(org.eclipse.core.runtime.CoreException) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) DQRespositoryView(org.talend.dataprofiler.core.ui.views.DQRespositoryView) IFolder(org.eclipse.core.resources.IFolder)

Example 60 with ReturnCode

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

the class AElementPersistance method saveWithDependencies.

/**
 * Save item with dependencies.
 *
 * @param element
 * @throws PersistenceException
 */
protected ReturnCode saveWithDependencies(Item item, ModelElement element) throws PersistenceException {
    ReturnCode rc = new ReturnCode();
    removeDependencies(item);
    addDependencies(element);
    addResourceContent(element.eResource(), element);
    Map<EObject, Collection<Setting>> find = EcoreUtil.ExternalCrossReferencer.find(element.eResource());
    Set<EObject> needSaves = new HashSet<EObject>();
    for (EObject object : find.keySet()) {
        Resource re = object.eResource();
        if (re == null) {
            continue;
        }
        // only do save when the dependency is not reference project node, and do not do resolve
        if (!re.getURI().segment(1).equals(ProjectManager.getInstance().getCurrentProject().getTechnicalLabel())) {
            continue;
        }
        // MOD sizhaoliu TDQ-6296 the resource should be resolved before saving the item to make sure the references
        // are updated.
        EcoreUtil.resolveAll(re);
        needSaves.add(object);
    }
    // Set the TDQ item file name.
    if (item instanceof TDQItem) {
        setTDQItemFileName(element, item);
    }
    ProxyRepositoryFactory.getInstance().save(item);
    AbstractResourceChangesService resChangeService = TDQServiceRegister.getInstance().getResourceChangeService(AbstractResourceChangesService.class);
    if (resChangeService != null) {
        for (EObject toSave : needSaves) {
            // only do save when the dependency is not reference project node
            toSave = EObjectHelper.resolveObject(toSave);
            if (!toSave.eResource().getURI().segment(1).equals(ProjectManager.getInstance().getCurrentProject().getTechnicalLabel())) {
                continue;
            }
            resChangeService.saveResourceByEMFShared(toSave.eResource());
        }
    }
    return rc;
}
Also used : TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) Collection(java.util.Collection) TDQItem(org.talend.core.model.properties.TDQItem) AbstractResourceChangesService(org.talend.core.repository.utils.AbstractResourceChangesService) HashSet(java.util.HashSet)

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