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:
Costantino Perciante 2016-10-11 09:39:25 +00:00
parent dfb9bef4c5
commit 37eccf53bf
6 changed files with 123 additions and 29 deletions

View File

@ -3,9 +3,6 @@
<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="/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="java-output-path" value="/grsf-publisher-ws/target/classes"/>
</wb-module>

View File

@ -23,7 +23,7 @@ public class Common {
@JsonProperty("description")
private String description;
@JsonProperty("license")
@JsonProperty("license_id")
private String license;
// filled automatically by the server
@ -70,9 +70,9 @@ public class Common {
@JsonProperty("extras")
private Map<String, String> extras = new HashMap<>();
@JsonProperty("spatial")
@CustomField(key="Spatial")
private String spatial;
// @JsonProperty("spatial")
// @CustomField(key="Spatial")
// private String spatial;
public Common() {
super();
@ -100,16 +100,16 @@ public class Common {
this.type = type;
this.resources = resources;
this.extras = extras;
this.spatial = spatial;
// this.spatial = spatial;
}
public String getSpatial() {
return spatial;
}
public void setSpatial(String spatial) {
this.spatial = spatial;
}
// public String getSpatial() {
// return spatial;
// }
//
// public void setSpatial(String spatial) {
// this.spatial = spatial;
// }
public String getDescription() {
return description;
@ -233,8 +233,7 @@ public class Common {
+ ", databaseSources=" + databaseSources
+ ", sourceOfInformation=" + sourceOfInformation
+ ", dataOwner=" + dataOwner + ", type=" + type
+ ", resources=" + resources + ", extras=" + extras
+ ", spatial=" + spatial + "]";
+ ", resources=" + resources + ", extras=" + extras + "]";
}
}

View File

@ -37,14 +37,16 @@ import org.slf4j.LoggerFactory;
*/
@Path("fishery/")
public class GrsfPublisherFisheryService {
private static final String DEFAULT_FISHERY_LICENSE = "CC-BY-SA-4.0";
// the context
@Context
ServletContext contextServlet;
// Logger
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GrsfPublisherFisheryService.class);
@GET
@Path("hello")
@Produces(MediaType.TEXT_PLAIN)
@ -52,6 +54,24 @@ public class GrsfPublisherFisheryService {
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
@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
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
id = catalogue.createCKanDataset(
catalogue.getApiKeyFromUsername(username),
@ -188,7 +215,7 @@ public class GrsfPublisherFisheryService {
record.getMaintainerContact(),
record.getVersion(),
record.getDescription(),
record.getLicense(),
license,
tags,
customFields,
resources,

View File

@ -38,13 +38,15 @@ import org.slf4j.LoggerFactory;
@Path("stock/")
public class GrsfPublisherStockService {
private static final String DEFAULT_STOCK_LICENSE = "CC-BY-SA-4.0";
// the context
@Context
ServletContext contextServlet;
// Logger
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GrsfPublisherStockService.class);
@GET
@Path("hello")
@Produces(MediaType.TEXT_PLAIN)
@ -52,6 +54,25 @@ public class GrsfPublisherStockService {
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
@Path("publish-product")
@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
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
id = catalogue.createCKanDataset(
catalogue.getApiKeyFromUsername(username),
@ -187,7 +216,7 @@ public class GrsfPublisherStockService {
record.getMaintainerContact(),
record.getVersion(),
record.getDescription(),
record.getLicense(),
license,
tags,
customFields,
resources,

View File

@ -4,11 +4,13 @@ import java.beans.PropertyDescriptor;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.Group;
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.impl.client.CloseableHttpClient;
import eu.trentorise.opendata.jackan.internal.org.apache.http.impl.client.HttpClientBuilder;
import eu.trentorise.opendata.jackan.model.CkanLicense;
/**
@ -52,7 +55,7 @@ public abstract class HelperMethods {
modified = modified.substring(1);
if(modified.endsWith("-"))
modified = modified.substring(0, modified.length() -1);
return modified;
}
@ -283,4 +286,36 @@ public abstract class HelperMethods {
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);
}
}

View File

@ -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.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
public class JJerseyTest extends JerseyTest{
//@Override
protected Application configure() {
forceSet(TestProperties.CONTAINER_PORT, "0");
return new ResourceConfig(GrsfPublisherFisheryService.class, GrsfPublisherStockService.class);
}
@ -30,9 +32,6 @@ public class JJerseyTest extends JerseyTest{
recordFishery.setType(Type.Fishing_Description);
recordFishery.setDatabaseSources(Source.FIRMS);
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));
System.out.println("Result is " + res.readEntity(String.class));
}
@ -50,4 +49,12 @@ public class JJerseyTest extends JerseyTest{
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);
}
}