Kaynağa Gözat

fix population of app objects upon account creation

tags/v0.9.7
Jonathan Cobb 4 yıl önce
ebeveyn
işleme
08f0b55905
3 değiştirilmiş dosya ile 20 ekleme ve 9 silme
  1. +13
    -0
      bubble-server/src/main/java/bubble/dao/account/AccountDAO.java
  2. +7
    -2
      bubble-server/src/main/java/bubble/model/account/AccountTemplate.java
  3. +0
    -7
      bubble-server/src/main/resources/models/apps/user_block/mr/bubbleApp_userBlock_mr_matchers.json

+ 13
- 0
bubble-server/src/main/java/bubble/dao/account/AccountDAO.java Dosyayı Görüntüle

@@ -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<Account> implements SqlViewSearc

final Map<String, AppSite> sites = new HashMap<>();
copyTemplateObjects(acct, parent, siteDAO, new AccountTemplate.CopyTemplate<>() {
@Override public AppSite findAccountEntity(AccountOwnedTemplateDAO<AppSite> 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<String, AppRule> rules = new HashMap<>();
copyTemplateObjects(acct, parent, ruleDAO, new AccountTemplate.CopyTemplate<>() {
@Override public AppRule findAccountEntity(AccountOwnedTemplateDAO<AppRule> 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<Account> implements SqlViewSearc

final Map<String, AppMatcher> matchers = new HashMap<>();
copyTemplateObjects(acct, parent, matchDAO, new AccountTemplate.CopyTemplate<>() {
@Override public AppMatcher findAccountEntity(AccountOwnedTemplateDAO<AppMatcher> 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())


+ 7
- 2
bubble-server/src/main/java/bubble/model/account/AccountTemplate.java Dosyayı Görüntüle

@@ -25,6 +25,9 @@ public interface AccountTemplate extends HasAccount {
Logger log = LoggerFactory.getLogger(AccountTemplate.class);

interface CopyTemplate<E extends AccountTemplate> {
default E findAccountEntity(AccountOwnedTemplateDAO<E> 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<E> 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);
}


+ 0
- 7
bubble-server/src/main/resources/models/apps/user_block/mr/bubbleApp_userBlock_mr_matchers.json Dosyayı Görüntüle

@@ -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"
}]
}
}]

Yükleniyor…
İptal
Kaydet