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;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  import javax.persistence.CascadeType;
24  import javax.persistence.Column;
25  import javax.persistence.Entity;
26  import javax.persistence.FetchType;
27  import javax.persistence.OneToMany;
28  import javax.persistence.OneToOne;
29  import javax.persistence.Table;
30  import javax.validation.constraints.NotNull;
31  import org.apache.syncope.common.lib.types.IdRepoImplementationType;
32  import org.apache.syncope.core.persistence.api.entity.Implementation;
33  import org.apache.syncope.core.persistence.api.entity.Report;
34  import org.apache.syncope.core.persistence.api.entity.ReportExec;
35  import org.apache.syncope.core.persistence.jpa.validation.entity.ReportCheck;
36  
37  @Entity
38  @Table(name = JPAReport.TABLE)
39  @ReportCheck
40  public class JPAReport extends AbstractGeneratedKeyEntity implements Report {
41  
42      private static final long serialVersionUID = -587652654964285834L;
43  
44      public static final String TABLE = "Report";
45  
46      @OneToOne(optional = false)
47      private JPAImplementation jobDelegate;
48  
49      @Column(unique = true, nullable = false)
50      private String name;
51  
52      @NotNull
53      private String mimeType;
54  
55      @NotNull
56      private String fileExt;
57  
58      private String cronExpression;
59  
60      @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER, mappedBy = "report")
61      private List<JPAReportExec> executions = new ArrayList<>();
62  
63      @NotNull
64      private Boolean active = true;
65  
66      @Override
67      public Implementation getJobDelegate() {
68          return jobDelegate;
69      }
70  
71      @Override
72      public void setJobDelegate(final Implementation jobDelegate) {
73          checkType(jobDelegate, JPAImplementation.class);
74          checkImplementationType(jobDelegate, IdRepoImplementationType.REPORT_DELEGATE);
75          this.jobDelegate = (JPAImplementation) jobDelegate;
76      }
77  
78      @Override
79      public String getName() {
80          return name;
81      }
82  
83      @Override
84      public void setName(final String name) {
85          this.name = name;
86      }
87  
88      @Override
89      public String getMimeType() {
90          return mimeType;
91      }
92  
93      @Override
94      public void setMimeType(final String mimeType) {
95          this.mimeType = mimeType;
96      }
97  
98      @Override
99      public String getFileExt() {
100         return fileExt;
101     }
102 
103     @Override
104     public void setFileExt(final String fileExt) {
105         this.fileExt = fileExt;
106     }
107 
108     @Override
109     public String getCronExpression() {
110         return cronExpression;
111     }
112 
113     @Override
114     public void setCronExpression(final String cronExpression) {
115         this.cronExpression = cronExpression;
116     }
117 
118     @Override
119     public boolean isActive() {
120         return active;
121     }
122 
123     @Override
124     public void setActive(final boolean active) {
125         this.active = active;
126     }
127 
128     @Override
129     public boolean add(final ReportExec exec) {
130         checkType(exec, JPAReportExec.class);
131         return exec != null && !executions.contains((JPAReportExec) exec) && executions.add((JPAReportExec) exec);
132     }
133 
134     @Override
135     public List<? extends ReportExec> getExecs() {
136         return executions;
137     }
138 }