ChangeCalendar/backend/src/main/java/com/nttdata/calender/changes/ChangeRequest.java

126 lines
3.3 KiB
Java

package com.nttdata.calender.changes;
import com.bmc.arsys.api.SortInfo;
import com.nttdata.calender.api.Query;
import com.nttdata.calender.changes.query.Filter;
import com.nttdata.calender.changes.query.FilterElement;
import com.nttdata.calender.changes.query.Sort;
import com.nttdata.calender.errorhandling.ErrorTypes.ValidationError;
/**
* Represents a change request object that stores information about slice start,
* slice end,
* filter criteria, and sorting options.
*/
public class ChangeRequest {
private int sliceStart;
private int sliceEnd;
private Filter filter;
private Sort sort;
/**
* Returns the starting index of the slice.
*
* @return an int representing the slice start index.
*/
public int getSliceStart() {
return this.sliceStart;
}
/**
* Sets the starting index of the slice.
*
* @param sliceStart an int representing the slice start index.
*/
public void setSliceStart(int sliceStart) {
this.sliceStart = sliceStart;
}
/**
* Returns the ending index of the slice.
*
* @return an int representing the slice end index.
*/
public int getSliceEnd() {
return this.sliceEnd;
}
/**
* Sets the ending index of the slice.
*
* @param sliceEnd an int representing the slice end index.
*/
public void setSliceEnd(int sliceEnd) {
this.sliceEnd = sliceEnd;
}
/**
* Returns the array of filter criteria.
*
* @return an array of {@link FilterElement} objects representing the filter
* criteria.
*/
public Filter getFilter() {
return this.filter;
}
/**
* Sets the array of filter criteria.
*
* @param filter an array of {@link FilterElement} objects representing the
* filter
* criteria.
*/
public void setFilter(Filter filter) {
this.filter = filter;
}
/**
* Returns the sorting options for the change request.
*
* @return a {@link Sort} object representing the sorting options.
*/
public Sort getSort() {
return this.sort;
}
/**
* Sets the sorting options for the change request.
*
* @param sort a {@link Sort} object representing the sorting options.
*/
public void setSort(Sort sort) {
this.sort = sort;
}
/**
* Adds a filter to the list of filters.
*
* @param filter the filter to add
*/
public void addFilter(FilterElement filter) {
if (this.filter == null) {
this.filter = new Filter();
}
this.filter.addFilter(filter);
}
/**
* Constructs and returns a `SortInfo` object based on the provided `Query`
* object.
* If no sort information is available, returns `null`.
*
* @param query the query object used for constructing the `SortInfo`
* @return the constructed `SortInfo` object, or `null` if no sort information
* is available
* @throws ValidationError if a validation error occurs during construction
*/
public SortInfo constructSortInfo(Query query) throws ValidationError {
if (this.sort != null) {
return this.sort.getSortInfo(query);
}
return null;
}
}