Initial OpenECOMP policy/engine commit
[policy/engine.git] / ECOMP-PAP-REST / src / main / java / org / openecomp / policy / pap / xacml / rest / components / CreateBrmsRawPolicy.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP-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.openecomp.policy.pap.xacml.rest.components;
22
23
24 import java.io.File;
25 import java.io.IOException;
26 import java.io.PrintWriter;
27 import java.net.URI;
28 import java.net.URISyntaxException;
29 import java.nio.charset.Charset;
30 import java.nio.charset.StandardCharsets;
31 import java.nio.file.Files;
32 import java.nio.file.Path;
33 import java.nio.file.Paths;
34 import java.util.HashMap;
35 import java.util.Map;
36 import java.util.StringTokenizer;
37
38 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType;
39 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
40 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
41 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
42 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType;
43 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
44 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
45 import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType;
46 import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
47 import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory;
48 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
49 import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
50 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
51
52 import org.apache.commons.io.FilenameUtils;
53 import org.openecomp.policy.pap.xacml.rest.adapters.PolicyRestAdapter;
54
55 import com.att.research.xacml.std.IdentifierImpl;
56
57 import org.openecomp.policy.common.logging.eelf.MessageCodes;
58 import org.openecomp.policy.common.logging.eelf.PolicyLogger;
59 import org.openecomp.policy.common.logging.flexlogger.FlexLogger; 
60 import org.openecomp.policy.common.logging.flexlogger.Logger; 
61
62
63 public class CreateBrmsRawPolicy extends Policy {
64         /**
65          * Config Fields
66          */
67         private static final Logger logger = FlexLogger
68                         .getLogger(CreateBrmsRawPolicy.class);
69
70         public static final String JSON_CONFIG = "JSON";
71         public static final String XML_CONFIG = "XML";
72         public static final String PROPERTIES_CONFIG = "PROPERTIES";
73         public static final String OTHER_CONFIG = "OTHER";
74
75         public CreateBrmsRawPolicy() {
76                 super();
77         }
78
79         public CreateBrmsRawPolicy(PolicyRestAdapter policyAdapter) {
80                 this.policyAdapter = policyAdapter;
81                 this.policyAdapter.setConfigType(policyAdapter.getConfigType());
82
83         }
84
85         // Saving the Configurations file at server location for config policy.
86         protected void saveConfigurations(String policyName, String prevPolicyName,
87                         String jsonBody) {
88                 final Path gitPath = Paths.get(policyAdapter.getUserGitPath()
89                                 .toString());
90                 String policyDir = policyAdapter.getParentPath().toString();
91                 int startIndex = policyDir.indexOf(gitPath.toString())
92                                 + gitPath.toString().length() + 1;
93                 policyDir = policyDir.substring(startIndex, policyDir.length());
94                 logger.info("print the main domain value" + policyDir);
95                 String path = policyDir.replace('\\', '.');
96                 if (path.contains("/")) {
97                         path = policyDir.replace('/', '.');
98                         logger.info("print the path:" + path);
99                 }
100
101                 try {
102                         String configFileName = getConfigFile(policyName);
103
104                         File file;
105                         if (CONFIG_HOME.contains("\\")) {
106                                 file = new File(CONFIG_HOME + "\\" + path + "."
107                                                 + configFileName);
108                         } else {
109                                 file = new File(CONFIG_HOME + "/" + path + "." + configFileName);
110                         }
111
112                         // if file doesnt exists, then create it
113                         if (!file.exists()) {
114                                 file.createNewFile();
115                         }
116
117                         // Getting the previous policy Config Json file to be used for
118                         // updating the dictionary tables
119                         if (policyAdapter.isEditPolicy()) {
120
121                                 String prevConfigFileName = getConfigFile(prevPolicyName);
122
123                                 File oldFile;
124                                 if (CONFIG_HOME.contains("\\")) {
125                                         oldFile = new File(CONFIG_HOME + "\\" + path + "."
126                                                         + prevConfigFileName);
127                                 } else {
128                                         oldFile = new File(CONFIG_HOME + "/" + path + "."
129                                                         + prevConfigFileName);
130                                 }
131
132                                 String filepath = oldFile.toString();
133
134                                 String prevJsonBody = readFile(filepath, StandardCharsets.UTF_8);
135                                 policyAdapter.setPrevJsonBody(prevJsonBody);
136                         }
137
138                         File configHomeDir = new File(CONFIG_HOME);
139                         File[] listOfFiles = configHomeDir.listFiles();
140                         if (listOfFiles != null) {
141                                 for (File eachFile : listOfFiles) {
142                                         if (eachFile.isFile()) {
143                                                 String fileNameWithoutExtension = FilenameUtils
144                                                                 .removeExtension(eachFile.getName());
145                                                 String configFileNameWithoutExtension = FilenameUtils
146                                                                 .removeExtension(configFileName);
147                                                 if (fileNameWithoutExtension
148                                                                 .equals(configFileNameWithoutExtension)) {
149                                                         // delete the file
150                                                         eachFile.delete();
151                                                 }
152                                         }
153                                 }
154                         }
155
156                         /*FileWriter fw = new FileWriter(file.getAbsoluteFile());
157                         BufferedWriter bw = new BufferedWriter(fw);
158                         bw.write(jsonBody);
159                         bw.close();
160                         if (logger.isDebugEnabled()) {
161                                 logger.debug("Configuration is succesfully saved");
162                         }*/
163                         
164                         try {
165                                 
166                                 if (policyName.endsWith(".xml")) {
167                                         policyName = policyName.substring(0,
168                                                         policyName.lastIndexOf(".xml"));
169                                 }
170                                 PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator
171                                                 + path + "." + policyName + ".txt");
172                                 out.println(jsonBody);
173                                 out.close();
174
175                         } catch (Exception e) {
176                                 //TODO:EELF Cleanup - Remove logger
177                                 //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
178                                 PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsRawPolicy", "Exception saving configurations file");
179                         }
180                         
181                 } catch (IOException e) {
182                         e.printStackTrace();
183                 }
184         }
185
186         // Utility to read json data from the existing file to a string
187         static String readFile(String path, Charset encoding) throws IOException {
188
189                 byte[] encoded = Files.readAllBytes(Paths.get(path));
190                 return new String(encoded, encoding);
191
192         }
193
194         // Here we are adding the extension for the configurations file based on the
195         // config type selection for saving.
196         private String getConfigFile(String filename) {
197                 filename = FilenameUtils.removeExtension(filename);
198                 if (filename.endsWith(".txt")) {
199                         filename = filename.substring(0, filename.length() - 3);
200                 }
201
202                 filename = filename + ".txt";
203                 return filename;
204         }
205
206         // Validations for Config form
207         public boolean validateConfigForm() {
208
209                 // Validating mandatory Fields.
210                 isValidForm = true;
211                 return isValidForm;
212
213         }
214
215         @Override
216         public Map<String, String> savePolicies() throws Exception {
217                 
218                 Map<String, String> successMap = new HashMap<String,String>();
219                 if(isPolicyExists()){
220                         successMap.put("EXISTS", "This Policy already exist on the PAP");
221                         return successMap;
222                 }
223                 
224                 if (!isPreparedToSave()) {
225                         prepareToSave();
226                 }
227                 // Until here we prepared the data and here calling the method to create
228                 // xml.
229                 Path newPolicyPath = null;
230                 newPolicyPath = Paths.get(policyAdapter.getParentPath().toString(),
231                                 policyName);
232                 
233                 Boolean dbIsUpdated = true;
234
235                 successMap = new HashMap<String, String>();
236                 if (dbIsUpdated) {
237                         successMap = createPolicy(newPolicyPath,
238                                         getCorrectPolicyDataObject());
239                 } else {
240                         //TODO:EELF Cleanup - Remove logger
241                         //logger.error("Failed to Update the Database Dictionary Tables.");
242                         PolicyLogger.error("Failed to Update the Database Dictionary Tables.");
243
244                         // remove the new json file
245                         String jsonBody = policyAdapter.getPrevJsonBody();
246                         saveConfigurations(policyName, "", jsonBody);
247                         successMap.put("error", "DB UPDATE");
248                 }
249
250                 if (successMap.containsKey("success")) {
251                         Path finalPolicyPath = getFinalPolicyPath();
252                         policyAdapter.setFinalPolicyPath(finalPolicyPath.toString());
253                 }
254                 return successMap;
255         }
256
257         // This is the method for preparing the policy for saving. We have broken it
258         // out
259         // separately because the fully configured policy is used for multiple
260         // things
261         @Override
262         public boolean prepareToSave() throws Exception {
263
264                 if (isPreparedToSave()) {
265                         // we have already done this
266                         return true;
267                 }
268
269                 int version = 0;
270                 String policyID = policyAdapter.getPolicyID();
271
272                 if (policyAdapter.isEditPolicy()) {
273                         // version = Integer.parseInt(policyAdapter.getVersion()) + 1;
274                         version = policyAdapter.getHighestVersion() + 1;
275                 } else {
276                         version = 1;
277                 }
278
279                 // Create the Instance for pojo, PolicyType object is used in
280                 // marshalling.
281                 if (policyAdapter.getPolicyType().equals("Config")) {
282                         PolicyType policyConfig = new PolicyType();
283
284                         policyConfig.setVersion(Integer.toString(version));
285                         policyConfig.setPolicyId(policyID);
286                         policyConfig.setTarget(new TargetType());
287                         policyAdapter.setData(policyConfig);
288                 }
289
290                 if (policyAdapter.getData() != null) {
291
292                         // Save off everything
293                         // making ready all the required elements to generate the action
294                         // policy xml.
295                         // Get the uniqueness for policy name.
296                         String prevPolicyName = null;
297                         if (policyAdapter.isEditPolicy()) {
298                                 prevPolicyName = "Config_BRMS_Raw_" + policyAdapter.getPolicyName()
299                                                 + "." + policyAdapter.getHighestVersion() + ".xml";
300                         }
301                         //if (!policyAdapter.isEditPolicy()) {
302                                 Path newFile = getNextFilename(
303                                                 Paths.get(policyAdapter.getParentPath().toString()),
304                                                 (policyAdapter.getPolicyType() + "_BRMS_Raw"),
305                                                 policyAdapter.getPolicyName(), version);
306         
307                                 if (newFile == null) {
308                                         //TODO:EELF Cleanup - Remove logger
309                                         //logger.error("File already exists, cannot create the policy.");
310                                         PolicyLogger.error("File already exists, cannot create the policy.");
311                                         setPolicyExists(true);
312                                         return false;
313                                 }
314                                 policyName = newFile.getFileName().toString();
315                         //}
316
317                         //String jsonBody = policyAdapter.getJsonBody();
318                         String configBody=policyAdapter.getConfigBodyData();
319                         saveConfigurations(policyName, prevPolicyName, configBody);
320
321                         // Make sure the filename ends with an extension
322                         if (policyName.endsWith(".xml") == false) {
323                                 policyName = policyName + ".xml";
324                         }
325
326                         PolicyType configPolicy = (PolicyType) policyAdapter.getData();
327
328                         configPolicy.setDescription(policyAdapter.getPolicyDescription());
329
330                         configPolicy.setRuleCombiningAlgId(policyAdapter
331                                         .getRuleCombiningAlgId());
332
333                         AllOfType allOfOne = new AllOfType();
334                         File policyFilePath = new File(policyAdapter.getParentPath()
335                                         .toString(), policyName);
336                         String policyDir = policyFilePath.getParentFile().getName();
337                         String fileName = FilenameUtils.removeExtension(policyName);
338                         fileName = policyDir + "." + fileName + ".xml";
339                         String name = fileName.substring(fileName.lastIndexOf("\\") + 1,
340                                         fileName.length());
341                         if ((name == null) || (name.equals(""))) {
342                                 name = fileName.substring(fileName.lastIndexOf("/") + 1,
343                                                 fileName.length());
344                         }
345                         allOfOne.getMatch().add(createMatch("PolicyName", name));
346                         
347                         
348                         AllOfType allOf = new AllOfType();
349
350                         // Match for ECOMPName
351                         allOf.getMatch().add(
352                                         createMatch("ECOMPName", policyAdapter.getEcompName()));
353                         allOf.getMatch().add(
354                                         createMatch("ConfigName", policyAdapter.getConfigName()));
355                         // Match for riskType
356                         allOf.getMatch().add(
357                                         createDynamicMatch("RiskType", policyAdapter.getRiskType()));
358                         // Match for riskLevel
359                         allOf.getMatch().add(
360                                         createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
361                         // Match for riskguard
362                         allOf.getMatch().add(
363                                         createDynamicMatch("guard", policyAdapter.getGuard()));
364                         // Match for ttlDate
365                         allOf.getMatch().add(
366                                         createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
367                         AnyOfType anyOf = new AnyOfType();
368                         anyOf.getAllOf().add(allOfOne);
369                         anyOf.getAllOf().add(allOf);
370
371                         TargetType target = new TargetType();
372                         ((TargetType) target).getAnyOf().add(anyOf);
373
374                         // Adding the target to the policy element
375                         configPolicy.setTarget((TargetType) target);
376
377                         RuleType rule = new RuleType();
378                         rule.setRuleId(policyAdapter.getRuleID());
379
380                         rule.setEffect(EffectType.PERMIT);
381
382                         // Create Target in Rule
383                         AllOfType allOfInRule = new AllOfType();
384
385                         // Creating match for ACCESS in rule target
386                         MatchType accessMatch = new MatchType();
387                         AttributeValueType accessAttributeValue = new AttributeValueType();
388                         accessAttributeValue.setDataType(STRING_DATATYPE);
389                         accessAttributeValue.getContent().add("ACCESS");
390                         accessMatch.setAttributeValue(accessAttributeValue);
391                         AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
392                         URI accessURI = null;
393                         try {
394                                 accessURI = new URI(ACTION_ID);
395                         } catch (URISyntaxException e) {
396                                 //TODO:EELF Cleanup - Remove logger
397                                 //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE
398                                                 //+ e.getStackTrace());
399                                 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsRawPolicy", "Exception creating ACCESS URI");
400                         }
401                         accessAttributeDesignator.setCategory(CATEGORY_ACTION);
402                         accessAttributeDesignator.setDataType(STRING_DATATYPE);
403                         accessAttributeDesignator.setAttributeId(new IdentifierImpl(
404                                         accessURI).stringValue());
405                         accessMatch.setAttributeDesignator(accessAttributeDesignator);
406                         accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
407
408                         // Creating Config Match in rule Target
409                         MatchType configMatch = new MatchType();
410                         AttributeValueType configAttributeValue = new AttributeValueType();
411                         configAttributeValue.setDataType(STRING_DATATYPE);
412
413                         configAttributeValue.getContent().add("Config");
414
415                         configMatch.setAttributeValue(configAttributeValue);
416                         AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType();
417                         URI configURI = null;
418                         try {
419                                 configURI = new URI(RESOURCE_ID);
420                         } catch (URISyntaxException e) {
421                                 //TODO:EELF Cleanup - Remove logger
422                                 //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE
423                                                 //+ e.getStackTrace());
424                                 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsRawPolicy", "Exception creating Config URI");
425                         }
426
427                         configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
428                         configAttributeDesignator.setDataType(STRING_DATATYPE);
429                         configAttributeDesignator.setAttributeId(new IdentifierImpl(
430                                         configURI).stringValue());
431                         configMatch.setAttributeDesignator(configAttributeDesignator);
432                         configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
433
434                         allOfInRule.getMatch().add(accessMatch);
435                         allOfInRule.getMatch().add(configMatch);
436
437                         AnyOfType anyOfInRule = new AnyOfType();
438                         anyOfInRule.getAllOf().add(allOfInRule);
439
440                         TargetType targetInRule = new TargetType();
441                         targetInRule.getAnyOf().add(anyOfInRule);
442
443                         rule.setTarget(targetInRule);
444                         rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
445
446                         configPolicy
447                                         .getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()
448                                         .add(rule);
449                         policyAdapter.setPolicyData(configPolicy);
450
451                 } else {
452                         //TODO:EELF Cleanup - Remove logger
453                         //logger.error("Unsupported data object."
454                                         //+ policyAdapter.getData().getClass().getCanonicalName());
455                         PolicyLogger.error("Unsupported data object."
456                                         + policyAdapter.getData().getClass().getCanonicalName());
457                 }
458                 setPreparedToSave(true);
459                 return true;
460         }
461
462         // Data required for Advice part is setting here.
463         private AdviceExpressionsType getAdviceExpressions(int version,
464                         String fileName) {
465
466                 // Policy Config ID Assignment
467                 AdviceExpressionsType advices = new AdviceExpressionsType();
468                 AdviceExpressionType advice = new AdviceExpressionType();
469                 advice.setAdviceId("BRMSRAWID");
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()
480                                 .createAttributeValue(configNameAttributeValue));
481                 advice.getAttributeAssignmentExpression().add(assignment1);
482
483                 // For Config file Url if configurations are provided.
484                 // URL ID Assignment
485                 final Path gitPath = Paths.get(policyAdapter.getUserGitPath()
486                                 .toString());
487                 AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
488                 assignment2.setAttributeId("URLID");
489                 assignment2.setCategory(CATEGORY_RESOURCE);
490                 assignment2.setIssuer("");
491                 AttributeValueType AttributeValue = new AttributeValueType();
492                 AttributeValue.setDataType(URI_DATATYPE);
493                 String policyDir1 = policyAdapter.getParentPath().toString();
494                 int startIndex1 = policyDir1.indexOf(gitPath.toString())
495                                 + gitPath.toString().length() + 1;
496                 policyDir1 = policyDir1.substring(startIndex1, policyDir1.length());
497                 logger.info("print the main domain value" + policyDir1);
498                 String path = policyDir1.replace('\\', '.');
499                 if (path.contains("/")) {
500                         path = policyDir1.replace('/', '.');
501                         logger.info("print the path:" + path);
502                 }
503                 String content = CONFIG_URL + "/Config/" + path + "."
504                                 + getConfigFile(policyName);
505
506                 AttributeValue.getContent().add(content);
507                 assignment2.setExpression(new ObjectFactory()
508                                 .createAttributeValue(AttributeValue));
509                 advice.getAttributeAssignmentExpression().add(assignment2);
510
511                 // Policy Name Assignment
512                 AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
513                 assignment3.setAttributeId("PolicyName");
514                 assignment3.setCategory(CATEGORY_RESOURCE);
515                 assignment3.setIssuer("");
516                 AttributeValueType attributeValue3 = new AttributeValueType();
517                 attributeValue3.setDataType(STRING_DATATYPE);
518                 String policyDir = policyAdapter.getParentPath().toString();
519                 int startIndex = policyDir.indexOf(gitPath.toString())
520                                 + gitPath.toString().length() + 1;
521                 policyDir = policyDir.substring(startIndex, policyDir.length());
522                 StringTokenizer tokenizer = null;
523                 StringBuffer buffer = new StringBuffer();
524                 if (policyDir.contains("\\")) {
525                         tokenizer = new StringTokenizer(policyDir, "\\");
526                 } else {
527                         tokenizer = new StringTokenizer(policyDir, "/");
528                 }
529                 if (tokenizer != null) {
530                         while (tokenizer.hasMoreElements()) {
531                                 String value = tokenizer.nextToken();
532                                 buffer.append(value);
533                                 buffer.append(".");
534                         }
535                 }
536                 fileName = FilenameUtils.removeExtension(fileName);
537                 fileName = buffer.toString() + fileName + ".xml";
538                 System.out.println(fileName);
539                 String name = fileName.substring(fileName.lastIndexOf("\\") + 1,
540                                 fileName.length());
541                 if ((name == null) || (name.equals(""))) {
542                         name = fileName.substring(fileName.lastIndexOf("/") + 1,
543                                         fileName.length());
544                 }
545                 System.out.println(name);
546                 attributeValue3.getContent().add(name);
547                 assignment3.setExpression(new ObjectFactory()
548                                 .createAttributeValue(attributeValue3));
549                 advice.getAttributeAssignmentExpression().add(assignment3);
550
551                 // Version Number Assignment
552                 AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
553                 assignment4.setAttributeId("VersionNumber");
554                 assignment4.setCategory(CATEGORY_RESOURCE);
555                 assignment4.setIssuer("");
556                 AttributeValueType configNameAttributeValue4 = new AttributeValueType();
557                 configNameAttributeValue4.setDataType(STRING_DATATYPE);
558                 configNameAttributeValue4.getContent().add(Integer.toString(version));
559                 assignment4.setExpression(new ObjectFactory()
560                                 .createAttributeValue(configNameAttributeValue4));
561                 advice.getAttributeAssignmentExpression().add(assignment4);
562
563                 // Ecomp Name Assignment
564                 AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
565                 assignment5.setAttributeId("matching:" + this.ECOMPID);
566                 assignment5.setCategory(CATEGORY_RESOURCE);
567                 assignment5.setIssuer("");
568                 AttributeValueType configNameAttributeValue5 = new AttributeValueType();
569                 configNameAttributeValue5.setDataType(STRING_DATATYPE);
570                 configNameAttributeValue5.getContent().add(policyAdapter.getEcompName());
571                 assignment5.setExpression(new ObjectFactory()
572                                 .createAttributeValue(configNameAttributeValue5));
573                 advice.getAttributeAssignmentExpression().add(assignment5);
574                 
575                 
576                 //Config Name Assignment
577                 AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
578                 assignment6.setAttributeId("matching:" + this.CONFIGID);
579                 assignment6.setCategory(CATEGORY_RESOURCE);
580                 assignment6.setIssuer("");
581                 AttributeValueType configNameAttributeValue6 = new AttributeValueType();
582                 configNameAttributeValue6.setDataType(STRING_DATATYPE);
583                 configNameAttributeValue6.getContent().add(policyAdapter.getConfigName());
584                 assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6));
585                 advice.getAttributeAssignmentExpression().add(assignment6);
586                 
587                 Map<String, String> dynamicFieldConfigAttributes = policyAdapter.getDynamicFieldConfigAttributes();
588                 for (String keyField : dynamicFieldConfigAttributes.keySet()) {
589                         String key = keyField;
590                         String value = dynamicFieldConfigAttributes.get(key);
591                         AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType();
592                         assignment7.setAttributeId("key:" + key);
593                         assignment7.setCategory(CATEGORY_RESOURCE);
594                         assignment7.setIssuer("");
595
596                         AttributeValueType configNameAttributeValue7 = new AttributeValueType();
597                         configNameAttributeValue7.setDataType(STRING_DATATYPE);
598                         configNameAttributeValue7.getContent().add(value);
599                         assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7));
600
601                         advice.getAttributeAssignmentExpression().add(assignment7);
602                 }
603                 
604                 //Risk Attributes
605                 AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType();
606                 assignment8.setAttributeId("RiskType");
607                 assignment8.setCategory(CATEGORY_RESOURCE);
608                 assignment8.setIssuer("");
609
610                 AttributeValueType configNameAttributeValue8 = new AttributeValueType();
611                 configNameAttributeValue8.setDataType(STRING_DATATYPE);
612                 configNameAttributeValue8.getContent().add(policyAdapter.getRiskType());
613                 assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8));
614
615                 advice.getAttributeAssignmentExpression().add(assignment8);
616                 
617                 AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
618                 assignment9.setAttributeId("RiskLevel");
619                 assignment9.setCategory(CATEGORY_RESOURCE);
620                 assignment9.setIssuer("");
621
622                 AttributeValueType configNameAttributeValue9 = new AttributeValueType();
623                 configNameAttributeValue9.setDataType(STRING_DATATYPE);
624                 configNameAttributeValue9.getContent().add(policyAdapter.getRiskLevel());
625                 assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
626
627                 advice.getAttributeAssignmentExpression().add(assignment9);     
628
629                 AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType();
630                 assignment10.setAttributeId("guard");
631                 assignment10.setCategory(CATEGORY_RESOURCE);
632                 assignment10.setIssuer("");
633
634                 AttributeValueType configNameAttributeValue10 = new AttributeValueType();
635                 configNameAttributeValue10.setDataType(STRING_DATATYPE);
636                 configNameAttributeValue10.getContent().add(policyAdapter.getGuard());
637                 assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10));
638
639                 advice.getAttributeAssignmentExpression().add(assignment10);
640
641                 AttributeAssignmentExpressionType assignment11 = new AttributeAssignmentExpressionType();
642                 assignment11.setAttributeId("TTLDate");
643                 assignment11.setCategory(CATEGORY_RESOURCE);
644                 assignment11.setIssuer("");
645
646                 AttributeValueType configNameAttributeValue11 = new AttributeValueType();
647                 configNameAttributeValue11.setDataType(STRING_DATATYPE);
648                 configNameAttributeValue11.getContent().add(policyAdapter.getTtlDate());
649                 assignment11.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue11));
650
651                 advice.getAttributeAssignmentExpression().add(assignment11);
652
653                 advices.getAdviceExpression().add(advice);
654                 return advices;
655         }
656
657         @Override
658         public Object getCorrectPolicyDataObject() {
659                 return policyAdapter.getData();
660         }
661 }