Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.github.davidmoten.odata.client.CollectionPageEntityRequest Maven / Gradle / Ivy
package com.github.davidmoten.odata.client;
import static com.github.davidmoten.odata.client.internal.Util.odataTypeName;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Stream;
import com.fasterxml.jackson.annotation.JsonIgnoreType;
import com.github.davidmoten.odata.client.internal.RequestHelper;
@JsonIgnoreType
public class CollectionPageEntityRequest> implements Iterable {
private final ContextPath contextPath;
private final Class cls;
private final EntityRequestFactory entityRequestFactory;
// the value for the collection if it has already been obtained (e.g. via expand option)
private final Optional value;
// should not be public api
public CollectionPageEntityRequest(ContextPath contextPath, Class cls,
EntityRequestFactory entityRequestFactory, Optional value) {
this.contextPath = contextPath;
this.entityRequestFactory = entityRequestFactory;
this.cls = cls;
this.value = value;
}
CollectionPage get(CollectionRequestOptions options) {
if (value.isPresent()) {
Map map = new HashMap<>();
map.put("value", value.get());
String json = Serializer.INSTANCE.serialize(map);
return Serializer.INSTANCE.deserializeCollectionPage( //
json, //
cls, //
contextPath, //
Collections.emptyList(), //
HttpRequestOptions.EMPTY, //
null);
} else {
// perform service request
ContextPath cp = contextPath.addQueries(options.getQueries());
List h = RequestHelper.cleanAndSupplementRequestHeaders(options, "minimal", false);
HttpResponse r = cp.context().service().get(options.getUrlOverride().orElse(cp.toUrl()), h, options);
RequestHelper.checkResponseCodeOk(cp, r);
return cp.context().serializer().deserializeCollectionPage(r.getText(), cls, cp, h, options,
null);
}
}
Optional post(CollectionRequestOptions options, T entity) {
return RequestHelper.post(entity, contextPath, cls, options);
}
Optional patch(CollectionRequestOptions options, T entity) {
return RequestHelper.patch(entity, contextPath, cls, options);
}
public R id(Object id) {
return entityRequestFactory.create(contextPath.addKeys(new NameValue(id, Object.class)));
}
public CollectionPage get() {
return new CollectionEntityRequestOptionsBuilder(this).get();
}
@Override
public Iterator iterator() {
return get().iterator();
}
public Stream stream() {
return get().stream();
}
public Stream> streamWithDeltaLink() {
return get().streamWithDeltaLink();
}
public S to(Function super CollectionPage,? extends S> function) {
return function.apply(get());
}
public List toList() {
return get().toList();
}
public Optional post(T entity) {
return new CollectionEntityRequestOptionsBuilder(this).post(entity);
}
public Optional patch(T entity) {
return new CollectionEntityRequestOptionsBuilder(this).patch(entity);
}
/**
* Returns a request for only those members of the collection that are of the
* requested type. This is referred to in the OData
* 4.01 specification as a "restriction to instances of the derived type".
*
* @param
* the type ("derived type") to be restricting to
* @param cls
* the Class of the type to restrict to
* @return a request for a collection of instances with the given type
*/
@SuppressWarnings("unchecked")
public CollectionPageEntityRequest> filter(Class cls) {
return new CollectionPageEntityRequest>(contextPath.addSegment(odataTypeName(cls)), cls,
(EntityRequestFactory>) entityRequestFactory, value);
}
public CollectionEntityRequestOptionsBuilder requestHeader(String key, String value) {
return new CollectionEntityRequestOptionsBuilder(this).requestHeader(key, value);
}
public CollectionEntityRequestOptionsBuilder query(String name, String value) {
return new CollectionEntityRequestOptionsBuilder(this).query(name, value);
}
public CollectionEntityRequestOptionsBuilder requestHeader(RequestHeader header) {
return new CollectionEntityRequestOptionsBuilder(this).requestHeader(header);
}
public CollectionEntityRequestOptionsBuilder maxPageSize(int size) {
return new CollectionEntityRequestOptionsBuilder(this).maxPageSize(size);
}
public CollectionEntityRequestOptionsBuilder search(String clause) {
return new CollectionEntityRequestOptionsBuilder(this).search(clause);
}
public CollectionEntityRequestOptionsBuilder expand(String clause) {
return new CollectionEntityRequestOptionsBuilder(this).expand(clause);
}
public CollectionEntityRequestOptionsBuilder filter(String clause) {
return new CollectionEntityRequestOptionsBuilder(this).filter(clause);
}
public CollectionEntityRequestOptionsBuilder orderBy(String clause) {
return new CollectionEntityRequestOptionsBuilder(this).orderBy(clause);
}
public CollectionEntityRequestOptionsBuilder skip(long n) {
return new CollectionEntityRequestOptionsBuilder(this).skip(n);
}
public CollectionEntityRequestOptionsBuilder top(long n) {
return new CollectionEntityRequestOptionsBuilder(this).top(n);
}
public CollectionEntityRequestOptionsBuilder select(String clause) {
return new CollectionEntityRequestOptionsBuilder(this).select(clause);
}
public CollectionEntityRequestOptionsBuilder metadataFull() {
return new CollectionEntityRequestOptionsBuilder(this).metadataFull();
}
public CollectionEntityRequestOptionsBuilder metadataMinimal() {
return new CollectionEntityRequestOptionsBuilder(this).metadataMinimal();
}
public CollectionEntityRequestOptionsBuilder metadataNone() {
return new CollectionEntityRequestOptionsBuilder(this).metadataNone();
}
public CollectionEntityRequestOptionsBuilder urlOverride(String urlOverride) {
return new CollectionEntityRequestOptionsBuilder(this).urlOverride(urlOverride);
}
public CollectionEntityRequestOptionsBuilder connectTimeout(long duration, TimeUnit unit) {
return new CollectionEntityRequestOptionsBuilder(this).connectTimeout(duration, unit);
}
public CollectionEntityRequestOptionsBuilder readTimeout(long duration, TimeUnit unit) {
return new CollectionEntityRequestOptionsBuilder(this).readTimeout(duration, unit);
}
public CollectionEntityRequestOptionsBuilder deltaTokenLatest() {
return new CollectionEntityRequestOptionsBuilder(this).deltaTokenLatest();
}
}