// Path: src/main/java/no/met/metadataeditor/InvalidEditorConfigurationException.java
// public class InvalidEditorConfigurationException extends EditorException {
// 
//     private static final long serialVersionUID = 4902574371399601804L;
// 
//     public static final int UNKNOWN_VARIABLE = 301; // the variable name used in config is not in template
//     public static final int INVALID_WIDGET_CONFIG = 302; // the configuration for a widget is not valid
//     
//     public InvalidEditorConfigurationException(String msg, int errorCode){
//         super(msg, errorCode);
//     }
//     
// }
// 
// Path: src/main/java/no/met/metadataeditor/dataTypes/attributes/StringAttribute.java
// public class StringAttribute extends DataAttribute {
//     
//     @IsAttributeValue(DataType.STRING)
//     String str;
// 
// }


import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import no.met.metadataeditor.InvalidEditorConfigurationException;
import no.met.metadataeditor.dataTypes.attributes.StringAttribute;
package no.met.metadataeditor.widget;



/**
 * Widget for auto generating a UUID value if a value is not found.
 * 
 * The widget only works with string variable with a max and min occurs of 1.
 */
public class AutoUUIDWidget extends EditorWidget {

    private static final long serialVersionUID = -2261929414552684579L;

    public AutoUUIDWidget(){
        super();
    }

    public AutoUUIDWidget(AutoUUIDWidget cloneFrom){
        super(cloneFrom);
    }

    @Override
    public Map<String, String> getDefaultValue() {

        Map<String,String> defaultValue = new HashMap<>();
        String uuid = UUID.randomUUID().toString();
        defaultValue.put("str", uuid);
        return defaultValue;
    }   
    
    @Override
    public void validateConfiguration() {
        
        if( getMaxOccurs() != 1 ){
            throw new InvalidEditorConfigurationException("maxOccurs for a variable associated with a AutoUUIDWidget must be 1", InvalidEditorConfigurationException.INVALID_WIDGET_CONFIG);
        }

        if( getMinOccurs() != 1 ){
// Path: src/main/java/no/met/metadataeditor/InvalidEditorConfigurationException.java
// public class InvalidEditorConfigurationException extends EditorException {
// 
//     private static final long serialVersionUID = 4902574371399601804L;
// 
//     public static final int UNKNOWN_VARIABLE = 301; // the variable name used in config is not in template
//     public static final int INVALID_WIDGET_CONFIG = 302; // the configuration for a widget is not valid
//     
//     public InvalidEditorConfigurationException(String msg, int errorCode){
//         super(msg, errorCode);
//     }
//     
// }
// 
// Path: src/main/java/no/met/metadataeditor/dataTypes/attributes/StringAttribute.java
// public class StringAttribute extends DataAttribute {
//     
//     @IsAttributeValue(DataType.STRING)
//     String str;
// 
// }


// Path: src/main/java/no/met/metadataeditor/widget/AutoUUIDWidget.java
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import no.met.metadataeditor.InvalidEditorConfigurationException;
import no.met.metadataeditor.dataTypes.attributes.StringAttribute;

package no.met.metadataeditor.widget;



/**
 * Widget for auto generating a UUID value if a value is not found.
 * 
 * The widget only works with string variable with a max and min occurs of 1.
 */
public class AutoUUIDWidget extends EditorWidget {

    private static final long serialVersionUID = -2261929414552684579L;

    public AutoUUIDWidget(){
        super();
    }

    public AutoUUIDWidget(AutoUUIDWidget cloneFrom){
        super(cloneFrom);
    }

    @Override
    public Map<String, String> getDefaultValue() {

        Map<String,String> defaultValue = new HashMap<>();
        String uuid = UUID.randomUUID().toString();
        defaultValue.put("str", uuid);
        return defaultValue;
    }   
    
    @Override
    public void validateConfiguration() {
        
        if( getMaxOccurs() != 1 ){
            throw new InvalidEditorConfigurationException("maxOccurs for a variable associated with a AutoUUIDWidget must be 1", InvalidEditorConfigurationException.INVALID_WIDGET_CONFIG);
        }

        if( getMinOccurs() != 1 ){
            throw new InvalidEditorConfigurationException("minOccurs for a variable associated with a AutoUUIDWidget must be 1", InvalidEditorConfigurationException.INVALID_WIDGET_CONFIG);