19 package org.turro.publication.www;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import org.turro.string.Strings;
24 import org.turro.auth.Authentication;
25 import org.turro.commentit.CommentItUtil;
26 import org.turro.elephant.context.ElephantContext;
27 import org.turro.elephant.context.IConstructor;
28 import org.turro.elephant.db.WhereClause;
29 import org.turro.elephant.impl.navigation.DefaultNavigatorItem;
30 import org.turro.elephant.impl.repository.RepositoryFile;
31 import org.turro.elephant.web.SocialImageMap;
32 import org.turro.elephant.web.SocialNet;
33 import org.turro.file.util.FileAttach;
34 import org.turro.jpa.entity.EntityWebUrls;
35 import org.turro.jpa.iterator.DaoHtmlIterator;
36 import org.turro.jpa.search.DaoHtmlSearch;
37 import org.turro.jpa.search.DaoSearchKey;
38 import org.turro.mail.recipients.MailContact;
39 import org.turro.marker.ElephantMarker;
40 import org.turro.plugin.contacts.IContact;
41 import org.turro.plugin.contacts.SoftContact;
42 import org.turro.polls.PollsCtrl;
43 import org.turro.publication.db.PublicationPU;
44 import org.turro.publication.entity.Publication;
45 import org.turro.publication.entity.PublicationCategory;
46 import org.turro.tags.TagCloud;
47 import org.turro.www.commentit.CommentItCtrl;
48 import org.turro.www.starit.StarItCtrl;
56 private String pubPath, contactId, actualParameters, uniqueId, lang;
57 private long groupId, categoryId;
59 private boolean blogger;
63 this.pubPath = pubPath;
64 this.uniqueId = uniqueId;
68 this.contactId = contactId;
72 this.groupId = groupId;
76 this.categoryId = categoryId;
84 return categoryFilter;
88 this.categoryFilter = categoryFilter;
96 this.blogger = blogger;
100 if(categoryFilter !=
null) {
107 if(categoryFilter !=
null) {
119 ArrayList<RepositoryFile> files =
new ArrayList<>();
120 String path = getItemLink(e, 0);
135 wc.
addClause(
"select distinct p from Publication as p");
144 wc.
addClause(
"select count(p) from Publication as p");
150 return Strings.isBlank(actualParameters) ?
"?a=b" : actualParameters;
160 prepareValues(e, page,
false);
163 actualParameters = getPageLink(page);
173 prepareValues(e, page,
false);
176 actualParameters = getPageLink(page);
181 return "publication";
192 if(identifier ==
null) {
193 identifier = super.getIdentifier();
200 wc.
addClause(
"where p.accepted = false");
202 if(contact !=
null && contact.
isWebUser()) {
204 wc.
addClause(
"select ps from PublicationBlogger ps");
205 wc.
addClause(
"where ps.publicationCategory = p.publicationCategory");
206 wc.
addClause(
"and ps.idContact = :blogger");
207 wc.
addClause(
"and ps.administrator = TRUE");
208 wc.
addClause(
") or ( p.idContact = :blogger and exists (");
209 wc.
addClause(
"select ps from PublicationBlogger ps");
210 wc.
addClause(
"where ps.publicationCategory = p.publicationCategory");
211 wc.
addClause(
"and ps.idContact = p.idContact");
212 wc.
addClause(
"and ps.administrator = FALSE");
222 DaoHtmlSearch dhs = DaoHtmlSearch.getInstance(
constructor, ElephantContext.getContextVariable(
constructor));
224 DaoSearchKey dsk = dhs.get(
"search-value");
226 String searchValue = dsk.getValue();
227 if(!Strings.isBlank(searchValue)) {
228 wc.
addClause(
"and (p.title like :search01");
230 wc.
addClause(
"or p.summary like :search02)");
237 wc.
addClause(
"and p.publicationGroup.id = :group");
240 wc.
addClause(
"and p.publicationGroup.publishable = TRUE");
242 if(categoryId != 0) {
243 wc.
addClause(
"and p.publicationCategory.id = :category");
245 }
else if(!blogger) {
246 wc.
addClause(
"and p.publicationCategory.publishable = TRUE");
248 if(!Strings.isBlank(contactId)) {
249 wc.
addClause(
"and p.idContact = :idContact");
252 if(!Strings.isBlank(lang)) {
253 wc.
addClause(
"and (p.lang is null or p.lang = :lang)");
256 PublicationCategory pc = CategoryFilter.getCategory(
constructor, uniqueId);
258 wc.
addClause(
"and p.publicationCategory = :selectedCat");
261 if(TagCloud.hasSelected(
constructor,
"publication")) {
262 wc.
addIn(
"and",
"p.id", TagCloud.getIdentifiersAsLong(
constructor,
"publication"));
266 private void prepareValues(Publication pub,
int page,
boolean asMail) {
270 if(asMail && pubPath !=
null) {
271 marker.
put(
"title", MailContact.createLink(pub.getTitle(), getItemLink(pub, page),
false));
273 if(pubPath !=
null) {
274 marker.
put(
"path", getItemLink(pub, page));
280 if(pub.getPublicationGroup().isSomeDetailToShow()) {
281 if(pub.getPublicationGroup().isAllowComments() && pub.getId() !=
null) {
282 IContact contact = Authentication.getIContact();
283 SoftContact scontact =
new SoftContact();
284 scontact.contact = contact;
286 marker.
put(
"comments", CommentItUtil.count(pub, scontact) +
"");
290 if(pub.getPublicationGroup().isAllowInterest()) {
292 sic.setEntityPath(PublicationPU.getObjectPath(pub));
295 if(pub.getPublicationGroup().isAllowComments()) {
296 CommentItCtrl cic =
new CommentItCtrl(
constructor);
297 cic.setEntityPath(PublicationPU.getObjectPath(pub));
301 pollc.setEntityPath(PublicationPU.getObjectPath(pub));
304 marker.
put(
"readall", getItemLink(pub, page));
306 marker.
put(
"files",
new FileAttach(PublicationPU.getObjectPath(pub)));
310 private String getItemLink(Publication pub,
int page) {
311 String ewu = EntityWebUrls.getUrlFromEntity(pub);
313 return pubPath + ewu;
315 return pubPath +
"?item=" + pub.getId();
319 private String getPageLink(
int page) {
320 return pubPath +
"?page=" + page;
static IContact getIContact()
void addClause(String clause)
void addIn(String operator, String field, List values)
void addNamedValue(String name, Object value)
Set< RepositoryFile > getRepositoryFiles(String pattern)
static boolean hasImage(String url)
List< String > getMetas()
Repository getPublishableRepository(IConstructor constructor)
ID getIDFromURL(String root)
String getSummaryTemplate()
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)
static String getObjectPath(Object object)
static boolean isAnyBlogger(IContact contact)
void updateReadings(Dao dao)
Collection< DefaultNavigatorItem > pubCategories(String parameters, long groupId)
void renderCategories(String parameters, long groupId)
void setLang(String lang)
Collection< String > metas(Publication e)
void renderItem(ElephantMarker marker, Publication e, int page)
String getActualParameters()
void setContactId(String contactId)
PublicationIterator(IConstructor constructor, String pubPath, String uniqueId)
WhereClause getWhereClause()
Collection< DefaultNavigatorItem > pubCategories()
String title(Publication e)
void renderSummary(ElephantMarker marker, Publication e, int page)
CategoryFilter getCategoryFilter()
Publication entity(Long value)
WhereClause getCountClause()
void setCategoryId(long categoryId)
void setBlogger(boolean blogger)
void setCategoryFilter(CategoryFilter categoryFilter)
void setGroupId(long groupId)
HttpServletRequest getRequest()