Skip to content

Commit

Permalink
Merge branch 'r-2022.1.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Chan committed Aug 21, 2023
2 parents f2687b0 + 67e6db0 commit 85efa6c
Show file tree
Hide file tree
Showing 87 changed files with 492 additions and 204 deletions.
24 changes: 16 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,25 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
uses: actions/setup-java@v2

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'
- name: Cache Maven packages
uses: actions/cache@v3
java-version: '17'

- name: Cache local Maven repository
uses: actions/[email protected]
env:
cache-name: cache-mvn
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
path: ~/.m2/repository
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Compile
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
Expand Down
27 changes: 16 additions & 11 deletions .github/workflows/oss-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v2

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'
cache: maven
- name: Cache Maven packages
uses: actions/cache@v1
java-version: '17'

- name: Cache local Maven repository
uses: actions/[email protected]
env:
cache-name: cache-mvn
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
path: ~/.m2/repository
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
# - name: Build with Maven
# run: mvn -B package --file pom.xml
Expand All @@ -33,9 +39,8 @@ jobs:
# run: mvn deploy
# env:
# GITHUB_TOKEN: ${{ github.token }} # GITHUB_TOKEN is the default env for the password

- name: Import GPG
uses: crazy-max/ghaction-import-gpg@v4.4.0
uses: crazy-max/ghaction-import-gpg@v5.3.0
with:
gpg_private_key: ${{ secrets.MAVEN_GPG_KEY }}
passphrase: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
Expand Down
Empty file added .springjavaformatconfig
Empty file.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.power4j.fist/fist-kit-dependencies/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.power4j.fist/fist-kit-dependencies)
## 技术栈

- JDK: `11`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ private List<ApiModel> parseFromJson(@Nullable String json) throws JsonProcessin
}
final JsonNode root = objectMapper.readTree(json);

