19 package org.turro.publication.util;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.Date;
25 import java.util.List;
26 import org.turro.string.Strings;
27 import org.turro.action.Contacts;
28 import org.turro.action.queue.ConstraintKeys;
29 import org.turro.elephant.db.WhereClause;
30 import org.turro.mail.queue.QueueManager;
31 import org.turro.plugin.contacts.IContact;
32 import org.turro.publication.db.PublicationPU;
33 import org.turro.publication.entity.Publication;
34 import org.turro.publication.entity.PublicationCategory;
35 import org.turro.publication.entity.PublicationGroup;
36 import org.turro.sql.SqlClause;
45 String idContact,
boolean accepted) {
50 IContact contact,
boolean accepted) {
55 String idContact,
boolean accepted, String extraSql) {
60 IContact contact,
boolean accepted, String extraSql) {
61 return SqlClause.select(
"publication").from(
"Publication publication")
62 .where().equal(
"accepted", accepted)
64 .and().equal(
"publication.publicationGroup.id", group)
66 .startIf(category != 0)
67 .and().equal(
"publication.publicationCategory.id", category)
69 .startIf(category == 0 || group == 0)
70 .and().isTrue(
"publication.publicationGroup.publishable")
72 .startIf(contact !=
null && contact.
isWebUser())
73 .and().equal(
"publication.idContact", contact.
getId())
75 .startIf(!Strings.isBlank(extraSql))
78 .orderBy(
"publication.date DESC")
137 return SqlClause.select(
"c").from(
"PublicationCategory c")
138 .where().isTrue(
"c.publishable")
143 if(contact !=
null && contact.
isWebUser()) {
144 return pc.strongBond(ConstraintKeys.from(contact));
146 return !pc.isRestricted();
156 ArrayList<PublicationCategory> list =
new ArrayList<>();
167 return SqlClause.select(
"c").from(
"PublicationCategory c")
168 .where().isFalse(
"c.publishable")
174 if(contact !=
null && contact.
isWebUser()) {
176 wc.
addClause(
"select b.publicationCategory from PublicationBlogger b");
177 wc.
addClause(
"where b.idContact = :idContact");
179 wc.
addClause(
"and b.publicationCategory.publishable = FALSE");
182 return Collections.EMPTY_LIST;
188 wc.
addClause(
"select publication from Publication publication");
189 wc.
addClause(
"where publication.sent = FALSE");
190 wc.
addClause(
"and publication.accepted = TRUE");
191 wc.
addClause(
"and (retainTill is null or retainTill <= :now)");
193 if(categoryID != 0) {
194 wc.
addClause(
"and publication.publicationCategory.id = :category");
197 wc.
addClause(
"order by publication.date DESC");
204 wc.
addClause(
"update Publication publication");
205 wc.
addClause(
"set publication.sent = TRUE");
206 wc.
addClause(
"where publication.accepted = TRUE");
207 wc.
addClause(
"and (publication.retainTill is null or publication.retainTill <= :now)");
209 if(categoryID != 0) {
210 wc.
addClause(
"and publication.publicationCategory.id = :category");
219 "select pc from PublicationCategory pc order by name");
224 "select pg from PublicationGroup pg order by name");
static ConstraintKeys from(IContact contact)
void addClause(String clause)
void addNamedValue(String name, Object value)
int executeUpdate(String query)
boolean contactWants(IContact contact, String idCategory)
static List< Publication > getPublicationsBy(int max, long group, long category, IContact contact, boolean accepted, String extraSql)
static Collection< PublicationCategory > getPublicCategories()
static List< Publication > getPublicationsBy(int max, long group, long category, IContact contact, boolean accepted)
static void markAsSentPublications(long categoryID)
static List< PublicationCategory > getPublicationCategories()
static List< Publication > getNotSentPublications(long categoryID)
static List< Publication > getPublicationsBy(int max, long group, long category, String idContact, boolean accepted, String extraSql)
static List< PublicationGroup > getPublicationGroups()
static Collection< PublicationCategory > getPublicCategories(String idContact)
static Collection< PublicationCategory > getPublicCategories(IContact contact)
static List< Publication > getPublicationsBy(int max, long group, long category, String idContact, boolean accepted)
static Collection< PublicationCategory > getSubscribedPrivateCategories(IContact contact)
static Collection< PublicationCategory > getPrivateCategories()
static Collection< PublicationCategory > getSubscribedPrivateCategories(String idContact)
static Collection<? extends PublicationCategory > getPrivateBloggerCategories(IContact contact)
static String convertId(PublicationCategory category)