code changed to match the new hierarchy structure as well as tags and groups reported in ticket #7059
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@142563 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
7f608a504f
commit
b0b56dc1a1
|
@ -18,11 +18,7 @@
|
||||||
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
filesCopiedToWebInfLib=
|
|
@ -12,5 +12,11 @@ import java.lang.annotation.Target;
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.FIELD)
|
@Target(ElementType.FIELD)
|
||||||
public @interface Group {
|
public @interface Group {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define a REGEX condition to be checked before the record
|
||||||
|
* is actually added to the group.
|
||||||
|
*/
|
||||||
|
String condition() default "";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ public class Common extends Base{
|
||||||
|
|
||||||
@JsonProperty("data_owner")
|
@JsonProperty("data_owner")
|
||||||
@CustomField(key="Data owner")
|
@CustomField(key="Data owner")
|
||||||
|
@Tag
|
||||||
private String dataOwner;
|
private String dataOwner;
|
||||||
|
|
||||||
@JsonProperty("database_sources")
|
@JsonProperty("database_sources")
|
||||||
|
@ -49,12 +50,13 @@ public class Common extends Base{
|
||||||
|
|
||||||
@JsonProperty("traceability_flag")
|
@JsonProperty("traceability_flag")
|
||||||
@CustomField(key="Traceability Flag")
|
@CustomField(key="Traceability Flag")
|
||||||
|
@Group(condition="true") // record is added to group if Traceability Flag is true
|
||||||
private Boolean traceabilityFlag;
|
private Boolean traceabilityFlag;
|
||||||
|
|
||||||
@JsonProperty("status")
|
@JsonProperty("status")
|
||||||
@CustomField(key="Status")
|
@CustomField(key="Status")
|
||||||
@Group
|
@Group
|
||||||
@Tag
|
// @Tag
|
||||||
private Status status;
|
private Status status;
|
||||||
|
|
||||||
@JsonProperty("reporting_year")
|
@JsonProperty("reporting_year")
|
||||||
|
@ -64,8 +66,8 @@ public class Common extends Base{
|
||||||
// automatically compiled
|
// automatically compiled
|
||||||
@JsonProperty("product_type")
|
@JsonProperty("product_type")
|
||||||
@CustomField(key=PRODUCT_TYPE_KEY)
|
@CustomField(key=PRODUCT_TYPE_KEY)
|
||||||
@Tag
|
//@Tag
|
||||||
@Group
|
//@Group
|
||||||
private String productType;
|
private String productType;
|
||||||
|
|
||||||
// automatically compiled
|
// automatically compiled
|
||||||
|
|
|
@ -40,6 +40,7 @@ public class FisheryRecord extends Common{
|
||||||
|
|
||||||
@JsonProperty("fishing_area")
|
@JsonProperty("fishing_area")
|
||||||
@CustomField(key="Fishing area")
|
@CustomField(key="Fishing area")
|
||||||
|
@Tag
|
||||||
private List<String> fishingArea;
|
private List<String> fishingArea;
|
||||||
|
|
||||||
@JsonProperty("exploited_stocks")
|
@JsonProperty("exploited_stocks")
|
||||||
|
@ -53,10 +54,11 @@ public class FisheryRecord extends Common{
|
||||||
|
|
||||||
@JsonProperty("jurisdiction_area")
|
@JsonProperty("jurisdiction_area")
|
||||||
@CustomField(key="Jurisdiction Area")
|
@CustomField(key="Jurisdiction Area")
|
||||||
|
@Tag
|
||||||
private List<String> jurisdictionArea;
|
private List<String> jurisdictionArea;
|
||||||
|
|
||||||
@JsonProperty("production_system_type")
|
@JsonProperty("production_system_type")
|
||||||
@Group
|
//@Group
|
||||||
@Tag
|
@Tag
|
||||||
@CustomField(key="Production system type")
|
@CustomField(key="Production system type")
|
||||||
private List<Production_System_Type> productionSystemType;
|
private List<Production_System_Type> productionSystemType;
|
||||||
|
@ -77,7 +79,7 @@ public class FisheryRecord extends Common{
|
||||||
|
|
||||||
@JsonProperty("catches_or_landings")
|
@JsonProperty("catches_or_landings")
|
||||||
@CustomField(key="Catches or landings")
|
@CustomField(key="Catches or landings")
|
||||||
@Tag
|
//@Tag
|
||||||
@TimeSeries
|
@TimeSeries
|
||||||
@Valid
|
@Valid
|
||||||
private List<TimeSeriesBean<String, String>> catchesOrLandings;
|
private List<TimeSeriesBean<String, String>> catchesOrLandings;
|
||||||
|
|
|
@ -41,6 +41,7 @@ public class StockRecord extends Common{
|
||||||
|
|
||||||
@JsonProperty("assessment_distribution_area")
|
@JsonProperty("assessment_distribution_area")
|
||||||
@CustomField(key="Assessment distribution area")
|
@CustomField(key="Assessment distribution area")
|
||||||
|
@Tag
|
||||||
private List<String> area;
|
private List<String> area;
|
||||||
|
|
||||||
@JsonProperty("exploiting_fishery")
|
@JsonProperty("exploiting_fishery")
|
||||||
|
@ -61,7 +62,7 @@ public class StockRecord extends Common{
|
||||||
|
|
||||||
@JsonProperty("standard_exploitation_rate")
|
@JsonProperty("standard_exploitation_rate")
|
||||||
@CustomField(key="Standard Exploitation Rate")
|
@CustomField(key="Standard Exploitation Rate")
|
||||||
@Tag
|
//@Tag
|
||||||
@TimeSeries
|
@TimeSeries
|
||||||
@Valid
|
@Valid
|
||||||
private List<TimeSeriesBean<Exploitation_Rate, Void>> exploitationRateStandard;
|
private List<TimeSeriesBean<Exploitation_Rate, Void>> exploitationRateStandard;
|
||||||
|
@ -74,7 +75,7 @@ public class StockRecord extends Common{
|
||||||
|
|
||||||
@JsonProperty("standard_abundance_level")
|
@JsonProperty("standard_abundance_level")
|
||||||
@CustomField(key="Standard Abundance Level")
|
@CustomField(key="Standard Abundance Level")
|
||||||
@Tag
|
//@Tag
|
||||||
@TimeSeries
|
@TimeSeries
|
||||||
@Valid
|
@Valid
|
||||||
private List<TimeSeriesBean<Abundance_Level, Void>> abundanceLevelStandard;
|
private List<TimeSeriesBean<Abundance_Level, Void>> abundanceLevelStandard;
|
||||||
|
@ -93,9 +94,10 @@ public class StockRecord extends Common{
|
||||||
@CustomField(key="Scientific advice")
|
@CustomField(key="Scientific advice")
|
||||||
private String scientificAdvice;
|
private String scientificAdvice;
|
||||||
|
|
||||||
@JsonProperty("reporting_entity")
|
@JsonProperty("assessor")
|
||||||
@CustomField(key="Reporting entity")
|
@CustomField(key="Assessor")
|
||||||
private String reportingEntity;
|
@Tag
|
||||||
|
private String assessor;
|
||||||
|
|
||||||
@JsonProperty("stock_uri")
|
@JsonProperty("stock_uri")
|
||||||
@CustomField(key="Stock Uri")
|
@CustomField(key="Stock Uri")
|
||||||
|
@ -103,6 +105,7 @@ public class StockRecord extends Common{
|
||||||
|
|
||||||
@JsonProperty("water_area")
|
@JsonProperty("water_area")
|
||||||
@CustomField(key="Water Area")
|
@CustomField(key="Water Area")
|
||||||
|
@Tag
|
||||||
private List<String> waterArea;
|
private List<String> waterArea;
|
||||||
|
|
||||||
@JsonProperty("type")
|
@JsonProperty("type")
|
||||||
|
@ -151,7 +154,7 @@ public class StockRecord extends Common{
|
||||||
List<TimeSeriesBean<Abundance_Level, Void>> abundanceLevelStandard,
|
List<TimeSeriesBean<Abundance_Level, Void>> abundanceLevelStandard,
|
||||||
List<TimeSeriesBean<String, String>> abundanceLevel,
|
List<TimeSeriesBean<String, String>> abundanceLevel,
|
||||||
String narrativeStateAndTrend, String scientificAdvice,
|
String narrativeStateAndTrend, String scientificAdvice,
|
||||||
String reportingEntity, Long reportingYear, String stockUri,
|
String assessor, Long reportingYear, String stockUri,
|
||||||
List<String> waterArea, Stock_Type type) {
|
List<String> waterArea, Stock_Type type) {
|
||||||
super();
|
super();
|
||||||
this.stockName = stockName;
|
this.stockName = stockName;
|
||||||
|
@ -168,7 +171,7 @@ public class StockRecord extends Common{
|
||||||
this.abundanceLevel = abundanceLevel;
|
this.abundanceLevel = abundanceLevel;
|
||||||
this.narrativeStateAndTrend = narrativeStateAndTrend;
|
this.narrativeStateAndTrend = narrativeStateAndTrend;
|
||||||
this.scientificAdvice = scientificAdvice;
|
this.scientificAdvice = scientificAdvice;
|
||||||
this.reportingEntity = reportingEntity;
|
this.assessor = assessor;
|
||||||
this.stockUri = stockUri;
|
this.stockUri = stockUri;
|
||||||
this.waterArea = waterArea;
|
this.waterArea = waterArea;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
@ -305,12 +308,12 @@ public class StockRecord extends Common{
|
||||||
this.scientificAdvice = scientificAdvice;
|
this.scientificAdvice = scientificAdvice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getReportingEntity() {
|
public String getAssessor() {
|
||||||
return reportingEntity;
|
return assessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReportingEntity(String reportingEntity) {
|
public void setAssessor(String assessor) {
|
||||||
this.reportingEntity = reportingEntity;
|
this.assessor = assessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TimeSeriesBean<String, String>> getExploitationRate() {
|
public List<TimeSeriesBean<String, String>> getExploitationRate() {
|
||||||
|
@ -336,7 +339,7 @@ public class StockRecord extends Common{
|
||||||
+ ", abundanceLevel=" + abundanceLevel
|
+ ", abundanceLevel=" + abundanceLevel
|
||||||
+ ", narrativeStateAndTrend=" + narrativeStateAndTrend
|
+ ", narrativeStateAndTrend=" + narrativeStateAndTrend
|
||||||
+ ", scientificAdvice=" + scientificAdvice
|
+ ", scientificAdvice=" + scientificAdvice
|
||||||
+ ", reportingEntity=" + reportingEntity + ", stockUri="
|
+ ", assessor=" + assessor + ", stockUri="
|
||||||
+ stockUri + ", waterArea=" + waterArea + ", type=" + type
|
+ stockUri + ", waterArea=" + waterArea + ", type=" + type
|
||||||
+ "]";
|
+ "]";
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,6 +195,7 @@ public class CommonServiceUtils {
|
||||||
*/
|
*/
|
||||||
private static void getGroupsByField(Field field, Class<?> current, Base record, Set<String> groups, Sources source){
|
private static void getGroupsByField(Field field, Class<?> current, Base record, Set<String> groups, Sources source){
|
||||||
if(field.isAnnotationPresent(Group.class)){
|
if(field.isAnnotationPresent(Group.class)){
|
||||||
|
String conditionToCheck = field.getAnnotation(Group.class).condition();
|
||||||
try{
|
try{
|
||||||
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){
|
||||||
|
@ -206,36 +207,45 @@ public class CommonServiceUtils {
|
||||||
|
|
||||||
// else add all the available elements
|
// else add all the available elements
|
||||||
for (int i = 0; i < asList.size(); i++) {
|
for (int i = 0; i < asList.size(); i++) {
|
||||||
String groupName = HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + asList.get(i).toString().trim());
|
boolean match = conditionToCheck.equals("") ? true : asList.get(i).toString().trim().matches(conditionToCheck);
|
||||||
logger.debug(groupName);
|
if(match){
|
||||||
groups.add(groupName);
|
String groupName = HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + asList.get(i).toString().trim());
|
||||||
|
logger.debug(groupName);
|
||||||
|
groups.add(groupName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
// also convert to the group name that should be on ckan
|
// also convert to the group name that should be on ckan
|
||||||
String groupName = HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + f.toString().trim());
|
boolean match = conditionToCheck.equals("") ? true : f.toString().trim().matches(conditionToCheck);
|
||||||
groups.add(groupName);
|
if(match){
|
||||||
|
String groupName = HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + f.toString().trim());
|
||||||
|
groups.add(groupName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the field is an enumerator, and the enum class is also annotated with @Group
|
// // check if the field is an enumerator, and the enum class is also annotated with @Group
|
||||||
if(field.getType().isEnum() && field.getType().isAnnotationPresent(Group.class)){
|
// if(field.getType().isEnum() && field.getType().isAnnotationPresent(Group.class)){
|
||||||
|
//
|
||||||
logger.info("Class " + field.getClass().getSimpleName() + " has annotation @Group");
|
// logger.info("Class " + field.getClass().getSimpleName() + " has annotation @Group");
|
||||||
|
//
|
||||||
// extract the name from the enum class and add it to the groups
|
// // extract the name from the enum class and add it to the groups
|
||||||
// also convert to the group name that should be on ckan
|
// // also convert to the group name that should be on ckan
|
||||||
String groupName = HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + field.getType().getSimpleName());
|
// String groupName = HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + field.getType().getSimpleName());
|
||||||
groups.add(groupName);
|
// groups.add(groupName);
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Failed to read value for field " + field.getName() + " skipping", e);
|
logger.error("Failed to read value for field " + field.getName() + " skipping", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add the record among the source group (check for grsf-group)
|
||||||
|
groups.add(source.equals(Sources.GRSF) ? "grsf-group" : source.getOrigName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -298,7 +308,6 @@ public class CommonServiceUtils {
|
||||||
* @param record
|
* @param record
|
||||||
* @param username
|
* @param username
|
||||||
* @param tags
|
* @param tags
|
||||||
* @param groups
|
|
||||||
* @param resources
|
* @param resources
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class GrsfPublisherFisheryService {
|
||||||
// Logger
|
// Logger
|
||||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GrsfPublisherFisheryService.class);
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GrsfPublisherFisheryService.class);
|
||||||
|
|
||||||
private static final String PRODUCT_URL_FIELD_KEY = "Product URL";
|
private static final String RECORD_URL_FIELD_KEY = "Record URL";
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("hello")
|
@Path("hello")
|
||||||
|
@ -246,7 +246,7 @@ public class GrsfPublisherFisheryService {
|
||||||
|
|
||||||
// add the "Product URL" to the field
|
// add the "Product URL" to the field
|
||||||
Map<String, List<String>> addField = new HashMap<String, List<String>>();
|
Map<String, List<String>> addField = new HashMap<String, List<String>>();
|
||||||
addField.put(PRODUCT_URL_FIELD_KEY, Arrays.asList(productUrl));
|
addField.put(RECORD_URL_FIELD_KEY, Arrays.asList(productUrl));
|
||||||
catalogue.patchProductCustomFields(id, apiKey, addField);
|
catalogue.patchProductCustomFields(id, apiKey, addField);
|
||||||
|
|
||||||
if(!groups.isEmpty()){
|
if(!groups.isEmpty()){
|
||||||
|
@ -440,8 +440,8 @@ public class GrsfPublisherFisheryService {
|
||||||
|
|
||||||
// retrieve the product url
|
// retrieve the product url
|
||||||
Map<String, String> customFields = dataset.getExtrasAsHashMap();
|
Map<String, String> customFields = dataset.getExtrasAsHashMap();
|
||||||
if(customFields.containsKey(PRODUCT_URL_FIELD_KEY))
|
if(customFields.containsKey(RECORD_URL_FIELD_KEY))
|
||||||
result.put("url", customFields.get(PRODUCT_URL_FIELD_KEY));
|
result.put("url", customFields.get(RECORD_URL_FIELD_KEY));
|
||||||
else
|
else
|
||||||
result.put("url", catalogue.getUnencryptedUrlFromDatasetIdOrName(dataset.getId()));
|
result.put("url", catalogue.getUnencryptedUrlFromDatasetIdOrName(dataset.getId()));
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class GrsfPublisherStockService {
|
||||||
// Logger
|
// Logger
|
||||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GrsfPublisherStockService.class);
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GrsfPublisherStockService.class);
|
||||||
|
|
||||||
private static final String PRODUCT_URL_FIELD_KEY = "Product URL";
|
private static final String RECORD_URL_FIELD_KEY = "Record URL";
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("hello")
|
@Path("hello")
|
||||||
|
@ -236,7 +236,7 @@ public class GrsfPublisherStockService {
|
||||||
|
|
||||||
// add the "Product URL" to the field
|
// add the "Product URL" to the field
|
||||||
Map<String, List<String>> addField = new HashMap<String, List<String>>();
|
Map<String, List<String>> addField = new HashMap<String, List<String>>();
|
||||||
addField.put(PRODUCT_URL_FIELD_KEY, Arrays.asList(productUrl));
|
addField.put(RECORD_URL_FIELD_KEY, Arrays.asList(productUrl));
|
||||||
catalogue.patchProductCustomFields(id, apiKey, addField);
|
catalogue.patchProductCustomFields(id, apiKey, addField);
|
||||||
|
|
||||||
if(!groups.isEmpty()){
|
if(!groups.isEmpty()){
|
||||||
|
@ -431,8 +431,8 @@ public class GrsfPublisherStockService {
|
||||||
|
|
||||||
// retrieve the product url
|
// retrieve the product url
|
||||||
Map<String, String> customFields = dataset.getExtrasAsHashMap();
|
Map<String, String> customFields = dataset.getExtrasAsHashMap();
|
||||||
if(customFields.containsKey(PRODUCT_URL_FIELD_KEY))
|
if(customFields.containsKey(RECORD_URL_FIELD_KEY))
|
||||||
result.put("url", customFields.get(PRODUCT_URL_FIELD_KEY));
|
result.put("url", customFields.get(RECORD_URL_FIELD_KEY));
|
||||||
else
|
else
|
||||||
result.put("url", catalogue.getUnencryptedUrlFromDatasetIdOrName(dataset.getId()));
|
result.put("url", catalogue.getUnencryptedUrlFromDatasetIdOrName(dataset.getId()));
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,8 @@ public enum Status {
|
||||||
Approved("Approved"),
|
Approved("Approved"),
|
||||||
Rejected("Rejected"),
|
Rejected("Rejected"),
|
||||||
Archived("Archived"),
|
Archived("Archived"),
|
||||||
Hidden("Hidden");
|
Hidden("Hidden"),
|
||||||
|
Merged("Merged");
|
||||||
|
|
||||||
private String origName;
|
private String origName;
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,8 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
*/
|
*/
|
||||||
public enum Stock_Type {
|
public enum Stock_Type {
|
||||||
|
|
||||||
Assessment_Unit("Assessment Unit"),// for stock
|
Assessment_Unit("Assessment Unit"),
|
||||||
Resource("Resource"); // for stock
|
Resource("Marine Resource");
|
||||||
|
|
||||||
private String subGroupNameOrig;
|
private String subGroupNameOrig;
|
||||||
|
|
||||||
|
|
|
@ -527,4 +527,15 @@ public class JTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//@Test
|
||||||
|
public void testMatch(){
|
||||||
|
|
||||||
|
Boolean value = Boolean.TRUE;
|
||||||
|
String expr = "false";
|
||||||
|
|
||||||
|
System.out.println("Check " + value.toString().matches(expr));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue