BrightSide Workbench Full Report + Source Code
DossierSitemap.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.dossier.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.dossier.db.DossierPU;
27 import org.turro.dossier.entity.Dossier;
28 import org.turro.dossier.entity.DossierType;
29 import org.turro.elephant.context.Application;
30 import org.turro.elephant.context.ElephantContext;
31 import org.turro.elephant.db.WhereClause;
32 import org.turro.elephant.impl.repository.Repository;
33 import org.turro.elephant.impl.repository.RepositoryFile;
34 import org.turro.elephant.sitemap.IElephantSitemap;
35 import org.turro.elephant.sitemap.Sitemaps;
36 import org.turro.file.util.FileAttach;
37 import org.turro.jpa.Dao;
38 import org.turro.jpa.entity.EntityWebUrls;
39 
44 @ElephantSitemap
45 public class DossierSitemap implements IElephantSitemap {
46 
47  @Override
48  public Collection<Sitemaps.SitemapLink> getLinks() {
49  ArrayList<Sitemaps.SitemapLink> list = new ArrayList<>();
50  String path = ElephantContext.getEntityWebContext("/dossier");
51  if(!Strings.isBlank(path)) {
52  // TODO: make the exact selection the context do
53  WhereClause wc = new WhereClause();
54  wc.addClause("select d.id from Dossier as d");
55  wc.addClause("where d.category.knowledgeBase = TRUE");
56  wc.addClause("and d.publishable = TRUE");
57  Dao dao = new DossierPU();
58  for(Long dossierId : (List<Long>) dao.getResultList(wc)) {
59  Dossier dossier = dao.find(Dossier.class, dossierId);
60  String ewu = EntityWebUrls.getUrlFromEntity(dossier);
61  if(!Strings.isBlank(ewu)) {
63  ElephantContext.getRootWebPath() + path + ewu);
64  FileAttach fa = new FileAttach(DossierPU.getObjectPath(dossier));
66  for(RepositoryFile rf : repository.getRepositoryFiles("/", "*.jpg,*.png")) {
67  sml.addImage(rf.getWebPath());
68  }
69  list.add(sml);
70  }
71  }
72  }
73  path = ElephantContext.getEntityWebContext("/project");
74  if(!Strings.isBlank(path)) {
75  // TODO: make the exact selection the context do
76  WhereClause wc = new WhereClause();
77  wc.addClause("select d.id from Dossier as d");
78  wc.addClause("where d.category.ownsProjects = TRUE");
79  wc.addClause("and d.publishable = TRUE");
80  wc.addClause("and d.type = :type");
82  Dao dao = new DossierPU();
83  for(Long dossierId : (List<Long>) dao.getResultList(wc)) {
84  Dossier dossier = dao.find(Dossier.class, dossierId);
85  String ewu = EntityWebUrls.getUrlFromEntity(dossier);
86  if(!Strings.isBlank(ewu)) {
88  ElephantContext.getRootWebPath() + path + ewu);
89  FileAttach fa = new FileAttach(DossierPU.getObjectPath(dossier));
91  for(RepositoryFile rf : repository.getRepositoryFiles("/", "*.jpg,*.png")) {
92  sml.addImage(rf.getWebPath());
93  }
94  list.add(sml);
95  }
96  }
97  }
98  return list;
99  }
100 
101 }
static String getObjectPath(Object object)
Definition: DossierPU.java:66
Collection< Sitemaps.SitemapLink > getLinks()
static String getEntityWebContext(String path)
void addNamedValue(String name, Object value)
Repository getPublishableRepository(IConstructor constructor)
Definition: FileAttach.java:47
static String getUrlFromEntity(Object entity)