aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/DeleteHandler.java
blob: fd98279e91bd63121854921e6d25ee665445e646 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
/*-
 * ============LICENSE_START=======================================================
 * ONAP-PAP-REST
 * ================================================================================
 * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.policy.pap.xacml.rest.handler;

import com.att.research.xacml.api.pap.PAPException;
import com.att.research.xacml.api.pap.PDPPolicy;
import com.att.research.xacml.util.XACMLProperties;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import javax.script.SimpleBindings;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.onap.policy.common.logging.OnapLoggingContext;
import org.onap.policy.common.logging.eelf.MessageCodes;
import org.onap.policy.common.logging.eelf.PolicyLogger;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.pap.xacml.rest.XACMLPapServlet;
import org.onap.policy.pap.xacml.rest.components.PolicyDBDaoTransaction;
import org.onap.policy.pap.xacml.rest.elk.client.PolicyElasticSearchController;
import org.onap.policy.pap.xacml.rest.model.RemoveGroupPolicy;
import org.onap.policy.pap.xacml.rest.util.JPAUtils;
import org.onap.policy.rest.adapter.PolicyRestAdapter;
import org.onap.policy.rest.dao.CommonClassDao;
import org.onap.policy.rest.jpa.PolicyEntity;
import org.onap.policy.rest.jpa.PolicyVersion;
import org.onap.policy.utils.PolicyUtils;
import org.onap.policy.xacml.api.XACMLErrorConstants;
import org.onap.policy.xacml.api.pap.OnapPDPGroup;
import org.onap.policy.xacml.std.pap.StdPAPPolicy;
import org.onap.policy.xacml.std.pap.StdPDPGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class DeleteHandler {

    private static CommonClassDao commonClassDao;

    @Autowired
    public DeleteHandler(CommonClassDao commonClassDao) {
        DeleteHandler.commonClassDao = commonClassDao;
    }

    public DeleteHandler() {
        // Default Constructor
    }

    private OnapPDPGroup newgroup;
    private static final Logger LOGGER = FlexLogger.getLogger(DeleteHandler.class);
    private static final String POLICY_IN_PDP = "PolicyInPDP";
    private static final String ERROR = "error";
    private static final String MESSAGE = "message";
    private static final String UNKNOWN = "unknown";
    private static final String SUCCESS = "success";
    private static final String OPERATION = "operation";
    private static final String CONFIG = "Config_";
    private static final String REGEX = "[0-9a-zA-Z._]*";
    private static final String DELETE = "delete";
    private static final String ACTION = "Action_";

    /**
     * Do API delete from PAP.
     *
     * @param request the request
     * @param response the response
     * @throws IOException Signals that an I/O exception has occurred.
     */
    public void doApiDeleteFromPap(HttpServletRequest request, HttpServletResponse response) throws IOException {
        // get the request content into a String
        String json = null;
        java.util.Scanner scanner = new java.util.Scanner(request.getInputStream());
        scanner.useDelimiter("\\A");
        json = scanner.hasNext() ? scanner.next() : "";
        scanner.close();
        PolicyLogger.info("JSON request from API to Delete Policy from the PAP: " + json);
        // convert Object sent as JSON into local object
        StdPAPPolicy policy = PolicyUtils.jsonStringToObject(json, StdPAPPolicy.class);
        String policyName = policy.getPolicyName();
        boolean policyVersionDeleted = false;
        String removeXmlExtension;
        int currentVersion;
        String removeVersionExtension;
        String splitPolicyName = null;
        String[] split = null;
        String status = ERROR;
        PolicyEntity policyEntity = null;
        JPAUtils jpaUtils = null;

        try {
            jpaUtils = JPAUtils.getJPAUtilsInstance();
        } catch (Exception e) {
            PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "doAPIDeleteFromPAP",
                    " Could not create JPAUtils instance on the PAP");
            response.addHeader(ERROR, "jpautils");
            response.addHeader(OPERATION, DELETE);
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return;
        }
        if (jpaUtils.dbLockdownIgnoreErrors()) {
            PolicyLogger.warn("Policies are locked down");
            response.addHeader(OPERATION, DELETE);
            response.addHeader("lockdown", "true");
            response.setStatus(HttpServletResponse.SC_ACCEPTED);
            return;
        }
        String policyEntityQuery = null;
        try {
            if (policyName.endsWith(".xml")) {
                removeXmlExtension = policyName.replace(".xml", "");
                currentVersion =
                        Integer.parseInt(removeXmlExtension.substring(removeXmlExtension.lastIndexOf('.') + 1));
                removeVersionExtension = removeXmlExtension.substring(0, removeXmlExtension.lastIndexOf('.'));
                boolean queryCheck = true;
                if ("All Versions".equalsIgnoreCase(policy.getDeleteCondition())) {
                    if (policyName.contains(CONFIG)) {
                        splitPolicyName = removeVersionExtension.replace(".Config_", ":Config_");
                    } else if (policyName.contains(ACTION)) {
                        splitPolicyName = removeVersionExtension.replace(".Action_", ":Action_");
                    } else if (policyName.contains("Decision_")) {
                        splitPolicyName = removeVersionExtension.replace(".Decision_", ":Decision_");
                    }
                    if (splitPolicyName != null) {
                        split = splitPolicyName.split(":");
                    } else {
                        PolicyLogger.error(MessageCodes.ERROR_UNKNOWN
                                + "Failed to delete the policy. Please, provide the valid policyname.");
                        response.addHeader(ERROR, UNKNOWN);
                        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                        return;
                    }
                    policyEntityQuery =
                            "SELECT p FROM PolicyEntity p WHERE p.policyName LIKE :pName and p.scope=:pScope";
                } else if ("Current Version".equalsIgnoreCase(policy.getDeleteCondition())) {
                    if (policyName.contains(CONFIG)) {
                        splitPolicyName = policyName.replace(".Config_", ":Config_");
                    } else if (policyName.contains(ACTION)) {
                        splitPolicyName = policyName.replace(".Action_", ":Action_");
                    } else if (policyName.contains("Decision_")) {
                        splitPolicyName = policyName.replace(".Decision_", ":Decision_");
                    }
                    split = splitPolicyName.split(":");
                    queryCheck = false;
                    policyEntityQuery = "SELECT p FROM PolicyEntity p WHERE p.policyName=:pName and p.scope=:pScope";
                }
                SimpleBindings params = new SimpleBindings();
                if (queryCheck) {
                    params.put("pName", "%" + split[1] + "%");
                } else {
                    params.put("pName", split[1]);
                }

                params.put("pScope", split[0]);
                List<?> peResult = commonClassDao.getDataByQuery(policyEntityQuery, params);
                if (!peResult.isEmpty()) {
                    String getPolicyVersion = "Select p from PolicyVersion p where p.policyName=:pname";
                    SimpleBindings pvParams = new SimpleBindings();
                    pvParams.put("pname", removeVersionExtension.replace(".", File.separator));
                    List<?> pvResult = commonClassDao.getDataByQuery(getPolicyVersion, pvParams);
                    PolicyVersion polVersion = (PolicyVersion) pvResult.get(0);
                    int newVersion = 0;
                    if ("All Versions".equalsIgnoreCase(policy.getDeleteCondition())) {
                        boolean groupCheck = checkPolicyGroupEntity(peResult);
                        if (!groupCheck) {
                            for (Object peData : peResult) {
                                policyEntity = (PolicyEntity) peData;
                                status = deletePolicyEntityData(policyEntity);
                            }
                        } else {
                            status = POLICY_IN_PDP;
                        }
                        switch (status) {
                            case ERROR:
                                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE
                                        + "Exception Occured while deleting the Entity from Database.");
                                response.addHeader(ERROR, UNKNOWN);
                                response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                                return;
                            case POLICY_IN_PDP:
                                PolicyLogger.error(MessageCodes.GENERAL_WARNING
                                        + "Policy can't be deleted, it is active in PDP Groups.");
                                response.addHeader(ERROR, POLICY_IN_PDP);
                                response.setStatus(HttpServletResponse.SC_CONFLICT);
                                return;
                            default:
                                try {
                                    policyVersionDeleted = true;
                                    commonClassDao.delete(polVersion);
                                } catch (Exception e) {
                                    LOGGER.error(e.getMessage(), e);
                                    policyVersionDeleted = false;
                                }
                                break;
                        }
                    } else if ("Current Version".equalsIgnoreCase(policy.getDeleteCondition())) {
                        boolean groupCheck = checkPolicyGroupEntity(peResult);
                        if (!groupCheck) {
                            policyEntity = (PolicyEntity) peResult.get(0);
                            status = deletePolicyEntityData(policyEntity);
                        } else {
                            status = POLICY_IN_PDP;
                        }

                        if (ERROR.equals(status)) {
                            PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE
                                    + "Exception Occured while deleting the Entity from Database.");
                            response.addHeader(ERROR, UNKNOWN);
                            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                            return;
                        } else if (POLICY_IN_PDP.equals(status)) {
                            PolicyLogger.error(MessageCodes.GENERAL_WARNING
                                    + "Policy can't be deleted, it is active in PDP Groups.");
                            response.addHeader(ERROR, POLICY_IN_PDP);
                            response.setStatus(HttpServletResponse.SC_CONFLICT);
                            return;
                        } else {
                            if (currentVersion > 1) {
                                if (!peResult.isEmpty()) {
                                    for (Object object : peResult) {
                                        policyEntity = (PolicyEntity) object;
                                        String policyEntityName = policyEntity.getPolicyName().replace(".xml", "");
                                        int policyEntityVersion = Integer.parseInt(
                                                policyEntityName.substring(policyEntityName.lastIndexOf('.') + 1));
                                        if (policyEntityVersion > newVersion) {
                                            newVersion = policyEntityVersion - 1;
                                        }
                                    }
                                }
                                polVersion.setActiveVersion(newVersion);
                                polVersion.setHigherVersion(newVersion);
                                try {
                                    policyVersionDeleted = true;
                                    commonClassDao.save(polVersion);
                                } catch (Exception e) {
                                    LOGGER.error(e.getMessage(), e);
                                    policyVersionDeleted = false;
                                }
                            } else {
                                try {
                                    policyVersionDeleted = true;
                                    commonClassDao.delete(polVersion);
                                } catch (Exception e) {
                                    LOGGER.error(e.getMessage(), e);
                                    policyVersionDeleted = false;
                                }
                            }
                        }
                    }
                } else {
                    PolicyLogger.error(MessageCodes.ERROR_UNKNOWN
                            + "Failed to delete the policy for an unknown reason.  Check the file system and other logs"
                            + " for further information.");
                    response.addHeader(ERROR, UNKNOWN);
                    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return;
                }
            }
        } catch (Exception e) {
            PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " ERROR");
            response.addHeader(ERROR, "deleteDB");
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return;
        }

        if (policyVersionDeleted) {
            response.setStatus(HttpServletResponse.SC_OK);
            response.addHeader("successMapKey", SUCCESS);
            response.addHeader(OPERATION, DELETE);
        } else {
            PolicyLogger.error(MessageCodes.ERROR_UNKNOWN
                    + "Failed to delete the policy for an unknown reason.  Check the file system and other logs for "
                    + "further information.");
            response.addHeader(ERROR, UNKNOWN);
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    }

    /**
     * Delete policy entity data.
     *
     * @param policyEntity the policy entity
     * @return the string
     */
    public static String deletePolicyEntityData(PolicyEntity policyEntity) {
        PolicyElasticSearchController controller = new PolicyElasticSearchController();
        PolicyRestAdapter policyData = new PolicyRestAdapter();
        String policyName = policyEntity.getPolicyName();
        try {
            if (policyName.contains("CONFIG") || policyName.contains("Decision_MS_")) {
                commonClassDao.delete(policyEntity.getConfigurationData());
            } else if (policyName.contains(ACTION)) {
                commonClassDao.delete(policyEntity.getActionBodyEntity());
            }
            String searchPolicyName = policyEntity.getScope() + "." + policyEntity.getPolicyName();
            policyData.setNewFileName(searchPolicyName);
            controller.deleteElk(policyData);
            commonClassDao.delete(policyEntity);
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            return ERROR;
        }
        return SUCCESS;
    }

    /**
     * Check policy group entity.
     *
     * @param peResult the pe result
     * @return true, if successful
     */
    public static boolean checkPolicyGroupEntity(List<?> peResult) {
        String groupEntityquery = "from PolicyGroupEntity where policyid = :policyEntityId";
        for (Object peData : peResult) {
            PolicyEntity policyEntity = (PolicyEntity) peData;
            SimpleBindings geParams = new SimpleBindings();
            geParams.put("policyEntityId", policyEntity.getPolicyId());
            List<Object> groupobject = commonClassDao.getDataByQuery(groupEntityquery, geParams);
            if (!groupobject.isEmpty()) {
                return true;
            }
        }
        return false;
    }

    /**
     * Do API delete from PDP.
     *
     * @param request the request
     * @param response the response
     * @param loggingContext the logging context
     * @throws IOException Signals that an I/O exception has occurred.
     */
    public void doApiDeleteFromPdp(HttpServletRequest request, HttpServletResponse response,
            OnapLoggingContext loggingContext) throws IOException {

        String groupId = request.getParameter("groupId");

        if (groupId != null && !groupId.matches(REGEX)) {
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            response.addHeader(ERROR, ERROR);
            response.addHeader(MESSAGE, "Group Id is not valid");
            return;
        }
        String requestId = request.getHeader("X-ECOMP-RequestID");
        String polName = request.getParameter("policyName");
        LOGGER.info("JSON request from API to Delete Policy from the PDP - " + polName + " -RequestId - " + requestId);

        // for PUT operations the group may or may not need to exist before the operation can be
        // done
        OnapPDPGroup group = null;
        try {
            group = XACMLPapServlet.getPAPEngine().getGroup(groupId);
        } catch (PAPException e) {
            LOGGER.error("Exception occured While PUT operation is performing for PDP Group" + " -  RequestId - "
                    + requestId + e);
        }
        if (group == null) {
            String message = "Unknown groupId '" + groupId + "'.";
            LOGGER.error(MessageCodes.ERROR_DATA_ISSUE + " - RequestId -  " + requestId + " - " + message);
            loggingContext.transactionEnded();
            PolicyLogger.audit("Transaction Failed - See Error.log");
            response.addHeader(ERROR, "UnknownGroup");
            response.addHeader(MESSAGE, message);
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
        loggingContext.setServiceName("API:PAP.deletPolicyFromPDPGroup");
        RemoveGroupPolicy removePolicy = new RemoveGroupPolicy((StdPDPGroup) group);
        removePolicy.prepareToRemove();
        List<String> policyIdList = Arrays.asList(polName.split(","));
        for (String policyName : policyIdList) {
            if (!policyName.endsWith("xml")) {
                String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid policyName... "
                        + "policyName must be the full name of the file to be deleted including version and extension";
                LOGGER.error(message + "   - RequestId - " + requestId);
                response.addHeader(ERROR, message);
                response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                return;
            }
            PDPPolicy policy = group.getPolicy(policyName);
            if (policy == null) {
                String message =
                        XACMLErrorConstants.ERROR_DATA_ISSUE + "Policy does not exist on the PDP - " + policyName;
                LOGGER.error(message + " - RequestId   - " + requestId);
                response.addHeader(ERROR, message);
                response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                return;
            }
            if (StringUtils.indexOfAny(policy.getId(), "Config_MS_", "BRMS_Param") >= 0) {
                preSafetyCheck(policy);
            }
            LOGGER.info("Preparing to remove policy from group: " + group.getId() + "- RequestId - " + requestId);
            removePolicy.removePolicy(policy);
        }
        OnapPDPGroup updatedGroup = removePolicy.getUpdatedObject();
        String userId = request.getParameter("userId");
        String responseString = deletePolicyFromPdpGroup(updatedGroup, loggingContext, userId);

        switch (responseString) {
            case SUCCESS:
                loggingContext.transactionEnded();
                LOGGER.info("Policy successfully removed from PDP - " + polName + " -   RequestId - " + requestId);
                PolicyLogger.audit("Policy successfully deleted!");
                response.setStatus(HttpServletResponse.SC_OK);
                response.addHeader("successMapKey", SUCCESS);
                response.addHeader(OPERATION, DELETE);
                break;
            case "No Group":
                String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Group update had bad input.";
                LOGGER.error(message + " - RequestId - " + requestId);
                response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                response.addHeader(ERROR, "groupUpdate");
                response.addHeader(MESSAGE, message);
                break;
            case "DB Error":
                LOGGER.error(MessageCodes.ERROR_PROCESS_FLOW + " Error while updating group in the database"
                        + " - RequestId - " + requestId);
                response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                response.addHeader(ERROR, "deleteDB");
                break;
            default:
                LOGGER.error(MessageCodes.ERROR_UNKNOWN
                        + " Failed to delete the policy for an unknown reason.  Check the file system and other logs "
                        + "for " + "further information.");
                response.addHeader(ERROR, UNKNOWN);
                response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                break;
        }
    }

    private String deletePolicyFromPdpGroup(OnapPDPGroup group, OnapLoggingContext loggingContext, String userId) {
        PolicyDBDaoTransaction acPutTransaction = XACMLPapServlet.getDbDaoTransaction();
        String response = null;
        loggingContext.setServiceName("API:PAP.DeleteHandler");
        OnapPDPGroup existingGroup = null;
        try {
            existingGroup = XACMLPapServlet.getPAPEngine().getGroup(group.getId());
        } catch (PAPException e1) {
            PolicyLogger.error("Exception occured While Deleting Policy From PDP Group" + e1);
        }
        if (!(group instanceof StdPDPGroup) || existingGroup == null
                || !(group.getId().equals(existingGroup.getId()))) {
            String existingId = null;
            if (existingGroup != null) {
                existingId = existingGroup.getId();
            }
            PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Group update had bad input. id=" + existingId
                    + " objectFromJSON=" + group);
            loggingContext.transactionEnded();
            PolicyLogger.audit("Transaction Failed - See Error.log");
            response = "No Group";
            return response;
        }
        // The Path on the PAP side is not carried on the RESTful interface with the AC
        // (because it is local to the PAP)
        // so we need to fill that in before submitting the group for update
        ((StdPDPGroup) group).setDirectory(((StdPDPGroup) existingGroup).getDirectory());
        try {
            acPutTransaction.updateGroup(group, "XACMLPapServlet.doDelete", userId);
        } catch (Exception e) {
            PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet",
                    " Error while updating group in the database: " + "group=" + existingGroup.getId());
            response = "DB Error";
            return response;
        }
        try {
            XACMLPapServlet.getPAPEngine().updateGroup(group);
        } catch (PAPException e) {
            PolicyLogger.error("Exception occured While Updating PDP Groups" + e);
            response = "error in updateGroup method";
        }
        PolicyLogger.debug("Group '" + group.getId() + "' updated");
        acPutTransaction.commitTransaction();
        // Group changed, which might include changing the policies
        try {
            newgroup = existingGroup;
        } catch (Exception e) {
            PolicyLogger.error("Exception occured in Group Change Method" + e);
            response = "error in groupChanged method";
        }
        if (response == null) {
            response = SUCCESS;
            loggingContext.transactionEnded();
            PolicyLogger.audit("Policy successfully deleted!");
        }
        loggingContext.transactionEnded();
        PolicyLogger.audit("Transaction Ended");
        return response;
    }

    public OnapPDPGroup getDeletedGroup() {
        return newgroup;
    }

    public boolean preSafetyCheck(PDPPolicy policy) {
        return true;
    }

    /**
     * Gets the single instance of DeleteHandler.
     *
     * @return single instance of DeleteHandler
     */
    public static DeleteHandler getInstance() {
        try {
            Class<?> deleteHandler = Class
                    .forName(XACMLProperties.getProperty("deletePolicy.impl.className", DeleteHandler.class.getName()));
            return (DeleteHandler) deleteHandler.newInstance();
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
        return null;
    }

}