Compare commits

..

No commits in common. "master" and "feature/22825" have entirely different histories.

22 changed files with 226 additions and 783 deletions

1
.gitignore vendored
View File

@ -1,4 +1,3 @@
target
.classpath
.project
/.DS_Store

View File

@ -1,6 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View File

@ -3,24 +3,9 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.13.3]
- Adding support for "FAO SDG 14.4.1 Questionnaire" source [#23670]
## [v1.13.2]
- Migrated request to social-service-client [#23679]
- Added "Assessment Methods" as Group [#23409]
## [v1.13.1]
- Aligned code and wiki to the new requirements [#23167]
- Changed group assign strategy [#23211] [#23215]
- Tag are added also to legacy records [#23216]
- Fixed code which generated groups id from name [#23215]
## [v1.13.1-SNAPSHOT]
- Enhanced range of storagehub-client-library to 2.0.0,3.0.0-SNAPSHOT [#22825]
## [v1.13.0]

20
pom.xml
View File

@ -11,7 +11,7 @@
<groupId>org.gcube.data-catalogue</groupId>
<artifactId>grsf-publisher-ws</artifactId>
<version>1.13.3</version>
<version>1.13.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>grsf-publisher-ws</name>
<description>Utility library to publish GRSF products on GRSF catalogue.</description>
@ -26,7 +26,6 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jsoup.version>1.10.1</jsoup.version>
<serviceClass>DataPublishing</serviceClass>
<maven.compiler.release>8</maven.compiler.release>
</properties>
<scm>
@ -40,7 +39,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-smartgears-bom</artifactId>
<version>2.2.0</version>
<version>2.1.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -51,17 +50,12 @@
<dependency>
<groupId>org.gcube.data-catalogue</groupId>
<artifactId>grsf-common-library</artifactId>
<version>[2.0.0, 3.0.0-SNAPSHOT)</version>
<version>[1-0-0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-library</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.social-networking</groupId>
<artifactId>social-service-client</artifactId>
<version>[1.0.0, 2.0.0-SNAPSHOT)</version>
</dependency>
<!-- jsoup HTML parser library @ http://jsoup.org/ -->
<dependency>
<groupId>org.jsoup</groupId>
@ -168,14 +162,6 @@
<artifactId>jersey-test-framework-provider-jetty</artifactId>
<scope>test</scope>
</dependency>
<!-- Added to support Java 11 JDK -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<!-- END Added to support Java 11 JDK -->
</dependencies>
<build>

View File

@ -21,8 +21,8 @@ public @interface Group {
String condition() default "";
/**
* If this value is set, it is used as name of the group in place of the filed value.
* (apart the source, i.e. "grsf", "ram", "firms", "fishsource" that will be prepended depending on prependSourceToGroupName)
* If this value is set, it is the name of the group (apart the source, i.e. "grsf", "ram", "firms", "fishsource" that will be prepended) to which the
* record needs to be put.
* @return
*/
String groupNameOverValue() default "";
@ -32,6 +32,6 @@ public @interface Group {
* Set to false to avoid source prepending
* @return
*/
boolean prependSourceToGroupName() default false;
boolean prependSourceToGroupName() default true;
}

View File

@ -202,18 +202,12 @@ public abstract class Base {
@Override
public String toString() {
return "Base ["
+ "catalogId=" + catalogId
+ ", description=" + description
+ ", license=" + license
+ ", author=" + author
+ ", authorContact=" + authorContact
+ ", version=" + version
+ ", maintainer=" + maintainer
+ ", maintainerContact=" + maintainerContact
+ ", extrasFields=" + extrasFields
+ ", extrasResources=" + extrasResources
+ "]";
return "Base [catalogId=" + catalogId + ", description=" + description
+ ", license=" + license + ", author=" + author
+ ", authorContact=" + authorContact + ", version=" + version
+ ", maintainer=" + maintainer + ", maintainerContact="
+ maintainerContact + ", extrasFields=" + extrasFields
+ ", extrasResources=" + extrasResources + "]";
}
}

View File

@ -28,14 +28,13 @@ import com.fasterxml.jackson.annotation.JsonProperty;
* @author Luca Frosini (ISTI - CNR)
*
*/
public abstract class Common extends Base {
public abstract class Common extends Base{
@JsonProperty(Constants.DATA_OWNER_JSON_KEY)
@CustomField(key=Constants.DATA_OWNER_CUSTOM_KEY)
private List<String> dataOwner;
@JsonProperty(Constants.DATABASE_SOURCES_JSON_KEY)
@CustomField(key=Constants.DATABASE_SOURCES_CUSTOM_KEY)
@CkanResource
@Valid
private List<Resource<Sources>> databaseSources;
@ -55,7 +54,7 @@ public abstract class Common extends Base {
@JsonProperty(Constants.SDG_FLAG_JSON_KEY)
@CustomField(key=Constants.SDG_FLAG_CUSTOM_KEY)
@Group(condition="true", groupNameOverValue=Constants.SDG_FLAG_GROUP_NAME, prependSourceToGroupName=false) // record is added to group grsf-sdg-flag if sdg Flag is true
@Group(condition="true", groupNameOverValue=Constants.SDG_FLAG_GROUP_NAME) // record is added to group grsf-sdg-flag if sdg Flag is true
private Boolean sdgFlag;
@JsonProperty(Constants.STATUS_OF_THE_GRSF_RECORD_JSON_KEY)
@ -89,6 +88,10 @@ public abstract class Common extends Base {
@CustomField(key=Constants.SIMILAR_GRSF_RECORDS_CUSTOM_KEY)
private List<SimilarRecordBean> similarGRSFRecords;
@JsonProperty(Constants.SIMILAR_SOURCE_RECORDS_JSON_KEY)
@CustomField(key=Constants.SIMILAR_SOURCE_RECORDS_CUSTOM_KEY)
private List<SimilarRecordBean> similarSourceRecords;
// automatically set
@CustomField(key=Constants.DOMAIN_CUSTOM_KEY)
private String domain;
@ -110,11 +113,7 @@ public abstract class Common extends Base {
@JsonProperty(Constants.CONNECTED_JSON_KEY)
@CustomField(key=Constants.CONNECTED_CUSTOM_KEY)
private List<String> connectedBeans;
@JsonProperty(Constants.CONNECTIONS_INDICATOR)
@Tag
private String connectionsIndicator;
@JsonProperty(Constants.ANNOTATION_PUBLISHER_JSON_KEY)
@CustomField(key=Constants.ANNOTATION_PUBLISHER_CUSTOM_KEY)
private List<AnnotationBean> annotations;
@ -123,6 +122,10 @@ public abstract class Common extends Base {
@Tag
private String similaritiesIndicator;
@JsonProperty(Constants.CONNECTIONS_INDICATOR)
@Tag
private String connectionsIndicator;
@JsonProperty(Constants.CITATION_JSON_KEY)
@CustomField(key=Constants.CITATION_CUSTOM_KEY)
private String citation;
@ -177,6 +180,7 @@ public abstract class Common extends Base {
this.landings = landings;
this.species = species;
this.similarGRSFRecords = similarGRSFRecords;
this.similarSourceRecords = similarSourceRecords;
this.domain = domain;
this.uuid = uuid;
this.managementBodyAuthorities = managementBodyAuthorities;
@ -224,7 +228,6 @@ public abstract class Common extends Base {
public void setRefersTo(List<RefersToBean> refersTo) {
this.refersTo = refersTo;
}
public List<Resource<Sources>> getDatabaseSources() {
return databaseSources;
}
@ -297,6 +300,14 @@ public abstract class Common extends Base {
this.similarGRSFRecords = similarGRSFRecords;
}
public List<SimilarRecordBean> getSimilarSourceRecords() {
return similarSourceRecords;
}
public void setSimilarSourceRecords(List<SimilarRecordBean> similarSourceRecords) {
this.similarSourceRecords = similarSourceRecords;
}
public String getSpatial() {
return spatial;
}
@ -356,28 +367,17 @@ public abstract class Common extends Base {
@Override
public String toString() {
return super.toString() + " - Common ["
+ " dataOwner=" + dataOwner
+ ", databaseSources=" + databaseSources
+ ", sourceOfInformation=" + sourceOfInformation
+ ", refersTo=" + refersTo
+ ", shortName=" + shortName
+ ", sdgFlag=" + sdgFlag
+ ", status=" + status
+ ", systemType=" + systemType
+ ", catches=" + catches
+ ", landings=" + landings
+ ", species=" + species
return "Common [dataOwner=" + dataOwner + ", databaseSources="
+ databaseSources + ", sourceOfInformation="
+ sourceOfInformation + ", refersTo=" + refersTo
+ ", shortName=" + shortName + ", sdgFlag=" + sdgFlag + ", status="
+ status + ", systemType=" + systemType + ", catches="
+ catches + ", landings=" + landings + ", species=" + species
+ ", similarGRSFRecords=" + similarGRSFRecords
+ ", domain=" + domain
+ ", uuid=" + uuid
+ ", similarSourceRecords=" + similarSourceRecords
+ ", domain=" + domain + ", uuid=" + uuid
+ ", managementBodyAuthorities=" + managementBodyAuthorities
+ ", spatial=" + spatial
+ ", connectedBeans=" + connectedBeans
+ ", annotations=" + annotations
+ ", similaritiesIndicator=" + similaritiesIndicator
+ ", connectionsIndicator=" + connectionsIndicator
+ ", citation=" + citation
+ "]";
+ ", spatial=" + spatial + ", connectedBeans=" + connectedBeans
+ ", annotations=" + annotations + "]";
}
}

View File

@ -22,9 +22,9 @@ import com.fasterxml.jackson.annotation.JsonProperty;
public class FisheryRecord extends Common {
@JsonProperty(Constants.FISHERY_NAME_JSON_KEY)
@CustomField(key=Constants.FISHERY_NAME_CUSTOM_KEY)
@NotNull(message="fishery_name cannot be null")
@Size(min=1, message="fishery_name cannot be empty")
@CustomField(key=Constants.FISHERY_NAME_CUSTOM_KEY)
private String fisheryName;
@JsonProperty(Constants.GRSF_SEMANTIC_IDENTIFIER_JSON_KEY)
@ -33,7 +33,7 @@ public class FisheryRecord extends Common {
@JsonProperty(Constants.TRACEABILITY_FLAG_JSON_KEY)
@CustomField(key=Constants.TRACEABILITY_FLAG_CUSTOM_KEY)
@Group(condition="true", groupNameOverValue=Constants.TRACEABILITY_FLAG_GROUP_NAME, prependSourceToGroupName=false) // record is added to group grsf-traceability-flag if Traceability Flag is true
@Group(condition="true", groupNameOverValue=Constants.TRACEABILITY_FLAG_GROUP_NAME) // record is added to group grsf-traceability-flag if Traceability Flag is true
private Boolean traceabilityFlag;
@JsonProperty(Constants.FISHING_AREA_JSON_KEY)
@ -43,13 +43,16 @@ public class FisheryRecord extends Common {
@JsonProperty(Constants.JURISDICTION_AREA_JSON_KEY)
@CustomField(key=Constants.JURISDICTION_AREA_CUSTOM_KEY)
@Tag
private List<String> jurisdictionArea;
@JsonProperty(Constants.RESOURCES_EXPLOITED_JSON_KEY)
@CustomField(key=Constants.RESOURCES_EXPLOITED_CUSTOM_KEY)
private List<String> resourcesExploited;
@JsonProperty(Constants.PRODUCTION_SYSTEM_TYPE_JSON_KEY)
@CustomField(key=Constants.PRODUCTION_SYSTEM_TYPE_CUSTOM_KEY)
private List<Production_System_Type> productionSystemType;
@JsonProperty(Constants.FLAG_STATE_JSON_KEY)
@CustomField(key=Constants.FLAG_STATE_CUSTOM_KEY)
@Tag
@ -62,6 +65,7 @@ public class FisheryRecord extends Common {
@JsonProperty(Constants.GRSF_TYPE_JSON_KEY)
@CustomField(key=Constants.GRSF_TYPE_CUSTOM_KEY)
@Group
@Tag
private Fishery_Type type;
@ -93,6 +97,7 @@ public class FisheryRecord extends Common {
this.fishingArea = fishingArea;
this.resourcesExploited = resourcesExploited;
this.jurisdictionArea = jurisdictionArea;
this.productionSystemType = productionSystemType;
this.flagState = flagState;
this.fishingGear = fishingGear;
this.type = type;
@ -160,6 +165,15 @@ public class FisheryRecord extends Common {
this.resourcesExploited = resourcesExploited;
}
public List<Production_System_Type> getProductionSystemType() {
return productionSystemType;
}
public void setProductionSystemType(
List<Production_System_Type> productionSystemType) {
this.productionSystemType = productionSystemType;
}
public List<String> getFlagState() {
return flagState;
}
@ -183,6 +197,7 @@ public class FisheryRecord extends Common {
+ ", traceabilityFlag=" + traceabilityFlag
+ ", resourcesExploited=" + resourcesExploited
+ ", jurisdictionArea=" + jurisdictionArea
+ ", productionSystemType=" + productionSystemType
+ ", flagState=" + flagState + ", fishingGear=" + fishingGear
+ ", type=" + type + "]";
}

View File

@ -26,9 +26,9 @@ import com.fasterxml.jackson.annotation.JsonProperty;
public class StockRecord extends Common{
@JsonProperty(Constants.STOCK_NAME_JSON_KEY)
@CustomField(key=Constants.STOCK_NAME_CUSTOM_KEY)
@NotNull(message=Constants.STOCK_NAME_JSON_KEY + " cannot be null")
@Size(min=2, message=Constants.STOCK_NAME_JSON_KEY + " cannot be empty")
@CustomField(key=Constants.STOCK_NAME_CUSTOM_KEY)
private String stockName;
@JsonProperty(Constants.GRSF_SEMANTIC_IDENTIFIER_JSON_KEY)
@ -46,7 +46,6 @@ public class StockRecord extends Common{
@JsonProperty(Constants.ASSESSMENT_METHODS_JSON_KEY)
@CustomField(key=Constants.ASSESSMENT_METHODS_CUSTOM_KEY)
@Group(groupNameOverValue=Constants.ASSESSMENT_METHODS_CUSTOM_KEY, prependSourceToGroupName=false)
private List<String> assessmentMethods;
@JsonProperty(Constants.FIRMS_ABUNDANCE_LEVEL_JSON_KEY)
@ -66,7 +65,7 @@ public class StockRecord extends Common{
@JsonProperty(Constants.BIOMASS_JSON_KEY)
@CustomField(key=Constants.BIOMASS_CUSTOM_KEY)
@TimeSeries
@Group(groupNameOverValue=Constants.BIOMASS_CUSTOM_KEY, prependSourceToGroupName=false)
// @Group(groupNameOverValue=Constants.BIOMASS_CUSTOM_KEY, prependSourceToGroupName=false)
@Valid
private List<TimeSeriesBean<String, String>> biomass;
@ -87,7 +86,7 @@ public class StockRecord extends Common{
@JsonProperty(Constants.STATE_AND_TREND_MARINE_RESOURCE_JSON_KEY)
@CustomField(key=Constants.STATE_AND_TREND_MARINE_RESOURCE_CUSTOM_KEY)
@TimeSeries
@Group(groupNameOverValue=Constants.STATE_AND_TREND_MARINE_RESOURCE_CUSTOM_KEY, prependSourceToGroupName=false)
@Group(groupNameOverValue="State and Trend of Marine Resource", prependSourceToGroupName=false)
@Valid
private List<TimeSeriesBean<String, Void>> narrativeState;
@ -110,6 +109,7 @@ public class StockRecord extends Common{
@JsonProperty(Constants.GRSF_TYPE_JSON_KEY)
@CustomField(key=Constants.GRSF_TYPE_CUSTOM_KEY)
@Group
@Tag
private Stock_Type type;

View File

@ -51,7 +51,7 @@ import eu.trentorise.opendata.jackan.model.CkanDataset;
* @author Costantino Perciante (ISTI - CNR)
* @author Luca Frosini (ISTI - CNR)
*/
@Path("{source:firms|FIRMS|grsf|GRSF|FishSource|fishsource|sdg|SDG}/fishery/")
@Path("{source:firms|FIRMS|grsf|GRSF|FishSource|fishsource}/fishery/")
public class GrsfPublisherFisheryService {
// the context
@ -257,7 +257,7 @@ public class GrsfPublisherFisheryService {
String type = fisheryInCkan.getExtrasAsHashMap().get(Constants.DOMAIN_CUSTOM_KEY);
if((fisheryInCkan.getOrganization().getName().equalsIgnoreCase(source)
|| fisheryInCkan.getOrganization().getName().toLowerCase().startsWith(source.toLowerCase()))
|| fisheryInCkan.getOrganization().getName().toLowerCase().contains(source))
&& Product_Type.FISHERY.getOrigName().equals(type)) {
logger.debug("Ok, this is a fishery of the right source, removing it");
@ -551,7 +551,7 @@ public class GrsfPublisherFisheryService {
// check system type
boolean isGRSF = !record.getExtrasAsHashMap().get(Constants.SYSTEM_TYPE_CUSTOM_KEY)
.equals(Constants.SYSTEM_TYPE_LEGACY_RECORD);
.equals(Constants.SYSTEM_TYPE_FOR_SOURCES_VALUE);
if(!isGRSF)
throw new Exception("You are trying to modify a Legacy record!");

View File

@ -51,7 +51,7 @@ import eu.trentorise.opendata.jackan.model.CkanDataset;
* @author Costantino Perciante (ISTI - CNR)
* @author Luca Frosini (ISTI - CNR)
*/
@Path("{source:firms|FIRMS|ram|RAM|grsf|GRSF|FishSource|fishsource|sdg|SDG}/stock/")
@Path("{source:firms|FIRMS|ram|RAM|grsf|GRSF|FishSource|fishsource}/stock/")
public class GrsfPublisherStockService {
// the context
@ -260,7 +260,7 @@ public class GrsfPublisherStockService {
// check it is in the right source and it is a stock
String type = stockInCkan.getExtrasAsHashMap().get(Constants.DOMAIN_CUSTOM_KEY);
if((stockInCkan.getOrganization().getName().equalsIgnoreCase(source)
|| stockInCkan.getOrganization().getName().toLowerCase().startsWith(source.toLowerCase()))
|| stockInCkan.getOrganization().getName().toLowerCase().contains(source))
&& Product_Type.STOCK.getOrigName().equals(type)) {
logger.debug("Ok, this is a stock of the right type, removing it");
@ -554,7 +554,7 @@ public class GrsfPublisherStockService {
// check system type
boolean isGRSF = !record.getExtrasAsHashMap().get(Constants.SYSTEM_TYPE_CUSTOM_KEY)
.equals(Constants.SYSTEM_TYPE_LEGACY_RECORD);
.equals(Constants.SYSTEM_TYPE_FOR_SOURCES_VALUE);
if(!isGRSF)
throw new Exception("You are trying to modify a Legacy record!");

View File

@ -4,6 +4,7 @@ import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@ -35,6 +36,7 @@ import org.gcube.datacatalogue.common.Constants;
import org.gcube.datacatalogue.common.enums.Product_Type;
import org.gcube.datacatalogue.common.enums.Sources;
import org.gcube.datacatalogue.common.enums.Status;
import org.gcube.datacatalogue.common.enums.Stock_Type;
import org.json.simple.JSONObject;
import org.slf4j.LoggerFactory;
@ -217,90 +219,6 @@ public class CommonServiceUtils {
}
}
public static final String GROUP_SUFFIX = "-group";
/**
* Convert a group name to its id on ckan
* @param origName
* @return
*/
private static String getGroupIDOnCkan(String origName){
if(origName == null) {
throw new IllegalArgumentException("origName cannot be null");
}
String modified = origName.replaceAll("\\(", "");
modified = modified.replaceAll("\\)", "");
modified = modified.trim().toLowerCase().replaceAll("[^A-Za-z0-9-]", "-");
if(modified.startsWith("-")) {
modified = modified.substring(1);
}
if(modified.endsWith("-")) {
modified = modified.substring(0, modified.length() -1);
}
return modified;
}
public static String getGroupId(String groupName) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(groupName);
/*
* The "_group" suffix is added to all groups to
* avoid issues on groups and organizations having the same name
* e.g. RAM organization (id=ram) and RAM group (id=ram_group)
*/
if(!groupName.endsWith(GROUP_SUFFIX)) {
stringBuffer.append(GROUP_SUFFIX);
}
return getGroupIDOnCkan(stringBuffer.toString());
}
private static void addGroup(Group group, Sources source, String value, Set<String> groups) {
String conditionToCheck = group.condition();
String groupNameOverValue = group.groupNameOverValue();
boolean prependSource = group.prependSourceToGroupName();
boolean match = conditionToCheck.isEmpty() ? true
: value.matches(conditionToCheck);
if(match) {
StringBuffer stringBuffer = new StringBuffer();
if(prependSource) {
stringBuffer.append(source.getURLPath());
stringBuffer.append(" ");
}
if(groupNameOverValue.isEmpty()) {
stringBuffer.append(value);
}else {
stringBuffer.append(groupNameOverValue);
}
String groupId = getGroupId(stringBuffer.toString());
groups.add(groupId);
}
}
/**
* Add the record to the group of sources
* @param groups
* @param sourcesList
* @param productType
* @param sourceInPath
*/
private static void addRecordToGroups(Set<String> groups, Set<String> sourcesList, Product_Type productType, Sources sourceInPath) {
if(sourceInPath == Sources.GRSF) {
groups.add(getGroupId(Sources.GRSF.getURLPath())); // i.e. grsf_group
}else {
groups.add(getGroupId(Constants.SYSTEM_TYPE_LEGACY_RECORD)); // i.e. legacy_group
}
// evaluate the custom fields/tags, resources and groups
groups.add(getGroupId(productType.getOrigName())); //i.e. stock_group or fishery_group
for(String source : sourcesList) {
groups.add(getGroupId(source)); // i.e. firms_group, fishsource_group, ram_group
}
}
/**
* Retrieve the list of groups' names for this object
*/
@ -308,22 +226,74 @@ public class CommonServiceUtils {
Sources source) {
if(field.isAnnotationPresent(Group.class)) {
Group group = field.getAnnotation(Group.class);
String conditionToCheck = group.condition();
String groupNameOverValue = group.groupNameOverValue();
// See https://support.d4science.org/issues/11832
boolean assessmentUnit = false;
boolean prependSource = group.prependSourceToGroupName();
if(record instanceof StockRecord) {
StockRecord stockRecord = (StockRecord) record;
Stock_Type stock_Type = stockRecord.getType();
if(stock_Type != Stock_Type.Assessment_Unit) {
prependSource = false;
}else {
assessmentUnit = true;
}
}
// end patch for https://support.d4science.org/issues/11832
try {
Object f = new PropertyDescriptor(field.getName(), current).getReadMethod().invoke(record);
if(f != null) {
if(f instanceof List<?>) {
List asList = ((List) f);
if(!asList.isEmpty()) {
logger.debug("The object annotated with @Group is a list. Adding ... ");
// add all the available elements
// else add all the available elements
for(int i = 0; i < asList.size(); i++) {
String value = asList.get(i).toString().trim();
addGroup(group, source, value, groups);
boolean match = conditionToCheck.isEmpty() ? true
: asList.get(i).toString().trim().matches(conditionToCheck);
if(match) {
String groupName = groupNameOverValue.isEmpty()
? HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-"
+ asList.get(i).toString().trim())
: source.toString().toLowerCase() + "-" + groupNameOverValue;
if(assessmentUnit && !prependSource) {
groups.add(groupNameOverValue);
}else {
groups.add(groupName);
}
}
}
}
} else {
String value = f.toString().trim();
addGroup(group, source, value, groups);
// also convert to the group name that should be on ckan
boolean match = conditionToCheck.isEmpty() ? true
: f.toString().trim().matches(conditionToCheck);
if(match) {
String groupName = groupNameOverValue.isEmpty()
? HelperMethods.getGroupNameOnCkan(
source.toString().toLowerCase() + "-" + f.toString().trim())
: source.toString().toLowerCase() + "-" + groupNameOverValue;
if(assessmentUnit && !prependSource) {
groups.add(groupNameOverValue);
}else {
groups.add(groupName);
}
}
}
}
@ -331,6 +301,7 @@ public class CommonServiceUtils {
logger.error("Failed to read value for field " + field.getName() + " skipping", e);
}
}
}
/**
@ -542,13 +513,13 @@ public class CommonServiceUtils {
if(databaseSources!=null) {
for(Resource<Sources> source : databaseSources) {
Sources sourceName = source.getName();
sourcesList.add(sourceName.getURLPath());
sourcesList.add(sourceName.getOrigName().toLowerCase());
}
}
}
addRecordToGroups(groups, sourcesList, productType, sourceInPath);
// append to groups: we need to add this record to the correspondent group of the sources
addRecordToGroupSources(groups, new ArrayList(sourcesList), productType, sourceInPath);
// validate
CommonServiceUtils.validateAggregatedRecord(record, sourceInPath);
@ -561,41 +532,57 @@ public class CommonServiceUtils {
sourceInPath.equals(Sources.GRSF)
? productType.equals(Product_Type.FISHERY) ? ((FisheryRecord) record).getType().getOrigName()
: ((StockRecord) record).getType().getOrigName()
: Constants.SYSTEM_TYPE_LEGACY_RECORD);
: Constants.SYSTEM_TYPE_FOR_SOURCES_VALUE);
logger.debug("Domain is " + productType.getOrigName() + " and system type " + record.getSystemType());
/*
* It has been decided to add tags also for legacy records see #23216
* boolean skipTags = !sourceInPath.equals(Sources.GRSF); // no tags for the Original records
*/
CommonServiceUtils.getTagsGroupsResourcesExtrasByRecord(tags, false, groups, false, resources, false,
// evaluate the custom fields/tags, resources and groups
groups.add(sourceInPath.getOrigName().toLowerCase() + "-" + productType.getOrigName().toLowerCase()); //e.g. grsf-fishery
boolean skipTags = !sourceInPath.equals(Sources.GRSF); // no tags for the Original records
CommonServiceUtils.getTagsGroupsResourcesExtrasByRecord(tags, skipTags, groups, false, resources, false,
customFields, record, username, sourceInPath);
}
// /**
// * Fetch the system:type property from a record
// * @param itemIdOrName
// * @param apiKey
// * @return null on error
// * @throws Exception
// */
// public static String getSystemTypeValue(String itemIdOrName, String apiKey, String context) throws Exception {
// DataCatalogue catalog = HelperMethods.getDataCatalogueRunningInstance(context);
// CkanDataset dataset = catalog.getDataset(itemIdOrName, apiKey);
// if(dataset == null) {
// throw new Exception("Unable to find record with id or name " + itemIdOrName);
// }
// String systemTypeValue = dataset.getExtrasAsHashMap().get(Constants.SYSTEM_TYPE_CUSTOM_KEY);
// if(systemTypeValue == null || systemTypeValue.isEmpty()) {
// throw new Exception(Constants.SYSTEM_TYPE_CUSTOM_KEY + " property not set in record " + itemIdOrName);
// }else {
// return systemTypeValue;
// }
//
// }
/**
* Add the record to the group of sources
* @param groups
* @param sourcesList
* @param productType
* @param sourceInPath
*/
private static void addRecordToGroupSources(Set<String> groups, List<String> sourcesList, Product_Type productType,
Sources sourceInPath) {
Collections.sort(sourcesList); // be sure the name are sorted because the groups have been generated this way
String groupName = sourceInPath.getOrigName().toLowerCase() + "-" + productType.getOrigName().toLowerCase();
for(String source : sourcesList) {
groupName += "-" + source;
}
groups.add(groupName);
}
/**
* Fetch the system:type property from a record
* @param itemIdOrName
* @param apiKey
* @return null on error
* @throws Exception
*/
public static String getSystemTypeValue(String itemIdOrName, String apiKey, String context) throws Exception {
DataCatalogue catalog = HelperMethods.getDataCatalogueRunningInstance(context);
CkanDataset dataset = catalog.getDataset(itemIdOrName, apiKey);
if(dataset == null)
throw new Exception("Unable to find record with id or name " + itemIdOrName);
String systemTypeValue = dataset.getExtrasAsHashMap().get(Constants.SYSTEM_TYPE_CUSTOM_KEY);
if(systemTypeValue == null || systemTypeValue.isEmpty())
throw new Exception(Constants.SYSTEM_TYPE_CUSTOM_KEY + " property not set in record " + itemIdOrName);
else
return systemTypeValue;
}
public static String getRecordOrganization(String itemIdOrName, String apiKey, String context) throws Exception {
DataCatalogue catalog = HelperMethods.getDataCatalogueRunningInstance(context);
@ -718,6 +705,6 @@ public class CommonServiceUtils {
return Constants.GRSF_PRE_ORGANIZATION_NAME;
}
}else
return sourceInPath.getURLPath();
return sourceInPath.getOrigName().toLowerCase();
}
}

View File

@ -31,7 +31,6 @@ import org.gcube.datacatalogue.common.caches.CacheInterface;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.Query;
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
import org.gcube.social_networking.social_networking_client_library.UserClient;
import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;
import org.slf4j.LoggerFactory;
@ -81,6 +80,29 @@ public abstract class HelperMethods {
private static CacheInterface<String, Map<String, String>> namespacesCache = new CacheImpl<String, Map<String, String>>(1000 * 60 * 60 * 24);
private static CacheInterface<String, DataCatalogue> catalogueCache = new CacheImpl<String, DataCatalogue>(1000 * 60 * 60 * 24);
/**
* Convert a group name to its id on ckan
* @param origName
* @return
*/
public static String getGroupNameOnCkan(String origName){
if(origName == null)
throw new IllegalArgumentException("origName cannot be null");
String modified = origName.replaceAll("\\(", "");
modified = origName.replaceAll("\\)", "");
modified = origName.trim().toLowerCase().replaceAll("[^A-Za-z0-9-]", "-");
if(modified.startsWith("-"))
modified = modified.substring(1);
if(modified.endsWith("-"))
modified = modified.substring(0, modified.length() -1);
logger.info("Group name generated is " + modified);
return modified;
}
/**
* Retrieve the running instance of the data catalogue for this scope
* @return
@ -135,18 +157,21 @@ public abstract class HelperMethods {
* @return
* @throws Exception
*/
public static String getUserEmail(String context, String token) throws Exception{
public static String getUserEmail(String context, String token){
// check in cache
String email = null;
if((email = (String) userEmailCache.get(token)) != null){
return email;
String result = null;
if((result = (String) userEmailCache.get(token)) != null){
return result;
}else{
UserClient userClient = new UserClient();
email = userClient.getEmail();
userEmailCache.insert(token, email);
String baseUrl = new GcoreEndPointReaderSocial(context).getBasePath();
String url = baseUrl.endsWith("/") ? baseUrl + "users/getUserEmail?gcube-token=" + token :
baseUrl + "/users/getUserEmail?gcube-token=" + token;
logger.debug("Request url is " + url);
result = executGETHttpRequest(url, 200);
userEmailCache.insert(token, result);
}
return email;
return result;
}
/**
@ -156,18 +181,21 @@ public abstract class HelperMethods {
* @return
* @throws Exception
*/
public static String getUserFullname(String context, String token) throws Exception{
public static String getUserFullname(String context, String token){
// check in cache
String fullName = null;
if((fullName = (String) userFullnameCache.get(token)) != null){
return fullName;
String result = null;
if((result = (String) userFullnameCache.get(token)) != null){
return result;
}else{
UserClient userClient = new UserClient();
fullName = userClient.getFullName();
userFullnameCache.insert(token, fullName);
String baseUrl = new GcoreEndPointReaderSocial(context).getBasePath();
String url = baseUrl.endsWith("/") ? baseUrl + "users/getUserFullname?gcube-token=" + token :
baseUrl + "/users/getUserFullname?gcube-token=" + token;
logger.debug("Request url is " + url);
result = executGETHttpRequest(url, 200);
userFullnameCache.insert(token, result);
}
return fullName;
return result;
}
/**

View File

@ -1,94 +0,0 @@
<Resource version="0.4.x">
<ID>85480b75-62f5-4708-acd9-382b22cffc90</ID>
<Type>GenericResource</Type>
<Scopes>
<Scope>/d4science.research-infrastructures.eu/FARM/GRSF</Scope>
</Scopes>
<Profile>
<SecondaryType>ApplicationProfile</SecondaryType>
<Name>GRSF Fishery</Name>
<Description>GRSF mapping between fields and namespaces for Fishery
records</Description>
<Body>
<fields>
<field>
<originalKey>Data Owner</originalKey>
<modifiedKey>none:none</modifiedKey>
</field>
<field>
<originalKey>Database Source</originalKey>
<modifiedKey>fishery_identity:Database Source</modifiedKey>
</field>
<field>
<originalKey>Short Name</originalKey>
<modifiedKey>fishery_identity:Short Name</modifiedKey>
</field>
<field>
<originalKey>Catch</originalKey>
<modifiedKey>none:none</modifiedKey>
</field>
<field>
<originalKey>Landing</originalKey>
<modifiedKey>none:none</modifiedKey>
</field>
<field>
<originalKey>Species</originalKey>
<modifiedKey>fishery_identity:Species</modifiedKey>
</field>
<field>
<originalKey>Similar GRSF Record</originalKey>
<modifiedKey>fishery_identity:Similar GRSF Record</modifiedKey>
</field>
<field>
<originalKey>Management Body/Authority</originalKey>
<modifiedKey>fishery_identity:Management Body/Authority</modifiedKey>
</field>
<field>
<originalKey>Connected Record</originalKey>
<modifiedKey>fishery_identity:Connected Record</modifiedKey>
</field>
<field>
<originalKey>Annotation</originalKey>
<modifiedKey>none:none</modifiedKey>
</field>
<field>
<originalKey>GRSF Fishery Name</originalKey>
<modifiedKey>fishery_identity:GRSF Fishery Name</modifiedKey>
</field>
<field>
<originalKey>GRSF Semantic Identifier</originalKey>
<modifiedKey>fishery_identity:GRSF Semantic Identifier
</modifiedKey>
</field>
<field>
<originalKey>Traceability Flag</originalKey>
<modifiedKey>fishery_identity:Traceability Flag</modifiedKey>
</field>
<field>
<originalKey>Fishing Area</originalKey>
<modifiedKey>fishery_identity:Fishing Area</modifiedKey>
</field>
<field>
<originalKey>Jurisdiction Area</originalKey>
<modifiedKey>fishery_identity:Jurisdiction Area</modifiedKey>
</field>
<field>
<originalKey>Resources Exploited</originalKey>
<modifiedKey>fishery_identity:Resources Exploited</modifiedKey>
</field>
<field>
<originalKey>Flag State</originalKey>
<modifiedKey>fishery_identity:Flag State</modifiedKey>
</field>
<field>
<originalKey>Fishing Gear</originalKey>
<modifiedKey>fishery_identity:Fishing Gear</modifiedKey>
</field>
<field>
<originalKey>GRSF Type</originalKey>
<modifiedKey>fishery_identity:GRSF Type</modifiedKey>
</field>
</fields>
</Body>
</Profile>
</Resource>

View File

@ -1,91 +0,0 @@
<Resource version="0.4.x">
<ID>c3326373-c620-45e8-a7e3-a25a1a2a970b</ID>
<Type>GenericResource</Type>
<Scopes>
<Scope>/d4science.research-infrastructures.eu/FARM/GRSF_Admin</Scope>
<Scope>/d4science.research-infrastructures.eu/FARM</Scope>
</Scopes>
<Profile>
<SecondaryType>ApplicationProfile</SecondaryType>
<Name>GRSF Fishery</Name>
<Description>GRSF mapping between fields and namespaces for Fishery
records</Description>
<Body>
<fields>
<field>
<originalKey>Data Owner</originalKey>
<modifiedKey>fishery_data:Data Owner</modifiedKey>
</field>
<field>
<originalKey>Database Source</originalKey>
<modifiedKey>fishery_identity:Database Source</modifiedKey>
</field>
<field>
<originalKey>Short Name</originalKey>
<modifiedKey>fishery_identity:Short Name</modifiedKey>
</field>
<field>
<originalKey>Catch</originalKey>
<modifiedKey>fishery_data:Catch</modifiedKey>
</field>
<field>
<originalKey>Landing</originalKey>
<modifiedKey>fishery_data:Landing</modifiedKey>
</field>
<field>
<originalKey>Species</originalKey>
<modifiedKey>fishery_identity:Species</modifiedKey>
</field>
<field>
<originalKey>Similar GRSF Record</originalKey>
<modifiedKey>fishery_identity:Similar GRSF Record</modifiedKey>
</field>
<field>
<originalKey>Management Body/Authority</originalKey>
<modifiedKey>fishery_identity:Management Body/Authority</modifiedKey>
</field>
<field>
<originalKey>Connected Record</originalKey>
<modifiedKey>fishery_identity:Connected Record</modifiedKey>
</field>
<field>
<originalKey>GRSF Fishery Name</originalKey>
<modifiedKey>fishery_identity:GRSF Fishery Name</modifiedKey>
</field>
<field>
<originalKey>GRSF Semantic Identifier</originalKey>
<modifiedKey>fishery_identity:GRSF Semantic Identifier
</modifiedKey>
</field>
<field>
<originalKey>Traceability Flag</originalKey>
<modifiedKey>fishery_identity:Traceability Flag</modifiedKey>
</field>
<field>
<originalKey>Fishing Area</originalKey>
<modifiedKey>fishery_identity:Fishing Area</modifiedKey>
</field>
<field>
<originalKey>Jurisdiction Area</originalKey>
<modifiedKey>fishery_identity:Jurisdiction Area</modifiedKey>
</field>
<field>
<originalKey>Resources Exploited</originalKey>
<modifiedKey>fishery_identity:Resources Exploited</modifiedKey>
</field>
<field>
<originalKey>Flag State</originalKey>
<modifiedKey>fishery_identity:Flag State</modifiedKey>
</field>
<field>
<originalKey>Fishing Gear</originalKey>
<modifiedKey>fishery_identity:Fishing Gear</modifiedKey>
</field>
<field>
<originalKey>GRSF Type</originalKey>
<modifiedKey>fishery_identity:GRSF Type</modifiedKey>
</field>
</fields>
</Body>
</Profile>
</Resource>

View File

@ -1,118 +0,0 @@
<Resource version="0.4.x">
<ID>512cca02-e178-420c-a766-b47171e154e2</ID>
<Type>GenericResource</Type>
<Scopes>
<Scope>/d4science.research-infrastructures.eu/FARM/GRSF</Scope>
</Scopes>
<Profile>
<SecondaryType>ApplicationProfile</SecondaryType>
<Name>GRSF Stock</Name>
<Description>GRSF mapping between fields and namespaces for Stock
records
</Description>
<Body>
<fields>
<field>
<originalKey>Data Owner</originalKey>
<modifiedKey>none:none</modifiedKey>
</field>
<field>
<originalKey>Database Source</originalKey>
<modifiedKey>stock_identity:Database Source</modifiedKey>
</field>
<field>
<originalKey>Short Name</originalKey>
<modifiedKey>stock_identity:Short Name</modifiedKey>
</field>
<field>
<originalKey>Catch</originalKey>
<modifiedKey>none:none</modifiedKey>
</field>
<field>
<originalKey>Landing</originalKey>
<modifiedKey>none:none</modifiedKey>
</field>
<field>
<originalKey>Species</originalKey>
<modifiedKey>stock_identity:Species</modifiedKey>
</field>
<field>
<originalKey>Similar GRSF Record</originalKey>
<modifiedKey>stock_identity:Similar GRSF Record</modifiedKey>
</field>
<field>
<originalKey>Management Body/Authority</originalKey>
<modifiedKey>stock_identity:Management Body/Authority</modifiedKey>
</field>
<field>
<originalKey>Connected Record</originalKey>
<modifiedKey>stock_identity:Connected Record</modifiedKey>
</field>
<field>
<originalKey>Annotation</originalKey>
<modifiedKey>none:none</modifiedKey>
</field>
<field>
<originalKey>GRSF Stock Name</originalKey>
<modifiedKey>stock_identity:GRSF Stock Name</modifiedKey>
</field>
<field>
<originalKey>GRSF Semantic Identifier</originalKey>
<modifiedKey>stock_identity:GRSF Semantic Identifier</modifiedKey>
</field>
<field>
<originalKey>Assessment Area</originalKey>
<modifiedKey>stock_identity:Assessment Area</modifiedKey>
</field>
<field>
<originalKey>Exploiting Fishery</originalKey>
<modifiedKey>stock_identity:Exploiting Fishery</modifiedKey>
</field>
<field>
<originalKey>Assessment Method</originalKey>
<modifiedKey>none:none</modifiedKey>
</field>
<field>
<originalKey>Abundance Level (FIRMS Standard)</originalKey>
<modifiedKey>none:none</modifiedKey>
</field>
<field>
<originalKey>Abundance Level</originalKey>
<modifiedKey>none:none</modifiedKey>
</field>
<field>
<originalKey>Biomass</originalKey>
<modifiedKey>none:none</modifiedKey>
</field>
<field>
<originalKey>Fishing Pressure (FIRMS Standard)</originalKey>
<modifiedKey>none:none</modifiedKey>
</field>
<field>
<originalKey>Fishing Pressure</originalKey>
<modifiedKey>none:none</modifiedKey>
</field>
<field>
<originalKey>State and Trend</originalKey>
<modifiedKey>none:none</modifiedKey>
</field>
<field>
<originalKey>FAO Stock Status Category</originalKey>
<modifiedKey>none:none</modifiedKey>
</field>
<field>
<originalKey>Scientific Advice</originalKey>
<modifiedKey>none:none</modifiedKey>
</field>
<field>
<originalKey>Assessor</originalKey>
<modifiedKey>none:none</modifiedKey>
</field>
<field>
<originalKey>GRSF Type</originalKey>
<modifiedKey>stock_identity:GRSF Type</modifiedKey>
</field>
</fields>
</Body>
</Profile>
</Resource>

View File

@ -1,115 +0,0 @@
<Resource version="0.4.x">
<ID>c9cad3f8-5773-4ca7-95a5-4692db5eae2e</ID>
<Type>GenericResource</Type>
<Scopes>
<Scope>/d4science.research-infrastructures.eu/FARM</Scope>
<Scope>/d4science.research-infrastructures.eu/FARM/GRSF_Admin</Scope>
</Scopes>
<Profile>
<SecondaryType>ApplicationProfile</SecondaryType>
<Name>GRSF Stock</Name>
<Description>GRSF mapping between fields and namespaces for Stock
records</Description>
<Body>
<fields>
<field>
<originalKey>Data Owner</originalKey>
<modifiedKey>stock_data:Data Owner</modifiedKey>
</field>
<field>
<originalKey>Database Source</originalKey>
<modifiedKey>stock_identity:Database Source</modifiedKey>
</field>
<field>
<originalKey>Short Name</originalKey>
<modifiedKey>stock_identity:Short Name</modifiedKey>
</field>
<field>
<originalKey>Catch</originalKey>
<modifiedKey>stock_data:Catch</modifiedKey>
</field>
<field>
<originalKey>Landing</originalKey>
<modifiedKey>stock_data:Landing</modifiedKey>
</field>
<field>
<originalKey>Species</originalKey>
<modifiedKey>stock_identity:Species</modifiedKey>
</field>
<field>
<originalKey>Similar GRSF Record</originalKey>
<modifiedKey>stock_identity:Similar GRSF Record</modifiedKey>
</field>
<field>
<originalKey>Management Body/Authority</originalKey>
<modifiedKey>stock_identity:Management Body/Authority</modifiedKey>
</field>
<field>
<originalKey>Connected Record</originalKey>
<modifiedKey>stock_identity:Connected Record</modifiedKey>
</field>
<field>
<originalKey>GRSF Stock Name</originalKey>
<modifiedKey>stock_identity:GRSF Stock Name</modifiedKey>
</field>
<field>
<originalKey>GRSF Semantic Identifier</originalKey>
<modifiedKey>stock_identity:GRSF Semantic Identifier</modifiedKey>
</field>
<field>
<originalKey>Assessment Area</originalKey>
<modifiedKey>stock_identity:Assessment Area</modifiedKey>
</field>
<field>
<originalKey>Exploiting Fishery</originalKey>
<modifiedKey>stock_identity:Exploiting Fishery</modifiedKey>
</field>
<field>
<originalKey>Assessment Method</originalKey>
<modifiedKey>stock_data:Assessment Method</modifiedKey>
</field>
<field>
<originalKey>Abundance Level (FIRMS Standard)</originalKey>
<modifiedKey>stock_data:Abundance Level (FIRMS Standard)
</modifiedKey>
</field>
<field>
<originalKey>Abundance Level</originalKey>
<modifiedKey>stock_data:Abundance Level</modifiedKey>
</field>
<field>
<originalKey>Biomass</originalKey>
<modifiedKey>stock_data:Biomass</modifiedKey>
</field>
<field>
<originalKey>Fishing Pressure (FIRMS Standard)</originalKey>
<modifiedKey>stock_data:Fishing Pressure (FIRMS Standard)</modifiedKey>
</field>
<field>
<originalKey>Fishing Pressure</originalKey>
<modifiedKey>stock_data:Fishing Pressure</modifiedKey>
</field>
<field>
<originalKey>State and Trend</originalKey>
<modifiedKey>stock_data:State and Trend</modifiedKey>
</field>
<field>
<originalKey>FAO Stock Status Category</originalKey>
<modifiedKey>stock_data:FAO Stock Status Category</modifiedKey>
</field>
<field>
<originalKey>Scientific Advice</originalKey>
<modifiedKey>stock_data:Scientific Advice</modifiedKey>
</field>
<field>
<originalKey>Assessor</originalKey>
<modifiedKey>stock_data:Assessor</modifiedKey>
</field>
<field>
<originalKey>GRSF Type</originalKey>
<modifiedKey>stock_identity:GRSF Type</modifiedKey>
</field>
</fields>
</Body>
</Profile>
</Resource>

View File

@ -1,40 +0,0 @@
<Resource version="0.4.x">
<ID>7ee9c6e9-ff73-4428-88e4-185aeb4b3742</ID>
<Type>GenericResource</Type>
<Scopes>
<Scope>/d4science.research-infrastructures.eu/FARM/GRSF_Pre</Scope>
<Scope>/d4science.research-infrastructures.eu/FARM/GRSF_Admin</Scope>
</Scopes>
<Profile>
<SecondaryType>ApplicationProfile</SecondaryType>
<Name>GRSFManageEntries</Name>
<Description>A list of extras metadata to be looked up and prompted by the GRSF Manage widget. The body reports the key values.</Description>
<Body>
fishery_identity:GRSF Type,
fishery_identity:Short Name,
fishery_identity:Database Source,
fishery_identity:GRSF Semantic Identifier,
fishery_data:Catch,
fishery_data:Landing,
stock_identity:GRSF Type,
stock_identity:Short Name,
stock_identity:Database Source,
stock_identity:GRSF Semantic Identifier,
stock_data:Catch,
stock_data:Landing
</Body>
</Profile>
</Resource>

View File

@ -270,7 +270,7 @@ public class JTests {
}
//@Test
public void testCaches() throws Exception{
public void testCaches(){
String context = "/gcube/devNext/NextNext";
String token = "";

View File

@ -1,38 +0,0 @@
package org.gcube.data_catalogue.grsf_publish_ws;
import java.io.File;
import java.net.URL;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.StockRecord;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class TestJson {
private static final Logger logger = LoggerFactory.getLogger(Test.class);
public File getResourcesDirectory() throws Exception {
URL logbackFileURL = TestJson.class.getClassLoader().getResource("logback-test.xml");
File logbackFile = new File(logbackFileURL.toURI());
File resourcesDirectory = logbackFile.getParentFile();
return resourcesDirectory;
}
@Test
public void testJsonDeserialization() throws Exception {
File jsonQueryFile = new File(getResourcesDirectory(), "70ae6895-7d3d-4f4a-86f9-bcb17d41bff6.json");
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(jsonQueryFile);
logger.debug("{}", jsonNode);
StockRecord sr = objectMapper.readValue(jsonQueryFile, StockRecord.class);
logger.debug("{}", sr);
}
}

View File

@ -1,34 +0,0 @@
{
"stock_name" : "European hake - Southern Adriatic",
"license_id" : "CC-BY-SA-4.0",
"version" : 1.0,
"database_sources" : [ {
"name" : "FAO SDG 14.4.1 questionnaire",
"description" : "FAO SDG 14.4.1 questionnaire",
"url" : "https://www.fao.org/sustainable-development-goals/indicators/14.4.1/en/"
} ],
"stock_uri" : "https://github.com/grsf/resource/sdg_14_4_1/stock/70ae6895-7d3d-4f4a-86f9-bcb17d41bff6",
"grsf_uuid" : "70ae6895-7d3d-4f4a-86f9-bcb17d41bff6",
"short_name" : "European hake - Southern Adriatic",
"description" : "European hake - Southern Adriatic",
"grsf_type" : "assessment unit",
"species" : [ "Code: HKE, Classification System: ASFIS, Scientific Name: Merluccius merluccius" ],
"assessment_area" : [ "Code: 18, System: gfcm, Name: Southern Adriatic " ],
"source_of_information" : [ {
"name" : "https://www.fao.org/sustainable-development-goals/indicators/14.4.1/en/sdg-alb-1",
"description" : "",
"url" : "https://www.fao.org/sustainable-development-goals/indicators/14.4.1/en/sdg-alb-1"
} ],
"data_owner" : [ "Albania" ],
"assessment_methods" : [ "The official stock assessment concludes 'Overfished' with respect to abundance reference points. [Rep. Year or Assessment ID: 2019, Ref. Year: 2018]" ],
"connections_indicator" : "not connected",
"similarities_indicator" : "without similar records",
"landings" : [ {
"value" : "872",
"unit" : "Tonnes",
"reference_year" : 2018,
"reporting_year_or_assessment_id" : "2020",
"data_owner" : "Albania"
} ],
"citation" : "citation TBD"
}

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n</pattern>
</encoder>
</appender>
<logger name="org.gcube" level="INFO" />
<logger name="org.gcube.data_catalogue.grsf_publish_ws" level="TRACE" />
<root level="WARN">
<appender-ref ref="STDOUT" />
</root>
</configuration>