Added the GRSF_Admin (manage context) and GRSF (public context) contexts in web.xml for production environment. Better checks for status field in manage context

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@139705 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-12-06 10:16:31 +00:00
parent 2df95eb79f
commit d3f3eeddd9
4 changed files with 77 additions and 43 deletions

View File

@ -155,12 +155,23 @@ public class GrsfPublisherFisheryService {
}else{ }else{
// validate the record if it is a GRSF one and set the record type // validate the record if it is a GRSF one and set the record type and in manage context
if(sourceInPath.equals(Sources.GRSF)){ // Status field is needed only in the Manage context
record.setRecordType(Record_Type.AGGREGATED); String contextFromStatus = HelperMethods.getContextTypeFromStatus(record.getStatus(), context, contextServlet);
CommonServiceUtils.validateAggregatedRecord(record); if(contextFromStatus == null)
}else throw new Exception("Please verify that the record you are publishing contains the 'status' "
record.setRecordType(Record_Type.ORIGINAL); + "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 // set the type
record.setProductType(Product_Type.FISHERY.getOrigName()); record.setProductType(Product_Type.FISHERY.getOrigName());

View File

@ -150,12 +150,23 @@ public class GrsfPublisherStockService {
}else{ }else{
// validate the record if it is a GRSF one and set the record type // validate the record if it is a GRSF one and set the record type and in manage context
if(sourceInPath.equals(Sources.GRSF)){ // Status field is needed only in the Manage context
record.setRecordType(Record_Type.AGGREGATED); String contextFromStatus = HelperMethods.getContextTypeFromStatus(record.getStatus(), context, contextServlet);
CommonServiceUtils.validateAggregatedRecord(record); if(contextFromStatus == null)
}else throw new Exception("Please verify that the record you are publishing contains the 'status' "
record.setRecordType(Record_Type.ORIGINAL); + "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 // set the type
record.setProductType(Product_Type.STOCK.getOrigName()); record.setProductType(Product_Type.STOCK.getOrigName());

View File

@ -8,12 +8,15 @@ 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 org.gcube.common.homelibrary.home.exceptions.InternalErrorException; import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder; import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; 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.InsufficientPrivilegesException;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException; import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException;
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile; 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.DataCatalogue;
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogueFactory; import org.gcube.datacatalogue.ckanutillibrary.DataCatalogueFactory;
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogueImpl; 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); private static final org.slf4j.Logger logger = LoggerFactory.getLogger(HelperMethods.class);
// to be retrieved from the web.xml // to be retrieved from the web.xml
public static final String PENDING_CONTEX_KEY = "PendingContext"; public static final String MANAGE_CONTEX_KEY = "ManageVRE";
public static final String CONFIRMED_CONTEX_KEY = "ConfirmedContext"; public static final String PUBLIC_CONTEX_KEY = "PublicVRE";
private static final String CSV_MIME = "text/csv"; private static final String CSV_MIME = "text/csv";
private static final String PATH_SEPARATOR = "/"; 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 * Return the context in which the user wants to publish by the status information
// * @param status * @param status
// * @param contextServlet * @param contextServlet
// * @return * @return
// */ */
// public static String getContextFromStatus(Status status, ServletContext contextServlet) {
// public static String getContextTypeFromStatus(Status status, String scope, ServletContext contextServlet) {
// String toReturn = null;
// switch(status){ String toReturn = null;
// case Confirmed :
// toReturn = (String)contextServlet.getInitParameter(CONFIRMED_CONTEX_KEY); switch(status){
// break; case Confirmed:
// case Pending: case Pending:
// toReturn = (String)contextServlet.getInitParameter(PENDING_CONTEX_KEY); case Rejected:
// break; if(scope.equals((String)contextServlet.getInitParameter(MANAGE_CONTEX_KEY)))
// default: break; toReturn = MANAGE_CONTEX_KEY;
// else
// } toReturn = null; // wrong context ...
// logger.debug("Context evaluated is " + toReturn); break;
// return toReturn; 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 * Validate the name the product will have

View File

@ -29,18 +29,18 @@
</welcome-file-list> </welcome-file-list>
<context-param> <context-param>
<description>Scope of pending products</description> <description>Scope of pending products under manage activities</description>
<param-name>PendingContext</param-name> <param-name>ManageVRE</param-name>
<!-- <param-value>/d4science.research-infrastructures.eu/FARM/GRSF</param-value> --> <!-- <param-value>/d4science.research-infrastructures.eu/FARM/GRSF_Admin</param-value> -->
<param-value>/gcube/devNext/NextNext</param-value> <param-value>/gcube/devNext/NextNext</param-value>
<!-- <param-value>/gcube/preprod/Dorne</param-value> --> <!-- <param-value>/gcube/preprod/Dorne</param-value> -->
</context-param> </context-param>
<context-param> <context-param>
<description>Scope of confirmed products</description> <description>Scope of products no longer under manage activities</description>
<param-name>ConfirmedContext</param-name> <param-name>PublicVRE</param-name>
<!-- <param-value>/d4science.research-infrastructures.eu/FARM/GRSFAccepted</param-value> --> <!-- <param-value>/d4science.research-infrastructures.eu/FARM/GRSF</param-value> -->
<param-value>/gcube/devNext/NextNext</param-value> <param-value>/gcube/devNext/NextNext</param-value>
<!-- <param-value>/gcube/preprod/Dorne</param-value> --> <!-- <param-value>/gcube/preprod/preVRE</param-value> -->
</context-param> </context-param>
</web-app> </web-app>