Skip to content

Commit

Permalink
Merge pull request #169 from InCadence/167
Browse files Browse the repository at this point in the history
#167 Deduplication Operation
  • Loading branch information
dclemenzi committed Mar 29, 2019
2 parents 8020938 + a415379 commit f3c8fad
Show file tree
Hide file tree
Showing 14 changed files with 742 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,13 @@ private List<T> createTasks() throws CoalesceException

for (String[] subset : subsets)
{
for (ICoalescePersistor target : targets)
{
T task = createTask();
task.setParameters(parameters);
task.setSource(source);
task.setRowset(rowset);
task.setSubset(subset);
task.setTarget(target);
tasks.add(task);
}
T task = createTask();
task.setParameters(parameters);
task.setSource(source);
task.setRowset(rowset);
task.setSubset(subset);
task.setTarget(targets);
tasks.add(task);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.incadencecorp.coalesce.synchronizer.api.common;

import com.incadencecorp.coalesce.common.exceptions.CoalescePersistorException;
import com.incadencecorp.coalesce.framework.datamodel.CoalesceEntity;
import com.incadencecorp.coalesce.framework.persistance.ICoalescePersistor;

import javax.sql.rowset.CachedRowSet;
Expand All @@ -34,7 +35,7 @@
public abstract class AbstractOperationTask implements Callable<Boolean> {

protected ICoalescePersistor source;
protected ICoalescePersistor target;
protected ICoalescePersistor[] targets;
protected Map<String, String> params = new HashMap<>();
protected String keys[];
protected CachedRowSet rowset;
Expand Down Expand Up @@ -68,11 +69,11 @@ public final void setSource(ICoalescePersistor source)
/**
* Sets the target that the results of this operation should be stored.
*
* @param target of this operation
* @param targets of this operation
*/
public final void setTarget(ICoalescePersistor target)
public final void setTarget(ICoalescePersistor[] targets)
{
this.target = target;
this.targets = targets;
}

/**
Expand Down Expand Up @@ -112,6 +113,23 @@ public String[] getErrorSubset()
return getSubset();
}

/**
* Calls {@link ICoalescePersistor#saveEntity(boolean, CoalesceEntity...)} on each target.
*
* @see ICoalescePersistor#saveEntity(boolean, CoalesceEntity...)
*/
protected boolean saveWork(boolean allowRemoval, CoalesceEntity... entities) throws CoalescePersistorException
{
boolean result = true;

for (ICoalescePersistor target : targets)
{
result = result && target.saveEntity(allowRemoval, entities);
}

return result;
}

protected abstract Boolean doWork(String[] keys, CachedRowSet rowset) throws CoalescePersistorException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.incadencecorp.coalesce.synchronizer.api.common;

import com.incadencecorp.coalesce.api.CoalesceErrors;
import com.incadencecorp.coalesce.common.exceptions.CoalesceException;
import com.incadencecorp.coalesce.common.helpers.StringHelper;
import com.incadencecorp.coalesce.framework.CoalesceComponentImpl;
Expand All @@ -32,7 +33,11 @@
import org.slf4j.LoggerFactory;

import javax.sql.rowset.CachedRowSet;
import java.util.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Abstract implementation to be used as the base of all scanner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,20 @@

package com.incadencecorp.coalesce.synchronizer.api.common.mocks;

import java.util.HashSet;
import java.util.Set;

import javax.sql.rowset.CachedRowSet;

import com.incadencecorp.coalesce.common.exceptions.CoalescePersistorException;
import com.incadencecorp.coalesce.common.helpers.StringHelper;
import com.incadencecorp.coalesce.framework.datamodel.CoalesceEntity;
import com.incadencecorp.coalesce.search.factory.CoalescePropertyFactory;
import com.incadencecorp.coalesce.synchronizer.api.common.AbstractOperation;
import com.incadencecorp.coalesce.synchronizer.api.common.AbstractOperationTask;

import javax.sql.rowset.CachedRowSet;
import java.util.HashSet;
import java.util.Set;

/**
* Mock Operation Implementation
*
*
* @author n78554
*/
public class MockOperation extends AbstractOperation<AbstractOperationTask> {
Expand All @@ -40,7 +39,7 @@ public class MockOperation extends AbstractOperation<AbstractOperationTask> {

/**
* Sets the title which will be set by this operation on each entity.
*
*
* @param title
*/
public void setTitle(String title)
Expand All @@ -58,24 +57,20 @@ protected Boolean doWork(String[] keys, CachedRowSet rowset) throws CoalescePers
{
if (!StringHelper.isNullOrEmpty(title))
{
for (String key : keys)
// Change Title
CoalesceEntity[] entities = source.getEntity(keys);

for (CoalesceEntity entity : entities)
{
// Change Title
CoalesceEntity[] entities = source.getEntity(key);

for (CoalesceEntity entity : entities)
{
entity.setTitle(title);
target.saveEntity(false, entity);
}
entity.setTitle(title);
}

return saveWork(false, entities);
}
else
{
throw new CoalescePersistorException("Failed", null);
}

return true;
}

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected Boolean doWork(String[] keys, CachedRowSet rowset) throws CoalescePers
// Copy to Targets
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("Processing {} key(s) for {}", entities.length, target.getClass().getName());
LOGGER.debug("Processing {} key(s)", entities.length);
LOGGER.trace("Details:");

for (CoalesceEntity entity : entities)
Expand All @@ -82,7 +82,7 @@ protected Boolean doWork(String[] keys, CachedRowSet rowset) throws CoalescePers

}

target.saveEntity(false, entities);
saveWork(false, entities);

return true;
}
Expand Down
Loading

0 comments on commit f3c8fad

Please sign in to comment.