Fields with @group annotation have also the @tag one.
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@133165 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9f71232585
commit
a0a0dd48b5
|
@ -50,13 +50,11 @@ public class Common {
|
||||||
private String catchesOrLandings;
|
private String catchesOrLandings;
|
||||||
|
|
||||||
@JsonProperty("database_sources")
|
@JsonProperty("database_sources")
|
||||||
@CustomField(key="Database sources")
|
|
||||||
@NotNull(message="database_source cannot be null")
|
@NotNull(message="database_source cannot be null")
|
||||||
@Size(min=1, message="database_source cannot be empty")
|
@Size(min=1, message="database_source cannot be empty")
|
||||||
private List<DatabaseSource> databaseSources;
|
private List<DatabaseSource> databaseSources;
|
||||||
|
|
||||||
@JsonProperty("source_of_information")
|
@JsonProperty("source_of_information")
|
||||||
@CustomField(key="Source of information")
|
|
||||||
@NotNull(message="source_of_information cannot be null")
|
@NotNull(message="source_of_information cannot be null")
|
||||||
@Size(min=1, message="source_of_information cannot be empty")
|
@Size(min=1, message="source_of_information cannot be empty")
|
||||||
private List<Resource> sourceOfInformation;
|
private List<Resource> sourceOfInformation;
|
||||||
|
|
|
@ -4,6 +4,7 @@ import javax.validation.constraints.NotNull;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.Group;
|
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.Group;
|
||||||
|
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.Tag;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Source;
|
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Source;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
@ -26,6 +27,7 @@ public class DatabaseSource {
|
||||||
|
|
||||||
@JsonProperty("name")
|
@JsonProperty("name")
|
||||||
@Group
|
@Group
|
||||||
|
@Tag
|
||||||
@NotNull(message="'name' attribute of database_source is missing or wrong")
|
@NotNull(message="'name' attribute of database_source is missing or wrong")
|
||||||
private Source name;
|
private Source name;
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ public class FisheryRecord extends Common{
|
||||||
|
|
||||||
@JsonProperty("production_system_type")
|
@JsonProperty("production_system_type")
|
||||||
@Group
|
@Group
|
||||||
|
@Tag
|
||||||
@CustomField(key="Production system type")
|
@CustomField(key="Production system type")
|
||||||
private Production_System_Type productionSystemType;
|
private Production_System_Type productionSystemType;
|
||||||
|
|
||||||
|
@ -66,6 +67,7 @@ public class FisheryRecord extends Common{
|
||||||
@JsonProperty("status")
|
@JsonProperty("status")
|
||||||
@CustomField(key="Status")
|
@CustomField(key="Status")
|
||||||
@Group
|
@Group
|
||||||
|
@Tag
|
||||||
@NotNull(message="status cannot be null")
|
@NotNull(message="status cannot be null")
|
||||||
private Status status;
|
private Status status;
|
||||||
|
|
||||||
|
|
|
@ -59,11 +59,13 @@ public class StockRecord extends Common{
|
||||||
@JsonProperty("exploitation_rate")
|
@JsonProperty("exploitation_rate")
|
||||||
@CustomField(key="Exploitation rate")
|
@CustomField(key="Exploitation rate")
|
||||||
@Group
|
@Group
|
||||||
|
@Tag
|
||||||
private Exploitation_Rate exploitationRate;
|
private Exploitation_Rate exploitationRate;
|
||||||
|
|
||||||
@JsonProperty("abundance_level")
|
@JsonProperty("abundance_level")
|
||||||
@CustomField(key="Abundance level")
|
@CustomField(key="Abundance level")
|
||||||
@Group
|
@Group
|
||||||
|
@Tag
|
||||||
private Abundance_Level abundanceLevel;
|
private Abundance_Level abundanceLevel;
|
||||||
|
|
||||||
@JsonProperty("narrative_state_and_trend")
|
@JsonProperty("narrative_state_and_trend")
|
||||||
|
|
|
@ -94,6 +94,7 @@ public abstract class HelperMethods {
|
||||||
* Retrieve the list of tags for this object
|
* Retrieve the list of tags for this object
|
||||||
*/
|
*/
|
||||||
public static void getTags(List<String> tags, Common record){
|
public static void getTags(List<String> tags, Common record){
|
||||||
|
|
||||||
Class<?> current = record.getClass();
|
Class<?> current = record.getClass();
|
||||||
do{
|
do{
|
||||||
Field[] fields = current.getDeclaredFields();
|
Field[] fields = current.getDeclaredFields();
|
||||||
|
@ -103,35 +104,7 @@ public abstract class HelperMethods {
|
||||||
Object f = new PropertyDescriptor(field.getName(), current).getReadMethod().invoke(record);
|
Object f = new PropertyDescriptor(field.getName(), current).getReadMethod().invoke(record);
|
||||||
if(f != null){
|
if(f != null){
|
||||||
|
|
||||||
tags.add(f.toString());
|
tags.add(f.toString().trim());
|
||||||
|
|
||||||
}
|
|
||||||
}catch(Exception e){
|
|
||||||
logger.error("Failed ot read value for field " + field.getName() + " skipping", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while((current = current.getSuperclass())!=null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the list of groups' names for this object
|
|
||||||
*/
|
|
||||||
public static void getGroups(List<String> groups, Common record){
|
|
||||||
Class<?> current = record.getClass();
|
|
||||||
do{
|
|
||||||
Field[] fields = current.getDeclaredFields();
|
|
||||||
for (Field field : fields) {
|
|
||||||
if(field.isAnnotationPresent(Group.class)){
|
|
||||||
try{
|
|
||||||
Object f = new PropertyDescriptor(field.getName(), current).getReadMethod().invoke(record);
|
|
||||||
if(f != null){
|
|
||||||
|
|
||||||
// also convert to the group name that should be on ckan
|
|
||||||
String groupName = getGroupNameOnCkan(f.toString());
|
|
||||||
if(!groups.contains(groupName))
|
|
||||||
groups.add(groupName);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
@ -142,13 +115,54 @@ public abstract class HelperMethods {
|
||||||
}
|
}
|
||||||
while((current = current.getSuperclass())!=null);
|
while((current = current.getSuperclass())!=null);
|
||||||
|
|
||||||
|
// now parse also the Database Sources field
|
||||||
|
List<DatabaseSource> sources = record.getDatabaseSources();
|
||||||
|
for (DatabaseSource databaseSource : sources) {
|
||||||
|
logger.debug("Database source is " + databaseSource);
|
||||||
|
String nameAsTag = databaseSource.getName().toString();
|
||||||
|
if(!tags.contains(nameAsTag))
|
||||||
|
tags.add(nameAsTag);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the list of groups' names for this object
|
||||||
|
*/
|
||||||
|
public static void getGroups(List<String> groups, Common record){
|
||||||
|
|
||||||
|
Class<?> current = record.getClass();
|
||||||
|
do{
|
||||||
|
Field[] fields = current.getDeclaredFields();
|
||||||
|
for (Field field : fields) {
|
||||||
|
if(field.isAnnotationPresent(Group.class)){
|
||||||
|
try{
|
||||||
|
Object f = new PropertyDescriptor(field.getName(), current).getReadMethod().invoke(record);
|
||||||
|
if(f != null){
|
||||||
|
|
||||||
|
// also convert to the group name that should be on ckan
|
||||||
|
String groupName = getGroupNameOnCkan(f.toString().trim());
|
||||||
|
if(!groups.contains(groupName))
|
||||||
|
groups.add(groupName);
|
||||||
|
|
||||||
|
}
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Failed ot read value for field " + field.getName() + " skipping", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while((current = current.getSuperclass())!=null);
|
||||||
|
|
||||||
|
logger.debug("Groups is " + groups);
|
||||||
|
|
||||||
// now parse also the Database Sources field
|
// now parse also the Database Sources field
|
||||||
List<DatabaseSource> sources = record.getDatabaseSources();
|
List<DatabaseSource> sources = record.getDatabaseSources();
|
||||||
for (DatabaseSource databaseSource : sources) {
|
for (DatabaseSource databaseSource : sources) {
|
||||||
|
|
||||||
logger.debug("Database source is " + databaseSource);
|
logger.debug("Database source is " + databaseSource);
|
||||||
Source name = databaseSource.getName();
|
Source name = databaseSource.getName();
|
||||||
String groupName = getGroupNameOnCkan(name.toString());
|
String groupName = getGroupNameOnCkan(name.toString().trim());
|
||||||
if(!groups.contains(groupName))
|
if(!groups.contains(groupName))
|
||||||
groups.add(groupName);
|
groups.add(groupName);
|
||||||
|
|
||||||
|
@ -159,6 +173,7 @@ public abstract class HelperMethods {
|
||||||
* Retrieve the list of extras for this object
|
* Retrieve the list of extras for this object
|
||||||
*/
|
*/
|
||||||
public static void getExtras(Map<String, String> extras, Common record){
|
public static void getExtras(Map<String, String> extras, Common record){
|
||||||
|
|
||||||
Class<?> current = record.getClass();
|
Class<?> current = record.getClass();
|
||||||
do{
|
do{
|
||||||
Field[] fields = current.getDeclaredFields();
|
Field[] fields = current.getDeclaredFields();
|
||||||
|
@ -169,7 +184,7 @@ public abstract class HelperMethods {
|
||||||
if(f != null){
|
if(f != null){
|
||||||
|
|
||||||
// get the key to put into the map first
|
// get the key to put into the map first
|
||||||
extras.put(field.getAnnotation(CustomField.class).key(), f.toString());
|
extras.put(field.getAnnotation(CustomField.class).key(), f.toString().trim());
|
||||||
|
|
||||||
}
|
}
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
|
Loading…
Reference in New Issue