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 java.util.Optional;
24  import javax.persistence.CascadeType;
25  import javax.persistence.Entity;
26  import javax.persistence.FetchType;
27  import javax.persistence.OneToMany;
28  import javax.persistence.Table;
29  import org.apache.syncope.core.persistence.api.entity.Application;
30  import org.apache.syncope.core.persistence.api.entity.Privilege;
31  import org.apache.syncope.core.persistence.jpa.validation.entity.ApplicationCheck;
32  
33  @Entity
34  @Table(name = JPAApplication.TABLE)
35  @ApplicationCheck
36  public class JPAApplication extends AbstractProvidedKeyEntity implements Application {
37  
38      private static final long serialVersionUID = -5951400197744722305L;
39  
40      public static final String TABLE = "Application";
41  
42      private String description;
43  
44      @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER, mappedBy = "application")
45      private List<JPAPrivilege> privileges = new ArrayList<>();
46  
47      @Override
48      public String getDescription() {
49          return description;
50      }
51  
52      @Override
53      public void setDescription(final String description) {
54          this.description = description;
55      }
56  
57      @Override
58      public boolean add(final Privilege privilege) {
59          checkType(privilege, JPAPrivilege.class);
60          return privileges.contains((JPAPrivilege) privilege) || privileges.add((JPAPrivilege) privilege);
61      }
62  
63      @Override
64      public Optional<? extends Privilege> getPrivilege(final String key) {
65          return privileges.stream().filter(privilege -> privilege.getKey().equals(key)).findFirst();
66      }
67  
68      @Override
69      public List<? extends Privilege> getPrivileges() {
70          return privileges;
71      }
72  }