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.anyobject;
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.OneToOne;
29  import javax.persistence.Table;
30  import javax.validation.Valid;
31  import org.apache.syncope.core.persistence.api.entity.PlainAttrUniqueValue;
32  import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
33  import org.apache.syncope.core.persistence.api.entity.anyobject.AMembership;
34  import org.apache.syncope.core.persistence.api.entity.anyobject.APlainAttr;
35  import org.apache.syncope.core.persistence.api.entity.anyobject.APlainAttrUniqueValue;
36  import org.apache.syncope.core.persistence.api.entity.anyobject.APlainAttrValue;
37  import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject;
38  import org.apache.syncope.core.persistence.jpa.entity.AbstractPlainAttr;
39  
40  @Entity
41  @Table(name = JPAAPlainAttr.TABLE)
42  public class JPAAPlainAttr extends AbstractPlainAttr<AnyObject> implements APlainAttr {
43  
44      private static final long serialVersionUID = 8066058729580952116L;
45  
46      public static final String TABLE = "APlainAttr";
47  
48      @ManyToOne(fetch = FetchType.EAGER)
49      private JPAAnyObject owner;
50  
51      /**
52       * The membership of this attribute; might be {@code NULL} if this attribute is not related to a membership.
53       */
54      @ManyToOne(fetch = FetchType.EAGER)
55      private JPAAMembership membership;
56  
57      @OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, orphanRemoval = true, mappedBy = "attribute")
58      @Valid
59      private List<JPAAPlainAttrValue> values = new ArrayList<>();
60  
61      @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "attribute")
62      @Valid
63      private JPAAPlainAttrUniqueValue uniqueValue;
64  
65      @Override
66      public AnyObject getOwner() {
67          return owner;
68      }
69  
70      @Override
71      public void setOwner(final AnyObject owner) {
72          checkType(owner, JPAAnyObject.class);
73          this.owner = (JPAAnyObject) owner;
74      }
75  
76      @Override
77      public AMembership getMembership() {
78          return membership;
79      }
80  
81      @Override
82      public void setMembership(final AMembership membership) {
83          checkType(membership, JPAAMembership.class);
84          this.membership = (JPAAMembership) membership;
85      }
86  
87      @Override
88      protected boolean addForMultiValue(final PlainAttrValue attrValue) {
89          checkType(attrValue, JPAAPlainAttrValue.class);
90          return values.add((JPAAPlainAttrValue) attrValue);
91      }
92  
93      @Override
94      public List<? extends APlainAttrValue> getValues() {
95          return values;
96      }
97  
98      @Override
99      public APlainAttrUniqueValue getUniqueValue() {
100         return uniqueValue;
101     }
102 
103     @Override
104     public void setUniqueValue(final PlainAttrUniqueValue uniqueValue) {
105         checkType(uniqueValue, JPAAPlainAttrUniqueValue.class);
106         this.uniqueValue = (JPAAPlainAttrUniqueValue) uniqueValue;
107     }
108 }