Skip to content

Commit

Permalink
💥keep silencer simple #265
Browse files Browse the repository at this point in the history
  • Loading branch information
trydofor committed Jul 1, 2024
1 parent b8832a7 commit 3b8a8e2
Show file tree
Hide file tree
Showing 57 changed files with 487 additions and 421 deletions.
1 change: 1 addition & 0 deletions WingsBoot.t.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Use `t.md` as local [Test Management](https://www.jetbrains.com/help/idea/test-m
* 11033 ThisLazyCglibTest: thisLazy with cglib
* 11034 ThisLazyProxyTest: thisLazy with default jdk proxy
* 11035 TypedClassTest: ResolvableType sugar
* 11036 CommonPropHelperTest: comma delimited string

## 12 Faceless

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.ResourceLoader;
import pro.fessional.mirana.data.CodeEnum;
import pro.fessional.wings.silencer.spring.help.SubclassSpringLoader;
import pro.fessional.wings.silencer.support.SubclassGather;

import java.util.Map;

Expand All @@ -27,7 +27,7 @@ public class Devops7EnumsDumperTest {

@Test
public void dumpCodeEnum() {
SubclassSpringLoader loader = new SubclassSpringLoader(resourceLoader);
SubclassGather loader = new SubclassGather(resourceLoader);
Class<CodeEnum> superEnum = CodeEnum.class;

Map<Class<?>, Enum<?>[]> enums = loader.loadSubEnums("pro.fessional", superEnum);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import java.util.Arrays;
import java.util.Objects;

import static pro.fessional.wings.silencer.spring.help.CommonPropHelper.mergeNotValue;
import static pro.fessional.wings.silencer.spring.help.CommonPropHelper.notValue;
import static pro.fessional.wings.silencer.support.PropHelper.mergeIfNon;
import static pro.fessional.wings.silencer.support.PropHelper.nonValue;

/**
* hashCode and equals with
Expand Down Expand Up @@ -138,27 +138,27 @@ public void adopt(TinyMailConfig that) {
public void merge(MailProperties that) {
if (that == null) return;

if (notValue(getHost())) {
if (nonValue(getHost())) {
setHost(that.getHost());
}
if (getPort() == null) {
setPort(that.getPort());
}
if (notValue(getUsername())) {
if (nonValue(getUsername())) {
setUsername(that.getUsername());
}
final String password = getPassword();
if (notValue(password)) {
if (nonValue(password)) {
setPassword(that.getPassword());
}
if (notValue(getProtocol())) {
if (nonValue(getProtocol())) {
setProtocol(that.getProtocol());
}
if (getDefaultEncoding() == null) {
setDefaultEncoding(that.getDefaultEncoding());
}

mergeNotValue(getProperties(), that.getProperties());
mergeIfNon(getProperties(), that.getProperties());
}

/**
Expand All @@ -169,12 +169,12 @@ public void merge(TinyMailConfig that) {
merge((MailProperties) that);

if (dryrun == null) dryrun = that.dryrun;
if (notValue(name)) name = that.name;
if (notValue(from)) from = that.from;
if (nonValue(name)) name = that.name;
if (nonValue(from)) from = that.from;
if (to == null) to = that.to;
if (cc == null) cc = that.cc;
if (bcc == null) bcc = that.bcc;
if (notValue(reply)) reply = that.reply;
if (nonValue(reply)) reply = that.reply;
if (html == null) html = that.html;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,18 @@ public TinyMailPlain loadDetail(long id) {
@Override
public void afterPropertiesSet() {
final WinMailSenderTable t = winMailSenderDao.getTable();
// skip large field
plainFields = new SelectField[]{
t.Id, t.MailApps, t.MailRuns, t.MailConf,
t.MailFrom, t.MailTo, t.MailCc, t.MailBcc,
t.MailReply, t.MailSubj, /*t.MailText,*/ t.MailFile,
t.MailReply, t.MailSubj, /*t.MailText, t.MailFile,*/
t.MailHtml, t.MailMark, t.MailDate,
t.CreateDt, t.LastSend, /*t.LastFail,*/ t.LastDone,
t.NextSend, t.SumSend, t.SumFail, t.SumDone, t.MaxFail, t.MaxDone,
};

sortsFields.put("id", t.Id);
sortsFields.put("done", t.LastDone);
sortsFields.put("fail", t.LastFail);
sortsFields.put("send", t.LastSend);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package pro.fessional.wings.tiny.mail.service.impl;

import com.fasterxml.jackson.databind.JsonNode;
import jakarta.mail.MessagingException;
import lombok.Data;
import lombok.Setter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
Expand All @@ -25,14 +23,15 @@
import pro.fessional.mirana.pain.ThrowableUtil;
import pro.fessional.mirana.time.DateLocaling;
import pro.fessional.mirana.time.ThreadNow;
import pro.fessional.wings.faceless.convention.EmptySugar;
import pro.fessional.wings.faceless.convention.EmptyValue;
import pro.fessional.wings.faceless.service.journal.JournalService;
import pro.fessional.wings.faceless.service.lightid.LightIdService;
import pro.fessional.wings.silencer.modulate.RunMode;
import pro.fessional.wings.silencer.modulate.RuntimeMode;
import pro.fessional.wings.silencer.spring.boot.ConditionalWingsEnabled;
import pro.fessional.wings.silencer.spring.help.CommonPropHelper;
import pro.fessional.wings.slardar.jackson.JacksonHelper;
import pro.fessional.wings.silencer.support.PropHelper;
import pro.fessional.wings.slardar.fastjson.FastJsonHelper;
import pro.fessional.wings.tiny.mail.database.autogen.tables.WinMailSenderTable;
import pro.fessional.wings.tiny.mail.database.autogen.tables.daos.WinMailSenderDao;
import pro.fessional.wings.tiny.mail.database.autogen.tables.pojos.WinMailSender;
Expand All @@ -52,16 +51,15 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;

import static org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.DEFAULT_TASK_SCHEDULER_BEAN_NAME;
import static pro.fessional.wings.silencer.spring.help.CommonPropHelper.arrayOrNull;
import static pro.fessional.wings.silencer.spring.help.CommonPropHelper.notValue;
import static pro.fessional.wings.silencer.support.PropHelper.commaArray;
import static pro.fessional.wings.silencer.support.PropHelper.nonValue;

/**
* @author trydofor
Expand Down Expand Up @@ -209,7 +207,7 @@ public long save(@NotNull TinyMailPlain msg) {
po.setMailSubj(msg.getSubject());
po.setMailText(msg.getContent());
po.setMailHtml(BoxedCastUtil.orElse(msg.getHtml(), config.getHtml()));
po.setMailFile(toStringMap(msg.getAttachment()));
po.setMailFile(toString(msg.getAttachment()));
po.setMailMark(msg.getMark());
po.setMailDate(md);

Expand Down Expand Up @@ -282,18 +280,18 @@ private TinyMailMessage makeMailMessage(@NotNull TinyMailConfig config, @NotNull

if (msg == null) {
message.setFrom(po.getMailFrom());
message.setTo(arrayOrNull(po.getMailTo(), true));
message.setCc(arrayOrNull(po.getMailCc(), true));
message.setBcc(arrayOrNull(po.getMailBcc(), true));
message.setReply(toStrOrNull(po.getMailReply()));
message.setTo(commaArray(po.getMailTo()));
message.setCc(commaArray(po.getMailCc()));
message.setBcc(commaArray(po.getMailBcc()));
message.setReply(EmptySugar.emptyToNull(po.getMailReply()));
message.setHtml(po.getMailHtml());
message.setSubject(po.getMailSubj());
message.setContent(po.getMailText());
final Map<String, Resource> files = toResource(po.getMailFile());
final Map<String, Resource> files = resourceString(po.getMailFile());
if (!files.isEmpty()) {
message.setAttachment(files);
}
message.setBizMark(toStrOrNull(po.getMailMark()));
message.setBizMark(EmptySugar.emptyToNull(po.getMailMark()));
}
else {
if (msg.getFrom() != null) message.setFrom(msg.getFrom());
Expand Down Expand Up @@ -328,7 +326,7 @@ private WinMailSender saveMailSender(@NotNull TinyMailConfig config, @NotNull Ti
po.setMailSubj(msg.getSubject());
po.setMailText(msg.getContent());
po.setMailHtml(BoxedCastUtil.orElse(msg.getHtml(), config.getHtml()));
po.setMailFile(toString(msg.getAttachment()));
po.setMailFile(stringResource(msg.getAttachment()));
po.setMailMark(msg.getMark());

final LocalDateTime md = msg.getDate();
Expand Down Expand Up @@ -694,7 +692,7 @@ private String toString(String[] arr, String[] elz) {

@Nullable
private String toString(String str, String[] elz) {
return notValue(str)
return nonValue(str)
? (elz == null || elz.length == 0
? null
: String.join(",", elz))
Expand All @@ -703,40 +701,34 @@ private String toString(String str, String[] elz) {

@Nullable
private String toString(String str, String elz) {
return notValue(str) ? elz : str;
}

@SneakyThrows
@NotNull
private String toString(Map<String, Resource> file) {
if (file == null || file.isEmpty()) return Null.Str;
Map<String, String> nameUrl = new LinkedHashMap<>(file.size());
for (Map.Entry<String, Resource> en : file.entrySet()) {
nameUrl.put(en.getKey(), CommonPropHelper.toString(en.getValue()));
}
return JacksonHelper.string(nameUrl, true);
return nonValue(str) ? elz : str;
}

@SneakyThrows
@NotNull
private String toStringMap(Map<String, String> file) {
if (file == null || file.isEmpty()) return Null.Str;
return JacksonHelper.string(file, true);
@Nullable
private String toString(Map<String, String> file) {
if (file == null || file.isEmpty()) return null;
return FastJsonHelper.string(file);
}

@Nullable
private String toStrOrNull(String str) {
return (str == null || str.isEmpty()) ? null : str;
private String stringResource(Map<String, Resource> file) {
if (file == null || file.isEmpty()) return null;

Map<String, String> nameUrl = new LinkedHashMap<>();
for (Map.Entry<String, Resource> en : file.entrySet()) {
nameUrl.put(en.getKey(), PropHelper.stringResource(en.getValue()));
}
return toString(nameUrl);
}

@NotNull
private Map<String, Resource> toResource(String map) {
if (map == null || map.isEmpty()) return Collections.emptyMap();
private Map<String, Resource> resourceString(String jsonMap) {
if (EmptySugar.asEmptyValue(jsonMap)) return Collections.emptyMap();

final Map<String, Resource> rst = new LinkedHashMap<>();
final Iterator<Map.Entry<String, JsonNode>> node = JacksonHelper.object(map).fields();
while (node.hasNext()) {
final Map.Entry<String, JsonNode> en = node.next();
rst.put(en.getKey(), resourceLoader.getResource(en.getValue().asText()));
Map<String, String> map = FastJsonHelper.object(jsonMap, Map.class, String.class, String.class);
for (Map.Entry<String, String> en : map.entrySet()) {
rst.put(en.getKey(), PropHelper.resourceString(en.getValue(), resourceLoader));
}
return rst;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
CREATE TABLE `win_mail_sender` (
`id` BIGINT(20) NOT NULL COMMENT 'primary key/mail_id',
`create_dt` DATETIME(3) NOT NULL DEFAULT NOW(3) COMMENT 'created datetime(sys)',
`modify_dt` DATETIME(3) NOT NULL DEFAULT '1000-01-01' ON UPDATE NOW(3) COMMENT 'modified datetime(sys)',
`delete_dt` DATETIME(3) NOT NULL DEFAULT '1000-01-01' COMMENT 'logic deleted datetime',
`commit_id` BIGINT(20) NOT NULL COMMENT 'commit id',
`mail_apps` VARCHAR(500) NOT NULL DEFAULT '' COMMENT 'belong to applications, comma-separated, default spring.application.name',
`mail_runs` VARCHAR(100) NOT NULL DEFAULT '' COMMENT 'RunMode(product|test|develop|local), comma-separated case-insensitive, default all',
`mail_conf` VARCHAR(100) NOT NULL DEFAULT '' COMMENT 'config name, default',
`mail_from` VARCHAR(200) NOT NULL DEFAULT '' COMMENT 'mail from (sender)',
`mail_to` VARCHAR(500) NOT NULL DEFAULT '' COMMENT 'mail to, comma-separated',
`mail_cc` VARCHAR(500) NOT NULL DEFAULT '' COMMENT 'mail cc, comma-separated',
`mail_bcc` VARCHAR(500) NOT NULL DEFAULT '' COMMENT 'mail bcc, comma-separated',
`mail_reply` VARCHAR(200) NOT NULL DEFAULT '' COMMENT 'mail reply',
`mail_subj` VARCHAR(400) NOT NULL DEFAULT '' COMMENT 'mail subject',
`mail_text` TEXT NULL COMMENT 'mail content',
`mail_html` TINYINT(1) NOT NULL DEFAULT '1' COMMENT 'whether HTML email',
`mail_file` VARCHAR(9000) NOT NULL DEFAULT '' COMMENT 'attachment name and path map, json format',
`mail_mark` VARCHAR(200) NOT NULL DEFAULT '' COMMENT 'space-separated business key',
`mail_date` DATETIME(3) NOT NULL DEFAULT '1000-01-01' COMMENT 'scheduled mail send (sys)',
`last_send` DATETIME(3) NOT NULL DEFAULT '1000-01-01' COMMENT 'previous send (sys)',
`last_fail` TEXT NULL COMMENT 'previous fail info',
`last_done` DATETIME(3) NOT NULL DEFAULT '1000-01-01' COMMENT 'previous success (sys)',
`last_cost` INT(11) NOT NULL DEFAULT '0' COMMENT 'mills of previous send cost',
`next_send` DATETIME(3) NOT NULL DEFAULT '1000-01-01' COMMENT 'next send datetime (sys)',
`next_lock` INT(11) NOT NULL DEFAULT '0' COMMENT 'optimistic lock of sending',
`sum_send` INT(11) NOT NULL DEFAULT '0' COMMENT 'total count of send',
`sum_fail` INT(11) NOT NULL DEFAULT '0' COMMENT 'total count of fail',
`sum_done` INT(11) NOT NULL DEFAULT '0' COMMENT 'total count of success',
`max_fail` INT(11) NOT NULL DEFAULT '0' COMMENT 'max count of fail, 0 means use the config',
`max_done` INT(11) NOT NULL DEFAULT '0' COMMENT 'max count of success, 0 means use the config',
`ref_type` INT(11) NOT NULL DEFAULT '0' COMMENT 'ref type to mark key1, key2 use',
`ref_key1` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'ref key1, generally the primary key',
`ref_key2` VARCHAR(500) NOT NULL DEFAULT '' COMMENT 'ref key2, generally the composite data',
`id` BIGINT(20) NOT NULL COMMENT 'primary key/mail_id',
`create_dt` DATETIME(3) NOT NULL DEFAULT NOW(3) COMMENT 'created datetime(sys)',
`modify_dt` DATETIME(3) NOT NULL DEFAULT '1000-01-01' ON UPDATE NOW(3) COMMENT 'modified datetime(sys)',
`delete_dt` DATETIME(3) NOT NULL DEFAULT '1000-01-01' COMMENT 'logic deleted datetime',
`commit_id` BIGINT(20) NOT NULL COMMENT 'commit id',
`mail_apps` VARCHAR(500) NOT NULL DEFAULT '' COMMENT 'belong to applications, comma-separated, default spring.application.name',
`mail_runs` VARCHAR(100) NOT NULL DEFAULT '' COMMENT 'RunMode(product|test|develop|local), comma-separated case-insensitive, default all',
`mail_conf` VARCHAR(100) NOT NULL DEFAULT '' COMMENT 'config name, default',
`mail_from` VARCHAR(200) NOT NULL DEFAULT '' COMMENT 'mail from (sender)',
`mail_to` VARCHAR(900) NOT NULL DEFAULT '' COMMENT 'mail to, comma-separated',
`mail_cc` VARCHAR(900) NOT NULL DEFAULT '' COMMENT 'mail cc, comma-separated',
`mail_bcc` VARCHAR(900) NOT NULL DEFAULT '' COMMENT 'mail bcc, comma-separated',
`mail_reply` VARCHAR(200) NOT NULL DEFAULT '' COMMENT 'mail reply',
`mail_subj` VARCHAR(400) NOT NULL DEFAULT '' COMMENT 'mail subject',
`mail_text` TEXT NULL COMMENT 'mail content',
`mail_html` TINYINT(1) NOT NULL DEFAULT '1' COMMENT 'whether HTML email',
`mail_file` TEXT NULL COMMENT 'attachment name and path map, json format',
`mail_mark` VARCHAR(900) NOT NULL DEFAULT '' COMMENT 'business key to lookup',
`mail_date` DATETIME(3) NOT NULL DEFAULT '1000-01-01' COMMENT 'scheduled mail send (sys)',
`last_send` DATETIME(3) NOT NULL DEFAULT '1000-01-01' COMMENT 'previous send (sys)',
`last_fail` TEXT NULL COMMENT 'previous fail info',
`last_done` DATETIME(3) NOT NULL DEFAULT '1000-01-01' COMMENT 'previous success (sys)',
`last_cost` INT(11) NOT NULL DEFAULT '0' COMMENT 'mills of previous send cost',
`next_send` DATETIME(3) NOT NULL DEFAULT '1000-01-01' COMMENT 'next send datetime (sys)',
`next_lock` INT(11) NOT NULL DEFAULT '0' COMMENT 'optimistic lock of sending',
`sum_send` INT(11) NOT NULL DEFAULT '0' COMMENT 'total count of send',
`sum_fail` INT(11) NOT NULL DEFAULT '0' COMMENT 'total count of fail',
`sum_done` INT(11) NOT NULL DEFAULT '0' COMMENT 'total count of success',
`max_fail` INT(11) NOT NULL DEFAULT '0' COMMENT 'max count of fail, 0 means use the config',
`max_done` INT(11) NOT NULL DEFAULT '0' COMMENT 'max count of success, 0 means use the config',
`ref_type` INT(11) NOT NULL DEFAULT '0' COMMENT 'ref type indicate key1, key2 usage',
`ref_key1` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'ref key1, generally the primary key',
`ref_key2` VARCHAR(500) NOT NULL DEFAULT '' COMMENT 'ref key2, generally the composite data',
PRIMARY KEY (`id`),
INDEX ix_next_send (`next_send`),
INDEX ix_sum_done (`sum_done`),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import pro.fessional.wings.silencer.spring.help.CommonPropHelper;
import pro.fessional.wings.silencer.support.PropHelper;

import java.io.IOException;
import java.util.Iterator;
Expand All @@ -36,7 +36,7 @@ public void jsonResourceSerializer() throws IOException {

Map<String, String> urls = new LinkedHashMap<>();
for (Map.Entry<String, Resource> en : res1.entrySet()) {
urls.put(en.getKey(), CommonPropHelper.toString(en.getValue()));
urls.put(en.getKey(), PropHelper.stringResource(en.getValue()));
}
final String json = objectMapper.writeValueAsString(urls);
Map<String, Resource> res2 = new LinkedHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;

import static pro.fessional.wings.silencer.spring.help.CommonPropHelper.arrayOrNull;
import static pro.fessional.wings.silencer.support.PropHelper.commaArray;
import static pro.fessional.wings.tiny.task.schedule.exec.NoticeExec.WhenDone;
import static pro.fessional.wings.tiny.task.schedule.exec.NoticeExec.WhenExec;
import static pro.fessional.wings.tiny.task.schedule.exec.NoticeExec.WhenFail;
Expand Down Expand Up @@ -316,7 +316,7 @@ private boolean notEnable(Boolean b, long id, String key) {
private boolean notApps(String apps, long id, String key) {
if (StringUtils.isEmpty(apps)) return false;

for (String s : arrayOrNull(apps, true)) {
for (String s : commaArray(apps)) {
if (s.trim().equals(appName)) return false;
}
log.info("skip tiny-task for not apps={}, cur={}, id={}, prop={}", apps, appName, id, key);
Expand All @@ -343,7 +343,7 @@ private boolean notRuns(String runs, long id, String key) {
private Set<String> noticeWhen(String nw) {
if (nw == null || nw.isEmpty()) return Collections.emptySet();
Set<String> rs = new HashSet<>();
for (String s : arrayOrNull(nw, true)) {
for (String s : commaArray(nw)) {
rs.add(s.trim().toLowerCase());
}
return rs;
Expand Down
Loading

0 comments on commit 3b8a8e2

Please sign in to comment.