|
31 | 31 |
|
32 | 32 | import cz.metacentrum.perun.core.bl.ExtSourcesManagerBl; |
33 | 33 | import cz.metacentrum.perun.core.bl.PerunBl; |
| 34 | +import cz.metacentrum.perun.core.impl.ExtSourceLdap; |
34 | 35 | import cz.metacentrum.perun.core.impl.Utils; |
35 | 36 | import cz.metacentrum.perun.core.implApi.ExtSourceSimpleApi; |
36 | 37 | import cz.metacentrum.perun.core.implApi.ExtSourcesManagerImplApi; |
@@ -73,7 +74,7 @@ public void initialize(PerunSession sess) { |
73 | 74 |
|
74 | 75 | private Map<Integer,ExtSource> extSourcesByIdMap = new HashMap<>(); |
75 | 76 | private Map<String,ExtSource> extSourcesByNameMap = new HashMap<>(); |
76 | | - |
| 77 | + |
77 | 78 | private void cacheExtSourcesInMemory(PerunSession sess) { |
78 | 79 | Map<Integer,ExtSource> extSourcesByIdMap = new HashMap<>(); |
79 | 80 | Map<String,ExtSource> extSourcesByNameMap = new HashMap<>(); |
@@ -112,34 +113,65 @@ public void deleteExtSource(PerunSession sess, ExtSource extSource) throws ExtSo |
112 | 113 | @Override |
113 | 114 | public ExtSource getExtSourceById(PerunSession sess, int id) throws InternalErrorException, ExtSourceNotExistsException { |
114 | 115 | ExtSource extSource = extSourcesByIdMap.get(id); |
| 116 | + if (extSource instanceof ExtSourceLdap) { |
| 117 | + // FIXME - retrieve new instance for LDAP ExtSources !! |
| 118 | + return getExtSourcesManagerImpl().getExtSourceById(sess, id); |
| 119 | + } |
115 | 120 | if (extSource == null) throw new ExtSourceNotExistsException("ExtSource with ID=" + id + " not exists"); |
116 | 121 | return extSource; |
117 | 122 | } |
118 | 123 |
|
119 | 124 | @Override |
120 | 125 | public ExtSource getExtSourceByName(PerunSession sess, String name) throws InternalErrorException, ExtSourceNotExistsException { |
121 | 126 | ExtSource extSource = extSourcesByNameMap.get(name); |
| 127 | + if (extSource instanceof ExtSourceLdap) { |
| 128 | + // FIXME - retrieve new instance for LDAP ExtSources !! |
| 129 | + return getExtSourcesManagerImpl().getExtSourceByName(sess, name); |
| 130 | + } |
122 | 131 | if (extSource == null) throw new ExtSourceNotExistsException("ExtSource with name =" + name + " not exists"); |
123 | 132 | return extSource; |
124 | 133 | } |
125 | 134 |
|
126 | 135 | @Override |
127 | 136 | public List<ExtSource> getVoExtSources(PerunSession sess, Vo vo) throws InternalErrorException { |
128 | 137 | List<Integer> ids = getExtSourcesManagerImpl().getVoExtSourcesIds(sess, vo); |
129 | | - return ids.stream().map(id -> extSourcesByIdMap.get(id)).collect(Collectors.toList()); |
| 138 | + return ids.stream().map(id -> { ExtSource extSource = extSourcesByIdMap.get(id); |
| 139 | + if (extSource instanceof ExtSourceLdap) { |
| 140 | + // FIXME - retrieve new instance for LDAP ExtSources !! |
| 141 | + try { |
| 142 | + return getExtSourcesManagerImpl().getExtSourceById(sess, id); |
| 143 | + } catch (ExtSourceNotExistsException e) { |
| 144 | + log.error("VO ExtSource by its ID doesn't exists!"); |
| 145 | + throw new ConsistencyErrorException("VO ExtSource by its ID doesn't exists!", e); |
| 146 | + } |
| 147 | + } |
| 148 | + return extSource; |
| 149 | + }).collect(Collectors.toList()); |
130 | 150 | } |
131 | 151 |
|
132 | 152 | @Override |
133 | 153 | public List<ExtSource> getGroupExtSources(PerunSession sess, Group group) throws InternalErrorException { |
134 | 154 | List<Integer> ids = getExtSourcesManagerImpl().getGroupExtSourcesIds(sess, group); |
135 | | - return ids.stream().map(id -> extSourcesByIdMap.get(id)).collect(Collectors.toList()); |
| 155 | + return ids.stream().map(id -> { ExtSource extSource = extSourcesByIdMap.get(id); |
| 156 | + if (extSource instanceof ExtSourceLdap) { |
| 157 | + // FIXME - retrieve new instance for LDAP ExtSources !! |
| 158 | + try { |
| 159 | + return getExtSourcesManagerImpl().getExtSourceById(sess, id); |
| 160 | + } catch (ExtSourceNotExistsException e) { |
| 161 | + log.error("Group ExtSource by its ID doesn't exists!"); |
| 162 | + throw new ConsistencyErrorException("VO ExtSource by its ID doesn't exists!", e); |
| 163 | + } |
| 164 | + } |
| 165 | + return extSource; |
| 166 | + }).collect(Collectors.toList()); |
136 | 167 | } |
137 | 168 |
|
138 | 169 | @Override |
139 | 170 | public List<ExtSource> getExtSources(PerunSession sess) throws InternalErrorException { |
| 171 | + // FIXME - no need to retrieve new instance for LDAP ExtSources since its used only by outer API and tests. |
140 | 172 | return new ArrayList<>(extSourcesByIdMap.values()); |
141 | 173 | } |
142 | | - |
| 174 | + |
143 | 175 | @Override |
144 | 176 | public void addExtSource(PerunSession sess, Vo vo, ExtSource source) throws ExtSourceAlreadyAssignedException { |
145 | 177 | getExtSourcesManagerImpl().addExtSource(sess, vo, source); |
|
0 commit comments