19 package org.turro.financials.contract.www;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import org.turro.string.Strings;
24 import org.turro.attach.www.AttachCtrl;
25 import org.turro.auth.Authentication;
26 import org.turro.elephant.context.IConstructor;
27 import org.turro.elephant.db.WhereClause;
28 import org.turro.elephant.impl.repository.Repository;
29 import org.turro.elephant.impl.repository.RepositoryFile;
30 import org.turro.elephant.web.SocialImageMap;
31 import org.turro.elephant.web.SocialNet;
32 import org.turro.file.util.FileAttach;
33 import org.turro.financials.command.ContractPortfolio;
34 import org.turro.financials.db.FinancialsPU;
35 import org.turro.financials.entity.Contract;
36 import org.turro.financials.entity.ContractInterventionType;
37 import org.turro.jpa.iterator.DaoHtmlIterator;
38 import org.turro.mail.recipients.MailContact;
39 import org.turro.marker.ElephantMarker;
48 private String pubPath, actualParameters;
49 private boolean publicOnly, checkParticipation;
54 this.pubPath = pubPath;
55 this.checkParticipation =
true;
63 this.publicOnly = publicOnly;
75 return checkParticipation;
79 this.checkParticipation = checkParticipation;
86 public Collection<Contract>
items() {
93 wc.
addClause(
"select distinct ctc from Contract ctc");
94 if(checkParticipation) {
95 wc.
addClause(
"left join ctc.participants par");
105 wc.
addClause(
"select count(distinct ctc) from Contract ctc");
106 if(checkParticipation) {
107 wc.
addClause(
"left join ctc.participants par");
114 return Strings.isBlank(actualParameters) ?
"?a=b" : actualParameters;
121 prepareValues(e, page,
false);
124 actualParameters = getPageLink(page);
130 prepareValues(e, page,
false);
132 actualParameters = getPageLink(page);
152 if(checkParticipation) {
154 wc.
addClause(
"and (ctc.contractor = :contractor");
157 if(cit.isShowDocuments()) {
158 wc.
addClause(
"or (par.interventionType = :cit" + cit.toString());
160 wc.
addClause(
"and par.idContact = :con" + cit.toString() +
")");
167 wc.
addClause(
"and ctc.contractDefinition.id = :ctcdef");
172 private void prepareValues(Contract contract,
int page,
boolean asMail) {
174 if(asMail && pubPath !=
null) {
175 marker.
put(
"name", MailContact.createLink(contract.getFullDescription(), getItemLink(contract, page),
false));
177 marker.
put(
"name", contract.getFullDescription());
179 if(pubPath !=
null) {
180 marker.
put(
"path", getItemLink(contract, page));
183 if(!Strings.isBlank(pubPath)) {
184 marker.
put(
"readall", getItemLink(contract, page));
187 (contract.isActive() ?
" active" :
"") +
188 (contract.isStock() ?
" store" :
""));
189 marker.
put(
"portfolio",
new ContractPortfolio(contract));
192 ac.setEntityPath(FinancialsPU.getObjectPath(contract));
193 ac.setPublicOnly(publicOnly);
198 private String getItemLink(Contract issue,
int page) {
199 return pubPath +
"?item=" + issue.getId() +
"&page=" + page;
202 private String getPageLink(
int page) {
203 return pubPath +
"?page=" + page;
213 ArrayList<RepositoryFile> files =
new ArrayList<>();
214 String path = getItemLink(e, 0);
static IContact getIContact()
void addClause(String clause)
void addNamedValue(String name, Object value)
Set< RepositoryFile > getRepositoryFiles(String pattern)
static boolean hasImage(String url)
List< String > getMetas()
Repository getPublishableRepository(IConstructor constructor)
void renderSummary(ElephantMarker marker, Contract e, int page)
void setCheckParticipation(boolean checkParticipation)
WhereClause getWhereClause()
Collection< Contract > items()
boolean isCheckParticipation()
Collection< String > metas(Contract e)
void setPublicOnly(boolean publicOnly)
boolean isValid(Contract e)
WhereClause getCountClause()
Contract entity(Long value)
String getActualParameters()
ContractIterator(IConstructor constructor, String pubPath)
void renderItem(ElephantMarker marker, Contract e, int page)
static String getObjectPath(Object object)
Collection< IContact > getIParticipants()
String getFullDescription()
String getSummaryTemplate()
List< E > getTotalItems()
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)