gcube-model/src/main/java/org/gcube/resourcemanagement/model/reference/properties/EnumStringProperty.java

54 lines
1.8 KiB
Java
Raw Normal View History

package org.gcube.resourcemanagement.model.reference.properties;
import java.util.Set;
2020-07-07 17:12:10 +02:00
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
import org.gcube.resourcemanagement.model.impl.properties.EnumStringPropertyImpl;
import org.gcube.resourcemanagement.model.reference.properties.utilities.PropertyValidator;
import org.gcube.resourcemanagement.model.reference.properties.utilities.ValidatedTypedProperty;
import org.gcube.resourcemanagement.model.reference.properties.utilities.Validation;
/**
* A string property validated against a set of accepted values.
*
* @author Manuele Simi (ISTI - CNR)
2020-12-15 18:51:20 +01:00
* @author Luca Frosini (ISTI - CNR)
*
*/
@JsonDeserialize(as=EnumStringPropertyImpl.class)
@TypeMetadata(
name = EnumStringProperty.NAME,
description = "Enum String Property",
version = Version.MINIMAL_VERSION_STRING
)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface EnumStringProperty extends GCubeProperty, ValidatedTypedProperty<Set<String>, String> {
2020-12-15 20:07:16 +01:00
public static final String NAME = "EnumStringProperty"; //EnumStringProperty.class.getSimpleName();
@Override
default Validation validate() {
return new SetStringValidator().validate(this);
}
/**
* Validator for {@link ValueSchema} properties.
*
* @author Manuele Simi (ISTI CNR)
*
*/
class SetStringValidator implements PropertyValidator<EnumStringProperty> {
@Override
public Validation validate(EnumStringProperty property) {
2020-12-21 16:02:46 +01:00
return property.getSchema().contains(property.getValue()) ? Validation.success("Accepted!")
: Validation.fail(property.getValue() + " is not a valid value.");
}
}
}