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.onap.policy.std;
23 import java.util.ArrayList;
24 import java.util.Collection;
26 import org.onap.policy.api.LoadedPolicy;
27 import org.onap.policy.api.RemovedPolicy;
28 import org.onap.policy.api.UpdateType;
29 import org.onap.policy.std.StdLoadedPolicy;
30 import org.onap.policy.std.StdPDPNotification;
32 import com.fasterxml.jackson.databind.ObjectMapper;
34 public class NotificationUnMarshal {
35 private static StdPDPNotification notification;
37 public static StdPDPNotification notificationJSON(String json) throws Exception{
38 ObjectMapper mapper = new ObjectMapper();
39 notification = mapper.readValue(json, StdPDPNotification.class);
40 if(notification!=null){
41 if(notification.getLoadedPolicies()!=null){
42 Collection<StdLoadedPolicy> stdLoadedPolicies = new ArrayList<>();
43 for(LoadedPolicy loadedPolicy: notification.getLoadedPolicies()){
44 StdLoadedPolicy stdLoadedPolicy = (StdLoadedPolicy) loadedPolicy;
45 if(notification.getRemovedPolicies()!=null){
46 Boolean updated = false;
47 for(RemovedPolicy removedPolicy: notification.getRemovedPolicies()){
48 String regex = ".(\\d)*.xml";
49 if(removedPolicy.getPolicyName().replaceAll(regex, "").equals(stdLoadedPolicy.getPolicyName().replaceAll(regex, ""))){
55 stdLoadedPolicy.setUpdateType(UpdateType.UPDATE);
57 stdLoadedPolicy.setUpdateType(UpdateType.NEW);
60 stdLoadedPolicy.setUpdateType(UpdateType.NEW);
62 stdLoadedPolicies.add(stdLoadedPolicy);
64 notification.setLoadedPolicies(stdLoadedPolicies);