aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/impl/validators/AttValetGroupAssignmentResourceValidator.java
blob: 30b65f4b3ea78da3068d7b33212e4d7d66b76be6 (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
package com.att.sdc.validation.impl.validators;

import com.att.sdc.validation.datatypes.AttLoggerErrorDescription;
import com.att.sdc.validation.datatypes.AttLoggerTargetServiceName;
import com.att.sdc.validation.datatypes.AttValetGroupTypeValues;
import com.att.sdc.validation.messages.Messages;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
import org.openecomp.core.validation.types.GlobalValidationContext;
import org.openecomp.sdc.datatypes.error.ErrorLevel;
import org.openecomp.sdc.heat.datatypes.model.Resource;
import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
import org.openecomp.sdc.validation.ResourceValidator;
import org.openecomp.sdc.validation.ValidationContext;

import java.util.Map;
import java.util.Objects;

/**
 * Created by TALIO on 2/26/2017.
 */
public class AttValetGroupAssignmentResourceValidator implements ResourceValidator {
  private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();

  @Override
  public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
                       GlobalValidationContext globalContext, ValidationContext validationContext) {
    mdcDataDebugMessage.debugEntryMessage("file", fileName);

    Resource resource = resourceEntry.getValue();

    Map<String, Object> propertiesMap = resource.getProperties();
    if (MapUtils.isEmpty(propertiesMap)) {
      return;
    }

    Object groupTypeValue = propertiesMap.get("group_type");
    if (Objects.isNull(groupTypeValue)) {
      return;
    }

    validateGroupTypeValue(fileName, resourceEntry.getKey(), groupTypeValue, globalContext);
    mdcDataDebugMessage.debugExitMessage("file", fileName);
  }

  private static void validateGroupTypeValue(String fileName, String resourceId,
                                             Object groupTypeValue,
                                             GlobalValidationContext globalContext) {
    mdcDataDebugMessage.debugEntryMessage("file", fileName);

    if (!AttValetGroupTypeValues.isGroupTypeValid(groupTypeValue)) {
      globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
              .getErrorWithParameters(Messages.UNEXPECTED_GROUP_TYPE_ATT_VALET.getErrorMessage(),
                  resourceId), AttLoggerTargetServiceName.VALIDATE_ATT_VALET_TYPE,
          AttLoggerErrorDescription.ATT_VALET_IN_USE);
    }

    mdcDataDebugMessage.debugExitMessage("file", fileName);
  }
}