Search in sources :

Example 6 with TestItem

use of com.epam.ta.reportportal.database.entity.item.TestItem in project commons-dao by reportportal.

the class TestItemRepositoryCustomImpl method findIdsNotInIssueType.

@Override
public List<String> findIdsNotInIssueType(String issueType, String launchId) {
    Query query = query(where(LAUNCH_REFERENCE).is(launchId)).addCriteria(where(ISSUE).exists(true)).addCriteria(where(ISSUE_TYPE).ne(issueType));
    query.fields().include(ID);
    return mongoTemplate.find(query, TestItem.class).stream().map(TestItem::getId).collect(toList());
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) TestItem(com.epam.ta.reportportal.database.entity.item.TestItem)

Example 7 with TestItem

use of com.epam.ta.reportportal.database.entity.item.TestItem in project commons-dao by reportportal.

the class TestItemRepositoryCustomImpl method findRetry.

@Override
public Optional<TestItem> findRetry(String retryId) {
    Query q = query(where("retries._id").is(retryId));
    q.fields().include("retries");
    return Optional.ofNullable(mongoTemplate.findOne(q, TestItem.class)).flatMap(it -> Optional.ofNullable(it.getRetries())).flatMap(it -> it.stream().filter(r -> retryId.equals(r.getId())).findAny());
}
Also used : java.util(java.util) MostFailedHistory(com.epam.ta.reportportal.database.entity.history.status.MostFailedHistory) RetryObject(com.epam.ta.reportportal.database.entity.history.status.RetryObject) Autowired(org.springframework.beans.factory.annotation.Autowired) MoreCollectors(com.epam.ta.reportportal.commons.MoreCollectors) TestItemIssueType(com.epam.ta.reportportal.database.entity.item.issue.TestItemIssueType) Fields(org.springframework.data.mongodb.core.aggregation.Fields) Query.query(org.springframework.data.mongodb.core.query.Query.query) CollectionUtils(org.apache.commons.collections.CollectionUtils) TestItem(com.epam.ta.reportportal.database.entity.item.TestItem) Duration(java.time.Duration) AddFieldsOperation.addFields(com.epam.ta.reportportal.database.dao.aggregation.AddFieldsOperation.addFields) Update(org.springframework.data.mongodb.core.query.Update) Sort(org.springframework.data.domain.Sort) StreamSupport(java.util.stream.StreamSupport) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Collectors.toSet(java.util.stream.Collectors.toSet) ASC(org.springframework.data.domain.Sort.Direction.ASC) Criteria.where(org.springframework.data.mongodb.core.query.Criteria.where) DbUtils(com.epam.ta.reportportal.commons.DbUtils) BasicDBObject(com.mongodb.BasicDBObject) TestItemIssue(com.epam.ta.reportportal.database.entity.item.issue.TestItemIssue) AggregationResults(org.springframework.data.mongodb.core.aggregation.AggregationResults) TestItemType(com.epam.ta.reportportal.database.entity.item.TestItemType) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) Criteria(org.springframework.data.mongodb.core.query.Criteria) Query(org.springframework.data.mongodb.core.query.Query) Collectors.toList(java.util.stream.Collectors.toList) com.epam.ta.reportportal.database.entity(com.epam.ta.reportportal.database.entity) UpdateStatisticsQueryBuilder(com.epam.ta.reportportal.database.search.UpdateStatisticsQueryBuilder) ModifiableQueryBuilder(com.epam.ta.reportportal.database.search.ModifiableQueryBuilder) ObjectId(org.bson.types.ObjectId) GroupOperation(org.springframework.data.mongodb.core.aggregation.GroupOperation) Pattern(java.util.regex.Pattern) DESC(org.springframework.data.domain.Sort.Direction.DESC) FlakyHistory(com.epam.ta.reportportal.database.entity.history.status.FlakyHistory) StatisticSubType(com.epam.ta.reportportal.database.entity.statistics.StatisticSubType) Query(org.springframework.data.mongodb.core.query.Query) TestItem(com.epam.ta.reportportal.database.entity.item.TestItem)

Example 8 with TestItem

use of com.epam.ta.reportportal.database.entity.item.TestItem in project commons-dao by reportportal.

the class TestItemRepositoryCustomImpl method findPathNames.

@Override
public Map<String, String> findPathNames(Iterable<String> path) {
    Query q = query(where("_id").in(toObjId(path)));
    q.fields().include("name");
    List<TestItem> testItems = mongoTemplate.find(q, TestItem.class);
    return testItems.stream().collect(MoreCollectors.toLinkedMap(TestItem::getId, TestItem::getName));
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) TestItem(com.epam.ta.reportportal.database.entity.item.TestItem)

Example 9 with TestItem

use of com.epam.ta.reportportal.database.entity.item.TestItem in project commons-dao by reportportal.

the class DeleteItemsListener method onBeforeDelete.

