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