Search in sources :

Example 1 with Project

use of com.epam.ta.reportportal.database.entity.Project 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 2 with Project

use of com.epam.ta.reportportal.database.entity.Project 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 3 with Project

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

the class ProjectRepositoryCustomImpl method clearExternalSystems.

@Override
public synchronized void clearExternalSystems(String projectId) {
    Project first = mongoTemplate.findOne(projectById(projectId), Project.class);
    first.getConfiguration().setExternalSystem(Collections.emptyList());
    mongoTemplate.save(first);
}
Also used : Project(com.epam.ta.reportportal.database.entity.Project)

Example 4 with Project

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

the class PersonalProjectService method generatePersonalProject.

/**
 * Generates personal project for provided user
 *
 * @param user User project should be created for
 * @return Built Project object
 */
public Project generatePersonalProject(User user) {
    Project project = new Project();
    project.setName(generatePersonalProjectName(user.getLogin()));
    project.setCreationDate(Date.from(ZonedDateTime.now().toInstant()));
    Project.UserConfig userConfig = new Project.UserConfig();
    userConfig.setLogin(user.getId());
    userConfig.setProjectRole(ProjectRole.PROJECT_MANAGER);
    userConfig.setProposedRole(ProjectRole.PROJECT_MANAGER);
    project.setUsers(ImmutableList.<Project.UserConfig>builder().add(userConfig).build());
    project.setAddInfo("Personal project of " + (isNullOrEmpty(user.getFullName()) ? user.getLogin() : user.getFullName()));
    project.setConfiguration(defaultConfiguration());
    /* Default email configuration */
    ProjectUtils.setDefaultEmailCofiguration(project);
    return project;
}
Also used : Project(com.epam.ta.reportportal.database.entity.Project)

Example 5 with Project

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

the class CascadeDeleteUserTrigger method clearProject.

/**
 * Remove user references from projects for which user was assigned
 *
 * @param id
 */
private void clearProject(String id) {
    List<Project> projects = projectRepository.findUserProjects(id);
    for (Project project : projects) {
        project.getUsers().removeIf(it -> id.equals(it.getLogin()));
    }
    projectRepository.save(projects);
}
Also used : Project(com.epam.ta.reportportal.database.entity.Project)

Aggregations

Project (com.epam.ta.reportportal.database.entity.Project)13 Query (org.springframework.data.mongodb.core.query.Query)4 Test (org.junit.Test)3 EmailSenderCase (com.epam.ta.reportportal.database.entity.project.email.EmailSenderCase)2 BaseDaoTest (com.epam.ta.reportportal.BaseDaoTest)1 UserConfig (com.epam.ta.reportportal.database.entity.Project.UserConfig)1 ProjectRole (com.epam.ta.reportportal.database.entity.ProjectRole)1 EntryType (com.epam.ta.reportportal.database.entity.project.EntryType)1 ProjectEmailConfig (com.epam.ta.reportportal.database.entity.project.email.ProjectEmailConfig)1 User (com.epam.ta.reportportal.database.entity.user.User)1 PERSONAL_PROJECT_POSTFIX (com.epam.ta.reportportal.database.personal.PersonalProjectService.PERSONAL_PROJECT_POSTFIX)1 BasicDBObject (com.mongodb.BasicDBObject)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)1