View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  
22  package org.opencastproject.adminui.usersettings.persistence;
23  
24  import static org.opencastproject.util.RequireUtil.notEmpty;
25  
26  import org.opencastproject.adminui.usersettings.UserSetting;
27  
28  import javax.persistence.Column;
29  import javax.persistence.Entity;
30  import javax.persistence.GeneratedValue;
31  import javax.persistence.Id;
32  import javax.persistence.Index;
33  import javax.persistence.Lob;
34  import javax.persistence.NamedQueries;
35  import javax.persistence.NamedQuery;
36  import javax.persistence.Table;
37  import javax.persistence.UniqueConstraint;
38  
39  /** Entity object for user settings. */
40  @Entity(name = "UserSettings")
41  @Table(name = "oc_user_settings", indexes = {
42      @Index(name = "IX_oc_user_setting_organization", columnList = "organization")
43    }, uniqueConstraints = {
44      @UniqueConstraint(columnNames = { "username", "organization" }) })
45  @NamedQueries({
46    @NamedQuery(name = "UserSettings.countByUserName", query = "SELECT COUNT(us) FROM UserSettings us WHERE us.username = :username AND us.organization = :org"),
47    @NamedQuery(name = "UserSettings.findByIdAndUsernameAndOrg", query = "SELECT us FROM UserSettings us WHERE us.id = :id AND us.username = :username AND us.organization = :org"),
48    @NamedQuery(name = "UserSettings.findByUserName", query = "SELECT us FROM UserSettings us WHERE us.username = :username AND us.organization = :org"),
49    @NamedQuery(name = "UserSettings.findByKey", query = "SELECT us FROM UserSettings us WHERE us.key = :key AND us.username = :username AND us.organization = :org"),
50    @NamedQuery(name = "UserSettings.clear", query = "DELETE FROM UserSettings us WHERE us.organization = :org") })
51  public class UserSettingDto {
52    @Id
53    @GeneratedValue
54    @Column(name = "id", nullable = false)
55    private long id;
56  
57    @Column(name = "setting_key", nullable = false)
58    private String key;
59  
60    @Lob
61    @Column(name = "setting_value", nullable = false)
62    private String value;
63  
64    @Column(name = "username", nullable = false, length = 128)
65    private String username;
66  
67    @Column(name = "organization", nullable = false)
68    private String organization;
69  
70    /** Default constructor */
71    public UserSettingDto() {
72    }
73  
74    /**
75     * Creates a user setting
76     * @param id
77     *          A unique id that identifies a user setting.
78     * @param key
79     *          The key to identify which user setting this is.
80     * @param value
81     *          THe value of the of the user setting.
82     * @param username
83     *          The user name to identify which user this user setting is for.
84     * @param organization
85     *          The org that the user belongs to.
86     */
87    public UserSettingDto(long id, String key, String value, String username, String organization) {
88      this.id = id;
89      this.key = notEmpty(key, "key");
90      this.value = notEmpty(value, "value");
91      this.username = username;
92      this.organization = organization;
93    }
94  
95  
96    /**
97     * @return the business object model of this message signature
98     */
99    public UserSetting toUserSetting() {
100     return new UserSetting(id, key, value);
101   }
102 
103   public long getId() {
104     return id;
105   }
106 
107   public void setId(long id) {
108     this.id = id;
109   }
110 
111   public String getKey() {
112     return key;
113   }
114 
115   public void setKey(String key) {
116     this.key = key;
117   }
118 
119   public String getValue() {
120     return value;
121   }
122 
123   public void setValue(String value) {
124     this.value = value;
125   }
126 
127   public String getUsername() {
128     return username;
129   }
130 
131   public void setUsername(String username) {
132     this.username = username;
133   }
134 
135   public String getOrganization() {
136     return organization;
137   }
138 
139   public void setOrganization(String organization) {
140     this.organization = organization;
141   }
142 }