001/*******************************************************************************
002 * Copyright 2017 The MIT Internet Trust Consortium
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *   http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *******************************************************************************/
016
017package org.mitre.uma.model;
018
019import java.util.Set;
020
021import javax.persistence.Basic;
022import javax.persistence.CollectionTable;
023import javax.persistence.Column;
024import javax.persistence.Convert;
025import javax.persistence.ElementCollection;
026import javax.persistence.Entity;
027import javax.persistence.FetchType;
028import javax.persistence.GeneratedValue;
029import javax.persistence.GenerationType;
030import javax.persistence.Id;
031import javax.persistence.JoinColumn;
032import javax.persistence.Table;
033
034import org.mitre.oauth2.model.convert.JsonElementStringConverter;
035
036import com.google.gson.JsonElement;
037
038/**
039 * @author jricher
040 *
041 */
042@Entity
043@Table(name = "claim")
044public class Claim {
045
046        private Long id;
047        private String name;
048        private String friendlyName;
049        private String claimType;
050        private JsonElement value;
051        private Set<String> claimTokenFormat;
052        private Set<String> issuer;
053
054        /**
055         * @return the id
056         */
057        @Id
058        @GeneratedValue(strategy = GenerationType.IDENTITY)
059        @Column(name = "id")
060        public Long getId() {
061                return id;
062        }
063        /**
064         * @param id the id to set
065         */
066        public void setId(Long id) {
067                this.id = id;
068        }
069        /**
070         * @return the name
071         */
072        @Basic
073        @Column(name = "name")
074        public String getName() {
075                return name;
076        }
077        /**
078         * @param name the name to set
079         */
080        public void setName(String name) {
081                this.name = name;
082        }
083
084        /**
085         * @return the friendlyName
086         */
087        @Basic
088        @Column(name = "friendly_name")
089        public String getFriendlyName() {
090                return friendlyName;
091        }
092        /**
093         * @param friendlyName the friendlyName to set
094         */
095        public void setFriendlyName(String friendlyName) {
096                this.friendlyName = friendlyName;
097        }
098
099        /**
100         * @return the claimType
101         */
102        @Basic
103        @Column(name = "claim_type")
104        public String getClaimType() {
105                return claimType;
106        }
107        /**
108         * @param claimType the claimType to set
109         */
110        public void setClaimType(String claimType) {
111                this.claimType = claimType;
112        }
113
114        /**
115         * @return the claimTokenFormat
116         */
117        @ElementCollection(fetch = FetchType.EAGER)
118        @Column(name = "claim_token_format")
119        @CollectionTable(
120                        name = "claim_token_format",
121                        joinColumns = @JoinColumn(name = "owner_id")
122                        )
123        public Set<String> getClaimTokenFormat() {
124                return claimTokenFormat;
125        }
126        /**
127         * @param claimTokenFormat the claimTokenFormat to set
128         */
129        public void setClaimTokenFormat(Set<String> claimTokenFormat) {
130                this.claimTokenFormat = claimTokenFormat;
131        }
132
133        /**
134         * @return the issuer
135         */
136        @ElementCollection(fetch = FetchType.EAGER)
137        @Column(name = "issuer")
138        @CollectionTable(
139                        name = "claim_issuer",
140                        joinColumns = @JoinColumn(name = "owner_id")
141                        )
142        public Set<String> getIssuer() {
143                return issuer;
144        }
145        /**
146         * @param issuer the issuer to set
147         */
148        public void setIssuer(Set<String> issuer) {
149                this.issuer = issuer;
150        }
151
152        /**
153         * @return the value
154         */
155        @Basic
156        @Column(name = "claim_value")
157        @Convert(converter = JsonElementStringConverter.class)
158        public JsonElement getValue() {
159                return value;
160        }
161        /**
162         * @param value the value to set
163         */
164        public void setValue(JsonElement value) {
165                this.value = value;
166        }
167        /* (non-Javadoc)
168         * @see java.lang.Object#toString()
169         */
170        @Override
171        public String toString() {
172                return "Claim [id=" + id + ", name=" + name + ", friendlyName=" + friendlyName + ", claimType=" + claimType + ", value=" + value + ", claimTokenFormat=" + claimTokenFormat + ", issuer=" + issuer + "]";
173        }
174        /* (non-Javadoc)
175         * @see java.lang.Object#hashCode()
176         */
177        @Override
178        public int hashCode() {
179                final int prime = 31;
180                int result = 1;
181                result = prime * result + ((claimTokenFormat == null) ? 0 : claimTokenFormat.hashCode());
182                result = prime * result + ((claimType == null) ? 0 : claimType.hashCode());
183                result = prime * result + ((friendlyName == null) ? 0 : friendlyName.hashCode());
184                result = prime * result + ((id == null) ? 0 : id.hashCode());
185                result = prime * result + ((issuer == null) ? 0 : issuer.hashCode());
186                result = prime * result + ((name == null) ? 0 : name.hashCode());
187                result = prime * result + ((value == null) ? 0 : value.hashCode());
188                return result;
189        }
190        /* (non-Javadoc)
191         * @see java.lang.Object#equals(java.lang.Object)
192         */
193        @Override
194        public boolean equals(Object obj) {
195                if (this == obj) {
196                        return true;
197                }
198                if (obj == null) {
199                        return false;
200                }
201                if (getClass() != obj.getClass()) {
202                        return false;
203                }
204                Claim other = (Claim) obj;
205                if (claimTokenFormat == null) {
206                        if (other.claimTokenFormat != null) {
207                                return false;
208                        }
209                } else if (!claimTokenFormat.equals(other.claimTokenFormat)) {
210                        return false;
211                }
212                if (claimType == null) {
213                        if (other.claimType != null) {
214                                return false;
215                        }
216                } else if (!claimType.equals(other.claimType)) {
217                        return false;
218                }
219                if (friendlyName == null) {
220                        if (other.friendlyName != null) {
221                                return false;
222                        }
223                } else if (!friendlyName.equals(other.friendlyName)) {
224                        return false;
225                }
226                if (id == null) {
227                        if (other.id != null) {
228                                return false;
229                        }
230                } else if (!id.equals(other.id)) {
231                        return false;
232                }
233                if (issuer == null) {
234                        if (other.issuer != null) {
235                                return false;
236                        }
237                } else if (!issuer.equals(other.issuer)) {
238                        return false;
239                }
240                if (name == null) {
241                        if (other.name != null) {
242                                return false;
243                        }
244                } else if (!name.equals(other.name)) {
245                        return false;
246                }
247                if (value == null) {
248                        if (other.value != null) {
249                                return false;
250                        }
251                } else if (!value.equals(other.value)) {
252                        return false;
253                }
254                return true;
255        }
256}