org.jboss.pnc.client.ProductClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rest-api Show documentation
Show all versions of rest-api Show documentation
Module with REST API bidings.
The newest version!
package org.jboss.pnc.client;
import java.lang.String;
import java.util.Optional;
import javax.ws.rs.NotAuthorizedException;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.WebApplicationException;
import org.jboss.pnc.dto.Product;
import org.jboss.pnc.dto.ProductVersion;
import org.jboss.pnc.rest.api.endpoints.ProductEndpoint;
public class ProductClient extends ClientBase {
public ProductClient(Configuration configuration) {
super(configuration, ProductEndpoint.class);
}
public RemoteCollection getAll(Optional sort, Optional query) throws
RemoteResourceException {
try {
PageReader pageLoader = new PageReader<>((pageParameters) -> { setSortAndQuery(pageParameters, sort, query); return getEndpoint().getAll(pageParameters);}, getRemoteCollectionConfig());
return pageLoader.getCollection();
} catch (NotAuthorizedException e) {
if (configuration.getBearerTokenSupplier() != null) {
try {
bearerAuthentication.setTokenSupplier(configuration.getBearerTokenSupplier());
PageReader pageLoader = new PageReader<>((pageParameters) -> { setSortAndQuery(pageParameters, sort, query); return getEndpoint().getAll(pageParameters);}, getRemoteCollectionConfig());
return pageLoader.getCollection();
} catch (WebApplicationException wae) {
throw new RemoteResourceException(readErrorResponse(wae), wae);
}
} else {
throw new RemoteResourceException(readErrorResponse(e), e);
}
} catch (WebApplicationException e) {
throw new RemoteResourceException(readErrorResponse(e), e);
}
}
public RemoteCollection getAll() throws RemoteResourceException {
try {
return getAll(Optional.empty(), Optional.empty());
} catch (NotAuthorizedException e) {
if (configuration.getBearerTokenSupplier() != null) {
try {
bearerAuthentication.setTokenSupplier(configuration.getBearerTokenSupplier());
return getAll(Optional.empty(), Optional.empty());
} catch (WebApplicationException wae) {
throw new RemoteResourceException(readErrorResponse(wae), wae);
}
} else {
throw new RemoteResourceException(readErrorResponse(e), e);
}
} catch (WebApplicationException e) {
throw new RemoteResourceException(readErrorResponse(e), e);
}
}
public Product createNew(Product product) throws RemoteResourceException {
try {
return getEndpoint().createNew(product);
} catch (NotFoundException e) {
throw new RemoteResourceNotFoundException(e);
} catch (NotAuthorizedException e) {
if (configuration.getBearerTokenSupplier() != null) {
try {
bearerAuthentication.setTokenSupplier(configuration.getBearerTokenSupplier());
return getEndpoint().createNew(product);
} catch (WebApplicationException wae) {
throw new RemoteResourceException(readErrorResponse(wae), wae);
}
} else {
throw new RemoteResourceException(readErrorResponse(e), e);
}
} catch (WebApplicationException e) {
throw new RemoteResourceException(readErrorResponse(e), e);
}
}
public Product getSpecific(String id) throws RemoteResourceException {
try {
return getEndpoint().getSpecific(id);
} catch (NotFoundException e) {
throw new RemoteResourceNotFoundException(e);
} catch (NotAuthorizedException e) {
if (configuration.getBearerTokenSupplier() != null) {
try {
bearerAuthentication.setTokenSupplier(configuration.getBearerTokenSupplier());
return getEndpoint().getSpecific(id);
} catch (WebApplicationException wae) {
throw new RemoteResourceException(readErrorResponse(wae), wae);
}
} else {
throw new RemoteResourceException(readErrorResponse(e), e);
}
} catch (WebApplicationException e) {
throw new RemoteResourceException(readErrorResponse(e), e);
}
}
public void update(String id, Product product) throws RemoteResourceException,
RemoteResourceNotFoundException {
try {
getEndpoint().update(id, product);
} catch (NotFoundException e) {
throw new RemoteResourceNotFoundException(e);
} catch (NotAuthorizedException e) {
if (configuration.getBearerTokenSupplier() != null) {
try {
bearerAuthentication.setTokenSupplier(configuration.getBearerTokenSupplier());
getEndpoint().update(id, product);
} catch (WebApplicationException wae) {
throw new RemoteResourceException(readErrorResponse(wae), wae);
}
} else {
throw new RemoteResourceException(readErrorResponse(e), e);
}
} catch (WebApplicationException e) {
throw new RemoteResourceException(readErrorResponse(e), e);
}
}
public RemoteCollection getProductVersions(String id, Optional sort,
Optional query) throws RemoteResourceException {
try {
PageReader pageLoader = new PageReader<>((pageParameters) -> { setSortAndQuery(pageParameters, sort, query); return getEndpoint().getProductVersions(id, pageParameters);}, getRemoteCollectionConfig());
return pageLoader.getCollection();
} catch (NotAuthorizedException e) {
if (configuration.getBearerTokenSupplier() != null) {
try {
bearerAuthentication.setTokenSupplier(configuration.getBearerTokenSupplier());
PageReader pageLoader = new PageReader<>((pageParameters) -> { setSortAndQuery(pageParameters, sort, query); return getEndpoint().getProductVersions(id, pageParameters);}, getRemoteCollectionConfig());
return pageLoader.getCollection();
} catch (WebApplicationException wae) {
throw new RemoteResourceException(readErrorResponse(wae), wae);
}
} else {
throw new RemoteResourceException(readErrorResponse(e), e);
}
} catch (WebApplicationException e) {
throw new RemoteResourceException(readErrorResponse(e), e);
}
}
public RemoteCollection getProductVersions(String id) throws
RemoteResourceException {
try {
return getProductVersions(id, Optional.empty(), Optional.empty());
} catch (NotAuthorizedException e) {
if (configuration.getBearerTokenSupplier() != null) {
try {
bearerAuthentication.setTokenSupplier(configuration.getBearerTokenSupplier());
return getProductVersions(id, Optional.empty(), Optional.empty());
} catch (WebApplicationException wae) {
throw new RemoteResourceException(readErrorResponse(wae), wae);
}
} else {
throw new RemoteResourceException(readErrorResponse(e), e);
}
} catch (WebApplicationException e) {
throw new RemoteResourceException(readErrorResponse(e), e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy