18 package org.turro.financials.entity;
20 import java.util.ArrayList;
21 import java.util.List;
23 import java.util.TreeSet;
24 import javax.persistence.*;
25 import org.turro.string.Strings;
26 import org.turro.financials.db.FinancialsPU;
27 import org.turro.jpa.Dao;
28 import org.turro.jpa.entity.IDaoEntity;
29 import org.turro.util.PhraseBuilder;
38 @GeneratedValue(strategy=GenerationType.IDENTITY)
39 @Column(name=
"IDENTIFIER")
42 @Column(name=
"CTCDEF_NAME")
45 private boolean cash, stock, useContractorCode;
48 private String asContact, asCash;
50 @OneToMany(mappedBy =
"contractDefinition", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval=
true)
52 private Set<ContractPreference> contractPreferences =
new TreeSet<ContractPreference>();
54 @OneToMany(mappedBy =
"contractDefinition", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval=
true)
55 @OrderBy(
"documentDefinition")
56 private Set<RelatedDocument> relatedDocuments =
new TreeSet<RelatedDocument>();
58 @OneToMany(mappedBy =
"contractDefinition", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval=
true)
60 private Set<DocumentWorkflow> documentWorkflows =
new TreeSet<DocumentWorkflow>();
75 this.asContact = asContact;
104 if(
id > 0 && dao.
isNotLoaded(contractPreferences)) {
105 contractPreferences = dao.lazyLoader(
ContractDefinition.class,
this,
"contractPreferences").contractPreferences;
107 return contractPreferences;
111 this.contractPreferences = contractPreferences;
117 documentWorkflows = dao.lazyLoader(
ContractDefinition.class,
this,
"documentWorkflows").documentWorkflows;
119 return documentWorkflows;
123 this.documentWorkflows = documentWorkflows;
153 relatedDocuments = dao.lazyLoader(
ContractDefinition.class,
this,
"relatedDocuments").relatedDocuments;
155 return relatedDocuments;
159 this.relatedDocuments = relatedDocuments;
187 return useContractorCode;
191 this.useContractorCode = useContractorCode;
203 return Strings.isBlank(name);
211 if(cp.getName().contentEquals(
"#")) {
223 PhraseBuilder pb =
new PhraseBuilder(name);
245 if(asContact !=
null) {
246 pb.addPendingSeparator(
",");
247 pb.addWord(
"c:" + asContact);
250 pb.addPendingSeparator(
",");
251 pb.addWord(
"d:" + asCash);
254 return pb.toString();
263 "select cdn from ContractDefinitionNotes cdn " +
264 "where cdn.contractDefinition = ?",
265 new Object[] {
this });
271 ArrayList<DocumentDefinition> v =
new ArrayList<DocumentDefinition>();
273 int pos1 = getPosition(v, dw.getAncestor());
274 int pos2 = getPosition(v, dw.getDescendant());
276 v.add(0, dw.getAncestor());
279 if(pos1 + 1 >= v.size()) {
280 v.add(dw.getDescendant());
282 v.add(pos1 + 1, dw.getDescendant());
287 int pos1 = getPosition(v, dw.getAncestor());
288 int pos2 = getPosition(v, dw.getDescendant());
290 v.set(pos1, dw.getDescendant());
291 v.set(pos2, dw.getAncestor());
297 private int getPosition(List<DocumentDefinition> list,
DocumentDefinition documentDefinition) {
301 if(dd.getId() == documentDefinition.
getId()) {
void setCash(boolean cash)
void setUseContractorCode(boolean useContractorCode)
Set< ContractPreference > getContractPreferences()
ContractPreference getDefaultContractPreference()
void setDocumentWorkflows(Set< DocumentWorkflow > documentWorkflows)
void setRelatedDocuments(Set< RelatedDocument > relatedDocuments)
Set< RelatedDocument > getRelatedDocuments()
boolean isUseContractorCode()
void setAsCash(String asCash)
void setAsContact(String asContact)
ContractDefinitionNotes getNotes()
List< DocumentDefinition > getWorkflow()
void setStock(boolean stock)
Set< DocumentWorkflow > getDocumentWorkflows()
void setContractPreferences(Set< ContractPreference > contractPreferences)
void setName(String name)
Object getSingleResultOrNull(SqlClause sc)
boolean isNotLoaded(Object o, String attribute)