BrightSide Workbench Full Report + Source Code
org.turro.financials.handshake.HandshakeDocument Class Reference
Collaboration diagram for org.turro.financials.handshake.HandshakeDocument:

Public Member Functions

int hashCode ()
 
boolean equals (Object obj)
 
Iterable< HandshakeProductgetProducts ()
 

Static Public Member Functions

static String createJsonFromDocument (Document document)
 
static HandshakeDocument createHandshakeFromDocument (Document document)
 
static HandshakeDocument createHandshakeFromJson (String value)
 
static HandshakeDocument createHandshakeFromFile (File file)
 
static void saveHandshakeToFile (File file, HandshakeDocument hd)
 
static Document getDocumentFromHandshake (Contract contract, HandshakeDocument hd)
 
static void saveHandshakeDocument (HandshakeDocument hd)
 
static boolean existsHandshake (HandshakeDocument hd)
 

Public Attributes

HandshakeContract contract
 
String documentName
 
String documentNumber
 
Date documentDate
 
long definitionId
 
List< HandshakeDocLinelines = new ArrayList<>()
 
List< HandshakeDocumentexpiries = new ArrayList<>()
 

Static Public Attributes

static final String HANDSHAKE_FOLDER = "/WEB-INF/handshake/document"
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 49 of file HandshakeDocument.java.

Member Function Documentation

◆ createHandshakeFromDocument()

static HandshakeDocument org.turro.financials.handshake.HandshakeDocument.createHandshakeFromDocument ( Document  document)
static

Definition at line 71 of file HandshakeDocument.java.

71  {
72  Company company = CompanyWrapper.getDefaultCompany();
73  if(company != null) {
74  HandshakeDocument hd = new HandshakeDocument();
75  hd.contract = HandshakeContract.createHandshakeFromContract(document.getContract());
76  hd.documentName = document.getDocumentDefinition().getName();
77  hd.documentNumber = document.getDocumentNumber();
78  hd.documentDate = document.getDocumentDate();
79  hd.definitionId = mapDocumentDefinition(document);
80  for(DocumentLine dl : document.getDocumentLines()) {
81  if(!dl.isEmpty()) {
82  HandshakeDocLine hdl = new HandshakeDocLine();
83  hdl.concept = dl.getConcept();
84  hdl.discountMoney = dl.getDiscountMoney();
85  hdl.discountPerCent = dl.getDiscountPerCent();
86  hdl.equivalenceSurcharge = dl.getEquivalenceSurcharge();
87  hdl.price = dl.getPrice();
88  if(dl.getProduct() != null) {
89  hdl.product = HandshakeProduct.createHandshakeFromProduct(dl.getProduct());
90  }
91  hdl.quantity = dl.getQuantity();
92  hdl.retention = dl.getRetention();
93  hdl.tax = dl.getTax();
94  hd.lines.add(hdl);
95  }
96  }
97  for(DocumentRelation dr : document.getDescendants()) {
98  Document doc = dr.getDescendant();
99  if(!doc.isEmpty()) {
100  hd.expiries.add(createHandshakeFromDocument(doc));
101  }
102  }
103  return hd;
104  }
105  return null;
106  }
static HandshakeDocument createHandshakeFromDocument(Document document)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ createHandshakeFromFile()

static HandshakeDocument org.turro.financials.handshake.HandshakeDocument.createHandshakeFromFile ( File  file)
static

Definition at line 113 of file HandshakeDocument.java.

