Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPMRPP-89699 implement OrganizationInfo endpoint #1942

Merged
merged 5 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ dependencies {
implementation 'com.epam.reportportal:plugin-api'
} else {
implementation 'com.github.reportportal:commons-events:e337f8b7be'
implementation 'com.github.reportportal:commons-dao:f6c9669'
implementation 'com.github.reportportal:commons-dao:65eb641'
implementation 'com.github.reportportal:commons-rules:1f6bfed'
implementation 'com.github.reportportal:commons-model:38a52fb'
implementation 'com.github.reportportal:commons-reporting:5c74bb2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

import com.epam.ta.reportportal.commons.ReportPortalUser;
import com.epam.ta.reportportal.commons.querygen.Queryable;
import com.epam.ta.reportportal.model.OrganizationResource;
import com.epam.ta.reportportal.model.organization.OrganizationInfoResource;
import com.epam.ta.reportportal.model.organization.OrganizationResource;
import org.springframework.data.domain.Pageable;

/**
Expand All @@ -44,4 +45,15 @@ public interface GetOrganizationHandler {
* projects
*/
Iterable<OrganizationResource> getOrganizations(Queryable filter, Pageable pageable);

/**
grabsefx marked this conversation as resolved.
Show resolved Hide resolved
* Get Organizations aggregated info by query parameters
*
* @param filter Queryable filter to apply on organizations
* @param pageable Pagination information for the results
* @return An {@link Iterable} of {@link OrganizationInfoResource} containing information about
* all projects
grabsefx marked this conversation as resolved.
Show resolved Hide resolved
*/
Iterable<OrganizationInfoResource> getOrganizationsInfo(Queryable filter, Pageable pageable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import com.epam.ta.reportportal.dao.organization.OrganizationRepositoryCustom;
import com.epam.ta.reportportal.entity.organization.Organization;
import com.epam.ta.reportportal.exception.ReportPortalException;
import com.epam.ta.reportportal.model.OrganizationResource;
import com.epam.ta.reportportal.model.organization.OrganizationInfoResource;
import com.epam.ta.reportportal.model.organization.OrganizationResource;
import com.epam.ta.reportportal.ws.converter.PagedResourcesAssembler;
import com.epam.ta.reportportal.ws.converter.converters.OrganizationConverter;
import com.epam.ta.reportportal.ws.reporting.ErrorType;
Expand Down Expand Up @@ -58,4 +59,11 @@ public Iterable<OrganizationResource> getOrganizations(Queryable filter, Pageabl
.apply(organizationRepositoryCustom.findByFilter(filter, pageable));
}

@Override
public Iterable<OrganizationInfoResource> getOrganizationsInfo(Queryable filter,
Pageable pageable) {
return PagedResourcesAssembler.pageConverter(OrganizationConverter.TO_ORGANIZATION_INFO_RESOURCE)
grabsefx marked this conversation as resolved.
Show resolved Hide resolved
.apply(organizationRepositoryCustom.findOrganizationInfoByFilter(filter, pageable));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.epam.ta.reportportal.model.organization;

/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


import com.epam.ta.reportportal.entity.enums.OrganizationType;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.LocalDateTime;
import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
* Basic JSON representation of Organization.
*
* @author Andrei Piankouski
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@Getter
@Setter
@ToString
public class OrganizationInfoResource {

@NotNull
@JsonProperty(value = "id", required = true)
private Long id;

@NotNull
@JsonProperty(value = "name", required = true)
private String name;

@NotNull
@JsonProperty(value = "slug", required = true)
private String slug;

@NotNull
@JsonProperty(value = "type", required = true)
private OrganizationType type;

@NotNull
@JsonProperty(value = "creationDate", required = true)
private LocalDateTime creationDate;

@JsonProperty(value = "usersQuantity", required = true)
private int usersQuantity;

@JsonProperty(value = "projectsQuantity", required = true)
private int projectsQuantity;

@JsonProperty(value = "launchesQuantity", required = true)
private int launchesQuantity;

@JsonProperty(value = "lastRun", required = true)
private LocalDateTime lastRun;

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.epam.ta.reportportal.model;
package com.epam.ta.reportportal.model.organization;

/*
* Copyright 2024 EPAM Systems
Expand All @@ -20,7 +20,7 @@
import com.epam.ta.reportportal.entity.enums.OrganizationType;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Date;
import java.time.LocalDateTime;
import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -55,6 +55,6 @@ public class OrganizationResource {

@NotNull
@JsonProperty(value = "creationDate", required = true)
private Date creationDate;
private LocalDateTime creationDate;

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@

package com.epam.ta.reportportal.ws.controller;

import static com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants.USER;

import com.epam.ta.reportportal.commons.ReportPortalUser;
import com.epam.ta.reportportal.commons.querygen.CompositeFilter;
import com.epam.ta.reportportal.commons.querygen.Condition;
import com.epam.ta.reportportal.commons.querygen.Filter;
import com.epam.ta.reportportal.commons.querygen.FilterCondition;
import com.epam.ta.reportportal.commons.querygen.Queryable;
import com.epam.ta.reportportal.core.organization.GetOrganizationHandler;
import com.epam.ta.reportportal.entity.organization.Organization;
import com.epam.ta.reportportal.model.OrganizationResource;
import com.epam.ta.reportportal.entity.organization.OrganizationInfo;
import com.epam.ta.reportportal.entity.user.UserRole;
import com.epam.ta.reportportal.model.organization.OrganizationResource;
import com.epam.ta.reportportal.model.organization.OrganizationInfoResource;
grabsefx marked this conversation as resolved.
Show resolved Hide resolved
import com.epam.ta.reportportal.ws.resolver.FilterFor;
import com.epam.ta.reportportal.ws.resolver.SortFor;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -41,7 +48,7 @@
* @author Andrei Piankouski
*/
@RestController
@RequestMapping("/v1/organization")
@RequestMapping("/v1")
@Tag(name = "organizations-controller", description = "Organizations Controller")
public class OrganizationController {

Expand All @@ -53,24 +60,50 @@ public OrganizationController(GetOrganizationHandler getOrganizationHandler) {
}

@Transactional
@GetMapping("/{organizationId}")
@GetMapping("/organizations/{organizationId}")
@Operation(summary = "Get information about organization")
public OrganizationResource getOrganization(@PathVariable Long organizationId,
@AuthenticationPrincipal ReportPortalUser user) {
return getOrganizationHandler.getResource(organizationId, user);
}

@Transactional
@GetMapping("/list")
@GetMapping("/organizations")
@Operation(summary = "Get list of all organizations")
public Iterable<OrganizationResource> getAllOrganizations(
@AuthenticationPrincipal ReportPortalUser user,
@FilterFor(Organization.class) Filter filter,
@FilterFor(Organization.class) Queryable predefinedFilter,
@SortFor(Organization.class) Pageable pageable
) {
@SortFor(Organization.class) Pageable pageable) {

modifyFilterWithUserCriteria(filter, user);

return getOrganizationHandler.getOrganizations(
new CompositeFilter(Operator.AND, filter, predefinedFilter),
pageable);
}


@Transactional
grabsefx marked this conversation as resolved.
Show resolved Hide resolved
@GetMapping("/organizations-info")
@Operation(summary = "Get list of all organizations")
public Iterable<OrganizationInfoResource> getOrganizationsInfo(
@AuthenticationPrincipal ReportPortalUser user,
@FilterFor(OrganizationInfo.class) Filter filter,
@FilterFor(OrganizationInfo.class) Queryable predefinedFilter,
@SortFor(OrganizationInfo.class) Pageable pageable) {

modifyFilterWithUserCriteria(filter, user);

return getOrganizationHandler.getOrganizationsInfo(
new CompositeFilter(Operator.AND, filter, predefinedFilter),
pageable);
}

private void modifyFilterWithUserCriteria(Filter filter, ReportPortalUser user) {
if (UserRole.ADMINISTRATOR != user.getUserRole()) {
filter.withCondition(
new FilterCondition(Condition.EQUALS,false, user.getUsername(), USER));
grabsefx marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package com.epam.ta.reportportal.ws.converter.converters;

import static com.epam.ta.reportportal.commons.EntityUtils.TO_DATE;

import com.epam.ta.reportportal.entity.organization.Organization;
import com.epam.ta.reportportal.model.OrganizationResource;
import com.epam.ta.reportportal.entity.organization.OrganizationInfo;
import com.epam.ta.reportportal.model.organization.OrganizationInfoResource;
import com.epam.ta.reportportal.model.organization.OrganizationResource;
import java.util.function.Function;

/**
Expand All @@ -39,8 +39,24 @@ private OrganizationConverter() {
orgResource.setName(org.getName());
orgResource.setSlug(org.getSlug());
orgResource.setType(org.getOrganizationType());
orgResource.setCreationDate(TO_DATE.apply(org.getCreationDate()));
orgResource.setCreationDate(org.getCreationDate());

return orgResource;
};

public static final Function<OrganizationInfo, OrganizationInfoResource> TO_ORGANIZATION_INFO_RESOURCE =
grabsefx marked this conversation as resolved.
Show resolved Hide resolved
org -> {
OrganizationInfoResource orgInfoResource = new OrganizationInfoResource();
orgInfoResource.setId(org.getId());
orgInfoResource.setName(org.getName());
orgInfoResource.setSlug(org.getSlug());
orgInfoResource.setType(org.getOrganizationType());
orgInfoResource.setCreationDate(org.getCreationDate());
orgInfoResource.setLastRun(org.getLastRun());
orgInfoResource.setLaunchesQuantity(org.getLaunchesQuantity());
orgInfoResource.setProjectsQuantity(org.getProjectsQuantity());
orgInfoResource.setUsersQuantity(org.getUsersQuantity());

return orgInfoResource;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,22 @@ class OrganizationControllerTest extends BaseMvcTest {

@Test
void getOrganization() throws Exception {
mockMvc.perform(get("/v1/organization/1").with(token(oAuthHelper.getSuperadminToken())))
mockMvc.perform(get("/v1/organizations/1")
.with(token(oAuthHelper.getSuperadminToken())))
.andExpect(status().isOk());
}

@Test
void getAllOrganizations() throws Exception {
mockMvc.perform(get("/v1/organization/list").with(token(oAuthHelper.getSuperadminToken())))
mockMvc.perform(get("/v1/organizations")
.with(token(oAuthHelper.getSuperadminToken())))
.andExpect(status().isOk());
}

@Test
void getAllOrganizationsInfo() throws Exception {
mockMvc.perform(get("/v1/organizations-info")
.with(token(oAuthHelper.getSuperadminToken())))
.andExpect(status().isOk());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import com.epam.ta.reportportal.entity.enums.OrganizationType;
import com.epam.ta.reportportal.entity.organization.Organization;
import com.epam.ta.reportportal.model.OrganizationResource;
import com.epam.ta.reportportal.model.organization.OrganizationResource;
import java.time.LocalDateTime;
import org.junit.jupiter.api.Test;

Expand Down
Loading