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.fit.core.reference;
20  
21  import org.apache.syncope.common.lib.Attr;
22  import org.apache.syncope.common.lib.request.AnyCR;
23  import org.apache.syncope.common.lib.request.AnyUR;
24  import org.apache.syncope.common.lib.request.AttrPatch;
25  import org.apache.syncope.common.lib.request.UserCR;
26  import org.apache.syncope.common.lib.to.EntityTO;
27  import org.apache.syncope.common.lib.types.PatchOperation;
28  import org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException;
29  import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningProfile;
30  import org.apache.syncope.core.provisioning.api.pushpull.PullActions;
31  import org.identityconnectors.framework.common.objects.SyncDelta;
32  import org.quartz.JobExecutionException;
33  
34  /**
35   * Test pull action.
36   */
37  public class TestPullActions implements PullActions {
38  
39      private int counter;
40  
41      @Override
42      public void beforeProvision(
43              final ProvisioningProfile<?, ?> profile, final SyncDelta delta, final AnyCR anyCR)
44              throws JobExecutionException {
45  
46          Attr attrTO = anyCR.getPlainAttrs().stream().
47                  filter(attr -> "fullname".equals(attr.getSchema())).findFirst().
48                  orElseGet(() -> {
49                      Attr a = new Attr();
50                      a.setSchema("fullname");
51                      return a;
52                  });
53          attrTO.getValues().clear();
54          attrTO.getValues().add(String.valueOf(counter++));
55      }
56  
57      @Override
58      public void beforeAssign(
59              final ProvisioningProfile<?, ?> profile, final SyncDelta delta, final AnyCR anyCR)
60              throws JobExecutionException {
61  
62          if (anyCR instanceof UserCR && "test2".equals(UserCR.class.cast(anyCR).getUsername())) {
63              throw new IgnoreProvisionException();
64          }
65      }
66  
67      @Override
68      public void beforeUpdate(
69              final ProvisioningProfile<?, ?> profile,
70              final SyncDelta delta,
71              final EntityTO entityTO,
72              final AnyUR anyUR) throws JobExecutionException {
73  
74          AttrPatch fullnamePatch = null;
75          for (AttrPatch attrPatch : anyUR.getPlainAttrs()) {
76              if ("fullname".equals(attrPatch.getAttr().getSchema())) {
77                  fullnamePatch = attrPatch;
78              }
79          }
80          if (fullnamePatch == null) {
81              fullnamePatch = new AttrPatch.Builder(new Attr.Builder("fullname").build()).
82                      operation(PatchOperation.ADD_REPLACE).
83                      build();
84          }
85  
86          fullnamePatch.getAttr().getValues().clear();
87          fullnamePatch.getAttr().getValues().add(String.valueOf(counter++));
88      }
89  }