merged with branch version 1.9 at 179217 RN

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@179847 82a268e6-3cf1-43bd-a215-b396298e98cf
feature/17695
Francesco Mangiacrapa 5 years ago
parent 8e9ecfe58c
commit 57c3d65283

@ -3,7 +3,7 @@
<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="grsf-common-library-1.0.3-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/grsf-common-library/grsf-common-library">
<dependent-module archiveName="ckan-util-library-2.10.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/ckan-util-library-TRUNK/ckan-util-library-TRUNK">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="grsf-publisher-ws"/>

@ -2,7 +2,10 @@
<!DOCTYPE xml>
<ReleaseNotes>
<Changeset component="org.gcube.data-catalogue.grsf-publisher-ws.1-9-0" date="${buildDate}">
<Change></Change>
<Change>refers_to can be null while publishing legacy records refs #13347</Change>
<Change>Removed the non-ascii clean from extra fields refs #12421</Change>
<Change>Properly supporting UTF-8 characters refs #12421</Change>
<Change>Title is updated according to Stock/Fishery Name refs #16395</Change>
</Changeset>
<Changeset component="org.gcube.data-catalogue.grsf-publisher-ws.1-8-0" date="2019-02-26">
<Change>The sources in GRSF VRE are calculated using 'database_sources' field #12861</Change>

@ -196,7 +196,7 @@ public abstract class Base {
else
values = new ArrayList<String>();
values.add(HelperMethods.removeHTML(value.toString()));
values.add(HelperMethods.removeHTML(value.toString(), false));
extrasFields.put(key, values);
}

