/**
   * Validates that the existance of the building room number is consistent with the asset type
   * requirements.
   *
   * @param roomNumber
   * @param detail
   * @prarm asset
   * @return boolean
   * @deprecated this method is replaced by
   *     validateBuildingCodeAndRoomNumber(BarcodeInventoryErrorDetail, Asset)
   */
  @Deprecated
  protected boolean validateBuildingRoomNumber(
      String roomNumber, BarcodeInventoryErrorDetail detail, Asset asset) {
    boolean result = true;
    String label =
        SpringContext.getBean(DataDictionaryService.class)
            .getDataDictionary()
            .getBusinessObjectEntry(BarcodeInventoryErrorDetail.class.getName())
            .getAttributeDefinition(CamsPropertyConstants.BarcodeInventory.BUILDING_ROOM_NUMBER)
            .getLabel();
    // String description = asset.getCapitalAssetType().getCapitalAssetTypeDescription();
    String description = asset.getCapitalAssetTypeCode();

    // if the asset has empty building room number, then the BCIE should too
    if (StringUtils.isBlank(asset.getBuildingRoomNumber())) {
      if (StringUtils.isNotBlank(roomNumber)) {
        GlobalVariables.getMessageMap()
            .putError(
                CamsPropertyConstants.BarcodeInventory.BUILDING_ROOM_NUMBER,
                CamsKeyConstants.BarcodeInventory.ERROR_NOT_ALLOWED_FIELD,
                label,
                description);
        result &= false;
      }
    }
    // otherwise the BCIE should have a non-empty and existing active building room number
    else {
      HashMap<String, Object> fields = new HashMap<String, Object>();
      fields.put(KFSPropertyConstants.CAMPUS_CODE, detail.getCampusCode());
      fields.put(KFSPropertyConstants.BUILDING_CODE, detail.getBuildingCode());
      fields.put(KFSPropertyConstants.BUILDING_ROOM_NUMBER, detail.getBuildingRoomNumber());
      Room room = getBusinessObjectService().findByPrimaryKey(Room.class, fields);

      if (StringUtils.isBlank(roomNumber)) {
        GlobalVariables.getMessageMap()
            .putError(
                CamsPropertyConstants.BarcodeInventory.BUILDING_ROOM_NUMBER,
                CamsKeyConstants.BarcodeInventory.ERROR_REQUIRED_FIELD,
                label,
                description);
        result &= false;
      } else if (ObjectUtils.isNull(room)) {
        GlobalVariables.getMessageMap()
            .putError(
                CamsPropertyConstants.BarcodeInventory.BUILDING_ROOM_NUMBER,
                CamsKeyConstants.BarcodeInventory.ERROR_INVALID_FIELD,
                label);
        result = false;
      } else if (!room.isActive()) {
        GlobalVariables.getMessageMap()
            .putError(
                CamsPropertyConstants.BarcodeInventory.BUILDING_ROOM_NUMBER,
                CamsKeyConstants.BarcodeInventory.ERROR_INACTIVE_FIELD,
                label);
        result &= false;
      }
    }

    return result;
  }
  /**
   * Validates that the existance of the building code and room number is consistent with the asset
   * type requirements.
   *
   * @param detail
   * @prarm asset
   * @return boolean
   */
  protected boolean validateBuildingCodeAndRoomNumber(
      BarcodeInventoryErrorDetail detail, Asset asset) {
    boolean result = true;

    String campusCode = detail.getCampusCode();
    String buildingCode = detail.getBuildingCode();
    String roomNumber = detail.getBuildingRoomNumber();
    String labelBuilding =
        SpringContext.getBean(DataDictionaryService.class)
            .getDataDictionary()
            .getBusinessObjectEntry(BarcodeInventoryErrorDetail.class.getName())
            .getAttributeDefinition(CamsPropertyConstants.BarcodeInventory.BUILDING_CODE)
            .getLabel();
    String labelRoom =
        SpringContext.getBean(DataDictionaryService.class)
            .getDataDictionary()
            .getBusinessObjectEntry(BarcodeInventoryErrorDetail.class.getName())
            .getAttributeDefinition(CamsPropertyConstants.BarcodeInventory.BUILDING_ROOM_NUMBER)
            .getLabel();

    String assetTypeCode = asset.getCapitalAssetTypeCode();
    AssetType assetType = asset.getCapitalAssetType();

    // retrieve building
    HashMap<String, Object> fields = new HashMap<String, Object>();
    fields.put(KFSPropertyConstants.CAMPUS_CODE, campusCode);
    fields.put(KFSPropertyConstants.BUILDING_CODE, buildingCode);
    Building building = getBusinessObjectService().findByPrimaryKey(Building.class, fields);

    // retrieve room
    fields.put(KFSPropertyConstants.BUILDING_ROOM_NUMBER, roomNumber);
    Room room = getBusinessObjectService().findByPrimaryKey(Room.class, fields);

    // if movingIndicator is true and requiredBuildingIndicator is false, then both building and
    // room are required
    if (assetType.isMovingIndicator() && !assetType.isRequiredBuildingIndicator()) {
      // check building
      if (StringUtils.isBlank(buildingCode)) {
        GlobalVariables.getMessageMap()
            .putError(
                CamsPropertyConstants.BarcodeInventory.BUILDING_CODE,
                CamsKeyConstants.BarcodeInventory.ERROR_REQUIRED_FIELD,
                labelBuilding,
                assetTypeCode);
        result &= false;
      } else if (ObjectUtils.isNull(building)) {
        GlobalVariables.getMessageMap()
            .putError(
                CamsPropertyConstants.BarcodeInventory.BUILDING_CODE,
                CamsKeyConstants.BarcodeInventory.ERROR_INVALID_FIELD,
                labelBuilding);
        result &= false;
      } else if (!building.isActive()) {
        GlobalVariables.getMessageMap()
            .putError(
                CamsPropertyConstants.BarcodeInventory.BUILDING_CODE,
                CamsKeyConstants.BarcodeInventory.ERROR_INACTIVE_FIELD,
                labelBuilding);
        result &= false;
      }

      // check room
      if (StringUtils.isBlank(roomNumber)) {
        GlobalVariables.getMessageMap()
            .putError(
                CamsPropertyConstants.BarcodeInventory.BUILDING_ROOM_NUMBER,
                CamsKeyConstants.BarcodeInventory.ERROR_REQUIRED_FIELD,
                labelRoom,
                assetTypeCode);
        result &= false;
      } else if (ObjectUtils.isNull(room)) {
        GlobalVariables.getMessageMap()
            .putError(
                CamsPropertyConstants.BarcodeInventory.BUILDING_ROOM_NUMBER,
                CamsKeyConstants.BarcodeInventory.ERROR_INVALID_FIELD,
                labelRoom);
        result = false;
      } else if (!room.isActive()) {
        GlobalVariables.getMessageMap()
            .putError(
                CamsPropertyConstants.BarcodeInventory.BUILDING_ROOM_NUMBER,
                CamsKeyConstants.BarcodeInventory.ERROR_INACTIVE_FIELD,
                labelRoom);
        result &= false;
      }
    }

    // if movingIndicator is false and requiredBuildingIndicator is true, then building is required
    // while room is not allowed
    else if (!assetType.isMovingIndicator() && assetType.isRequiredBuildingIndicator()) {
      // check building
      if (StringUtils.isBlank(buildingCode)) {
        GlobalVariables.getMessageMap()
            .putError(
                CamsPropertyConstants.BarcodeInventory.BUILDING_CODE,
                CamsKeyConstants.BarcodeInventory.ERROR_REQUIRED_FIELD,
                labelBuilding,
                assetTypeCode);
        result &= false;
      } else if (ObjectUtils.isNull(building)) {
        GlobalVariables.getMessageMap()
            .putError(
                CamsPropertyConstants.BarcodeInventory.BUILDING_CODE,
                CamsKeyConstants.BarcodeInventory.ERROR_INVALID_FIELD,
                labelBuilding);
        result &= false;
      } else if (!building.isActive()) {
        GlobalVariables.getMessageMap()
            .putError(
                CamsPropertyConstants.BarcodeInventory.BUILDING_CODE,
                CamsKeyConstants.BarcodeInventory.ERROR_INACTIVE_FIELD,
                labelBuilding);
        result &= false;
      }

      // check room
      if (StringUtils.isNotBlank(roomNumber)) {
        GlobalVariables.getMessageMap()
            .putError(
                CamsPropertyConstants.BarcodeInventory.BUILDING_ROOM_NUMBER,
                CamsKeyConstants.BarcodeInventory.ERROR_NOT_ALLOWED_FIELD,
                labelRoom,
                assetTypeCode);
        result &= false;
      }
    }

    // if both movingIndicator and requiredBuildingIndicator are false, then neither building nor
    // room is allowed
    else if (!assetType.isMovingIndicator() && !assetType.isRequiredBuildingIndicator()) {
      // check building
      if (StringUtils.isNotBlank(buildingCode)) {
        GlobalVariables.getMessageMap()
            .putError(
                CamsPropertyConstants.BarcodeInventory.BUILDING_CODE,
                CamsKeyConstants.BarcodeInventory.ERROR_NOT_ALLOWED_FIELD,
                labelBuilding,
                assetTypeCode);
        result &= false;
      }

      // check room
      if (StringUtils.isNotBlank(roomNumber)) {
        GlobalVariables.getMessageMap()
            .putError(
                CamsPropertyConstants.BarcodeInventory.BUILDING_ROOM_NUMBER,
                CamsKeyConstants.BarcodeInventory.ERROR_NOT_ALLOWED_FIELD,
                labelRoom,
                assetTypeCode);
        result &= false;
      }
    }

    return result;
  }