Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
ref: ${{ github.event.pull_request.head.sha }}
- name: Build Java
run: |
mvn clean compile -DskipTests -f ./server/api-service/pom.xml
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.lowcoder.domain.configurations;

import java.util.List;

import javax.annotation.PostConstruct;

import com.github.cloudyrock.mongock.driver.mongodb.springdata.v3.SpringDataMongoV3Driver;
import com.github.cloudyrock.spring.v5.MongockSpring5;
import com.mongodb.ReadConcern;
import com.mongodb.ReadPreference;
import com.mongodb.WriteConcern;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.lowcoder.domain.user.model.User;
import org.lowcoder.sdk.config.MaterialProperties;
import org.lowcoder.sdk.models.HasIdAndAuditing;
Expand All @@ -23,13 +26,7 @@
import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories;
import org.springframework.security.core.context.ReactiveSecurityContextHolder;

import com.github.cloudyrock.mongock.driver.mongodb.springdata.v3.SpringDataMongoV3Driver;
import com.github.cloudyrock.spring.v5.MongockSpring5;
import com.mongodb.ReadConcern;
import com.mongodb.ReadPreference;
import com.mongodb.WriteConcern;

import lombok.extern.slf4j.Slf4j;
import java.util.List;

@Slf4j
@Configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
package org.lowcoder.domain.datasource.service.impl;

import static org.lowcoder.infra.perf.PerfEvent.CLIENT_BASED_CONNECTION_CREATE;
import static org.lowcoder.infra.perf.PerfEvent.CLIENT_BASED_CONNECTION_REMOVE;
import static org.lowcoder.infra.perf.PerfEvent.CLIENT_BASED_CONNECTION_SIZE;
import static org.lowcoder.infra.perf.PerfEvent.HIKARI_POOL_ACTIVE_CONNECTIONS;
import static org.lowcoder.infra.perf.PerfEvent.HIKARI_POOL_IDLE_CONNECTIONS;
import static org.lowcoder.infra.perf.PerfEvent.HIKARI_POOL_TOTAL_CONNECTIONS;
import static org.lowcoder.infra.perf.PerfEvent.HIKARI_POOL_WAITING_CONNECTIONS;
import static org.lowcoder.sdk.exception.BizError.PLUGIN_CREATE_CONNECTION_FAILED;
import static org.lowcoder.sdk.plugin.common.QueryExecutionUtils.querySharedScheduler;

import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.PostConstruct;

import com.google.common.cache.*;
import com.google.common.collect.ImmutableList;
import io.micrometer.core.instrument.Tags;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.lowcoder.domain.datasource.model.ClientBasedDatasourceConnectionHolder;
import org.lowcoder.domain.datasource.model.Datasource;
Expand All @@ -38,17 +20,22 @@
import org.lowcoder.sdk.plugin.common.sql.HikariPerfWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification;
import com.google.common.collect.ImmutableList;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import io.micrometer.core.instrument.Tags;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Mono;
import static org.lowcoder.infra.perf.PerfEvent.*;
import static org.lowcoder.sdk.exception.BizError.PLUGIN_CREATE_CONNECTION_FAILED;
import static org.lowcoder.sdk.plugin.common.QueryExecutionUtils.querySharedScheduler;

