Search in sources :

Example 1 with Launch

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

the class LaunchRepositoryTest method findLatestLaunch.

@Test
public void findLatestLaunch() {
    String project = "project";
    String launch = "launch";
    String mode = "DEFAULT";
    Launch launch1 = new Launch();
    launch1.setName(launch);
    launch1.setProjectRef(project);
    launch1.setMode(Mode.valueOf(mode));
    launch1.setNumber(1L);
    launch1.setStatus(Status.PASSED);
    Launch launch2 = new Launch();
    launch2.setName(launch);
    launch2.setProjectRef(project);
    launch2.setMode(Mode.valueOf(mode));
    launch2.setNumber(2L);
    launch2.setStatus(Status.IN_PROGRESS);
    launchRepository.save(asList(launch1, launch2));
    Optional<Launch> latestLaunch = launchRepository.findLatestLaunch(project, launch, mode);
    Assert.assertTrue(latestLaunch.isPresent());
    Assert.assertEquals(1L, latestLaunch.get().getNumber().longValue());
}
Also used : Launch(com.epam.ta.reportportal.database.entity.Launch) BaseDaoTest(com.epam.ta.reportportal.BaseDaoTest) Test(org.junit.Test)

Example 2 with Launch

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

the class LaunchRepositoryCustomImpl method findLastLaunch.

@Override
public Optional<Launch> findLastLaunch(String projectId, String launchName, String mode) {
    Query query = query(where(PROJECT_ID_REFERENCE).is(projectId)).addCriteria(where(NAME).is(launchName)).addCriteria(where(MODE).is(mode)).limit(1).with(new Sort(Lists.newArrayList(new Sort.Order(DESC, START_TIME), new Sort.Order(DESC, NUMBER))));
    List<Launch> launches = mongoTemplate.find(query, Launch.class);
    return !launches.isEmpty() ? Optional.of(launches.get(0)) : Optional.empty();
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) Sort(org.springframework.data.domain.Sort) Launch(com.epam.ta.reportportal.database.entity.Launch)

Example 3 with Launch

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

the class LaunchRepositoryCustomImpl method findLatestLaunch.

@Override
public Optional<Launch> findLatestLaunch(String projectName, String launchName, String mode) {
    Query query = query(where(PROJECT_ID_REFERENCE).is(projectName)).addCriteria(where(NAME).is(launchName)).addCriteria(where(STATUS).ne(Status.IN_PROGRESS)).addCriteria(where(MODE).is(mode)).limit(1).with(new Sort(DESC, NUMBER));
    List<Launch> launches = mongoTemplate.find(query, Launch.class);
    return !launches.isEmpty() ? Optional.of(launches.get(0)) : Optional.empty();
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) Sort(org.springframework.data.domain.Sort) Launch(com.epam.ta.reportportal.database.entity.Launch)

Example 4 with Launch

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

the class DeleteLaunchesListener method onBeforeDelete.

@Override
public void onBeforeDelete(BeforeDeleteEvent<Launch> event) {
    DBObject dboq = queryMapper.getMappedObject(event.getDBObject(), mappingContext.getPersistentEntity(Launch.class));
    List<String> ids = stream(mongoTemplate.getCollection(event.getCollectionName()).find(dboq).spliterator(), false).map(dbObject -> dbObject.get("_id").toString()).distinct().collect(toList());
    final BasicDBObject itemsQuery = new BasicDBObject("parent", new BasicDBObject("$exists", false));
    itemsQuery.put("launchRef", new BasicDBObject("$in", ids));
    final List<String> itemIds = stream(mongoTemplate.getCollection("testItem").find(itemsQuery).spliterator(), false).map(dbObject -> dbObject.get("_id").toString()).collect(toList());
    testItemRepository.delete(itemIds);
}
Also used : TestItemRepository(com.epam.ta.reportportal.database.dao.TestItemRepository) 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) BeforeDeleteEvent(org.springframework.data.mongodb.core.mapping.event.BeforeDeleteEvent) AbstractMongoEventListener(org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) StreamSupport.stream(java.util.stream.StreamSupport.stream) DBObject(com.mongodb.DBObject) Service(org.springframework.stereotype.Service) Launch(com.epam.ta.reportportal.database.entity.Launch) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) BasicDBObject(com.mongodb.BasicDBObject) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) Launch(com.epam.ta.reportportal.database.entity.Launch)

Example 5 with Launch

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

the class LaunchRepositoryTest method findByProjectIdsData.

public List<Launch> findByProjectIdsData() {
    final Launch launch1 = new Launch();
    launch1.setProjectRef("project1");
    launch1.setName("launch1");
    final Launch launch2 = new Launch();
    launch2.setProjectRef("project2");
    launch2.setName("launch2");
    final Launch launch3 = new Launch();
    launch3.setProjectRef("project2");
    launch3.setName("launch3");
    final Launch launch4 = new Launch();
    return launchRepository.save(asList(launch1, launch2, launch3, launch4));
}
Also used : Launch(com.epam.ta.reportportal.database.entity.Launch)

Aggregations

Launch (com.epam.ta.reportportal.database.entity.Launch)6 Query (org.springframework.data.mongodb.core.query.Query)3 Sort (org.springframework.data.domain.Sort)2 BaseDaoTest (com.epam.ta.reportportal.BaseDaoTest)1 TestItemRepository (com.epam.ta.reportportal.database.dao.TestItemRepository)1 BasicDBObject (com.mongodb.BasicDBObject)1 DBObject (com.mongodb.DBObject)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 StreamSupport.stream (java.util.stream.StreamSupport.stream)1 Test (org.junit.Test)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)1 QueryMapper (org.springframework.data.mongodb.core.convert.QueryMapper)1 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)1 AbstractMongoEventListener (org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener)1 BeforeDeleteEvent (org.springframework.data.mongodb.core.mapping.event.BeforeDeleteEvent)1 Service (org.springframework.stereotype.Service)1