Search in sources :

Example 1 with V3API

use of org.ovirt.engine.api.v3.types.V3API in project ovirt-engine by oVirt.

the class V3SystemServer method replaceLinkHeader.

private Response replaceLinkHeader(Response response) {
    Object entity = response.getEntity();
    if (entity != null && entity instanceof V3API) {
        V3API api = (V3API) entity;
        List<V3Link> links = api.getLinks();
        if (links != null) {
            String root = CurrentManager.get().getRoot();
            String header = links.stream().map(link -> String.format("<%s%s>; rel=%s", root, link.getHref(), link.getRel())).collect(joining(","));
            response = Response.fromResponse(response).header("Link", null).header("Link", header).build();
        }
    }
    return response;
}
Also used : PathParam(javax.ws.rs.PathParam) SystemResource(org.ovirt.engine.api.resource.SystemResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) V3Action(org.ovirt.engine.api.v3.types.V3Action) Path(javax.ws.rs.Path) CurrentManager(org.ovirt.engine.api.restapi.invocation.CurrentManager) Actionable(org.ovirt.engine.api.model.Actionable) V3Server(org.ovirt.engine.api.v3.V3Server) RsdlLoader(org.ovirt.engine.api.restapi.rsdl.RsdlLoader) Consumes(javax.ws.rs.Consumes) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) IOException(java.io.IOException) ParametersHelper(org.ovirt.engine.api.restapi.util.ParametersHelper) Collectors.joining(java.util.stream.Collectors.joining) V3RSDL(org.ovirt.engine.api.v3.types.V3RSDL) List(java.util.List) V3API(org.ovirt.engine.api.v3.types.V3API) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) UriInfo(javax.ws.rs.core.UriInfo) V3Link(org.ovirt.engine.api.v3.types.V3Link) HEAD(javax.ws.rs.HEAD) V3Link(org.ovirt.engine.api.v3.types.V3Link) V3API(org.ovirt.engine.api.v3.types.V3API)

Example 2 with V3API

use of org.ovirt.engine.api.v3.types.V3API in project ovirt-engine by oVirt.

the class V3ApiOutAdapter method adapt.

@Override
public V3API adapt(Api from) {
    V3API to = new V3API();
    if (from.isSetActions()) {
        to.setActions(adaptOut(from.getActions()));
    }
    // Remove the links for "rels" that are new in version 4 of the API:
    if (from.isSetLinks()) {
        List<Link> links = from.getLinks().stream().filter(link -> !RELS_TO_REMOVE.contains(link.getRel())).collect(toList());
        to.getLinks().addAll(adaptOut(links));
    }
    // In version 4 of the API the "capabilities" resource was removed, but it still exists in version 3, so we
    // need to explicitly add a the link:
    to.getLinks().add(0, makeCapabilitiesLink());
    if (from.isSetSpecialObjects()) {
        to.setSpecialObjects(adaptOut(from.getSpecialObjects()));
    }
    if (from.isSetProductInfo()) {
        to.setProductInfo(adaptOut(from.getProductInfo()));
    }
    if (from.isSetSummary()) {
        to.setSummary(adaptOut(from.getSummary()));
    }
    if (from.isSetTime()) {
        to.setTime(from.getTime());
    }
    return to;
}
Also used : HashSet(java.util.HashSet) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) V3API(org.ovirt.engine.api.v3.types.V3API) Link(org.ovirt.engine.api.model.Link) V3Adapter(org.ovirt.engine.api.v3.V3Adapter) Current(org.ovirt.engine.api.restapi.invocation.Current) CurrentManager(org.ovirt.engine.api.restapi.invocation.CurrentManager) Set(java.util.Set) Api(org.ovirt.engine.api.model.Api) V3OutAdapters.adaptOut(org.ovirt.engine.api.v3.adapters.V3OutAdapters.adaptOut) V3Link(org.ovirt.engine.api.v3.types.V3Link) V3API(org.ovirt.engine.api.v3.types.V3API) Link(org.ovirt.engine.api.model.Link) V3Link(org.ovirt.engine.api.v3.types.V3Link)

Aggregations

List (java.util.List)2 CurrentManager (org.ovirt.engine.api.restapi.invocation.CurrentManager)2 V3API (org.ovirt.engine.api.v3.types.V3API)2 V3Link (org.ovirt.engine.api.v3.types.V3Link)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Collectors.joining (java.util.stream.Collectors.joining)1 Collectors.toList (java.util.stream.Collectors.toList)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 HEAD (javax.ws.rs.HEAD)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 PathParam (javax.ws.rs.PathParam)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Context (javax.ws.rs.core.Context)1 HttpHeaders (javax.ws.rs.core.HttpHeaders)1 Response (javax.ws.rs.core.Response)1