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.concurrent.RejectedExecutionException;
22  import org.apache.syncope.core.persistence.api.entity.task.PullTask;
23  import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningProfile;
24  import org.apache.syncope.core.provisioning.api.pushpull.PullActions;
25  import org.apache.syncope.core.provisioning.api.pushpull.SyncopePullExecutor;
26  import org.apache.syncope.core.provisioning.api.pushpull.SyncopePullResultHandler;
27  import org.identityconnectors.framework.common.objects.SyncDelta;
28  import org.identityconnectors.framework.common.objects.SyncResultsHandler;
29  import org.springframework.transaction.annotation.Transactional;
30  
31  public class PullResultHandlerDispatcher
32          extends SyncopeResultHandlerDispatcher<PullTask, PullActions, SyncopePullResultHandler>
33          implements SyncResultsHandler {
34  
35      protected final SyncopePullExecutor executor;
36  
37      public PullResultHandlerDispatcher(
38              final ProvisioningProfile<PullTask, PullActions> profile,
39              final SyncopePullExecutor executor) {
40  
41          super(profile);
42          this.executor = executor;
43      }
44  
45      @Transactional
46      @Override
47      public boolean handle(final SyncDelta delta) {
48          if (executor.wasInterruptRequested()) {
49              LOG.debug("Pull interrupted");
50              executor.setInterrupted();
51              return false;
52          }
53  
54          if (tpte.isEmpty()) {
55              boolean result = nonConcurrentHandler(delta.getObjectClass().getObjectClassValue()).handle(delta);
56  
57              executor.reportHandled(delta.getObjectClass().getObjectClassValue(), delta.getObject().getName());
58              if (result) {
59                  executor.setLatestSyncToken(delta.getObjectClass().getObjectClassValue(), delta.getToken());
60              }
61  
62              return result;
63          }
64  
65          try {
66              submit(() -> {
67                  executor.setLatestSyncToken(delta.getObjectClass().getObjectClassValue(), delta.getToken());
68  
69                  suppliers.get(delta.getObjectClass().getObjectClassValue()).get().handle(delta);
70  
71                  executor.reportHandled(delta.getObjectClass().getObjectClassValue(), delta.getObject().getName());
72              });
73              return true;
74          } catch (RejectedExecutionException e) {
75              LOG.error("Could not submit pull handler for {} {}",
76                      delta.getObjectClass().getObjectClassValue(), delta.getObject().getName());
77              return false;
78          }
79      }
80  }