]> git.argeo.org Git - lgpl/argeo-commons.git/blob - security/UserNature.java
Prepare next development cycle
[lgpl/argeo-commons.git] / security / UserNature.java
1 package org.argeo.security;
2
3 import java.io.Serializable;
4 import java.util.List;
5
6 import org.argeo.ArgeoException;
7
8 public class UserNature implements Serializable {
9 private static final long serialVersionUID = 1L;
10
11 private String type;
12
13 public String getType() {
14 if (type != null)
15 return type;
16 else
17 return getClass().getName();
18 }
19
20 public void setType(String type) {
21 this.type = type;
22 }
23
24 public final static void updateUserNaturesWithCheck(
25 List<UserNature> userNatures, List<UserNature> userNaturesData) {
26 if (userNatures.size() != userNaturesData.size())
27 throw new ArgeoException(
28 "It is forbidden to add or remove user natures via this method");
29 for (int i = 0; i < userNatures.size(); i++) {
30 String type = userNatures.get(i).getType();
31 boolean found = false;
32 for (int j = 0; j < userNatures.size(); j++) {
33 String newType = userNaturesData.get(j).getType();
34 if (type.equals(newType))
35 found = true;
36 }
37 if (!found)
38 throw new ArgeoException(
39 "Could not find a user nature of type " + type);
40 }
41
42 for (int i = 0; i < userNatures.size(); i++) {
43 userNatures.set(i, userNaturesData.get(i));
44 }
45 }
46 }