/**
* for hikari pool/redis client/es client/..., these clients has taken over underlying connections
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
package org.lowcoder.domain.datasource.service.impl;

import static org.lowcoder.domain.plugin.DatasourceMetaInfoConstants.REST_API;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import javax.annotation.PostConstruct;

import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.lowcoder.domain.datasource.model.Datasource;
import org.lowcoder.domain.datasource.model.DatasourceConnectionHolder;
import org.lowcoder.domain.datasource.service.DatasourceConnectionPool;
Expand All @@ -22,10 +15,15 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.lowcoder.domain.plugin.DatasourceMetaInfoConstants.REST_API;

@Primary
@Service
@Slf4j
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
package org.lowcoder.domain.user.service;


import static com.google.common.collect.Sets.newHashSet;
import static org.lowcoder.domain.user.model.UserDetail.ANONYMOUS_CURRENT_USER;
import static org.lowcoder.sdk.constants.GlobalContext.CLIENT_IP;
import static org.lowcoder.sdk.util.ExceptionUtils.ofError;
import static org.lowcoder.sdk.util.ExceptionUtils.ofException;

import java.security.SecureRandom;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

import javax.annotation.Nonnull;
import javax.annotation.PostConstruct;

import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -34,11 +16,7 @@
import org.lowcoder.domain.group.service.GroupService;
import org.lowcoder.domain.organization.model.OrgMember;
import org.lowcoder.domain.organization.service.OrgMemberService;
import org.lowcoder.domain.user.model.AuthUser;
import org.lowcoder.domain.user.model.Connection;
import org.lowcoder.domain.user.model.User;
import org.lowcoder.domain.user.model.UserDetail;
import org.lowcoder.domain.user.model.UserState;
import org.lowcoder.domain.user.model.*;
import org.lowcoder.domain.user.model.User.TransformedUserInfo;
import org.lowcoder.domain.user.repository.UserRepository;
import org.lowcoder.infra.mongo.MongoUpsertHelper;
Expand All @@ -57,11 +35,21 @@
import org.springframework.http.codec.multipart.Part;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ServerWebExchange;

import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import javax.annotation.Nonnull;
import java.security.SecureRandom;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

import static com.google.common.collect.Sets.newHashSet;
import static org.lowcoder.domain.user.model.UserDetail.ANONYMOUS_CURRENT_USER;
import static org.lowcoder.sdk.constants.GlobalContext.CLIENT_IP;
import static org.lowcoder.sdk.util.ExceptionUtils.ofError;
import static org.lowcoder.sdk.util.ExceptionUtils.ofException;

@Slf4j
@Service
public class UserServiceImpl implements UserService {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package org.lowcoder.infra.config;

import static java.util.Collections.emptyMap;
import static java.util.stream.Collectors.toUnmodifiableMap;
import static org.lowcoder.sdk.util.JsonUtils.toJson;

import java.time.Duration;
import java.util.Map;

import javax.annotation.Nullable;
import javax.annotation.PostConstruct;

import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.lowcoder.infra.config.model.ServerConfig;
import org.lowcoder.infra.config.repository.ServerConfigRepository;
import org.lowcoder.infra.localcache.ReloadableCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;
import javax.annotation.Nullable;
import java.time.Duration;
import java.util.Map;

import static java.util.Collections.emptyMap;
import static java.util.stream.Collectors.toUnmodifiableMap;
import static org.lowcoder.sdk.util.JsonUtils.toJson;

@Slf4j
@Component
Expand Down
4 changes: 4 additions & 0 deletions server/api-service/lowcoder-plugins/graphqlPlugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@
<artifactId>netty-http-authenticator</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ private QueryExecutionResult convertToQueryExecutionResult(ResponseEntity<byte[]
HttpHeaders headers = stringResponseEntity.getHeaders();
MediaType contentType = firstNonNull(headers.getContentType(), MediaType.TEXT_PLAIN); // text type if null
byte[] body = stringResponseEntity.getBody();
HttpStatus statusCode = stringResponseEntity.getStatusCode();
HttpStatus statusCode = HttpStatus.resolve(stringResponseEntity.getStatusCode().value());
JsonNode resultHeaders = parseExecuteResultHeaders(headers);

if (body == null) {
Expand Down
4 changes: 4 additions & 0 deletions server/api-service/lowcoder-plugins/restApiPlugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,12 @@

package org.lowcoder.plugin.restapi;

import static com.google.common.base.MoreObjects.firstNonNull;
import static org.apache.commons.collections4.MapUtils.emptyIfNull;
import static org.apache.commons.lang3.StringUtils.trimToEmpty;
import static org.lowcoder.plugin.restapi.RestApiError.REST_API_EXECUTION_ERROR;
import static org.lowcoder.plugin.restapi.helpers.ContentTypeHelper.isBinary;
import static org.lowcoder.plugin.restapi.helpers.ContentTypeHelper.isJson;
import static org.lowcoder.plugin.restapi.helpers.ContentTypeHelper.isJsonContentType;
import static org.lowcoder.plugin.restapi.helpers.ContentTypeHelper.isPicture;
import static org.lowcoder.plugin.restapi.helpers.ContentTypeHelper.isValidContentType;
import static org.lowcoder.plugin.restapi.helpers.ContentTypeHelper.parseContentType;
import static org.lowcoder.sdk.exception.PluginCommonError.JSON_PARSE_ERROR;
import static org.lowcoder.sdk.exception.PluginCommonError.QUERY_ARGUMENT_ERROR;
import static org.lowcoder.sdk.exception.PluginCommonError.QUERY_EXECUTION_ERROR;
import static org.lowcoder.sdk.plugin.restapi.DataUtils.convertToMultiformFileValue;
import static org.lowcoder.sdk.plugin.restapi.auth.RestApiAuthType.DIGEST_AUTH;
import static org.lowcoder.sdk.plugin.restapi.auth.RestApiAuthType.OAUTH2_INHERIT_FROM_LOGIN;
import static org.lowcoder.sdk.util.ExceptionUtils.propagateError;
import static org.lowcoder.sdk.util.JsonUtils.readTree;
import static org.lowcoder.sdk.util.JsonUtils.toJsonThrows;
import static org.lowcoder.sdk.util.MustacheHelper.renderMustacheJson;
import static org.lowcoder.sdk.util.MustacheHelper.renderMustacheString;
import static org.lowcoder.sdk.util.StreamUtils.collectList;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.annotation.Nullable;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableMap;
import lombok.Builder;
import lombok.Getter;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -86,27 +52,41 @@
import org.lowcoder.sdk.query.QueryVisitorContext;
import org.lowcoder.sdk.webclient.WebClientBuildHelper;
import org.pf4j.Extension;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.*;
import org.springframework.http.client.reactive.ClientHttpRequest;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyInserter;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableMap;
import javax.annotation.Nullable;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import lombok.Builder;
import lombok.Getter;
import reactor.core.publisher.Mono;
import static com.google.common.base.MoreObjects.firstNonNull;
import static org.apache.commons.collections4.MapUtils.emptyIfNull;
import static org.apache.commons.lang3.StringUtils.trimToEmpty;
import static org.lowcoder.plugin.restapi.RestApiError.REST_API_EXECUTION_ERROR;
import static org.lowcoder.plugin.restapi.helpers.ContentTypeHelper.*;
import static org.lowcoder.sdk.exception.PluginCommonError.*;
import static org.lowcoder.sdk.plugin.restapi.DataUtils.convertToMultiformFileValue;
import static org.lowcoder.sdk.plugin.restapi.auth.RestApiAuthType.DIGEST_AUTH;
import static org.lowcoder.sdk.plugin.restapi.auth.RestApiAuthType.OAUTH2_INHERIT_FROM_LOGIN;
import static org.lowcoder.sdk.util.ExceptionUtils.propagateError;
import static org.lowcoder.sdk.util.JsonUtils.readTree;
import static org.lowcoder.sdk.util.JsonUtils.toJsonThrows;
import static org.lowcoder.sdk.util.MustacheHelper.renderMustacheJson;
import static org.lowcoder.sdk.util.MustacheHelper.renderMustacheString;
import static org.lowcoder.sdk.util.StreamUtils.collectList;

@Extension
public class RestApiExecutor implements QueryExecutor<RestApiDatasourceConfig, Object, RestApiQueryExecutionContext> {
Expand Down Expand Up @@ -382,7 +362,7 @@ private QueryExecutionResult convertToQueryExecutionResult(ResponseEntity<byte[]
HttpHeaders headers = responseEntity.getHeaders();
MediaType contentType = firstNonNull(headers.getContentType(), MediaType.TEXT_PLAIN); // text type if null
byte[] body = responseEntity.getBody();
HttpStatus statusCode = responseEntity.getStatusCode();
HttpStatus statusCode = HttpStatus.resolve(responseEntity.getStatusCode().value());
JsonNode resultHeaders = parseExecuteResultHeaders(headers);

if (body == null) {
Expand Down
4 changes: 4 additions & 0 deletions server/api-service/lowcoder-sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,9 @@
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
</dependencies>
</project>
Loading