Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* DataCleaner (community edition)
* Copyright (C) 2014 Neopost - Customer Information Management
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.datacleaner.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import org.apache.metamodel.schema.Column;
import org.apache.metamodel.schema.Table;
import org.datacleaner.api.ExpressionBasedInputColumn;
import org.datacleaner.api.InputColumn;
import org.datacleaner.job.AnalysisJob;
import org.datacleaner.job.ComponentRequirement;
import org.datacleaner.job.FilterOutcome;
import org.datacleaner.job.HasComponentRequirement;
import org.datacleaner.job.HasFilterOutcomes;
import org.datacleaner.job.InputColumnSinkJob;
import org.datacleaner.job.InputColumnSourceJob;
import org.datacleaner.job.builder.AnalysisJobBuilder;
import org.datacleaner.job.builder.SourceColumns;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Helper class for traversing dependencies between virtual and physical
* columns.
*/
public class SourceColumnFinder {
private static final String LOG_MESSAGE_RECURSIVE_TRAVERSAL = "Ending traversal of object graph because the same originating objects are appearing recursively";
private static final Logger logger = LoggerFactory.getLogger(SourceColumnFinder.class);
private Set _inputColumnSinks = new HashSet();
private Set _inputColumnSources = new LinkedHashSet();
private Set _outcomeSources = new HashSet();
private Set _outcomeSinks = new HashSet();
private void addSources(Object... sources) {
for (Object source : sources) {
if (source instanceof InputColumnSinkJob) {
_inputColumnSinks.add((InputColumnSinkJob) source);
}
if (source instanceof InputColumnSourceJob) {
_inputColumnSources.add((InputColumnSourceJob) source);
}
if (source instanceof HasFilterOutcomes) {
_outcomeSources.add((HasFilterOutcomes) source);
}
if (source instanceof HasComponentRequirement) {
_outcomeSinks.add((HasComponentRequirement) source);
}
}
}
private void addSources(Collection> sources) {
addSources(sources.toArray());
}
public void addSources(AnalysisJobBuilder job) {
addSources(new SourceColumns(job.getSourceColumns()));
addSources(job.getFilterComponentBuilders());
addSources(job.getTransformerComponentBuilders());
addSources(job.getAnalyzerComponentBuilders());
}
public void addSources(AnalysisJob job) {
addSources(new SourceColumns(job.getSourceColumns()));
addSources(job.getFilterJobs());
addSources(job.getTransformerJobs());
addSources(job.getAnalyzerJobs());
}
public List> findInputColumns(final Class> dataType) {
final List> result = new ArrayList>();
for (InputColumnSourceJob source : _inputColumnSources) {
InputColumn>[] outputColumns = source.getOutput();
for (InputColumn> col : outputColumns) {
final Class> columnDataType = col.getDataType();
if (dataType == null || columnDataType == null) {
result.add(col);
} else {
if (ReflectionUtils.is(columnDataType, dataType)) {
result.add(col);
}
}
}
}
return result;
}
/**
* Finds all source jobs/components for a particular job/component. This
* method uses {@link Object} as types because input and output can be quite
* polymorphic. Typically {@link InputColumnSinkJob},
* {@link InputColumnSourceJob}, {@link HasComponentRequirement} and
* {@link OutcomeSourceJob} implementations are used.
*
* @param job
* typically some {@link InputColumnSinkJob}
* @return a list of jobs/components that are a source of this job.
*/
public Set