/**
  * Populate an instance of vcenter with the provided vcenter parameter
  *
  * @param vcenter the vcenter to be populated
  * @param param the parameter that contains the attributes.
  */
 protected void populateVcenterData(Vcenter vcenter, VcenterParam param) {
   vcenter.setLabel(param.getName());
   vcenter.setOsVersion(param.getOsVersion());
   vcenter.setUsername(param.getUserName());
   vcenter.setPassword(param.getPassword());
   vcenter.setIpAddress(param.findIpAddress());
   vcenter.setPortNumber(param.getPortNumber());
   vcenter.setUseSSL(param.getUseSsl());
 }
  /**
   * Validates vCenter user credentials from create or update parameters.
   *
   * @param param either vCenter create or update param.
   * @param vcenter vCenter object.
   */
  private void validateVcenterCredentials(VcenterParam param, Vcenter vcenter) {
    if (StringUtils.isBlank(param.getPassword()) && vcenter != null) {
      param.setPassword(StringUtils.trimToNull(vcenter.getPassword()));
    }

    if (StringUtils.isBlank(param.getUserName()) && vcenter != null) {
      param.setUserName(StringUtils.trimToNull(vcenter.getUsername()));
    }

    ArgValidator.checkFieldNotNull(param.getUserName(), "username");
    ArgValidator.checkFieldNotNull(param.getPassword(), "password");
  }
 /**
  * Creates a new instance of vcenter.
  *
  * @param tenant the vcenter parent tenant organization
  * @param param the input parameter containing the vcenter attributes
  * @return an instance of {@link Vcenter}
  */
 protected Vcenter createNewVcenter(TenantOrg tenant, VcenterParam param) {
   Vcenter vcenter = new Vcenter();
   vcenter.setId(URIUtil.createId(Vcenter.class));
   addVcenterAclIfTenantAdmin(tenant, vcenter);
   populateVcenterData(vcenter, param);
   if (isSystemAdmin()) {
     // Since, the creating user is either SysAdmin make the tenantCreated
     // flag to false.
     vcenter.setTenantCreated(Boolean.FALSE);
   } else {
     // Since the creating user is a TenantAdmin, just make the vCenter
     // as a tenant created resource by default. When the SecAdmin or
     // SysAdmin adds any new tenant then the vCenter will be shared
     // across those tenants.
     _log.debug("Tenant admin creates the vCenter {}", param.getName());
     vcenter.setTenantCreated(Boolean.TRUE);
   }
   return vcenter;
 }
  /**
   * Validates the create/update vCenter input data
   *
   * @param param the input parameter
   * @param vcenter the vcenter being updated in case of update operation. This parameter must be
   *     null for create operations.
   */
  protected void validateVcenter(VcenterParam param, Vcenter vcenter, Boolean validateConnection) {
    if (vcenter == null
        || (param.findIpAddress() != null
            && !param.findIpAddress().equals(vcenter.getIpAddress()))) {
      checkDuplicateAltId(Vcenter.class, "ipAddress", param.findIpAddress(), "vcenter");
    }
    if (vcenter == null
        || (param.getName() != null && !param.getName().equals(vcenter.getLabel()))) {
      checkDuplicateLabel(Vcenter.class, param.getName(), "vcenter");
    }
    validateVcenterCredentials(param, vcenter);

    if (validateConnection != null && validateConnection == true) {
      String errorMessage = VCenterConnectionValidator.isVCenterConnectionValid(param);
      if (StringUtils.isNotBlank(errorMessage)) {
        throw APIException.badRequests.invalidVCenterConnection(errorMessage);
      }
    }
  }