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 1505842..dfb2b5c 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 @@ -155,12 +155,23 @@ public class GrsfPublisherFisheryService { }else{ - // validate the record if it is a GRSF one and set the record type - if(sourceInPath.equals(Sources.GRSF)){ - record.setRecordType(Record_Type.AGGREGATED); - CommonServiceUtils.validateAggregatedRecord(record); - }else - record.setRecordType(Record_Type.ORIGINAL); + // validate the record if it is a GRSF one and set the record type and in manage context + // Status field is needed only in the Manage context + String contextFromStatus = HelperMethods.getContextTypeFromStatus(record.getStatus(), context, contextServlet); + if(contextFromStatus == null) + throw new Exception("Please verify that the record you are publishing contains the 'status' " + + "field if you are in the Manage VRE. This field is not needed in the Public VRE. " + + " The current Manage context is " + (String)contextServlet.getInitParameter(HelperMethods.MANAGE_CONTEX_KEY) + + " The current Public context is " + (String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY) + ); + + if(contextFromStatus.equals(HelperMethods.MANAGE_CONTEX_KEY)){ + if(sourceInPath.equals(Sources.GRSF)){ + record.setRecordType(Record_Type.AGGREGATED); + CommonServiceUtils.validateAggregatedRecord(record); + }else + record.setRecordType(Record_Type.ORIGINAL); + } // set the type record.setProductType(Product_Type.FISHERY.getOrigName()); 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 03ef9ac..074e0a7 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 @@ -150,12 +150,23 @@ public class GrsfPublisherStockService { }else{ - // validate the record if it is a GRSF one and set the record type - if(sourceInPath.equals(Sources.GRSF)){ - record.setRecordType(Record_Type.AGGREGATED); - CommonServiceUtils.validateAggregatedRecord(record); - }else - record.setRecordType(Record_Type.ORIGINAL); + // validate the record if it is a GRSF one and set the record type and in manage context + // Status field is needed only in the Manage context + String contextFromStatus = HelperMethods.getContextTypeFromStatus(record.getStatus(), context, contextServlet); + if(contextFromStatus == null) + throw new Exception("Please verify that the record you are publishing contains the 'status' " + + "field if you are in the Manage VRE. This field is not needed in the Public VRE. " + + " The current Manage context is " + (String)contextServlet.getInitParameter(HelperMethods.MANAGE_CONTEX_KEY) + + " The current Public context is " + (String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY) + ); + + if(contextFromStatus.equals(HelperMethods.MANAGE_CONTEX_KEY)){ + if(sourceInPath.equals(Sources.GRSF)){ + record.setRecordType(Record_Type.AGGREGATED); + CommonServiceUtils.validateAggregatedRecord(record); + }else + record.setRecordType(Record_Type.ORIGINAL); + } // set the type record.setProductType(Product_Type.STOCK.getOrigName()); diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/HelperMethods.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/HelperMethods.java index b89d518..fe707dd 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/HelperMethods.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/HelperMethods.java @@ -8,12 +8,15 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.servlet.ServletContext; + import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder; import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException; import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException; import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile; +import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status; import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue; import org.gcube.datacatalogue.ckanutillibrary.DataCatalogueFactory; import org.gcube.datacatalogue.ckanutillibrary.DataCatalogueImpl; @@ -37,8 +40,8 @@ public abstract class HelperMethods { private static final org.slf4j.Logger logger = LoggerFactory.getLogger(HelperMethods.class); // to be retrieved from the web.xml - public static final String PENDING_CONTEX_KEY = "PendingContext"; - public static final String CONFIRMED_CONTEX_KEY = "ConfirmedContext"; + public static final String MANAGE_CONTEX_KEY = "ManageVRE"; + public static final String PUBLIC_CONTEX_KEY = "PublicVRE"; private static final String CSV_MIME = "text/csv"; private static final String PATH_SEPARATOR = "/"; @@ -93,28 +96,37 @@ public abstract class HelperMethods { } - // /** - // * Return the context in which the user wants to publish by the status information - // * @param status - // * @param contextServlet - // * @return - // */ - // public static String getContextFromStatus(Status status, ServletContext contextServlet) { - // - // String toReturn = null; - // switch(status){ - // case Confirmed : - // toReturn = (String)contextServlet.getInitParameter(CONFIRMED_CONTEX_KEY); - // break; - // case Pending: - // toReturn = (String)contextServlet.getInitParameter(PENDING_CONTEX_KEY); - // break; - // default: break; - // - // } - // logger.debug("Context evaluated is " + toReturn); - // return toReturn; - // } + /** + * Return the context in which the user wants to publish by the status information + * @param status + * @param contextServlet + * @return + */ + + public static String getContextTypeFromStatus(Status status, String scope, ServletContext contextServlet) { + + String toReturn = null; + + switch(status){ + case Confirmed: + case Pending: + case Rejected: + if(scope.equals((String)contextServlet.getInitParameter(MANAGE_CONTEX_KEY))) + toReturn = MANAGE_CONTEX_KEY; + else + toReturn = null; // wrong context ... + break; + default: + if(scope.equals((String)contextServlet.getInitParameter(PUBLIC_CONTEX_KEY))) + toReturn = PUBLIC_CONTEX_KEY; + else + toReturn = null; // wrong context ... + break; + } + + logger.debug("Context type evaluated is " + toReturn); + return toReturn; + } /** * Validate the name the product will have diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 260256a..e2e1594 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -29,18 +29,18 @@ - Scope of pending products - PendingContext - + Scope of pending products under manage activities + ManageVRE + /gcube/devNext/NextNext - Scope of confirmed products - ConfirmedContext - + Scope of products no longer under manage activities + PublicVRE + /gcube/devNext/NextNext - +