dfe5c70f3bf44e22f3ca7611e9937b0e9f69d738
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / components / PolicyDBDaoTransaction.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PAP-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.onap.policy.pap.xacml.rest.components;
22
23 import java.util.List;
24
25 import javax.persistence.PersistenceException;
26
27 import org.onap.policy.rest.dao.PolicyDBException;
28 import org.onap.policy.rest.jpa.GroupEntity;
29 import org.onap.policy.rest.jpa.PdpEntity;
30 import org.onap.policy.xacml.api.pap.OnapPDP;
31 import org.onap.policy.xacml.api.pap.OnapPDPGroup;
32
33 import com.att.research.xacml.api.pap.PAPException;
34
35 public interface PolicyDBDaoTransaction {
36
37         /**
38          * Commits (makes permanent) the current transaction. Also, notifies other PolicyDBDao instances on other PAP servers of the update.
39          * @throws IllegalStateException if the PolicyDBDao transaction has not been used or has been committed already.
40          * @throws PersistenceException if the commit fails for some reason
41          */
42         public void commitTransaction();
43         
44         /**
45          * Create or update a policy
46          * @param policy A Policy object representing the policy to store or update
47          * @param username A string of the username you want to be stored for doing this operation
48          * @throws IllegalStateException If a transaction is open that has not yet been committed
49          * @throws PersistenceException If a database error occurs
50          * @throws IllegalArgumentException If the Policy's PolicyRestAdapter contains incorrect data.
51          */
52         public void createPolicy(Policy policy, String username) throws PolicyDBException;
53         
54         /**
55          * Check if the PolicyDBDaoTransaction is currently open
56          * @return False if the PolicyDBDao transaction has not been used or has been committed already, true if it is open.
57          */
58         public boolean isTransactionOpen();
59         
60         
61         
62         /**
63          * Delete an existing policy
64          * @param policyToDelete The file path of the policy to delete
65          * @throws IllegalArgumentException If the file path given can not be parsed
66          * @throws IllegalStateException If a transaction is open that has not yet been committed
67          * @throws PolicyDBException If a database error occurs
68          */
69         public void deletePolicy(String policyToDelete) throws PolicyDBException;
70         
71         /**
72          * Rollback (undo) the current transaction.
73          */
74         public void rollbackTransaction();
75         
76         /**
77          * Close the PolicyDBDaoTransaction without rolling back or doing anything. Just used to close the EntityManager
78          */
79         public void close();
80         
81         
82         /**
83          * Create a new PDP group in the database
84          * @param groupID The ID to name the new group (use PolicyDBDao.createNewPDPGroupId)
85          * @param groupName The name to use for the new group
86          * @param groupDescription Description of the new group (optional)
87          * @param username Username of the user performing the operation
88          * @throws IllegalArgumentException If non-optional parameters are null or empty strings
89          * @throws IllegalStateException If a transaction is already open
90          * @throws PersistenceException If a database error occurs
91          */
92         public void createGroup(String groupID, String groupName, String groupDescription, String username) throws PolicyDBException;
93         
94         /**
95          * Updates a group in the database with a new name of description
96          * @param group The group with updated information. The id must match an existing group, but the name and description can be changed.
97          * @param username Username of the user performing the operation
98          * @throws IllegalArgumentException If non-optional parameters are null or empty strings
99          * @throws IllegalStateException If a transaction is already open
100          * @throws PersistenceException If a database error occurs or if the group can not be found
101          */
102         public void updateGroup(OnapPDPGroup group, String username) throws PolicyDBException;
103         
104         /**
105          * Updates a PDP in the database with new information
106          * @param pdp The PDP to update
107          * @param username Username of the user performing the operation
108          * @throws IllegalArgumentException If non-optional parameters are null or empty strings
109          * @throws IllegalStateException If a transaction is already open
110          * @throws PersistenceException If a database error occurs or if the pdp can not be found
111          */
112         public void updatePdp(OnapPDP pdp, String username) throws PolicyDBException;
113         
114         /**
115          * Change the default group in the database to the group provided.
116          * @param group The new group which should be set as default in the database
117          * @param username Username of the user performing the operation
118          * @throws IllegalArgumentException If non-optional parameters are null or empty strings
119          * @throws IllegalStateException If a transaction is already open
120          * @throws PersistenceException If a database error occurs
121          */
122         public void changeDefaultGroup(OnapPDPGroup group, String username) throws PolicyDBException;
123         
124         /**
125          * Moves a PDP to a new group.
126          * @param pdp The PDP which is to be moved to a new group
127          * @param group The new group which the PDP should be added to
128          * @param username Username of the user performing the operation
129          * @throws IllegalArgumentException If non-optional parameters are null or empty strings
130          * @throws IllegalStateException If a transaction is already open
131          * @throws PersistenceException If a database error occurs
132          */
133         public void movePdp(OnapPDP pdp, OnapPDPGroup group, String username) throws PolicyDBException;
134         
135         /**
136          * Add a new PDP to an existing group
137          * @param pdpID The ID to name the new PDP
138          * @param groupID The ID of the existing group to add the PDP to
139          * @param pdpName The name to use for the new PDP
140          * @param pdpDescription Description of the new PDP (optional)
141          * @param pdpJmxPort
142          * @param username Username of the user performing the operation
143          * @throws IllegalArgumentException If non-optional parameters are null or empty strings
144          * @throws IllegalStateException If a transaction is already open
145          * @throws PersistenceException If a database error occurs
146          */
147         public void addPdpToGroup(String pdpID, String groupID, String pdpName, String pdpDescription, int pdpJmxPort, String username) throws PolicyDBException;
148         
149         /**
150          * Add an existing policy to an existing group
151          * @param group The ID of the existing group to add the policy to
152          * @param policyID The ID of an existing policy
153          * @throws IllegalArgumentException If non-optional parameters are null or empty strings
154          * @throws IllegalStateException If a transaction is already open
155          * @throws PersistenceException If a database error occurs
156          * @throws PolicyDBException 
157          */
158         public void addPolicyToGroup(String group, String policyID, String username) throws PolicyDBException;
159         
160         
161         /**
162          * Delete an existing PDP groupPolicyDBException
163          * @param group A PDPGroup object representing the group to delete
164          * @param moveToGroup A PDPGroup object representing another existing group which PDPs in the group being deleted should be moved to
165          * @throws IllegalArgumentException If non-optional parameters are null or empty strings
166          * @throws IllegalStateException If a transaction is already open
167          * @throws PersistenceException If a database error occurs
168          * @throws PAPException If an error relating to how groups are handled occurs
169          */
170         public void deleteGroup(OnapPDPGroup group, OnapPDPGroup moveToGroup, String username)throws PolicyDBException;
171         
172         /**
173          * Removes an existing PDP from its group and deletes it.
174          * @param pdpID The ID of the existing PDP which should be deleted
175          * @throws IllegalArgumentException If non-optional parameters are null or empty strings
176          * @throws IllegalStateException If a transaction is already open
177          * @throws PersistenceException If a database error occurs
178          */
179         public void removePdpFromGroup(String pdpID, String username) throws PolicyDBException;
180         
181         public GroupEntity getGroup(long groupKey);
182         public GroupEntity getGroup(String groupId);
183         public List<?> getPdpsInGroup(long groupKey);
184         public PdpEntity getPdp(long pdpKey);
185
186         void renamePolicy(String oldPath, String newPath,String username);
187
188         void clonePolicy(String oldPolicyPath, String newPolicyPath, String username);
189                 
190 }