Skip to content

Commit

Permalink
feat: replace the configuration of "dynamic" (#424)
Browse files Browse the repository at this point in the history
  • Loading branch information
coryhh authored Jun 24, 2024
1 parent 087fb21 commit b744f58
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.arextest.web.api.service.beans;

import com.arextest.web.common.LogUtils;
import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import lombok.extern.slf4j.Slf4j;
import org.bson.codecs.configuration.CodecRegistries;
import org.bson.codecs.configuration.CodecRegistry;
import org.bson.codecs.pojo.PojoCodecProvider;
Expand All @@ -11,19 +17,14 @@
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;
import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import org.springframework.data.mongodb.core.convert.MongoConverter;

import com.arextest.web.common.LogUtils;
import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Configuration
public class MongodbConfiguration {

private static final String AREX_STORAGE_DB = "arex_storage_db";
@Value("${arex.mongo.uri}")
private String mongoUrl;
Expand Down Expand Up @@ -56,6 +57,11 @@ public MongoDatabaseFactory mongoDbFactory() {
@Bean
@ConditionalOnMissingBean(MongoOperations.class)
public MongoTemplate mongoTemplate(MongoDatabaseFactory factory, MongoConverter converter) {
return new MongoTemplate(factory, converter);
// remove the field "_class" in the document.
// https://stackoverflow.com/questions/6810488/spring-data-mongodb-mappingmongoconverter-remove-class/
MappingMongoConverter mappingMongoConverter = (MappingMongoConverter) converter;
mappingMongoConverter.setTypeMapper(new DefaultMongoTypeMapper(null));

return new MongoTemplate(factory, mappingMongoConverter);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.arextest.web.api.service.controller.config;

import com.arextest.common.model.response.Response;
import com.arextest.common.utils.ResponseUtils;
import com.arextest.config.model.dto.ModifyType;
import com.arextest.config.model.dto.record.DynamicClassConfiguration;
import com.arextest.web.core.business.config.ConfigurableHandler;
import com.arextest.web.core.business.config.record.DynamicClassConfigurableHandler;
import com.arextest.web.core.business.config.record.ServiceCollectConfigurableHandler;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
Expand All @@ -25,6 +28,9 @@ public class DynamicClassConfigurableController extends
@Resource
private ServiceCollectConfigurableHandler serviceCollectConfigurableHandler;

@Resource
private DynamicClassConfigurableHandler dynamicClassConfigurableHandler;

public DynamicClassConfigurableController(
@Autowired ConfigurableHandler<DynamicClassConfiguration> configurableHandler) {
super(configurableHandler);
Expand All @@ -40,4 +46,16 @@ public Response modify(@PathVariable ModifyType modifyType,

return super.modify(modifyType, configuration);
}

@SuppressWarnings("java:S3752")
@RequestMapping("/replace/{appId}")
@ResponseBody
public Response replace(@PathVariable String appId,
@RequestBody List<DynamicClassConfiguration> configurations) {
serviceCollectConfigurableHandler.updateServiceCollectTime(appId);
return ResponseUtils.successResponse(
dynamicClassConfigurableHandler.replace(appId, configurations)
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import com.arextest.config.model.dto.record.DynamicClassConfiguration;
import com.arextest.config.repository.ConfigRepositoryProvider;
import com.arextest.config.repository.impl.DynamicClassConfigurationRepositoryImpl;
import com.arextest.web.core.business.config.AbstractConfigurableHandler;
import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -21,6 +24,9 @@ protected DynamicClassConfigurableHandler(
super(repositoryProvider);
}

@Resource
DynamicClassConfigurationRepositoryImpl dynamicClassConfigurationRepository;

@Override
public boolean insert(DynamicClassConfiguration configuration) {
if (StringUtils.isEmpty(configuration.getAppId())) {
Expand All @@ -36,4 +42,8 @@ public boolean removeByAppId(String appId) {
return CollectionUtils.isEmpty(super.useResultAsList(appId))
|| repositoryProvider.removeByAppId(appId);
}

public boolean replace(String appId, List<DynamicClassConfiguration> configuration) {
return dynamicClassConfigurationRepository.cover(appId, configuration);
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@
<revision>0.6.4.12</revision>
<arex-common.version>0.1.28</arex-common.version>
<arex-extension-interface.version>0.0.1</arex-extension-interface.version>
<arex-storage-config.version>1.1.28</arex-storage-config.version>
<arex-storage-config.version>1.2.7</arex-storage-config.version>
<arex-storage.version>1.1.27</arex-storage.version>
<arex-compare-extension.version>0.0.1</arex-compare-extension.version>
<caffeine.version>2.9.3</caffeine.version>
Expand Down

0 comments on commit b744f58

Please sign in to comment.