BrightSide Workbench Full Report + Source Code
ProfileVM.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2023 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.profile;
20 
21 import org.turro.action.Actions;
22 import org.turro.auth.Authentication;
23 import org.turro.collections.KeyValueMap;
24 import org.turro.config.Configurator;
25 import org.turro.contacts.Contact;
26 import static org.turro.contacts.ContactType.CONTACT_COMPANY;
27 import static org.turro.contacts.ContactType.CONTACT_LEARNINGCENTER;
28 import org.turro.contacts.db.ContactsPU;
29 import org.zkoss.bind.annotation.BindingParam;
30 import org.zkoss.bind.annotation.Command;
31 
36 public class ProfileVM {
37 
38  /* Policies */
39 
40  public String getPolicy(String element, ProfileRelation relation) {
42  return pp.getPolicy(relation, element).toString();
43  }
44 
45  @Command("policy")
46  public void setPolicy(@BindingParam("type") String type, @BindingParam("element") String element,
47  @BindingParam("relation") ProfileRelation relation) {
49  PublishPolicy policy = PublishPolicy.valueOf(type);
50  pp.setPolicy(relation == null ? getContact() : relation.getRelation(), element, policy);
51  pp.save();
52  }
53 
54  /* Contact */
55 
56  private Contact contact;
57 
58  public Contact getContact() {
59  if(contact == null) {
61  }
62  return contact;
63  }
64 
65  public Profile getProfile() {
66  return getContact().getEditProfile();
67  }
68 
69  public long getMaxDocuments() {
70  return Configurator.instance().asLong("Profile.Documents.Maximum");
71  }
72 
73  /* Edit links */
74 
75  public String getNewLink(String element) {
76  KeyValueMap kvm = new KeyValueMap();
77  kvm.put("contact", contact.getId());
78  kvm.put("element", element);
79  switch(element) {
80  case "company":
81  return "/user/profile/editrb?" + Actions.createRightNowAction(kvm);
82  case "center":
83  return "/user/profile/editrc?" + Actions.createRightNowAction(kvm);
84  }
85  return "#";
86  }
87 
88  public String getEditLink(ProfileRelation relation) {
89  KeyValueMap kvm = new KeyValueMap();
90  kvm.put("contact", contact.getId());
91  kvm.put("relation", relation.getRelation().getId());
92  switch(relation.getRelation().getBusiness().getType()) {
93  case CONTACT_COMPANY:
94  return "/user/profile/editrb?" + Actions.createRightNowAction(kvm);
95  case CONTACT_LEARNINGCENTER:
96  return "/user/profile/editrc?" + Actions.createRightNowAction(kvm);
97  }
98  return "#";
99  }
100 
101  public String getCompanyLink(ProfileRelation relation) {
102  KeyValueMap kvm = new KeyValueMap();
103  kvm.put("contact", relation.getRelation().getBusiness().getId());
104  return "/user/profile/editc?" + Actions.createRightNowAction(kvm);
105  }
106 
107  public String getEditLink() {
108  KeyValueMap kvm = new KeyValueMap();
109  kvm.put("contact", contact.getId());
110  return "/user/profile/edit?" + Actions.createRightNowAction(kvm);
111  }
112 
113  public String getSkillsLink() {
114  KeyValueMap kvm = new KeyValueMap();
115  kvm.put("entityPath", ContactsPU.getObjectPath(contact));
116  return "/user/profile/editsk?" + Actions.createRightNowAction(kvm);
117  }
118 
119 }
static String createRightNowAction(String values)
Definition: Actions.java:312
static String getObjectPath(Object object)
Definition: ContactsPU.java:68
PublishPolicy getPolicy(Object obj, String element)
void setPolicy(Object obj, String element, PublishPolicy publish)
void setPolicy(@BindingParam("type") String type, @BindingParam("element") String element, @BindingParam("relation") ProfileRelation relation)
Definition: ProfileVM.java:46
String getNewLink(String element)
Definition: ProfileVM.java:75
String getPolicy(String element, ProfileRelation relation)
Definition: ProfileVM.java:40
String getEditLink(ProfileRelation relation)
Definition: ProfileVM.java:88
String getCompanyLink(ProfileRelation relation)
Definition: ProfileVM.java:101