BrightSide Workbench Full Report + Source Code
HumanResourcesVM.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 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.contacts.hhrr;
20 
21 import java.util.Collections;
22 import java.util.List;
23 import java.util.Set;
24 import org.turro.auth.Authentication;
25 import org.turro.contacts.BusinessRelation;
26 import org.turro.contacts.Contact;
27 import org.turro.contacts.db.ContactsPU;
28 import org.turro.plugin.contacts.ContactList;
29 import org.turro.plugin.contacts.IContact;
30 import org.zkoss.bind.annotation.BindingParam;
31 import org.zkoss.bind.annotation.Command;
32 import org.zkoss.bind.annotation.NotifyChange;
33 
38 public class HumanResourcesVM {
39 
40  private IContact contact, business;
41  private HumanResourcesSet model;
42  private boolean editable;
43 
44  @NotifyChange("model")
45  @Command("business")
46  public void setBusiness(@BindingParam("business") Object business) {
47  if(business instanceof IContact) {
48  this.business = (IContact) business;
49  model = null;
50  editable = contact.isHHRR((IContact) business) || contact.isAdmin();
51  }
52  }
53 
54  @NotifyChange("model")
55  @Command("save")
56  public void save() {
57  if(editable && model != null && !model.isEmpty()) {
58  new ContactsPU().saveCollection(model);
59  }
60  }
61 
62  public boolean isEditable() {
63  return editable;
64  }
65 
66  public IContact getBusiness() {
67  return business;
68  }
69 
70  public Set<BusinessRelation> getModel() {
71  if(business != null && business.isValid()) {
72  model = new HumanResourcesSet(((Contact) business.getContact()).getWorkerRelations());
73  } else {
74  model = new HumanResourcesSet(Collections.EMPTY_SET);
75  }
76  return model;
77  }
78 
79  public List<IContact> getBusinessModel() {
80  if(contact == null) {
81  contact = Authentication.getIContact();
82  }
83  if(contact.isAdmin()) {
84  ContactList list = new ContactList();
85  list.addAll(contact.getCenters());
86  list.addAll(contact.getCompanies());
87  list.sort((o1, o2) -> {
88  return o1.getName().compareTo(o2.getName());
89  });
90  return list;
91  } else {
92  return contact.getBusinessList();
93  }
94  }
95 
96 }
void setBusiness(@BindingParam("business") Object business)
void saveCollection(Collection objs)
Definition: Dao.java:144
List< IContact > getBusinessList()