AccountServiceImpl.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.account.impl;

  17. import jakarta.validation.constraints.NotBlank;
  18. import jakarta.validation.constraints.NotNull;
  19. import org.ameba.annotation.Measured;
  20. import org.ameba.annotation.TxService;
  21. import org.ameba.exception.NotFoundException;
  22. import org.ameba.i18n.Translator;
  23. import org.openwms.common.account.Account;
  24. import org.openwms.common.account.AccountService;
  25. import org.springframework.transaction.annotation.Transactional;
  26. import org.springframework.validation.annotation.Validated;

  27. import java.util.List;
  28. import java.util.Optional;

  29. import static org.openwms.common.CommonMessageCodes.ACCOUNT_NOT_FOUND_BY_PKEY;

  30. /**
  31.  * A AccountServiceImpl.
  32.  *
  33.  * @author Heiko Scherrer
  34.  */
  35. @Validated
  36. @TxService
  37. class AccountServiceImpl implements AccountService {

  38.     private final AccountRepository repository;
  39.     private final Translator translator;

  40.     AccountServiceImpl(AccountRepository repository, Translator translator) {
  41.         this.repository = repository;
  42.         this.translator = translator;
  43.     }

  44.     /**
  45.      * {@inheritDoc}
  46.      */
  47.     @Measured
  48.     @Transactional(readOnly = true)
  49.     @Override
  50.     public @NotNull List<Account> findAll() {
  51.         return repository.findAll();
  52.     }

  53.     /**
  54.      * {@inheritDoc}
  55.      */
  56.     @Measured
  57.     @Transactional(readOnly = true)
  58.     @Override
  59.     public @NotNull Account findByPKey(@NotBlank String pKey) {
  60.         return repository.findBypKey(pKey)
  61.                 .orElseThrow(() -> new NotFoundException(translator, ACCOUNT_NOT_FOUND_BY_PKEY, new String[]{pKey}, pKey));
  62.     }

  63.     /**
  64.      * {@inheritDoc}
  65.      */
  66.     @Measured
  67.     @Transactional(readOnly = true)
  68.     @Override
  69.     public Optional<Account> findByIdentifier(@NotBlank String identifier) {
  70.         return repository.findByIdentifier(identifier);
  71.     }

  72.     /**
  73.      * {@inheritDoc}
  74.      */
  75.     @Measured
  76.     @Transactional(readOnly = true)
  77.     @Override
  78.     public Optional<Account> findByName(@NotBlank String name) {
  79.         return repository.findByName(name);
  80.     }

  81.     /**
  82.      * {@inheritDoc}
  83.      */
  84.     @Measured
  85.     @Transactional(readOnly = true)
  86.     @Override
  87.     public Optional<Account> findDefault() {
  88.         return repository.findByDefaultAccount(true);
  89.     }
  90. }