private UniPort createUniPort(CreatePhysicalPortCommand command, NbiPort nbiPort) {
    UniPort uniPort = new UniPort(nbiPort);

    uniPort.setNocLabel(command.getNocLabel());
    uniPort.setBodPortId(command.getBodPortId());
    if (Strings.isNullOrEmpty(command.getManagerLabel())) {
      uniPort.setManagerLabel(null);
    } else {
      uniPort.setManagerLabel(command.getManagerLabel());
    }
    uniPort.setPhysicalResourceGroup(command.getPhysicalResourceGroup());
    uniPort.setTopologyName(bodEnvironment.getBodTopologyName());
    return uniPort;
  }
  @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;
  }
 @ModelAttribute("bodTopologyName")
 public String bodTopologyName() {
   return bodEnvironment.getBodTopologyName();
 }
  @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);
  }