@RequestMapping(value = "create", params = ID_KEY, method = RequestMethod.GET)
  public String createForm(@RequestParam(ID_KEY) String nmsPortId, Model model) {
    Optional<NbiPort> maybeNbiPort = physicalPortService.findNbiPort(nmsPortId);
    if (!maybeNbiPort.isPresent()) {
      return "redirect:";
    }

    NbiPort nbiPort = maybeNbiPort.get();

    model.addAttribute("interfaceTypes", availableInterfaceTypes(nbiPort));
    model.addAttribute("availableTopologies", physicalPortService.findTopologyNames());
    model.addAttribute("vlanRequired", nbiPort.isVlanRequired());
    model.addAttribute(
        "createPhysicalPortCommand",
        new CreatePhysicalPortCommand(nbiPort, bodEnvironment.getBodTopologyName()));

    return PAGE_URL + CREATE;
  }
  @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(method = RequestMethod.POST)
  public String create(
      @Valid CreatePhysicalPortCommand command,
      BindingResult result,
      RedirectAttributes redirectAttributes,
      Model model) {
    PhysicalPort physicalPort = physicalPortService.findByBodPortId(command.getBodPortId());
    if (physicalPort != null) {
      result.rejectValue("bodPortId", "validation.not.unique");
    }

    Optional<NbiPort> maybeNbiPort = physicalPortService.findNbiPort(command.getNmsPortId());
    if (!maybeNbiPort.isPresent()) {
      return "redirect:";
    }

    NbiPort nbiPort = maybeNbiPort.get();

    command.validate(nbiPort, bodEnvironment.getBodTopologyName(), result);

    if (result.hasErrors()) {
      model.addAttribute("interfaceTypes", availableInterfaceTypes(nbiPort));
      model.addAttribute("availableTopologies", physicalPortService.findTopologyNames());
      model.addAttribute("vlanRequired", nbiPort.isVlanRequired());
      model.addAttribute("createPhysicalPortCommand", command);

      return PAGE_URL + CREATE;
    }

    PhysicalPort port;
    switch (command.getInterfaceType()) {
      case E_NNI:
        port = createEnniPort(command, nbiPort);

        messageManager.addInfoFlashMessage(
            redirectAttributes, "info_physicalport_enni_created", port.getNocLabel());

        break;
      case UNI:
        UniPort uniPort = createUniPort(command, nbiPort);

        messageManager.addInfoFlashMessage(
            redirectAttributes,
            "info_physicalport_uni_created",
            uniPort.getNocLabel(),
            uniPort.getPhysicalResourceGroup().getName());

        port = uniPort;
        break;
      default:
        throw new IllegalArgumentException("unknown interface type " + command.getInterfaceType());
    }

    try {
      physicalPortService.save(port);
    } catch (OverlappingSubportAllocationException e) {
      result.reject(e.getMessage());
      model.addAttribute("interfaceTypes", availableInterfaceTypes(nbiPort));
      model.addAttribute("availableTopologies", physicalPortService.findTopologyNames());
      model.addAttribute("vlanRequired", nbiPort.isVlanRequired());
      model.addAttribute("createPhysicalPortCommand", command);

      return PAGE_URL + CREATE;
    }

    return redirectPortListPage(port);
  }