Skip to content

Commit

Permalink
EPMRPP-98940 merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
grabsefx committed Feb 4, 2025
1 parent 2cf9135 commit 777a9fd
Show file tree
Hide file tree
Showing 14 changed files with 543 additions and 128 deletions.
233 changes: 145 additions & 88 deletions src/main/java/com/epam/reportportal/auth/commons/ReportPortalUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,25 @@

import static java.util.Optional.ofNullable;

import com.epam.reportportal.auth.entity.project.ProjectRole;
import com.epam.reportportal.auth.entity.user.UserRole;
import com.epam.reportportal.auth.commons.ReportPortalUser.OrganizationDetails.ProjectDetails;
import com.epam.reportportal.auth.rules.exception.ErrorType;
import com.epam.reportportal.auth.rules.exception.ReportPortalException;
import com.epam.reportportal.auth.entity.organization.OrganizationRole;
import com.epam.reportportal.auth.entity.project.ProjectRole;
import com.epam.reportportal.auth.entity.user.ProjectUser;
import com.epam.reportportal.auth.entity.user.UserRole;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
Expand All @@ -38,33 +47,30 @@
*
* @author <a href="mailto:[email protected]">Andrei Varabyeu</a>
*/
@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
public class ReportPortalUser extends User {

private boolean active;

private Long userId;

private UserRole userRole;

private String email;
private Map<String, OrganizationDetails> organizationDetails;

private Map<String, ProjectDetails> projectDetails;

private ReportPortalUser(String username, String password,
Collection<? extends GrantedAuthority> authorities, Long userId,
UserRole role, Map<String, ProjectDetails> projectDetails, String email, boolean isActive) {
UserRole role, Map<String, OrganizationDetails> organizationDetails, String email, boolean isActive) {
super(username, password, authorities);
this.userId = userId;
this.userRole = role;
this.projectDetails = projectDetails;
this.organizationDetails = organizationDetails;
this.email = email;
this.active = isActive;
}

public static ReportPortalUserBuilder userBuilder() {
return new ReportPortalUserBuilder();
}

@Override
public boolean isEnabled() {
return active;
Expand All @@ -75,100 +81,138 @@ public boolean isAccountNonLocked() {
return active;
}

public Long getUserId() {
return userId;
}

public void setUserId(Long userId) {
this.userId = userId;
}

public UserRole getUserRole() {
return userRole;
}

public void setUserRole(UserRole userRole) {
this.userRole = userRole;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public Map<String, ProjectDetails> getProjectDetails() {
return projectDetails;
public static ReportPortalUserBuilder userBuilder() {
return new ReportPortalUserBuilder();
}

public void setProjectDetails(Map<String, ProjectDetails> projectDetails) {
this.projectDetails = projectDetails;
}

public static class ProjectDetails implements Serializable {
@Getter
@Setter
@AllArgsConstructor
public static class OrganizationDetails implements Serializable {

@JsonProperty(value = "id")
private Long projectId;
private Long orgId;

@JsonProperty(value = "name")
private String projectName;
private String orgName;

@JsonProperty("role")
private ProjectRole projectRole;
private OrganizationRole orgRole;

public ProjectDetails(Long projectId, String projectName, ProjectRole projectRole) {
this.projectId = projectId;
this.projectName = projectName;
this.projectRole = projectRole;
}

public static ProjectDetailsBuilder builder() {
return new ProjectDetailsBuilder();
}
private Map<String, ProjectDetails> projectDetails;

public Long getProjectId() {
return projectId;
public static OrganizationDetailsBuilder builder() {
return new OrganizationDetailsBuilder();
}

public String getProjectName() {
return projectName;
}
public static class OrganizationDetailsBuilder {

public ProjectRole getProjectRole() {
return projectRole;
}
private Long orgId;
private String orgName;
private OrganizationRole orgRole;
private Map<String, ProjectDetails> projectDetails;

public static class ProjectDetailsBuilder {

private Long projectId;
private String projectName;
private ProjectRole projectRole;
private OrganizationDetailsBuilder() {
}

private ProjectDetailsBuilder() {
public OrganizationDetailsBuilder withOrgId(Long orgId) {
this.orgId = orgId;
return this;
}

public ProjectDetailsBuilder withProjectId(Long projectId) {
this.projectId = projectId;
public OrganizationDetailsBuilder withOrgName(String orgName) {
this.orgName = orgName;
return this;
}

public ProjectDetailsBuilder withProjectName(String projectName) {
this.projectName = projectName;
public OrganizationDetailsBuilder withOrganizationRole(String orgRole) {
this.orgRole = OrganizationRole.forName(orgRole)
.orElseThrow(() -> new ReportPortalException(ErrorType.ROLE_NOT_FOUND, orgRole));
return this;
}

public ProjectDetailsBuilder withProjectRole(String projectRole) {
this.projectRole = ProjectRole.forName(projectRole)
.orElseThrow(() -> new ReportPortalException(ErrorType.ROLE_NOT_FOUND, projectRole));
public OrganizationDetailsBuilder withProjectDetails(Map<String, ProjectDetails> projectDetails) {
this.projectDetails = projectDetails;
return this;
}

public ProjectDetails build() {
return new ProjectDetails(projectId, projectName, projectRole);
public OrganizationDetails build() {
return new OrganizationDetails(orgId, orgName, orgRole, projectDetails);
}
}

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class ProjectDetails implements Serializable {

@JsonProperty(value = "id")
private Long projectId;

@JsonProperty(value = "name")
private String projectName;

@JsonProperty(value = "key")
private String projectKey;

@JsonProperty("role")
private ProjectRole projectRole;

@JsonProperty("organization_id")
private Long organizationId;


public static ProjectDetailsBuilder builder() {
return new ProjectDetailsBuilder();
}

public static class ProjectDetailsBuilder {

private Long projectId;
private String projectName;
private String projectKey;
private ProjectRole projectRole;
private Long organizationId;

private ProjectDetailsBuilder() {
}

public ProjectDetailsBuilder withProjectId(Long projectId) {
this.projectId = projectId;
return this;
}

public ProjectDetailsBuilder withProjectName(String projectName) {
this.projectName = projectName;
return this;
}

public ProjectDetailsBuilder withProjectKey(String projectKey) {
this.projectKey = projectKey;
return this;
}

public ProjectDetailsBuilder withOrgId(Long orgId) {
this.organizationId = orgId;
return this;
}

public ProjectDetailsBuilder withProjectRole(String projectRole) {
this.projectRole = ProjectRole.forName(projectRole)
.orElseThrow(() -> new ReportPortalException(ErrorType.ROLE_NOT_FOUND, projectRole));
return this;
}

public ProjectDetails build() {
return new ProjectDetails(projectId, projectName, projectKey, projectRole, organizationId);
}
}
}

}

public static class ReportPortalUserBuilder {
Expand All @@ -179,11 +223,10 @@ public static class ReportPortalUserBuilder {
private Long userId;
private UserRole userRole;
private String email;
private Map<String, ProjectDetails> projectDetails;
private Map<String, OrganizationDetails> organizationDetails;
private Collection<? extends GrantedAuthority> authorities;

private ReportPortalUserBuilder() {

}

public ReportPortalUserBuilder withActive(boolean active) {
Expand Down Expand Up @@ -230,8 +273,8 @@ public ReportPortalUserBuilder withEmail(String email) {
return this;
}

public ReportPortalUserBuilder withProjectDetails(Map<String, ProjectDetails> projectDetails) {
this.projectDetails = projectDetails;
public ReportPortalUserBuilder withOrganizationDetails(Map<String, OrganizationDetails> organizationDetails) {
this.organizationDetails = organizationDetails;
return this;
}

Expand All @@ -244,20 +287,34 @@ public ReportPortalUser fromUser(com.epam.reportportal.auth.entity.user.User use
this.password = ofNullable(user.getPassword()).orElse("");
this.authorities = Collections.singletonList(
new SimpleGrantedAuthority(user.getRole().getAuthority()));
this.projectDetails = user.getProjects().stream().collect(Collectors.toMap(
it -> it.getProject().getName(),
it -> ProjectDetails.builder()
.withProjectId(it.getProject().getId())
.withProjectRole(it.getProjectRole().name())
.withProjectName(it.getProject().getName())
.build()
));
this.organizationDetails = user.getOrganizationUsers()
.stream()
.collect(Collectors.toMap(it -> it.getOrganization().getName(),
it -> OrganizationDetails.builder()
.withOrgId(it.getOrganization().getId())
.withOrganizationRole(it.getOrganizationRole().name())
.withProjectDetails(mapProjectDetails(user.getProjects(), it.getOrganization().getId()))
.withOrgName(it.getOrganization().getName())
.build()
));
return build();
}

private Map<String, ProjectDetails> mapProjectDetails (Set<ProjectUser> projects, Long orgId) {
return projects.stream()
.filter(projectUser -> projectUser.getProject().getOrganizationId().equals(orgId))
.collect(Collectors.toMap(projectUser -> projectUser.getProject().getKey(),
projectUser -> ProjectDetails.builder()
.withProjectId(projectUser.getProject().getId())
.withProjectRole(projectUser.getProjectRole().name())
.withProjectKey(projectUser.getProject().getKey())
.build())
);
}

public ReportPortalUser build() {
return new ReportPortalUser(username, password, authorities, userId, userRole, projectDetails,
email, active);
return new ReportPortalUser(username, password, authorities, userId, userRole,
organizationDetails, email, active);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 EPAM Systems
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,19 +20,19 @@
import java.util.Optional;

/**
* Project Type enumeration<br> Used for supporting different project types processing
* Project Type enumeration<br> Used for supporting different organization types processing.
*
* @author Andrei_Ramanchuk
* @author <a href="mailto:[email protected]">Andrei Varabyeu</a>
* @author Siarhei Hrabko
*/
public enum ProjectType {
public enum OrganizationType {

PERSONAL,
INTERNAL,
UPSA;
EXTERNAL;

public static Optional<ProjectType> findByName(String name) {
return Arrays.stream(ProjectType.values()).filter(type -> type.name().equalsIgnoreCase(name))
public static Optional<OrganizationType> findByName(String name) {
return Arrays.stream(OrganizationType.values())
.filter(type -> type.name().equalsIgnoreCase(name))
.findAny();
}

Expand Down
Loading

0 comments on commit 777a9fd

Please sign in to comment.