-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add SystemConfiguration repo (#167)
* feat: add SystemConfiguration repo * feat: add SystemConfiguration repo --------- Co-authored-by: wildeslam <[email protected]>
- Loading branch information
Showing
11 changed files
with
214 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
arex-storage-config/src/main/java/com/arextest/config/mapper/SystemConfigurationMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.arextest.config.mapper; | ||
|
||
import com.arextest.config.model.dao.config.SystemConfigurationCollection; | ||
import com.arextest.config.model.dto.SystemConfiguration; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.Mappings; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
/** | ||
* @author wildeslam. | ||
* @create 2024/2/21 19:53 | ||
*/ | ||
@Mapper | ||
public interface SystemConfigurationMapper { | ||
|
||
SystemConfigurationMapper INSTANCE = Mappers.getMapper(SystemConfigurationMapper.class); | ||
|
||
SystemConfiguration dtoFromDao(SystemConfigurationCollection dao); | ||
|
||
@Mappings({@Mapping(target = "id", expression = "java(null)"), | ||
@Mapping(target = "dataChangeCreateTime", expression = "java(System.currentTimeMillis())"), | ||
@Mapping(target = "dataChangeUpdateTime", expression = "java(System.currentTimeMillis())")}) | ||
SystemConfigurationCollection daoFromDto(SystemConfiguration dto); | ||
} | ||
|
35 changes: 35 additions & 0 deletions
35
...fig/src/main/java/com/arextest/config/model/dao/config/SystemConfigurationCollection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.arextest.config.model.dao.config; | ||
|
||
import com.arextest.config.model.dao.BaseEntity; | ||
import com.arextest.config.model.dto.DesensitizationJar; | ||
import java.util.Map; | ||
import lombok.Data; | ||
import lombok.experimental.FieldNameConstants; | ||
|
||
/** | ||
* @author wildeslam. | ||
* @create 2024/2/21 19:43 | ||
*/ | ||
@Data | ||
@FieldNameConstants | ||
public class SystemConfigurationCollection extends BaseEntity { | ||
|
||
public static final String DOCUMENT_NAME = "SystemConfiguration"; | ||
|
||
/** | ||
* The problem of prohibiting concurrent repeated insertions, the key is unique the function of | ||
* this record | ||
*/ | ||
private String key; | ||
private Map<String, Integer> refreshTaskMark; | ||
private DesensitizationJar desensitizationJar; | ||
private String callbackUrl; | ||
|
||
|
||
public interface KeySummary { | ||
String REFRESH_DATA = "refresh_data"; | ||
String DESERIALIZATION_JAR = "deserialization_jar"; | ||
String CALLBACK_URL = "callback_url"; | ||
|
||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
arex-storage-config/src/main/java/com/arextest/config/model/dto/DesensitizationJar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.arextest.config.model.dto; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* @author wildeslam. | ||
* @create 2024/2/20 20:11 | ||
*/ | ||
@Data | ||
public class DesensitizationJar { | ||
private String jarUrl; | ||
private String remark; | ||
} |
43 changes: 43 additions & 0 deletions
43
arex-storage-config/src/main/java/com/arextest/config/model/dto/SystemConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.arextest.config.model.dto; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import lombok.Data; | ||
|
||
/** | ||
* @author wildeslam. | ||
* @create 2024/2/21 19:54 | ||
*/ | ||
@Data | ||
public class SystemConfiguration { | ||
/** | ||
* The problem of prohibiting concurrent repeated insertions, the key is unique the function of | ||
* this record | ||
*/ | ||
private String key; | ||
private Map<String, Integer> refreshTaskMark; | ||
private DesensitizationJar desensitizationJar; | ||
private String callbackUrl; | ||
|
||
public static SystemConfiguration mergeConfigs(List<SystemConfiguration> systemConfigurations) { | ||
if (systemConfigurations == null || systemConfigurations.isEmpty()) { | ||
return new SystemConfiguration(); | ||
} | ||
SystemConfiguration result = new SystemConfiguration(); | ||
for (SystemConfiguration systemConfiguration : systemConfigurations) { | ||
if (systemConfiguration == null) { | ||
continue; | ||
} | ||
if (systemConfiguration.getRefreshTaskMark() != null) { | ||
result.setRefreshTaskMark(systemConfiguration.getRefreshTaskMark()); | ||
} | ||
if (systemConfiguration.getDesensitizationJar() != null) { | ||
result.setDesensitizationJar(systemConfiguration.getDesensitizationJar()); | ||
} | ||
if (systemConfiguration.getCallbackUrl() != null) { | ||
result.setCallbackUrl(systemConfiguration.getCallbackUrl()); | ||
} | ||
} | ||
return result; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ge-config/src/main/java/com/arextest/config/repository/SystemConfigurationRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.arextest.config.repository; | ||
|
||
import com.arextest.config.model.dto.SystemConfiguration; | ||
import java.util.List; | ||
|
||
/** | ||
* @author wildeslam. | ||
* @create 2024/2/21 19:57 | ||
*/ | ||
public interface SystemConfigurationRepository { | ||
boolean saveConfig(SystemConfiguration systemConfig); | ||
|
||
List<SystemConfiguration> getAllSystemConfigList(); | ||
|
||
SystemConfiguration getSystemConfigByKey(String key); | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
.../src/main/java/com/arextest/config/repository/impl/SystemConfigurationRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.arextest.config.repository.impl; | ||
|
||
import com.arextest.config.mapper.SystemConfigurationMapper; | ||
import com.arextest.config.model.dao.config.SystemConfigurationCollection; | ||
import com.arextest.config.model.dao.config.SystemConfigurationCollection.Fields; | ||
import com.arextest.config.model.dto.SystemConfiguration; | ||
import com.arextest.config.repository.SystemConfigurationRepository; | ||
import com.arextest.config.utils.MongoHelper; | ||
import com.mongodb.client.MongoCollection; | ||
import com.mongodb.client.MongoCursor; | ||
import com.mongodb.client.MongoDatabase; | ||
import com.mongodb.client.model.Filters; | ||
import com.mongodb.client.model.UpdateOptions; | ||
import com.mongodb.client.model.Updates; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import javax.annotation.PostConstruct; | ||
import org.bson.conversions.Bson; | ||
|
||
/** | ||
* @author wildeslam. | ||
* @create 2024/2/21 19:58 | ||
*/ | ||
public class SystemConfigurationRepositoryImpl implements SystemConfigurationRepository { | ||
|
||
MongoCollection<SystemConfigurationCollection> mongoCollection; | ||
private MongoDatabase mongoDatabase; | ||
|
||
public SystemConfigurationRepositoryImpl(MongoDatabase mongoDatabase) { | ||
this.mongoDatabase = mongoDatabase; | ||
} | ||
|
||
@PostConstruct | ||
public void init() { | ||
this.mongoCollection = mongoDatabase.getCollection(SystemConfigurationCollection.DOCUMENT_NAME, | ||
SystemConfigurationCollection.class); | ||
} | ||
|
||
@Override | ||
public boolean saveConfig(SystemConfiguration systemConfig) { | ||
Bson filter = Filters.eq(Fields.key, systemConfig.getKey()); | ||
List<Bson> updateList = Arrays.asList(MongoHelper.getUpdate(), | ||
MongoHelper.getFullProperties(systemConfig)); | ||
Bson updateCombine = Updates.combine(updateList); | ||
return mongoCollection.updateOne(filter, updateCombine, new UpdateOptions().upsert(true)) | ||
.getModifiedCount() > 0; | ||
} | ||
|
||
@Override | ||
public List<SystemConfiguration> getAllSystemConfigList() { | ||
List<SystemConfiguration> systemConfigurations = new ArrayList<>(); | ||
try (MongoCursor<SystemConfigurationCollection> cursor = mongoCollection.find().iterator()) { | ||
while (cursor.hasNext()) { | ||
SystemConfigurationCollection document = cursor.next(); | ||
SystemConfiguration dto = SystemConfigurationMapper.INSTANCE.dtoFromDao(document); | ||
systemConfigurations.add(dto); | ||
} | ||
} | ||
return systemConfigurations; | ||
} | ||
|
||
@Override | ||
public SystemConfiguration getSystemConfigByKey(String key) { | ||
Bson filter = Filters.eq(Fields.key, key); | ||
SystemConfigurationCollection collection = mongoCollection.find(filter).first(); | ||
return collection == null ? null : SystemConfigurationMapper.INSTANCE.dtoFromDao(collection); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters