-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from reportportal/EPMRPP-89744-update-plugin-api
EPMRPP-89744 || Update plugin api
- Loading branch information
Showing
38 changed files
with
1,170 additions
and
1,237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,357 changes: 680 additions & 677 deletions
1,357
src/main/java/com/epam/reportportal/extension/azure/AzureExtension.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 15 additions & 13 deletions
28
src/main/java/com/epam/reportportal/extension/azure/command/role/ProjectManagerCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,32 @@ | ||
package com.epam.reportportal.extension.azure.command.role; | ||
|
||
import static java.util.Optional.ofNullable; | ||
|
||
import com.epam.ta.reportportal.commons.ReportPortalUser; | ||
import com.epam.ta.reportportal.commons.validation.BusinessRule; | ||
import com.epam.ta.reportportal.dao.ProjectRepository; | ||
import com.epam.ta.reportportal.entity.project.Project; | ||
import com.epam.ta.reportportal.entity.project.ProjectRole; | ||
import com.epam.ta.reportportal.exception.ReportPortalException; | ||
import com.epam.ta.reportportal.ws.model.ErrorType; | ||
|
||
import static java.util.Optional.ofNullable; | ||
import com.epam.ta.reportportal.ws.reporting.ErrorType; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Ivan Budayeu</a> | ||
*/ | ||
public abstract class ProjectManagerCommand<T> extends ProjectMemberCommand<T> { | ||
|
||
protected ProjectManagerCommand(ProjectRepository projectRepository) { | ||
super(projectRepository); | ||
} | ||
protected ProjectManagerCommand(ProjectRepository projectRepository) { | ||
super(projectRepository); | ||
} | ||
|
||
@Override | ||
protected void validatePermissions(ReportPortalUser user, Project project) { | ||
ProjectRole projectRole = ofNullable(user.getProjectDetails()).flatMap(detailsMapping -> ofNullable(detailsMapping.get(project.getName()))) | ||
.map(ReportPortalUser.ProjectDetails::getProjectRole) | ||
.orElseThrow(() -> new ReportPortalException(ErrorType.ACCESS_DENIED)); | ||
@Override | ||
protected void validatePermissions(ReportPortalUser user, Project project) { | ||
ProjectRole projectRole = ofNullable(user.getProjectDetails()).flatMap( | ||
detailsMapping -> ofNullable(detailsMapping.get(project.getName()))) | ||
.map(ReportPortalUser.ProjectDetails::getProjectRole) | ||
.orElseThrow(() -> new ReportPortalException(ErrorType.ACCESS_DENIED)); | ||
|
||
BusinessRule.expect(projectRole, ProjectRole.PROJECT_MANAGER::sameOrLowerThan).verify(ErrorType.ACCESS_DENIED); | ||
} | ||
BusinessRule.expect(projectRole, ProjectRole.PROJECT_MANAGER::sameOrLowerThan) | ||
.verify(ErrorType.ACCESS_DENIED); | ||
} | ||
} |
52 changes: 27 additions & 25 deletions
52
src/main/java/com/epam/reportportal/extension/azure/command/role/ProjectMemberCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,49 @@ | ||
package com.epam.reportportal.extension.azure.command.role; | ||
|
||
import static com.epam.reportportal.extension.azure.command.utils.CommandParamUtils.PROJECT_ID_PARAM; | ||
import static com.epam.reportportal.extension.azure.command.utils.CommandParamUtils.retrieveLong; | ||
import static java.util.Optional.ofNullable; | ||
|
||
import com.epam.ta.reportportal.commons.ReportPortalUser; | ||
import com.epam.ta.reportportal.commons.validation.BusinessRule; | ||
import com.epam.ta.reportportal.dao.ProjectRepository; | ||
import com.epam.ta.reportportal.entity.project.Project; | ||
import com.epam.ta.reportportal.exception.ReportPortalException; | ||
import com.epam.ta.reportportal.ws.model.ErrorType; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
|
||
import com.epam.ta.reportportal.ws.reporting.ErrorType; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import static com.epam.reportportal.extension.azure.command.utils.CommandParamUtils.PROJECT_ID_PARAM; | ||
import static com.epam.reportportal.extension.azure.command.utils.CommandParamUtils.retrieveLong; | ||
import static java.util.Optional.ofNullable; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Ivan Budayeu</a> | ||
*/ | ||
public abstract class ProjectMemberCommand<T> extends AbstractRoleBasedCommand<T> { | ||
|
||
protected final ProjectRepository projectRepository; | ||
protected final ProjectRepository projectRepository; | ||
|
||
protected ProjectMemberCommand(ProjectRepository projectRepository) { | ||
this.projectRepository = projectRepository; | ||
} | ||
protected ProjectMemberCommand(ProjectRepository projectRepository) { | ||
this.projectRepository = projectRepository; | ||
} | ||
|
||
@Override | ||
public void validateRole(Map<String, Object> params) { | ||
Long projectId = retrieveLong(params, PROJECT_ID_PARAM); | ||
Project project = projectRepository.findById(projectId) | ||
.orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectId)); | ||
@Override | ||
public void validateRole(Map<String, Object> params) { | ||
Long projectId = retrieveLong(params, PROJECT_ID_PARAM); | ||
Project project = projectRepository.findById(projectId) | ||
.orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectId)); | ||
|
||
ReportPortalUser user = (ReportPortalUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); | ||
BusinessRule.expect(user, Objects::nonNull).verify(ErrorType.ACCESS_DENIED); | ||
ReportPortalUser user = | ||
(ReportPortalUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); | ||
BusinessRule.expect(user, Objects::nonNull).verify(ErrorType.ACCESS_DENIED); | ||
|
||
validatePermissions(user, project); | ||
} | ||
validatePermissions(user, project); | ||
} | ||
|
||
protected void validatePermissions(ReportPortalUser user, Project project) { | ||
BusinessRule.expect(ofNullable(user.getProjectDetails()).flatMap(detailsMapping -> ofNullable(detailsMapping.get(project.getName()))), | ||
Optional::isPresent | ||
).verify(ErrorType.ACCESS_DENIED); | ||
} | ||
protected void validatePermissions(ReportPortalUser user, Project project) { | ||
BusinessRule.expect( | ||
ofNullable(user.getProjectDetails()).flatMap( | ||
detailsMapping -> ofNullable(detailsMapping.get(project.getName()))), | ||
Optional::isPresent | ||
).verify(ErrorType.ACCESS_DENIED); | ||
} | ||
} |
91 changes: 45 additions & 46 deletions
91
src/main/java/com/epam/reportportal/extension/azure/command/utils/CommandParamUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,59 @@ | ||
package com.epam.reportportal.extension.azure.command.utils; | ||
|
||
import static java.util.Optional.ofNullable; | ||
|
||
import com.epam.ta.reportportal.commons.validation.Suppliers; | ||
import com.epam.ta.reportportal.exception.ReportPortalException; | ||
import com.epam.ta.reportportal.ws.model.ErrorType; | ||
|
||
import javax.validation.ConstraintViolation; | ||
import javax.validation.Path; | ||
import com.epam.ta.reportportal.ws.reporting.ErrorType; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import static java.util.Optional.ofNullable; | ||
import javax.validation.ConstraintViolation; | ||
import javax.validation.Path; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Ivan Budayeu</a> | ||
*/ | ||
public final class CommandParamUtils { | ||
|
||
public static final String ID_PARAM = "id"; | ||
public static final String PROJECT_ID_PARAM = "projectId"; | ||
public static final String ENTITY_PARAM = "entity"; | ||
public static final String URL_PARAM = "url"; | ||
|
||
private CommandParamUtils() { | ||
//static only | ||
} | ||
|
||
public static Long retrieveLong(Map<String, Object> params, String param) { | ||
return ofNullable(params.get(param)).map(String::valueOf) | ||
.map(CommandParamUtils::safeParseLong) | ||
.orElseThrow(() -> new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, | ||
Suppliers.formattedSupplier("Parameter '{}' was not provided", param).get() | ||
)); | ||
} | ||
|
||
public static Long safeParseLong(String param) { | ||
try { | ||
return Long.parseLong(param); | ||
} catch (NumberFormatException ex) { | ||
throw new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, ex.getMessage()); | ||
} | ||
} | ||
|
||
public static void handleValidatorConstraints(Set<ConstraintViolation<?>> constraintViolations) { | ||
if (constraintViolations != null && !constraintViolations.isEmpty()) { | ||
StringBuilder messageBuilder = new StringBuilder(); | ||
for (ConstraintViolation<?> constraintViolation : constraintViolations) { | ||
messageBuilder.append("["); | ||
messageBuilder.append("Incorrect value in request '"); | ||
messageBuilder.append(constraintViolation.getInvalidValue()); | ||
messageBuilder.append("' in field '"); | ||
Iterator<Path.Node> iterator = constraintViolation.getPropertyPath().iterator(); | ||
messageBuilder.append(iterator.hasNext() ? iterator.next().getName() : ""); | ||
messageBuilder.append("'.]"); | ||
} | ||
throw new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, messageBuilder.toString()); | ||
} | ||
} | ||
public static final String ID_PARAM = "id"; | ||
public static final String PROJECT_ID_PARAM = "projectId"; | ||
public static final String ENTITY_PARAM = "entity"; | ||
public static final String URL_PARAM = "url"; | ||
|
||
private CommandParamUtils() { | ||
//static only | ||
} | ||
|
||
public static Long retrieveLong(Map<String, Object> params, String param) { | ||
return ofNullable(params.get(param)).map(String::valueOf).map(CommandParamUtils::safeParseLong) | ||
.orElseThrow(() -> new ReportPortalException( | ||
ErrorType.BAD_REQUEST_ERROR, | ||
Suppliers.formattedSupplier("Parameter '{}' was not provided", param).get() | ||
)); | ||
} | ||
|
||
public static Long safeParseLong(String param) { | ||
try { | ||
return Long.parseLong(param); | ||
} catch (NumberFormatException ex) { | ||
throw new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, ex.getMessage()); | ||
} | ||
} | ||
|
||
public static void handleValidatorConstraints(Set<ConstraintViolation<?>> constraintViolations) { | ||
if (constraintViolations != null && !constraintViolations.isEmpty()) { | ||
StringBuilder messageBuilder = new StringBuilder(); | ||
for (ConstraintViolation<?> constraintViolation : constraintViolations) { | ||
messageBuilder.append("["); | ||
messageBuilder.append("Incorrect value in request '"); | ||
messageBuilder.append(constraintViolation.getInvalidValue()); | ||
messageBuilder.append("' in field '"); | ||
Iterator<Path.Node> iterator = constraintViolation.getPropertyPath().iterator(); | ||
messageBuilder.append(iterator.hasNext() ? iterator.next().getName() : ""); | ||
messageBuilder.append("'.]"); | ||
} | ||
throw new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, messageBuilder.toString()); | ||
} | ||
} | ||
} |
Oops, something went wrong.