Iterator<Map.Entry<String, JsonNode>> pathIter = Optional.ofNullable(root.get(KEY_PATHS)).map(JsonNode::fields)
.orElse(null);
Iterator<Map.Entry<String, JsonNode>> pathIter = Optional.ofNullable(root.get(KEY_PATHS))
.map(JsonNode::fields)
.orElse(null);
if (Objects.isNull(pathIter)) {
return Collections.emptyList();
}
Expand All @@ -73,16 +74,17 @@ private List<ApiModel> parseFromJson(@Nullable String json) throws JsonProcessin
apiModel.setMethod(kv.getKey().toLowerCase());
Optional<JsonNode> methodInfo = Optional.ofNullable(kv.getValue());
methodInfo.ifPresent(o -> {
apiModel.setAction(Optional.ofNullable(o.get(KEY_OPERATION_ID)).map(JsonNode::asText)
.orElse(StringPool.EMPTY));
apiModel.setAction(Optional.ofNullable(o.get(KEY_OPERATION_ID))
.map(JsonNode::asText)
.orElse(StringPool.EMPTY));
apiModel.setDocTags(Optional.ofNullable(o.get(KEY_TAGS)).map(this::readStrArray).orElse(null));
apiModel.setDescription(
Optional.ofNullable(o.get(KEY_SUMMARY)).map(JsonNode::asText).orElse(StringPool.EMPTY));
});
Optional<JsonNode> secureDetails = methodInfo.map(o -> o.get(DocConstant.SECURE_API_DETAILS_EXTENSION));
if (secureDetails.isEmpty()) {
secureDetails = methodInfo.map(o -> o.get(SWAGGER_EXTENSION_KEY))
.map(o -> o.get(DocConstant.SECURE_API_DETAILS_EXTENSION));
.map(o -> o.get(DocConstant.SECURE_API_DETAILS_EXTENSION));
}
if (secureDetails.isEmpty()) {
log.info("忽略注册 {} {}", kv.getKey(), path.getKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ public class ApiTraitOperationPlugin implements OperationBuilderPlugin {

@Override
public void apply(OperationContext context) {
context.findAnnotation(ApiTrait.class).map(DocUtil::createDetails).map(this::toObjectVendorExtension)
.ifPresent(extension -> context.operationBuilder().extensions(Collections.singletonList(extension)));
context.findAnnotation(ApiTrait.class)
.map(DocUtil::createDetails)
.map(this::toObjectVendorExtension)
.ifPresent(extension -> context.operationBuilder().extensions(Collections.singletonList(extension)));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,22 @@ public OperationBuilderPlugin apiTraitOperationPlugin() {
@Bean
public Docket docket() {
// FIXME 可配置化
return new Docket(DocumentationType.OAS_30).apiInfo(apiInfo()).enable(true).securitySchemes(apiKeyList())
.securityContexts(securityContexts()).select()
.apis(RequestHandlerSelectors.withMethodAnnotation(Operation.class))
// .apis(RequestHandlerSelectors.basePackage("com.power4j.fist"))
.paths(PathSelectors.any()).build();
return new Docket(DocumentationType.OAS_30).apiInfo(apiInfo())
.enable(true)
.securitySchemes(apiKeyList())
.securityContexts(securityContexts())
.select()
.apis(RequestHandlerSelectors.withMethodAnnotation(Operation.class))
// .apis(RequestHandlerSelectors.basePackage("com.power4j.fist"))
.paths(PathSelectors.any())
.build();
}

private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("FIST 接口文档")
.contact(new Contact("power4j", "https://github.com/power4j", "amNsYXp6QG91dGxvb2suY29t"))
.version("1.0").build();
.contact(new Contact("power4j", "https://github.com/power4j", "amNsYXp6QG91dGxvb2suY29t"))
.version("1.0")
.build();
}

private List<SecurityScheme> apiKeyList() {
Expand All @@ -80,8 +85,10 @@ private List<SecurityScheme> apiKeyList() {
}

private List<SecurityContext> securityContexts() {
SecurityContext securityContext = SecurityContext.builder().securityReferences(defaultAuth())
.operationSelector(c -> true).build();
SecurityContext securityContext = SecurityContext.builder()
.securityReferences(defaultAuth())
.operationSelector(c -> true)
.build();
return Collections.singletonList(securityContext);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public AuditFiller auditAll() {
@ConditionalOnProperty(prefix = TenantProperties.PROP_PREFIX, name = "enabled", havingValue = "true")
public TenantLineInnerInterceptor tenantLineInnerInterceptor() {
TenantLineInnerInterceptor innerInterceptor = new TenantLineInnerInterceptor();
innerInterceptor.setTenantLineHandler(
new DynamicTenantHandler(tenantProperties.getColumn(), tenantProperties.getTables()));
innerInterceptor
.setTenantLineHandler(new DynamicTenantHandler(tenantProperties.getColumn(), tenantProperties.getTables()));
return innerInterceptor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,9 @@ public long lambdaCount(Eq<T> expr, @Nullable ID exclude) {

@Override
public long lambdaCount(List<Eq<T>> expr, @Nullable ID exclude) {
Map<String, Object> parsed = expr.stream().collect(Collectors
.toMap(o -> lambdaHelper.colToStr(o.getColumn(), true), o -> Objects.requireNonNull(o.getValue())));
Map<String, Object> parsed = expr.stream()
.collect(Collectors.toMap(o -> lambdaHelper.colToStr(o.getColumn(), true),
o -> Objects.requireNonNull(o.getValue())));
return countByColumns(parsed, exclude);
}

Expand All @@ -239,8 +240,11 @@ Object loadVersionValueById(T entity, TableInfo tableInfo) {
if (!tableInfo.havePK()) {
throw new UnsupportedOperationException("不支持没有ID字段的实体类型");
}
TableFieldInfo idField = tableInfo.getFieldList().stream()
.filter(o -> tableInfo.getKeyColumn().equals(o.getColumn())).findFirst().orElse(null);
TableFieldInfo idField = tableInfo.getFieldList()
.stream()
.filter(o -> tableInfo.getKeyColumn().equals(o.getColumn()))
.findFirst()
.orElse(null);
assert idField != null;

Object idValue = getFieldValue(entity, idField.getField());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class QueryTest {
long ID90001 = 90001L;

List<Long> ids = Collections
.unmodifiableList(LongStream.range(ID90001, ID90001 + 5).boxed().collect(Collectors.toList()));
.unmodifiableList(LongStream.range(ID90001, ID90001 + 5).boxed().collect(Collectors.toList()));

@Autowired
private BookRepository bookRepository;
Expand Down Expand Up @@ -96,8 +96,8 @@ void findAllBy() {
List<Book> list2 = bookRepository.findAllBy(wrapper2);
Assertions.assertEquals(0, list2.size());

LambdaQueryWrapper<Book> wrapper3 = bookRepository.lambdaWrapper().in(Book::getId,
Arrays.asList(ID90001, ID90001 + 1));
LambdaQueryWrapper<Book> wrapper3 = bookRepository.lambdaWrapper()
.in(Book::getId, Arrays.asList(ID90001, ID90001 + 1));
List<Book> list3 = bookRepository.findAllBy(wrapper3);
Assertions.assertEquals(2, list3.size());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.power4j.fist.boot.web.model;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
* @author CJ ([email protected])
* @since 1.0
*/
@Data
public class PageDTO<T> implements Serializable {

private final static long serialVersionUID = 1L;

@Schema(description = "数据")
private List<T> content;

@Schema(description = "总行数")
private Integer total;

@Schema(description = "是否有下一页")
private Boolean hasNext;

@Schema(description = "页码")
private Integer pageNumber;

@Schema(description = "页大小")
private Integer pageSize;

}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ public static <T> PageData<T> of(Paged<T> paged) {
paged.getPageSize());
}

public static <T> PageData<T> of(PageDTO<T> dto) {
return new PageData(dto.getContent(), dto.getTotal(), dto.getHasNext(), dto.getPageNumber(), dto.getPageSize());
}

public static <T> PageDTO<T> toPageDTO(PageData<T> src) {
PageDTO<T> dto = new PageDTO<>();
dto.setContent(src.getContent());
dto.setTotal(src.getTotal());
dto.setHasNext(src.isHasNext());
dto.setPageNumber(src.getPageNumber());
dto.setPageSize(src.getPageSize());
return dto;
}

public PageData(List<T> content, int total, boolean hasNext, Integer pageNumber, Integer pageSize) {
this.content = content;
this.total = total;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package com.power4j.fist.data.tenant;

import com.power4j.fist.boot.common.aop.AopUtil;
import com.power4j.fist.boot.common.spel.MethodParameterResolver;
import com.power4j.fist.boot.common.spel.SpringElUtil;
import com.power4j.fist.support.spring.aop.AopUtil;
import com.power4j.fist.support.spring.spel.MethodParameterResolver;
import com.power4j.fist.support.spring.spel.SpringElUtil;
import com.power4j.fist.data.tenant.annotation.InTenant;
import com.power4j.fist.data.tenant.isolation.TenantBroker;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

/**
* 租户隔离注解,表示在某个租户的上下文中执行,也可用于重新指定租户
*
* @author CJ ([email protected])
* @date 2021/11/11
* @since 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class DataAutoConfigurationTest {

private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(DataAutoConfiguration.class));
.withConfiguration(AutoConfigurations.of(DataAutoConfiguration.class));

@Test
void shouldCreateDefaultBeans() {
Expand Down
1 change: 0 additions & 1 deletion fist-kit-app/fist-data/fist-support-data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.4</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private String checkoutCurrentId() {
private List<OpHandler<T>> prepareHandlerList(List<HandlerInfo<T>> infoList) {
return infoList.stream().map(info -> {
OpHandler<T> handler = Optional.ofNullable(info.getHandler())
.orElseGet(() -> findHandler(info.getHandlerClass()));
.orElseGet(() -> findHandler(info.getHandlerClass()));
if (null == handler) {
throw new OpTemplateException("No handler of " + info.getHandlerClass());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ private static ResourceBundleMessageSource getMessageSource() {
*/
public static <T> Set<ConstraintViolation<T>> check(T object, Class<?>... groups) {
Locale.setDefault(LocaleContextHolder.getLocale());
Validator validator = Validation.byDefaultProvider().configure()
.messageInterpolator(new ResourceBundleMessageInterpolator(
new MessageSourceResourceBundleLocator(getMessageSource())))
.buildValidatorFactory().getValidator();
Validator validator = Validation.byDefaultProvider()
.configure()
.messageInterpolator(
new ResourceBundleMessageInterpolator(new MessageSourceResourceBundleLocator(getMessageSource())))
.buildValidatorFactory()
.getValidator();

return validator.validate(object, groups);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.power4j.fist.data.tenant;

import com.power4j.fist.boot.web.servlet.util.HttpServletRequestUtil;
import com.power4j.fist.support.spring.web.servlet.util.HttpServletRequestUtil;
import lombok.experimental.UtilityClass;

import javax.servlet.http.HttpServletRequest;
Expand All @@ -32,7 +32,7 @@ public class TenantUtil {

public Optional<String> resolveTenantId(HttpServletRequest request) {
return Optional.ofNullable(HttpServletRequestUtil.getHeader(request, TenantConstant.TENANT_ID_HEADER)
.orElse(request.getParameter(TenantConstant.TENANT_ID_PARAMETER)));
.orElse(request.getParameter(TenantConstant.TENANT_ID_PARAMETER)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class TreeMaker<ID, N extends Node<ID, N>> {
*/
public static <ID, N extends Node<ID, N>> TreeMaker<ID, N> use(Collection<N> data) {
Map<ID, N> sourceData = data.stream()
.collect(Collectors.toMap(Node::getId, Function.identity(), (x, y) -> y, LinkedHashMap::new));
.collect(Collectors.toMap(Node::getId, Function.identity(), (x, y) -> y, LinkedHashMap::new));
return new TreeMaker<>(sourceData);
}

Expand All @@ -69,11 +69,14 @@ public static <ID, N extends Node<ID, N>> TreeMaker<ID, N> use(Collection<N> dat
*/
public static <ID> TreeMaker<ID, TreeNode<ID>> useIdx(Collection<? extends NodeIdx<ID, ?>> nodes) {
Function<ID, TreeNode<ID>> treeMapper = id -> TreeNode.of(id, null);
Map<ID, ID> parentMap = nodes.stream().filter(o -> (1 == o.getDistance()))
.collect(Collectors.toMap(NodeIdx::getDescendant, NodeIdx::getAncestor));
Map<ID, TreeNode<ID>> data = nodes.stream().filter(o -> (0 == o.getDistance())).map(NodeIdx::getAncestor)
.map(treeMapper)
.collect(Collectors.toMap(TreeNode::getId, Function.identity(), (x, y) -> y, LinkedHashMap::new));
Map<ID, ID> parentMap = nodes.stream()
.filter(o -> (1 == o.getDistance()))
.collect(Collectors.toMap(NodeIdx::getDescendant, NodeIdx::getAncestor));
Map<ID, TreeNode<ID>> data = nodes.stream()
.filter(o -> (0 == o.getDistance()))
.map(NodeIdx::getAncestor)
.map(treeMapper)
.collect(Collectors.toMap(TreeNode::getId, Function.identity(), (x, y) -> y, LinkedHashMap::new));
data.values().forEach(o -> o.setParentId(parentMap.get(o.getId())));
return new TreeMaker<>(data);
}
Expand Down
Loading

0 comments on commit 85efa6c

Please sign in to comment.