protected CreatePhysicalPortCommand(UniPort port) {
   setNmsPortId(port.getNmsPortId());
   setNocLabel(port.getNocLabel());
   setBodPortId(port.getBodPortId());
   setManagerLabel(port.hasManagerLabel() ? port.getManagerLabel() : "");
   setPhysicalResourceGroup(port.getPhysicalResourceGroup());
   setTopologyName(port.getTopologyName());
 }
  @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);
  }