Few JUnit additions for PAP-REST
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / components / CreateBrmsParamPolicy.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PAP-REST
4  * ================================================================================
5  * Copyright (C) 2017-2019 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 com.att.research.xacml.api.pap.PAPException;
24 import com.att.research.xacml.std.IdentifierImpl;
25 import com.google.common.annotations.VisibleForTesting;
26 import java.io.File;
27 import java.io.IOException;
28 import java.io.PrintWriter;
29 import java.net.URI;
30 import java.net.URISyntaxException;
31 import java.nio.charset.Charset;
32 import java.nio.file.Files;
33 import java.nio.file.Path;
34 import java.nio.file.Paths;
35 import java.util.ArrayList;
36 import java.util.HashMap;
37 import java.util.Iterator;
38 import java.util.List;
39 import java.util.Map;
40 import java.util.Map.Entry;
41 import java.util.UUID;
42 import java.util.regex.Matcher;
43 import java.util.regex.Pattern;
44 import javax.script.SimpleBindings;
45 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType;
46 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
47 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
48 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
49 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType;
50 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
51 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
52 import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType;
53 import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
54 import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory;
55 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
56 import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
57 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
58 import org.apache.commons.io.FilenameUtils;
59 import org.onap.policy.common.logging.eelf.MessageCodes;
60 import org.onap.policy.common.logging.eelf.PolicyLogger;
61 import org.onap.policy.common.logging.flexlogger.FlexLogger;
62 import org.onap.policy.common.logging.flexlogger.Logger;
63 import org.onap.policy.pap.xacml.rest.controller.BRMSDictionaryController;
64 import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl;
65 import org.onap.policy.rest.adapter.PolicyRestAdapter;
66 import org.onap.policy.rest.jpa.BrmsParamTemplate;
67
68 public class CreateBrmsParamPolicy extends Policy {
69
70     private static final Logger LOGGER = FlexLogger.getLogger(CreateBrmsParamPolicy.class);
71
72     public CreateBrmsParamPolicy() {
73         super();
74     }
75
76     public CreateBrmsParamPolicy(PolicyRestAdapter policyAdapter) {
77         this.policyAdapter = policyAdapter;
78         this.policyAdapter.setConfigType(policyAdapter.getConfigType());
79
80     }
81
82     public String expandConfigBody(String ruleContents, Map<String, String> brmsParamBody) {
83
84         Map<String, String> copyMap = new HashMap<>();
85         copyMap.putAll(brmsParamBody);
86         copyMap.put("policyName", policyName.substring(0, policyName.replace(".xml", "").lastIndexOf('.')));
87         copyMap.put("policyScope", policyAdapter.getDomainDir());
88         copyMap.put("policyVersion", policyAdapter.getHighestVersion().toString());
89         copyMap.put("unique", ("p" + policyName + UUID.randomUUID().toString()).replaceAll("[^A-Za-z0-9]", ""));
90
91         // Finding all the keys in the Map data-structure.
92         Iterator<String> iterator = copyMap.keySet().iterator();
93         Pattern p;
94         Matcher m;
95         while (iterator.hasNext()) {
96             // Converting the first character of the key into a lower case.
97             String input = iterator.next();
98             String output = Character.toLowerCase(input.charAt(0)) + (input.length() > 1 ? input.substring(1) : "");
99             // Searching for a pattern in the String using the key.
100             p = Pattern.compile("\\$\\{" + output + "\\}");
101             m = p.matcher(ruleContents);
102             // Replacing the value with the inputs provided by the user in the editor.
103             String finalInput = copyMap.get(input);
104             if (finalInput.contains("$")) {
105                 finalInput = finalInput.replace("$", "\\$");
106             }
107             ruleContents = m.replaceAll(finalInput);
108         }
109         return ruleContents;
110     }
111
112     // Utility to read json data from the existing file to a string
113     static String readFile(String path, Charset encoding) throws IOException {
114         byte[] encoded = Files.readAllBytes(Paths.get(path));
115         return new String(encoded, encoding);
116     }
117
118     // Saving the Configurations file at server location for config policy.
119     protected void saveConfigurations(String policyName, String ruleBody) {
120         if (policyName.endsWith(".xml")) {
121             policyName = policyName.substring(0, policyName.lastIndexOf(".xml"));
122         }
123         try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName + ".txt")) {
124             String expandedBody = expandConfigBody(ruleBody, policyAdapter.getBrmsParamBody());
125             out.println(expandedBody);
126             policyAdapter.setJsonBody(expandedBody);
127             policyAdapter.setConfigBodyData(expandedBody);
128             out.close();
129         } catch (Exception e) {
130             PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy",
131                 "Exception saving configuration file");
132         }
133     }
134
135     // Here we are adding the extension for the configurations file based on the
136     // config type selection for saving.
137     private String getConfigFile(String filename) {
138         filename = FilenameUtils.removeExtension(filename);
139         if (filename.endsWith(".txt")) {
140             filename = filename.substring(0, filename.length() - 3);
141         }
142
143         filename = filename + ".txt";
144         return filename;
145     }
146
147     // Validations for Config form
148     @Override
149     public boolean validateConfigForm() {
150
151         // Validating mandatory Fields.
152         isValidForm = true;
153         return isValidForm;
154
155     }
156
157     @Override
158     public Map<String, String> savePolicies() throws PAPException {
159
160         Map<String, String> successMap = new HashMap<>();
161         if (isPolicyExists()) {
162             successMap.put("EXISTS", "This Policy already exist on the PAP");
163             return successMap;
164         }
165
166         if (!isPreparedToSave()) {
167             prepareToSave();
168         }
169         // Until here we prepared the data and here calling the method to create
170         // xml.
171         Path newPolicyPath = null;
172         newPolicyPath = Paths.get(policyAdapter.getNewFileName());
173         successMap = createPolicy(newPolicyPath, getCorrectPolicyDataObject());
174         if (successMap == null) {
175             successMap = new HashMap<>();
176             PolicyLogger.error("Failed to Update the Database Dictionary Tables.");
177             successMap.put("error", "DB UPDATE");
178         }
179         return successMap;
180     }
181
182     private String getValueFromDictionary(String templateName) {
183         String ruleTemplate = null;
184         CommonClassDaoImpl dbConnection = new CommonClassDaoImpl();
185         String queryString = "from BrmsParamTemplate where param_template_name= :templateName";
186         SimpleBindings params = new SimpleBindings();
187         params.put("templateName", templateName);
188         List<Object> result = dbConnection.getDataByQuery(queryString, params);
189         if (!result.isEmpty()) {
190             BrmsParamTemplate template = (BrmsParamTemplate) result.get(0);
191             ruleTemplate = template.getRule();
192         }
193         return ruleTemplate;
194     }
195
196     protected Map<String, String> findType(String rule) {
197         Map<String, String> mapFieldType = new HashMap<>();
198         if (rule != null) {
199             try {
200                 StringBuilder params = new StringBuilder();
201                 Boolean flag = false;
202                 Boolean comment = false;
203                 String lines[] = rule.split("\n");
204                 for (String line : lines) {
205                     if (line.isEmpty() || line.startsWith("//")) {
206                         continue;
207                     }
208                     if (line.startsWith("/*")) {
209                         comment = true;
210                         continue;
211                     }
212                     if (line.contains("//") && !(line.contains("http://") || line.contains("https://"))) {
213                         line = line.split("\\/\\/")[0];
214                     }
215                     if (line.contains("/*")) {
216                         comment = true;
217                         if (line.contains("*/")) {
218                             try {
219                                 comment = false;
220                                 line = line.split("\\/\\*")[0] + line.split("\\*\\/")[1].replace("*/", "");
221                             } catch (Exception e) {
222                                 LOGGER.debug(e);
223                                 line = line.split("\\/\\*")[0];
224                             }
225                         } else {
226                             line = line.split("\\/\\*")[0];
227                         }
228                     }
229                     if (line.contains("*/")) {
230                         comment = false;
231                         try {
232                             line = line.split("\\*\\/")[1].replace("*/", "");
233                         } catch (Exception e) {
234                             LOGGER.debug(e);
235                             line = "";
236                         }
237                     }
238                     if (comment) {
239                         continue;
240                     }
241                     if (flag) {
242                         params.append(line);
243                     }
244                     if (line.contains("declare Params")) {
245                         params.append(line);
246                         flag = true;
247                     }
248                     if (line.contains("end") && flag) {
249                         break;
250                     }
251                 }
252                 String param =
253                     params.toString().replace("declare Params", "").replace("end", "").replaceAll("\\s+", "");
254                 String[] components = param.split(":");
255                 String caption = "";
256                 for (int i = 0; i < components.length; i++) {
257                     String type = "";
258                     if (i == 0) {
259                         caption = components[i];
260                     }
261                     if (caption.equals("")) {
262                         break;
263                     }
264                     String nextComponent = "";
265                     try {
266                         nextComponent = components[i + 1];
267                     } catch (Exception e) {
268                         LOGGER.debug(e);
269                         nextComponent = components[i];
270                     }
271                     // If the type is of type String then we add the UI Item and type to the map.
272                     if (nextComponent.startsWith("String")) {
273                         type = "String";
274                         mapFieldType.put(caption, type);
275                         caption = nextComponent.replace("String", "");
276                     } else if (nextComponent.startsWith("int")) {
277                         type = "int";
278                         mapFieldType.put(caption, type);
279                         caption = nextComponent.replace("int", "");
280                     }
281                 }
282             } catch (Exception e) {
283                 PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "CreateBrmsParamPolicy",
284                     "Exception parsing file in findType");
285             }
286         }
287         return mapFieldType;
288     }
289
290     // This is the method for preparing the policy for saving. We have broken it
291     // out
292     // separately because the fully configured policy is used for multiple
293     // things
294     @Override
295     public boolean prepareToSave() throws PAPException {
296
297         if (isPreparedToSave()) {
298             // we have already done this
299             return true;
300         }
301
302         int version = 0;
303         String policyID = policyAdapter.getPolicyID();
304         version = policyAdapter.getHighestVersion();
305
306         // Create the Instance for pojo, PolicyType object is used in
307         // marshalling.
308         if (policyAdapter.getPolicyType().equals("Config")) {
309             PolicyType policyConfig = new PolicyType();
310
311             policyConfig.setVersion(Integer.toString(version));
312             policyConfig.setPolicyId(policyID);
313             policyConfig.setTarget(new TargetType());
314             policyAdapter.setData(policyConfig);
315         }
316
317         policyName = policyAdapter.getNewFileName();
318
319         if (policyAdapter.getData() != null) {
320             Map<String, String> ruleAndUIValue = policyAdapter.getBrmsParamBody();
321             String templateValue = ruleAndUIValue.get("templateName");
322             String valueFromDictionary = getValueFromDictionary(templateValue);
323
324             StringBuilder body = new StringBuilder();
325
326             try {
327                 body.append("/* Autogenerated Code Please Don't change/remove this comment section. This is for the UI "
328                     + "purpose. \n\t " + "<$%BRMSParamTemplate=" + templateValue + "%$> \n");
329                 body.append("<%$Values=");
330                 for (Map.Entry<String, String> entry : ruleAndUIValue.entrySet()) {
331                     String uiKey = entry.getKey();
332                     if (!"templateName".equals(uiKey)) {
333                         body.append(uiKey + ":-:" + entry.getValue() + ":|:");
334                     }
335                 }
336                 body.append("$%> \n*/ \n");
337                 body.append(valueFromDictionary + "\n");
338             } catch (Exception e) {
339                 PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy",
340                     "Exception saving policy");
341             }
342
343             saveConfigurations(policyName, body.toString());
344
345             // Make sure the filename ends with an extension
346             if (!policyName.endsWith(".xml")) {
347                 policyName = policyName + ".xml";
348             }
349
350             PolicyType configPolicy = (PolicyType) policyAdapter.getData();
351
352             configPolicy.setDescription(policyAdapter.getPolicyDescription());
353
354             configPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
355
356             AllOfType allOfOne = new AllOfType();
357
358             String fileName = policyAdapter.getNewFileName();
359             String name = fileName.substring(fileName.lastIndexOf("\\") + 1);
360             if ((name == null) || (name.equals(""))) {
361                 name = fileName.substring(fileName.lastIndexOf("/") + 1);
362             }
363             allOfOne.getMatch().add(createMatch("PolicyName", name));
364
365             AllOfType allOf = new AllOfType();
366
367             // Match for ONAPName
368             allOf.getMatch().add(createMatch("ONAPName", policyAdapter.getOnapName()));
369             allOf.getMatch().add(createMatch("ConfigName", policyAdapter.getConfigName()));
370             // Match for riskType
371             allOf.getMatch().add(createDynamicMatch("RiskType", policyAdapter.getRiskType()));
372             // Match for riskLevel
373             allOf.getMatch().add(createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
374             // Match for riskguard
375             allOf.getMatch().add(createDynamicMatch("guard", policyAdapter.getGuard()));
376             // Match for ttlDate
377             allOf.getMatch().add(createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
378             AnyOfType anyOf = new AnyOfType();
379             anyOf.getAllOf().add(allOfOne);
380             anyOf.getAllOf().add(allOf);
381
382             TargetType target = new TargetType();
383             target.getAnyOf().add(anyOf);
384
385             // Adding the target to the policy element
386             configPolicy.setTarget((TargetType) target);
387
388             RuleType rule = new RuleType();
389             rule.setRuleId(policyAdapter.getRuleID());
390
391             rule.setEffect(EffectType.PERMIT);
392
393             // Create Target in Rule
394             AllOfType allOfInRule = new AllOfType();
395
396             // Creating match for ACCESS in rule target
397             MatchType accessMatch = new MatchType();
398             AttributeValueType accessAttributeValue = new AttributeValueType();
399             accessAttributeValue.setDataType(STRING_DATATYPE);
400             accessAttributeValue.getContent().add("ACCESS");
401             accessMatch.setAttributeValue(accessAttributeValue);
402             AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
403             URI accessURI = null;
404             try {
405                 accessURI = new URI(ACTION_ID);
406             } catch (URISyntaxException e) {
407                 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsParamPolicy",
408                     "Exception creating ACCESS URI");
409             }
410             accessAttributeDesignator.setCategory(CATEGORY_ACTION);
411             accessAttributeDesignator.setDataType(STRING_DATATYPE);
412             accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue());
413             accessMatch.setAttributeDesignator(accessAttributeDesignator);
414             accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
415
416             // Creating Config Match in rule Target
417             MatchType configMatch = new MatchType();
418             AttributeValueType configAttributeValue = new AttributeValueType();
419             configAttributeValue.setDataType(STRING_DATATYPE);
420
421             configAttributeValue.getContent().add("Config");
422
423             configMatch.setAttributeValue(configAttributeValue);
424             AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType();
425             URI configURI = null;
426             try {
427                 configURI = new URI(RESOURCE_ID);
428             } catch (URISyntaxException e) {
429                 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsParamPolicy",
430                     "Exception creating Config URI");
431             }
432
433             configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
434             configAttributeDesignator.setDataType(STRING_DATATYPE);
435             configAttributeDesignator.setAttributeId(new IdentifierImpl(configURI).stringValue());
436             configMatch.setAttributeDesignator(configAttributeDesignator);
437             configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
438
439             allOfInRule.getMatch().add(accessMatch);
440             allOfInRule.getMatch().add(configMatch);
441
442             AnyOfType anyOfInRule = new AnyOfType();
443             anyOfInRule.getAllOf().add(allOfInRule);
444
445             TargetType targetInRule = new TargetType();
446             targetInRule.getAnyOf().add(anyOfInRule);
447
448             rule.setTarget(targetInRule);
449             rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
450
451             configPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
452             policyAdapter.setPolicyData(configPolicy);
453
454         } else {
455             PolicyLogger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName());
456         }
457         setPreparedToSave(true);
458         return true;
459     }
460
461     // Data required for Advice part is setting here.
462     @VisibleForTesting
463     protected AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
464
465         // Policy Config ID Assignment
466         AdviceExpressionsType advices = new AdviceExpressionsType();
467         AdviceExpressionType advice = new AdviceExpressionType();
468         advice.setAdviceId("BRMSPARAMID");
469         advice.setAppliesTo(EffectType.PERMIT);
470         // For Configuration
471         AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
472         assignment1.setAttributeId("type");
473         assignment1.setCategory(CATEGORY_RESOURCE);
474         assignment1.setIssuer("");
475         AttributeValueType configNameAttributeValue = new AttributeValueType();
476         configNameAttributeValue.setDataType(STRING_DATATYPE);
477         configNameAttributeValue.getContent().add("Configuration");
478         assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue));
479         advice.getAttributeAssignmentExpression().add(assignment1);
480
481         // For Config file Url if configurations are provided.
482         // URL ID Assignment
483         AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
484         assignment2.setAttributeId("URLID");
485         assignment2.setCategory(CATEGORY_RESOURCE);
486         assignment2.setIssuer("");
487         AttributeValueType attributeValue = new AttributeValueType();
488         attributeValue.setDataType(URI_DATATYPE);
489
490         String content = CONFIG_URL + "/Config/" + getConfigFile(policyName);
491
492         attributeValue.getContent().add(content);
493         assignment2.setExpression(new ObjectFactory().createAttributeValue(attributeValue));
494         advice.getAttributeAssignmentExpression().add(assignment2);
495
496         // Policy Name Assignment
497         AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
498         assignment3.setAttributeId("PolicyName");
499         assignment3.setCategory(CATEGORY_RESOURCE);
500         assignment3.setIssuer("");
501         AttributeValueType attributeValue3 = new AttributeValueType();
502         attributeValue3.setDataType(STRING_DATATYPE);
503         fileName = FilenameUtils.removeExtension(fileName);
504         fileName = fileName + ".xml";
505         String name = fileName.substring(fileName.lastIndexOf("\\") + 1);
506         if ((name == null) || (name.equals(""))) {
507             name = fileName.substring(fileName.lastIndexOf("/") + 1);
508         }
509         attributeValue3.getContent().add(name);
510         assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3));
511         advice.getAttributeAssignmentExpression().add(assignment3);
512
513         // Version Number Assignment
514         AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
515         assignment4.setAttributeId("VersionNumber");
516         assignment4.setCategory(CATEGORY_RESOURCE);
517         assignment4.setIssuer("");
518         AttributeValueType configNameAttributeValue4 = new AttributeValueType();
519         configNameAttributeValue4.setDataType(STRING_DATATYPE);
520         configNameAttributeValue4.getContent().add(Integer.toString(version));
521         assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4));
522         advice.getAttributeAssignmentExpression().add(assignment4);
523
524         // Onap Name Assignment
525         AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
526         assignment5.setAttributeId("matching:" + ONAPID);
527         assignment5.setCategory(CATEGORY_RESOURCE);
528         assignment5.setIssuer("");
529         AttributeValueType configNameAttributeValue5 = new AttributeValueType();
530         configNameAttributeValue5.setDataType(STRING_DATATYPE);
531         configNameAttributeValue5.getContent().add(policyAdapter.getOnapName());
532         assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5));
533         advice.getAttributeAssignmentExpression().add(assignment5);
534
535         // Config Name Assignment
536         AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
537         assignment6.setAttributeId("matching:" + CONFIGID);
538         assignment6.setCategory(CATEGORY_RESOURCE);
539         assignment6.setIssuer("");
540         AttributeValueType configNameAttributeValue6 = new AttributeValueType();
541         configNameAttributeValue6.setDataType(STRING_DATATYPE);
542         configNameAttributeValue6.getContent().add(policyAdapter.getConfigName());
543         assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6));
544         advice.getAttributeAssignmentExpression().add(assignment6);
545         // Adding Controller Information.
546         if (policyAdapter.getBrmsController() != null) {
547             BRMSDictionaryController brmsDicitonaryController = new BRMSDictionaryController();
548             advice.getAttributeAssignmentExpression()
549                 .add(createResponseAttributes("controller:" + policyAdapter.getBrmsController(),
550                     brmsDicitonaryController.getControllerDataByID(policyAdapter.getBrmsController()).getController()));
551         }
552
553         // Adding Dependencies.
554         if (policyAdapter.getBrmsDependency() != null) {
555             BRMSDictionaryController brmsDicitonaryController = new BRMSDictionaryController();
556             ArrayList<String> dependencies = new ArrayList<>();
557             StringBuilder key = new StringBuilder();
558             for (String dependencyName : policyAdapter.getBrmsDependency()) {
559                 dependencies.add(brmsDicitonaryController.getDependencyDataByID(dependencyName).getDependency());
560                 key.append(dependencyName + ",");
561             }
562             advice.getAttributeAssignmentExpression()
563                 .add(createResponseAttributes("dependencies:" + key.toString(), dependencies.toString()));
564         }
565
566         // Dynamic Field Config Attributes.
567         Map<String, String> dynamicFieldConfigAttributes = policyAdapter.getDynamicFieldConfigAttributes();
568         for (Entry<String, String> map : dynamicFieldConfigAttributes.entrySet()) {
569             advice.getAttributeAssignmentExpression()
570                 .add(createResponseAttributes("key:" + map.getKey(), map.getValue()));
571         }
572
573         // Risk Attributes
574         AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType();
575         assignment8.setAttributeId("RiskType");
576         assignment8.setCategory(CATEGORY_RESOURCE);
577         assignment8.setIssuer("");
578
579         AttributeValueType configNameAttributeValue8 = new AttributeValueType();
580         configNameAttributeValue8.setDataType(STRING_DATATYPE);
581         configNameAttributeValue8.getContent().add(policyAdapter.getRiskType());
582         assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8));
583
584         advice.getAttributeAssignmentExpression().add(assignment8);
585
586         AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
587         assignment9.setAttributeId("RiskLevel");
588         assignment9.setCategory(CATEGORY_RESOURCE);
589         assignment9.setIssuer("");
590
591         AttributeValueType configNameAttributeValue9 = new AttributeValueType();
592         configNameAttributeValue9.setDataType(STRING_DATATYPE);
593         configNameAttributeValue9.getContent().add(policyAdapter.getRiskLevel());
594         assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
595
596         advice.getAttributeAssignmentExpression().add(assignment9);
597
598         AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType();
599         assignment10.setAttributeId("guard");
600         assignment10.setCategory(CATEGORY_RESOURCE);
601         assignment10.setIssuer("");
602
603         AttributeValueType configNameAttributeValue10 = new AttributeValueType();
604         configNameAttributeValue10.setDataType(STRING_DATATYPE);
605         configNameAttributeValue10.getContent().add(policyAdapter.getGuard());
606         assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10));
607
608         advice.getAttributeAssignmentExpression().add(assignment10);
609
610         AttributeAssignmentExpressionType assignment11 = new AttributeAssignmentExpressionType();
611         assignment11.setAttributeId("TTLDate");
612         assignment11.setCategory(CATEGORY_RESOURCE);
613         assignment11.setIssuer("");
614
615         AttributeValueType configNameAttributeValue11 = new AttributeValueType();
616         configNameAttributeValue11.setDataType(STRING_DATATYPE);
617         configNameAttributeValue11.getContent().add(policyAdapter.getTtlDate());
618         assignment11.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue11));
619
620         advice.getAttributeAssignmentExpression().add(assignment11);
621
622         advices.getAdviceExpression().add(advice);
623         return advices;
624     }
625
626     @Override
627     public Object getCorrectPolicyDataObject() {
628         return policyAdapter.getData();
629     }
630
631     private AttributeAssignmentExpressionType createResponseAttributes(String key, String value) {
632         AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType();
633         assignment7.setAttributeId(key);
634         assignment7.setCategory(CATEGORY_RESOURCE);
635         assignment7.setIssuer("");
636         AttributeValueType configNameAttributeValue7 = new AttributeValueType();
637         configNameAttributeValue7.setDataType(STRING_DATATYPE);
638         configNameAttributeValue7.getContent().add(value);
639         assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7));
640         return assignment7;
641     }
642 }