Fixed group association retrieval: also the enums have been annotated with the @Group annotation
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@135147 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
39b9131fa7
commit
35a7c82586
|
@ -10,7 +10,7 @@ import java.lang.annotation.Target;
|
|||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
@Target({ElementType.FIELD, ElementType.TYPE})
|
||||
public @interface Group {
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -90,7 +90,6 @@ public class Common {
|
|||
@CustomField(key="Status")
|
||||
@Group
|
||||
@Tag
|
||||
@NotNull(message="status cannot be null")
|
||||
private Status status;
|
||||
|
||||
// automatically compiled
|
||||
|
|
|
@ -10,8 +10,8 @@ import javax.validation.constraints.Size;
|
|||
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;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Fishery_Type;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Production_System_Type;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Type_Fishery;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
@ -85,7 +85,7 @@ public class FisheryRecord extends Common{
|
|||
@CustomField(key="Type")
|
||||
@Tag
|
||||
@Group
|
||||
private Type_Fishery type;
|
||||
private Fishery_Type type;
|
||||
|
||||
public FisheryRecord() {
|
||||
super();
|
||||
|
@ -113,7 +113,7 @@ public class FisheryRecord extends Common{
|
|||
Production_System_Type productionSystemType, String flagState,
|
||||
String fishingGear, String environment,
|
||||
List<TimeSeriesBean<String, String>> catchesOrLandings,
|
||||
Type_Fishery type) {
|
||||
Fishery_Type type) {
|
||||
super();
|
||||
this.fisheryName = fisheryName;
|
||||
this.fisheryId = fisheryId;
|
||||
|
@ -230,11 +230,11 @@ public class FisheryRecord extends Common{
|
|||
}
|
||||
}
|
||||
|
||||
public Type_Fishery getType() {
|
||||
public Fishery_Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Type_Fishery type) {
|
||||
public void setType(Fishery_Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ 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.utils.groups.Abundance_Level;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Exploitation_Rate;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Type_Stock;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Stock_Type;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
@ -111,7 +111,7 @@ public class StockRecord extends Common{
|
|||
@CustomField(key="Type")
|
||||
@Tag
|
||||
@Group
|
||||
private Type_Stock type;
|
||||
private Stock_Type type;
|
||||
|
||||
public StockRecord() {
|
||||
super();
|
||||
|
@ -149,7 +149,7 @@ public class StockRecord extends Common{
|
|||
Abundance_Level abundanceLevelForGrouping,
|
||||
String narrativeStateAndTrend, String scientificAdvice,
|
||||
String reportingEntity, Long reportingYear, String stockUri,
|
||||
List<String> waterArea, Type_Stock type) {
|
||||
List<String> waterArea, Stock_Type type) {
|
||||
super();
|
||||
this.stockName = stockName;
|
||||
this.stockID = stockID;
|
||||
|
@ -172,11 +172,11 @@ public class StockRecord extends Common{
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public Type_Stock getType() {
|
||||
public Stock_Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Type_Stock type) {
|
||||
public void setType(Stock_Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
|
|
@ -125,6 +125,14 @@ public class GrsfPublisherFisheryService {
|
|||
throw new Exception("There was a problem while serving your request");
|
||||
|
||||
}else{
|
||||
|
||||
// in this case, the status is mandatory
|
||||
if(record.getStatus() == null && contextInWhichPublish.equals(HelperMethods.PENDING_CONTEX_KEY)){
|
||||
|
||||
status = Status.BAD_REQUEST;
|
||||
throw new Exception("Status information is missing");
|
||||
|
||||
}
|
||||
|
||||
// check the user has editor/admin role into the org
|
||||
String organization = HelperMethods.retrieveOrgNameFromScope(contextInWhichPublish);
|
||||
|
|
|
@ -122,6 +122,14 @@ public class GrsfPublisherStockService {
|
|||
throw new Exception("There was a problem while serving your request");
|
||||
|
||||
}else{
|
||||
|
||||
// in this case, the status is mandatory
|
||||
if(record.getStatus() == null && contextInWhichPublish.equals(HelperMethods.PENDING_CONTEX_KEY)){
|
||||
|
||||
status = Status.BAD_REQUEST;
|
||||
throw new Exception("Status information is missing");
|
||||
|
||||
}
|
||||
|
||||
// check the user has editor/admin role into the org
|
||||
String organization = HelperMethods.retrieveOrgNameFromScope(contextInWhichPublish);
|
||||
|
|
|
@ -52,8 +52,8 @@ public abstract class HelperMethods {
|
|||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(HelperMethods.class);
|
||||
|
||||
// to be retrieved from the web.xml
|
||||
private static final String PENDING_CONTEX_KEY = "PendingContext";
|
||||
private static final String CONFIRMED_CONTEX_KEY = "ConfirmedContext";
|
||||
public static final String PENDING_CONTEX_KEY = "PendingContext";
|
||||
public static final String CONFIRMED_CONTEX_KEY = "ConfirmedContext";
|
||||
private static final int TIME_SERIES_TAKE_LAST_VALUES = 5;
|
||||
private static final String CSV_MIME = "text/csv";
|
||||
private static final String PATH_SEPARATOR = "/";
|
||||
|
@ -174,6 +174,18 @@ public abstract class HelperMethods {
|
|||
groups.add(groupName);
|
||||
|
||||
}
|
||||
|
||||
// check if the field is an enumerator, and the enum class is also annotated with @Group
|
||||
if(field.getClass().isEnum() && field.getClass().isAnnotationPresent(Group.class)){
|
||||
|
||||
// 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 = getGroupNameOnCkan(field.getClass().getName());
|
||||
if(!groups.contains(groupName))
|
||||
groups.add(groupName);
|
||||
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Failed ot read value for field " + field.getName() + " skipping", e);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.gcube.data_catalogue.grsf_publish_ws.utils.groups;
|
||||
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.Group;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
|
@ -7,6 +9,7 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
|||
* Abundance_Level for Stock records
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
@Group
|
||||
public enum Abundance_Level {
|
||||
|
||||
Intermediate_Abundance("Intermediate abundance"),
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
package org.gcube.data_catalogue.grsf_publish_ws.utils.groups;
|
||||
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.Group;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
|
||||
/**
|
||||
* Exploitation_Rate for Stock records
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
@Group
|
||||
public enum Exploitation_Rate {
|
||||
|
||||
Moderate_Fishing_Mortality("Moderate fishing mortality"),
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.gcube.data_catalogue.grsf_publish_ws.utils.groups;
|
||||
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.Group;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
|
@ -8,14 +10,15 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
|||
* Type for Fishery records
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public enum Type_Fishery {
|
||||
@Group
|
||||
public enum Fishery_Type {
|
||||
|
||||
Fishery_Activity("Fishery Activity"), // for fishery
|
||||
Fishing_Description("Fishing Description"); // for fishery
|
||||
|
||||
private String subGroupNameOrig;
|
||||
|
||||
private Type_Fishery(String origName) {
|
||||
private Fishery_Type(String origName) {
|
||||
this.subGroupNameOrig = origName;
|
||||
}
|
||||
|
||||
|
@ -42,9 +45,9 @@ public enum Type_Fishery {
|
|||
* @return
|
||||
*/
|
||||
@JsonCreator
|
||||
public static Type_Fishery onDeserialize(String typeString) {
|
||||
public static Fishery_Type onDeserialize(String typeString) {
|
||||
if(typeString != null) {
|
||||
for(Type_Fishery type : Type_Fishery.values()) {
|
||||
for(Fishery_Type type : Fishery_Type.values()) {
|
||||
if(type.getOrigName().equalsIgnoreCase(typeString.trim()))
|
||||
return type;
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package org.gcube.data_catalogue.grsf_publish_ws.utils.groups;
|
||||
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.Group;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
|
@ -7,6 +9,7 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
|||
* Production_System_Type for Fishery records
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
@Group
|
||||
public enum Production_System_Type {
|
||||
|
||||
Subsistence("Subsistence"),
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.gcube.data_catalogue.grsf_publish_ws.utils.groups;
|
||||
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.Group;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
|
@ -7,6 +9,7 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
|||
* Source Group and sub groups (for both Stock and Fishery) -> look at "Database Sources"
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
@Group
|
||||
public enum Source {
|
||||
|
||||
FIRMS("FIRMS"),
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.gcube.data_catalogue.grsf_publish_ws.utils.groups;
|
||||
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.Group;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
|
@ -7,6 +9,7 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
|||
* Status Group and sub groups (for both Stock and Fishery)
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
@Group
|
||||
public enum Status {
|
||||
|
||||
Pending("Pending"),
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.gcube.data_catalogue.grsf_publish_ws.utils.groups;
|
||||
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.Group;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
|
@ -8,14 +10,15 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
|||
* @author Costantino Perciante at ISTI-CNR
|
||||
* (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public enum Type_Stock {
|
||||
@Group
|
||||
public enum Stock_Type {
|
||||
|
||||
Assessment_Unit("Assessment Unit"),// for stock
|
||||
Resource("Resource"); // for stock
|
||||
|
||||
private String subGroupNameOrig;
|
||||
|
||||
private Type_Stock(String origName) {
|
||||
private Stock_Type(String origName) {
|
||||
this.subGroupNameOrig = origName;
|
||||
}
|
||||
|
||||
|
@ -42,9 +45,9 @@ public enum Type_Stock {
|
|||
* @return
|
||||
*/
|
||||
@JsonCreator
|
||||
public static Type_Stock onDeserialize(String typeString) {
|
||||
public static Stock_Type onDeserialize(String typeString) {
|
||||
if(typeString != null) {
|
||||
for(Type_Stock type : Type_Stock.values()) {
|
||||
for(Stock_Type type : Stock_Type.values()) {
|
||||
if(type.getOrigName().equalsIgnoreCase(typeString.trim()))
|
||||
return type;
|
||||
}
|
|
@ -12,10 +12,10 @@ import org.gcube.data_catalogue.grsf_publish_ws.json.input.Resource;
|
|||
import org.gcube.data_catalogue.grsf_publish_ws.json.input.StockRecord;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.services.GrsfPublisherFisheryService;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.services.GrsfPublisherStockService;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Fishery_Type;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Source;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Type_Fishery;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Type_Stock;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Stock_Type;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
import org.glassfish.jersey.test.JerseyTest;
|
||||
import org.glassfish.jersey.test.TestProperties;
|
||||
|
@ -35,7 +35,7 @@ public class JJerseyTest extends JerseyTest{
|
|||
recordFishery.setAuthorContact("costantino.perciante@isti.cnr.it");
|
||||
recordFishery.setLicense("a caso una lincense");
|
||||
recordFishery.setDataOwner("data owner");
|
||||
recordFishery.setType(Type_Fishery.Fishing_Description);
|
||||
recordFishery.setType(Fishery_Type.Fishing_Description);
|
||||
recordFishery.setDatabaseSources(new ArrayList<Resource<Source>>(1));
|
||||
recordFishery.setSourceOfInformation(new ArrayList<Resource<String>>(1));
|
||||
recordFishery.setStatus(Status.Pending);
|
||||
|
@ -48,7 +48,7 @@ public class JJerseyTest extends JerseyTest{
|
|||
StockRecord stock = new StockRecord();
|
||||
stock.setAuthor("Costantino Perciante");
|
||||
stock.setAuthorContact("costantino.perciante@isti.cnr.it");
|
||||
stock.setType(Type_Stock.Assessment_Unit);
|
||||
stock.setType(Stock_Type.Assessment_Unit);
|
||||
stock.setDatabaseSources(null);
|
||||
stock.setStatus(Status.Pending);
|
||||
|
||||
|
|
|
@ -37,9 +37,9 @@ import org.gcube.data_catalogue.grsf_publish_ws.json.input.TimeSeriesBean;
|
|||
import org.gcube.data_catalogue.grsf_publish_ws.utils.CSVHelpers;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.HelperMethods;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Abundance_Level;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Fishery_Type;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Source;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Type_Fishery;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogueFactory;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -61,7 +61,7 @@ public class JTests {
|
|||
public void test() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, IntrospectionException {
|
||||
|
||||
FisheryRecord recordFishery = new FisheryRecord();
|
||||
recordFishery.setType(Type_Fishery.Fishing_Description);
|
||||
recordFishery.setType(Fishery_Type.Fishing_Description);
|
||||
recordFishery.setDatabaseSources(new ArrayList<Resource<Source>>());
|
||||
recordFishery.setStatus(Status.Pending);
|
||||
|
||||
|
|
Loading…
Reference in New Issue