Minor fixes for new model
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@142814 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
ae05d37066
commit
a7003850ce
|
@ -19,4 +19,11 @@ public @interface Group {
|
|||
*/
|
||||
String condition() default "";
|
||||
|
||||
/**
|
||||
* If this value is set, it is the name of the group to which the
|
||||
* record needs to be put.
|
||||
* @return
|
||||
*/
|
||||
String groupNameOverValue() default "";
|
||||
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class Common extends Base{
|
|||
|
||||
@JsonProperty("traceability_flag")
|
||||
@CustomField(key="Traceability Flag")
|
||||
@Group(condition="true") // record is added to group if Traceability Flag is true
|
||||
@Group(condition="true", groupNameOverValue="traceability-flag") // record is added to group if Traceability Flag is true
|
||||
private Boolean traceabilityFlag;
|
||||
|
||||
@JsonProperty("status")
|
||||
|
|
|
@ -210,12 +210,12 @@ public class StockRecord extends Common{
|
|||
this.stockName = stockName;
|
||||
}
|
||||
|
||||
public String getStockID() {
|
||||
public String getStockId() {
|
||||
return stockId;
|
||||
}
|
||||
|
||||
public void setStockID(String stockID) {
|
||||
this.stockId = stockID;
|
||||
public void setStockId(String stockId) {
|
||||
this.stockId = stockId;
|
||||
}
|
||||
|
||||
public List<String> getSpecies() {
|
||||
|
|
|
@ -196,6 +196,7 @@ public class CommonServiceUtils {
|
|||
private static void getGroupsByField(Field field, Class<?> current, Base record, Set<String> groups, Sources source){
|
||||
if(field.isAnnotationPresent(Group.class)){
|
||||
String conditionToCheck = field.getAnnotation(Group.class).condition();
|
||||
String groupNameOverValue = field.getAnnotation(Group.class).groupNameOverValue();
|
||||
try{
|
||||
Object f = new PropertyDescriptor(field.getName(), current).getReadMethod().invoke(record);
|
||||
if(f != null){
|
||||
|
@ -209,10 +210,10 @@ public class CommonServiceUtils {
|
|||
for (int i = 0; i < asList.size(); i++) {
|
||||
boolean match = conditionToCheck.equals("") ? true : asList.get(i).toString().trim().matches(conditionToCheck);
|
||||
if(match){
|
||||
|
||||
String groupName = HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + asList.get(i).toString().trim());
|
||||
groups.add(groupName);
|
||||
|
||||
String groupName = groupNameOverValue.equals("") ?
|
||||
HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + asList.get(i).toString().trim()) :
|
||||
source.toString().toLowerCase() + "-" + groupNameOverValue;
|
||||
groups.add(groupName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -222,10 +223,12 @@ public class CommonServiceUtils {
|
|||
// also convert to the group name that should be on ckan
|
||||
boolean match = conditionToCheck.equals("") ? true : f.toString().trim().matches(conditionToCheck);
|
||||
if(match){
|
||||
|
||||
String groupName = HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + f.toString().trim());
|
||||
groups.add(groupName);
|
||||
|
||||
|
||||
String groupName = groupNameOverValue.equals("") ?
|
||||
HelperMethods.getGroupNameOnCkan(source.toString().toLowerCase() + "-" + f.toString().trim()) :
|
||||
source.toString().toLowerCase() + "-" + groupNameOverValue;
|
||||
groups.add(groupName);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,10 +125,13 @@ public class GrsfPublisherFisheryService {
|
|||
}else{
|
||||
|
||||
String apiKey = catalogue.getApiKeyFromUsername(username);
|
||||
String organization = HelperMethods.retrieveOrgNameFromScope(context);
|
||||
String organization = HelperMethods.retrieveOrgNameFromScope(context); //"grsf_admin";
|
||||
String role = catalogue.getRoleOfUserInOrganization(username, organization, apiKey);
|
||||
|
||||
logger.info("Role of the user " + username + " is " + role);
|
||||
|
||||
if(role == null || role.isEmpty())
|
||||
throw new Exception("You are not authorized to create a product. Please check you have the Catalogue-Administrator role!");
|
||||
|
||||
if(!role.equalsIgnoreCase(RolesCkanGroupOrOrg.ADMIN.toString())){
|
||||
status = Status.FORBIDDEN;
|
||||
|
@ -281,7 +284,7 @@ public class GrsfPublisherFisheryService {
|
|||
futureTitle,
|
||||
itemUrl,
|
||||
false,
|
||||
new ArrayList<String>(tags),
|
||||
new ArrayList<String>(),
|
||||
authorFullname).start();
|
||||
|
||||
logger.info("Thread to write a post about the new product has been launched");
|
||||
|
|
|
@ -120,10 +120,13 @@ public class GrsfPublisherStockService {
|
|||
}else{
|
||||
|
||||
String apiKey = catalogue.getApiKeyFromUsername(username);
|
||||
String organization = HelperMethods.retrieveOrgNameFromScope(context);
|
||||
String organization = HelperMethods.retrieveOrgNameFromScope(context); //"grsf_admin";// TODO
|
||||
String role = catalogue.getRoleOfUserInOrganization(username, organization, apiKey);
|
||||
|
||||
logger.info("Role of the user " + username + " is " + role);
|
||||
|
||||
if(role == null || role.isEmpty())
|
||||
throw new Exception("You are not authorized to create a product. Please check you have the Catalogue-Administrator role!");
|
||||
|
||||
if(!role.equalsIgnoreCase(RolesCkanGroupOrOrg.ADMIN.toString())){
|
||||
|
||||
|
@ -237,7 +240,7 @@ public class GrsfPublisherStockService {
|
|||
new ArrayList<String>(tags),
|
||||
customFields,
|
||||
resources,
|
||||
publicDataset);
|
||||
publicDataset);
|
||||
|
||||
if(id != null){
|
||||
|
||||
|
@ -276,7 +279,7 @@ public class GrsfPublisherStockService {
|
|||
futureTitle,
|
||||
itemUrl,
|
||||
false,
|
||||
new ArrayList<String>(tags),
|
||||
new ArrayList<String>(),
|
||||
authorFullname).start();
|
||||
logger.info("Thread to write a post about the new product has been launched");
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import eu.trentorise.opendata.jackan.internal.org.apache.http.client.methods.Htt
|
|||
import eu.trentorise.opendata.jackan.internal.org.apache.http.entity.StringEntity;
|
||||
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.LaxRedirectStrategy;
|
||||
import eu.trentorise.opendata.jackan.internal.org.apache.http.util.EntityUtils;
|
||||
import eu.trentorise.opendata.jackan.model.CkanLicense;
|
||||
|
||||
|
@ -141,7 +142,8 @@ public abstract class HelperMethods {
|
|||
return result;
|
||||
}else{
|
||||
String baseUrl = new GcoreEndPointReaderSocial(context).getBasePath();
|
||||
String url = baseUrl + "users/getUserEmail?gcube-token=" + token;
|
||||
String url = baseUrl.endsWith("/") ? baseUrl + "users/getUserEmail?gcube-token=" + token :
|
||||
baseUrl + "/users/getUserEmail?gcube-token=" + token;
|
||||
logger.debug("Request url is " + url);
|
||||
result = executGETHttpRequest(url, 200);
|
||||
userEmailCache.insert(token, result);
|
||||
|
@ -164,7 +166,8 @@ public abstract class HelperMethods {
|
|||
return result;
|
||||
}else{
|
||||
String baseUrl = new GcoreEndPointReaderSocial(context).getBasePath();
|
||||
String url = baseUrl + "users/getUserFullname?gcube-token=" + token;
|
||||
String url = baseUrl.endsWith("/") ? baseUrl + "users/getUserFullname?gcube-token=" + token :
|
||||
baseUrl + "/users/getUserFullname?gcube-token=" + token;
|
||||
logger.debug("Request url is " + url);
|
||||
result = executGETHttpRequest(url, 200);
|
||||
userFullnameCache.insert(token, result);
|
||||
|
@ -363,8 +366,10 @@ public abstract class HelperMethods {
|
|||
logger.error("Unable to write a post because there is no social networking service available");
|
||||
|
||||
}else{
|
||||
|
||||
basePath = basePath.endsWith("/") ? basePath : basePath + "/";
|
||||
|
||||
try(CloseableHttpClient client = HttpClientBuilder.create().build();){
|
||||
try(CloseableHttpClient client = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();){
|
||||
|
||||
// ask token application
|
||||
HttpPost postRequest = new HttpPost(basePath + SOCIAL_SERVICE_APPLICATION_TOKEN + "?gcube-token=" + tokenUser);
|
||||
|
|
|
@ -128,6 +128,7 @@ public class ManageTimeSeriesThread extends Thread{
|
|||
* @throws WorkspaceFolderNotFoundException
|
||||
* @throws ItemNotFoundException
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static void manageTimeSeries(Common record, String packageName, String username, DataCatalogue catalogue) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException, WorkspaceFolderNotFoundException, InternalErrorException, HomeNotFoundException, UserNotFoundException, ItemNotFoundException{
|
||||
|
||||
if(record == null)
|
||||
|
@ -163,6 +164,7 @@ public class ManageTimeSeriesThread extends Thread{
|
|||
char firstLetter = productName.charAt(0);
|
||||
|
||||
// the whole path of the directory is going to be...
|
||||
productName = replaceIllegalChars(productName);
|
||||
String csvDirectoryForThisProduct = recordTypeFolderName + PATH_SEPARATOR + firstLetter + PATH_SEPARATOR + productName + PATH_SEPARATOR + "csv";
|
||||
logger.debug("The path under which the time series are going to be saved is " + csvDirectoryForThisProduct);
|
||||
WorkspaceFolder csvFolder = HelperMethods.createOrGetSubFoldersByPath(catalogueFolder, csvDirectoryForThisProduct);
|
||||
|
@ -186,7 +188,7 @@ public class ManageTimeSeriesThread extends Thread{
|
|||
|
||||
CustomField customAnnotation = field.getAnnotation(CustomField.class);
|
||||
logger.debug("A time series has been just found (from field " + customAnnotation.key() + ")");
|
||||
String resourceToAttachName = (productName + "_" + customAnnotation.key()).replaceAll("\\s", "_") + CSV_FILE_FORMAT;
|
||||
String resourceToAttachName = (productName + "_" + customAnnotation.key()).replaceAll("\\s", "_").replaceAll("[_]+", "_") + CSV_FILE_FORMAT;
|
||||
String resourceToAttachDescription = productName + " : " + customAnnotation.key() + " time series";
|
||||
|
||||
File csvFile = CSVHelpers.listToCSV(asList);
|
||||
|
@ -235,6 +237,15 @@ public class ManageTimeSeriesThread extends Thread{
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace chars
|
||||
* @param productName
|
||||
* @return
|
||||
*/
|
||||
private static String replaceIllegalChars(String productName) {
|
||||
return productName.replaceAll("[/\\[\\],|:*.+]", "_");
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload a resource on ckan
|
||||
* @param csvFile
|
||||
|
|
|
@ -5,6 +5,20 @@
|
|||
<description>Data Catalogue Service</description>
|
||||
<local-persistence location='target' />
|
||||
<exclude>/rest/</exclude>
|
||||
<exclude>/rest/stock/hello</exclude>
|
||||
<exclude>/rest/fishery/hello</exclude>
|
||||
<exclude>/rest/firms/stock/hello</exclude>
|
||||
<exclude>/rest/FIRMS/stock/hello</exclude>
|
||||
<exclude>/rest/ram/stock/hello</exclude>
|
||||
<exclude>/rest/RAM/stock/hello</exclude>
|
||||
<exclude>/rest/GRSF/stock/hello</exclude>
|
||||
<exclude>/rest/grsf/stock/hello</exclude>
|
||||
<exclude>/rest/FishSource/stock/hello</exclude>
|
||||
<exclude>/rest/fishsource/stock/hello</exclude>
|
||||
<exclude>/rest/firms/fishery/hello</exclude>
|
||||
<exclude>/rest/FIRMS/fishery/hello</exclude>
|
||||
<exclude>/rest/ram/fishery/hello</exclude>
|
||||
<exclude>/rest/RAM/fishery/hello</exclude>
|
||||
<exclude>/rest/GRSF/fishery/hello</exclude>
|
||||
<exclude>/rest/grsf/fishery/hello</exclude>
|
||||
<exclude>/rest/FishSource/fishery/hello</exclude>
|
||||
<exclude>/rest/fishsource/fishery/hello</exclude>
|
||||
</application>
|
|
@ -31,16 +31,16 @@
|
|||
<context-param>
|
||||
<description>Scope of pending products under manage activities</description>
|
||||
<param-name>ManageVRE</param-name>
|
||||
<param-value>/d4science.research-infrastructures.eu/FARM/GRSF_Admin</param-value>
|
||||
<!-- <param-value>/gcube/devNext/NextNext</param-value> -->
|
||||
<!-- <param-value>/d4science.research-infrastructures.eu/FARM/GRSF_Admin</param-value> -->
|
||||
<param-value>/gcube/devNext/NextNext</param-value>
|
||||
<!-- <param-value>/gcube/preprod/Dorne</param-value> -->
|
||||
</context-param>
|
||||
|
||||
<context-param>
|
||||
<description>Scope of products no longer under manage activities</description>
|
||||
<param-name>PublicVRE</param-name>
|
||||
<param-value>/d4science.research-infrastructures.eu/FARM/GRSF</param-value>
|
||||
<!-- <param-value>/gcube/devNext/NextNext</param-value> -->
|
||||
<!-- <param-value>/d4science.research-infrastructures.eu/FARM/GRSF</param-value> -->
|
||||
<param-value>/gcube/devNext/NextNext</param-value>
|
||||
<!-- <param-value>/gcube/preprod/preVRE</param-value> -->
|
||||
</context-param>
|
||||
</web-app>
|
||||
|
|
Loading…
Reference in New Issue