DefaultLocationStateInTransformer.java

  1. /*
  2.  * Copyright 2005-2025 the original author or authors.
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  * http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */
  16. package org.openwms.common.location.spi;

  17. import jakarta.validation.constraints.NotBlank;
  18. import org.openwms.common.location.api.ErrorCodeTransformers;
  19. import org.openwms.common.location.api.ErrorCodeVO;
  20. import org.springframework.core.annotation.Order;
  21. import org.springframework.stereotype.Component;
  22. import org.springframework.util.Assert;
  23. import org.springframework.validation.annotation.Validated;

  24. import java.util.Optional;

  25. /**
  26.  * A DefaultLocationStateInTransformer.
  27.  *
  28.  * @author Heiko Scherrer
  29.  */
  30. @Order(5)
  31. @Validated
  32. @Component
  33. class DefaultLocationStateInTransformer implements ErrorCodeTransformers.LocationStateIn {

  34.     /**
  35.      * {@inheritDoc}
  36.      */
  37.     @Override
  38.     public Optional<Boolean> available(@NotBlank String errorCode) {
  39.         Assert.hasText(errorCode, "ErrorCode must be applied");
  40.         if (errorCode.charAt(ErrorCodeVO.STATE_IN_POSITION) == 42 /* '*' */) {
  41.             return Optional.empty();
  42.         }
  43.         // A Zero in the errorCode means no errors
  44.         return Optional.of(errorCode.charAt(ErrorCodeVO.STATE_IN_POSITION) == 48 /* '0' */);
  45.     }
  46. }