/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.apache.syncope.console.rest;

import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.Response;
import org.apache.syncope.common.services.ReportService;
import org.apache.syncope.common.services.ReportletConfClasses;
import org.apache.syncope.common.to.ReportTO;
import org.apache.syncope.common.types.ReportExecExportFormat;
import org.apache.syncope.common.validation.SyncopeClientCompositeErrorException;
import org.springframework.stereotype.Component;

@Component
public class ReportRestClient extends BaseRestClient implements ExecutionRestClient {

    private static final long serialVersionUID = 1644689667998953604L;

    public List<String> getReportletConfClasses() {
        try {
            ReportletConfClasses reportletConfClasses = getService(ReportService.class).getReportletConfClasses();
            return reportletConfClasses.getConfClasses();
        } catch (SyncopeClientCompositeErrorException e) {
            LOG.error("While getting available reportlet classes", e);
            return new ArrayList<String>();
        }
    }

    public ReportTO read(final Long reportId) {
        return getService(ReportService.class).read(reportId);
    }

    public List<ReportTO> list() {
        return getService(ReportService.class).list();
    }

    public List<ReportTO> list(final int page, final int size) {
        return getService(ReportService.class).list(page, size);
    }

    public int count() {
        return getService(ReportService.class).count();
    }

    public ReportTO create(final ReportTO reportTO) {
        Response response = getService(ReportService.class).create(reportTO);
        Long reportId = (Long) response.getEntity();
        return getService(ReportService.class).read(reportId);
    }

    public void update(final ReportTO reportTO) {
        getService(ReportService.class).update(reportTO.getId(), reportTO);
    }

    /**
     * Delete specified report.
     *
     * @param reportId report to delete
     */
    public void delete(final Long reportId) {
        getService(ReportService.class).delete(reportId);
    }

    /**
     * Start execution for the specified report.
     *
     * @param reportId report id
     */
    @Override
    public void startExecution(final long reportId) {
        getService(ReportService.class).execute(reportId);
    }

    /**
     * Delete specified report execution.
     *
     * @param reportExecId report execution id
     */
    @Override
    public void deleteExecution(final long reportExecId) {
        getService(ReportService.class).deleteExecution(reportExecId);
    }

    public Response exportExecutionResult(final Long executionId, final ReportExecExportFormat fmt) {
        return getService(ReportService.class).exportExecutionResult(executionId, fmt);
    }
}

@@ -2341,24 +2341,20 @@
  public 
-ReportTO
+void
  create(
@@ -2391,28 +2391,8 @@
     
- Response response =
  get
@@ -2442,124 +2442,8 @@
 O);%0A
-        Long reportId = (Long) response.getEntity();%0A        return getService(ReportService.class).read(reportId);%0A
     

Merge from 1_1_X