BrightSide Workbench Full Report + Source Code
ProfileCompletion.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.profile;
20 
21 import org.turro.action.Actions;
22 import org.turro.collections.KeyValueMap;
23 import org.turro.config.Configurator;
24 import org.turro.contacts.db.ContactsPU;
25 import org.turro.contacts.relation.Relations;
26 import org.turro.i18n.I_;
27 import org.turro.plugin.contacts.IContactRelation;
28 import org.turro.plugin.contacts.IProfile;
29 
34 public class ProfileCompletion {
35 
36  private final Profile profile;
37 
38  public ProfileCompletion(Profile profile) {
39  this.profile = profile;
40  readSettings();
41  }
42 
43  public double getPercent() {
44  double should = 0, have = 0;
45  Configurator settings = Configurator.instance();
46  if(settings.asBoolean("Profile.Suggest.Image")) {
47  should++; have += !image ? 1 : 0;
48  }
49  if(settings.asBoolean("Profile.Suggest.Skills")) {
50  should++; have += !skills ? 1 : 0;
51  }
52  if(settings.asBoolean("Profile.Suggest.Relation")) {
53  should++; have += !relation ? 1 : 0;
54  }
55  if(settings.asBoolean("Profile.Suggest.Company")) {
56  should++; have += !company ? 1 : 0;
57  }
58  if(settings.asBoolean("Profile.Suggest.Professional.Documents") && profile.isWorker()) {
59  should++; have += !documents ? 1 : 0;
60  } else if(settings.asBoolean("Profile.Suggest.Student.Documents") && profile.isStudent()) {
61  should++; have += !documents ? 1 : 0;
62  }
63  return should == 0 ? 100.0 : (have / should) * 100.0;
64  }
65 
66  /* Suggest */
67 
68  public Profile getProfile() {
69  return profile;
70  }
71 
72  public boolean isImage() {
73  return image;
74  }
75 
76  public boolean isSkills() {
77  return skills;
78  }
79 
80  public boolean isRelation() {
81  return relation;
82  }
83 
84  public boolean isDocuments() {
85  return documents;
86  }
87 
88  public boolean isCompany() {
89  return company;
90  }
91 
92  public String getCompanyType() {
93  return companyType;
94  }
95 
96  /* Configuration */
97 
98  private boolean image, skills, relation, documents, company;
99  private String companyType;
100 
101  private void readSettings() {
102  Configurator settings = Configurator.instance();
103  image = settings.asBoolean("Profile.Suggest.Image") && !profile.getHasImage();
104  skills = settings.asBoolean("Profile.Suggest.Skills") && !profile.getHasSkills();
105  relation = settings.asBoolean("Profile.Suggest.Relation") &&
106  profile.getCurrentCenters().isEmpty() &&
107  profile.getCurrentCompanies().isEmpty();
108  if(profile.isWorker()) {
110  IProfile cprofile = crelation.getRelatedIContact().getProfile();
111  company = settings.asBoolean("Profile.Suggest.Company") &&
112  (!cprofile.getHasAbout() || !cprofile.getHasImage());
113  companyType = I_.get("Company");
114  documents = settings.asBoolean("Profile.Suggest.Professional.Documents") &&
115  !profile.getHasDocuments();
116  } else if(profile.isResponsible()) {
117  IContactRelation crelation = Relations.companies(profile.getContact()).getCompanyRelation();
118  IProfile cprofile = crelation.getRelatedIContact().getProfile();
119  company = settings.asBoolean("Profile.Suggest.Company") &&
120  (!cprofile.getHasAbout() || !cprofile.getHasImage());
121  companyType = I_.get("Learning center");;
122  } else if(profile.isStudent()) {
123  documents = settings.asBoolean("Profile.Suggest.Student.Documents") &&
124  !profile.getHasDocuments();
125  }
126  }
127 
128  public String getEditLink() {
129  KeyValueMap kvm = new KeyValueMap();
130  kvm.put("contact", profile.getContact().getId());
131  return "/user/profile/edit?" + Actions.createRightNowAction(kvm);
132  }
133 
134  public String getSkillsLink() {
135  KeyValueMap kvm = new KeyValueMap();
136  kvm.put("entityPath", ContactsPU.getObjectPath(profile.getContact().getContact()));
137  return "/user/profile/editsk?" + Actions.createRightNowAction(kvm);
138  }
139 
140  public String getDocumentsLink() {
141  KeyValueMap kvm = new KeyValueMap();
142  kvm.put("entityPath", ContactsPU.getObjectPath(profile.getContact().getContact()));
143  return "/user/profile/pubs";
144  }
145 
146 }
static String createRightNowAction(String values)
Definition: Actions.java:312
static String getObjectPath(Object object)
Definition: ContactsPU.java:68
static String get(String msg)
Definition: I_.java:41