19 package org.turro.security;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.HashSet;
24 import java.util.List;
26 import java.util.stream.Collectors;
27 import org.turro.auth.Authentication;
28 import org.turro.contacts.Contact;
29 import org.turro.contacts.ContactType;
30 import org.turro.contacts.Syndication;
31 import org.turro.jpa.Dao;
32 import org.turro.plugin.contacts.IContact;
33 import org.turro.sql.SqlClause;
34 import org.turro.tags.Tags;
51 Set<SecurityGroup> socials =
new HashSet<>();
60 public static void syndicate(List<Contact> contacts, Set<String> socialGroupIds,
Dao dao) {
62 contacts.forEach(contact -> {
65 dao.saveObject(contact);
70 public static void unsyndicate(List<Contact> contacts, Set<String> socialGroupIds,
Dao dao) {
72 contacts.forEach(contact -> {
75 dao.saveObject(contact);
82 contacts.forEach(contact -> {
85 dao.saveObject(contact);
92 Set<String> socialGroupIds =
new HashSet<>();
93 contacts.forEach(contact -> {
96 dao.saveObject(contact);
105 contacts.forEach(contact -> {
113 contact.
getSyndications().removeIf(syndication -> socialGroupIds.contains(syndication.getName()));
117 contact.
getSyndications().removeIf(syndication -> !socialGroupIds.contains(syndication.getName()));
119 .map(syndication -> syndication.getName()).collect(Collectors.toSet());
120 socialGroupIds.stream().filter(social -> !syndicationNames.contains(social)).forEach(social -> {
130 Set<String> currentTags =
Tags.
getTags(contact).stream()
131 .map(tag -> tag.getTagName()).collect(Collectors.toSet());
132 currentTags.stream().filter(tag -> !tags.contains(tag) &&
possibleTag(tag)).forEach(tag -> {
135 tags.stream().filter(tag -> !currentTags.contains(tag)).forEach(tag -> {
141 Set<String> flatSocials =
new HashSet<>();
142 if(contact !=
null) {
144 .map(syndication -> syndication.getName()).collect(Collectors.toSet()));
146 socials.forEach(social -> {
152 public Set<String>
flatRoles(Set<Syndication> syndications) {
154 syndications.forEach(syndication -> {
157 flatRoles.addAll(sg.getRoles());
164 public Set<String>
flatTags(Set<Syndication> syndications) {
165 Set<String>
flatTags =
new HashSet<>();
166 syndications.forEach(syndication -> {
169 flatTags.addAll(sg.getTags());
187 if(current !=
null) {
190 SqlClause.delete(
"Syndication")
191 .where().notIn(
"name", inheritance)
192 .and().equal(
"dynamic",
true)
193 .and().equal(
"contact", current)
197 SqlClause.update(
"Syndication")
198 .set(
"dynamic",
true)
199 .where().in(
"name", inheritance)
200 .and().equal(
"contact", current)
204 List<String> currentNames = SqlClause.select(
"s.name").from(
"Syndication s")
205 .where().equal(
"contact", current)
207 .resultList(String.class);
208 inheritance.stream().filter(name -> !currentNames.contains(name))
214 dao.saveObject(syndication);
224 List<String> inheritance =
new ArrayList<>();
225 if(contact !=
null) {
227 inheritance.addAll(business.getSyndications().stream()
228 .filter(syndication -> syndication.getSocialGroup().isInherits())
229 .map(syndication -> syndication.getName())
static IContact getIContact()
final Map< String, SecurityGroup > socialGroups
boolean possibleTag(String tag)
void recurseSocialGroups(Set< String > flatSocials, SecurityGroup sg)
static Collection< SecurityGroup > allowedSocialGroups()
static Collection< SecurityGroup > allowedSocialGroups(IContact contact)
List< String > getInheritedFrom(Contact contact)
void synchronizeSocials(Contact contact, Set< String > socialGroupIds)
static void unsyndicate(List< Contact > contacts, Set< String > socialGroupIds, Dao dao)
Set< String > flatSocialGroups(Contact contact, Set< String > socials)
static void absoluteSyndicate(List< Contact > contacts, Set< String > socialGroupIds, Dao dao)
void synchronizeTags(Contact contact, Set< String > tags)
static void resyndicate(List< Contact > contacts, Dao dao)
Set< String > flatTags(Set< Syndication > syndications)
static void checkInheritance(List< Contact > contacts, Dao dao)
Set< String > flatRoles(Set< Syndication > syndications)
Contact checkCompanyInheritance(Contact contact, Dao dao)
static void syndicate(List< Contact > contacts, Set< String > socialGroupIds, Dao dao)
static SocialGroups instance()
void removeSocials(Contact contact, Set< String > socialGroupIds)
void checkInheritance(Contact contact, Dao dao)