BrightSide Workbench Full Report + Source Code
FinancialsAssistants.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2017 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 
19 package org.turro.financials.command;
20 
21 import java.util.Collections;
22 import java.util.List;
23 import org.turro.annotation.ExternalAssistant;
24 import org.turro.assistant.Assistant;
25 import org.turro.assistant.AssistantSet;
26 import org.turro.assistant.IAssistant;
27 import org.turro.elephant.security.IUser;
28 import org.turro.entities.Entities;
29 import org.turro.financials.entity.Contract;
30 import org.turro.financials.entity.ContractParticipant;
31 import org.turro.plugin.contacts.IContact;
32 
37 @ExternalAssistant
38 public class FinancialsAssistants implements IAssistant {
39 
40  @Override
41  public void add(Object entity, boolean deep, AssistantSet assistants, Object data) {
42  if(entity instanceof String) {
43  addFromEntityPath((String) entity, deep, assistants, data);
44  } else {
45  addFromEntity(entity, deep, assistants, data);
46  }
47  }
48 
49  @Override
50  public void addFromEntityPath(String entityPath, boolean deep, AssistantSet assistants, Object data) {
51  Object entity = Entities.getController(entityPath).getEntity();
52  addFromEntity(entity, deep, assistants, data);
53  }
54 
55  @Override
56  public void addFromEntity(Object entity, boolean deep, AssistantSet assistants, Object data) {
57  if(entity instanceof Contract) {
58  Contract contract = (Contract) entity;
59  assistants.addSubject(contract.getName());
60  IContact c = contract.getIContractor();
61  if(c != null && c.isWebUser()) {
62  assistants.add(new Assistant(c.getName(), c.getConnector(IUser.CONNECTOR_EMAIL), c, contract));
63  }
64  for(ContractParticipant cp : contract.getParticipants()) {
65  c = cp.getIContact();
66  if(c != null && c.isWebUser()) {
67  assistants.add(new Assistant(cp.getName(), c.getConnector(IUser.CONNECTOR_EMAIL), c, cp));
68  }
69  }
70  }
71  }
72 
73  @Override
74  public void addFromEntityPathData(String entityPath, AssistantSet assistants, Object data) {
75  Object entity = Entities.getController(entityPath).getEntity();
76  addFromEntityData(entity, assistants, data);
77  }
78 
79  @Override
80  public void addFromEntityData(Object entity, AssistantSet assistants, Object data) {
81  //TODO: contracts->dossier
82  }
83 
84  @Override
85  public List<String> getParticiped(IContact contact) {
86  return Collections.EMPTY_LIST;
87  }
88 
89 }
static IElephantEntity getController(String path)
Definition: Entities.java:78
void addFromEntity(Object entity, boolean deep, AssistantSet assistants, Object data)
void addFromEntityPathData(String entityPath, AssistantSet assistants, Object data)
void addFromEntityPath(String entityPath, boolean deep, AssistantSet assistants, Object data)
void addFromEntityData(Object entity, AssistantSet assistants, Object data)
void add(Object entity, boolean deep, AssistantSet assistants, Object data)
Set< ContractParticipant > getParticipants()
Definition: Contract.java:260
static final String CONNECTOR_EMAIL
Definition: IUser.java:27