BrightSide Workbench Full Report + Source Code
PublicationSitemap.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2018 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.publication.util;
20 
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.List;
24 import org.turro.string.Strings;
25 import org.turro.annotation.ElephantSitemap;
26 import org.turro.elephant.context.Application;
27 import org.turro.elephant.context.ElephantContext;
28 import org.turro.elephant.db.WhereClause;
29 import org.turro.elephant.impl.repository.Repository;
30 import org.turro.elephant.impl.repository.RepositoryFile;
31 import org.turro.elephant.sitemap.IElephantSitemap;
32 import org.turro.elephant.sitemap.Sitemaps;
33 import org.turro.file.util.FileAttach;
34 import org.turro.jpa.Dao;
35 import org.turro.jpa.entity.EntityWebUrls;
36 import org.turro.publication.db.PublicationPU;
37 import org.turro.publication.entity.Publication;
38 
43 @ElephantSitemap
44 public class PublicationSitemap implements IElephantSitemap {
45 
46  @Override
47  public Collection<Sitemaps.SitemapLink> getLinks() {
48  ArrayList<Sitemaps.SitemapLink> list = new ArrayList<>();
49  String path = ElephantContext.getEntityWebContext("/publication");
50  if(!Strings.isBlank(path)) {
51  // TODO: make the exact selection the context do
52  WhereClause wc = new WhereClause();
53  wc.addClause("select p.id from Publication as p");
54  wc.addClause("where p.publicationGroup.publishable = TRUE");
55  wc.addClause("and p.publicationCategory.publishable = TRUE");
56  Dao dao = new PublicationPU();
57  for(Long pubId : (List<Long>) dao.getResultList(wc)) {
58  Publication pub = dao.find(Publication.class, pubId);
59  String ewu = EntityWebUrls.getUrlFromEntity(pub);
60  if(!Strings.isBlank(ewu)) {
62  ElephantContext.getRootWebPath() + path + ewu);
65  for(RepositoryFile rf : repository.getRepositoryFiles("/topmost", "*.jpg,*.png")) {
66  sml.addImage(rf.getWebPath());
67  }
68  for(RepositoryFile rf : repository.getRepositoryFiles("/priorized", "*.jpg,*.png")) {
69  sml.addImage(rf.getWebPath());
70  }
71  for(RepositoryFile rf : repository.getRepositoryFiles("/included", "*.jpg,*.png")) {
72  sml.addImage(rf.getWebPath());
73  }
74  list.add(sml);
75  }
76  }
77  }
78  return list;
79  }
80 
81 }
static String getEntityWebContext(String path)
Repository getPublishableRepository(IConstructor constructor)
Definition: FileAttach.java:47
static String getUrlFromEntity(Object entity)
static String getObjectPath(Object object)
Collection< Sitemaps.SitemapLink > getLinks()