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 javax.ws.rs.core.Response;
22  import org.apache.commons.lang3.StringUtils;
23  import org.apache.syncope.common.lib.SyncopeClientException;
24  import org.apache.syncope.common.lib.request.AnyObjectCR;
25  import org.apache.syncope.common.lib.request.AnyObjectUR;
26  import org.apache.syncope.common.lib.search.SpecialAttr;
27  import org.apache.syncope.common.lib.to.AnyObjectTO;
28  import org.apache.syncope.common.lib.to.PagedResult;
29  import org.apache.syncope.common.lib.to.ProvisioningResult;
30  import org.apache.syncope.common.lib.types.ClientExceptionType;
31  import org.apache.syncope.common.rest.api.beans.AnyQuery;
32  import org.apache.syncope.common.rest.api.service.AnyObjectService;
33  import org.apache.syncope.core.logic.AbstractAnyLogic;
34  import org.apache.syncope.core.logic.AnyObjectLogic;
35  import org.apache.syncope.core.persistence.api.dao.AnyDAO;
36  import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO;
37  import org.apache.syncope.core.persistence.api.search.SearchCondVisitor;
38  import org.springframework.stereotype.Service;
39  
40  @Service
41  public class AnyObjectServiceImpl extends AbstractAnyService<AnyObjectTO, AnyObjectCR, AnyObjectUR>
42          implements AnyObjectService {
43  
44      protected final AnyObjectDAO anyObjectDAO;
45  
46      protected final AnyObjectLogic logic;
47  
48      public AnyObjectServiceImpl(
49              final SearchCondVisitor searchCondVisitor,
50              final AnyObjectDAO anyObjectDAO,
51              final AnyObjectLogic logic) {
52  
53          super(searchCondVisitor);
54          this.anyObjectDAO = anyObjectDAO;
55          this.logic = logic;
56      }
57  
58      @Override
59      protected AnyDAO<?> getAnyDAO() {
60          return anyObjectDAO;
61      }
62  
63      @Override
64      protected AbstractAnyLogic<AnyObjectTO, AnyObjectCR, AnyObjectUR> getAnyLogic() {
65          return logic;
66      }
67  
68      @Override
69      public AnyObjectTO read(final String key) {
70          return logic.read(key);
71      }
72  
73      @Override
74      public AnyObjectTO read(final String type, final String name) {
75          return logic.read(type, name);
76      }
77  
78      @Override
79      protected AnyObjectUR newUpdateReq(final String key) {
80          return new AnyObjectUR.Builder(key).build();
81      }
82  
83      @Override
84      public Response create(final AnyObjectCR createReq) {
85          ProvisioningResult<AnyObjectTO> created = logic.create(createReq, isNullPriorityAsync());
86          return createResponse(created);
87      }
88  
89      @Override
90      public Response update(final AnyObjectUR updateReq) {
91          return doUpdate(updateReq);
92      }
93  
94      @Override
95      public PagedResult<AnyObjectTO> search(final AnyQuery anyQuery) {
96          if (StringUtils.isBlank(anyQuery.getFiql())
97                  || -1 == anyQuery.getFiql().indexOf(SpecialAttr.TYPE.toString())) {
98  
99              SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSearchParameters);
100             sce.getElements().add(SpecialAttr.TYPE.toString() + " is required in the FIQL string");
101             throw sce;
102         }
103 
104         return super.search(anyQuery);
105     }
106 }