/*
 * Copyright 2016 Honza Brázdil <jbrazdil@redhat.com>.
 *
 * 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.jboss.pnc.causeway.bpmclient;

import org.jboss.pnc.causeway.rest.BrewPushMilestoneResult;
import org.jboss.pnc.causeway.rest.Callback;
import org.jboss.pnc.rest.restmodel.causeway.MilestoneReleaseResultRest;
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;

import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;

/**
 *
 * @author Honza Brázdil <jbrazdil@redhat.com>
 */
@ApplicationScoped
public class BPMClientImpl implements BPMClient {
    private final ResteasyClient client;

    public BPMClientImpl() {
        client = new ResteasyClientBuilder().build();
    }

    private void send(String url, BrewPushMilestoneResult result){
        ResteasyWebTarget target = client.target(url);
        target.request(MediaType.APPLICATION_JSON).post(Entity.entity(result, MediaType.APPLICATION_JSON_TYPE));
    }

    @Override
    public void success(String url, String callbackId, MilestoneReleaseResultRest result) {
        Callback callback = new Callback(callbackId, 200);
        send(url, new BrewPushMilestoneResult(result, callback));
    }
    
    @Override
    public void error(String url, String callbackId, MilestoneReleaseResultRest result) {
        Callback callback = new Callback(callbackId, 418);
        send(url, new BrewPushMilestoneResult(result, callback));
    }

    @Override
    public void failure(String url, String callbackId, MilestoneReleaseResultRest result) {
        Callback callback = new Callback(callbackId, 500);
        send(url, new BrewPushMilestoneResult(result, callback));
    }
}

@@ -653,24 +653,83 @@
 bpmclient;%0A%0A
+import org.jboss.pnc.causeway.ctl.PncImportControllerImpl;%0A
 import org.j
@@ -776,16 +776,16 @@
 Result;%0A
-
 import o
@@ -1191,16 +1191,82 @@
 aType;%0A%0A
+import java.util.logging.Level;%0Aimport java.util.logging.Logger;%0A%0A
 /**%0A *%0A 
@@ -1856,32 +1856,177 @@
 tRest result) %7B%0A
+        Logger.getLogger(BPMClientImpl.class.getName()).log(Level.INFO, %22Import of milestone %7B0%7D ended with success.%22, result.getMilestoneId());%0A
         Callback
@@ -2241,32 +2241,175 @@
 tRest result) %7B%0A
+        Logger.getLogger(BPMClientImpl.class.getName()).log(Level.INFO, %22Import of milestone %7B0%7D ended with error.%22, result.getMilestoneId());%0A
         Callback
@@ -2530,32 +2530,32 @@
 %0A%0A    @Override%0A
-
     public void 
@@ -2622,32 +2622,177 @@
 tRest result) %7B%0A
+        Logger.getLogger(BPMClientImpl.class.getName()).log(Level.INFO, %22Import of milestone %7B0%7D ended with failure.%22, result.getMilestoneId());%0A
         Callback

add logging after import process ends