@Test public void test_should_not_thrown_exception_when_group_constraint_is_at_least_one_required_and_one_attribute_entry_is_present() { final GroupConstraintAttributeValidator validator = new GroupConstraintAttributeValidator(); final List<AttributeEntry> attributeEntries = Arrays.asList( new AttributeEntry("key1", "value1"), new AttributeEntry("key3", "value1") ); final ServiceRequest serviceRequest = createServiceRequest(attributeEntries, getCitizen()); final AttributeDefinition attributeDefinition1 = AttributeDefinition.builder() .code("key1") .groupCode("groupCode1") .dataType(AttributeDataType.STRING) .build(); final AttributeDefinition attributeDefinition2 = AttributeDefinition.builder() .code("key2") .groupCode("groupCode1") .dataType(AttributeDataType.STRING) .build(); final GroupConstraint groupConstraint = GroupConstraint.builder() .role("CITIZEN") .action(ServiceStatus.CITIZEN_SERVICE_NEW) .constraintType(GroupConstraintType.AT_LEAST_ONE_REQUIRED) .build(); final GroupDefinition groupDefinition = GroupDefinition.builder() .code("groupCode1") .constraints(Collections.singletonList(groupConstraint)) .build(); final List<AttributeDefinition> attributeDefinitions = Arrays.asList(attributeDefinition1, attributeDefinition2); final ServiceDefinition serviceDefinition = ServiceDefinition.builder() .attributes(attributeDefinitions) .groups(Collections.singletonList(groupDefinition)) .build(); validator.validate(serviceRequest, serviceDefinition, ServiceStatus.COMPLAINT_REGISTERED); }
@Override public void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action) { final List<String> roleCodes = getUserRoles(serviceRequest); final List<GroupDefinition> groups = serviceDefinition.getGroupsWithConstraints(action, roleCodes); if (CollectionUtils.isEmpty(groups)) { return; } groups.forEach(group -> validateAttributeEntriesForGroup(group, serviceDefinition, serviceRequest, action)); }
GroupConstraintAttributeValidator implements AttributeValueValidator { @Override public void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action) { final List<String> roleCodes = getUserRoles(serviceRequest); final List<GroupDefinition> groups = serviceDefinition.getGroupsWithConstraints(action, roleCodes); if (CollectionUtils.isEmpty(groups)) { return; } groups.forEach(group -> validateAttributeEntriesForGroup(group, serviceDefinition, serviceRequest, action)); } }
GroupConstraintAttributeValidator implements AttributeValueValidator { @Override public void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action) { final List<String> roleCodes = getUserRoles(serviceRequest); final List<GroupDefinition> groups = serviceDefinition.getGroupsWithConstraints(action, roleCodes); if (CollectionUtils.isEmpty(groups)) { return; } groups.forEach(group -> validateAttributeEntriesForGroup(group, serviceDefinition, serviceRequest, action)); }  }
GroupConstraintAttributeValidator implements AttributeValueValidator { @Override public void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action) { final List<String> roleCodes = getUserRoles(serviceRequest); final List<GroupDefinition> groups = serviceDefinition.getGroupsWithConstraints(action, roleCodes); if (CollectionUtils.isEmpty(groups)) { return; } groups.forEach(group -> validateAttributeEntriesForGroup(group, serviceDefinition, serviceRequest, action)); }  @Override void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action); }
GroupConstraintAttributeValidator implements AttributeValueValidator { @Override public void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action) { final List<String> roleCodes = getUserRoles(serviceRequest); final List<GroupDefinition> groups = serviceDefinition.getGroupsWithConstraints(action, roleCodes); if (CollectionUtils.isEmpty(groups)) { return; } groups.forEach(group -> validateAttributeEntriesForGroup(group, serviceDefinition, serviceRequest, action)); }  @Override void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action);  }