-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EPMRPP-92350 fix organization projects for member (#2017)
- Loading branch information
Showing
8 changed files
with
117 additions
and
51 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
Submodule reportportal-common-api
updated
2 files
+0 −58 | api/openapi/models/project/ProjectRelation.yaml | |
+58 −6 | api/openapi/models/project/ProjectRelationships.yaml |
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
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
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
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
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
39 changes: 39 additions & 0 deletions
39
src/main/java/com/epam/ta/reportportal/util/OffsetUtils.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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.epam.ta.reportportal.util; | ||
|
||
import com.epam.reportportal.api.model.Offset; | ||
import com.epam.reportportal.api.model.Offset.OrderEnum; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort.Direction; | ||
import org.springframework.data.domain.Sort.Order; | ||
|
||
public class OffsetUtils { | ||
|
||
private OffsetUtils() { | ||
} | ||
|
||
public static <T extends Offset> T responseWithPageParameters(T offsetObject, Pageable pageable, | ||
long totalElements) { | ||
return (T) offsetObject | ||
.offset((int) pageable.getOffset()) | ||
.limit(pageable.getPageSize()) | ||
.totalCount((int) totalElements) | ||
.sort(getSortFields(pageable)) | ||
.order(getOrderEnum(pageable)); | ||
} | ||
|
||
private static String getSortFields(Pageable pageable) { | ||
return pageable.getSort().stream() | ||
.map(Order::getProperty) | ||
.reduce((s1, s2) -> s1 + ", " + s2) | ||
.orElse(""); | ||
} | ||
|
||
private static OrderEnum getOrderEnum(Pageable pageable) { | ||
return pageable.getSort().stream() | ||
.map(Order::getDirection) | ||
.findFirst() | ||
.map(direction -> direction.equals(Direction.ASC) ? OrderEnum.ASC : OrderEnum.DESC) | ||
.orElse(OrderEnum.ASC); | ||
} | ||
|
||
} |