MaintenancePolicyServiceImpl.java

  1. /*
  2.  * Copyright 2020 Global Crop Diversity Trust
  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.gringlobal.service.impl;

  17. import lombok.extern.slf4j.Slf4j;
  18. import org.gringlobal.custom.elasticsearch.SearchException;
  19. import org.gringlobal.model.InventoryMaintenancePolicy;
  20. import org.gringlobal.persistence.InventoryMaintenancePolicyRepository;
  21. import org.gringlobal.service.MaintenancePolicyService;
  22. import org.gringlobal.service.filter.InventoryMaintenancePolicyFilter;
  23. import org.springframework.data.domain.Page;
  24. import org.springframework.data.domain.Pageable;
  25. import org.springframework.stereotype.Service;
  26. import org.springframework.transaction.annotation.Transactional;

  27. /**
  28.  * @author Maxym Borodenko
  29.  */
  30. @Service
  31. @Transactional(readOnly = true)
  32. @Slf4j
  33. public class MaintenancePolicyServiceImpl extends FilteredCRUDServiceImpl<InventoryMaintenancePolicy, InventoryMaintenancePolicyFilter, InventoryMaintenancePolicyRepository> implements MaintenancePolicyService {

  34.     @Override
  35.     @Transactional
  36.     public InventoryMaintenancePolicy update(final InventoryMaintenancePolicy input, InventoryMaintenancePolicy target) {
  37.         log.debug("Update maintenance policy. Input data {}", input);
  38.         target.apply(input);

  39.         InventoryMaintenancePolicy saved = repository.save(target);
  40.         return _lazyLoad(saved);
  41.     }

  42.     @Override
  43.     @Transactional
  44.     public InventoryMaintenancePolicy create(final InventoryMaintenancePolicy source) {
  45.         log.debug("Create maintenance policy. Input data {}", source);
  46.         InventoryMaintenancePolicy maintenancePolicy = new InventoryMaintenancePolicy();
  47.         maintenancePolicy.apply(source);

  48.         InventoryMaintenancePolicy saved = repository.save(maintenancePolicy);
  49.         saved.lazyLoad();

  50.         return saved;
  51.     }

  52.     @Override
  53.     public Page<InventoryMaintenancePolicy> list(InventoryMaintenancePolicyFilter filter, Pageable page) throws SearchException {
  54.         return super.list(InventoryMaintenancePolicy.class, filter, page);
  55.     }
  56. }