@ -173,7 +173,7 @@ public class FisheryRecord extends Common {
@Override
public String toString() {
return "FisheryRecord [fisheryName=" + fisheryName + ", fisheryId="
return super.toString() + " - FisheryRecord [fisheryName=" + fisheryName + ", fisheryId="
+ fisheryId + ", fishingArea=" + fishingArea
+ ", resourcesExploited=" + resourcesExploited
+ ", jurisdictionArea=" + jurisdictionArea

@ -292,7 +292,7 @@ public class StockRecord extends Common{
@Override
public String toString() {
return "StockRecord [stockName=" + stockName + ", stockId=" + stockId
return super.toString() + "- StockRecord [stockName=" + stockName + ", stockId=" + stockId
+ ", area=" + area + ", exploitingFishery=" + exploitingFishery
+ ", assessmentMethods=" + assessmentMethods
+ ", abundanceLevelStandard=" + abundanceLevelStandard

@ -423,9 +423,12 @@ public class GrsfPublisherFisheryService {
// check he/she has admin role
CommonServiceUtils.hasAdminRole(username, catalogue, apiKey, organization);
// name, title, product url and are going to remain unchanged (so we keep them from the already published record);
// name, product url and are going to remain unchanged (so we keep them from the already published record);
String name = recordPublished.getName();
String title = recordPublished.getTitle();
// The title must change if Fishery Name change
//String title = recordPublished.getTitle();
String title = record.getFisheryName();
// Cast the source to the accepted ones
Sources sourceInPath = Sources.onDeserialize(source);
@ -480,7 +483,7 @@ public class GrsfPublisherFisheryService {
// update the product
String id = catalogue.updateCKanDataset(apiKey, catalogId, title, name, publishInOrganization,
authorFullname, authorMail, record.getMaintainer(), record.getMaintainerContact(), version,
HelperMethods.removeHTML(record.getDescription()), license, new ArrayList<String>(tags), null, // remove any previous group
HelperMethods.removeHTML(record.getDescription(), false), license, new ArrayList<String>(tags), null, // remove any previous group
customFields, resources, publicDataset);
if(id != null) {

@ -188,7 +188,7 @@ public class GrsfPublisherStockService {
publishInOrganization, authorFullname, authorMail,
record.getMaintainer() == null ? authorFullname : record.getMaintainer(),
record.getMaintainerContact() == null ? authorMail : record.getMaintainerContact(), version,
HelperMethods.removeHTML(record.getDescription()), license, new ArrayList<String>(tags),
HelperMethods.removeHTML(record.getDescription(), false), license, new ArrayList<String>(tags),
customFields, resources, publicDataset);
if(id != null) {
@ -425,9 +425,13 @@ public class GrsfPublisherStockService {
// check he/she has admin role
CommonServiceUtils.hasAdminRole(username, catalogue, apiKey, organization);
// name, title, product url and are going to remain unchanged (so we keep them from the publisher record);
// name, product url and are going to remain unchanged (so we keep them from the publisher record);
String name = recordPublished.getName();
String title = recordPublished.getTitle();
// The title must change if Stock Name change
//String title = recordPublished.getTitle();
String title = record.getStockName();
// Cast the source to the accepted ones
Sources sourceInPath = Sources.onDeserialize(source);
@ -482,7 +486,7 @@ public class GrsfPublisherStockService {
// update the product
String id = catalogue.updateCKanDataset(apiKey, catalogId, title, name, publishInOrganization,
authorFullname, authorMail, record.getMaintainer(), record.getMaintainerContact(), version,
HelperMethods.removeHTML(record.getDescription()), license, new ArrayList<String>(tags), null, // remove any previous group
HelperMethods.removeHTML(record.getDescription(), false), license, new ArrayList<String>(tags), null, // remove any previous group
customFields, resources, publicDataset);
if(id != null) {

@ -80,21 +80,20 @@ public class CommonServiceUtils {
List<RefersToBean> refersToList = record.getRefersTo();
if(refersToList == null || refersToList.isEmpty())
throw new Exception("refers_to cannot be null/empty");
Boolean traceabilityFlag = record.isTraceabilityFlag();
if(traceabilityFlag == null)
throw new Exception("traceability_flag cannot be null");
Status status = record.getStatus();
if(status == null)
throw new Exception("status cannot be null/empty");
}
String shortTitle = record.getShortName();
Boolean traceabilityFlag = record.isTraceabilityFlag();
Status status = record.getStatus();
if(traceabilityFlag == null)
throw new Exception("traceability_flag cannot be null");
if(shortTitle == null || shortTitle.isEmpty())
throw new Exception("short_title cannot be null/empty");
if(status == null)
throw new Exception("status cannot be null/empty");
// check if it is a stock and perform related checks
if(record.getClass().equals(StockRecord.class)) {
@ -349,18 +348,21 @@ public class CommonServiceUtils {
Constants.TIME_SERIES_TAKE_LAST_VALUES);
for(int i = 0; i < elementsToConsider; i++) {
// trim and remove html
String clean = HelperMethods.removeHTML(asList.get(i).toString().trim());
// String clean = HelperMethods.removeHTML(asList.get(i).toString().trim());
String clean = HelperMethods.removeHTML(asList.get(i).toString().trim(), false);
valuesForKey.add(clean);
}
} else
for(int i = 0; i < elementsToConsider; i++) {
String clean = HelperMethods.removeHTML(asList.get(i).toString().trim());
// String clean = HelperMethods.removeHTML(asList.get(i).toString().trim());
String clean = HelperMethods.removeHTML(asList.get(i).toString().trim(), false);
valuesForKey.add(clean);
}
}
} else {
String clean = HelperMethods.removeHTML(f.toString().trim());
// String clean = HelperMethods.removeHTML(f.toString().trim());
String clean = HelperMethods.removeHTML(f.toString().trim(), false);
valuesForKey.add(clean);
}
@ -500,9 +502,11 @@ public class CommonServiceUtils {
// I'm not in GRSF Admin so the groups must be added using databaseSources
List<Resource<Sources>> databaseSources = record.getDatabaseSources();
for(Resource<Sources> source : databaseSources) {
Sources sourceName = source.getName();
sourcesList.add(sourceName.getOrigName().toLowerCase());
if(databaseSources!=null) {
for(Resource<Sources> source : databaseSources) {
Sources sourceName = source.getName();
sourcesList.add(sourceName.getOrigName().toLowerCase());
}
}
}

@ -9,7 +9,6 @@ import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Iterator;
@ -66,7 +65,7 @@ public abstract class HelperMethods {
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(HelperMethods.class);
private static final String APPLICATION_ID_CATALOGUE_MANAGER = "org.gcube.datacatalogue.ProductCatalogue";
private static final String NOTIFICATION_MESSAGE = "Dear members,<br>The record 'PRODUCT_TITLE' has been just published by USER_FULLNAME.<br>You can find it here: PRODUCT_URL <br>";
private static final String NOTIFICATION_MESSAGE = "Dear members,\nThe record 'PRODUCT_TITLE' has been just published by USER_FULLNAME.\nYou can find it here: PRODUCT_URL\n";
private static final String SOCIAL_SERVICE_APPLICATION_TOKEN = "/2/tokens/generate-application-token/";
private static final String SOCIAL_SERVICE_WRITE_APPLICATION_POST = "/2/posts/write-post-app/";
private static final String MEDIATYPE_JSON = "application/json";
@ -350,26 +349,33 @@ public abstract class HelperMethods {
}
return result;
}
/**
* Strip out HTML code
* @param html
* @return
* @throws UnsupportedEncodingException
*/
public static String removeHTML(String html) {
public static String removeHTML(String html, boolean removeAscii) {
if(html == null || html.isEmpty())
return html;
// remove html and clean
String withoutHTML = Jsoup.parse(html).text();
withoutHTML = Jsoup.clean(withoutHTML, Whitelist.basic());
if(removeAscii) {
// remove non ascii chars ...
withoutHTML = withoutHTML.replaceAll("[^\\p{ASCII}]", " ");
withoutHTML = withoutHTML.replaceAll("[^\\p{ASCII}]", " ");
}
return withoutHTML;
}
/**
* Strip out HTML code
* @param html
* @return
* @throws UnsupportedEncodingException
*/
/*
public static String removeHTML(String html) {
return removeHTML(html, true);
}
*/
/**
* Send notification to vre members about the created product by writing a post.
* @param productName the title of the product

@ -374,7 +374,7 @@ public class JTests {
public void removeHTML() throws Exception{
String toTest = "<p>Based on the results of the MP operation[] asdkljlasdklsa . - * ; for 2015&ndash;17 in its 2013 meeting and the outcome of the review of exceptional circumstances in its 2015 meeting, the ESC recommended that there is no need to revise the Extended Commission&rsquo;s 2013 TAC decision regarding the TAC for 2016&ndash;17. The recommended annual TAC for the years 2016-2017 is 14,647.4t.</p>";
HelperMethods.removeHTML(toTest);
HelperMethods.removeHTML(toTest, false);
}

Loading…
Cancel
Save