BrightSide Workbench Full Report + Source Code
bsfinancials-www/src/main/java/org/turro/financials/attach/AttachProcessor.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.attach;
19 
20 import org.turro.elephant.impl.util.StringParser;
21 import org.turro.financials.db.FinancialsPU;
22 import org.turro.financials.document.logic.DocumentWrapper;
23 import org.turro.financials.entity.Contract;
24 import org.turro.financials.entity.Document;
25 import org.turro.financials.entity.Product;
26 import org.turro.i18n.I_;
27 import org.turro.plugin.attach.IAttachFolder;
28 import org.turro.plugin.attach.IAttachProcessor;
29 
34 public class AttachProcessor implements IAttachProcessor {
35 
36  @Override
37  public void processFolder(IAttachFolder folder) {
38  IAttachFolder parent = folder.getParentFolder();
39  if("/contract".equals(folder.getFolderPath())) {
40  folder.setFolderLabel(I_.get("Contract"));
41  } else if("/document".equals(folder.getFolderPath())) {
42  folder.setFolderLabel(I_.get("Document"));
43  } else if("/product".equals(folder.getFolderPath())) {
44  folder.setFolderLabel(I_.get("Product"));
45  } else if(parent != null && "/contract".equals(parent.getFolderPath())) {
46  Contract contract = new FinancialsPU().find(Contract.class, Long.valueOf(folder.getFolderLabel()));
47  if(contract != null) {
48  folder.setFolderLabel(contract.getId() + " - " + StringParser.cutString(contract.getFullDescription(), 50));
49  }
50  } else if(parent != null && "/document".equals(parent.getFolderPath())) {
51  Document document = new FinancialsPU().find(Document.class, Long.valueOf(folder.getFolderLabel()));
52  if(document != null) {
53  folder.setFolderLabel(StringParser.cutString(new DocumentWrapper(document).getDocDescription(), 50));
54  }
55  } else if(parent != null && "/product".equals(parent.getFolderPath())) {
56  Product product = new FinancialsPU().find(Product.class, Long.valueOf(folder.getFolderLabel()));
57  if(product != null) {
58  folder.setFolderLabel(product.getProductCodeStr() + " - " + StringParser.cutString(product.getDescription(), 50));
59  }
60  }
61  }
62 
63 }
static String cutString(String value, int maxChars)
static String get(String msg)
Definition: I_.java:41