/*
 * 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 javax.ws.rs.core.MediaType.APPLICATION_JSON;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.Encoded;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;

import org.hawkular.inventory.api.IdentityHashed;
import org.hawkular.inventory.api.model.Blueprint;
import org.hawkular.inventory.api.model.CanonicalPath;
import org.hawkular.inventory.api.model.Entity;
import org.hawkular.inventory.api.model.IdentityHashable;
import org.hawkular.inventory.api.model.InventoryStructure;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

/**
 * @author Lukas Krejci
 * @since 0.15.0
 */
@Path("/sync")
@Produces(value = APPLICATION_JSON)
@Consumes(value = APPLICATION_JSON)
@Api(value = "/sync", description = "Synchronization of entity trees", tags = "Sync")
public class RestSync extends RestBase {

    @POST
    @Path("/{path}")
    @ApiOperation("Make the inventory under given path match the provided inventory structure. Note that the " +
            "relationships specified in the provided entities will be ignored and will not be applied.")
    @ApiResponses({
            @ApiResponse(code = 204, message = "Synchronization success")
    })
    @SuppressWarnings("unchecked")
    public Response sync(@Encoded @PathParam("path") List<PathSegment> path, InventoryStructure.Offline<?> structure) {
        CanonicalPath cp = parsePath(path);

        if (!IdentityHashable.class.isAssignableFrom(cp.getSegment().getElementType())) {
            throw new IllegalArgumentException("Entities of type " + cp.getSegment().getElementType().getSimpleName()
                    + " are not synchronizable.");
        }

        inventory.inspect(cp, IdentityHashed.SingleWithRelationships.class).synchronize(structure);

        return Response.noContent().build();
    }
}

@@ -1130,120 +1130,21 @@
 del.
-Blueprint;%0Aimport org.hawkular.inventory.api.model.CanonicalPath;%0Aimport org.hawkular.inventory.api.model.Entity
+CanonicalPath
 ;%0Aim

Make checkstyle happy.