2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.policy.pap.xacml.rest.components;
23 import java.util.List;
25 import javax.persistence.PersistenceException;
27 import org.openecomp.policy.rest.jpa.GroupEntity;
28 import org.openecomp.policy.rest.jpa.PdpEntity;
29 import org.openecomp.policy.xacml.api.pap.EcompPDP;
30 import org.openecomp.policy.xacml.api.pap.EcompPDPGroup;
32 import com.att.research.xacml.api.pap.PAPException;
34 public interface PolicyDBDaoTransaction {
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
41 public void commitTransaction();
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.
51 public void createPolicy(Policy policy, String username) throws IllegalStateException, PersistenceException, IllegalArgumentException;
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.
57 public boolean isTransactionOpen();
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
68 public void deletePolicy(String policyToDelete) throws IllegalStateException, PersistenceException, IllegalArgumentException;
71 * Rollback (undo) the current transaction.
73 public void rollbackTransaction();
76 * Close the PolicyDBDaoTransaction without rolling back or doing anything. Just used to close the EntityManager
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
91 public void createGroup(String groupID, String groupName, String groupDescription, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
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
101 public void updateGroup(EcompPDPGroup group, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
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
111 public void updatePdp(EcompPDP pdp, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
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
121 public void changeDefaultGroup(EcompPDPGroup group, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
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
132 public void movePdp(EcompPDP pdp, EcompPDPGroup group, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
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)
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
146 public void addPdpToGroup(String pdpID, String groupID, String pdpName, String pdpDescription, int pdpJmxPort, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
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
156 public void addPolicyToGroup(String group, String policyID, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
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
168 public void deleteGroup(EcompPDPGroup group, EcompPDPGroup moveToGroup, String username)throws IllegalArgumentException, IllegalStateException, PersistenceException, PAPException;
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
177 public void removePdpFromGroup(String pdpID, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
179 public GroupEntity getGroup(long groupKey);
180 public GroupEntity getGroup(String groupId);
181 public List<?> getPdpsInGroup(long groupKey);
182 public PdpEntity getPdp(long pdpKey);
184 void renamePolicy(String oldPath, String newPath,String username);
186 void clonePolicy(String oldPolicyPath, String newPolicyPath, String username);