private String renderMoveForm(PhysicalPort port, Model model, RedirectAttributes redirectAttrs) { List<UnallocatedPortView> unallocatedPorts = physicalPortService .findUnallocatedPorts() .stream() .filter(x -> x.isAvailable(port.getSVlan(), port.getAllowedVlan().orElse(Vlan.none()))) .collect(Collectors.toList()); if (unallocatedPorts.isEmpty()) { messageManager.addInfoFlashMessage( redirectAttrs, "info_physicalport_nounallocated", port.isVlanRequired() ? "EVPL" : "EPL"); return redirectPortListPage(port); } long numberOfVirtualPorts = port instanceof UniPort ? virtualPortService.countForUniPort((UniPort) port) : 0; long numberOfReservations = reservationService.countForPhysicalPort(port); long numberOfActiveReservations = reservationService.countActiveReservationsForPhysicalPort(port); model.addAttribute( "relatedObjects", new RelatedObjects(numberOfVirtualPorts, numberOfReservations, numberOfActiveReservations)); model.addAttribute("physicalPort", new PhysicalPortMoveView(port)); model.addAttribute("unallocatedPhysicalPorts", unallocatedPorts); if (!model.containsAttribute("movePhysicalPortCommand")) { // Only add when not present. Otherwise validatione errors are // automagically removed by Spring :( model.addAttribute("movePhysicalPortCommand", new MovePhysicalPortCommand(port)); } return PAGE_URL + "/move"; }
private void validatePort(String stpId, String attribute, RichUserDetails user) throws ServiceException { final VirtualPort port = virtualPortService.findByNsiStpId(stpId); if (port == null) { log.warn("Could not find a virtual port for stpId '{}'", stpId); throw createInvalidParameterServiceException(attribute); } if (!user.getUserGroupIds().contains(port.getVirtualResourceGroup().getAdminGroup())) { log.warn("User has no rights on virtual port with stpId '{}'", stpId); throw createInvalidOrMissingUserCredentialsException(attribute); } }