Group association now works. Added methods to retrieve licenses' ids. By default the license_id (if not specified ) is CC-BY-SA-4.0
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@133037 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
dfb9bef4c5
commit
37eccf53bf
|
@ -3,9 +3,6 @@
|
||||||
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
|
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
|
||||||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||||
<dependent-module archiveName="ckan-util-library-2.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/ckan-util-library/ckan-util-library">
|
|
||||||
<dependency-type>uses</dependency-type>
|
|
||||||
</dependent-module>
|
|
||||||
<property name="context-root" value="grsf-publisher-ws"/>
|
<property name="context-root" value="grsf-publisher-ws"/>
|
||||||
<property name="java-output-path" value="/grsf-publisher-ws/target/classes"/>
|
<property name="java-output-path" value="/grsf-publisher-ws/target/classes"/>
|
||||||
</wb-module>
|
</wb-module>
|
||||||
|
|
|
@ -23,7 +23,7 @@ public class Common {
|
||||||
@JsonProperty("description")
|
@JsonProperty("description")
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@JsonProperty("license")
|
@JsonProperty("license_id")
|
||||||
private String license;
|
private String license;
|
||||||
|
|
||||||
// filled automatically by the server
|
// filled automatically by the server
|
||||||
|
@ -70,9 +70,9 @@ public class Common {
|
||||||
@JsonProperty("extras")
|
@JsonProperty("extras")
|
||||||
private Map<String, String> extras = new HashMap<>();
|
private Map<String, String> extras = new HashMap<>();
|
||||||
|
|
||||||
@JsonProperty("spatial")
|
// @JsonProperty("spatial")
|
||||||
@CustomField(key="Spatial")
|
// @CustomField(key="Spatial")
|
||||||
private String spatial;
|
// private String spatial;
|
||||||
|
|
||||||
public Common() {
|
public Common() {
|
||||||
super();
|
super();
|
||||||
|
@ -100,16 +100,16 @@ public class Common {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.resources = resources;
|
this.resources = resources;
|
||||||
this.extras = extras;
|
this.extras = extras;
|
||||||
this.spatial = spatial;
|
// this.spatial = spatial;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSpatial() {
|
// public String getSpatial() {
|
||||||
return spatial;
|
// return spatial;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setSpatial(String spatial) {
|
// public void setSpatial(String spatial) {
|
||||||
this.spatial = spatial;
|
// this.spatial = spatial;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
|
@ -233,8 +233,7 @@ public class Common {
|
||||||
+ ", databaseSources=" + databaseSources
|
+ ", databaseSources=" + databaseSources
|
||||||
+ ", sourceOfInformation=" + sourceOfInformation
|
+ ", sourceOfInformation=" + sourceOfInformation
|
||||||
+ ", dataOwner=" + dataOwner + ", type=" + type
|
+ ", dataOwner=" + dataOwner + ", type=" + type
|
||||||
+ ", resources=" + resources + ", extras=" + extras
|
+ ", resources=" + resources + ", extras=" + extras + "]";
|
||||||
+ ", spatial=" + spatial + "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,8 @@ import org.slf4j.LoggerFactory;
|
||||||
@Path("fishery/")
|
@Path("fishery/")
|
||||||
public class GrsfPublisherFisheryService {
|
public class GrsfPublisherFisheryService {
|
||||||
|
|
||||||
|
private static final String DEFAULT_FISHERY_LICENSE = "CC-BY-SA-4.0";
|
||||||
|
|
||||||
// the context
|
// the context
|
||||||
@Context
|
@Context
|
||||||
ServletContext contextServlet;
|
ServletContext contextServlet;
|
||||||
|
@ -52,6 +54,24 @@ public class GrsfPublisherFisheryService {
|
||||||
return Response.ok("Hello.. Fishery service is here").build();
|
return Response.ok("Hello.. Fishery service is here").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("get-licenses")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response getLicenses(){
|
||||||
|
|
||||||
|
// since are equals for stock and fishery, we just retrieve them all
|
||||||
|
Map<String, String> licenses = new HashMap<String, String>();
|
||||||
|
Status status;
|
||||||
|
try{
|
||||||
|
licenses = HelperMethods.getLicenses();
|
||||||
|
status = Status.OK;
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Failed to retrieve the list of licenses");
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
return Response.status(status).entity(licenses).build();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("publish-product")
|
@Path("publish-product")
|
||||||
|
@ -172,11 +192,18 @@ public class GrsfPublisherFisheryService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// if confirmed, set to visible TODO anyway if it is confirmed we should another method
|
// if confirmed, set to visible TODO anyway if it is confirmed we should another method
|
||||||
boolean setPublic = record.getStatus() == org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status.Confirmed;
|
boolean setPublic = record.getStatus() == org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status.Confirmed;
|
||||||
|
|
||||||
|
// check the license id
|
||||||
|
String license = null;
|
||||||
|
if(record.getLicense() == null || record.getLicense().isEmpty())
|
||||||
|
license = DEFAULT_FISHERY_LICENSE;
|
||||||
|
else
|
||||||
|
if(HelperMethods.existsLicenseId(record.getLicense()))
|
||||||
|
license = record.getLicense();
|
||||||
|
else throw new Exception("Please check the license id!");
|
||||||
|
|
||||||
// create the product
|
// create the product
|
||||||
id = catalogue.createCKanDataset(
|
id = catalogue.createCKanDataset(
|
||||||
catalogue.getApiKeyFromUsername(username),
|
catalogue.getApiKeyFromUsername(username),
|
||||||
|
@ -188,7 +215,7 @@ public class GrsfPublisherFisheryService {
|
||||||
record.getMaintainerContact(),
|
record.getMaintainerContact(),
|
||||||
record.getVersion(),
|
record.getVersion(),
|
||||||
record.getDescription(),
|
record.getDescription(),
|
||||||
record.getLicense(),
|
license,
|
||||||
tags,
|
tags,
|
||||||
customFields,
|
customFields,
|
||||||
resources,
|
resources,
|
||||||
|
|
|
@ -38,6 +38,8 @@ import org.slf4j.LoggerFactory;
|
||||||
@Path("stock/")
|
@Path("stock/")
|
||||||
public class GrsfPublisherStockService {
|
public class GrsfPublisherStockService {
|
||||||
|
|
||||||
|
private static final String DEFAULT_STOCK_LICENSE = "CC-BY-SA-4.0";
|
||||||
|
|
||||||
// the context
|
// the context
|
||||||
@Context
|
@Context
|
||||||
ServletContext contextServlet;
|
ServletContext contextServlet;
|
||||||
|
@ -52,6 +54,25 @@ public class GrsfPublisherStockService {
|
||||||
return Response.ok("Hello.. Stock service is here").build();
|
return Response.ok("Hello.. Stock service is here").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("get-licenses")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response getLicenses(){
|
||||||
|
|
||||||
|
// since are equals for stock and fishery, we just retrieve them all
|
||||||
|
Map<String, String> licenses = new HashMap<String, String>();
|
||||||
|
Status status;
|
||||||
|
try{
|
||||||
|
licenses = HelperMethods.getLicenses();
|
||||||
|
status = Status.OK;
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Failed to retrieve the list of licenses");
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
return Response.status(status).entity(licenses).build();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("publish-product")
|
@Path("publish-product")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@ -172,10 +193,18 @@ public class GrsfPublisherStockService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// if confirmed, set to visible TODO anyway if it is confirmed we should another method
|
// if confirmed, set to visible TODO anyway if it is confirmed we should another method
|
||||||
boolean setPublic = record.getStatus() == org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status.Confirmed;
|
boolean setPublic = record.getStatus() == org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status.Confirmed;
|
||||||
|
|
||||||
|
// check the license id
|
||||||
|
String license = null;
|
||||||
|
if(record.getLicense() == null || record.getLicense().isEmpty())
|
||||||
|
license = DEFAULT_STOCK_LICENSE;
|
||||||
|
else
|
||||||
|
if(HelperMethods.existsLicenseId(record.getLicense()))
|
||||||
|
license = record.getLicense();
|
||||||
|
else throw new Exception("Please check the license id!");
|
||||||
|
|
||||||
// create the product
|
// create the product
|
||||||
id = catalogue.createCKanDataset(
|
id = catalogue.createCKanDataset(
|
||||||
catalogue.getApiKeyFromUsername(username),
|
catalogue.getApiKeyFromUsername(username),
|
||||||
|
@ -187,7 +216,7 @@ public class GrsfPublisherStockService {
|
||||||
record.getMaintainerContact(),
|
record.getMaintainerContact(),
|
||||||
record.getVersion(),
|
record.getVersion(),
|
||||||
record.getDescription(),
|
record.getDescription(),
|
||||||
record.getLicense(),
|
license,
|
||||||
tags,
|
tags,
|
||||||
customFields,
|
customFields,
|
||||||
resources,
|
resources,
|
||||||
|
|
|
@ -4,11 +4,13 @@ import java.beans.PropertyDescriptor;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.CustomField;
|
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.CustomField;
|
||||||
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.custom_annotations.Tag;
|
||||||
|
@ -23,6 +25,7 @@ import eu.trentorise.opendata.jackan.internal.org.apache.http.HttpResponse;
|
||||||
import eu.trentorise.opendata.jackan.internal.org.apache.http.client.methods.HttpGet;
|
import eu.trentorise.opendata.jackan.internal.org.apache.http.client.methods.HttpGet;
|
||||||
import eu.trentorise.opendata.jackan.internal.org.apache.http.impl.client.CloseableHttpClient;
|
import eu.trentorise.opendata.jackan.internal.org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import eu.trentorise.opendata.jackan.internal.org.apache.http.impl.client.HttpClientBuilder;
|
import eu.trentorise.opendata.jackan.internal.org.apache.http.impl.client.HttpClientBuilder;
|
||||||
|
import eu.trentorise.opendata.jackan.model.CkanLicense;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -283,4 +286,36 @@ public abstract class HelperMethods {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the list of ckan licenses and build up a map <license_id, license_title>
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static Map<String, String> getLicenses() throws Exception {
|
||||||
|
|
||||||
|
Map<String, String> toReturn = new HashMap<String, String>();
|
||||||
|
String scope = ScopeProvider.instance.get();
|
||||||
|
DataCatalogue catalogue = getDataCatalogueRunningInstance(scope);
|
||||||
|
List<CkanLicense> licenses = catalogue.getLicenses();
|
||||||
|
|
||||||
|
for (CkanLicense ckanLicense : licenses) {
|
||||||
|
toReturn.put(ckanLicense.getId(), ckanLicense.getTitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that the given license id is in CKAN
|
||||||
|
* @param license id to check
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static boolean existsLicenseId(String license) throws Exception {
|
||||||
|
|
||||||
|
Map<String, String> licenses = getLicenses();
|
||||||
|
return licenses.containsKey(license);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,13 @@ import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status;
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Type;
|
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Type;
|
||||||
import org.glassfish.jersey.server.ResourceConfig;
|
import org.glassfish.jersey.server.ResourceConfig;
|
||||||
import org.glassfish.jersey.test.JerseyTest;
|
import org.glassfish.jersey.test.JerseyTest;
|
||||||
|
import org.glassfish.jersey.test.TestProperties;
|
||||||
|
|
||||||
public class JJerseyTest extends JerseyTest{
|
public class JJerseyTest extends JerseyTest{
|
||||||
|
|
||||||
//@Override
|
//@Override
|
||||||
protected Application configure() {
|
protected Application configure() {
|
||||||
|
forceSet(TestProperties.CONTAINER_PORT, "0");
|
||||||
return new ResourceConfig(GrsfPublisherFisheryService.class, GrsfPublisherStockService.class);
|
return new ResourceConfig(GrsfPublisherFisheryService.class, GrsfPublisherStockService.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,9 +32,6 @@ public class JJerseyTest extends JerseyTest{
|
||||||
recordFishery.setType(Type.Fishing_Description);
|
recordFishery.setType(Type.Fishing_Description);
|
||||||
recordFishery.setDatabaseSources(Source.FIRMS);
|
recordFishery.setDatabaseSources(Source.FIRMS);
|
||||||
recordFishery.setStatus(Status.Pending);
|
recordFishery.setStatus(Status.Pending);
|
||||||
recordFishery.setSpatial(
|
|
||||||
"{\"type\":\"Polygon\",\"coordinates\":[[[2.05827, 49.8625],[2.05827, 55.7447], [-6.41736, 55.7447], [-6.41736, 49.8625], [2.05827, 49.8625]]]}");
|
|
||||||
|
|
||||||
Response res = target("fishery").path("/publish-product").request().post(Entity.entity(recordFishery, MediaType.APPLICATION_JSON));
|
Response res = target("fishery").path("/publish-product").request().post(Entity.entity(recordFishery, MediaType.APPLICATION_JSON));
|
||||||
System.out.println("Result is " + res.readEntity(String.class));
|
System.out.println("Result is " + res.readEntity(String.class));
|
||||||
}
|
}
|
||||||
|
@ -50,4 +49,12 @@ public class JJerseyTest extends JerseyTest{
|
||||||
|
|
||||||
System.out.println("Result is " + res);
|
System.out.println("Result is " + res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//@Test
|
||||||
|
public void getLicenses(){
|
||||||
|
|
||||||
|
Response res = target("fishery").path("/get-licenses").request().get();
|
||||||
|
System.out.println("Result is " + res);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue