Search in sources :

Example 11 with BusinessException

use of org.talend.commons.exception.BusinessException in project tdq-studio-se by Talend.

the class DQEditorLinkHelper method activateEditor.

public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
    IRepositoryNode repNode = (IRepositoryNode) aSelection.getFirstElement();
    OpenItemEditorAction openEditorAction = new OpenItemEditorAction(new IRepositoryNode[] { repNode });
    // MOD msjian TDQ-4209 2012-2-7 : modify to IEditorInput type
    try {
        IEditorInput absEditorInput = openEditorAction.computeEditorInput(repNode, false);
        if (absEditorInput != null) {
            aPage.bringToTop(aPage.findEditor(absEditorInput));
        }
    } catch (BusinessException e) {
        ExceptionHandler.process(e, Level.FATAL);
    }
// TDQ-4209~
}
Also used : BusinessException(org.talend.commons.exception.BusinessException) IRepositoryNode(org.talend.repository.model.IRepositoryNode) OpenItemEditorAction(org.talend.dataprofiler.core.ui.action.actions.OpenItemEditorAction) IEditorInput(org.eclipse.ui.IEditorInput)

Example 12 with BusinessException

use of org.talend.commons.exception.BusinessException in project tdq-studio-se by Talend.

the class ExecuteMatchRuleHandler method computeMatchGroupResult.

/**
 * DOC zhao Comment method "computeMatchGroupResult".
 *
 * @param columnMap
 * @param matchResultConsumer
 * @param matchRows
 * @return
 */
private void computeMatchGroupResult(Map<MetadataColumn, String> columnMap, MatchGroupResultConsumer matchResultConsumer, List<Object[]> matchRows, RecordMatchingIndicator recordMatchingIndicator) throws BusinessException {
    boolean isOpenWarningDialog = false;
    AnalysisMatchRecordGrouping analysisMatchRecordGrouping = null;
    if (recordMatchingIndicator.getBuiltInMatchRuleDefinition().getRecordLinkageAlgorithm().equals(RecordMatcherType.T_SwooshAlgorithm.name())) {
        analysisMatchRecordGrouping = new AnalysisSwooshMatchRecordGrouping(matchResultConsumer);
    } else {
        analysisMatchRecordGrouping = new AnalysisMatchRecordGrouping(matchResultConsumer);
    }
    AnalysisRecordGroupingUtils.setRuleMatcher(columnMap, recordMatchingIndicator, analysisMatchRecordGrouping);
    analysisMatchRecordGrouping.setMatchRows(matchRows);
    try {
        AnalysisRecordGroupingUtils.initialMatchGrouping(columnMap, recordMatchingIndicator, analysisMatchRecordGrouping);
        // TDQ-14276 set the Map<columnName, dataPattern>
        Map<String, String> patternMap = AnalysisRecordGroupingUtils.createColumnDatePatternMap(columnMap, colName2IndexMap);
        analysisMatchRecordGrouping.setColumnDatePatternMap(patternMap);
        analysisMatchRecordGrouping.run();
    } catch (InstantiationException e1) {
        isOpenWarningDialog = true;
    } catch (IllegalAccessException e1) {
        isOpenWarningDialog = true;
    } catch (ClassNotFoundException e1) {
        isOpenWarningDialog = true;
    } finally {
        if (isOpenWarningDialog) {
            BusinessException businessException = new BusinessException();
            throw businessException;
        }
    }
}
Also used : AnalysisMatchRecordGrouping(org.talend.dataquality.record.linkage.grouping.AnalysisMatchRecordGrouping) BusinessException(org.talend.commons.exception.BusinessException) AnalysisSwooshMatchRecordGrouping(org.talend.dataquality.record.linkage.grouping.swoosh.AnalysisSwooshMatchRecordGrouping)

Example 13 with BusinessException

use of org.talend.commons.exception.BusinessException in project tdq-studio-se by Talend.

the class ExecuteMatchRuleHandler method computeMatchGroupWithBlockKey.

/**
 * DOC zhao Comment method "computeMatchGroupWithBlockKey".
 *
 * @param recordMatchingIndicator
 * @param blockKeyIndicator
 * @param columnMap
 * @param matchResultConsumer
 * @param matchRows
 */
private ReturnCode computeMatchGroupWithBlockKey(RecordMatchingIndicator recordMatchingIndicator, BlockKeyIndicator blockKeyIndicator, Map<MetadataColumn, String> columnMap, MatchGroupResultConsumer matchResultConsumer, List<Object[]> matchRows) {
    ReturnCode rc = new ReturnCode(Boolean.TRUE);
    Map<String, List<String[]>> resultWithBlockKey = computeBlockingKey(columnMap, matchRows, recordMatchingIndicator);
    Iterator<String> keyIterator = resultWithBlockKey.keySet().iterator();
    TreeMap<Object, Long> blockSize2Freq = new TreeMap<Object, Long>();
    while (keyIterator.hasNext()) {
        // Match group with in each block
        List<String[]> matchRowsInBlock = resultWithBlockKey.get(keyIterator.next());
        List<Object[]> objList = new ArrayList<Object[]>();
        objList.addAll(matchRowsInBlock);
        // Add check match key
        try {
            computeMatchGroupResult(columnMap, matchResultConsumer, objList, recordMatchingIndicator);
        } catch (BusinessException e) {
            rc.setOk(Boolean.FALSE);
            rc.setMessage(e.getAdditonalMessage());
            return rc;
        }
        // Store indicator
        Integer blockSize = matchRowsInBlock.size();
        if (blockSize == null) {
            // should not happen
            blockSize = 0;
        }
        Long freq = blockSize2Freq.get(Long.valueOf(blockSize));
        if (freq == null) {
            freq = 0l;
        }
        blockSize2Freq.put(Long.valueOf(blockSize), freq + 1);
    }
    blockKeyIndicator.setBlockSize2frequency(blockSize2Freq);
    return rc;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) BusinessException(org.talend.commons.exception.BusinessException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with BusinessException

use of org.talend.commons.exception.BusinessException in project tdq-studio-se by Talend.

the class LocalRepositoryObjectCRUD method moveObject.

/**
 * move the IRepositoryViewObject from the sourceNode to targetNode, don't refresh the source and target node, user
 * need to refresh the dq repository view tree by hand.
 *
 * @param sourceNode
 * @param targetNode
 * @param basePath
 */
private void moveObject(final IRepositoryNode sourceNode, final IRepositoryNode targetNode, final IPath basePath) {
    final IPath targetPath = RepositoryNodeHelper.getPath(targetNode);
    RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>(// $NON-NLS-1$
    DefaultMessagesImpl.getString("LocalRepositoryObjectCRUD.MOVE_ITEM") + sourceNode.getObject().getProperty().getDisplayName()) {

        @Override
        protected void run() {
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            IWorkspaceRunnable operation = new IWorkspaceRunnable() {

                public void run(IProgressMonitor monitor) throws CoreException {
                    IPath makeRelativeTo = Path.EMPTY;
                    if (!basePath.isEmpty()) {
                        makeRelativeTo = targetPath.makeRelativeTo(basePath);
                    }
                    try {
                        factory.moveObject(sourceNode.getObject(), makeRelativeTo, Path.EMPTY);
                    } catch (PersistenceException e) {
                        log.error(sourceNode, e);
                    } catch (BusinessException e) {
                        log.error(sourceNode, e);
                    }
                }
            };
            try {
                workspace.run(operation, new NullProgressMonitor());
            } catch (CoreException e) {
                log.error(e, e);
            }
        }
    };
    workUnit.setAvoidUnloadResources(true);
    ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(workUnit);
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) BusinessException(org.talend.commons.exception.BusinessException) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 15 with BusinessException

use of org.talend.commons.exception.BusinessException in project tdq-studio-se by Talend.

the class MatchAnalysisExecutor method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dq.analysis.IAnalysisExecutor#execute(org.talend.dataquality.analysis.Analysis)
     */
public ReturnCode execute(Analysis analysis) {
    assert analysis != null;
    // --- preconditions
    ReturnCode rc = AnalysisExecutorHelper.check(analysis);
    if (!rc.isOk()) {
        AnalysisExecutorHelper.setExecutionInfoInAnalysisResult(analysis, rc.isOk(), rc.getMessage());
        return rc;
    }
    // --- creation time
    final long startime = AnalysisExecutorHelper.setExecutionDateInAnalysisResult(analysis);
    EList<Indicator> indicators = analysis.getResults().getIndicators();
    RecordMatchingIndicator recordMatchingIndicator = null;
    BlockKeyIndicator blockKeyIndicator = null;
    for (Indicator ind : indicators) {
        if (ind instanceof RecordMatchingIndicator) {
            recordMatchingIndicator = (RecordMatchingIndicator) ind;
        } else if (ind instanceof BlockKeyIndicator) {
            blockKeyIndicator = (BlockKeyIndicator) ind;
        }
    }
    if (recordMatchingIndicator == null || blockKeyIndicator == null) {
        rc.setOk(Boolean.FALSE);
        // $NON-NLS-1$
        rc.setMessage(Messages.getString("MatchAnalysisExecutor.noIndicators"));
        AnalysisExecutorHelper.setExecutionInfoInAnalysisResult(analysis, rc.isOk(), rc.getMessage());
        return rc;
    }
    List<ModelElement> anlayzedElements = analysis.getContext().getAnalysedElements();
    if (anlayzedElements == null || anlayzedElements.size() == 0) {
        rc.setOk(Boolean.FALSE);
        // $NON-NLS-1$
        rc.setMessage(Messages.getString("MatchAnalysisExecutor.EmptyAnalyzedElement"));
        AnalysisExecutorHelper.setExecutionInfoInAnalysisResult(analysis, rc.isOk(), rc.getMessage());
        return rc;
    }
    // TDQ-9664 msjian: check the store on disk path.
    Boolean isStoreOnDisk = TaggedValueHelper.getValueBoolean(SQLExecutor.STORE_ON_DISK_KEY, analysis);
    if (isStoreOnDisk) {
        String tempDataPath = TaggedValueHelper.getValueString(SQLExecutor.TEMP_DATA_DIR, analysis);
        File file = new File(tempDataPath);
        if (!file.exists() || !file.isDirectory()) {
            rc.setOk(Boolean.FALSE);
            // $NON-NLS-1$
            rc.setMessage(Messages.getString("MatchAnalysisExecutor.InvalidPath", file.getPath()));
            AnalysisExecutorHelper.setExecutionInfoInAnalysisResult(analysis, rc.isOk(), rc.getMessage());
            return rc;
        }
    }
    // TDQ-9664~
    Map<MetadataColumn, String> columnMap = getColumn2IndexMap(anlayzedElements);
    ISQLExecutor sqlExecutor = getSQLExectutor(analysis, recordMatchingIndicator, columnMap);
    if (sqlExecutor == null) {
        rc.setOk(Boolean.FALSE);
        // $NON-NLS-1$
        rc.setMessage(Messages.getString("MatchAnalysisExecutor.noSqlExecutor"));
        AnalysisExecutorHelper.setExecutionInfoInAnalysisResult(analysis, rc.isOk(), rc.getMessage());
        return rc;
    }
    if (getMonitor() != null) {
        getMonitor().worked(20);
    }
    // Set schema for match key.
    TypedReturnCode<MatchGroupResultConsumer> returnCode = new TypedReturnCode<MatchGroupResultConsumer>();
    MetadataColumn[] completeColumnSchema = AnalysisRecordGroupingUtils.getCompleteColumnSchema(columnMap);
    String[] colSchemaString = new String[completeColumnSchema.length];
    int idx = 0;
    for (MetadataColumn metadataCol : completeColumnSchema) {
        colSchemaString[idx++] = metadataCol.getName();
    }
    recordMatchingIndicator.setMatchRowSchema(colSchemaString);
    recordMatchingIndicator.reset();
    MatchGroupResultConsumer matchResultConsumer = createMatchGroupResultConsumer(recordMatchingIndicator);
    if (sqlExecutor.isStoreOnDisk()) {
        // need to execute the query
        try {
            sqlExecutor.executeQuery(analysis.getContext().getConnection(), analysis.getContext().getAnalysedElements());
        } catch (SQLException e) {
            log.error(e, e);
            rc.setOk(Boolean.FALSE);
            rc.setMessage(e.getMessage());
            AnalysisExecutorHelper.setExecutionInfoInAnalysisResult(analysis, rc.isOk(), rc.getMessage());
            return rc;
        }
        try {
            TypedReturnCode<Object> result = StoreOnDiskUtils.getDefault().executeWithStoreOnDisk(columnMap, recordMatchingIndicator, blockKeyIndicator, sqlExecutor.getStoreOnDiskHandler(), matchResultConsumer);
            if (result != null) {
                returnCode.setObject((MatchGroupResultConsumer) result.getObject());
                returnCode.setOk(result.isOk());
                returnCode.setMessage(result.getMessage());
            }
        } catch (Exception e) {
            log.error(e, e);
            returnCode.setMessage(e.getMessage());
            returnCode.setOk(false);
        }
    } else {
        // Added TDQ-9320 , use the result set iterator to replace the list of result in the memory.
        try {
            Iterator<Record> resultSetIterator = sqlExecutor.getResultSetIterator(analysis.getContext().getConnection(), anlayzedElements);
            BlockAndMatchManager bAndmManager = new BlockAndMatchManager(resultSetIterator, matchResultConsumer, columnMap, recordMatchingIndicator, blockKeyIndicator);
            bAndmManager.run();
        } catch (SQLException e) {
            log.error(e, e);
            rc.setOk(Boolean.FALSE);
            rc.setMessage(e.getMessage());
            AnalysisExecutorHelper.setExecutionInfoInAnalysisResult(analysis, rc.isOk(), rc.getMessage());
            return rc;
        } catch (BusinessException e) {
            log.error(e, e);
            rc.setOk(Boolean.FALSE);
            rc.setMessage(e.getMessage());
            AnalysisExecutorHelper.setExecutionInfoInAnalysisResult(analysis, rc.isOk(), rc.getMessage());
            return rc;
        }
    }
    if (!returnCode.isOk()) {
        rc.setOk(returnCode.isOk());
        rc.setMessage(returnCode.getMessage());
    }
    if (getMonitor() != null) {
        getMonitor().worked(20);
    }
    if (isLowMemory) {
        // $NON-NLS-1$
        rc.setMessage(Messages.getString("Evaluator.OutOfMomory", usedMemory));
    }
    // nodify the master page
    refreshTableWithMatchFullResult(analysis);
    // --- set metadata information of analysis
    AnalysisExecutorHelper.setExecutionInfoInAnalysisResult(analysis, rc.isOk(), rc.getMessage());
    // --- compute execution duration
    if (this.continueRun()) {
        long endtime = System.currentTimeMillis();
        final ExecutionInformations resultMetadata = analysis.getResults().getResultMetadata();
        resultMetadata.setExecutionDuration((int) (endtime - startime));
        resultMetadata.setOutThreshold(false);
    }
    if (getMonitor() != null) {
        getMonitor().worked(20);
    }
    return rc;
}
Also used : BlockKeyIndicator(org.talend.dataquality.indicators.columnset.BlockKeyIndicator) ISQLExecutor(org.talend.cwm.db.connection.ISQLExecutor) SQLException(java.sql.SQLException) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) BusinessException(org.talend.commons.exception.BusinessException) Record(org.talend.dataquality.matchmerge.Record) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) RecordMatchingIndicator(org.talend.dataquality.indicators.columnset.RecordMatchingIndicator) RecordMatchingIndicator(org.talend.dataquality.indicators.columnset.RecordMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) BlockKeyIndicator(org.talend.dataquality.indicators.columnset.BlockKeyIndicator) SQLException(java.sql.SQLException) BusinessException(org.talend.commons.exception.BusinessException) ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) MatchGroupResultConsumer(org.talend.dataquality.record.linkage.grouping.MatchGroupResultConsumer) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) BlockAndMatchManager(org.talend.dq.analysis.match.BlockAndMatchManager) File(java.io.File)

Aggregations

BusinessException (org.talend.commons.exception.BusinessException)46 PersistenceException (org.talend.commons.exception.PersistenceException)21 IPath (org.eclipse.core.runtime.IPath)9 Path (org.eclipse.core.runtime.Path)9 Project (org.talend.core.model.general.Project)9 Item (org.talend.core.model.properties.Item)9 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)9 ArrayList (java.util.ArrayList)8 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)8 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)7 IFile (org.eclipse.core.resources.IFile)6 IProject (org.eclipse.core.resources.IProject)6 MDMServerObjectItem (org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem)5 File (java.io.File)4 HashMap (java.util.HashMap)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 ReturnCode (org.talend.utils.sugars.ReturnCode)4 IOException (java.io.IOException)3 IWorkspace (org.eclipse.core.resources.IWorkspace)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3