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