From c8007931d9c71e347d77d71a2660cb9b31ea4db5 Mon Sep 17 00:00:00 2001 From: Andrei Piankouski Date: Mon, 5 Feb 2024 13:21:22 +0300 Subject: [PATCH] Return models --- .../epam/ta/reportportal/ws/model/Page.java | 139 ++++++++++++++++++ .../launch/cluster/CreateClustersRQ.java | 55 +++++++ 2 files changed, 194 insertions(+) create mode 100644 src/main/java/com/epam/ta/reportportal/ws/model/Page.java create mode 100644 src/main/java/com/epam/ta/reportportal/ws/model/launch/cluster/CreateClustersRQ.java diff --git a/src/main/java/com/epam/ta/reportportal/ws/model/Page.java b/src/main/java/com/epam/ta/reportportal/ws/model/Page.java new file mode 100644 index 00000000..4c62a2a5 --- /dev/null +++ b/src/main/java/com/epam/ta/reportportal/ws/model/Page.java @@ -0,0 +1,139 @@ +/* + * Copyright 2023 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. + */ +package com.epam.ta.reportportal.ws.model; + + +import java.util.Collection; +import java.util.Iterator; + +/** + * Paged response representation + * Re-implementation of Spring's HATEAOS Page implementation to get rid of Spring's deps in model package + * + * @author Andrei Varabyeu + */ +public class Page implements Iterable { + + private final Collection content; + private final PageMetadata page; + + /** + * Visible for deserializer + */ + Page() { + this(null, null); + } + + public Page(Collection content, PageMetadata page) { + this.content = content; + this.page = page; + } + + public Page(Collection content, long size, long number, long totalElements, long totalPages) { + this.content = content; + this.page = new PageMetadata(size, number, totalElements, totalPages); + } + + public Page(Collection content, long size, long number, long totalElements) { + this.content = content; + this.page = new PageMetadata(size, number, totalElements); + } + + public Collection getContent() { + return content; + } + + public PageMetadata getPage() { + return page; + } + + @Override + public Iterator iterator() { + return content.iterator(); + } + + public static class PageMetadata { + long number; + long size; + long totalElements; + long totalPages; + + /** + * Visible for deserializer + */ + PageMetadata(){ + } + + public PageMetadata(long size, long number, long totalElements, long totalPages) { + checkArgument(size > -1, "Size must not be negative!"); + checkArgument(number > -1, "Number must not be negative!"); + checkArgument(totalElements > -1, "Total elements must not be negative!"); + checkArgument(totalPages > -1, "Total pages must not be negative!"); + + this.number = number; + this.size = size; + this.totalElements = totalElements; + this.totalPages = totalPages; + + } + + public PageMetadata(long size, long number, long totalElements) { + this(size, number, totalElements, size == 0 ? 0 : (long) Math.ceil((double) totalElements / (double) size)); + } + + public long getNumber() { + return number; + } + + public long getSize() { + return size; + } + + public long getTotalElements() { + return totalElements; + } + + public long getTotalPages() { + return totalPages; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("PageMetadata{"); + sb.append("number=").append(number); + sb.append(", size=").append(size); + sb.append(", totalElements=").append(totalElements); + sb.append(", totalPages=").append(totalPages); + sb.append('}'); + return sb.toString(); + } + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("Page{"); + sb.append("content=").append(content); + sb.append(", page=").append(page); + sb.append('}'); + return sb.toString(); + } + + private static void checkArgument(boolean expression, String errorMessage) { + if (!expression) { + throw new IllegalArgumentException(errorMessage); + } + } +} diff --git a/src/main/java/com/epam/ta/reportportal/ws/model/launch/cluster/CreateClustersRQ.java b/src/main/java/com/epam/ta/reportportal/ws/model/launch/cluster/CreateClustersRQ.java new file mode 100644 index 00000000..dd0e43a5 --- /dev/null +++ b/src/main/java/com/epam/ta/reportportal/ws/model/launch/cluster/CreateClustersRQ.java @@ -0,0 +1,55 @@ +/* + * Copyright 2023 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. + */ + +package com.epam.ta.reportportal.ws.model.launch.cluster; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import javax.validation.constraints.NotNull; + +/** + * @author Ivan Budayeu + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class CreateClustersRQ { + + @NotNull + @JsonProperty(value = "launchId", required = true) + private Long launchId; + + @JsonProperty(value = "removeNumbers") + private boolean removeNumbers; + + public CreateClustersRQ() { + } + + public Long getLaunchId() { + return launchId; + } + + public void setLaunchId(Long launchId) { + this.launchId = launchId; + } + + public boolean isRemoveNumbers() { + return removeNumbers; + } + + public void setRemoveNumbers(boolean removeNumbers) { + this.removeNumbers = removeNumbers; + } +}