@RequestMapping(value = "move", method = RequestMethod.GET) public String moveForm(@RequestParam Long id, Model model, RedirectAttributes redirectAttrs) { return physicalPortService .find(id) .map(port -> renderMoveForm(port, model, redirectAttrs)) .orElse("redirect:"); }
@RequestMapping(value = "move", method = RequestMethod.POST) public String move( @Valid MovePhysicalPortCommand command, BindingResult result, RedirectAttributes redirectAttrs, Model model) { Optional<NbiPort> newPort = physicalPortService.findNbiPort(command.getNewPhysicalPort()); Optional<PhysicalPort> oldPort = physicalPortService.find(command.getId()); if (!newPort.isPresent() || !oldPort.isPresent()) { return "redirect:"; } if (result.hasErrors()) { return renderMoveForm(oldPort.get(), model, redirectAttrs); } model.addAttribute("lastEventId", endPoints.getLastEventId()); try { Collection<Reservation> reservations = nocService.movePort(oldPort.get(), newPort.get()); ElementActionView disabledAction = new ElementActionView(false); Collection<ReservationView> reservationViews = reservations .stream() .map( reservation -> new ReservationView( reservation, disabledAction, disabledAction, disabledAction)) .collect(toList()); messageManager.addInfoMessage(model, "label_physicalport_port_moved"); model.addAttribute("list", reservationViews); return PAGE_URL + "/moveResult"; } catch (OverlappingSubportAllocationException e) { result.reject(e.getMessage()); return renderMoveForm(oldPort.get(), model, redirectAttrs); } }
@RequestMapping(value = DELETE, params = ID_KEY, method = RequestMethod.DELETE) public String delete( Long id, @RequestParam(value = PAGE_KEY, required = false) Integer page, Model uiModel) { return physicalPortService .find(id) .map( port -> { if (port instanceof UniPort) { virtualServiceService .findEntriesForUniPort((UniPort) port) .forEach( service -> virtualServiceService.delete(service, Security.getUserDetails())); } physicalPortService.delete(id); uiModel.asMap().clear(); uiModel.addAttribute(PAGE_KEY, page == null ? "1" : page.toString()); return redirectPortListPage(port); }) .orElse("redirect:"); }