BrightSide Workbench Full Report + Source Code
UsualUpdate.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.usual;
19 
20 import java.util.List;
21 import org.turro.financials.db.FinancialsPU;
22 import org.turro.financials.entity.Document;
23 import org.turro.financials.entity.DocumentLine;
24 import org.turro.financials.entity.DocumentRelation;
25 import org.turro.jpa.Dao;
26 import org.turro.usual.IUsualUpdate;
27 import org.turro.usual.UsualUsages;
28 
33 public class UsualUpdate implements IUsualUpdate {
34 
35  @Override
36  public void update() {
37  Dao dao = new FinancialsPU();
38  deleteUsuals();
39  for(Document doc : (List<Document>) dao.getResultList("select doc from Document as doc")) {
40  updateDocument(doc);
41  }
42  }
43 
44  public void deleteUsuals() {
45  UsualUsages.clearUsuals("dc-");
46  }
47 
48  public void updateDocument(Document doc) {
49  for(DocumentLine l : doc.getDocumentLines()) {
50  if(!l.isEmpty() && l.getStore() != null) {
51  UsualUsages.addUsage(doc.getUsualPath() + "st:" + l.getStore().getId());
52  UsualUsages.addUsage(doc.getUsualPath() + "cp:" + l.getConcept());
53  }
54  }
55  for(DocumentRelation dr : doc.getDescendants()) {
56  for(DocumentLine l : dr.getDescendant().getDocumentLines()) {
57  if(!l.isEmpty() && l.getStore() != null) {
58  UsualUsages.addUsage(doc.getUsualPath() + "df:" + l.getDocument().getDocumentDefinition().getId());
59  }
60  }
61  }
62  }
63 
64 }
Set< DocumentRelation > getDescendants()
Definition: Document.java:139
Set< DocumentLine > getDocumentLines()
Definition: Document.java:180
static Usually addUsage(String path)
static void clearUsuals(String path)