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.time.OffsetDateTime;
22  import javax.persistence.Entity;
23  import javax.persistence.EnumType;
24  import javax.persistence.Enumerated;
25  import javax.persistence.Lob;
26  import javax.persistence.ManyToOne;
27  import javax.persistence.Table;
28  import javax.validation.constraints.NotNull;
29  import org.apache.syncope.common.lib.request.AnyCR;
30  import org.apache.syncope.common.lib.request.AnyUR;
31  import org.apache.syncope.common.lib.types.ResourceOperation;
32  import org.apache.syncope.core.persistence.api.entity.AnyType;
33  import org.apache.syncope.core.persistence.api.entity.Remediation;
34  import org.apache.syncope.core.persistence.api.entity.task.PullTask;
35  import org.apache.syncope.core.persistence.jpa.entity.task.JPAPullTask;
36  import org.apache.syncope.core.persistence.jpa.validation.entity.RemediationCheck;
37  import org.apache.syncope.core.provisioning.api.serialization.POJOHelper;
38  
39  @Entity
40  @Table(name = JPARemediation.TABLE)
41  @RemediationCheck
42  public class JPARemediation extends AbstractGeneratedKeyEntity implements Remediation {
43  
44      private static final long serialVersionUID = -1612530286294448682L;
45  
46      public static final String TABLE = "Remediation";
47  
48      @ManyToOne
49      private JPAAnyType anyType;
50  
51      @NotNull
52      @Enumerated(EnumType.STRING)
53      private ResourceOperation operation;
54  
55      @NotNull
56      @Lob
57      private String payload;
58  
59      @NotNull
60      @Lob
61      private String error;
62  
63      @NotNull
64      private OffsetDateTime instant;
65  
66      @ManyToOne
67      private JPAPullTask pullTask;
68  
69      @NotNull
70      private String remoteName;
71  
72      @Override
73      public AnyType getAnyType() {
74          return anyType;
75      }
76  
77      @Override
78      public void setAnyType(final AnyType anyType) {
79          checkType(anyType, JPAAnyType.class);
80          this.anyType = (JPAAnyType) anyType;
81      }
82  
83      @Override
84      public ResourceOperation getOperation() {
85          return operation;
86      }
87  
88      @Override
89      public void setOperation(final ResourceOperation operation) {
90          this.operation = operation;
91      }
92  
93      @Override
94      public <C extends AnyCR> C getPayloadAsCR(final Class<C> reference) {
95          return POJOHelper.deserialize(this.payload, reference);
96      }
97  
98      @Override
99      public <U extends AnyUR> U getPayloadAsUR(final Class<U> reference) {
100         return POJOHelper.deserialize(this.payload, reference);
101     }
102 
103     @Override
104     public String getPayloadAsKey() {
105         return this.payload;
106     }
107 
108     @Override
109     public void setPayload(final AnyCR anyCR) {
110         this.payload = POJOHelper.serialize(anyCR);
111     }
112 
113     @Override
114     public void setPayload(final AnyUR anyUR) {
115         this.payload = POJOHelper.serialize(anyUR);
116     }
117 
118     @Override
119     public void setPayload(final String key) {
120         this.payload = key;
121     }
122 
123     @Override
124     public String getError() {
125         return error;
126     }
127 
128     @Override
129     public void setError(final String error) {
130         this.error = error;
131     }
132 
133     @Override
134     public OffsetDateTime getInstant() {
135         return instant;
136     }
137 
138     @Override
139     public void setInstant(final OffsetDateTime instant) {
140         this.instant = instant;
141     }
142 
143     @Override
144     public PullTask getPullTask() {
145         return pullTask;
146     }
147 
148     @Override
149     public void setPullTask(final PullTask pullTask) {
150         checkType(pullTask, JPAPullTask.class);
151         this.pullTask = (JPAPullTask) pullTask;
152     }
153 
154     @Override
155     public String getRemoteName() {
156         return remoteName;
157     }
158 
159     @Override
160     public void setRemoteName(final String remoteName) {
161         this.remoteName = remoteName;
162     }
163 }