Commit 0d26b7a2 authored by Matija Obreza's avatar Matija Obreza
Browse files

CRM updates

- Default content in src/main/resources/default-content uses .json extension
- Template articles can only be created in default language first
- Content of default articles updated
- ArticleRepository#onSave will remove template articles from index or reindex them when not templates
parent 8c9e8211
/**
* Copyright 2014 Global Crop Diversity Trust
/*
* Copyright 2017 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -12,7 +12,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
*/
package org.genesys2.server.listener.sample;
......@@ -22,7 +22,11 @@ import java.util.Iterator;
import java.util.Locale;
import java.util.Map.Entry;
import org.apache.commons.io.IOUtils;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.genesys2.server.listener.RunAsAdminListener;
import org.genesys2.server.model.impl.Article;
import org.genesys2.server.service.CRMException;
......@@ -33,10 +37,6 @@ import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* This startup listener enumerates the resources in "default-content" directory
* of this package. Each resource name represents a content slug (URL) of a
......@@ -60,7 +60,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
public class CreateContentListener extends RunAsAdminListener {
@Value("${auto.createContent}")
private final boolean createContent = false;
private boolean createContent = false;
@Autowired
private ContentService contentService;
......@@ -73,42 +73,43 @@ public class CreateContentListener extends RunAsAdminListener {
private void createArticles() throws IOException, JsonProcessingException {
if (!createContent) {
_logger.info("Skipping menu creation on startup.");
_logger.warn("Skipping content creation on startup.");
return;
}
_logger.info("Checking if default content exists");
_logger.debug("Checking if default content exists");
final ClassLoader classLoader = CreateContentListener.class.getClassLoader();
final PathMatchingResourcePatternResolver rpr = new PathMatchingResourcePatternResolver(classLoader);
final String resourcePath = "/default-content/*";
final Resource[] rs = rpr.getResources(resourcePath);
for (final Resource r : rs) {
_logger.info(r.getFilename());
final String slug = r.getFilename();
final String slug = r.getFilename().substring(0, r.getFilename().lastIndexOf(".json"));
_logger.info("Using " + r.getFilename() + " for article slug=" + slug);
final ObjectMapper mapper = new ObjectMapper();
final InputStream stream = r.getInputStream();
final JsonNode json = mapper.readTree(stream);
IOUtils.closeQuietly(stream);
final Iterator<Entry<String, JsonNode>> it = json.fields();
while (it.hasNext()) {
final Entry<String, JsonNode> entry = it.next();
final Locale locale = new Locale(entry.getKey());
// Load from default locale if exists
final Article article = contentService.getGlobalArticle(slug, locale, false);
// If nothing is found, parse the resource and create content
if (article == null) {
try {
contentService.createGlobalArticle(slug, locale, entry.getValue().get("title").asText(), entry.getValue().get("body").asText(), null, false);
_logger.info("Created article for slug: " + slug + " lang=" + locale.getLanguage());
} catch (CRMException e) {
_logger.warn("Failed to create global article slug=" + slug + ".", e);
try (InputStream stream = r.getInputStream()) {
final JsonNode json = mapper.readTree(stream);
final Iterator<Entry<String, JsonNode>> it = json.fields();
while (it.hasNext()) {
final Entry<String, JsonNode> entry = it.next();
final Locale locale = new Locale(entry.getKey());
// Load from default locale if exists
final Article article = contentService.getGlobalArticle(slug, locale, false);
// If nothing is found, parse the resource and create content
if (article == null) {
try {
contentService.createGlobalArticle(slug, locale, entry.getValue().get("title").asText(), entry.getValue().get("body").asText(), null, false);
_logger.info("Created article for slug: " + slug + " lang=" + locale.getLanguage());
} catch (CRMException e) {
_logger.warn("Failed to create global article slug=" + slug + ".", e);
}
}
}
} catch (JsonParseException e) {
_logger.error("Could not create global article " + slug + " from " + r.getFilename() + ". JSON is not valid.");
}
}
}
......@@ -133,13 +134,15 @@ public class CreateContentListener extends RunAsAdminListener {
contentService.ensureMenuItem("about", "/content/about/newsletter", "menu.newsletter");
contentService.ensureMenuItem("about", "/content/about/frequently-asked-questions", "menu.faq");
contentService.ensureMenuItem("about", "/content/help/how-to-use-genesys", "menu.how-to-use-genesys");
// legal
contentService.ensureMenuItem("help", "/content/help/how-to-use-genesys", "menu.how-to-use-genesys");
// contentService.ensureMenuItem("help", "/content/help/about-genesys-data", "menu.about-genesys-data");
// contentService.ensureMenuItem("help", "/content/help/who-uses-genesys", "menu.who-uses-genesys");
// contentService.ensureMenuItem("help", "/content/help/how-to-use-genesys", "menu.how-to-use-genesys");
// contentService.ensureMenuItem("help", "/content/help/about-genesys-data",
// "menu.about-genesys-data");
// contentService.ensureMenuItem("help", "/content/help/who-uses-genesys",
// "menu.who-uses-genesys");
// contentService.ensureMenuItem("help", "/content/help/how-to-use-genesys",
// "menu.how-to-use-genesys");
contentService.ensureMenuItem("help", "/content/about/about", "menu.about");
}
......
......@@ -189,7 +189,7 @@ public class ContentServiceImpl implements ContentService {
if (article == null) {
article = new Article();
Article sourceArticle = getGlobalArticle(slug, locale, true);
if (sourceArticle==null) {
if (sourceArticle == null) {
throw new CRMException("Article " + slug + " must exist in original language!");
}
article.setTemplate(sourceArticle.isTemplate());
......@@ -210,7 +210,7 @@ public class ContentServiceImpl implements ContentService {
* @param body
* @param locale
* @return
* @throws CRMException
* @throws CRMException
*/
@Override
@Transactional(readOnly = false)
......@@ -464,7 +464,7 @@ public class ContentServiceImpl implements ContentService {
return menu;
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasRole('CONTENTMANAGER')")
@Transactional
......@@ -488,17 +488,26 @@ public class ContentServiceImpl implements ContentService {
@Override
@Transactional
public Article createGlobalArticle(String slug, Locale locale, String title, String body, String summary, boolean isTemplate) throws CRMException {
if (! getDefaultLocale().getLanguage().equals(locale.getLanguage())) {
Article primaryArticle = getGlobalArticle(slug, locale, true);
if (primaryArticle == null && !getDefaultLocale().getLanguage().equals(locale.getLanguage())) {
throw new CRMException("Global articles must first be created in primary language=" + getDefaultLocale().getLanguage());
}
Article article=new Article();
article.setTemplate(isTemplate);
article.setLang(locale.getLanguage());
article.setClassPk(ensureClassPK(Article.class));
article.setTargetId(null);
Article article = new Article();
if (primaryArticle == null) {
article.setTemplate(isTemplate);
article.setClassPk(ensureClassPK(Article.class));
article.setTargetId(null);
} else {
article.setTemplate(primaryArticle.isTemplate());
article.setClassPk(primaryArticle.getClassPk());
article.setTargetId(primaryArticle.getTargetId());
}
article.setLang(locale.getLanguage());
updateArticleContent(article, slug, title, body, summary);
return articleRepository.save(article);
}
......
/**
* Copyright 2014 Global Crop Diversity Trust
/*
* Copyright 2017 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -12,7 +12,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
*/
package org.genesys2.server.service.worker;
......@@ -268,7 +268,12 @@ public class ElasticUpdaterAspect {
LOG.trace("Result " + result.getClass());
LOG.trace("Indexing object " + result);
}
elasticUpdater.update(Article.class, ((Article) result).getId());
Article article = (Article) result;
if (!article.isTemplate()) {
elasticUpdater.update(Article.class, article.getId());
} else {
elasticUpdater.remove(Article.class, article.getId());
}
}
return result;
}
......
......@@ -883,3 +883,5 @@ welcome.networks=Networks
geo.country=Country:
article.is.template=Is template:
article.template.false=Article is not a template.
article.template.true=This is a template.
{
"en": {
"title": "About Genesys",
"body": "<p>GENESYS is a global portal to information about Plant Genetic Resources for Food and Agriculture (PGRFA). It is a gateway from which germplasm accessions from genebanks around the world can be easily found and ordered. GENESYS is the result of collaboration between <a href=\"http://www.bioversityinternational.org/\" rel=\"nofollow\">Bioversity International</a> on behalf of System-wide Genetic Resources Programme of the CGIAR*, the <a href=\"http://www.croptrust.org/main/\" rel=\"nofollow\">Global Crop Diversity Trust</a> and the <a href=\"http://www.planttreaty.org/index_en.htm\" rel=\"nofollow\">Secretariat of the International Treaty on the Plant Genetic Resources for Food and Agriculture</a>. By facilitating access to and use of PGRFA, GENESYS helps to secure its long-term conservation.</p>\n\n<h3>Data Providers to GENESYS</h3>\n<p>When it was launched in 2011, GENESYS was a one-stop access point to the information provided by these three important genetic resources communities:</p>\n<ul><li>The <a href=\"http://eurisco.ecpgr.org/\" rel=\"nofollow\">European Plant Genetic Resources Search Catalogue</a></li><li>The <a href=\"http://singer.cgiar.org/\" rel=\"nofollow\">System-wide Information Network for Genetic Resources</a></li><li>The <a href=\"http://www.ars-grin.gov/\" rel=\"nofollow\">Genetic Resources Information Network of the United States Department of Agriculture</a></li></ul>\n<p>That means it provided access to about one third of the accessions estimated to be held worldwide. However, its coverage will continue to increase over time. All genebanks are welcome to provide data to GENESYS.</p>\n\n<h3>The Data in GENESYS</h3>\n<p>At the launch, in addition to passport data, GENESYS provided access to over 11 million records of characterisation and evaluation data. GENESYS also provides access to millions of records of environmental information associated with accession collecting sites. Its unlimited data capacity allows it to incorporate relevant data from data providers worldwide.\nResearchers, breeders or indeed farmers seeking specific genetic variation can use GENESYS to select, for example, Triticum aestivum accessions with brown kernels collected in Turkey where the annual precipitation is between 150 and 350 mm. They can quickly do so with only about six keystrokes and 12 clicks of the mouse. The accessions meeting the query can then be requested directly from the holding genebank(s).\nTo become a GENESYS data provider, please indicate your interest in doing so and request a copy of the GENESYS Data Sharing Agreement (DSA) from the <a href=\"mailto:genesys-helpdesk&#64;cgiar.org\" rel=\"nofollow\">GENESYS Helpdesk</a>. The GENESYS team will help you load legacy data and provide the utilities for future additions and updates.</p>\n\n<h3>The Future</h3>\n<p>Development of the GENESYS portal is ongoing. Future goals include adding information from many more data providers, enhancing functionality with pedigree management, and expanding the environmental data available all things that our stakeholders have already identified. The user of the information in GENESYS is the most crucial contributor to the future development of the system. Please use the Comments and Feedback link at the bottom of the main window (or click this link to guide the future development of the portal.</p>\n<br />\n* <i>Consultative Group on International Agricultural Research</i>"
}
}
\ No newline at end of file
{
"en": {
"title": "About Genesys",
"body": "<p>Genesys is a global portal to information about Plant Genetic Resources for Food and Agriculture (PGRFA). It is a gateway from which germplasm accessions from genebanks around the world can be easily found and ordered. Genesys is the result of collaboration between <a href=\"http://www.bioversityinternational.org/\" rel=\"nofollow\">Bioversity International</a> on behalf of System-wide Genetic Resources Programme of the CGIAR (<em>Consultative Group on International Agricultural Research)</em>, the <a href=\"https://www.croptrust.org\" rel=\"nofollow\">Global Crop Diversity Trust</a> and the <a href=\"http://www.planttreaty.org/\" rel=\"nofollow\">Secretariat of the International Treaty on the Plant Genetic Resources for Food and Agriculture</a>. By facilitating access to and use of PGRFA, Genesys helps to secure its long-term conservation.</p><h3>Data Providers to Genesys</h3><p>When it was launched in 2011, Genesys was a one-stop access point to the information provided by these three important genetic resources communities:</p><ul><li>The <a href=\"http://eurisco.ecpgr.org/\" target=\"_blank\" rel=\"nofollow\">European Plant Genetic Resources Search Catalogue</a>&nbsp;(EURISCO)</li><li>The System-wide Information Network for Genetic Resources (SINGER)</li><li>The <a href=\"https://www.ars-grin.gov/\" target=\"_blank\" rel=\"nofollow\">Genetic Resources Information Network of the United States Department of Agriculture</a>&nbsp;(GRIN)</li></ul><p>That means it provided access to about one third of the accessions estimated to be held worldwide. However, its coverage will continue to increase over time. All genebanks are welcome to provide data to Genesys.</p><h3>The Data in Genesys</h3><p>At the launch, in addition to passport data, Genesys provided access to over 11 million records of characterisation and evaluation data. Genesys also provides access to millions of records of environmental information associated with accession collecting sites. Its unlimited data capacity allows it to incorporate relevant data from data providers worldwide. Researchers, breeders or indeed farmers seeking specific genetic variation can use Genesys to select, for example, <em>Triticum aestivum</em> accessions with brown kernels collected in Turkey where the annual precipitation is between 150 and 350 mm. They can quickly do so with only about six keystrokes and 12 clicks of the mouse. The accessions meeting the query can then be requested directly from the holding genebank(s). To become a Genesys data provider, please indicate your interest in doing so and request a copy of the Genesys Data Sharing Agreement (DSA) from the <a href=\"mailto:helpdesk@genesys-pgr.org\" rel=\"nofollow\">Genesys helpdesk</a>. The Genesys team will help you load legacy data and provide the utilities for future additions and updates.</p><h3>The Future</h3><p>Development of the Genesys portal is ongoing. Future goals include adding information from many more data providers, enhancing functionality with pedigree management, and expanding the environmental data available all things that our stakeholders have already identified. The user of the information in Genesys is the most crucial contributor to the future development of the system. Please use the Comments and Feedback link at the bottom of the main window (or click this link to guide the future development of the portal.</p>"
}
}
{
"en": {
"title": "Cookies on the Genesys website",
"body": "<p>Cookies allow us to provide you a personalized experience of the portal. Read more about use of cookies in <a href="/content/privacy">our Privacy policy</a>.</p>"
"body": "<p>Cookies allow us to provide you a personalized experience of the portal. Read more about use of cookies in <a href=\"/content/privacy\">our Privacy policy</a>.</p>"
}
}
\ No newline at end of file
{
"en": {
"title": "Disclaimer",
"body": "<p>The data providers to GENESYS independently manage the information stored in, or made accessible to GENESYS.</p>\n<p>Users must contact the specific data providing institute(s) directly, with any questions or comments regarding information stored in GENESYS and for queries regarding the germplasm held in a specific institute(s). The contact person for each institute can be found here by using the FAO Institute Code that accompanies every accession.</p>\n<p>The responsibility of managing requests created using the GENESYS requesting module remains with the individual institiute(s) to where the request is directed. Therefore, GENESYS and Global Crop Diversity Trust, as GENESYS’ legal host entity, will not be held responsible for any errors or negligence in handling the request, or for the inability to fulfill any request. Once a request is completed via the online requesting module, the party requesting the germplasm will be sent a summary of the request specifying the institute(s) which will be processing the request, corresponding contact details, a copy this Disclaimer and the GENESYS Terms and Conditions of Use. Possible claims and complaints related to germplasm requests must be addressed to the specific institute(s) concerned, and not to GENESYS.</p>\n<p>Should the internet service providers, or the facilities associated with the GENESYS requesting module fail, due to causes beyond the control of GENESYS or Crop Trust, neither GENESYS nor Crop Trust will be held responsible for any delays in transmission, delivery, or fulfillment of requests due to these failures.</p>"
}
}
{
"en": {
"title": "Disclaimer",
"body": "<p>The data providers to Genesys independently manage the information stored in, or made accessible to Genesys. Users should contact the specific data providing institute(s) directly with any questions or comments regarding this information or the associated germplasm.</p><p>The responsibility of managing requests created using the Genesys requesting module remains with the individual institiute(s) to where the request is directed. Therefore, Genesys and Gobal Crop Diversity Trust, as Genesys&rsquo; legal host entity, will not be held responsible for any errors or negligence in handling the request, or for the inability to fulfill any request. Once a request is completed via the online requesting module, the party requesting the germplasm will be sent a summary of the request specifying the institute(s) which will be processing the request, corresponding contact details, a copy this Disclaimer and the Genesys Terms and Conditions of Use. Possible claims and complaints related to germplasm requests must be addressed to the specific institute(s) concerned, and not to Genesys.</p><p>Should the internet service providers, or the facilities associated with the Genesys requesting module fail, due to causes beyond the control of Genesys or Gobal Crop Diversity Trust, neither Genesys nor Gobal Crop Diversity Trust will be held responsible for any delays in transmission, delivery, or fulfillment of requests due to these failures.</p>"
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment