better code

This commit is contained in:
devezhao 2021-05-14 15:53:04 +08:00
parent 800632079d
commit 16dc0c7d02
9 changed files with 133 additions and 22 deletions

View file

@ -46,7 +46,7 @@ public class EasyEntity extends BaseEasyMeta<Entity> {
@Override
public JSON toJSON() {
return JSONUtils.toJSONObject(
new String[] { "entity", "entityLabel", "icon" },
new String[] { getName(), getLabel(), getIcon() });
new String[] { "entity", "entityLabel", "entityCode", "icon" },
new Object[] { getName(), getLabel(), getRawMeta().getEntityCode(), getIcon() });
}
}

View file

@ -203,8 +203,9 @@ public class PrivilegesManager {
if (action.getMask() <= BizzPermission.READ.getMask() && EasyMetaFactory.valueOf(entity).isPlainEntity()) {
return true;
}
// Feeds: R
if (entity == EntityHelper.Feeds && action == BizzPermission.READ) {
// 允许读取
if ((entity == EntityHelper.Feeds || entity == EntityHelper.ProjectTask)
&& action == BizzPermission.READ) {
return true;
}

View file

@ -22,7 +22,6 @@ import com.rebuild.core.metadata.MetadataHelper;
import com.rebuild.core.metadata.easymeta.EasyMetaFactory;
import com.rebuild.core.privileges.bizz.Department;
import com.rebuild.core.privileges.bizz.User;
import com.rebuild.utils.CommonsUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
@ -102,7 +101,6 @@ public class RoleBaseQueryFilter implements Filter, QueryFilter {
useMain = entity.getMainEntity();
} else {
log.warn("None privileges entity use `Application#createQueryNoFilter` please : {}", entity);
CommonsUtils.printStackTrace();
return DENIED.evaluate(null);
}
}

View file

@ -28,4 +28,14 @@ public class I18nUtils {
return CalendarUtils.getUTCWithZoneDateTimeFormat().format(date);
}
/**
* 多语言支持
*
* @param key
* @param placeholders
* @return
*/
public static String $L(String key, Object... placeholders) {
return Language.getCurrentBundle().formatLang(key, placeholders);
}
}

View file