@Override
public void onBeforeDelete(BeforeDeleteEvent<TestItem> event) {
    DBObject dbqo = queryMapper.getMappedObject(event.getDBObject(), mappingContext.getPersistentEntity(TestItem.class));
    for (DBObject dbObject : mongoTemplate.getCollection(event.getCollectionName()).find(dbqo)) {
        Boolean isRetryProcessed = (Boolean) dbObject.get("retryProcessed");
        if (isRetryProcessed == null || isRetryProcessed) {
            String objectId = dbObject.get("_id").toString();
            List<TestItem> itemsForDelete = mongoTemplate.find(queryItems(objectId), TestItem.class);
            List<ObjectId> objectIds = itemsForDelete.stream().map(it -> new ObjectId(it.getId())).collect(toList());
            BasicDBObject query = new BasicDBObject("_id", new BasicDBObject("$in", objectIds));
            mongoTemplate.getCollection(event.getCollectionName()).remove(query);
            List<String> itemRefs = getLogItemReferences(itemsForDelete);
            logRepository.deleteByItemRef(itemRefs);
        }
    }
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) BasicDBObject(com.mongodb.BasicDBObject) Autowired(org.springframework.beans.factory.annotation.Autowired) LogRepository(com.epam.ta.reportportal.database.dao.LogRepository) BeforeDeleteEvent(org.springframework.data.mongodb.core.mapping.event.BeforeDeleteEvent) Criteria(org.springframework.data.mongodb.core.query.Criteria) Query(org.springframework.data.mongodb.core.query.Query) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) AbstractMongoEventListener(org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) DBObject(com.mongodb.DBObject) TestItem(com.epam.ta.reportportal.database.entity.item.TestItem) Service(org.springframework.stereotype.Service) ObjectId(org.bson.types.ObjectId) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) BasicDBObject(com.mongodb.BasicDBObject) ObjectId(org.bson.types.ObjectId) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) TestItem(com.epam.ta.reportportal.database.entity.item.TestItem)

Example 10 with TestItem

use of com.epam.ta.reportportal.database.entity.item.TestItem in project commons-dao by reportportal.

the class DeleteProjectListenerTest method testData.

private TestData testData() {
    final Project project = new Project();
    project.setName(PROJECT_ID);
    projectRepository.save(project);
    final Launch launch = new Launch();
    launch.setProjectRef(project.getId());
    launchRepository.save(launch);
    final TestItem suite = new TestItem();
    suite.setLaunchRef(launch.getId());
    testItemRepository.save(suite);
    final TestItem test = new TestItem();
    test.setLaunchRef(launch.getId());
    test.setParent(suite.getId());
    test.setPath(singletonList(suite.getId()));
    testItemRepository.save(test);
    final TestItem step = new TestItem();
    step.setLaunchRef(launch.getId());
    step.setParent(test.getId());
    final List<String> stepPath = new ArrayList<>(test.getPath());
    stepPath.add(test.getId());
    step.setPath(stepPath);
    testItemRepository.save(step);
    final Log log = log(step.getId());
    final TestData testData = new TestData();
    testData.projectId = project.getId();
    testData.launchId = launch.getId();
    testData.suiteId = suite.getId();
    testData.testId = test.getId();
    testData.stepId = step.getId();
    testData.logId = log.getId();
    testData.fileName = log.getBinaryContent().getBinaryDataId();
    testData.thumbnail = log.getBinaryContent().getThumbnailId();
    return testData;
}
Also used : ArrayList(java.util.ArrayList) TestItem(com.epam.ta.reportportal.database.entity.item.TestItem)

Aggregations

TestItem (com.epam.ta.reportportal.database.entity.item.TestItem)10 Query (org.springframework.data.mongodb.core.query.Query)6 ArrayList (java.util.ArrayList)3 TestItemIssue (com.epam.ta.reportportal.database.entity.item.issue.TestItemIssue)2 BasicDBObject (com.mongodb.BasicDBObject)2 Collectors.toList (java.util.stream.Collectors.toList)2 ObjectId (org.bson.types.ObjectId)2 Test (org.junit.Test)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)2 Criteria (org.springframework.data.mongodb.core.query.Criteria)2 BaseDaoTest (com.epam.ta.reportportal.BaseDaoTest)1 DbUtils (com.epam.ta.reportportal.commons.DbUtils)1 MoreCollectors (com.epam.ta.reportportal.commons.MoreCollectors)1 LogRepository (com.epam.ta.reportportal.database.dao.LogRepository)1 AddFieldsOperation.addFields (com.epam.ta.reportportal.database.dao.aggregation.AddFieldsOperation.addFields)1 com.epam.ta.reportportal.database.entity (com.epam.ta.reportportal.database.entity)1 FlakyHistory (com.epam.ta.reportportal.database.entity.history.status.FlakyHistory)1 MostFailedHistory (com.epam.ta.reportportal.database.entity.history.status.MostFailedHistory)1 RetryObject (com.epam.ta.reportportal.database.entity.history.status.RetryObject)1