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.user;
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.user.LAPlainAttr;
34  import org.apache.syncope.core.persistence.api.entity.user.LAPlainAttrUniqueValue;
35  import org.apache.syncope.core.persistence.api.entity.user.LAPlainAttrValue;
36  import org.apache.syncope.core.persistence.api.entity.user.LinkedAccount;
37  import org.apache.syncope.core.persistence.api.entity.user.User;
38  import org.apache.syncope.core.persistence.jpa.entity.AbstractPlainAttr;
39  
40  @Entity
41  @Table(name = JPALAPlainAttr.TABLE)
42  public class JPALAPlainAttr extends AbstractPlainAttr<User> implements LAPlainAttr {
43  
44      private static final long serialVersionUID = 7827533741035423694L;
45  
46      public static final String TABLE = "LAPlainAttr";
47  
48      /**
49       * The owner of this attribute.
50       */
51      @ManyToOne(fetch = FetchType.EAGER)
52      private JPAUser owner;
53  
54      @ManyToOne(fetch = FetchType.EAGER)
55      private JPALinkedAccount account;
56  
57      /**
58       * Values of this attribute (if schema is not UNIQUE).
59       */
60      @OneToMany(cascade = CascadeType.MERGE, orphanRemoval = true, mappedBy = "attribute")
61      @Valid
62      private List<JPALAPlainAttrValue> values = new ArrayList<>();
63  
64      /**
65       * Value of this attribute (if schema is UNIQUE).
66       */
67      @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "attribute")
68      @Valid
69      private JPALAPlainAttrUniqueValue uniqueValue;
70  
71      @Override
72      public User getOwner() {
73          return owner;
74      }
75  
76      @Override
77      public void setOwner(final User owner) {
78          checkType(owner, JPAUser.class);
79          this.owner = (JPAUser) owner;
80      }
81  
82      @Override
83      public LinkedAccount getAccount() {
84          return account;
85      }
86  
87      @Override
88      public void setAccount(final LinkedAccount account) {
89          checkType(account, JPALinkedAccount.class);
90          this.account = (JPALinkedAccount) account;
91      }
92  
93      @Override
94      protected boolean addForMultiValue(final PlainAttrValue attrValue) {
95          checkType(attrValue, JPALAPlainAttrValue.class);
96          return values.add((JPALAPlainAttrValue) attrValue);
97      }
98  
99      @Override
100     public List<? extends LAPlainAttrValue> getValues() {
101         return values;
102     }
103 
104     @Override
105     public LAPlainAttrUniqueValue getUniqueValue() {
106         return uniqueValue;
107     }
108 
109     @Override
110     public void setUniqueValue(final PlainAttrUniqueValue uniqueValue) {
111         checkType(uniqueValue, JPALAPlainAttrUniqueValue.class);
112         this.uniqueValue = (JPALAPlainAttrUniqueValue) uniqueValue;
113     }
114 }