Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/update scene info mongo #451

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion arex-web-api/src/main/resources/application-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ arex:
service:
url: http://10.118.1.217:18092
mongo:
uri: mongodb://arex:password@10.118.1.217:37017/arex_storage_db
uri: mongodb://arex:iLoveArex@10.118.1.217:37017/arex_storage_db

# standalone without password
spring:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.arextest.web.model.dto.PlanItemDto;
import com.arextest.web.model.dto.ReportPlanStatisticDto;
import com.arextest.web.model.dto.iosummary.CaseSummary;
import com.arextest.web.model.dto.iosummary.DiffDetail;
import com.arextest.web.model.dto.iosummary.SceneInfo;
import com.arextest.web.model.dto.iosummary.SubSceneInfo;
import com.arextest.web.model.enums.DiffResultCode;
Expand Down Expand Up @@ -65,9 +66,8 @@ public class SceneReportService {
*/
public void report(CaseSummary caseSummary) {
SceneInfo sceneInfo = SceneInfo.builder().code(caseSummary.getCode())
.categoryKey(caseSummary.categoryKey())
.planId(caseSummary.getPlanId()).planItemId(caseSummary.getPlanItemId())
.summary(caseSummary).build();
.categoryKey(caseSummary.categoryKey()).planId(caseSummary.getPlanId())
.planItemId(caseSummary.getPlanItemId()).summary(caseSummary).build();
sceneInfoRepository.save(sceneInfo);
}

Expand Down Expand Up @@ -101,11 +101,10 @@ private List<SceneInfo> checkDuplicateScene(List<SceneInfo> sceneInfos) {

public QuerySceneInfoResponseType querySceneInfo(String planId, String planItemId) {
QuerySceneInfoResponseType response = new QuerySceneInfoResponseType();
List<SceneInfo> sceneInfos = sceneInfoRepository.querySceneInfo(planId, planItemId);
List<SceneInfo> sceneInfos = queryCompleteSceneInfo(planId, planItemId);
sceneInfos = checkDuplicateScene(sceneInfos);
List<QuerySceneInfoResponseType.SceneInfoType> sceneInfoTypes =
sceneInfos.stream().map(SceneInfoMapper.INSTANCE::contractFromDto)
.collect(Collectors.toList());
List<QuerySceneInfoResponseType.SceneInfoType> sceneInfoTypes = sceneInfos.stream()
.map(SceneInfoMapper.INSTANCE::contractFromDto).collect(Collectors.toList());

// to set recordTime and replayTime
Map<String, QuerySceneInfoResponseType.SubSceneInfoType> subSceneInfoTypeMap = new HashMap<>();
Expand All @@ -118,8 +117,7 @@ public QuerySceneInfoResponseType querySceneInfo(String planId, String planItemI
if (MapUtils.isNotEmpty(subSceneInfoTypeMap)) {
List<CompareResultDto> dtos = replayCompareResultRepository.queryCompareResults(planId,
Collections.singletonList(planItemId), new ArrayList<>(subSceneInfoTypeMap.keySet()),
null,
Arrays.asList(RECORD_ID, RECORD_TIME, REPLAY_TIME));
null, Arrays.asList(RECORD_ID, RECORD_TIME, REPLAY_TIME));
for (CompareResultDto dto : dtos) {
String recordId = dto.getRecordId();
QuerySceneInfoResponseType.SubSceneInfoType subSceneInfoType = subSceneInfoTypeMap.get(
Expand All @@ -145,7 +143,7 @@ public boolean feedbackScene(FeedbackSceneRequest request) {
final Integer feedbackType = request.getFeedbackType();

// update scene
List<SceneInfo> sceneInfos = sceneInfoRepository.querySceneInfo(planId, planItemId);
List<SceneInfo> sceneInfos = queryCompleteSceneInfo(planId, planItemId);
sceneInfos.forEach(sceneInfo -> {
if (MapUtils.isNotEmpty(sceneInfo.getSubSceneInfoMap())) {
sceneInfo.getSubSceneInfoMap().forEach((groupKey, subSceneInfo) -> {
Expand Down Expand Up @@ -176,6 +174,36 @@ public boolean feedbackScene(FeedbackSceneRequest request) {
return true;
}


public List<SceneInfo> queryCompleteSceneInfo(String planId, String planItemId) {
List<SceneInfo> sceneInfos = sceneInfoRepository.querySceneInfo(planId, planItemId);
if (CollectionUtils.isEmpty(sceneInfos)) {
return sceneInfos;
}

Map<String, SubSceneInfo> recordIdToSubSceneInfoMap = new HashMap<>();
sceneInfos.forEach(item -> {
Map<String, SubSceneInfo> subSceneInfoMap = item.getSubSceneInfoMap();
if (MapUtils.isEmpty(subSceneInfoMap)) {
return;
}
subSceneInfoMap.forEach(
(groupKey, subSceneInfo) -> recordIdToSubSceneInfoMap.put(subSceneInfo.getRecordId(),
subSceneInfo)
);
});
List<String> recordIds = new ArrayList<>(recordIdToSubSceneInfoMap.keySet());
List<CaseSummary> caseSummaries = caseSummaryRepository.queryCaseSummary(planId, planItemId,
recordIds);
for (CaseSummary caseSummary : caseSummaries) {
String recordId = caseSummary.getRecordId();
List<DiffDetail> diffDetails = caseSummary.getDiffs();
SubSceneInfo subSceneInfo = recordIdToSubSceneInfoMap.get(recordId);
subSceneInfo.setDetails(diffDetails);
}
return sceneInfos;
}

private boolean checkAllSubScenes(SceneInfo sceneInfo) {
boolean result = true;
for (SubSceneInfo subSceneInfo : sceneInfo.getSubSceneInfoMap().values()) {
Expand All @@ -191,15 +219,13 @@ private boolean passCases(String planId, String planItemId, String groupKey) {
LOGGER.info("All the scenes has been passed");
// query other cases in the same subScene
List<CaseSummary> caseSummaryList = caseSummaryRepository.query(planId, planItemId);
List<String> recordIds =
caseSummaryList.stream()
.filter(caseSummary -> String.valueOf(caseSummary.groupKey()).equals(groupKey))
.map(CaseSummary::getRecordId).collect(Collectors.toList());
List<String> recordIds = caseSummaryList.stream()
.filter(caseSummary -> String.valueOf(caseSummary.groupKey()).equals(groupKey))
.map(CaseSummary::getRecordId).collect(Collectors.toList());

// update compareResult
List<CompareResultDto> compareResultList = replayCompareResultRepository.queryCompareResults(
planId,
Collections.singletonList(planItemId), recordIds, null,
planId, Collections.singletonList(planItemId), recordIds, null,
Arrays.asList(RECORD_ID, RECORD_TIME, REPLAY_TIME));
for (CompareResultDto compareResult : compareResultList) {
compareResult.setDiffResultCode(DiffResultCode.COMPARED_WITHOUT_DIFFERENCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public interface CaseSummaryRepository extends RepositoryProvider {
boolean upsert(CaseSummary summary);

List<CaseSummary> query(String planId, String planItemId);

List<CaseSummary> queryCaseSummary(String planId, String planItemId, List<String> recordIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import com.arextest.web.model.dao.mongodb.iosummary.CaseSummaryCollection;
import com.arextest.web.model.dto.iosummary.CaseSummary;
import com.arextest.web.model.mapper.CaseSummaryMapper;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.FindAndModifyOptions;
import org.springframework.data.mongodb.core.MongoTemplate;
Expand Down Expand Up @@ -59,4 +61,20 @@ public List<CaseSummary> query(String planId, String planItemId) {
return caseSummaryCollections.stream().map(CaseSummaryMapper.INSTANCE::dtoFromDao)
.collect(Collectors.toList());
}

@Override
public List<CaseSummary> queryCaseSummary(String planId, String planItemId,
List<String> recordIds) {
if (CollectionUtils.isEmpty(recordIds)) {
return Collections.emptyList();
}
Query query = Query.query(Criteria.where(PLAN_ID).is(planId).and(PLAN_ITEM_ID)
.is(planItemId).and(RECORD_ID).in(recordIds));
List<CaseSummaryCollection> caseSummaryCollections = mongoTemplate.find(query,
CaseSummaryCollection.class);
return caseSummaryCollections.stream().map(CaseSummaryMapper.INSTANCE::dtoFromDao)
.collect(Collectors.toList());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public SceneInfo save(SceneInfo sceneInfo) {
subSceneInfo.getRecordId());
update.set(toColumnName(groupKeyName, SubSceneInfoDao.Fields.replayId),
subSceneInfo.getReplayId());
update.set(toColumnName(groupKeyName, SubSceneInfoDao.Fields.details),
subSceneInfo.getDetails());
}

SceneInfoCollection andModify = mongoTemplate.findAndModify(query, update,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ public class CaseSummaryCollection extends ModelBase {

private List<DiffDetailDao> diffs;

private Long categoryKey;
private Long groupKey;

private Date dataCreateTime;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.arextest.web.model.dao.mongodb.iosummary;

import com.arextest.web.model.enums.FeedbackTypeEnum;
import java.util.List;
import lombok.Data;
import lombok.experimental.FieldNameConstants;

Expand All @@ -12,16 +11,15 @@
@FieldNameConstants
public class SubSceneInfoDao {

private int code;
private int count;

private int code;
private String recordId;
private String replayId;

/**
* @see FeedbackTypeEnum#getCode() ;
*/
private Integer feedbackType;
private String remark;

private List<DiffDetailDao> details;
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@

<properties>
<!-- Maven CI Friendly Versions https://maven.apache.org/maven-ci-friendly.html -->
<revision>0.6.5.7</revision>
<revision>0.6.5.8</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.2.24</arex-storage-config.version>
Expand Down