From 08f0b55905e2a1c6c07b378e2003ec27b05708fd Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Fri, 28 Feb 2020 16:32:07 -0500 Subject: [PATCH] fix population of app objects upon account creation --- .../main/java/bubble/dao/account/AccountDAO.java | 13 +++++++++++++ .../java/bubble/model/account/AccountTemplate.java | 9 +++++++-- .../mr/bubbleApp_userBlock_mr_matchers.json | 7 ------- 3 files changed, 20 insertions(+), 9 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 f9a9de6e..032fb4bd 100644 --- a/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java +++ b/bubble-server/src/main/java/bubble/dao/account/AccountDAO.java @@ -46,6 +46,8 @@ import static bubble.server.BubbleConfiguration.getDEFAULT_LOCALE; import static java.lang.Thread.currentThread; import static java.util.concurrent.TimeUnit.MINUTES; import static org.cobbzilla.util.daemon.ZillaRuntime.daemon; +import static org.cobbzilla.util.json.JsonUtil.COMPACT_MAPPER; +import static org.cobbzilla.util.json.JsonUtil.json; import static org.cobbzilla.wizard.model.IdentifiableBase.CTIME_ASC; import static org.cobbzilla.wizard.resources.ResourceUtil.invalidEx; @@ -251,16 +253,24 @@ public class AccountDAO extends AbstractCRUDDAO implements SqlViewSearc final Map sites = new HashMap<>(); copyTemplateObjects(acct, parent, siteDAO, new AccountTemplate.CopyTemplate<>() { + @Override public AppSite findAccountEntity(AccountOwnedTemplateDAO dao, String accountUuid, AppSite parentEntity) { + return ((AppSiteDAO) dao).findByAccountAndAppAndId(accountUuid, apps.get(parentEntity.getApp()).getUuid(), parentEntity.getName()); + } @Override public AppSite preCreate(AppSite parentEntity, AppSite accountEntity) { + log.info("CopyTemplate.AppSite.preCreate: site="+json(accountEntity, COMPACT_MAPPER)); return accountEntity.setApp(apps.get(parentEntity.getApp()).getUuid()); } @Override public void postCreate(AppSite parentEntity, AppSite accountEntity) { + log.info("CopyTemplate.AppSite.postCreate: site="+json(accountEntity, COMPACT_MAPPER)); sites.put(parentEntity.getUuid(), accountEntity); } }); final Map rules = new HashMap<>(); copyTemplateObjects(acct, parent, ruleDAO, new AccountTemplate.CopyTemplate<>() { + @Override public AppRule findAccountEntity(AccountOwnedTemplateDAO dao, String accountUuid, AppRule parentEntity) { + return ((AppRuleDAO) dao).findByAccountAndAppAndId(accountUuid, apps.get(parentEntity.getApp()).getUuid(), parentEntity.getName()); + } @Override public AppRule preCreate(AppRule parentEntity, AppRule accountEntity) { return accountEntity .setApp(apps.get(parentEntity.getApp()).getUuid()) @@ -273,6 +283,9 @@ public class AccountDAO extends AbstractCRUDDAO implements SqlViewSearc final Map matchers = new HashMap<>(); copyTemplateObjects(acct, parent, matchDAO, new AccountTemplate.CopyTemplate<>() { + @Override public AppMatcher findAccountEntity(AccountOwnedTemplateDAO dao, String accountUuid, AppMatcher parentEntity) { + return ((AppMatcherDAO) dao).findByAccountAndAppAndId(accountUuid, apps.get(parentEntity.getApp()).getUuid(), parentEntity.getName()); + } @Override public AppMatcher preCreate(AppMatcher parentEntity, AppMatcher accountEntity) { return accountEntity .setApp(apps.get(parentEntity.getApp()).getUuid()) diff --git a/bubble-server/src/main/java/bubble/model/account/AccountTemplate.java b/bubble-server/src/main/java/bubble/model/account/AccountTemplate.java index cc0ef53d..a904cc79 100644 --- a/bubble-server/src/main/java/bubble/model/account/AccountTemplate.java +++ b/bubble-server/src/main/java/bubble/model/account/AccountTemplate.java @@ -25,6 +25,9 @@ public interface AccountTemplate extends HasAccount { Logger log = LoggerFactory.getLogger(AccountTemplate.class); interface CopyTemplate { + default E findAccountEntity(AccountOwnedTemplateDAO dao, String accountUuid, E parentEntity) { + return dao.findByAccountAndId(parentEntity.getName(), accountUuid); + } default E preCreate (E parentEntity, E accountEntity) { return accountEntity; } default void postCreate (E parentEntity, E accountEntity) { } } @@ -41,7 +44,9 @@ public interface AccountTemplate extends HasAccount { CopyTemplate copy) { try { for (E parentEntity : dao.findPublicTemplates(parentAccountUuid)) { - E accountEntity = dao.findByAccountAndId(accountUuid, parentEntity.getName()); + E accountEntity = copy != null + ? copy.findAccountEntity(dao, accountUuid, parentEntity) + : dao.findByAccountAndId(parentEntity.getName(), accountUuid); if (accountEntity == null) { accountEntity = ((E) instantiate(parentEntity.getClass(), parentEntity)).setAccount(accountUuid); if (copy != null) accountEntity = copy.preCreate(parentEntity, accountEntity); @@ -49,7 +54,7 @@ public interface AccountTemplate extends HasAccount { log.warn("copyTemplateObjects: preCreate returned null for parentEntity: " + parentEntity); return; } - accountEntity= dao.create(accountEntity.setTemplate(false)); + accountEntity = dao.create(accountEntity.setTemplate(false)); } if (copy != null) copy.postCreate(parentEntity, accountEntity); } diff --git a/bubble-server/src/main/resources/models/apps/user_block/mr/bubbleApp_userBlock_mr_matchers.json b/bubble-server/src/main/resources/models/apps/user_block/mr/bubbleApp_userBlock_mr_matchers.json index 442e1497..6ca8977f 100644 --- a/bubble-server/src/main/resources/models/apps/user_block/mr/bubbleApp_userBlock_mr_matchers.json +++ b/bubble-server/src/main/resources/models/apps/user_block/mr/bubbleApp_userBlock_mr_matchers.json @@ -8,13 +8,6 @@ "fqdn": "marginalrevolution.com", "urlRegex": "(/marginalrevolution)?/20\\d{2}/\\d{2}/\\w+", "rule": "mr_user_blocker" - }, { - "name": "MRTestMatcher", - "site": "MarginalRevolution", - "template": true, - "fqdn": "kyuss.org", - "urlRegex": "/20\\d{2}/\\d{2}/\\w+", - "rule": "mr_user_blocker" }] } }]