Merge "Added missing license headers"
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / components / MicroServiceConfigPolicy.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.io.File;
24 import java.io.PrintWriter;
25 import java.net.URI;
26 import java.net.URISyntaxException;
27 import java.nio.file.Path;
28 import java.nio.file.Paths;
29 import java.util.HashMap;
30 import java.util.Iterator;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.Map.Entry;
34
35 import org.apache.commons.io.FilenameUtils;
36 import org.apache.commons.lang.StringUtils;
37 import org.onap.policy.common.logging.eelf.MessageCodes;
38 import org.onap.policy.common.logging.eelf.PolicyLogger;
39 import org.onap.policy.common.logging.flexlogger.FlexLogger;
40 import org.onap.policy.common.logging.flexlogger.Logger;
41 import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl;
42 import org.onap.policy.rest.adapter.PolicyRestAdapter;
43 import org.onap.policy.rest.jpa.MicroServiceModels;
44
45 import com.att.research.xacml.std.IdentifierImpl;
46 import com.fasterxml.jackson.databind.JsonNode;
47 import com.fasterxml.jackson.databind.ObjectMapper;
48 import com.google.common.base.Splitter;
49
50 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType;
51 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
52 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
53 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
54 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType;
55 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
56 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
57 import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType;
58 import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
59 import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory;
60 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
61 import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
62 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; 
63
64 public class MicroServiceConfigPolicy extends Policy {
65         
66         private static final Logger LOGGER = FlexLogger.getLogger(MicroServiceConfigPolicy.class);
67         
68     private static Map<String, String> mapAttribute = new HashMap<>();
69     private static Map<String, String> mapMatch = new HashMap<>();
70
71         private static synchronized Map<String, String> getMatchMap () {
72                 return mapMatch;
73         }
74
75         private static synchronized void setMatchMap(Map<String, String> mm) {
76                 mapMatch = mm;
77         }
78
79         public MicroServiceConfigPolicy() {
80                 super();
81         }
82         
83         public MicroServiceConfigPolicy(PolicyRestAdapter policyAdapter){
84                 this.policyAdapter = policyAdapter;
85         }
86
87         //save configuration of the policy based on the policyname
88         private void saveConfigurations(String policyName, String jsonBody) {
89                 try {
90                         if(policyName.endsWith(".xml")){
91                                 policyName = policyName.replace(".xml", "");
92                         }
93                         PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName +".json");
94                         out.println(jsonBody);
95                         out.close();
96                 } catch (Exception e) {
97                         LOGGER.error("Exception Occured While writing Configuration data"+e);
98                 } 
99         }
100         
101         
102         @Override
103         public Map<String, String> savePolicies() throws Exception {
104
105                 Map<String, String> successMap = new HashMap<>();
106                 if(isPolicyExists()){
107                         successMap.put("EXISTS", "This Policy already exist on the PAP");
108                         return successMap;
109                 }
110
111                 if(!isPreparedToSave()){
112                         //Prep and configure the policy for saving
113                         prepareToSave();
114                 }
115
116                 // Until here we prepared the data and here calling the method to create xml.
117                 Path newPolicyPath = null;
118                 newPolicyPath = Paths.get(policyAdapter.getNewFileName());
119
120                 successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject());  
121         
122                 return successMap;              
123         }
124         
125         //This is the method for preparing the policy for saving.  We have broken it out
126         //separately because the fully configured policy is used for multiple things
127         @Override
128         public boolean prepareToSave() throws Exception{
129
130                 if(isPreparedToSave()){
131                         //we have already done this
132                         return true;
133                 }
134                 
135                 int version = 0;
136                 String policyID = policyAdapter.getPolicyID();
137                 version = policyAdapter.getHighestVersion();
138                 
139                 // Create the Instance for pojo, PolicyType object is used in marshalling.
140                 if (policyAdapter.getPolicyType().equals("Config")) {
141                         PolicyType policyConfig = new PolicyType();
142
143                         policyConfig.setVersion(Integer.toString(version));
144                         policyConfig.setPolicyId(policyID);
145                         policyConfig.setTarget(new TargetType());
146                         policyAdapter.setData(policyConfig);
147                 }
148                 policyName = policyAdapter.getNewFileName();
149                 if (policyAdapter.getData() != null) {
150                         // Save the Configurations file with the policy name with extention based on selection.
151                         String jsonBody = policyAdapter.getJsonBody();
152                         saveConfigurations(policyName, jsonBody);
153                         
154                         // Make sure the filename ends with an extension
155                         if (policyName.endsWith(".xml") == false) {
156                                 policyName = policyName + ".xml";
157                         }
158                         
159         
160                         PolicyType configPolicy = (PolicyType) policyAdapter.getData();
161                         
162                         configPolicy.setDescription(policyAdapter.getPolicyDescription());
163
164                         configPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
165                         
166                         AllOfType allOfOne = new AllOfType();
167                         String fileName = policyAdapter.getNewFileName();
168                         String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
169                         if ((name == null) || (name.equals(""))) {
170                                 name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
171                         }
172                         
173             //setup values for pulling out matching attributes
174             ObjectMapper mapper = new ObjectMapper();
175             JsonNode rootNode = mapper.readTree(policyAdapter.getJsonBody());
176             String matching = null;
177             
178             if (policyAdapter.getTtlDate()==null){
179                 policyAdapter.setTtlDate("NA");
180             }
181             if (policyAdapter.getServiceType().contains("-v")){
182                 matching = getValueFromDictionary(policyAdapter.getServiceType());
183             } else {
184                 String jsonVersion  = StringUtils.replaceEach(rootNode.get("version").toString(), new String[]{"\""}, new String[]{""});
185                 matching = getValueFromDictionary(policyAdapter.getServiceType() + "-v" + jsonVersion);
186             }
187
188             Map<String, String> matchMap = null;
189             if (matching != null && !matching.isEmpty()){
190                 matchMap = Splitter.on(",").withKeyValueSeparator("=").split(matching);
191                 setMatchMap(matchMap);
192                 if(policyAdapter.getJsonBody() != null){
193                     pullMatchValue(rootNode);           
194                 }
195             }
196             
197                         // Match for policyName
198                         allOfOne.getMatch().add(createMatch("PolicyName", name));
199                         
200                         AllOfType allOf = new AllOfType();
201                 
202                         // Adding the matches to AllOfType element Match for Onap
203                         allOf.getMatch().add(createMatch("ONAPName", policyAdapter.getOnapName()));
204                         if (matchMap==null || matchMap.isEmpty()){
205                                 // Match for ConfigName
206                                 allOf.getMatch().add(createMatch("ConfigName", policyAdapter.getConfigName()));
207                                 // Match for Service
208                                 allOf.getMatch().add(createDynamicMatch("service", policyAdapter.getServiceType()));
209                                 // Match for uuid
210                                 allOf.getMatch().add(createDynamicMatch("uuid", policyAdapter.getUuid()));
211                                 // Match for location
212                                 allOf.getMatch().add(createDynamicMatch("location", policyAdapter.getLocation()));
213                         }else {
214                                 for (Entry<String, String> matchValue : matchMap.entrySet()){
215                                         String value = matchValue.getValue();
216                                         String key = matchValue.getKey().trim();
217                                         if (value.contains("matching-true")){
218                                                 if (mapAttribute.containsKey(key)){
219                                                         allOf.getMatch().add(createDynamicMatch(key, mapAttribute.get(key)));
220                                                 }
221                                         }
222                                 }
223                         }
224                         // Match for riskType
225                         allOf.getMatch().add(
226                                         createDynamicMatch("RiskType", policyAdapter.getRiskType()));
227                         // Match for riskLevel
228                         allOf.getMatch().add(
229                                         createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
230                         // Match for riskguard
231                         allOf.getMatch().add(
232                                         createDynamicMatch("guard", policyAdapter.getGuard()));
233                         // Match for ttlDate
234                         allOf.getMatch().add(
235                                         createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
236
237                         AnyOfType anyOf = new AnyOfType();
238                         anyOf.getAllOf().add(allOfOne);
239                         anyOf.getAllOf().add(allOf);
240
241                         TargetType target = new TargetType();
242                         ((TargetType) target).getAnyOf().add(anyOf);
243                         
244                         // Adding the target to the policy element
245                         configPolicy.setTarget((TargetType) target);
246
247                         RuleType rule = new RuleType();
248                         rule.setRuleId(policyAdapter.getRuleID());
249                         
250                         rule.setEffect(EffectType.PERMIT);
251                         
252                         // Create Target in Rule
253                         AllOfType allOfInRule = new AllOfType();
254
255                         // Creating match for ACCESS in rule target
256                         MatchType accessMatch = new MatchType();
257                         AttributeValueType accessAttributeValue = new AttributeValueType();
258                         accessAttributeValue.setDataType(STRING_DATATYPE);
259                         accessAttributeValue.getContent().add("ACCESS");
260                         accessMatch.setAttributeValue(accessAttributeValue);
261                         AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
262                         URI accessURI = null;
263                         try {
264                                 accessURI = new URI(ACTION_ID);
265                         } catch (URISyntaxException e) {
266                                 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "MicroServiceConfigPolicy", "Exception creating ACCESS URI");
267                         }
268                         accessAttributeDesignator.setCategory(CATEGORY_ACTION);
269                         accessAttributeDesignator.setDataType(STRING_DATATYPE);
270                         accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue());
271                         accessMatch.setAttributeDesignator(accessAttributeDesignator);
272                         accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
273
274                         // Creating Config Match in rule Target
275                         MatchType configMatch = new MatchType();
276                         AttributeValueType configAttributeValue = new AttributeValueType();
277                         configAttributeValue.setDataType(STRING_DATATYPE);
278                         configAttributeValue.getContent().add("Config");
279                         configMatch.setAttributeValue(configAttributeValue);
280                         AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType();
281                         URI configURI = null;
282                         try {
283                                 configURI = new URI(RESOURCE_ID);
284                         } catch (URISyntaxException e) {
285                                 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "MicroServiceConfigPolicy", "Exception creating Config URI");
286                         }
287                         configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
288                         configAttributeDesignator.setDataType(STRING_DATATYPE);
289                         configAttributeDesignator.setAttributeId(new IdentifierImpl(configURI).stringValue());
290                         configMatch.setAttributeDesignator(configAttributeDesignator);
291                         configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
292
293                         allOfInRule.getMatch().add(accessMatch);
294                         allOfInRule.getMatch().add(configMatch);
295
296                         AnyOfType anyOfInRule = new AnyOfType();
297                         anyOfInRule.getAllOf().add(allOfInRule);
298
299                         TargetType targetInRule = new TargetType();
300                         targetInRule.getAnyOf().add(anyOfInRule);
301
302                         rule.setTarget(targetInRule);
303                         rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
304
305                         configPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
306                         policyAdapter.setPolicyData(configPolicy);
307
308                 } else {
309                         PolicyLogger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName());
310                 }
311                 setPreparedToSave(true);
312                 return true;
313         }
314         
315     private void pullMatchValue(JsonNode rootNode) {
316         Iterator<Map.Entry<String, JsonNode>> fieldsIterator = rootNode.fields();
317         String newValue = null;
318            while (fieldsIterator.hasNext()) {
319                Map.Entry<String, JsonNode> field = fieldsIterator.next();
320                final String key = field.getKey();
321                final JsonNode value = field.getValue();
322                if (value.isContainerNode() && !value.isArray()) {
323                    pullMatchValue(value); // RECURSIVE CALL
324                } else {
325                    newValue = StringUtils.replaceEach(value.toString(), new String[]{"[", "]", "\""}, new String[]{"", "", ""});
326                    mapAttribute.put(key, newValue);
327                }
328            }
329        
330    }
331
332    private String getValueFromDictionary(String service){
333        String ruleTemplate=null;
334        String modelName = service.split("-v")[0];
335        String modelVersion = service.split("-v")[1];
336        
337        CommonClassDaoImpl dbConnection = new CommonClassDaoImpl();
338        List<Object> result = dbConnection.getDataById(MicroServiceModels.class, "modelName:version", modelName+":"+modelVersion);
339        if(result != null && !result.isEmpty()){
340            MicroServiceModels model = (MicroServiceModels) result.get(0);
341            ruleTemplate = model.getAnnotation();
342        }
343        return ruleTemplate;
344    }
345    
346         // Data required for Advice part is setting here.
347         private AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
348                 AdviceExpressionsType advices = new AdviceExpressionsType();
349                 AdviceExpressionType advice = new AdviceExpressionType();
350                 advice.setAdviceId("MSID");
351                 advice.setAppliesTo(EffectType.PERMIT);
352                 // For Configuration
353                 AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
354                 assignment1.setAttributeId("type");
355                 assignment1.setCategory(CATEGORY_RESOURCE);
356                 assignment1.setIssuer("");
357
358                 AttributeValueType configNameAttributeValue = new AttributeValueType();
359                 configNameAttributeValue.setDataType(STRING_DATATYPE);
360                 configNameAttributeValue.getContent().add("Configuration");
361                 assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue));
362
363                 advice.getAttributeAssignmentExpression().add(assignment1);
364                 // For Config file Url if configurations are provided.
365                 AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
366                 assignment2.setAttributeId("URLID");
367                 assignment2.setCategory(CATEGORY_RESOURCE);
368                 assignment2.setIssuer("");
369
370                 AttributeValueType AttributeValue = new AttributeValueType();
371                 AttributeValue.setDataType(URI_DATATYPE);
372                 String configName;
373                 if(policyName.endsWith(".xml")){
374                         configName = policyName.replace(".xml", "");
375                 }else{
376                         configName = policyName;
377                 }
378                 String content = CONFIG_URL +"/Config/" + configName + ".json";
379                 AttributeValue.getContent().add(content);
380                 assignment2.setExpression(new ObjectFactory().createAttributeValue(AttributeValue));
381
382                 advice.getAttributeAssignmentExpression().add(assignment2);
383                 AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
384                 assignment3.setAttributeId("PolicyName");
385                 assignment3.setCategory(CATEGORY_RESOURCE);
386                 assignment3.setIssuer("");
387
388                 AttributeValueType attributeValue3 = new AttributeValueType();
389                 attributeValue3.setDataType(STRING_DATATYPE);
390                 fileName = FilenameUtils.removeExtension(fileName);
391                 fileName = fileName + ".xml";
392                 String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
393                 if ((name == null) || (name.equals(""))) {
394                         name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
395                 }
396                 attributeValue3.getContent().add(name);
397                 assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3));
398                 advice.getAttributeAssignmentExpression().add(assignment3);
399
400                 AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
401                 assignment4.setAttributeId("VersionNumber");
402                 assignment4.setCategory(CATEGORY_RESOURCE);
403                 assignment4.setIssuer("");
404
405                 AttributeValueType configNameAttributeValue4 = new AttributeValueType();
406                 configNameAttributeValue4.setDataType(STRING_DATATYPE);
407                 configNameAttributeValue4.getContent().add(Integer.toString(version));
408                 assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4));
409
410                 advice.getAttributeAssignmentExpression().add(assignment4);
411
412                 AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
413                 assignment5.setAttributeId("matching:" + ONAPID);
414                 assignment5.setCategory(CATEGORY_RESOURCE);
415                 assignment5.setIssuer("");
416
417                 AttributeValueType configNameAttributeValue5 = new AttributeValueType();
418                 configNameAttributeValue5.setDataType(STRING_DATATYPE);
419                 configNameAttributeValue5.getContent().add(policyAdapter.getOnapName());
420                 assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5));
421
422                 advice.getAttributeAssignmentExpression().add(assignment5);
423
424         AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType();
425         assignment7.setAttributeId("matching:service");
426         assignment7.setCategory(CATEGORY_RESOURCE);
427         assignment7.setIssuer("");
428  
429         AttributeValueType configNameAttributeValue7 = new AttributeValueType();
430         configNameAttributeValue7.setDataType(STRING_DATATYPE);
431         configNameAttributeValue7.getContent().add(policyAdapter.getServiceType());
432         assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7));
433  
434         advice.getAttributeAssignmentExpression().add(assignment7);
435
436         Map<String, String> matchMap = getMatchMap();
437         if (matchMap==null || matchMap.isEmpty()){
438                 AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
439                 assignment6.setAttributeId("matching:" + CONFIGID);
440                 assignment6.setCategory(CATEGORY_RESOURCE);
441                 assignment6.setIssuer("");
442
443                 AttributeValueType configNameAttributeValue6 = new AttributeValueType();
444                 configNameAttributeValue6.setDataType(STRING_DATATYPE);
445                 configNameAttributeValue6.getContent().add(policyAdapter.getConfigName());
446                 assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6));
447
448                 advice.getAttributeAssignmentExpression().add(assignment6);
449
450
451                 AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType();
452                 assignment8.setAttributeId("matching:uuid");
453                 assignment8.setCategory(CATEGORY_RESOURCE);
454                 assignment8.setIssuer("");
455
456                 AttributeValueType configNameAttributeValue8 = new AttributeValueType();
457                 configNameAttributeValue8.setDataType(STRING_DATATYPE);
458                 configNameAttributeValue8.getContent().add(policyAdapter.getUuid());
459                 assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8));
460
461                 advice.getAttributeAssignmentExpression().add(assignment8);
462
463                 AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
464                 assignment9.setAttributeId("matching:Location");
465                 assignment9.setCategory(CATEGORY_RESOURCE);
466                 assignment9.setIssuer("");
467
468                 AttributeValueType configNameAttributeValue9 = new AttributeValueType();
469                 configNameAttributeValue9.setDataType(STRING_DATATYPE);
470                 configNameAttributeValue9.getContent().add(policyAdapter.getLocation());
471                 assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
472
473                 advice.getAttributeAssignmentExpression().add(assignment9);
474         } else {
475             for (Entry<String, String> matchValue : matchMap.entrySet()){
476                 String value = matchValue.getValue();
477                 String key = matchValue.getKey().trim();
478                 if (value.contains("matching-true")){
479                     if (mapAttribute.containsKey(key)){
480                         AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
481                         assignment9.setAttributeId("matching:" + key);
482                         assignment9.setCategory(CATEGORY_RESOURCE);
483                         assignment9.setIssuer("");
484                 
485                         AttributeValueType configNameAttributeValue9 = new AttributeValueType();
486                         configNameAttributeValue9.setDataType(STRING_DATATYPE);
487                         configNameAttributeValue9.getContent().add(mapAttribute.get(key));
488                         assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
489                 
490                         advice.getAttributeAssignmentExpression().add(assignment9);
491  
492                     }
493                 }
494             }
495         }
496         
497                 AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType();
498                 assignment10.setAttributeId("Priority");
499                 assignment10.setCategory(CATEGORY_RESOURCE);
500                 assignment10.setIssuer("");
501
502                 AttributeValueType configNameAttributeValue10 = new AttributeValueType();
503                 configNameAttributeValue10.setDataType(STRING_DATATYPE);
504                 configNameAttributeValue10.getContent().add(policyAdapter.getPriority());
505                 assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10));
506
507                 advice.getAttributeAssignmentExpression().add(assignment10);
508                 
509                 //Risk Attributes
510                 AttributeAssignmentExpressionType assignment11 = new AttributeAssignmentExpressionType();
511                 assignment11.setAttributeId("RiskType");
512                 assignment11.setCategory(CATEGORY_RESOURCE);
513                 assignment11.setIssuer("");
514
515                 AttributeValueType configNameAttributeValue11 = new AttributeValueType();
516                 configNameAttributeValue11.setDataType(STRING_DATATYPE);
517                 configNameAttributeValue11.getContent().add(policyAdapter.getRiskType());
518                 assignment11.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue11));
519
520                 advice.getAttributeAssignmentExpression().add(assignment11);
521                 
522                 AttributeAssignmentExpressionType assignment12 = new AttributeAssignmentExpressionType();
523                 assignment12.setAttributeId("RiskLevel");
524                 assignment12.setCategory(CATEGORY_RESOURCE);
525                 assignment12.setIssuer("");
526
527                 AttributeValueType configNameAttributeValue12 = new AttributeValueType();
528                 configNameAttributeValue12.setDataType(STRING_DATATYPE);
529                 configNameAttributeValue12.getContent().add(policyAdapter.getRiskLevel());
530                 assignment12.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue12));
531
532                 advice.getAttributeAssignmentExpression().add(assignment12);    
533
534                 AttributeAssignmentExpressionType assignment13 = new AttributeAssignmentExpressionType();
535                 assignment13.setAttributeId("guard");
536                 assignment13.setCategory(CATEGORY_RESOURCE);
537                 assignment13.setIssuer("");
538
539                 AttributeValueType configNameAttributeValue13 = new AttributeValueType();
540                 configNameAttributeValue13.setDataType(STRING_DATATYPE);
541                 configNameAttributeValue13.getContent().add(policyAdapter.getGuard());
542                 assignment13.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue13));
543
544                 advice.getAttributeAssignmentExpression().add(assignment13);
545                 
546                 AttributeAssignmentExpressionType assignment14 = new AttributeAssignmentExpressionType();
547                 assignment14.setAttributeId("TTLDate");
548                 assignment14.setCategory(CATEGORY_RESOURCE);
549                 assignment14.setIssuer("");
550
551                 AttributeValueType configNameAttributeValue14 = new AttributeValueType();
552                 configNameAttributeValue14.setDataType(STRING_DATATYPE);
553                 configNameAttributeValue14.getContent().add(policyAdapter.getTtlDate());
554                 assignment14.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue14));
555
556                 advice.getAttributeAssignmentExpression().add(assignment14);
557
558                 advices.getAdviceExpression().add(advice);
559                 return advices;
560         }
561
562         @Override
563         public Object getCorrectPolicyDataObject() {
564                 return policyAdapter.getPolicyData();
565         }       
566 }