BrightSide Workbench Full Report + Source Code
bsfinancials-core/src/main/java/org/turro/financials/model/document/BatchOfWrapper.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.financials.model.document;
19 
20 import java.util.ArrayList;
21 import java.util.HashSet;
22 import java.util.List;
23 import java.util.Set;
24 import org.turro.financials.db.FinancialsPU;
25 import org.turro.financials.entity.BatchOf;
26 import org.turro.financials.entity.Document;
27 import org.turro.financials.entity.DocumentLine;
28 
33 public class BatchOfWrapper {
34 
35  protected BatchOf batchOf;
36 
38  this.batchOf = batchOf;
39  }
40 
41  public BatchOf getBatchOf() {
42  return batchOf;
43  }
44 
45  public void keepRelations(Set<Document> docs) {
46  batchOf.setDocuments(docs);
47  }
48 
49  public boolean save(List<DocumentLine> lines) {
50  if(batchOf.getBatch() != null && !batchOf.getBatch().isEmpty()) {
51  batchOf.setBatch(new DocumentWrapper(batchOf.getBatch()).save(lines, null));
52  ArrayList<Document> al = new ArrayList<Document>();
53  for(Document d : batchOf.getDocuments()) {
54  if(!d.isEmpty()) {
55  // tricky: document lines are passed as to have relations saved
56  al.add(new DocumentWrapper(d).save(
57  new ArrayList(d.getDocumentLines()), null));
58  }
59  }
60  batchOf.setDocuments(new HashSet<Document>(al));
61  batchOf = new FinancialsPU().saveObject(batchOf);
62  }
63  return batchOf.getId() != 0;
64  }
65 
66  public boolean delete() {
68  return true;
69  }
70 }
void setDocuments(Set< Document > documents)
Definition: BatchOf.java:71
void setBatch(Document batch)
Definition: BatchOf.java:63
Set< Document > getDocuments()
Definition: BatchOf.java:67
void deleteObject(Object obj)
Definition: Dao.java:162