Skip to content

Commit

Permalink
0004665: Added service code necessary for Save As Copy button
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-miller-jumpmind committed Dec 9, 2021
1 parent c1bb789 commit e573ff8
Show file tree
Hide file tree
Showing 30 changed files with 419 additions and 47 deletions.
Expand Up @@ -358,6 +358,16 @@ public void init() {
public void saveJob(JobDefinition jobDefinition) {
// No action on Android
}

@Override
public void saveJobAsCopy(JobDefinition jobDefinition) {
// No action on Android
}

@Override
public void editJob(String oldName, JobDefinition jobDefinition) {
// No action on Android
}

@Override
public void removeJob(String name) {
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.jumpmind.db.sql.ISqlTransaction;
Expand Down Expand Up @@ -203,6 +204,18 @@ public void saveJob(JobDefinition job) {
}
}

@Override
public void saveJobAsCopy(JobDefinition job) {
String newName = job.getJobName();
List<String> names = jobs.stream().map(IJob::getName).collect(Collectors.toList());
String suffix = "";
for (int i = 2; names.contains(newName + suffix); i++) {
suffix = "_" + i;
}
job.setJobName(newName + suffix);
saveJob(job);
}

@Override
public void editJob(String oldName, JobDefinition job) {
ISqlTransaction transaction = null;
Expand Down
Expand Up @@ -43,6 +43,8 @@ public interface IJobManager {

public void saveJob(JobDefinition jobDefinition);

public void saveJobAsCopy(JobDefinition jobDefinition);

public void editJob(String oldName, JobDefinition jobDefinition);

public void removeJob(String name);
Expand Down
Expand Up @@ -68,6 +68,8 @@ public interface IConfigurationService {

public void saveChannel(NodeChannel channel, boolean reloadChannels);

public void saveChannelAsCopy(Channel channel, boolean reloadChannels);

public void editChannel(String oldId, Channel channel);

public void saveNodeChannel(NodeChannel channel, boolean reloadChannels);
Expand Down
Expand Up @@ -71,6 +71,8 @@ public interface IDataLoaderService {

public void save(ConflictNodeGroupLink settings);

public void saveAsCopy(ConflictNodeGroupLink settings);

public void edit(String oldId, ConflictNodeGroupLink settings);

public void clearCache();
Expand Down
Expand Up @@ -48,6 +48,8 @@ public interface IExtensionService {

public void saveExtension(Extension extension);

public void saveExtensionAsCopy(Extension extension);

public void editExtension(String oldId, Extension extension);

public void deleteExtension(String extensionId);
Expand Down
Expand Up @@ -44,6 +44,8 @@ public interface IFileSyncService {

public void saveFileTrigger(FileTrigger fileTrigger);

public void saveFileTriggerAsCopy(String originalId, FileTrigger fileTrigger);

public void editFileTrigger(String oldId, FileTrigger fileTrigger);

public void saveFileTriggerRouter(FileTriggerRouter fileTriggerRouter);
Expand Down
Expand Up @@ -50,6 +50,8 @@ public interface IGroupletService {

public void saveGrouplet(Grouplet grouplet);

public void saveGroupletAsCopy(Grouplet grouplet);

public void editGrouplet(Grouplet oldGrouplet, Grouplet newGrouplet);

public void saveGroupletLink(Grouplet grouplet, GroupletLink link);
Expand Down
Expand Up @@ -35,6 +35,8 @@ public interface ILoadFilterService {

public void saveLoadFilter(LoadFilterNodeGroupLink loadFilter);

public void saveLoadFilterAsCopy(LoadFilterNodeGroupLink loadFilter);

public void editLoadFilter(String oldId, LoadFilterNodeGroupLink loadFilter);

public void deleteLoadFilter(String loadFilterId);
Expand Down
Expand Up @@ -39,6 +39,8 @@ public interface IMonitorService {

public void saveMonitor(Monitor monitor);

public void saveMonitorAsCopy(Monitor monitor);

public void editMonitor(String oldId, Monitor monitor);

public List<MonitorEvent> getMonitorEvents();
Expand All @@ -59,6 +61,8 @@ public interface IMonitorService {

public void saveNotification(Notification notification);

public void saveNotificationAsCopy(Notification notification);

public void editNotification(String oldId, Notification notification);

public void deleteNotification(String notificationId);
Expand Down
Expand Up @@ -47,6 +47,8 @@ public List<TransformTableNodeGroupLink> findTransformsFor(NodeGroupLink link,

public void saveTransformTable(TransformTableNodeGroupLink transformTable, boolean saveTransformColumns);

public void saveTransformTableAsCopy(String originalId, TransformTableNodeGroupLink transformTable);

public void editTransformTable(String oldId, TransformTableNodeGroupLink transformTable);

public void deleteTransformTable(String transformTableId);
Expand Down
Expand Up @@ -128,6 +128,8 @@ public interface ITriggerRouterService {

public void saveRouter(Router router);

public void saveRouterAsCopy(Router router);

public void editRouter(String oldId, Router router);

public List<TriggerRouter> getAllTriggerRoutersForCurrentNode(String sourceNodeGroupId);
Expand All @@ -141,6 +143,8 @@ public interface ITriggerRouterService {

public void saveTrigger(Trigger trigger);

public void saveTriggerAsCopy(String originalId, Trigger trigger);

public void editTrigger(String oldId, Trigger trigger);

public void deleteTrigger(Trigger trigger);
Expand Down
Expand Up @@ -28,6 +28,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.jumpmind.db.sql.ISqlRowMapper;
import org.jumpmind.db.sql.ISqlTransaction;
Expand Down Expand Up @@ -334,6 +335,19 @@ public void saveChannel(NodeChannel nodeChannel, boolean reloadChannels) {
saveChannel(nodeChannel.getChannel(), reloadChannels);
}

public void saveChannelAsCopy(Channel channel, boolean reloadChannels) {
String newId = channel.getChannelId();
List<Channel> channels = sqlTemplate.query(getSql("selectChannelsWhereChannelIdLikeSql"), new ChannelMapper(),
newId + "%");
List<String> ids = channels.stream().map(Channel::getChannelId).collect(Collectors.toList());
String suffix = "";
for (int i = 2; ids.contains(newId + suffix); i++) {
suffix = "_" + i;
}
channel.setChannelId(newId + suffix);
saveChannel(channel, reloadChannels);
}

public void editChannel(String oldId, Channel channel) {
ISqlTransaction transaction = null;
try {
Expand Down Expand Up @@ -576,38 +590,7 @@ public Map<String, Channel> getChannels(boolean refreshCache) {
@Override
public Map<String, Channel> getChannelsFromDb() {
Map<String, Channel> channels = new HashMap<String, Channel>();
List<Channel> list = sqlTemplate.query(getSql("selectChannelsSql"),
new ISqlRowMapper<Channel>() {
public Channel mapRow(Row row) {
Channel channel = new Channel();
channel.setChannelId(row.getString("channel_id"));
channel.setProcessingOrder(row.getInt("processing_order"));
channel.setMaxBatchSize(row.getInt("max_batch_size"));
channel.setEnabled(row.getBoolean("enabled"));
channel.setMaxBatchToSend(row.getInt("max_batch_to_send"));
channel.setMaxDataToRoute(row.getInt("max_data_to_route"));
channel.setUseOldDataToRoute(row
.getBoolean("use_old_data_to_route"));
channel.setUseRowDataToRoute(row
.getBoolean("use_row_data_to_route"));
channel.setUsePkDataToRoute(row
.getBoolean("use_pk_data_to_route"));
channel.setContainsBigLob(row.getBoolean("contains_big_lob"));
channel.setBatchAlgorithm(row.getString("batch_algorithm"));
channel.setExtractPeriodMillis(row
.getLong("extract_period_millis"));
channel.setDataLoaderType(row.getString("data_loader_type"));
channel.setCreateTime(row.getDateTime("create_time"));
channel.setLastUpdateBy(row.getString("last_update_by"));
channel.setLastUpdateTime(row.getDateTime("last_update_time"));
channel.setReloadFlag(row.getBoolean("reload_flag"));
channel.setFileSyncFlag(row.getBoolean("file_sync_flag"));
channel.setQueue(row.getString("queue"));
channel.setMaxKBytesPerSecond(row.getBigDecimal("max_network_kbps"));
channel.setDataEventAction(NodeGroupLinkAction.fromCode(row.getString("data_event_action")));
return channel;
}
});
List<Channel> list = sqlTemplate.query(getSql("selectChannelsSql"), new ChannelMapper());
for (Channel channel : list) {
channels.put(channel.getChannelId(), channel);
}
Expand Down Expand Up @@ -710,4 +693,36 @@ public NodeChannel mapRow(Row row) {
return nodeChannel;
}
}

static class ChannelMapper implements ISqlRowMapper<Channel> {
public Channel mapRow(Row row) {
Channel channel = new Channel();
channel.setChannelId(row.getString("channel_id"));
channel.setProcessingOrder(row.getInt("processing_order"));
channel.setMaxBatchSize(row.getInt("max_batch_size"));
channel.setEnabled(row.getBoolean("enabled"));
channel.setMaxBatchToSend(row.getInt("max_batch_to_send"));
channel.setMaxDataToRoute(row.getInt("max_data_to_route"));
channel.setUseOldDataToRoute(row
.getBoolean("use_old_data_to_route"));
channel.setUseRowDataToRoute(row
.getBoolean("use_row_data_to_route"));
channel.setUsePkDataToRoute(row
.getBoolean("use_pk_data_to_route"));
channel.setContainsBigLob(row.getBoolean("contains_big_lob"));
channel.setBatchAlgorithm(row.getString("batch_algorithm"));
channel.setExtractPeriodMillis(row
.getLong("extract_period_millis"));
channel.setDataLoaderType(row.getString("data_loader_type"));
channel.setCreateTime(row.getDateTime("create_time"));
channel.setLastUpdateBy(row.getString("last_update_by"));
channel.setLastUpdateTime(row.getDateTime("last_update_time"));
channel.setReloadFlag(row.getBoolean("reload_flag"));
channel.setFileSyncFlag(row.getBoolean("file_sync_flag"));
channel.setQueue(row.getString("queue"));
channel.setMaxKBytesPerSecond(row.getBigDecimal("max_network_kbps"));
channel.setDataEventAction(NodeGroupLinkAction.fromCode(row.getString("data_event_action")));
return channel;
}
}
}
Expand Up @@ -75,6 +75,15 @@ public ConfigurationServiceSqlMap(IDatabasePlatform platform,
" c.last_update_time, c.last_update_by, c.create_time, c.reload_flag, c.file_sync_flag, " +
" c.queue, c.max_network_kbps, c.data_event_action " +
" from $(channel) c order by c.processing_order asc, c.channel_id ");

putSql("selectChannelsWhereChannelIdLikeSql",
"select c.channel_id, c.processing_order, c.max_batch_size, c.enabled, " +
" c.max_batch_to_send, c.max_data_to_route, c.use_old_data_to_route, " +
" c.use_row_data_to_route, c.use_pk_data_to_route, c.contains_big_lob, " +
" c.batch_algorithm, c.extract_period_millis, c.data_loader_type, " +
" c.last_update_time, c.last_update_by, c.create_time, c.reload_flag, c.file_sync_flag, " +
" c.queue, c.max_network_kbps, c.data_event_action " +
" from $(channel) c where channel_id like ? order by c.processing_order asc, c.channel_id");

putSql("selectNodeChannelsSql",
"select c.channel_id, c.processing_order, "
Expand Down
Expand Up @@ -51,6 +51,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.jumpmind.db.model.Table;
Expand Down Expand Up @@ -127,6 +128,7 @@
import org.jumpmind.symmetric.service.RegistrationNotOpenException;
import org.jumpmind.symmetric.service.RegistrationPendingException;
import org.jumpmind.symmetric.service.RegistrationRequiredException;
import org.jumpmind.symmetric.service.impl.DataLoaderService.ConflictNodeGroupLink;
import org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink;
import org.jumpmind.symmetric.statistic.IStatisticManager;
import org.jumpmind.symmetric.transport.AuthenticationException;
Expand Down Expand Up @@ -820,6 +822,19 @@ public void save(ConflictNodeGroupLink setting) {
}
}

public void saveAsCopy(ConflictNodeGroupLink settings) {
String newId = settings.getConflictId();
List<ConflictNodeGroupLink> conflicts = sqlTemplate.query(
getSql("selectConflictSettingsSql", "whereConflictIdLike"), new ConflictSettingsNodeGroupLinkMapper(), newId + "%");
List<String> ids = conflicts.stream().map(ConflictNodeGroupLink::getConflictId).collect(Collectors.toList());
String suffix = "";
for (int i = 2; ids.contains(newId + suffix); i++) {
suffix = "_" + i;
}
settings.setConflictId(newId + suffix);
save(settings);
}

public void edit(String oldId, ConflictNodeGroupLink setting) {
ISqlTransaction transaction = null;
try {
Expand Down
Expand Up @@ -85,6 +85,8 @@ public class DataLoaderServiceSqlMap extends AbstractSqlMap {
putSql("updateIncomingErrorSql",
"update $(incoming_error) set resolve_data = ?, resolve_ignore = ? " +
"where batch_id = ? and node_id = ? and failed_row_number = ?");

putSql("whereConflictIdLike", "where conflict_id like ?");

// @formatter:on
}
Expand Down
Expand Up @@ -25,6 +25,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -291,6 +292,19 @@ public void saveExtension(Extension extension) {
}
}

public void saveExtensionAsCopy(Extension extension) {
String newId = extension.getExtensionId();
List<Extension> extensions = sqlTemplate.query(getSql("selectAll", "whereExtensionIdLike"),
new ExtensionRowMapper(), newId + "%");
List<String> ids = extensions.stream().map(Extension::getExtensionId).collect(Collectors.toList());
String suffix = "";
for (int i = 2; ids.contains(newId + suffix); i++) {
suffix = "_" + i;
}
extension.setExtensionId(newId + suffix);
saveExtension(extension);
}

public void editExtension(String oldId, Extension extension) {
ISqlTransaction transaction = null;
try {
Expand Down
Expand Up @@ -39,5 +39,6 @@ public ExtensionServiceSqlMap(IDatabasePlatform platform, Map<String, String> re
"node_group_id = ?, enabled = ?, extension_order = ?, extension_text = ?, last_update_by = ?, " +
"last_update_time = current_timestamp where extension_id = ?");
putSql("deleteExtensionSql", "delete from $(extension) where extension_id = ?");
putSql("whereExtensionIdLike", "where extension_id like ?");
}
}

0 comments on commit e573ff8

Please sign in to comment.