Added type changelog
This commit is contained in:
parent
b0b5fdf3cd
commit
619dd586c1
|
@ -106,4 +106,17 @@ public class TypeMapper {
|
|||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <O extends Object> O getStaticFieldByName(Class<? extends Element> clz, String fieldName, O defaultValue){
|
||||
Field field;
|
||||
try {
|
||||
field = clz.getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return (O) field.get(null);
|
||||
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,9 @@ package org.gcube.informationsystem.types.impl;
|
|||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
|
||||
|
@ -40,12 +42,22 @@ public class TypeImpl implements Type {
|
|||
|
||||
public final static String DESCRIPTION = "DESCRIPTION";
|
||||
public final static String VERSION = "VERSION";
|
||||
public final static String CHANGELOG = "CHANGELOG";
|
||||
|
||||
public static final Map<TypeVersion, String> DEFAULT_CHANGELOG_MAP;
|
||||
|
||||
static {
|
||||
DEFAULT_CHANGELOG_MAP = new HashMap<>();
|
||||
DEFAULT_CHANGELOG_MAP.put(new TypeVersion("1.0.0"), "First Version");
|
||||
}
|
||||
|
||||
protected Header header;
|
||||
|
||||
protected String name;
|
||||
protected String description;
|
||||
protected TypeVersion version;
|
||||
protected Map<TypeVersion, String> changelog;
|
||||
|
||||
@JsonProperty(value="abstract")
|
||||
protected boolean abstractType;
|
||||
protected Set<String> superClasses;
|
||||
|
@ -138,8 +150,15 @@ public class TypeImpl implements Type {
|
|||
protected TypeImpl(Class<? extends Element> clz) {
|
||||
this.name = TypeMapper.getType(clz);
|
||||
this.description = TypeMapper.getStaticStringFieldByName(clz, DESCRIPTION, "");
|
||||
String versionString = TypeMapper.getStaticStringFieldByName(clz, VERSION, "1.0.0");
|
||||
String versionString = TypeMapper.getStaticStringFieldByName(clz, VERSION, TypeVersion.MINIMAL_VERSION_STRING);
|
||||
this.version = new TypeVersion(versionString);
|
||||
|
||||
this.changelog = TypeMapper.getStaticFieldByName(clz, CHANGELOG, DEFAULT_CHANGELOG_MAP);
|
||||
|
||||
if(!changelog.containsKey(version)) {
|
||||
throw new RuntimeException("The Type " + name + " does not provided the appropriated changelog Map");
|
||||
}
|
||||
|
||||
this.abstractType = false;
|
||||
|
||||
if(clz.isAnnotationPresent(Abstract.class)){
|
||||
|
@ -184,6 +203,28 @@ public class TypeImpl implements Type {
|
|||
this.version = new TypeVersion(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<TypeVersion, String> getChangelog() {
|
||||
return changelog;
|
||||
}
|
||||
|
||||
@JsonGetter(value=CHANGELOG_PROPERTY)
|
||||
public Map<String, String> getChangelogwithVersionAsString() {
|
||||
Map<String,String> map = new HashMap<>();
|
||||
for(TypeVersion typeVersion : changelog.keySet()) {
|
||||
map.put(typeVersion.toString(), changelog.get(typeVersion));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@JsonSetter(value = CHANGELOG_PROPERTY)
|
||||
public void setChangelog(Map<String, String> changelog) {
|
||||
this.changelog = new HashMap<>();
|
||||
for(String version : changelog.keySet()) {
|
||||
this.changelog.put(new TypeVersion(version), changelog.get(version));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbstract() {
|
||||
return abstractType;
|
||||
|
@ -199,4 +240,6 @@ public class TypeImpl implements Type {
|
|||
return properties;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
|
|||
public final static String UUID_REGEX = "^([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}$";
|
||||
public final static String URI_REGEX = null;
|
||||
public final static String URL_REGEX = null;
|
||||
public final static String TYPE_VERSION_REGEX = "^(0|([1-9][0-9]{0,}))\\.(0|([1-9][0-9]{0,}))\\.(0|([1-9][0-9]{0,}))$";
|
||||
public final static String TYPE_VERSION_REGEX = "^[1-9][0-9]{0,}\\.(0|([1-9][0-9]{0,}))\\.(0|([1-9][0-9]{0,}))$";
|
||||
|
||||
private String name= "";
|
||||
private String description= "";
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.gcube.informationsystem.types.reference;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
@ -18,6 +19,7 @@ public interface Type extends IdentifiableElement {
|
|||
public static final String NAME_PROPERTY = "name";
|
||||
public static final String DESCRIPTION_PROPERTY = "description";
|
||||
public static final String VERSION_PROPERTY = "version";
|
||||
public static final String CHANGELOG_PROPERTY = "changelog";
|
||||
public static final String ABSTRACT_PROPERTY = "abstract";
|
||||
public static final String TYPE_SUPERCLASSES_PROPERTY = "superClasses";
|
||||
public static final String PROPERTIES_PROPERTY = "properties";
|
||||
|
@ -28,6 +30,8 @@ public interface Type extends IdentifiableElement {
|
|||
|
||||
public TypeVersion getVersion();
|
||||
|
||||
public Map<TypeVersion, String> getChangelog();
|
||||
|
||||
public boolean isAbstract();
|
||||
|
||||
public Set<String> getSuperClasses();
|
||||
|
|
|
@ -11,8 +11,12 @@ public class TypeVersion implements Comparable<TypeVersion> {
|
|||
|
||||
public final static Pattern TYPE_VERSION_PATTERN;
|
||||
|
||||
public static final String MINIMAL_VERSION_STRING = "1.0.0";
|
||||
public static final TypeVersion MINIMAL_VERSION;
|
||||
|
||||
static {
|
||||
TYPE_VERSION_PATTERN = Pattern.compile(TYPE_VERSION_REGEX);
|
||||
MINIMAL_VERSION = new TypeVersion(MINIMAL_VERSION_STRING);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
|
@ -32,6 +36,7 @@ public class TypeVersion implements Comparable<TypeVersion> {
|
|||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.revision = revision;
|
||||
check();
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
|
@ -42,6 +47,18 @@ public class TypeVersion implements Comparable<TypeVersion> {
|
|||
this.major = Integer.valueOf(parts[0]);
|
||||
this.minor = Integer.valueOf(parts[1]);
|
||||
this.revision = Integer.valueOf(parts[2]);
|
||||
check();
|
||||
}
|
||||
|
||||
/*
|
||||
* The REGEX does not allow a 0.X.X Version.
|
||||
* Anyway I added this check in case we decide to change the minimal version and the
|
||||
* regex.
|
||||
*/
|
||||
protected void check() {
|
||||
if(this.compareTo(MINIMAL_VERSION)<0) {
|
||||
throw new RuntimeException("Minimal Allowed version is " + MINIMAL_VERSION_STRING);
|
||||
}
|
||||
}
|
||||
|
||||
public int getMajor() {
|
||||
|
@ -92,6 +109,16 @@ public class TypeVersion implements Comparable<TypeVersion> {
|
|||
return compare;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + major;
|
||||
result = prime * result + minor;
|
||||
result = prime * result + revision;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
|
|
|
@ -6,7 +6,7 @@ import org.junit.Test;
|
|||
public class TypeVersionTest {
|
||||
|
||||
String[] validVersions = new String[] {"1.0.0", "13.23.45", "1.12.3"};
|
||||
String[] inValidVersions = new String[] {"1.0", "01.23.45", "1.02.3"};
|
||||
String[] inValidVersions = new String[] {"1.0", "01.23.45", "1.02.3", "0.1.0"};
|
||||
|
||||
@Test
|
||||
public void testPatterns() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue