From 93caad9d6d9624ed4eae88be2284329f61b66b23 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Sat, 1 Feb 2020 09:15:03 -0500 Subject: [PATCH] reorganize app config classes/packages --- .../main/java/bubble/abp/BlockListType.java | 11 ---- .../app/analytics/TrafficAnalyticsApp.java | 1 + .../java/bubble/model/app/AppDataDriver.java | 1 + .../bubble/model/app/AppDataDriverBase.java | 1 + .../main/java/bubble/model/app/BubbleApp.java | 1 + .../model/app/config/AppConfigAction.java | 13 +++++ .../model/app/config/AppConfigActionType.java | 13 +++++ .../model/app/config/AppConfigView.java | 14 +++++ .../model/app/config/AppConfigViewType.java | 13 +++++ .../model/app/{ => config}/AppDataAction.java | 2 +- .../model/app/{ => config}/AppDataConfig.java | 14 ++++- .../model/app/{ => config}/AppDataField.java | 2 +- .../model/app/{ => config}/AppDataParam.java | 2 +- .../app/{ => config}/AppDataPresentation.java | 2 +- .../model/app/{ => config}/AppDataView.java | 2 +- .../resources/app/AppSitesResource.java | 2 +- .../bubble/resources/app/AppsResource.java | 2 +- .../resources/app/AppsResourceBase.java | 4 +- .../service/message/AppMessageService.java | 3 + .../post_auth/ResourceMessages.properties | 1 + .../models/apps/bblock/bubbleApp_bblock.json | 58 +++++++++++++------ 21 files changed, 121 insertions(+), 41 deletions(-) delete mode 100644 bubble-server/src/main/java/bubble/abp/BlockListType.java create mode 100644 bubble-server/src/main/java/bubble/model/app/config/AppConfigAction.java create mode 100644 bubble-server/src/main/java/bubble/model/app/config/AppConfigActionType.java create mode 100644 bubble-server/src/main/java/bubble/model/app/config/AppConfigView.java create mode 100644 bubble-server/src/main/java/bubble/model/app/config/AppConfigViewType.java rename bubble-server/src/main/java/bubble/model/app/{ => config}/AppDataAction.java (82%) rename bubble-server/src/main/java/bubble/model/app/{ => config}/AppDataConfig.java (77%) rename bubble-server/src/main/java/bubble/model/app/{ => config}/AppDataField.java (88%) rename bubble-server/src/main/java/bubble/model/app/{ => config}/AppDataParam.java (93%) rename bubble-server/src/main/java/bubble/model/app/{ => config}/AppDataPresentation.java (90%) rename bubble-server/src/main/java/bubble/model/app/{ => config}/AppDataView.java (90%) diff --git a/bubble-server/src/main/java/bubble/abp/BlockListType.java b/bubble-server/src/main/java/bubble/abp/BlockListType.java deleted file mode 100644 index 50c6c6f3..00000000 --- a/bubble-server/src/main/java/bubble/abp/BlockListType.java +++ /dev/null @@ -1,11 +0,0 @@ -package bubble.abp; - -import com.fasterxml.jackson.annotation.JsonCreator; - -public enum BlockListType { - - ads, malware, privacy, clickbait, gambling, phishing, nsfw, crypto, annoyances, custom; - - @JsonCreator public BlockListType fromString (String v) { return valueOf(v.toLowerCase()); } - -} diff --git a/bubble-server/src/main/java/bubble/app/analytics/TrafficAnalyticsApp.java b/bubble-server/src/main/java/bubble/app/analytics/TrafficAnalyticsApp.java index 9d06efdc..0f659959 100644 --- a/bubble-server/src/main/java/bubble/app/analytics/TrafficAnalyticsApp.java +++ b/bubble-server/src/main/java/bubble/app/analytics/TrafficAnalyticsApp.java @@ -2,6 +2,7 @@ package bubble.app.analytics; import bubble.model.account.Account; import bubble.model.app.*; +import bubble.model.app.config.AppDataView; import bubble.model.device.Device; import bubble.rule.analytics.TrafficAnalytics; import bubble.rule.analytics.TrafficRecord; diff --git a/bubble-server/src/main/java/bubble/model/app/AppDataDriver.java b/bubble-server/src/main/java/bubble/model/app/AppDataDriver.java index 8a073444..5adde03d 100644 --- a/bubble-server/src/main/java/bubble/model/app/AppDataDriver.java +++ b/bubble-server/src/main/java/bubble/model/app/AppDataDriver.java @@ -1,6 +1,7 @@ package bubble.model.app; import bubble.model.account.Account; +import bubble.model.app.config.AppDataView; import bubble.model.device.Device; import org.cobbzilla.wizard.dao.SearchResults; import org.cobbzilla.wizard.model.search.SearchQuery; diff --git a/bubble-server/src/main/java/bubble/model/app/AppDataDriverBase.java b/bubble-server/src/main/java/bubble/model/app/AppDataDriverBase.java index 4dbe594e..a7aa3c02 100644 --- a/bubble-server/src/main/java/bubble/model/app/AppDataDriverBase.java +++ b/bubble-server/src/main/java/bubble/model/app/AppDataDriverBase.java @@ -2,6 +2,7 @@ package bubble.model.app; import bubble.dao.app.AppDataDAO; import bubble.model.account.Account; +import bubble.model.app.config.AppDataView; import bubble.model.device.Device; import bubble.service.SearchService; import org.cobbzilla.wizard.cache.redis.RedisService; diff --git a/bubble-server/src/main/java/bubble/model/app/BubbleApp.java b/bubble-server/src/main/java/bubble/model/app/BubbleApp.java index dedf2dd7..42175a33 100644 --- a/bubble-server/src/main/java/bubble/model/app/BubbleApp.java +++ b/bubble-server/src/main/java/bubble/model/app/BubbleApp.java @@ -2,6 +2,7 @@ package bubble.model.app; import bubble.model.account.Account; import bubble.model.account.AccountTemplate; +import bubble.model.app.config.AppDataConfig; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/bubble-server/src/main/java/bubble/model/app/config/AppConfigAction.java b/bubble-server/src/main/java/bubble/model/app/config/AppConfigAction.java new file mode 100644 index 00000000..a0d79dfd --- /dev/null +++ b/bubble-server/src/main/java/bubble/model/app/config/AppConfigAction.java @@ -0,0 +1,13 @@ +package bubble.model.app.config; + +import lombok.Getter; +import lombok.Setter; + +public class AppConfigAction { + + @Getter @Setter private String name; + @Getter @Setter private AppConfigActionType type; + @Getter @Setter private String when; + @Getter @Setter private String view; + +} diff --git a/bubble-server/src/main/java/bubble/model/app/config/AppConfigActionType.java b/bubble-server/src/main/java/bubble/model/app/config/AppConfigActionType.java new file mode 100644 index 00000000..5d425e0a --- /dev/null +++ b/bubble-server/src/main/java/bubble/model/app/config/AppConfigActionType.java @@ -0,0 +1,13 @@ +package bubble.model.app.config; + +import com.fasterxml.jackson.annotation.JsonCreator; + +import static bubble.ApiConstants.enumFromString; + +public enum AppConfigActionType { + + create, update; + + @JsonCreator public static AppConfigActionType fromString(String v) { return enumFromString(AppConfigActionType.class, v); } + +} diff --git a/bubble-server/src/main/java/bubble/model/app/config/AppConfigView.java b/bubble-server/src/main/java/bubble/model/app/config/AppConfigView.java new file mode 100644 index 00000000..f7678c66 --- /dev/null +++ b/bubble-server/src/main/java/bubble/model/app/config/AppConfigView.java @@ -0,0 +1,14 @@ +package bubble.model.app.config; + +import lombok.Getter; +import lombok.Setter; + +public class AppConfigView { + + @Getter @Setter private String name; + @Getter @Setter private AppConfigViewType type; + @Getter @Setter private String[] columns; + @Getter @Setter private AppConfigAction[] actions; + @Getter @Setter private AppDataField[] fields; + +} diff --git a/bubble-server/src/main/java/bubble/model/app/config/AppConfigViewType.java b/bubble-server/src/main/java/bubble/model/app/config/AppConfigViewType.java new file mode 100644 index 00000000..1b6718f3 --- /dev/null +++ b/bubble-server/src/main/java/bubble/model/app/config/AppConfigViewType.java @@ -0,0 +1,13 @@ +package bubble.model.app.config; + +import com.fasterxml.jackson.annotation.JsonCreator; + +import static bubble.ApiConstants.enumFromString; + +public enum AppConfigViewType { + + list, item; + + @JsonCreator public static AppConfigViewType fromString (String v) { return enumFromString(AppConfigViewType.class, v); } + +} diff --git a/bubble-server/src/main/java/bubble/model/app/AppDataAction.java b/bubble-server/src/main/java/bubble/model/app/config/AppDataAction.java similarity index 82% rename from bubble-server/src/main/java/bubble/model/app/AppDataAction.java rename to bubble-server/src/main/java/bubble/model/app/config/AppDataAction.java index 907f2782..6b1c8bcf 100644 --- a/bubble-server/src/main/java/bubble/model/app/AppDataAction.java +++ b/bubble-server/src/main/java/bubble/model/app/config/AppDataAction.java @@ -1,4 +1,4 @@ -package bubble.model.app; +package bubble.model.app.config; import lombok.Getter; import lombok.Setter; diff --git a/bubble-server/src/main/java/bubble/model/app/AppDataConfig.java b/bubble-server/src/main/java/bubble/model/app/config/AppDataConfig.java similarity index 77% rename from bubble-server/src/main/java/bubble/model/app/AppDataConfig.java rename to bubble-server/src/main/java/bubble/model/app/config/AppDataConfig.java index 51f4b5fd..6ce05819 100644 --- a/bubble-server/src/main/java/bubble/model/app/AppDataConfig.java +++ b/bubble-server/src/main/java/bubble/model/app/config/AppDataConfig.java @@ -1,5 +1,6 @@ -package bubble.model.app; +package bubble.model.app.config; +import bubble.model.app.*; import bubble.server.BubbleConfiguration; import lombok.Getter; import lombok.Setter; @@ -7,7 +8,7 @@ import lombok.Setter; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import static bubble.model.app.AppDataPresentation.none; +import static bubble.model.app.config.AppDataPresentation.none; import static org.cobbzilla.util.daemon.ZillaRuntime.empty; import static org.cobbzilla.util.reflect.ReflectionUtil.instantiate; @@ -42,6 +43,15 @@ public class AppDataConfig { return null; } + @Getter @Setter private AppConfigView[] configViews; + public boolean hasConfigViews () { return !empty(configViews); } + + public AppConfigView getConfigView(String viewName) { + if (!hasConfigViews()) return null; + for (AppConfigView v : getConfigViews()) if (v.getName().equalsIgnoreCase(viewName)) return v; + return null; + } + private final Map DRIVER_CACHE = new ConcurrentHashMap<>(); public AppDataDriver getDriver(BubbleConfiguration configuration) { return DRIVER_CACHE.computeIfAbsent(getDriverClass(), c -> configuration.autowire(instantiate(c))); diff --git a/bubble-server/src/main/java/bubble/model/app/AppDataField.java b/bubble-server/src/main/java/bubble/model/app/config/AppDataField.java similarity index 88% rename from bubble-server/src/main/java/bubble/model/app/AppDataField.java rename to bubble-server/src/main/java/bubble/model/app/config/AppDataField.java index d31bc7a3..e128d3c8 100644 --- a/bubble-server/src/main/java/bubble/model/app/AppDataField.java +++ b/bubble-server/src/main/java/bubble/model/app/config/AppDataField.java @@ -1,4 +1,4 @@ -package bubble.model.app; +package bubble.model.app.config; import lombok.Getter; import lombok.Setter; diff --git a/bubble-server/src/main/java/bubble/model/app/AppDataParam.java b/bubble-server/src/main/java/bubble/model/app/config/AppDataParam.java similarity index 93% rename from bubble-server/src/main/java/bubble/model/app/AppDataParam.java rename to bubble-server/src/main/java/bubble/model/app/config/AppDataParam.java index 02cc4039..72b6bd45 100644 --- a/bubble-server/src/main/java/bubble/model/app/AppDataParam.java +++ b/bubble-server/src/main/java/bubble/model/app/config/AppDataParam.java @@ -1,4 +1,4 @@ -package bubble.model.app; +package bubble.model.app.config; import lombok.Getter; import lombok.Setter; diff --git a/bubble-server/src/main/java/bubble/model/app/AppDataPresentation.java b/bubble-server/src/main/java/bubble/model/app/config/AppDataPresentation.java similarity index 90% rename from bubble-server/src/main/java/bubble/model/app/AppDataPresentation.java rename to bubble-server/src/main/java/bubble/model/app/config/AppDataPresentation.java index af8d7c8b..638dfa77 100644 --- a/bubble-server/src/main/java/bubble/model/app/AppDataPresentation.java +++ b/bubble-server/src/main/java/bubble/model/app/config/AppDataPresentation.java @@ -1,4 +1,4 @@ -package bubble.model.app; +package bubble.model.app.config; import com.fasterxml.jackson.annotation.JsonCreator; diff --git a/bubble-server/src/main/java/bubble/model/app/AppDataView.java b/bubble-server/src/main/java/bubble/model/app/config/AppDataView.java similarity index 90% rename from bubble-server/src/main/java/bubble/model/app/AppDataView.java rename to bubble-server/src/main/java/bubble/model/app/config/AppDataView.java index 4cfd6bae..6d03f50e 100644 --- a/bubble-server/src/main/java/bubble/model/app/AppDataView.java +++ b/bubble-server/src/main/java/bubble/model/app/config/AppDataView.java @@ -1,4 +1,4 @@ -package bubble.model.app; +package bubble.model.app.config; import lombok.Getter; import lombok.Setter; diff --git a/bubble-server/src/main/java/bubble/resources/app/AppSitesResource.java b/bubble-server/src/main/java/bubble/resources/app/AppSitesResource.java index 9a60253d..ebb507ff 100644 --- a/bubble-server/src/main/java/bubble/resources/app/AppSitesResource.java +++ b/bubble-server/src/main/java/bubble/resources/app/AppSitesResource.java @@ -3,7 +3,7 @@ package bubble.resources.app; import bubble.dao.app.AppSiteDAO; import bubble.model.account.Account; import bubble.model.app.AppDataDriver; -import bubble.model.app.AppDataView; +import bubble.model.app.config.AppDataView; import bubble.model.app.AppSite; import bubble.model.app.BubbleApp; import bubble.model.device.Device; diff --git a/bubble-server/src/main/java/bubble/resources/app/AppsResource.java b/bubble-server/src/main/java/bubble/resources/app/AppsResource.java index c8aba457..d11c1304 100644 --- a/bubble-server/src/main/java/bubble/resources/app/AppsResource.java +++ b/bubble-server/src/main/java/bubble/resources/app/AppsResource.java @@ -2,7 +2,7 @@ package bubble.resources.app; import bubble.model.account.Account; import bubble.model.app.AppDataDriver; -import bubble.model.app.AppDataView; +import bubble.model.app.config.AppDataView; import bubble.model.app.BubbleApp; import bubble.model.device.Device; import bubble.service.cloud.DeviceIdService; diff --git a/bubble-server/src/main/java/bubble/resources/app/AppsResourceBase.java b/bubble-server/src/main/java/bubble/resources/app/AppsResourceBase.java index b9377189..7e21a9dd 100644 --- a/bubble-server/src/main/java/bubble/resources/app/AppsResourceBase.java +++ b/bubble-server/src/main/java/bubble/resources/app/AppsResourceBase.java @@ -4,9 +4,9 @@ import bubble.dao.app.AppMatcherDAO; import bubble.dao.app.AppRuleDAO; import bubble.dao.app.BubbleAppDAO; import bubble.model.account.Account; -import bubble.model.app.AppDataConfig; +import bubble.model.app.config.AppDataConfig; import bubble.model.app.AppDataDriver; -import bubble.model.app.AppDataPresentation; +import bubble.model.app.config.AppDataPresentation; import bubble.model.app.BubbleApp; import bubble.resources.account.AccountOwnedTemplateResource; import bubble.server.BubbleConfiguration; diff --git a/bubble-server/src/main/java/bubble/service/message/AppMessageService.java b/bubble-server/src/main/java/bubble/service/message/AppMessageService.java index c1b74324..6d7ca293 100644 --- a/bubble-server/src/main/java/bubble/service/message/AppMessageService.java +++ b/bubble-server/src/main/java/bubble/service/message/AppMessageService.java @@ -4,6 +4,9 @@ import bubble.dao.app.AppMessageDAO; import bubble.dao.app.BubbleAppDAO; import bubble.model.account.Account; import bubble.model.app.*; +import bubble.model.app.config.AppDataAction; +import bubble.model.app.config.AppDataConfig; +import bubble.model.app.config.AppDataView; import lombok.extern.slf4j.Slf4j; import org.cobbzilla.util.collection.NameAndValue; import org.cobbzilla.wizard.model.entityconfig.EntityFieldConfig; diff --git a/bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties b/bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties index fcb0bbd6..01cbead6 100644 --- a/bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties +++ b/bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties @@ -426,6 +426,7 @@ err.accountPlan.noVerifiedContacts=Cannot proceed, no account contact informatio err.admin.cannotRemoveAdminStatusFromSelf=You cannot remove admin status from your own account err.allowedCountriesJson.length=Allowed countries list is too long err.approval.invalid=Approval cannot proceed +err.appMessages.length=App messages maximum length exceeded err.authenticator.cannotCreate=Cannot create authenticator err.authenticator.configured=Only one authenticator can be configured err.authenticator.invalid=Authenticator data is invalid diff --git a/bubble-server/src/main/resources/models/apps/bblock/bubbleApp_bblock.json b/bubble-server/src/main/resources/models/apps/bblock/bubbleApp_bblock.json index f308412b..09a6486a 100644 --- a/bubble-server/src/main/resources/models/apps/bblock/bubbleApp_bblock.json +++ b/bubble-server/src/main/resources/models/apps/bblock/bubbleApp_bblock.json @@ -28,11 +28,11 @@ "type": "list", "columns": ["name", "description", "url", "enabled", "tags"], "actions": [ - {"name": "enable", "when": "!item.enabled"}, - {"name": "disable", "when": "item.enabled"}, + {"name": "enable_blocklist", "when": "!item.enabled"}, + {"name": "disable_blocklist", "when": "item.enabled"}, {"name": "manage_blocklist", "view": "manage_blocklist"}, - {"name": "remove"}, - {"name": "add", "type": "new", "view": "manage_blocklist"} + {"name": "remove_blocklist"}, + {"name": "add_blocklist", "type": "create", "view": "manage_blocklist"} ] }, { "name": "manage_blocklist", @@ -45,26 +45,26 @@ {"name": "enabled", "type": "flag"} ], "actions": [ - {"name": "enable", "when": "!item.enabled"}, - {"name": "disable", "when": "item.enabled"}, - {"name": "remove", "when": "item.id !== null"}, - {"name": "create", "when": "item.id === null"}, - {"name": "update", "when": "item.id !== null"}, - {"name": "manage_entries", "when": "item.id !== null"} + {"name": "enable_blocklist", "when": "!item.enabled"}, + {"name": "disable_blocklist", "when": "item.enabled"}, + {"name": "remove_blocklist", "when": "item.id !== null"}, + {"name": "create_blocklist", "when": "item.id === null"}, + {"name": "update_blocklist", "when": "item.id !== null"}, + {"name": "manage_blocklist_entries", "when": "item.id !== null"} ] }, { "name": "manage_entries", "type": "list", "columns": ["block_rule"], "actions": [ - {"name": "remove"}, - {"name": "add", "type": "new", "view": "add_entry"} + {"name": "remove_rule"}, + {"name": "add_rule", "type": "create", "view": "add_entry"} ] }, { "name": "add_entry", "type": "item", "fields": [ {"name": "block_rule"} ], - "actions": ["create"] + "actions": ["create_rule"] }] }, "children": { @@ -122,12 +122,32 @@ {"name": "view.last_30_days", "value": "Last 30 Days"}, {"name": "view.last_30_days.ctime.format", "value": "{{MM}} {{d}}, {{YYYY}}"}, - {"name": "list.easylist.name", "value": "EasyList"}, - {"name": "list.easylist.description", "value": "EasyList is the primary filter list that removes most adverts from international web pages, including unwanted frames, images, and objects. It is the most popular list used by many ad blockers and forms the basis of over a dozen combination and supplementary filter lists."}, - {"name": "list.local.name", "value": "Bubble Custom List"}, - {"name": "list.local.description", "value": "A place to maintain your own block rules for this Bubble."}, - {"name": "list.dandelion_sprouts_anti_malware_list.name", "value": "Dandelion Sprout's Anti-Malware List"}, - {"name": "list.dandelion_sprouts_anti_malware_list.description", "value": "Most anti-malware lists are pretty big and can cover a 5- or 6-digit amount of specific domains. But my list hereby claims to remove more than 25% of all known malware sites with just a 2-digit amount of entries. This is mostly done by blocking top-level domains that have become devastatingly abused by spammers, usually because they allowed for free and uncontrolled domain registrations. There's also additional categories that cover unusual malware and phishing domains that very few other lists seem to cover."} + {"name": "config.field.name", "value": "Name"}, + {"name": "config.field.description", "value": "Description"}, + {"name": "config.field.url", "value": "URL"}, + {"name": "config.field.tags", "value": "Tags"}, + {"name": "config.field.tags.description", "value": "A comma-separated list of tags: "}, + {"name": "config.field.enabled", "value": "Enabled"}, + {"name": "config.field.block_rule", "value": "Rule"}, + + {"name": "config.action.enable_blocklist", "value": "Enable"}, + {"name": "config.action.disable_blocklist", "value": "Disable"}, + {"name": "config.action.manage_blocklist", "value": "Manage List"}, + {"name": "config.action.remove_blocklist", "value": "Remove List"}, + {"name": "config.action.add_blocklist", "value": "Add New List"}, + {"name": "config.action.create_blocklist", "value": "Create List"}, + {"name": "config.action.update_blocklist", "value": "Update List"}, + {"name": "config.action.manage_blocklist_entries", "value": "Manage Entries"}, + {"name": "config.action.remove_rule", "value": "Remove Rule"}, + {"name": "config.action.add_rule", "value": "Add New Rule"}, + {"name": "config.action.create_rule", "value": "Create Rule"}, + + {"name": "config.item.easylist.name", "value": "EasyList"}, + {"name": "config.item.easylist.description", "value": "EasyList is the primary filter list that removes most adverts from international web pages, including unwanted frames, images, and objects. It is the most popular list used by many ad blockers and forms the basis of over a dozen combination and supplementary filter lists."}, + {"name": "config.item.local.name", "value": "Bubble Custom List"}, + {"name": "config.item.local.description", "value": "A place to maintain your own block rules for this Bubble."}, + {"name": "config.item.dandelion_sprouts_anti_malware_list.name", "value": "Dandelion Sprout's Anti-Malware List"}, + {"name": "config.item.dandelion_sprouts_anti_malware_list.description", "value": "Most anti-malware lists are pretty big and can cover a 5- or 6-digit amount of specific domains. But my list hereby claims to remove more than 25% of all known malware sites with just a 2-digit amount of entries. This is mostly done by blocking top-level domains that have become devastatingly abused by spammers, usually because they allowed for free and uncontrolled domain registrations. There's also additional categories that cover unusual malware and phishing domains that very few other lists seem to cover."} ] }] }