Skip to content

Commit

Permalink
Return models
Browse files Browse the repository at this point in the history
  • Loading branch information
APiankouski committed Feb 5, 2024
1 parent 29ae3e1 commit c800793
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 0 deletions.
139 changes: 139 additions & 0 deletions src/main/java/com/epam/ta/reportportal/ws/model/Page.java
Original file line number Diff line number Diff line change
@@ -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<T> implements Iterable<T> {

private final Collection<T> content;
private final PageMetadata page;

/**
* Visible for deserializer
*/
Page() {
this(null, null);
}

public Page(Collection<T> content, PageMetadata page) {
this.content = content;
this.page = page;
}

public Page(Collection<T> content, long size, long number, long totalElements, long totalPages) {
this.content = content;
this.page = new PageMetadata(size, number, totalElements, totalPages);
}

public Page(Collection<T> content, long size, long number, long totalElements) {
this.content = content;
this.page = new PageMetadata(size, number, totalElements);
}

public Collection<T> getContent() {
return content;
}

public PageMetadata getPage() {
return page;
}

@Override
public Iterator<T> 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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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 <a href="mailto:[email protected]">Ivan Budayeu</a>
*/
@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;
}
}

0 comments on commit c800793

Please sign in to comment.