BrightSide Workbench Full Report + Source Code
SocialGroup.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 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.socialgroup;
20 
21 import java.io.File;
22 import java.io.IOException;
23 import java.util.HashSet;
24 import java.util.List;
25 import java.util.Set;
26 import java.util.logging.Level;
27 import java.util.logging.Logger;
28 import org.jdom.Document;
29 import org.jdom.Element;
30 import org.jdom.JDOMException;
31 import org.jdom.input.SAXBuilder;
32 import org.turro.elephant.context.ElephantContext;
33 
38 @Deprecated
39 public class SocialGroup {
40 
41  private String name, id;
42  private final Set<String> syndicate = new HashSet<>();
43  private final Set<AllowedSocialGroup> allowed = new HashSet<>();
44  private final Set<String> roles = new HashSet<>();
45  private final Set<String> tags = new HashSet<>();
46 
47  public String getId() {
48  return id;
49  }
50 
51  public String getName() {
52  return name;
53  }
54 
55  public Set<String> getSyndicate() {
56  return syndicate;
57  }
58 
59  public Set<String> getRoles() {
60  return roles;
61  }
62 
63  public Set<String> getTags() {
64  return tags;
65  }
66 
67  public Set<AllowedSocialGroup> getAllowed() {
68  return allowed;
69  }
70 
71  public void loadSet(File confFile) {
72  SAXBuilder builder = new SAXBuilder();
73  Document doc;
74  try {
75  if(confFile.exists()) {
76  doc = builder.build(confFile);
77  readXML(doc.getRootElement());
78  }
79  } catch (IOException | JDOMException ex) {
80  Logger.getLogger(SocialGroup.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
81  }
82  }
83 
84  private void readXML(Element rootElement) {
85  name = rootElement.getAttributeValue("name");
86  for(Element el : (List<Element>) rootElement.getChildren("allowed")) {
88  asg.setName(el.getAttributeValue("name"));
89  asg.setReadonly("true".equals(el.getAttributeValue("readOnly")));
90  asg.setInherits("true".equals(el.getAttributeValue("inherits")));
91  for(Element el2 : (List<Element>) el.getChildren("deny")) {
92  asg.addDeny(el2.getAttributeValue("name"), el2.getAttributeValue("value"));
93  }
94  allowed.add(asg);
95  }
96  for(Element el : (List<Element>) rootElement.getChildren("role")) {
97  roles.add(el.getAttributeValue("name"));
98  }
99  for(Element el : (List<Element>) rootElement.getChildren("tag")) {
100  tags.add(el.getAttributeValue("name"));
101  }
102  for(Element el : (List<Element>) rootElement.getChildren("criteria")) {
103  String javaClass = el.getAttributeValue("java-class");
104  String order = el.getAttributeValue("order");
105  if(javaClass != null && javaClass.contains("SyndicationCriteria")) {
106  if("0".equals(order)) {
107  id = el.getAttributeValue("value");
108  } else {
109  syndicate.add(el.getAttributeValue("value"));
110  }
111  }
112  }
113  }
114 
115  public void assignAllowedIds(SocialGroupMap map) {
116  allowed.forEach(a -> a.setId(map.get(a.getName()).id));
117  }
118 
119 }
void addDeny(String name, String values)
Set< AllowedSocialGroup > getAllowed()
void assignAllowedIds(SocialGroupMap map)