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