113  {
114  try {
115  return createHandshakeFromJson(FileUtil.getContent(file));
116  } catch (IOException ex) {
117  Logger.getLogger(HandshakeDocument.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
118  }
119  return null;
120  }
static HandshakeDocument createHandshakeFromJson(String value)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ createHandshakeFromJson()

static HandshakeDocument org.turro.financials.handshake.HandshakeDocument.createHandshakeFromJson ( String  value)
static

Definition at line 108 of file HandshakeDocument.java.

108  {
109  Gson gson = new GsonBuilder().setDateFormat("yyyy/MM/dd").create();
110  return gson.fromJson(value, HandshakeDocument.class);
111  }
Here is the caller graph for this function:

◆ createJsonFromDocument()

static String org.turro.financials.handshake.HandshakeDocument.createJsonFromDocument ( Document  document)
static

Definition at line 62 of file HandshakeDocument.java.

62  {
63  Gson gson = new GsonBuilder().setDateFormat("yyyy/MM/dd").create();
64  HandshakeDocument hd = createHandshakeFromDocument(document);
65  if(hd != null) {
66  return gson.toJson(hd);
67  }
68  return null;
69  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ equals()

boolean org.turro.financials.handshake.HandshakeDocument.equals ( Object  obj)

Definition at line 188 of file HandshakeDocument.java.

188  {
189  if (obj == null) {
190  return false;
191  }
192  if (getClass() != obj.getClass()) {
193  return false;
194  }
195  final HandshakeDocument other = (HandshakeDocument) obj;
196  if (!Objects.equals(this.contract, other.contract)) {
197  return false;
198  }
199  if (!Objects.equals(this.documentNumber, other.documentNumber)) {
200  return false;
201  }
202  if (!Objects.equals(this.documentDate, other.documentDate)) {
203  return false;
204  }
205  return true;
206  }
Here is the caller graph for this function:

◆ existsHandshake()

static boolean org.turro.financials.handshake.HandshakeDocument.existsHandshake ( HandshakeDocument  hd)
static

Definition at line 152 of file HandshakeDocument.java.

152  {
153  File folder = new File(ElephantContext.getRealPath(HANDSHAKE_FOLDER));
154  if(!folder.exists()) { folder.mkdirs(); }
155  for(File file : folder.listFiles()) {
156  HandshakeDocument fhd = createHandshakeFromFile(file);
157  if(hd.equals(fhd)) {
158  return true;
159  }
160  }
161  return false;
162  }
static HandshakeDocument createHandshakeFromFile(File file)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDocumentFromHandshake()

static Document org.turro.financials.handshake.HandshakeDocument.getDocumentFromHandshake ( Contract  contract,
HandshakeDocument  hd 
)
static

Definition at line 131 of file HandshakeDocument.java.

131  {
132  Dao dao = new FinancialsPU();
133  return (Document) dao.getSingleResultOrNull(
134  "select d from Document d " +
135  "where d.contract.id = ? " +
136  "and d.documentNumber = ? " +
137  "and d.documentDate = ?",
138  new Object[] {
139  contract.getId(),
140  hd.documentNumber,
141  hd.documentDate
142  });
143  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getProducts()

Iterable<HandshakeProduct> org.turro.financials.handshake.HandshakeDocument.getProducts ( )

Definition at line 208 of file HandshakeDocument.java.

208  {
209  Set<HandshakeProduct> products = new HashSet<>();
210  addProducts(products, this);
211  return products;
212  }
Here is the caller graph for this function:

◆ hashCode()

int org.turro.financials.handshake.HandshakeDocument.hashCode ( )

Definition at line 179 of file HandshakeDocument.java.

179  {
180  int hash = 5;
181  hash = 61 * hash + Objects.hashCode(this.contract);
182  hash = 61 * hash + Objects.hashCode(this.documentNumber);
183  hash = 61 * hash + Objects.hashCode(this.documentDate);
184  return hash;
185  }

◆ saveHandshakeDocument()

static void org.turro.financials.handshake.HandshakeDocument.saveHandshakeDocument ( HandshakeDocument  hd)
static

Definition at line 145 of file HandshakeDocument.java.

145  {
146  if(!existsHandshake(hd)) {
147  File file = new File(ElephantContext.getRealPath(HANDSHAKE_FOLDER) + "/doc" + IdGenerator.generate() + ".handshake");
148  saveHandshakeToFile(file, hd);
149  }
150  }
static boolean existsHandshake(HandshakeDocument hd)
static void saveHandshakeToFile(File file, HandshakeDocument hd)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveHandshakeToFile()

static void org.turro.financials.handshake.HandshakeDocument.saveHandshakeToFile ( File  file,
HandshakeDocument  hd 
)
static

Definition at line 122 of file HandshakeDocument.java.

122  {
123  Gson gson = new GsonBuilder().setDateFormat("yyyy/MM/dd").create();
124  try {
125  FileUtil.setContent(file, gson.toJson(hd));
126  } catch (IOException ex) {
127  Logger.getLogger(HandshakeContract.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
128  }
129  }
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ contract

HandshakeContract org.turro.financials.handshake.HandshakeDocument.contract

Definition at line 54 of file HandshakeDocument.java.

◆ definitionId

long org.turro.financials.handshake.HandshakeDocument.definitionId

Definition at line 58 of file HandshakeDocument.java.

◆ documentDate

Date org.turro.financials.handshake.HandshakeDocument.documentDate

Definition at line 57 of file HandshakeDocument.java.

◆ documentName

String org.turro.financials.handshake.HandshakeDocument.documentName

Definition at line 55 of file HandshakeDocument.java.

◆ documentNumber

String org.turro.financials.handshake.HandshakeDocument.documentNumber

Definition at line 56 of file HandshakeDocument.java.

◆ expiries

List<HandshakeDocument> org.turro.financials.handshake.HandshakeDocument.expiries = new ArrayList<>()

Definition at line 60 of file HandshakeDocument.java.

◆ HANDSHAKE_FOLDER

final String org.turro.financials.handshake.HandshakeDocument.HANDSHAKE_FOLDER = "/WEB-INF/handshake/document"
static

Definition at line 52 of file HandshakeDocument.java.

◆ lines

List<HandshakeDocLine> org.turro.financials.handshake.HandshakeDocument.lines = new ArrayList<>()

Definition at line 59 of file HandshakeDocument.java.


The documentation for this class was generated from the following file: