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.time.OffsetDateTime;
22  import javax.ws.rs.core.Response;
23  import org.apache.syncope.common.lib.request.StatusR;
24  import org.apache.syncope.common.lib.request.UserCR;
25  import org.apache.syncope.common.lib.request.UserUR;
26  import org.apache.syncope.common.lib.to.ProvisioningResult;
27  import org.apache.syncope.common.lib.to.UserTO;
28  import org.apache.syncope.common.rest.api.service.UserService;
29  import org.apache.syncope.core.logic.AbstractAnyLogic;
30  import org.apache.syncope.core.logic.UserLogic;
31  import org.apache.syncope.core.persistence.api.dao.AnyDAO;
32  import org.apache.syncope.core.persistence.api.dao.UserDAO;
33  import org.apache.syncope.core.persistence.api.search.SearchCondVisitor;
34  import org.springframework.stereotype.Service;
35  
36  @Service
37  public class UserServiceImpl extends AbstractAnyService<UserTO, UserCR, UserUR> implements UserService {
38  
39      protected final UserDAO userDAO;
40  
41      protected final UserLogic logic;
42  
43      public UserServiceImpl(
44              final SearchCondVisitor searchCondVisitor,
45              final UserDAO userDAO,
46              final UserLogic logic) {
47  
48          super(searchCondVisitor);
49          this.userDAO = userDAO;
50          this.logic = logic;
51      }
52  
53      @Override
54      protected AnyDAO<?> getAnyDAO() {
55          return userDAO;
56      }
57  
58      @Override
59      protected AbstractAnyLogic<UserTO, UserCR, UserUR> getAnyLogic() {
60          return logic;
61      }
62  
63      @Override
64      protected UserUR newUpdateReq(final String key) {
65          return new UserUR.Builder(key).build();
66      }
67  
68      @Override
69      public Response create(final UserCR createReq) {
70          ProvisioningResult<UserTO> created = logic.create(createReq, isNullPriorityAsync());
71          return createResponse(created);
72      }
73  
74      @Override
75      public Response update(final UserUR updateReq) {
76          return doUpdate(updateReq);
77      }
78  
79      @Override
80      public Response status(final StatusR statusR) {
81          OffsetDateTime etag = findLastChange(statusR.getKey());
82          checkETag(String.valueOf(etag.toInstant().toEpochMilli()));
83  
84          ProvisioningResult<UserTO> updated = logic.status(statusR, isNullPriorityAsync());
85          return modificationResponse(updated);
86      }
87  }