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 org.apache.syncope.core.persistence.api.entity.Entity;
22  import org.apache.syncope.core.persistence.api.entity.anyobject.APlainAttr;
23  import org.apache.syncope.core.persistence.api.entity.anyobject.APlainAttrUniqueValue;
24  import org.apache.syncope.core.persistence.api.entity.anyobject.APlainAttrValue;
25  import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject;
26  import org.apache.syncope.core.persistence.api.entity.group.GPlainAttr;
27  import org.apache.syncope.core.persistence.api.entity.group.GPlainAttrUniqueValue;
28  import org.apache.syncope.core.persistence.api.entity.group.GPlainAttrValue;
29  import org.apache.syncope.core.persistence.api.entity.group.Group;
30  import org.apache.syncope.core.persistence.api.entity.user.LAPlainAttr;
31  import org.apache.syncope.core.persistence.api.entity.user.LAPlainAttrUniqueValue;
32  import org.apache.syncope.core.persistence.api.entity.user.LAPlainAttrValue;
33  import org.apache.syncope.core.persistence.api.entity.user.LinkedAccount;
34  import org.apache.syncope.core.persistence.api.entity.user.UPlainAttr;
35  import org.apache.syncope.core.persistence.api.entity.user.UPlainAttrUniqueValue;
36  import org.apache.syncope.core.persistence.api.entity.user.UPlainAttrValue;
37  import org.apache.syncope.core.persistence.api.entity.user.User;
38  import org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAJSONAPlainAttr;
39  import org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAJSONAPlainAttrUniqueValue;
40  import org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAJSONAPlainAttrValue;
41  import org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAJSONAnyObject;
42  import org.apache.syncope.core.persistence.jpa.entity.group.JPAJSONGPlainAttr;
43  import org.apache.syncope.core.persistence.jpa.entity.group.JPAJSONGPlainAttrUniqueValue;
44  import org.apache.syncope.core.persistence.jpa.entity.group.JPAJSONGPlainAttrValue;
45  import org.apache.syncope.core.persistence.jpa.entity.group.JPAJSONGroup;
46  import org.apache.syncope.core.persistence.jpa.entity.user.JPAJSONLAPlainAttr;
47  import org.apache.syncope.core.persistence.jpa.entity.user.JPAJSONLAPlainAttrUniqueValue;
48  import org.apache.syncope.core.persistence.jpa.entity.user.JPAJSONLAPlainAttrValue;
49  import org.apache.syncope.core.persistence.jpa.entity.user.JPAJSONLinkedAccount;
50  import org.apache.syncope.core.persistence.jpa.entity.user.JPAJSONUPlainAttr;
51  import org.apache.syncope.core.persistence.jpa.entity.user.JPAJSONUPlainAttrUniqueValue;
52  import org.apache.syncope.core.persistence.jpa.entity.user.JPAJSONUPlainAttrValue;
53  import org.apache.syncope.core.persistence.jpa.entity.user.JPAJSONUser;
54  import org.apache.syncope.core.spring.security.SecureRandomUtils;
55  
56  public abstract class JPAJSONEntityFactory extends JPAEntityFactory {
57  
58      @SuppressWarnings("unchecked")
59      @Override
60      public <E extends Entity> E newEntity(final Class<E> reference) {
61          E result;
62  
63          if (reference.equals(User.class)) {
64              result = (E) new JPAJSONUser();
65              ((JPAJSONUser) result).setKey(SecureRandomUtils.generateRandomUUID().toString());
66          } else if (reference.equals(LinkedAccount.class)) {
67              result = (E) new JPAJSONLinkedAccount();
68              ((JPAJSONLinkedAccount) result).setKey(SecureRandomUtils.generateRandomUUID().toString());
69          } else if (reference.equals(Group.class)) {
70              result = (E) new JPAJSONGroup();
71              ((JPAJSONGroup) result).setKey(SecureRandomUtils.generateRandomUUID().toString());
72          } else if (reference.equals(AnyObject.class)) {
73              result = (E) new JPAJSONAnyObject();
74              ((JPAJSONAnyObject) result).setKey(SecureRandomUtils.generateRandomUUID().toString());
75          } else if (reference.equals(APlainAttr.class)) {
76              result = (E) new JPAJSONAPlainAttr();
77          } else if (reference.equals(APlainAttrValue.class)) {
78              result = (E) new JPAJSONAPlainAttrValue();
79          } else if (reference.equals(APlainAttrUniqueValue.class)) {
80              result = (E) new JPAJSONAPlainAttrUniqueValue();
81          } else if (reference.equals(GPlainAttr.class)) {
82              result = (E) new JPAJSONGPlainAttr();
83          } else if (reference.equals(GPlainAttrValue.class)) {
84              result = (E) new JPAJSONGPlainAttrValue();
85          } else if (reference.equals(GPlainAttrUniqueValue.class)) {
86              result = (E) new JPAJSONGPlainAttrUniqueValue();
87          } else if (reference.equals(UPlainAttr.class)) {
88              result = (E) new JPAJSONUPlainAttr();
89          } else if (reference.equals(UPlainAttrValue.class)) {
90              result = (E) new JPAJSONUPlainAttrValue();
91          } else if (reference.equals(UPlainAttrUniqueValue.class)) {
92              result = (E) new JPAJSONUPlainAttrUniqueValue();
93          } else if (reference.equals(LAPlainAttr.class)) {
94              result = (E) new JPAJSONLAPlainAttr();
95          } else if (reference.equals(LAPlainAttrValue.class)) {
96              result = (E) new JPAJSONLAPlainAttrValue();
97          } else if (reference.equals(LAPlainAttrUniqueValue.class)) {
98              result = (E) new JPAJSONLAPlainAttrUniqueValue();
99          } else {
100             result = super.newEntity(reference);
101         }
102 
103         return result;
104     }
105 
106     @Override
107     public Class<? extends User> userClass() {
108         return JPAJSONUser.class;
109     }
110 
111     @Override
112     public Class<? extends Group> groupClass() {
113         return JPAJSONGroup.class;
114     }
115 
116     @Override
117     public Class<? extends AnyObject> anyObjectClass() {
118         return JPAJSONAnyObject.class;
119     }
120 }