@ -13,6 +13,7 @@ import cn.devezhao.persist4j.Field;
import cn.devezhao.persist4j.dialect.FieldType;
import cn.devezhao.persist4j.engine.ID;
import cn.devezhao.persist4j.metadata.BaseMeta;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.rebuild.core.Application;
import com.rebuild.core.metadata.EntityHelper;
@ -29,7 +30,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* 元数据获取
@ -42,19 +46,17 @@ import java.util.*;
public class MetadataGetting extends BaseController {
@GetMapping("entities")
public List<Map<String, Object>> entities(HttpServletRequest request) {
public List<JSON> entities(HttpServletRequest request) {
ID user = getRequestUser(request);
// 返回明细实体
boolean usesDetail = getBoolParameter(request, "detail", false);
List<Map<String, Object>> data = new ArrayList<>();
List<JSON> data = new ArrayList<>();
for (Entity e : MetadataSorter.sortEntities(user, false, usesDetail)) {
Map<String, Object> map = new HashMap<>();
EasyEntity easy = EasyMetaFactory.valueOf(e);
map.put("name", e.getName());
map.put("label", easy.getLabel());
map.put("icon", easy.getIcon());
data.add(map);
JSONObject item = (JSONObject) EasyMetaFactory.valueOf(e).toJSON();
item.put("name", item.getString("entity"));
item.put("label", item.getString("entityLabel"));
data.add(item);
}
return data;
}

View file

@ -27,6 +27,7 @@ import com.rebuild.web.BaseController;
import com.rebuild.web.IdParam;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@ -39,6 +40,8 @@ import java.io.IOException;
import java.util.Date;
import java.util.Set;
import static com.rebuild.core.support.i18n.I18nUtils.$L;
/**
* 任务
*
@ -224,9 +227,10 @@ public class ProjectTaskController extends BaseController {
}
@RequestMapping("tasks/related-list")
public JSON relatedTaskList(@IdParam(name = "related") ID relatedId,
public JSON relatedTaskList(@IdParam(name = "related", required = false) ID relatedId,
@IdParam(name = "task", required = false) ID taskId,
HttpServletRequest request) {
Assert.isTrue(relatedId != null || taskId != null, $L("无效请求参数"));
String queryWhere = String.format("relatedRecord = '%s'", relatedId);
// 关键词搜索

View file

@ -0,0 +1,98 @@
/*
Copyright (c) Ruifang Tech <http://ruifang-tech.com/> and/or its owners. All rights reserved.
*/
package com.rebuild;
import com.alibaba.fastjson.JSONObject;
import com.rebuild.utils.JSONUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 多语言提取
*
* @author devezhao
* @since 2021/5/14
*/
@Slf4j
public class I18nGettextParser {
public static void main(String[] args) throws IOException {
// final File root = new File("D:\\GitHub\\rebuild\\rebuild-mob");
final File root = new File("D:\\GitHub\\rebuild\\rebuild");
Set<String> into = new TreeSet<>();
parse(root, into);
log.info("Found {} items", into.size());
File target = new File(root, "lang.zh_CN.json");
if (target.exists()) target.delete();
JSONObject content = new JSONObject(true);
content.put("_", "[中文]");
for (String gettext : into) {
content.put(gettext, String.format("[%s]", gettext));
}
FileUtils.writeStringToFile(target, JSONUtils.prettyPrint(content));
log.info("File write : {}", target.getAbsolutePath());
}
static void parse(File fileOrDir, Set<String> into) throws IOException {
String fileName = fileOrDir.getName();
if (fileOrDir.isFile()) {
if (fileName.endsWith(".js")) {
into.addAll(parseJs(fileOrDir));
} else if (fileName.endsWith(".html")) {
into.addAll(parseHtml(fileOrDir));
} else if (fileName.endsWith(".java")) {
into.addAll(parseJava(fileOrDir));
}
} else if (fileOrDir.isDirectory()) {
if (fileName.equalsIgnoreCase("node_modules")) {
return;
}
for (File sub : Objects.requireNonNull(fileOrDir.listFiles())) {
parse(sub, into);
}
}
}
static List<String> parseJs(File file) throws IOException {
Pattern pattern = Pattern.compile("\\$L\\('(\\S+)'\\)");
return parseWithPattern(file, pattern);
}
static List<String> parseHtml(File file) throws IOException {
Pattern pattern = Pattern.compile("bundle\\.L\\('(\\S+)'\\)");
return parseWithPattern(file, pattern);
}
static List<String> parseJava(File file) throws IOException {
Pattern pattern = Pattern.compile("\\$L\\(\"(\\S+)\"\\)");
return parseWithPattern(file, pattern);
}
static List<String> parseWithPattern(File file, Pattern pattern) throws IOException {
String content = FileUtils.readFileToString(file, "utf-8");
Matcher matcher = pattern.matcher(content);
List<String> list = new ArrayList<>();
while (matcher.find()) {
String gettext = matcher.group(1);
log.info("`{}` in `{}`", gettext, file.getName());
list.add(gettext);
}
return list;
}
}

View file

@ -7,21 +7,19 @@ See LICENSE and COMMERCIAL in the project root for license information.
package com.rebuild;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.thymeleaf.spring5.view.ThymeleafViewResolver;
/**
* @see com.rebuild.web.RebuildWebConfigurer
*/
@Slf4j
@Component("thymeleafViewResolver")
public class MockThymeleafViewResolver extends ThymeleafViewResolver {
private static final Logger LOG = LoggerFactory.getLogger(MockThymeleafViewResolver.class);
public MockThymeleafViewResolver() {
super();
LOG.warn("Mock `thymeleafViewResolver` has been enabled");
log.warn("Mock `thymeleafViewResolver` has been enabled");
}
}