diff --git a/.classpath b/.classpath index 6b5910d..d6737f6 100644 --- a/.classpath +++ b/.classpath @@ -18,11 +18,7 @@ - - - - - + diff --git a/.settings/com.google.gwt.eclipse.core.prefs b/.settings/com.google.gwt.eclipse.core.prefs new file mode 100644 index 0000000..82c36af --- /dev/null +++ b/.settings/com.google.gwt.eclipse.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +filesCopiedToWebInfLib= diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/custom_annotations/Group.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/custom_annotations/Group.java index 644e6c9..67af7d3 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/custom_annotations/Group.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/custom_annotations/Group.java @@ -12,5 +12,11 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Group { + + /** + * Define a REGEX condition to be checked before the record + * is actually added to the group. + */ + String condition() default ""; } diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/Common.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/Common.java index 611d46d..bfe251d 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/Common.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/Common.java @@ -27,6 +27,7 @@ public class Common extends Base{ @JsonProperty("data_owner") @CustomField(key="Data owner") + @Tag private String dataOwner; @JsonProperty("database_sources") @@ -49,12 +50,13 @@ public class Common extends Base{ @JsonProperty("traceability_flag") @CustomField(key="Traceability Flag") + @Group(condition="true") // record is added to group if Traceability Flag is true private Boolean traceabilityFlag; @JsonProperty("status") @CustomField(key="Status") @Group - @Tag + // @Tag private Status status; @JsonProperty("reporting_year") @@ -64,8 +66,8 @@ public class Common extends Base{ // automatically compiled @JsonProperty("product_type") @CustomField(key=PRODUCT_TYPE_KEY) - @Tag - @Group + //@Tag + //@Group private String productType; // automatically compiled diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/FisheryRecord.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/FisheryRecord.java index 3d42051..764682b 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/FisheryRecord.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/FisheryRecord.java @@ -40,6 +40,7 @@ public class FisheryRecord extends Common{ @JsonProperty("fishing_area") @CustomField(key="Fishing area") + @Tag private List fishingArea; @JsonProperty("exploited_stocks") @@ -53,10 +54,11 @@ public class FisheryRecord extends Common{ @JsonProperty("jurisdiction_area") @CustomField(key="Jurisdiction Area") + @Tag private List jurisdictionArea; @JsonProperty("production_system_type") - @Group + //@Group @Tag @CustomField(key="Production system type") private List productionSystemType; @@ -77,7 +79,7 @@ public class FisheryRecord extends Common{ @JsonProperty("catches_or_landings") @CustomField(key="Catches or landings") - @Tag + //@Tag @TimeSeries @Valid private List> catchesOrLandings; diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/StockRecord.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/StockRecord.java index c0bfba5..8d2f18d 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/StockRecord.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/StockRecord.java @@ -41,6 +41,7 @@ public class StockRecord extends Common{ @JsonProperty("assessment_distribution_area") @CustomField(key="Assessment distribution area") + @Tag private List area; @JsonProperty("exploiting_fishery") @@ -61,7 +62,7 @@ public class StockRecord extends Common{ @JsonProperty("standard_exploitation_rate") @CustomField(key="Standard Exploitation Rate") - @Tag + //@Tag @TimeSeries @Valid private List> exploitationRateStandard; @@ -74,7 +75,7 @@ public class StockRecord extends Common{ @JsonProperty("standard_abundance_level") @CustomField(key="Standard Abundance Level") - @Tag + //@Tag @TimeSeries @Valid private List> abundanceLevelStandard; @@ -93,9 +94,10 @@ public class StockRecord extends Common{ @CustomField(key="Scientific advice") private String scientificAdvice; - @JsonProperty("reporting_entity") - @CustomField(key="Reporting entity") - private String reportingEntity; + @JsonProperty("assessor") + @CustomField(key="Assessor") + @Tag + private String assessor; @JsonProperty("stock_uri") @CustomField(key="Stock Uri") @@ -103,6 +105,7 @@ public class StockRecord extends Common{ @JsonProperty("water_area") @CustomField(key="Water Area") + @Tag private List waterArea; @JsonProperty("type") @@ -151,7 +154,7 @@ public class StockRecord extends Common{ List> abundanceLevelStandard, List> abundanceLevel, String narrativeStateAndTrend, String scientificAdvice, - String reportingEntity, Long reportingYear, String stockUri, + String assessor, Long reportingYear, String stockUri, List waterArea, Stock_Type type) { super(); this.stockName = stockName; @@ -168,7 +171,7 @@ public class StockRecord extends Common{ this.abundanceLevel = abundanceLevel; this.narrativeStateAndTrend = narrativeStateAndTrend; this.scientificAdvice = scientificAdvice; - this.reportingEntity = reportingEntity; + this.assessor = assessor; this.stockUri = stockUri; this.waterArea = waterArea; this.type = type; @@ -305,12 +308,12 @@ public class StockRecord extends Common{ this.scientificAdvice = scientificAdvice; } - public String getReportingEntity() { - return reportingEntity; + public String getAssessor() { + return assessor; } - public void setReportingEntity(String reportingEntity) { - this.reportingEntity = reportingEntity; + public void setAssessor(String assessor) { + this.assessor = assessor; } public List> getExploitationRate() { @@ -336,7 +339,7 @@ public class StockRecord extends Common{ + ", abundanceLevel=" + abundanceLevel + ", narrativeStateAndTrend=" + narrativeStateAndTrend + ", scientificAdvice=" + scientificAdvice - + ", reportingEntity=" + reportingEntity + ", stockUri=" + + ", assessor=" + assessor + ", stockUri=" + stockUri + ", waterArea=" + waterArea + ", type=" + type + "]"; } diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/CommonServiceUtils.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/CommonServiceUtils.java index b9cd6db..83ee7eb 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/CommonServiceUtils.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/CommonServiceUtils.java @@ -195,6 +195,7 @@ public class CommonServiceUtils { */ private static void getGroupsByField(Field field, Class current, Base record, Set groups, Sources source){ if(field.isAnnotationPresent(Group.class)){ + String conditionToCheck = field.getAnnotation(Group.class).condition(); try{ Object f = new PropertyDescriptor(field.getName(), current).getReadMethod().invoke(record); if(f != null){ @@ -206,36 +207,45 @@ public class CommonServiceUtils { // else add all the available elements for (int i = 0; i < asList.size(); i++) { - String groupName = HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + asList.get(i).toString().trim()); - logger.debug(groupName); - groups.add(groupName); + boolean match = conditionToCheck.equals("") ? true : asList.get(i).toString().trim().matches(conditionToCheck); + if(match){ + String groupName = HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + asList.get(i).toString().trim()); + logger.debug(groupName); + groups.add(groupName); + } } } }else{ // also convert to the group name that should be on ckan - String groupName = HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + f.toString().trim()); - groups.add(groupName); + boolean match = conditionToCheck.equals("") ? true : f.toString().trim().matches(conditionToCheck); + 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 - if(field.getType().isEnum() && field.getType().isAnnotationPresent(Group.class)){ - - logger.info("Class " + field.getClass().getSimpleName() + " has annotation @Group"); - - // extract the name from the enum class and add it to the groups - // also convert to the group name that should be on ckan - String groupName = HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + field.getType().getSimpleName()); - groups.add(groupName); - - } + // // 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)){ + // + // logger.info("Class " + field.getClass().getSimpleName() + " has annotation @Group"); + // + // // extract the name from the enum class and add it to the groups + // // also convert to the group name that should be on ckan + // String groupName = HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + field.getType().getSimpleName()); + // groups.add(groupName); + // + // } }catch(Exception 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 username * @param tags - * @param groups * @param resources * @return */ diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherFisheryService.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherFisheryService.java index 6ab460d..3948687 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherFisheryService.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherFisheryService.java @@ -63,7 +63,7 @@ public class GrsfPublisherFisheryService { // Logger 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 @Path("hello") @@ -246,7 +246,7 @@ public class GrsfPublisherFisheryService { // add the "Product URL" to the field Map> addField = new HashMap>(); - addField.put(PRODUCT_URL_FIELD_KEY, Arrays.asList(productUrl)); + addField.put(RECORD_URL_FIELD_KEY, Arrays.asList(productUrl)); catalogue.patchProductCustomFields(id, apiKey, addField); if(!groups.isEmpty()){ @@ -440,8 +440,8 @@ public class GrsfPublisherFisheryService { // retrieve the product url Map customFields = dataset.getExtrasAsHashMap(); - if(customFields.containsKey(PRODUCT_URL_FIELD_KEY)) - result.put("url", customFields.get(PRODUCT_URL_FIELD_KEY)); + if(customFields.containsKey(RECORD_URL_FIELD_KEY)) + result.put("url", customFields.get(RECORD_URL_FIELD_KEY)); else result.put("url", catalogue.getUnencryptedUrlFromDatasetIdOrName(dataset.getId())); diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java index a22abaf..74f4502 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java @@ -63,7 +63,7 @@ public class GrsfPublisherStockService { // Logger 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 @Path("hello") @@ -236,7 +236,7 @@ public class GrsfPublisherStockService { // add the "Product URL" to the field Map> addField = new HashMap>(); - addField.put(PRODUCT_URL_FIELD_KEY, Arrays.asList(productUrl)); + addField.put(RECORD_URL_FIELD_KEY, Arrays.asList(productUrl)); catalogue.patchProductCustomFields(id, apiKey, addField); if(!groups.isEmpty()){ @@ -431,8 +431,8 @@ public class GrsfPublisherStockService { // retrieve the product url Map customFields = dataset.getExtrasAsHashMap(); - if(customFields.containsKey(PRODUCT_URL_FIELD_KEY)) - result.put("url", customFields.get(PRODUCT_URL_FIELD_KEY)); + if(customFields.containsKey(RECORD_URL_FIELD_KEY)) + result.put("url", customFields.get(RECORD_URL_FIELD_KEY)); else result.put("url", catalogue.getUnencryptedUrlFromDatasetIdOrName(dataset.getId())); diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Status.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Status.java index 06d0559..266f4e7 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Status.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Status.java @@ -13,7 +13,8 @@ public enum Status { Approved("Approved"), Rejected("Rejected"), Archived("Archived"), - Hidden("Hidden"); + Hidden("Hidden"), + Merged("Merged"); private String origName; diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Stock_Type.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Stock_Type.java index 4c2cbaf..9337abc 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Stock_Type.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/groups/Stock_Type.java @@ -10,8 +10,8 @@ import com.fasterxml.jackson.annotation.JsonValue; */ public enum Stock_Type { - Assessment_Unit("Assessment Unit"),// for stock - Resource("Resource"); // for stock + Assessment_Unit("Assessment Unit"), + Resource("Marine Resource"); private String subGroupNameOrig; diff --git a/src/test/java/org/gcube/data_catalogue/grsf_publish_ws/JTests.java b/src/test/java/org/gcube/data_catalogue/grsf_publish_ws/JTests.java index 3e51dbb..2e2c070 100644 --- a/src/test/java/org/gcube/data_catalogue/grsf_publish_ws/JTests.java +++ b/src/test/java/org/gcube/data_catalogue/grsf_publish_ws/JTests.java @@ -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)); + + + } }