Search in sources :

Example 16 with Query

use of org.springframework.data.mongodb.core.query.Query in project commons-dao by reportportal.

the class ProjectRepositoryCustomImpl method findPersonalProjectName.

@Override
public Optional<String> findPersonalProjectName(String user) {
    Query query = Query.query(userExists(user)).addCriteria(Criteria.where(PROJECT_TYPE).is(EntryType.PERSONAL)).addCriteria(Criteria.where(PROJECT_ID).regex("^" + user + PERSONAL_PROJECT_POSTFIX));
    query.fields().include("name");
    return Optional.ofNullable(mongoTemplate.findOne(query, Project.class)).map(Project::getName);
}
Also used : Project(com.epam.ta.reportportal.database.entity.Project) Query(org.springframework.data.mongodb.core.query.Query)

Example 17 with Query

use of org.springframework.data.mongodb.core.query.Query in project commons-dao by reportportal.

the class ProjectRepositoryCustomImpl method removeUserFromProjects.

@Override
public void removeUserFromProjects(String userId) {
    Query query = Query.query(Criteria.where(USER_LOGIN).is(userId));
    mongoTemplate.updateMulti(query, new Update().pull("users", new BasicDBObject("login", userId)), Project.class);
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) Query(org.springframework.data.mongodb.core.query.Query) Update(org.springframework.data.mongodb.core.query.Update)

Example 18 with Query

use of org.springframework.data.mongodb.core.query.Query in project commons-dao by reportportal.

the class ProjectRepositoryCustomImpl method findProjectRoles.

@Override
public Map<String, ProjectRole> findProjectRoles(String login) {
    final Query q = Query.query(userExists(login));
    q.fields().include("users");
    return mongoTemplate.find(q, Project.class).stream().collect(Collectors.toMap(Project::getName, p -> p.getUsers().stream().filter(it -> login.equals(it.getLogin())).findFirst().get().getProjectRole()));
}
Also used : UserConfig(com.epam.ta.reportportal.database.entity.Project.UserConfig) Predicate(java.util.function.Predicate) BasicDBObject(com.mongodb.BasicDBObject) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) Criteria(org.springframework.data.mongodb.core.query.Criteria) Query(org.springframework.data.mongodb.core.query.Query) PERSONAL_PROJECT_POSTFIX(com.epam.ta.reportportal.database.personal.PersonalProjectService.PERSONAL_PROJECT_POSTFIX) List(java.util.List) ProjectRole(com.epam.ta.reportportal.database.entity.ProjectRole) EntryType(com.epam.ta.reportportal.database.entity.project.EntryType) Map(java.util.Map) Update(org.springframework.data.mongodb.core.query.Update) Optional(java.util.Optional) Project(com.epam.ta.reportportal.database.entity.Project) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Collections(java.util.Collections) Query(org.springframework.data.mongodb.core.query.Query)

Example 19 with Query

use of org.springframework.data.mongodb.core.query.Query in project commons-dao by reportportal.

the class ReportPortalRepositoryImpl method findByFilter.

@Override
public List<T> findByFilter(Queryable filter) {
    Class<T> entityType = getEntityInformation().getJavaType();
    Query query = QueryBuilder.newBuilder().with(filter).build();
    return getMongoOperations().find(query, entityType);
}
Also used : Query(org.springframework.data.mongodb.core.query.Query)

Example 20 with Query

use of org.springframework.data.mongodb.core.query.Query in project commons-dao by reportportal.

the class ReportPortalRepositoryImpl method findByIds.

@Override
public List<T> findByIds(Collection<ID> ids, List<String> fieldsToLoad) {
    Class<T> entityType = getEntityInformation().getJavaType();
    String idField = getEntityInformation().getIdAttribute();
    Query query = query(where(idField).in(ids));
    fieldsToLoad.forEach(field -> query.fields().include(field));
    return getMongoOperations().find(query, entityType);
}
Also used : Query(org.springframework.data.mongodb.core.query.Query)

Aggregations

Query (org.springframework.data.mongodb.core.query.Query)488 Test (org.junit.Test)312 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)156 Update (org.springframework.data.mongodb.core.query.Update)79 NearQuery (org.springframework.data.mongodb.core.query.NearQuery)66 Document (org.bson.Document)56 Criteria (org.springframework.data.mongodb.core.query.Criteria)47 PartTree (org.springframework.data.repository.query.parser.PartTree)44 Sort (org.springframework.data.domain.Sort)30 ObjectId (org.bson.types.ObjectId)27 BasicDBObject (com.mongodb.BasicDBObject)22 DBObject (com.mongodb.DBObject)20 Before (org.junit.Before)18 List (java.util.List)17 Autowired (org.springframework.beans.factory.annotation.Autowired)17 GeoJsonPoint (org.springframework.data.mongodb.core.geo.GeoJsonPoint)17 Collectors (java.util.stream.Collectors)16 ArrayList (java.util.ArrayList)15 OptimisticLockingFailureException (org.springframework.dao.OptimisticLockingFailureException)15 MappingException (org.springframework.data.mapping.MappingException)15