Commit ca00923b authored by Matija Obreza's avatar Matija Obreza

Updated sitemap frequency and page priority

- Introduced SitemapXMLController.Frequency enum
parent 9973512e
......@@ -74,6 +74,15 @@ public class SitemapXMLController {
private static final Logger LOG = LoggerFactory.getLogger(SitemapXMLController.class);
public static enum Frequency {
YEARLY,
MONTHLY,
WEEKLY,
DAILY,
HOURLY,
ALWAYS
}
@Value("${frontend.url}")
private String frontendUrl;
......@@ -109,7 +118,7 @@ public class SitemapXMLController {
private static class SitemapPage {
String url;
String freq = "always";
Frequency freq = Frequency.MONTHLY;
Double priority;
public SitemapPage(String url) {
......@@ -121,7 +130,7 @@ public class SitemapXMLController {
this.priority = priority;
}
public SitemapPage(String url, String changeFrequency, double priority) {
public SitemapPage(String url, Frequency changeFrequency, double priority) {
this.url = url;
this.freq = changeFrequency;
this.priority = priority;
......@@ -141,12 +150,12 @@ public class SitemapXMLController {
};
private final SitemapPage[] sitemapContentPages = new SitemapPage[] {
new SitemapPage("/", 1.0),
new SitemapPage("/content/about/about", "monthly", 0.2),
new SitemapPage("/", Frequency.WEEKLY, 1.0),
new SitemapPage("/content/about/about", 0.2),
new SitemapPage("/content/legal/terms", 1.0),
new SitemapPage("/content/legal/disclaimer", 1.0),
new SitemapPage("/documentation/apis", 1.0),
new SitemapPage("/documentation/brapi", 1.0)
new SitemapPage("/content/legal/disclaimer", 0.6),
new SitemapPage("/documentation/apis", 0.7),
new SitemapPage("/documentation/brapi", 0.7)
};
@RequestMapping(value = "/sitemap.xml", method = RequestMethod.GET, produces = { MediaType.TEXT_XML_VALUE })
......@@ -174,8 +183,8 @@ public class SitemapXMLController {
List<ActivityPost> activityPosts = contentService.allNews(new PageRequest(0, Integer.MAX_VALUE, Sort.Direction.DESC, "postDate")).getContent();
for (ActivityPost ap : activityPosts) {
String title = jspHelper.suggestUrlForText(ap.getTitle());
SitemapPage sm = new SitemapPage("/content/news/" + ap.getId() + "/" + title);
String slug = jspHelper.suggestUrlForText(ap.getTitle());
SitemapPage sm = new SitemapPage("/content/news/" + ap.getId() + "/" + slug);
list.add(sm);
}
......@@ -210,7 +219,7 @@ public class SitemapXMLController {
List<Partner> partners = partnerService.listPartners(new PartnerFilter(), new PageRequest(0, Integer.MAX_VALUE, Sort.Direction.ASC, "id")).getContent();
for (Partner partner : partners) {
writePage(response, sb, "/partners/" + partner.getUuid(), null, null);
writePage(response, sb, "/partners/" + partner.getUuid(), Frequency.MONTHLY, 0.8);
}
sb.append("</urlset>");
......@@ -228,7 +237,7 @@ public class SitemapXMLController {
List<Subset> subsets = subsetService.list(new SubsetFilter(), new PageRequest(0, Integer.MAX_VALUE, Sort.Direction.ASC, "id")).getContent();
for (Subset subset : subsets) {
writePage(response, sb, "/subsets/" + subset.getUuid(), null, null);
writePage(response, sb, "/subsets/" + subset.getUuid(), Frequency.MONTHLY, 0.4);
}
sb.append("</urlset>");
......@@ -246,7 +255,7 @@ public class SitemapXMLController {
List<Dataset> datasets = datasetService.listDatasets(new DatasetFilter(), new PageRequest(0, Integer.MAX_VALUE, Sort.Direction.ASC, "id")).getContent();
for (Dataset dataset : datasets) {
writePage(response, sb, "/datasets/" + dataset.getUuid(), null, null);
writePage(response, sb, "/datasets/" + dataset.getUuid(), Frequency.MONTHLY, 0.4);
}
sb.append("</urlset>");
......@@ -264,7 +273,7 @@ public class SitemapXMLController {
List<DescriptorList> descriptorLists = descriptorListService.listDescriptorLists(new DescriptorListFilter(), new PageRequest(0, Integer.MAX_VALUE, Sort.Direction.ASC, "id")).getContent();
for (DescriptorList descriptorList : descriptorLists) {
writePage(response, sb, "/descriptorlists/" + descriptorList.getUuid(), null, null);
writePage(response, sb, "/descriptorlists/" + descriptorList.getUuid(), Frequency.MONTHLY, 0.3);
}
sb.append("</urlset>");
......@@ -303,7 +312,7 @@ public class SitemapXMLController {
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
sb.append("<urlset xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\" xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">");
writePage(response, sb, "/wiews/" + faoInstitute.getCode(), null, null);
writePage(response, sb, "/wiews/" + faoInstitute.getCode(), Frequency.MONTHLY, 0.3);
// Create JSON filter
AccessionFilter instituteFilter = new AccessionFilter();
......@@ -313,9 +322,9 @@ public class SitemapXMLController {
accessionProcessor.process(instituteFilter, (accessions) -> {
for (Accession accession: accessions) {
if (accession.getDoi() != null) {
writePage(response, sb, "/" + accession.getDoi(), null, null);
writePage(response, sb, "/" + accession.getDoi(), Frequency.MONTHLY, 0.2);
} else {
writePage(response, sb, "/a/" + accession.getUuid(), null, null);
writePage(response, sb, "/a/" + accession.getUuid(), Frequency.MONTHLY, 0.2);
}
}
sb.flush();
......@@ -340,7 +349,7 @@ public class SitemapXMLController {
sb.append("<urlset xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\" xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">");
for (Crop crop : cropService.listCrops()) {
writePage(response, sb, "/c/" + crop.getShortName(), null, null);
writePage(response, sb, "/c/" + crop.getShortName(), Frequency.WEEKLY, 0.6);
}
sb.append("</urlset>");
......@@ -360,11 +369,11 @@ public class SitemapXMLController {
return sb.toString();
}
private void writePage(HttpServletResponse response, final StringBuffer sb, final String url, final String frequency, final Double priority) {
private void writePage(HttpServletResponse response, final StringBuffer sb, final String url, final Frequency frequency, final Double priority) {
sb.append(" <url>");
sb.append(" <loc>").append(frontendUrl).append(response.encodeURL(url)).append("</loc>");
if (frequency != null) {
sb.append(" <changefreq>").append(frequency).append("</changefreq>");
sb.append(" <changefreq>").append(frequency.toString().toLowerCase()).append("</changefreq>");
}
if (priority != null) {
sb.append(" <priority>").append(priority).append("</priority>");
......@@ -372,11 +381,11 @@ public class SitemapXMLController {
sb.append(" </url>");
}
private void writePage(HttpServletResponse response, final Writer sb, final String url, final String frequency, final Double priority) throws IOException {
private void writePage(HttpServletResponse response, final Writer sb, final String url, final Frequency frequency, final Double priority) throws IOException {
sb.append(" <url>");
sb.append(" <loc>").append(frontendUrl).append(response.encodeURL(url)).append("</loc>");
if (frequency != null) {
sb.append(" <changefreq>").append(frequency).append("</changefreq>");
sb.append(" <changefreq>").append(frequency.toString().toLowerCase()).append("</changefreq>");
}
if (priority != null) {
sb.append(" <priority>").append(priority.toString()).append("</priority>");
......
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