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.group;
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.group.GPlainAttr;
34  import org.apache.syncope.core.persistence.api.entity.group.GPlainAttrUniqueValue;
35  import org.apache.syncope.core.persistence.api.entity.group.GPlainAttrValue;
36  import org.apache.syncope.core.persistence.api.entity.group.Group;
37  import org.apache.syncope.core.persistence.jpa.entity.AbstractPlainAttr;
38  
39  @Entity
40  @Table(name = JPAGPlainAttr.TABLE)
41  public class JPAGPlainAttr extends AbstractPlainAttr<Group> implements GPlainAttr {
42  
43      private static final long serialVersionUID = 2848159565890995780L;
44  
45      public static final String TABLE = "GPlainAttr";
46  
47      @ManyToOne(fetch = FetchType.EAGER)
48      private JPAGroup owner;
49  
50      @OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, orphanRemoval = true, mappedBy = "attribute")
51      @Valid
52      private List<JPAGPlainAttrValue> values = new ArrayList<>();
53  
54      @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "attribute")
55      @Valid
56      private JPAGPlainAttrUniqueValue uniqueValue;
57  
58      @Override
59      public Group getOwner() {
60          return owner;
61      }
62  
63      @Override
64      public void setOwner(final Group owner) {
65          checkType(owner, JPAGroup.class);
66          this.owner = (JPAGroup) owner;
67      }
68  
69      @Override
70      protected boolean addForMultiValue(final PlainAttrValue attrValue) {
71          checkType(attrValue, JPAGPlainAttrValue.class);
72          return values.add((JPAGPlainAttrValue) attrValue);
73      }
74  
75      @Override
76      public List<? extends GPlainAttrValue> getValues() {
77          return values;
78      }
79  
80      @Override
81      public GPlainAttrUniqueValue getUniqueValue() {
82          return uniqueValue;
83      }
84  
85      @Override
86      public void setUniqueValue(final PlainAttrUniqueValue uniqueValue) {
87          checkType(uniqueValue, JPAGPlainAttrUniqueValue.class);
88          this.uniqueValue = (JPAGPlainAttrUniqueValue) uniqueValue;
89      }
90  }