From 665ca2458ff3950d92551a9e025e4b13d84c02aa Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Tue, 8 Sep 2020 12:25:21 +0200 Subject: [PATCH 1/7] Skip network owner account in bulk delete --- .../java/bubble/dao/account/AccountDAO.java | 18 ++++++++++++++++++ .../bubble/service/stream/AppDataCleaner.java | 2 +- utils/cobbzilla-wizard | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java b/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java index 35a7a13b..e72f784d 100644 --- a/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java +++ b/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java @@ -37,7 +37,9 @@ import org.glassfish.grizzly.http.server.Request; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; +import javax.annotation.Nullable; import javax.transaction.Transactional; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -346,6 +348,22 @@ public class AccountDAO extends AbstractCRUDDAO implements SqlViewSearc log.info("copyTemplates completed: "+acct); } + @Override + public int bulkDeleteWhere(@NonNull final String whereClause, @NonNull final Map parameters) { + parameters.put("thisNetworkOwnerAccountUuid", configuration.getThisNetwork().getAccount()); + return super.bulkDeleteWhere("uuid != :thisNetworkOwnerAccountUuid AND (" + whereClause + ")", parameters); + } + + @Override + public void delete(@Nullable final Collection accounts) { + if (empty(accounts)) return; + final var networkOwnerUuid = configuration.getThisNetwork().getAccount(); + if (accounts.removeIf(a -> a != null && a.getUuid().equals(networkOwnerUuid))) { + log.warn("delete: skipping deletion of network owner's account: " + networkOwnerUuid); + } + super.delete(accounts); + } + @Override public void delete(@NonNull final String uuid) { // you cannot delete the account that owns the current network if (uuid.equals(configuration.getThisNetwork().getAccount())) { diff --git a/bubble-server/src/main/java/bubble/service/stream/AppDataCleaner.java b/bubble-server/src/main/java/bubble/service/stream/AppDataCleaner.java index f814b597..e77877af 100644 --- a/bubble-server/src/main/java/bubble/service/stream/AppDataCleaner.java +++ b/bubble-server/src/main/java/bubble/service/stream/AppDataCleaner.java @@ -25,7 +25,7 @@ public class AppDataCleaner extends SimpleDaemon { @Override protected void process() { try { - final int ct = dataDAO.bulkDeleteWhere("expiration < " + now()); + final int ct = dataDAO.bulkDeleteWhere("expiration < " + now(), null); log.info("process: removed " + ct + " expired AppData records"); } catch (Exception e) { reportError("AppDataCleaner.process: "+shortError(e), e); diff --git a/utils/cobbzilla-wizard b/utils/cobbzilla-wizard index 47b03e4b..c591f697 160000 --- a/utils/cobbzilla-wizard +++ b/utils/cobbzilla-wizard @@ -1 +1 @@ -Subproject commit 47b03e4b00490119357d8972ce7ed727266b6c35 +Subproject commit c591f6970bb385312f94fc7fbc5848025ac77eec -- 2.17.1 From 92c12d87f705b436158b53fe837b0b66df06c843 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Tue, 8 Sep 2020 12:44:53 +0200 Subject: [PATCH 2/7] Set bulkDelete's parameters to be non null --- .../src/main/java/bubble/service/stream/AppDataCleaner.java | 4 +++- utils/cobbzilla-wizard | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bubble-server/src/main/java/bubble/service/stream/AppDataCleaner.java b/bubble-server/src/main/java/bubble/service/stream/AppDataCleaner.java index e77877af..d53a11b1 100644 --- a/bubble-server/src/main/java/bubble/service/stream/AppDataCleaner.java +++ b/bubble-server/src/main/java/bubble/service/stream/AppDataCleaner.java @@ -11,6 +11,8 @@ import org.cobbzilla.util.daemon.SimpleDaemon; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.HashMap; + import static java.util.concurrent.TimeUnit.HOURS; import static org.cobbzilla.util.daemon.ZillaRuntime.now; import static org.cobbzilla.util.daemon.ZillaRuntime.shortError; @@ -25,7 +27,7 @@ public class AppDataCleaner extends SimpleDaemon { @Override protected void process() { try { - final int ct = dataDAO.bulkDeleteWhere("expiration < " + now(), null); + final int ct = dataDAO.bulkDeleteWhere("expiration < " + now(), new HashMap<>()); log.info("process: removed " + ct + " expired AppData records"); } catch (Exception e) { reportError("AppDataCleaner.process: "+shortError(e), e); diff --git a/utils/cobbzilla-wizard b/utils/cobbzilla-wizard index c591f697..04683a86 160000 --- a/utils/cobbzilla-wizard +++ b/utils/cobbzilla-wizard @@ -1 +1 @@ -Subproject commit c591f6970bb385312f94fc7fbc5848025ac77eec +Subproject commit 04683a86d81eefb61e337b073e851de47a61e769 -- 2.17.1 From cd3d87132778c85b7ea14bbbae570a5c3eb3ad29 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Tue, 8 Sep 2020 14:36:37 +0200 Subject: [PATCH 3/7] Do not checkout master of utils submodules on build --- bin/first_time_setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/first_time_setup.sh b/bin/first_time_setup.sh index 832be08f..d751664e 100755 --- a/bin/first_time_setup.sh +++ b/bin/first_time_setup.sh @@ -46,7 +46,7 @@ abp-parser " pushd utils for repo in ${UTIL_REPOS} ; do - pushd ${repo} && git checkout master && mvn -DskipTests=true -Dcheckstyle.skip=true clean install && popd || die "Error installing ${repo}" + pushd ${repo} && mvn -DskipTests=true -Dcheckstyle.skip=true clean install && popd || die "Error installing ${repo}" done popd -- 2.17.1 From b32ac10e01163d8524b7d53f34d9450bf96c75ae Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Tue, 8 Sep 2020 14:59:27 +0200 Subject: [PATCH 4/7] Update cobbzilla-wizard --- utils/cobbzilla-wizard | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/cobbzilla-wizard b/utils/cobbzilla-wizard index 04683a86..0ce731a3 160000 --- a/utils/cobbzilla-wizard +++ b/utils/cobbzilla-wizard @@ -1 +1 @@ -Subproject commit 04683a86d81eefb61e337b073e851de47a61e769 +Subproject commit 0ce731a3f64aa75c0da578021e7985ca03c24e87 -- 2.17.1 From 5ed2e5851ffbff38dd0ec8f0a893f9c3672e0ee9 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Wed, 9 Sep 2020 12:48:49 +0200 Subject: [PATCH 5/7] Use old bulk delete method without params --- .../src/main/java/bubble/service/stream/AppDataCleaner.java | 4 +--- utils/cobbzilla-wizard | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/bubble-server/src/main/java/bubble/service/stream/AppDataCleaner.java b/bubble-server/src/main/java/bubble/service/stream/AppDataCleaner.java index d53a11b1..f814b597 100644 --- a/bubble-server/src/main/java/bubble/service/stream/AppDataCleaner.java +++ b/bubble-server/src/main/java/bubble/service/stream/AppDataCleaner.java @@ -11,8 +11,6 @@ import org.cobbzilla.util.daemon.SimpleDaemon; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.HashMap; - import static java.util.concurrent.TimeUnit.HOURS; import static org.cobbzilla.util.daemon.ZillaRuntime.now; import static org.cobbzilla.util.daemon.ZillaRuntime.shortError; @@ -27,7 +25,7 @@ public class AppDataCleaner extends SimpleDaemon { @Override protected void process() { try { - final int ct = dataDAO.bulkDeleteWhere("expiration < " + now(), new HashMap<>()); + final int ct = dataDAO.bulkDeleteWhere("expiration < " + now()); log.info("process: removed " + ct + " expired AppData records"); } catch (Exception e) { reportError("AppDataCleaner.process: "+shortError(e), e); diff --git a/utils/cobbzilla-wizard b/utils/cobbzilla-wizard index 0ce731a3..6ad35ab2 160000 --- a/utils/cobbzilla-wizard +++ b/utils/cobbzilla-wizard @@ -1 +1 @@ -Subproject commit 0ce731a3f64aa75c0da578021e7985ca03c24e87 +Subproject commit 6ad35ab2c21b8887f945b65cb224f99d870ab3ed -- 2.17.1 From e648f6b6099c4c293b73580e61ec988621bab2e0 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Wed, 9 Sep 2020 12:52:50 +0200 Subject: [PATCH 6/7] Join Override annotation with method signature in a line --- .../src/main/java/bubble/dao/account/AccountDAO.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java b/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java index e72f784d..768a8d51 100644 --- a/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java +++ b/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java @@ -348,14 +348,13 @@ public class AccountDAO extends AbstractCRUDDAO implements SqlViewSearc log.info("copyTemplates completed: "+acct); } - @Override - public int bulkDeleteWhere(@NonNull final String whereClause, @NonNull final Map parameters) { + @Override public int bulkDeleteWhere(@NonNull final String whereClause, + @NonNull final Map parameters) { parameters.put("thisNetworkOwnerAccountUuid", configuration.getThisNetwork().getAccount()); return super.bulkDeleteWhere("uuid != :thisNetworkOwnerAccountUuid AND (" + whereClause + ")", parameters); } - @Override - public void delete(@Nullable final Collection accounts) { + @Override public void delete(@Nullable final Collection accounts) { if (empty(accounts)) return; final var networkOwnerUuid = configuration.getThisNetwork().getAccount(); if (accounts.removeIf(a -> a != null && a.getUuid().equals(networkOwnerUuid))) { -- 2.17.1 From 8c1f182169370193e216e47856aaa6e1a7bdd360 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Wed, 9 Sep 2020 18:11:03 +0200 Subject: [PATCH 7/7] Allow now as second parameter of bulk delete --- .../src/main/java/bubble/dao/account/AccountDAO.java | 11 ++++++++--- utils/cobbzilla-wizard | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java b/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java index 768a8d51..2a56ea38 100644 --- a/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java +++ b/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java @@ -348,10 +348,15 @@ public class AccountDAO extends AbstractCRUDDAO implements SqlViewSearc log.info("copyTemplates completed: "+acct); } + private final String NETWORK_OWNER_ACCOUNT_UUID_PARAM = "__thisNetworkOwnerAccountUuid__"; + @Override public int bulkDeleteWhere(@NonNull final String whereClause, - @NonNull final Map parameters) { - parameters.put("thisNetworkOwnerAccountUuid", configuration.getThisNetwork().getAccount()); - return super.bulkDeleteWhere("uuid != :thisNetworkOwnerAccountUuid AND (" + whereClause + ")", parameters); + @Nullable final Map parameters) { + final Map enhancedParams = parameters != null ? parameters : new HashMap<>(); + enhancedParams.put(NETWORK_OWNER_ACCOUNT_UUID_PARAM, configuration.getThisNetwork().getAccount()); + + return super.bulkDeleteWhere("uuid != :" + NETWORK_OWNER_ACCOUNT_UUID_PARAM + " AND (" + whereClause + ")", + enhancedParams); } @Override public void delete(@Nullable final Collection accounts) { diff --git a/utils/cobbzilla-wizard b/utils/cobbzilla-wizard index 6ad35ab2..14518c3c 160000 --- a/utils/cobbzilla-wizard +++ b/utils/cobbzilla-wizard @@ -1 +1 @@ -Subproject commit 6ad35ab2c21b8887f945b65cb224f99d870ab3ed +Subproject commit 14518c3c60a455df3542e68949d87dffc9e70ae7 -- 2.17.1