2019-03-22 15:51:44 +01:00
|
|
|
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;
|
2020-12-15 18:44:48 +01:00
|
|
|
import org.gcube.informationsystem.types.reference.Change;
|
|
|
|
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
2021-10-21 12:50:29 +02:00
|
|
|
import org.gcube.informationsystem.utils.Version;
|
2019-03-22 15:51:44 +01:00
|
|
|
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)
|
2019-03-22 15:51:44 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
@JsonDeserialize(as=EnumStringPropertyImpl.class)
|
2020-12-15 18:44:48 +01:00
|
|
|
@TypeMetadata(
|
|
|
|
name = EnumStringProperty.NAME,
|
|
|
|
description = "Enum String Property",
|
2021-10-21 12:50:29 +02:00
|
|
|
version = Version.MINIMAL_VERSION_STRING
|
2020-12-15 18:44:48 +01:00
|
|
|
)
|
2021-10-21 12:50:29 +02:00
|
|
|
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
2019-03-22 15:51:44 +01:00
|
|
|
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();
|
|
|
|
|
2019-03-22 15:51:44 +01:00
|
|
|
@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!")
|
2019-03-22 15:51:44 +01:00
|
|
|
: Validation.fail(property.getValue() + " is not a valid value.");
|
|
|
|
}
|
|
|
|
}
|
2020-12-21 13:59:53 +01:00
|
|
|
|
2019-03-22 15:51:44 +01:00
|
|
|
}
|