View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.core.rest.cxf.service;
20  
21  import java.net.URI;
22  import java.util.List;
23  import javax.ws.rs.core.HttpHeaders;
24  import javax.ws.rs.core.Response;
25  import javax.ws.rs.core.StreamingOutput;
26  import org.apache.syncope.common.lib.to.ReportTO;
27  import org.apache.syncope.common.rest.api.RESTHeaders;
28  import org.apache.syncope.common.rest.api.service.ReportService;
29  import org.apache.syncope.core.logic.AbstractExecutableLogic;
30  import org.apache.syncope.core.logic.ReportLogic;
31  import org.springframework.stereotype.Service;
32  
33  @Service
34  public class ReportServiceImpl extends AbstractExecutableService implements ReportService {
35  
36      protected final ReportLogic logic;
37  
38      public ReportServiceImpl(final ReportLogic logic) {
39          this.logic = logic;
40      }
41  
42      @Override
43      protected AbstractExecutableLogic<?> getExecutableLogic() {
44          return logic;
45      }
46  
47      @Override
48      public Response create(final ReportTO reportTO) {
49          ReportTO createdReportTO = logic.create(reportTO);
50          URI location = uriInfo.getAbsolutePathBuilder().path(createdReportTO.getKey()).build();
51          return Response.created(location).
52                  header(RESTHeaders.RESOURCE_KEY, createdReportTO.getKey()).
53                  build();
54      }
55  
56      @Override
57      public void update(final ReportTO reportTO) {
58          logic.update(reportTO);
59      }
60  
61      @Override
62      public List<ReportTO> list() {
63          return logic.list();
64      }
65  
66      @Override
67      public ReportTO read(final String key) {
68          return logic.read(key);
69      }
70  
71      @Override
72      public Response exportExecutionResult(final String executionKey) {
73          String filename = logic.getFilename(executionKey);
74          StreamingOutput sout = os -> logic.exportExecutionResult(os, executionKey);
75  
76          return Response.ok(sout).
77                  header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename).
78                  build();
79      }
80  
81      @Override
82      public void delete(final String key) {
83          logic.delete(key);
84      }
85  }