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.persistence.jpa.entity.task;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  import javax.persistence.CascadeType;
24  import javax.persistence.Entity;
25  import javax.persistence.FetchType;
26  import javax.persistence.ManyToOne;
27  import javax.persistence.OneToMany;
28  import javax.persistence.OrderBy;
29  import javax.persistence.Table;
30  import javax.validation.Valid;
31  import javax.validation.constraints.NotNull;
32  import org.apache.syncope.common.lib.types.IdRepoImplementationType;
33  import org.apache.syncope.core.persistence.api.entity.Implementation;
34  import org.apache.syncope.core.persistence.api.entity.Realm;
35  import org.apache.syncope.core.persistence.api.entity.task.FormPropertyDef;
36  import org.apache.syncope.core.persistence.api.entity.task.MacroTask;
37  import org.apache.syncope.core.persistence.api.entity.task.MacroTaskCommand;
38  import org.apache.syncope.core.persistence.api.entity.task.SchedTask;
39  import org.apache.syncope.core.persistence.api.entity.task.TaskExec;
40  import org.apache.syncope.core.persistence.jpa.entity.JPAImplementation;
41  import org.apache.syncope.core.persistence.jpa.entity.JPARealm;
42  
43  @Entity
44  @Table(name = JPAMacroTask.TABLE)
45  public class JPAMacroTask extends JPASchedTask implements MacroTask {
46  
47      private static final long serialVersionUID = 8261850094316787406L;
48  
49      public static final String TABLE = "MacroTask";
50  
51      @ManyToOne(fetch = FetchType.EAGER, optional = false)
52      private JPARealm realm;
53  
54      @NotNull
55      private Boolean continueOnError = false;
56  
57      @NotNull
58      private Boolean saveExecs = true;
59  
60      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true, mappedBy = "macroTask")
61      @OrderBy("idx")
62      private List<JPAMacroTaskCommand> macroTaskCommands = new ArrayList<>();
63  
64      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true, mappedBy = "macroTask")
65      @OrderBy("idx")
66      @Valid
67      private List<JPAFormPropertyDef> formPropertyDefs = new ArrayList<>();
68  
69      @ManyToOne(fetch = FetchType.EAGER)
70      private JPAImplementation macroActions;
71  
72      @OneToMany(targetEntity = JPAMacroTaskExec.class,
73              cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "task")
74      private List<TaskExec<SchedTask>> executions = new ArrayList<>();
75  
76      @Override
77      public Realm getRealm() {
78          return realm;
79      }
80  
81      @Override
82      public void setRealm(final Realm realm) {
83          checkType(realm, JPARealm.class);
84          this.realm = (JPARealm) realm;
85      }
86  
87      @Override
88      public boolean isContinueOnError() {
89          return continueOnError == null ? false : continueOnError;
90      }
91  
92      @Override
93      public void setContinueOnError(final boolean continueOnError) {
94          this.continueOnError = continueOnError;
95      }
96  
97      @Override
98      public boolean isSaveExecs() {
99          return saveExecs == null ? true : saveExecs;
100     }
101 
102     @Override
103     public void setSaveExecs(final boolean saveExecs) {
104         this.saveExecs = saveExecs;
105     }
106 
107     @Override
108     protected Class<? extends TaskExec<SchedTask>> executionClass() {
109         return JPAMacroTaskExec.class;
110     }
111 
112     @Override
113     protected List<TaskExec<SchedTask>> executions() {
114         return executions;
115     }
116 
117     @Override
118     public void add(final MacroTaskCommand macroTaskCommand) {
119         checkType(macroTaskCommand, JPAMacroTaskCommand.class);
120         ((JPAMacroTaskCommand) macroTaskCommand).setIdx(macroTaskCommands.size());
121         macroTaskCommands.add((JPAMacroTaskCommand) macroTaskCommand);
122     }
123 
124     @Override
125     public List<? extends MacroTaskCommand> getCommands() {
126         return macroTaskCommands;
127     }
128 
129     @Override
130     public void add(final FormPropertyDef formPropertyDef) {
131         checkType(formPropertyDef, JPAFormPropertyDef.class);
132         ((JPAFormPropertyDef) formPropertyDef).setIdx(formPropertyDefs.size());
133         formPropertyDefs.add((JPAFormPropertyDef) formPropertyDef);
134     }
135 
136     @Override
137     public List<? extends FormPropertyDef> getFormPropertyDefs() {
138         return formPropertyDefs;
139     }
140 
141     @Override
142     public Implementation getMacroActions() {
143         return macroActions;
144     }
145 
146     @Override
147     public void setMacroAction(final Implementation macroActions) {
148         checkType(macroActions, JPAImplementation.class);
149         checkImplementationType(macroActions, IdRepoImplementationType.MACRO_ACTIONS);
150         this.macroActions = (JPAImplementation) macroActions;
151     }
152 }