BrightSide Workbench Full Report + Source Code
ConceptPermissionMap.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 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.security;
20 
21 import java.util.Collection;
22 import java.util.HashMap;
23 import java.util.TreeMap;
24 import org.turro.elephant.context.Application;
25 import org.turro.entities.IElephantEntity;
26 import org.turro.plugin.contacts.IContact;
27 import org.turro.util.Cached;
28 
33 public class ConceptPermissionMap extends HashMap<String, ConceptPermission> {
34 
35  private final transient Cached<IContact> contact = Cached.<IContact>instance(() -> Application.getUser());
36 
37  @Override
38  public ConceptPermission put(String key, ConceptPermission value) {
39  if(value.getOrder() == -1) value.order(size());
40  return super.put(key, value);
41  }
42 
44  return this.put(value.getName(), value);
45  }
46 
47  @Override
48  public ConceptPermission get(Object key) {
49  throw new UnsupportedOperationException("Use get(name, iee)");
50  }
51 
52  public ConceptPermission get(String name, IElephantEntity iee) {
53  ConceptPermission cp = super.get(name);
54  if(cp != null) cp.init(iee, contact);
55  return cp;
56  }
57 
58  public Collection<String> concepts() {
59  TreeMap<Integer, String> names = new TreeMap<>();
60  forEach((k, v) -> names.put(v.getOrder(), k));
61  return names.values();
62  }
63 
64 }
ConceptPermission put(ConceptPermission value)
ConceptPermission put(String key, ConceptPermission value)
void init(IElephantEntity iee, Cached< IContact > contact)