|
10 | 10 |
|
11 | 11 | import javax.servlet.ServletContext; |
12 | 12 |
|
| 13 | +import co.elastic.clients.elasticsearch._types.Refresh; |
| 14 | +import com.google.common.collect.Lists; |
13 | 15 | import org.phoebus.channelfinder.AuthorizationService.ROLES; |
14 | 16 | import org.springframework.beans.factory.annotation.Autowired; |
15 | 17 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
@@ -187,7 +189,7 @@ public Iterable<XmlChannel> create(@RequestBody Iterable<XmlChannel> channels) { |
187 | 189 | }); |
188 | 190 |
|
189 | 191 | // create new channels |
190 | | - return channelRepository.indexAll(channels); |
| 192 | + return channelRepository.indexAll(Lists.newArrayList(channels)); |
191 | 193 | } else { |
192 | 194 | log.log(Level.SEVERE, "User does not have the proper authorization to perform an operation on this channel: " + channels, new ResponseStatusException(HttpStatus.UNAUTHORIZED)); |
193 | 195 | throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, |
@@ -220,20 +222,34 @@ public XmlChannel update(@PathVariable("channelName") String channelName, @Reque |
220 | 222 | } |
221 | 223 | Optional<XmlChannel> existingChannel = channelRepository.findById(channelName); |
222 | 224 | boolean present = existingChannel.isPresent(); |
| 225 | + |
| 226 | + XmlChannel newChannel; |
223 | 227 | if(present) { |
224 | 228 | if(!authorizationService.isAuthorizedOwner(SecurityContextHolder.getContext().getAuthentication(), existingChannel.get())) { |
225 | 229 | log.log(Level.SEVERE, "User does not have the proper authorization to perform an operation on this channel: " + existingChannel.get().toLog(), new ResponseStatusException(HttpStatus.UNAUTHORIZED)); |
226 | 230 | throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, |
227 | 231 | "User does not have the proper authorization to perform an operation on this channel: " + existingChannel.get(), null); |
228 | 232 | } |
229 | | - } |
| 233 | + newChannel = existingChannel.get(); |
| 234 | + newChannel.setOwner(channel.getOwner()); |
| 235 | + newChannel.addProperties(channel.getProperties()); |
| 236 | + newChannel.addTags(channel.getTags()); |
| 237 | + // Is an existing channel being renamed |
| 238 | + if (!channel.getName().equalsIgnoreCase(existingChannel.get().getName())) { |
| 239 | + // Since this is a rename operation we will need to remove the old channel. |
| 240 | + channelRepository.deleteById(existingChannel.get().getName()); |
| 241 | + newChannel.setName(channel.getName()); |
| 242 | + } |
| 243 | + } else { |
| 244 | + newChannel = channel; |
| 245 | + } |
230 | 246 |
|
231 | 247 | // reset owners of attached tags/props back to existing owners |
232 | 248 | channel.getProperties().forEach(prop -> prop.setOwner(propertyRepository.findById(prop.getName()).get().getOwner())); |
233 | 249 | channel.getTags().forEach(tag -> tag.setOwner(tagRepository.findById(tag.getName()).get().getOwner())); |
234 | 250 |
|
235 | 251 | // update channel |
236 | | - return channelRepository.save(channelName,channel); |
| 252 | + return channelRepository.save(newChannel); |
237 | 253 | } else { |
238 | 254 | log.log(Level.SEVERE, "User does not have the proper authorization to perform an operation on this channel: " + channelName, new ResponseStatusException(HttpStatus.UNAUTHORIZED)); |
239 | 255 | throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, |
|
0 commit comments