-
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.
- Loading branch information
Showing
10 changed files
with
220 additions
and
5 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
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
30 changes: 30 additions & 0 deletions
30
arex-storage-web-api/src/main/java/com/arextest/storage/model/Constants.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,30 @@ | ||
package com.arextest.storage.model; | ||
|
||
public interface Constants{ | ||
|
||
String APP_ID = "appId"; | ||
|
||
String REPLAY_SCHEDULE_CONFIG_COLLECTION_NAME = "ReplayScheduleConfig"; | ||
|
||
String CONFIG_COMPARISON_ENCRYPTION_COLLECTION_NAME = "ConfigComparisonEncryption"; | ||
|
||
String CONFIG_COMPARISON_EXCLUSIONS_COLLECTION_NAME = "ConfigComparisonExclusions"; | ||
|
||
String CONFIG_COMPARISON_IGNORE_CATEGORY_COLLECTION_NAME = "ConfigComparisonIgnoreCategory"; | ||
|
||
String CONFIG_COMPARISON_LIST_SORT_COLLECTION_NAME = "ConfigComparisonListSort"; | ||
|
||
String CONFIG_COMPARISON_REFERENCE_COLLECTION_NAME = "ConfigComparisonReference"; | ||
|
||
// region: fieldNames of Config | ||
String COMPARE_CONFIG_TYPE = "compareConfigType"; | ||
String OPERATION_ID = "operationId"; | ||
String FS_INTERFACE_ID = "fsInterfaceId"; | ||
String DEPENDENCY_ID = "dependencyId"; | ||
String DATA_CHANGE_CREATE_TIME = "dataChangeCreateTime"; | ||
String DATA_CHANGE_UPDATE_TIME = "dataChangeUpdateTime"; | ||
String EXPIRATION_TYPE = "expirationType"; | ||
String EXPIRATION_TIME = "expirationTime"; | ||
// endregion | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...rage-web-api/src/main/java/com/arextest/storage/model/event/ApplicationCreationEvent.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,10 @@ | ||
package com.arextest.storage.model.event; | ||
|
||
import org.springframework.context.ApplicationEvent; | ||
|
||
public class ApplicationCreationEvent extends ApplicationEvent { | ||
|
||
public ApplicationCreationEvent(String appId) { | ||
super(appId); | ||
} | ||
} |
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
125 changes: 125 additions & 0 deletions
125
...pi/src/main/java/com/arextest/storage/service/event/ApplicationCreationEventListener.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,125 @@ | ||
package com.arextest.storage.service.event; | ||
|
||
import com.arextest.storage.model.Constants; | ||
import com.arextest.storage.model.event.ApplicationCreationEvent; | ||
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.Date; | ||
import java.util.List; | ||
import javax.annotation.Resource; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import lombok.Setter; | ||
import org.apache.commons.collections4.CollectionUtils; | ||
import org.bson.Document; | ||
import org.bson.conversions.Bson; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class ApplicationCreationEventListener implements | ||
ApplicationListener<ApplicationCreationEvent> { | ||
|
||
@Resource | ||
private MongoDatabase mongoDatabase; | ||
|
||
@Resource | ||
private CompareConfiguration compareConfiguration; | ||
|
||
private static final String IGNORE_CATEGORY_DETAIL = "ignoreCategoryDetail"; | ||
|
||
@Override | ||
public void onApplicationEvent(@NonNull ApplicationCreationEvent event) { | ||
String appId = (String) event.getSource(); | ||
// create default mock compare ignore config | ||
createDefaultMockCompareIgnoreConfig(appId); | ||
} | ||
|
||
|
||
private void createDefaultMockCompareIgnoreConfig(String appId) { | ||
List<CategoryDetail> ignoredCategoryTypes = compareConfiguration.getIgnoredCategoryTypes(); | ||
if (CollectionUtils.isEmpty(ignoredCategoryTypes)) { | ||
return; | ||
} | ||
|
||
List<Document> mockCompareIgnoreConfig = new ArrayList<>(); | ||
for (CategoryDetail category : ignoredCategoryTypes) { | ||
if (category == null || category.getOperationType().isEmpty()) { | ||
continue; | ||
} | ||
long currentTimeMillis = System.currentTimeMillis(); | ||
Document document = new Document(); | ||
document.put(Constants.APP_ID, appId); | ||
// to see com.arextest.web.model.contract.contracts.common.enums.CompareConfigType in arex-api | ||
// it represents the config of comparison, which is main entrance | ||
document.put(Constants.COMPARE_CONFIG_TYPE, 0); | ||
document.put(Constants.OPERATION_ID, null); | ||
document.put(Constants.DEPENDENCY_ID, null); | ||
document.put(Constants.FS_INTERFACE_ID, null); | ||
document.put(Constants.DATA_CHANGE_CREATE_TIME, currentTimeMillis); | ||
document.put(Constants.DATA_CHANGE_UPDATE_TIME, currentTimeMillis); | ||
// to see com.arextest.web.model.contract.contracts.common.enums.ExpirationType in arex-api | ||
// it represents the config pinned forever use it | ||
document.put(Constants.EXPIRATION_TYPE, 0); | ||
document.put(Constants.EXPIRATION_TIME, new Date()); | ||
document.put(IGNORE_CATEGORY_DETAIL, category); | ||
mockCompareIgnoreConfig.add(document); | ||
} | ||
|
||
if (CollectionUtils.isNotEmpty(mockCompareIgnoreConfig)) { | ||
for (Document document : mockCompareIgnoreConfig) { | ||
Bson filter = Filters.and( | ||
Filters.eq(Constants.APP_ID, document.get(Constants.APP_ID)), | ||
Filters.eq(Constants.COMPARE_CONFIG_TYPE, document.get(Constants.COMPARE_CONFIG_TYPE)), | ||
Filters.eq(Constants.OPERATION_ID, document.get(Constants.OPERATION_ID)), | ||
Filters.eq(Constants.DEPENDENCY_ID, document.get(Constants.DEPENDENCY_ID)), | ||
Filters.eq(Constants.FS_INTERFACE_ID, document.get(Constants.FS_INTERFACE_ID)), | ||
Filters.eq(IGNORE_CATEGORY_DETAIL, document.get(IGNORE_CATEGORY_DETAIL)) | ||
); | ||
|
||
Bson update = Updates.combine( | ||
Updates.set(Constants.APP_ID, document.get(Constants.APP_ID)), | ||
Updates.set(Constants.COMPARE_CONFIG_TYPE, document.get(Constants.COMPARE_CONFIG_TYPE)), | ||
Updates.set(Constants.OPERATION_ID, document.get(Constants.OPERATION_ID)), | ||
Updates.set(Constants.DEPENDENCY_ID, document.get(Constants.DEPENDENCY_ID)), | ||
Updates.set(Constants.FS_INTERFACE_ID, document.get(Constants.FS_INTERFACE_ID)), | ||
Updates.set(IGNORE_CATEGORY_DETAIL, document.get(IGNORE_CATEGORY_DETAIL)), | ||
Updates.set(Constants.DATA_CHANGE_CREATE_TIME, | ||
document.get(Constants.DATA_CHANGE_CREATE_TIME)), | ||
Updates.set(Constants.DATA_CHANGE_UPDATE_TIME, | ||
document.get(Constants.DATA_CHANGE_UPDATE_TIME)), | ||
Updates.set(Constants.EXPIRATION_TYPE, document.get(Constants.EXPIRATION_TYPE)), | ||
Updates.set(Constants.EXPIRATION_TIME, document.get(Constants.EXPIRATION_TIME)) | ||
); | ||
|
||
mongoDatabase.getCollection(Constants.CONFIG_COMPARISON_IGNORE_CATEGORY_COLLECTION_NAME) | ||
.updateOne(filter, update, new UpdateOptions().upsert(true)); | ||
} | ||
} | ||
} | ||
|
||
@Configuration | ||
@ConfigurationProperties(prefix = "arex.config.default.compare") | ||
@Getter | ||
@Setter | ||
public static class CompareConfiguration { | ||
|
||
private List<CategoryDetail> ignoredCategoryTypes; | ||
|
||
} | ||
|
||
@Getter | ||
@Setter | ||
public static class CategoryDetail { | ||
|
||
private String operationType; | ||
private String operationName; | ||
} | ||
|
||
|
||
} |
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