Initial OpenECOMP policy/engine commit
[policy/engine.git] / ECOMP-REST / src / main / java / org / openecomp / policy / rest / jpa / DescriptiveScope.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP-REST
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.policy.rest.jpa;
22
23 import java.io.Serializable;
24 import java.util.Date;
25
26 import javax.persistence.Column;
27 import javax.persistence.Entity;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.GenerationType;
30 import javax.persistence.Id;
31 import javax.persistence.JoinColumn;
32 import javax.persistence.ManyToOne;
33 import javax.persistence.NamedQuery;
34 import javax.persistence.OrderBy;
35 import javax.persistence.PrePersist;
36 import javax.persistence.PreUpdate;
37 import javax.persistence.Table;
38 import javax.persistence.Temporal;
39 import javax.persistence.TemporalType;
40
41 import org.apache.commons.logging.Log;
42 import org.apache.commons.logging.LogFactory;
43 import org.openecomp.policy.rest.XacmlAdminAuthorization;
44
45 import org.openecomp.policy.common.logging.eelf.MessageCodes;
46 import org.openecomp.policy.common.logging.eelf.PolicyLogger;
47
48
49 @Entity
50 @Table(name = "DescriptiveScope")
51 @NamedQuery(name = "DescriptiveScope.findAll", query= "Select p from DescriptiveScope p")
52 public class DescriptiveScope implements Serializable {
53         private static final long serialVersionUID = 1L;
54         @Id
55         @GeneratedValue(strategy = GenerationType.AUTO)
56         @Column(name = "Id")
57         private int id;
58
59         @Column(name="scopename", nullable=false)
60         @OrderBy("asc")
61         private String descriptiveScopeName;
62
63         @Column(name="description", nullable=true, length=2048)
64         private String description;
65
66         @Column(name="search", nullable=true)
67         @OrderBy("asc")
68         private String search;
69
70         @Temporal(TemporalType.TIMESTAMP)
71         @Column(name="created_date", updatable=false)
72         private Date createdDate;
73
74         @Temporal(TemporalType.TIMESTAMP)
75         @Column(name="modified_date", nullable=false)
76         private Date modifiedDate;
77
78         @ManyToOne(optional = false)
79         @JoinColumn(name="created_by")
80         private UserInfo userCreatedBy;
81
82         @ManyToOne(optional = false)
83         @JoinColumn(name="modified_by")
84         private UserInfo userModifiedBy;
85         
86         public UserInfo getUserCreatedBy() {
87                 return userCreatedBy;
88         }
89
90         public void setUserCreatedBy(UserInfo userCreatedBy) {
91                 this.userCreatedBy = userCreatedBy;
92         }
93
94         public UserInfo getUserModifiedBy() {
95                 return userModifiedBy;
96         }
97
98         public void setUserModifiedBy(UserInfo userModifiedBy) {
99                 this.userModifiedBy = userModifiedBy;
100         }
101
102         private static Log logger = LogFactory.getLog(DescriptiveScope.class);
103         
104         public DescriptiveScope(){
105                 
106         }
107         
108         public DescriptiveScope(String string, String userid) {
109                 this(string);
110         }
111
112         public DescriptiveScope(String domain) {
113                 this.descriptiveScopeName = domain;
114         }       
115         
116         @PrePersist
117         public void     prePersist() {
118                 Date date = new Date();
119                 this.createdDate = date;
120                 this.modifiedDate = date;
121         }
122         
123         @PreUpdate
124         public void preUpdate() {
125                 this.modifiedDate = new Date();
126                 try {
127                         this.userModifiedBy =XacmlAdminAuthorization.getUserId();;
128                 } catch (Exception e) {
129                         logger.error("Exception caused While adding Modified by Role"+e);
130                         // TODO:EELF Cleanup - Remove logger
131                         PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "DescriptiveScope", "Exception caused While adding Modified by Role");
132                 }
133         }
134         
135         public int getId() {
136                 return this.id;
137         }
138         public void setId(int id) {
139                 this.id = id;
140         }
141         
142         public String getScopeName() {
143                 return descriptiveScopeName;
144         }
145
146         public void setScopeName(String descriptiveScopeName) {
147                 this.descriptiveScopeName = descriptiveScopeName;
148         }
149
150         public String getSearch() {
151                 return search;
152         }
153
154         public void setSearch(String search) {
155                 this.search = search;
156         }
157         
158         public Date getCreatedDate() {
159                 return this.createdDate;
160         }
161         
162         public void setCreatedDate(Date createdDate) {
163                 this.createdDate = createdDate;
164         }
165         
166         public String getDescription() {
167                 return this.description;
168         }
169         
170         public void setDescription(String description) {
171                 this.description = description;
172         }
173         
174         public Date getModifiedDate() {
175                 return this.modifiedDate;
176         }
177         
178         public void setModifiedDate(Date modifiedDate) {
179                 this.modifiedDate = modifiedDate;
180         }
181
182 }