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.provisioning.java.pushpull;
20  
21  import java.util.List;
22  import java.util.Map;
23  import java.util.Set;
24  import org.apache.commons.lang3.tuple.Pair;
25  import org.apache.syncope.common.lib.request.AnyCR;
26  import org.apache.syncope.common.lib.request.AnyObjectCR;
27  import org.apache.syncope.common.lib.request.AnyObjectUR;
28  import org.apache.syncope.common.lib.request.AnyUR;
29  import org.apache.syncope.common.lib.to.AnyObjectTO;
30  import org.apache.syncope.common.lib.to.AnyTO;
31  import org.apache.syncope.common.lib.to.PropagationStatus;
32  import org.apache.syncope.common.lib.to.ProvisioningReport;
33  import org.apache.syncope.common.lib.types.AnyTypeKind;
34  import org.apache.syncope.core.persistence.api.entity.Any;
35  import org.apache.syncope.core.persistence.api.entity.AnyUtils;
36  import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject;
37  import org.apache.syncope.core.provisioning.api.AnyObjectProvisioningManager;
38  import org.apache.syncope.core.provisioning.api.ProvisioningManager;
39  import org.apache.syncope.core.provisioning.api.WorkflowResult;
40  import org.apache.syncope.core.provisioning.api.pushpull.AnyObjectPullResultHandler;
41  import org.identityconnectors.framework.common.objects.SyncDelta;
42  import org.springframework.beans.factory.annotation.Autowired;
43  
44  public class DefaultAnyObjectPullResultHandler extends AbstractPullResultHandler implements AnyObjectPullResultHandler {
45  
46      @Autowired
47      private AnyObjectProvisioningManager anyObjectProvisioningManager;
48  
49      @Override
50      protected AnyUtils getAnyUtils() {
51          return anyUtilsFactory.getInstance(AnyTypeKind.ANY_OBJECT);
52      }
53  
54      @Override
55      protected String getName(final AnyTO anyTO) {
56          return AnyObjectTO.class.cast(anyTO).getName();
57      }
58  
59      @Override
60      protected String getName(final AnyCR anyCR) {
61          return AnyObjectCR.class.cast(anyCR).getName();
62      }
63  
64      @Override
65      protected ProvisioningManager<?, ?> getProvisioningManager() {
66          return anyObjectProvisioningManager;
67      }
68  
69      @Override
70      protected AnyTO getAnyTO(final Any<?> any) {
71          return anyObjectDataBinder.getAnyObjectTO((AnyObject) any, true);
72      }
73  
74      @Override
75      protected WorkflowResult<? extends AnyUR> update(final AnyUR req) {
76          return awfAdapter.update((AnyObjectUR) req, profile.getExecutor(), getContext());
77      }
78  
79      @Override
80      protected AnyTO doCreate(final AnyCR anyCR, final SyncDelta delta) {
81          AnyObjectCR anyObjectCR = AnyObjectCR.class.cast(anyCR);
82  
83          Map.Entry<String, List<PropagationStatus>> created = anyObjectProvisioningManager.create(
84                  anyObjectCR,
85                  Set.of(profile.getTask().getResource().getKey()),
86                  true,
87                  profile.getExecutor(),
88                  getContext());
89  
90          return anyObjectDataBinder.getAnyObjectTO(created.getKey());
91      }
92  
93      @Override
94      protected AnyUR doUpdate(
95              final AnyTO before,
96              final AnyUR req,
97              final SyncDelta delta,
98              final ProvisioningReport result) {
99  
100         AnyObjectUR anyObjectUR = AnyObjectUR.class.cast(req);
101 
102         Pair<AnyObjectUR, List<PropagationStatus>> updated = anyObjectProvisioningManager.update(
103                 anyObjectUR,
104                 Set.of(profile.getTask().getResource().getKey()),
105                 true,
106                 profile.getExecutor(),
107                 getContext());
108 
109         createRemediationIfNeeded(req, delta, result);
110 
111         return updated.getLeft();
112     }
113 }