/*
 * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates
 * and other contributors as indicated by the @author tags.
 *
 * 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 org.hawkular.inventory.rest;

import static org.hawkular.inventory.rest.RequestUtil.extractPaging;

import java.io.IOException;
import java.io.Reader;
import java.net.URISyntaxException;
import java.util.Collection;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import org.hawkular.inventory.api.Query;
import org.hawkular.inventory.api.model.AbstractElement;
import org.hawkular.inventory.api.model.Tenant;
import org.hawkular.inventory.api.paging.Page;
import org.hawkular.inventory.paths.CanonicalPath;
import org.hawkular.inventory.paths.SegmentType;

/**
 * @author Lukas Krejci
 * @since 0.16.0
 */
@Path("/tenant")
public class RestTenant extends RestBase {

    public RestTenant() {
        super("/tenant".length());
    }

    @GET
    public Tenant get() {
        return inventory.tenants().get(getTenantId()).entity();
    }

    @PUT
    public Response put(Tenant.Update update) {
        inventory.tenants().get(getTenantId()).update(update);
        return Response.noContent().build();
    }

    @GET
    @Path("/relationships")
    public Response getRelationships(@Context UriInfo uriInfo) {
        Traverser traverser = getTraverser(uriInfo);
        Query q = traverser.navigate(getPath(uriInfo));

        @SuppressWarnings("unchecked")
        Page<AbstractElement<?, ?>> results = inventory.execute(q, (Class) AbstractElement.class,
                extractPaging(uriInfo));

        return pagedResponse(Response.ok(), uriInfo, results).build();
    }

    @POST
    @Path("/relationship")
    @SuppressWarnings("unchecked")
    public Response createRelationships(@Context UriInfo uriInfo, Reader input)
            throws IOException, URISyntaxException {
        CanonicalPath tenant = getTenantPath();

        Object toReport = create(tenant, SegmentType.rl, input);
        if (toReport instanceof Collection) {
            return ResponseUtil.created((Collection<? extends AbstractElement<?, ?>>) toReport, uriInfo).build();
        } else {
            return ResponseUtil.created((AbstractElement<?, ?>) toReport, uriInfo).build();
        }
    }
}

@@ -714,16 +714,76 @@
 .rest;%0A%0A
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;%0A%0A
 import s
@@ -843,16 +843,16 @@
 Paging;%0A
-
 %0Aimport 
@@ -961,16 +961,45 @@
 ction;%0A%0A
+import javax.ws.rs.Consumes;%0A
 import j
@@ -1063,16 +1063,16 @@
 rs.PUT;%0A
-
 import j
@@ -1084,24 +1084,53 @@
 ws.rs.Path;%0A
+import javax.ws.rs.Produces;%0A
 import javax
@@ -1578,16 +1578,72 @@
 enant%22)%0A
+@Produces(APPLICATION_JSON)%0A@Consumes(APPLICATION_JSON)%0A
 public c

Add the produced/consumed content type to the /tenant endpoint.