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.workflow.java;
20  
21  import org.apache.syncope.common.lib.request.AnyObjectCR;
22  import org.apache.syncope.common.lib.request.AnyObjectUR;
23  import org.apache.syncope.common.lib.types.ResourceOperation;
24  import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO;
25  import org.apache.syncope.core.persistence.api.dao.GroupDAO;
26  import org.apache.syncope.core.persistence.api.entity.EntityFactory;
27  import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject;
28  import org.apache.syncope.core.provisioning.api.PropagationByResource;
29  import org.apache.syncope.core.provisioning.api.WorkflowResult;
30  import org.apache.syncope.core.provisioning.api.data.AnyObjectDataBinder;
31  import org.apache.syncope.core.provisioning.api.event.EntityLifecycleEvent;
32  import org.apache.syncope.core.spring.security.AuthContextUtils;
33  import org.identityconnectors.framework.common.objects.SyncDeltaType;
34  import org.springframework.context.ApplicationEventPublisher;
35  
36  /**
37   * Simple implementation basically not involving any workflow engine.
38   */
39  public class DefaultAnyObjectWorkflowAdapter extends AbstractAnyObjectWorkflowAdapter {
40  
41      public DefaultAnyObjectWorkflowAdapter(
42              final AnyObjectDataBinder dataBinder,
43              final AnyObjectDAO anyObjectDAO,
44              final GroupDAO groupDAO,
45              final EntityFactory entityFactory,
46              final ApplicationEventPublisher publisher) {
47  
48          super(dataBinder, anyObjectDAO, groupDAO, entityFactory, publisher);
49      }
50  
51      @Override
52      protected WorkflowResult<String> doCreate(
53              final AnyObjectCR anyObjectCR, final String creator, final String context) {
54  
55          AnyObject anyObject = entityFactory.newEntity(AnyObject.class);
56          dataBinder.create(anyObject, anyObjectCR);
57          metadata(anyObject, creator, context);
58          anyObject = anyObjectDAO.save(anyObject);
59  
60          publisher.publishEvent(
61                  new EntityLifecycleEvent<>(this, SyncDeltaType.CREATE, anyObject, AuthContextUtils.getDomain()));
62  
63          PropagationByResource<String> propByRes = new PropagationByResource<>();
64          propByRes.set(ResourceOperation.CREATE, anyObjectDAO.findAllResourceKeys(anyObject.getKey()));
65  
66          return new WorkflowResult<>(anyObject.getKey(), propByRes, "create");
67      }
68  
69      @Override
70      protected WorkflowResult<AnyObjectUR> doUpdate(
71              final AnyObject anyObject, final AnyObjectUR anyObjectUR, final String updater, final String context) {
72  
73          PropagationByResource<String> propByRes = dataBinder.update(anyObject, anyObjectUR);
74          metadata(anyObject, updater, context);
75          AnyObject updated = anyObjectDAO.save(anyObject);
76  
77          publisher.publishEvent(
78                  new EntityLifecycleEvent<>(this, SyncDeltaType.UPDATE, updated, AuthContextUtils.getDomain()));
79  
80          return new WorkflowResult<>(anyObjectUR, propByRes, "update");
81      }
82  
83      @Override
84      protected void doDelete(final AnyObject anyObject, final String eraser, final String context) {
85          anyObjectDAO.delete(anyObject);
86  
87          publisher.publishEvent(
88                  new EntityLifecycleEvent<>(this, SyncDeltaType.DELETE, anyObject, AuthContextUtils.getDomain()));
89      }
90  }