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.time.OffsetDateTime;
22  import java.util.ArrayList;
23  import java.util.List;
24  import javax.persistence.CascadeType;
25  import javax.persistence.Column;
26  import javax.persistence.Entity;
27  import javax.persistence.Inheritance;
28  import javax.persistence.InheritanceType;
29  import javax.persistence.OneToMany;
30  import javax.persistence.OneToOne;
31  import javax.persistence.Table;
32  import javax.validation.constraints.NotNull;
33  import org.apache.syncope.common.lib.types.IdRepoImplementationType;
34  import org.apache.syncope.core.persistence.api.entity.Implementation;
35  import org.apache.syncope.core.persistence.api.entity.task.SchedTask;
36  import org.apache.syncope.core.persistence.api.entity.task.TaskExec;
37  import org.apache.syncope.core.persistence.jpa.entity.JPAImplementation;
38  import org.apache.syncope.core.persistence.jpa.validation.entity.SchedTaskCheck;
39  
40  @Entity
41  @Table(name = JPASchedTask.TABLE)
42  @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
43  @SchedTaskCheck
44  public class JPASchedTask extends AbstractTask<SchedTask> implements SchedTask {
45  
46      private static final long serialVersionUID = 7596236684832602180L;
47  
48      public static final String TABLE = "SchedTask";
49  
50      @OneToOne(optional = false)
51      private JPAImplementation jobDelegate;
52  
53      private OffsetDateTime startAt;
54  
55      private String cronExpression;
56  
57      @Column(unique = true, nullable = false)
58      private String name;
59  
60      private String description;
61  
62      @NotNull
63      private Boolean active = true;
64  
65      @OneToMany(targetEntity = JPASchedTaskExec.class,
66              cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "task")
67      private List<TaskExec<SchedTask>> executions = new ArrayList<>();
68  
69      @Override
70      public Implementation getJobDelegate() {
71          return jobDelegate;
72      }
73  
74      @Override
75      public void setJobDelegate(final Implementation jobDelegate) {
76          checkType(jobDelegate, JPAImplementation.class);
77          checkImplementationType(jobDelegate, IdRepoImplementationType.TASKJOB_DELEGATE);
78          this.jobDelegate = (JPAImplementation) jobDelegate;
79      }
80  
81      @Override
82      public OffsetDateTime getStartAt() {
83          return startAt;
84      }
85  
86      @Override
87      public void setStartAt(final OffsetDateTime startAt) {
88          this.startAt = startAt;
89      }
90  
91      @Override
92      public String getCronExpression() {
93          return cronExpression;
94      }
95  
96      @Override
97      public void setCronExpression(final String cronExpression) {
98          this.cronExpression = cronExpression;
99      }
100 
101     @Override
102     public String getDescription() {
103         return description;
104     }
105 
106     @Override
107     public void setDescription(final String description) {
108         this.description = description;
109     }
110 
111     @Override
112     public String getName() {
113         return name;
114     }
115 
116     @Override
117     public void setName(final String name) {
118         this.name = name;
119     }
120 
121     @Override
122     public boolean isActive() {
123         return active;
124     }
125 
126     @Override
127     public void setActive(final boolean active) {
128         this.active = active;
129     }
130 
131     @Override
132     protected Class<? extends TaskExec<SchedTask>> executionClass() {
133         return JPASchedTaskExec.class;
134     }
135 
136     @Override
137     protected List<TaskExec<SchedTask>> executions() {
138         return executions;
139     }
140 }