BrightSide Workbench Full Report + Source Code
SkillCloud.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.skills.tags;
20 
21 import java.util.Collections;
22 import java.util.List;
23 import java.util.stream.Collectors;
24 import org.turro.collections.KeyValueMap;
25 import org.turro.elephant.context.IConstructor;
26 import org.turro.marker.MarkerHelper;
27 
32 public class SkillCloud {
33 
34  private static final String SKILLS_CONTEXT = "skill-cloud-ctx";
35 
36  public static SkillSet getSkills(IConstructor constructor, String root, boolean user) {
37  SkillSet skills = getSkillSet(constructor, root, user);
38  if(skills == null) {
39  skills = SkillTags.getAvailables(root, user);
40  constructor.setSessionAttribute(getContextName(constructor, root, user), skills);
41  }
42  return skills;
43  }
44 
45  public static void toggleSkills(IConstructor constructor, String root, boolean user) {
46  KeyValueMap kvm = MarkerHelper.getObfuscatedParameters();
47  if(kvm != null && kvm.containsKey("skill")) {
48  SkillSet set = getSkillSet(constructor, root, user);
49  if(set != null) {
50  set.toggle(kvm.get("skill"));
51  set.markSiblingsFromSelection(root);
52  }
53  }
54  }
55 
56  public static void resetContext(IConstructor constructor, String root) {
57  constructor.removeSessionAttribute(getContextName(constructor, root, true));
58  constructor.removeSessionAttribute(getContextName(constructor, root, false));
59  }
60 
61  public static List<String> getIdentifiers(IConstructor constructor, String root, boolean user) {
62  SkillSet set = getSkillSet(constructor, root, user);
63  if(set != null) {
64  return set.getIdentifiers(root);
65  }
66  return Collections.EMPTY_LIST;
67  }
68 
69  public static List<Long> getIdentifiersAsLong(IConstructor constructor, String root, boolean user) {
70  return getIdentifiers(constructor, root, user).stream().map(s -> Long.valueOf(s)).collect(Collectors.toList());
71  }
72 
73  public static boolean hasSelected(IConstructor constructor, String root, boolean user) {
74  SkillSet set = getSkillSet(constructor, root, user);
75  if(set != null) {
76  return !(set.getSelected().isEmpty());
77  }
78  return false;
79  }
80 
81  private static SkillSet getSkillSet(IConstructor constructor, String root, boolean user) {
82  return (SkillSet) constructor.getSessionAttribute(getContextName(constructor, root, user));
83  }
84 
85  private static String getContextName(IConstructor constructor, String root, boolean user) {
86  return SKILLS_CONTEXT + "-" + root + "-" + (user ? "user" : "company");
87  }
88 
89 }
90 
static KeyValueMap getObfuscatedParameters()
static List< Long > getIdentifiersAsLong(IConstructor constructor, String root, boolean user)
Definition: SkillCloud.java:69
static void toggleSkills(IConstructor constructor, String root, boolean user)
Definition: SkillCloud.java:45
static List< String > getIdentifiers(IConstructor constructor, String root, boolean user)
Definition: SkillCloud.java:61
static void resetContext(IConstructor constructor, String root)
Definition: SkillCloud.java:56
static SkillSet getSkills(IConstructor constructor, String root, boolean user)
Definition: SkillCloud.java:36
static boolean hasSelected(IConstructor constructor, String root, boolean user)
Definition: SkillCloud.java:73
static SkillSet getAvailables(String root)
Definition: SkillTags.java:42
void setSessionAttribute(String key, Object value)