[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-be / lib / openecomp-sdc-validation-lib / att-sdc-validation-impl / src / main / java / com / att / sdc / validation / impl / validators / AttValetGroupAssignmentResourceValidator.java
1 package com.att.sdc.validation.impl.validators;
2
3 import com.att.sdc.validation.datatypes.AttLoggerErrorDescription;
4 import com.att.sdc.validation.datatypes.AttLoggerTargetServiceName;
5 import com.att.sdc.validation.datatypes.AttValetGroupTypeValues;
6 import com.att.sdc.validation.messages.Messages;
7 import org.apache.commons.collections4.MapUtils;
8 import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
9 import org.openecomp.core.validation.types.GlobalValidationContext;
10 import org.openecomp.sdc.datatypes.error.ErrorLevel;
11 import org.openecomp.sdc.heat.datatypes.model.Resource;
12 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
13 import org.openecomp.sdc.validation.ResourceValidator;
14 import org.openecomp.sdc.validation.ValidationContext;
15
16 import java.util.Map;
17 import java.util.Objects;
18
19 /**
20  * Created by TALIO on 2/26/2017.
21  */
22 public class AttValetGroupAssignmentResourceValidator implements ResourceValidator {
23   private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
24
25   @Override
26   public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
27                        GlobalValidationContext globalContext, ValidationContext validationContext) {
28     mdcDataDebugMessage.debugEntryMessage("file", fileName);
29
30     Resource resource = resourceEntry.getValue();
31
32     Map<String, Object> propertiesMap = resource.getProperties();
33     if (MapUtils.isEmpty(propertiesMap)) {
34       return;
35     }
36
37     Object groupTypeValue = propertiesMap.get("group_type");
38     if (Objects.isNull(groupTypeValue)) {
39       return;
40     }
41
42     validateGroupTypeValue(fileName, resourceEntry.getKey(), groupTypeValue, globalContext);
43     mdcDataDebugMessage.debugExitMessage("file", fileName);
44   }
45
46   private static void validateGroupTypeValue(String fileName, String resourceId,
47                                              Object groupTypeValue,
48                                              GlobalValidationContext globalContext) {
49     mdcDataDebugMessage.debugEntryMessage("file", fileName);
50
51     if (!AttValetGroupTypeValues.isGroupTypeValid(groupTypeValue)) {
52       globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
53               .getErrorWithParameters(Messages.UNEXPECTED_GROUP_TYPE_ATT_VALET.getErrorMessage(),
54                   resourceId), AttLoggerTargetServiceName.VALIDATE_ATT_VALET_TYPE,
55           AttLoggerErrorDescription.ATT_VALET_IN_USE);
56     }
57
58     mdcDataDebugMessage.debugExitMessage("file", fileName);
59   }
60 }