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.util.List;
22  import javax.ws.rs.core.Response;
23  import org.apache.commons.lang3.tuple.Pair;
24  import org.apache.syncope.common.lib.to.ExecTO;
25  import org.apache.syncope.common.lib.to.JobTO;
26  import org.apache.syncope.common.lib.to.PagedResult;
27  import org.apache.syncope.common.lib.types.JobAction;
28  import org.apache.syncope.common.rest.api.RESTHeaders;
29  import org.apache.syncope.common.rest.api.batch.BatchPayloadGenerator;
30  import org.apache.syncope.common.rest.api.batch.BatchResponseItem;
31  import org.apache.syncope.common.rest.api.beans.ExecQuery;
32  import org.apache.syncope.common.rest.api.beans.ExecSpecs;
33  import org.apache.syncope.common.rest.api.service.ExecutableService;
34  import org.apache.syncope.common.rest.api.service.JAXRSService;
35  import org.apache.syncope.core.logic.AbstractExecutableLogic;
36  import org.apache.syncope.core.spring.security.SecureRandomUtils;
37  
38  public abstract class AbstractExecutableService extends AbstractService implements ExecutableService {
39  
40      protected abstract AbstractExecutableLogic<?> getExecutableLogic();
41  
42      @Override
43      public PagedResult<ExecTO> listExecutions(final ExecQuery query) {
44          Pair<Integer, List<ExecTO>> result = getExecutableLogic().listExecutions(
45                  query.getKey(),
46                  query.getBefore(),
47                  query.getAfter(),
48                  query.getPage(),
49                  query.getSize(),
50                  getOrderByClauses(query.getOrderBy()));
51          return buildPagedResult(result.getRight(), query.getPage(), query.getSize(), result.getLeft());
52      }
53  
54      @Override
55      public List<ExecTO> listRecentExecutions(final int max) {
56          return getExecutableLogic().listRecentExecutions(max);
57      }
58  
59      @Override
60      public void deleteExecution(final String executionKey) {
61          getExecutableLogic().deleteExecution(executionKey);
62      }
63  
64      @Override
65      public Response deleteExecutions(final ExecQuery query) {
66          List<BatchResponseItem> batchResponseItems = getExecutableLogic().deleteExecutions(
67                  query.getKey(),
68                  query.getBefore(),
69                  query.getAfter());
70  
71          String boundary = "deleteExecutions_" + SecureRandomUtils.generateRandomUUID().toString();
72          return Response.ok(BatchPayloadGenerator.generate(
73                  batchResponseItems, JAXRSService.DOUBLE_DASH + boundary)).
74                  type(RESTHeaders.multipartMixedWith(boundary)).
75                  build();
76      }
77  
78      @Override
79      public ExecTO execute(final ExecSpecs query) {
80          return getExecutableLogic().execute(query.getKey(), query.getStartAt(), query.getDryRun());
81      }
82  
83      @Override
84      public JobTO getJob(final String key) {
85          return getExecutableLogic().getJob(key);
86      }
87  
88      @Override
89      public List<JobTO> listJobs() {
90          return getExecutableLogic().listJobs();
91      }
92  
93      @Override
94      public void actionJob(final String key, final JobAction action) {
95          getExecutableLogic().actionJob(key, action);
96      }
97  }