// Path: src/main/java/org/osiam/addons/administration/model/validation/ExtensionValidator.java
// public class ExtensionValidator {
//     private final String path;
//     private final Map<String, Extension> extensions;
//     private final BindingResult bindingResult;
// 
//     public ExtensionValidator(
//             String path,
//             Map<String, Extension> extensions,
//             BindingResult bindingResult) {
// 
//         this.path = path;
//         this.extensions = extensions;
//         this.bindingResult = bindingResult;
//     }
// 
//     public void validate(String urn, String fieldKey, String fieldValue) {
//         final Extension extension = extensions.get(urn);
//         final Field field = extension.getFields().get(fieldKey);
// 
//         try {
//             field.getType().fromString(fieldValue);
//         } catch (Exception e) {
//             final String fieldPath = getFieldPath(urn, fieldKey);
//             final String message = getMessage(field.getType(), e);
//             final Object[] errorArgs = new Object[] {
//                     urn, fieldKey, fieldValue
//             };
// 
//             bindingResult.rejectValue(fieldPath, message, errorArgs, message);
//         }
//     }
// 
//     private String getMessage(ExtensionFieldType<?> type, Exception e) {
//         return "msg.validation.error.extension." + type.getName().toLowerCase();
//     }
// 
//     private String getFieldPath(String urn, String fieldKey) {
//         return path + "['" + urn + "']['" + fieldKey + "']";
//     }
// 
// }


import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.URL;
import org.osiam.addons.administration.model.validation.ExtensionValidator;
import org.osiam.resources.scim.*;
import org.osiam.resources.scim.Extension.Field;
import org.springframework.validation.BindingResult;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.*;
import java.util.Map.Entry;
    }

    private void removeEmptyExtensions() {
        // remove empty fields
        for (Map<String, String> extension : extensions.values()) {
            Iterator<Entry<String, String>> iter = extension.entrySet().iterator();
            while (iter.hasNext()) {
                Entry<String, String> field = iter.next();

                if (field.getValue() == null || field.getValue().equals("")) {
                    iter.remove();
                }
            }
        }

        // remove empty extensions
        Iterator<Entry<String, SortedMap<String, String>>> iter = extensions.entrySet().iterator();
        while (iter.hasNext()) {
            Entry<String, SortedMap<String, String>> extension = iter.next();
            if (extension.getValue().isEmpty()) {
                iter.remove();
            }
        }
    }

    public void validate(Map<String, Extension> allExtensions, BindingResult bindingResult) {
        validateExtensions(allExtensions, bindingResult);
    }

    private void validateExtensions(Map<String, Extension> allExtensions, BindingResult bindingResult) {
// Path: src/main/java/org/osiam/addons/administration/model/validation/ExtensionValidator.java
// public class ExtensionValidator {
//     private final String path;
//     private final Map<String, Extension> extensions;
//     private final BindingResult bindingResult;
// 
//     public ExtensionValidator(
//             String path,
//             Map<String, Extension> extensions,
//             BindingResult bindingResult) {
// 
//         this.path = path;
//         this.extensions = extensions;
//         this.bindingResult = bindingResult;
//     }
// 
//     public void validate(String urn, String fieldKey, String fieldValue) {
//         final Extension extension = extensions.get(urn);
//         final Field field = extension.getFields().get(fieldKey);
// 
//         try {
//             field.getType().fromString(fieldValue);
//         } catch (Exception e) {
//             final String fieldPath = getFieldPath(urn, fieldKey);
//             final String message = getMessage(field.getType(), e);
//             final Object[] errorArgs = new Object[] {
//                     urn, fieldKey, fieldValue
//             };
// 
//             bindingResult.rejectValue(fieldPath, message, errorArgs, message);
//         }
//     }
// 
//     private String getMessage(ExtensionFieldType<?> type, Exception e) {
//         return "msg.validation.error.extension." + type.getName().toLowerCase();
//     }
// 
//     private String getFieldPath(String urn, String fieldKey) {
//         return path + "['" + urn + "']['" + fieldKey + "']";
//     }
// 
// }


// Path: src/main/java/org/osiam/addons/administration/model/command/UpdateUserCommand.java
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.URL;
import org.osiam.addons.administration.model.validation.ExtensionValidator;
import org.osiam.resources.scim.*;
import org.osiam.resources.scim.Extension.Field;
import org.springframework.validation.BindingResult;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.*;
import java.util.Map.Entry;

    }

    private void removeEmptyExtensions() {
        // remove empty fields
        for (Map<String, String> extension : extensions.values()) {
            Iterator<Entry<String, String>> iter = extension.entrySet().iterator();
            while (iter.hasNext()) {
                Entry<String, String> field = iter.next();

                if (field.getValue() == null || field.getValue().equals("")) {
                    iter.remove();
                }
            }
        }

        // remove empty extensions
        Iterator<Entry<String, SortedMap<String, String>>> iter = extensions.entrySet().iterator();
        while (iter.hasNext()) {
            Entry<String, SortedMap<String, String>> extension = iter.next();
            if (extension.getValue().isEmpty()) {
                iter.remove();
            }
        }
    }

    public void validate(Map<String, Extension> allExtensions, BindingResult bindingResult) {
        validateExtensions(allExtensions, bindingResult);
    }

    private void validateExtensions(Map<String, Extension> allExtensions, BindingResult bindingResult) {
        ExtensionValidator validator = new ExtensionValidator("extensions", allExtensions, bindingResult);