aboutsummaryrefslogtreecommitdiffstats
path: root/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/CreateBrmsRawPolicy.java
blob: d77abf0f15b31ad36ad81a76044da42f57734404 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
/*-
 * ============LICENSE_START=======================================================
 * ECOMP-PAP-REST
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.policy.pap.xacml.rest.components;


import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;

import org.apache.commons.io.FilenameUtils;
import org.openecomp.policy.pap.xacml.rest.adapters.PolicyRestAdapter;

import com.att.research.xacml.std.IdentifierImpl;

import org.openecomp.policy.common.logging.eelf.MessageCodes;
import org.openecomp.policy.common.logging.eelf.PolicyLogger;
import org.openecomp.policy.common.logging.flexlogger.FlexLogger; 
import org.openecomp.policy.common.logging.flexlogger.Logger; 


public class CreateBrmsRawPolicy extends Policy {
	/**
	 * Config Fields
	 */
	private static final Logger logger = FlexLogger
			.getLogger(CreateBrmsRawPolicy.class);

	public static final String JSON_CONFIG = "JSON";
	public static final String XML_CONFIG = "XML";
	public static final String PROPERTIES_CONFIG = "PROPERTIES";
	public static final String OTHER_CONFIG = "OTHER";

	public CreateBrmsRawPolicy() {
		super();
	}

	public CreateBrmsRawPolicy(PolicyRestAdapter policyAdapter) {
		this.policyAdapter = policyAdapter;
		this.policyAdapter.setConfigType(policyAdapter.getConfigType());

	}

	// Saving the Configurations file at server location for config policy.
	protected void saveConfigurations(String policyName, String prevPolicyName,
			String jsonBody) {
		final Path gitPath = Paths.get(policyAdapter.getUserGitPath()
				.toString());
		String policyDir = policyAdapter.getParentPath().toString();
		int startIndex = policyDir.indexOf(gitPath.toString())
				+ gitPath.toString().length() + 1;
		policyDir = policyDir.substring(startIndex, policyDir.length());
		logger.info("print the main domain value" + policyDir);
		String path = policyDir.replace('\\', '.');
		if (path.contains("/")) {
			path = policyDir.replace('/', '.');
			logger.info("print the path:" + path);
		}

		try {
			String configFileName = getConfigFile(policyName);

			File file;
			if (CONFIG_HOME.contains("\\")) {
				file = new File(CONFIG_HOME + "\\" + path + "."
						+ configFileName);
			} else {
				file = new File(CONFIG_HOME + "/" + path + "." + configFileName);
			}

			// if file doesnt exists, then create it
			if (!file.exists()) {
				file.createNewFile();
			}

			// Getting the previous policy Config Json file to be used for
			// updating the dictionary tables
			if (policyAdapter.isEditPolicy()) {

				String prevConfigFileName = getConfigFile(prevPolicyName);

				File oldFile;
				if (CONFIG_HOME.contains("\\")) {
					oldFile = new File(CONFIG_HOME + "\\" + path + "."
							+ prevConfigFileName);
				} else {
					oldFile = new File(CONFIG_HOME + "/" + path + "."
							+ prevConfigFileName);
				}

				String filepath = oldFile.toString();

				String prevJsonBody = readFile(filepath, StandardCharsets.UTF_8);
				policyAdapter.setPrevJsonBody(prevJsonBody);
			}

			File configHomeDir = new File(CONFIG_HOME);
			File[] listOfFiles = configHomeDir.listFiles();
			if (listOfFiles != null) {
				for (File eachFile : listOfFiles) {
					if (eachFile.isFile()) {
						String fileNameWithoutExtension = FilenameUtils
								.removeExtension(eachFile.getName());
						String configFileNameWithoutExtension = FilenameUtils
								.removeExtension(configFileName);
						if (fileNameWithoutExtension
								.equals(configFileNameWithoutExtension)) {
							// delete the file
							eachFile.delete();
						}
					}
				}
			}

			/*FileWriter fw = new FileWriter(file.getAbsoluteFile());
			BufferedWriter bw = new BufferedWriter(fw);
			bw.write(jsonBody);
			bw.close();
			if (logger.isDebugEnabled()) {
				logger.debug("Configuration is succesfully saved");
			}*/
			
			try {
				
				if (policyName.endsWith(".xml")) {
					policyName = policyName.substring(0,
							policyName.lastIndexOf(".xml"));
				}
				PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator
						+ path + "." + policyName + ".txt");
				out.println(jsonBody);
				out.close();

			} catch (Exception e) {
				//TODO:EELF Cleanup - Remove logger
				//logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
				PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsRawPolicy", "Exception saving configurations file");
			}
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	// Utility to read json data from the existing file to a string
	static String readFile(String path, Charset encoding) throws IOException {

		byte[] encoded = Files.readAllBytes(Paths.get(path));
		return new String(encoded, encoding);

	}

	// Here we are adding the extension for the configurations file based on the
	// config type selection for saving.
	private String getConfigFile(String filename) {
		filename = FilenameUtils.removeExtension(filename);
		if (filename.endsWith(".txt")) {
			filename = filename.substring(0, filename.length() - 3);
		}

		filename = filename + ".txt";
		return filename;
	}

	// Validations for Config form
	public boolean validateConfigForm() {

		// Validating mandatory Fields.
		isValidForm = true;
		return isValidForm;

	}

	@Override
	public Map<String, String> savePolicies() throws Exception {
		
		Map<String, String> successMap = new HashMap<String,String>();
		if(isPolicyExists()){
			successMap.put("EXISTS", "This Policy already exist on the PAP");
			return successMap;
		}
		
		if (!isPreparedToSave()) {
			prepareToSave();
		}
		// Until here we prepared the data and here calling the method to create
		// xml.
		Path newPolicyPath = null;
		newPolicyPath = Paths.get(policyAdapter.getParentPath().toString(),
				policyName);
		
		Boolean dbIsUpdated = true;

		successMap = new HashMap<String, String>();
		if (dbIsUpdated) {
			successMap = createPolicy(newPolicyPath,
					getCorrectPolicyDataObject());
		} else {
			//TODO:EELF Cleanup - Remove logger
			//logger.error("Failed to Update the Database Dictionary Tables.");
			PolicyLogger.error("Failed to Update the Database Dictionary Tables.");

			// remove the new json file
			String jsonBody = policyAdapter.getPrevJsonBody();
			saveConfigurations(policyName, "", jsonBody);
			successMap.put("error", "DB UPDATE");
		}

		if (successMap.containsKey("success")) {
			Path finalPolicyPath = getFinalPolicyPath();
			policyAdapter.setFinalPolicyPath(finalPolicyPath.toString());
		}
		return successMap;
	}

	// This is the method for preparing the policy for saving. We have broken it
	// out
	// separately because the fully configured policy is used for multiple
	// things
	@Override
	public boolean prepareToSave() throws Exception {

		if (isPreparedToSave()) {
			// we have already done this
			return true;
		}

		int version = 0;
		String policyID = policyAdapter.getPolicyID();

		if (policyAdapter.isEditPolicy()) {
			// version = Integer.parseInt(policyAdapter.getVersion()) + 1;
			version = policyAdapter.getHighestVersion() + 1;
		} else {
			version = 1;
		}

		// Create the Instance for pojo, PolicyType object is used in
		// marshalling.
		if (policyAdapter.getPolicyType().equals("Config")) {
			PolicyType policyConfig = new PolicyType();

			policyConfig.setVersion(Integer.toString(version));
			policyConfig.setPolicyId(policyID);
			policyConfig.setTarget(new TargetType());
			policyAdapter.setData(policyConfig);
		}

		if (policyAdapter.getData() != null) {

			// Save off everything
			// making ready all the required elements to generate the action
			// policy xml.
			// Get the uniqueness for policy name.
			String prevPolicyName = null;
			if (policyAdapter.isEditPolicy()) {
				prevPolicyName = "Config_BRMS_Raw_" + policyAdapter.getPolicyName()
						+ "." + policyAdapter.getHighestVersion() + ".xml";
			}
			//if (!policyAdapter.isEditPolicy()) {
				Path newFile = getNextFilename(
						Paths.get(policyAdapter.getParentPath().toString()),
						(policyAdapter.getPolicyType() + "_BRMS_Raw"),
						policyAdapter.getPolicyName(), version);
	
				if (newFile == null) {
					//TODO:EELF Cleanup - Remove logger
					//logger.error("File already exists, cannot create the policy.");
					PolicyLogger.error("File already exists, cannot create the policy.");
					setPolicyExists(true);
					return false;
				}
				policyName = newFile.getFileName().toString();
			//}

			//String jsonBody = policyAdapter.getJsonBody();
			String configBody=policyAdapter.getConfigBodyData();
			saveConfigurations(policyName, prevPolicyName, configBody);

			// Make sure the filename ends with an extension
			if (policyName.endsWith(".xml") == false) {
				policyName = policyName + ".xml";
			}

			PolicyType configPolicy = (PolicyType) policyAdapter.getData();

			configPolicy.setDescription(policyAdapter.getPolicyDescription());

			configPolicy.setRuleCombiningAlgId(policyAdapter
					.getRuleCombiningAlgId());

			AllOfType allOfOne = new AllOfType();
			File policyFilePath = new File(policyAdapter.getParentPath()
					.toString(), policyName);
			String policyDir = policyFilePath.getParentFile().getName();
			String fileName = FilenameUtils.removeExtension(policyName);
			fileName = policyDir + "." + fileName + ".xml";
			String name = fileName.substring(fileName.lastIndexOf("\\") + 1,
					fileName.length());
			if ((name == null) || (name.equals(""))) {
				name = fileName.substring(fileName.lastIndexOf("/") + 1,
						fileName.length());
			}
			allOfOne.getMatch().add(createMatch("PolicyName", name));
			
			
			AllOfType allOf = new AllOfType();

			// Match for ECOMPName
			allOf.getMatch().add(
					createMatch("ECOMPName", policyAdapter.getEcompName()));
			allOf.getMatch().add(
					createMatch("ConfigName", policyAdapter.getConfigName()));
			// Match for riskType
			allOf.getMatch().add(
					createDynamicMatch("RiskType", policyAdapter.getRiskType()));
			// Match for riskLevel
			allOf.getMatch().add(
					createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
			// Match for riskguard
			allOf.getMatch().add(
					createDynamicMatch("guard", policyAdapter.getGuard()));
			// Match for ttlDate
			allOf.getMatch().add(
					createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
			AnyOfType anyOf = new AnyOfType();
			anyOf.getAllOf().add(allOfOne);
			anyOf.getAllOf().add(allOf);

			TargetType target = new TargetType();
			((TargetType) target).getAnyOf().add(anyOf);

			// Adding the target to the policy element
			configPolicy.setTarget((TargetType) target);

			RuleType rule = new RuleType();
			rule.setRuleId(policyAdapter.getRuleID());

			rule.setEffect(EffectType.PERMIT);

			// Create Target in Rule
			AllOfType allOfInRule = new AllOfType();

			// Creating match for ACCESS in rule target
			MatchType accessMatch = new MatchType();
			AttributeValueType accessAttributeValue = new AttributeValueType();
			accessAttributeValue.setDataType(STRING_DATATYPE);
			accessAttributeValue.getContent().add("ACCESS");
			accessMatch.setAttributeValue(accessAttributeValue);
			AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
			URI accessURI = null;
			try {
				accessURI = new URI(ACTION_ID);
			} catch (URISyntaxException e) {
				//TODO:EELF Cleanup - Remove logger
				//logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE
						//+ e.getStackTrace());
				PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsRawPolicy", "Exception creating ACCESS URI");
			}
			accessAttributeDesignator.setCategory(CATEGORY_ACTION);
			accessAttributeDesignator.setDataType(STRING_DATATYPE);
			accessAttributeDesignator.setAttributeId(new IdentifierImpl(
					accessURI).stringValue());
			accessMatch.setAttributeDesignator(accessAttributeDesignator);
			accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);

			// Creating Config Match in rule Target
			MatchType configMatch = new MatchType();
			AttributeValueType configAttributeValue = new AttributeValueType();
			configAttributeValue.setDataType(STRING_DATATYPE);

			configAttributeValue.getContent().add("Config");

			configMatch.setAttributeValue(configAttributeValue);
			AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType();
			URI configURI = null;
			try {
				configURI = new URI(RESOURCE_ID);
			} catch (URISyntaxException e) {
				//TODO:EELF Cleanup - Remove logger
				//logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE
						//+ e.getStackTrace());
				PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsRawPolicy", "Exception creating Config URI");
			}

			configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
			configAttributeDesignator.setDataType(STRING_DATATYPE);
			configAttributeDesignator.setAttributeId(new IdentifierImpl(
					configURI).stringValue());
			configMatch.setAttributeDesignator(configAttributeDesignator);
			configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);

			allOfInRule.getMatch().add(accessMatch);
			allOfInRule.getMatch().add(configMatch);

			AnyOfType anyOfInRule = new AnyOfType();
			anyOfInRule.getAllOf().add(allOfInRule);

			TargetType targetInRule = new TargetType();
			targetInRule.getAnyOf().add(anyOfInRule);

			rule.setTarget(targetInRule);
			rule.setAdviceExpressions(getAdviceExpressions(version, policyName));

			configPolicy
					.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()
					.add(rule);
			policyAdapter.setPolicyData(configPolicy);

		} else {
			//TODO:EELF Cleanup - Remove logger
			//logger.error("Unsupported data object."
					//+ policyAdapter.getData().getClass().getCanonicalName());
			PolicyLogger.error("Unsupported data object."
					+ policyAdapter.getData().getClass().getCanonicalName());
		}
		setPreparedToSave(true);
		return true;
	}

	// Data required for Advice part is setting here.
	private AdviceExpressionsType getAdviceExpressions(int version,
			String fileName) {

		// Policy Config ID Assignment
		AdviceExpressionsType advices = new AdviceExpressionsType();
		AdviceExpressionType advice = new AdviceExpressionType();
		advice.setAdviceId("BRMSRAWID");
		advice.setAppliesTo(EffectType.PERMIT);
		// For Configuration
		AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
		assignment1.setAttributeId("type");
		assignment1.setCategory(CATEGORY_RESOURCE);
		assignment1.setIssuer("");
		AttributeValueType configNameAttributeValue = new AttributeValueType();
		configNameAttributeValue.setDataType(STRING_DATATYPE);
		configNameAttributeValue.getContent().add("Configuration");
		assignment1.setExpression(new ObjectFactory()
				.createAttributeValue(configNameAttributeValue));
		advice.getAttributeAssignmentExpression().add(assignment1);

		// For Config file Url if configurations are provided.
		// URL ID Assignment
		final Path gitPath = Paths.get(policyAdapter.getUserGitPath()
				.toString());
		AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
		assignment2.setAttributeId("URLID");
		assignment2.setCategory(CATEGORY_RESOURCE);
		assignment2.setIssuer("");
		AttributeValueType AttributeValue = new AttributeValueType();
		AttributeValue.setDataType(URI_DATATYPE);
		String policyDir1 = policyAdapter.getParentPath().toString();
		int startIndex1 = policyDir1.indexOf(gitPath.toString())
				+ gitPath.toString().length() + 1;
		policyDir1 = policyDir1.substring(startIndex1, policyDir1.length());
		logger.info("print the main domain value" + policyDir1);
		String path = policyDir1.replace('\\', '.');
		if (path.contains("/")) {
			path = policyDir1.replace('/', '.');
			logger.info("print the path:" + path);
		}
		String content = CONFIG_URL + "/Config/" + path + "."
				+ getConfigFile(policyName);

		AttributeValue.getContent().add(content);
		assignment2.setExpression(new ObjectFactory()
				.createAttributeValue(AttributeValue));
		advice.getAttributeAssignmentExpression().add(assignment2);

		// Policy Name Assignment
		AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
		assignment3.setAttributeId("PolicyName");
		assignment3.setCategory(CATEGORY_RESOURCE);
		assignment3.setIssuer("");
		AttributeValueType attributeValue3 = new AttributeValueType();
		attributeValue3.setDataType(STRING_DATATYPE);
		String policyDir = policyAdapter.getParentPath().toString();
		int startIndex = policyDir.indexOf(gitPath.toString())
				+ gitPath.toString().length() + 1;
		policyDir = policyDir.substring(startIndex, policyDir.length());
		StringTokenizer tokenizer = null;
		StringBuffer buffer = new StringBuffer();
		if (policyDir.contains("\\")) {
			tokenizer = new StringTokenizer(policyDir, "\\");
		} else {
			tokenizer = new StringTokenizer(policyDir, "/");
		}
		if (tokenizer != null) {
			while (tokenizer.hasMoreElements()) {
				String value = tokenizer.nextToken();
				buffer.append(value);
				buffer.append(".");
			}
		}
		fileName = FilenameUtils.removeExtension(fileName);
		fileName = buffer.toString() + fileName + ".xml";
		System.out.println(fileName);
		String name = fileName.substring(fileName.lastIndexOf("\\") + 1,
				fileName.length());
		if ((name == null) || (name.equals(""))) {
			name = fileName.substring(fileName.lastIndexOf("/") + 1,
					fileName.length());
		}
		System.out.println(name);
		attributeValue3.getContent().add(name);
		assignment3.setExpression(new ObjectFactory()
				.createAttributeValue(attributeValue3));
		advice.getAttributeAssignmentExpression().add(assignment3);

		// Version Number Assignment
		AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
		assignment4.setAttributeId("VersionNumber");
		assignment4.setCategory(CATEGORY_RESOURCE);
		assignment4.setIssuer("");
		AttributeValueType configNameAttributeValue4 = new AttributeValueType();
		configNameAttributeValue4.setDataType(STRING_DATATYPE);
		configNameAttributeValue4.getContent().add(Integer.toString(version));
		assignment4.setExpression(new ObjectFactory()
				.createAttributeValue(configNameAttributeValue4));
		advice.getAttributeAssignmentExpression().add(assignment4);

		// Ecomp Name Assignment
		AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
		assignment5.setAttributeId("matching:" + this.ECOMPID);
		assignment5.setCategory(CATEGORY_RESOURCE);
		assignment5.setIssuer("");
		AttributeValueType configNameAttributeValue5 = new AttributeValueType();
		configNameAttributeValue5.setDataType(STRING_DATATYPE);
		configNameAttributeValue5.getContent().add(policyAdapter.getEcompName());
		assignment5.setExpression(new ObjectFactory()
				.createAttributeValue(configNameAttributeValue5));
		advice.getAttributeAssignmentExpression().add(assignment5);
		
		
		//Config Name Assignment
		AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
		assignment6.setAttributeId("matching:" + this.CONFIGID);
		assignment6.setCategory(CATEGORY_RESOURCE);
		assignment6.setIssuer("");
		AttributeValueType configNameAttributeValue6 = new AttributeValueType();
		configNameAttributeValue6.setDataType(STRING_DATATYPE);
		configNameAttributeValue6.getContent().add(policyAdapter.getConfigName());
		assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6));
		advice.getAttributeAssignmentExpression().add(assignment6);
		
		Map<String, String> dynamicFieldConfigAttributes = policyAdapter.getDynamicFieldConfigAttributes();
		for (String keyField : dynamicFieldConfigAttributes.keySet()) {
			String key = keyField;
			String value = dynamicFieldConfigAttributes.get(key);
			AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType();
			assignment7.setAttributeId("key:" + key);
			assignment7.setCategory(CATEGORY_RESOURCE);
			assignment7.setIssuer("");

			AttributeValueType configNameAttributeValue7 = new AttributeValueType();
			configNameAttributeValue7.setDataType(STRING_DATATYPE);
			configNameAttributeValue7.getContent().add(value);
			assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7));

			advice.getAttributeAssignmentExpression().add(assignment7);
		}
		
		//Risk Attributes
		AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType();
		assignment8.setAttributeId("RiskType");
		assignment8.setCategory(CATEGORY_RESOURCE);
		assignment8.setIssuer("");

		AttributeValueType configNameAttributeValue8 = new AttributeValueType();
		configNameAttributeValue8.setDataType(STRING_DATATYPE);
		configNameAttributeValue8.getContent().add(policyAdapter.getRiskType());
		assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8));

		advice.getAttributeAssignmentExpression().add(assignment8);
		
		AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
		assignment9.setAttributeId("RiskLevel");
		assignment9.setCategory(CATEGORY_RESOURCE);
		assignment9.setIssuer("");

		AttributeValueType configNameAttributeValue9 = new AttributeValueType();
		configNameAttributeValue9.setDataType(STRING_DATATYPE);
		configNameAttributeValue9.getContent().add(policyAdapter.getRiskLevel());
		assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));

		advice.getAttributeAssignmentExpression().add(assignment9);	

		AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType();
		assignment10.setAttributeId("guard");
		assignment10.setCategory(CATEGORY_RESOURCE);
		assignment10.setIssuer("");

		AttributeValueType configNameAttributeValue10 = new AttributeValueType();
		configNameAttributeValue10.setDataType(STRING_DATATYPE);
		configNameAttributeValue10.getContent().add(policyAdapter.getGuard());
		assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10));

		advice.getAttributeAssignmentExpression().add(assignment10);

		AttributeAssignmentExpressionType assignment11 = new AttributeAssignmentExpressionType();
		assignment11.setAttributeId("TTLDate");
		assignment11.setCategory(CATEGORY_RESOURCE);
		assignment11.setIssuer("");

		AttributeValueType configNameAttributeValue11 = new AttributeValueType();
		configNameAttributeValue11.setDataType(STRING_DATATYPE);
		configNameAttributeValue11.getContent().add(policyAdapter.getTtlDate());
		assignment11.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue11));

		advice.getAttributeAssignmentExpression().add(assignment11);

		advices.getAdviceExpression().add(advice);
		return advices;
	}

	@Override
	public Object getCorrectPolicyDataObject() {
		return policyAdapter.getData();
	}
}