View Javadoc
1   package net.sumaris.core.service.referential.taxon;
2   
3   /*-
4    * #%L
5    * SUMARiS:: Core
6    * %%
7    * Copyright (C) 2018 - 2019 SUMARiS Consortium
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import net.sumaris.core.dao.referential.taxon.TaxonGroupRepository;
26  import net.sumaris.core.dao.technical.SortDirection;
27  import net.sumaris.core.service.schema.DatabaseSchemaService;
28  import net.sumaris.core.vo.filter.ReferentialFilterVO;
29  import net.sumaris.core.vo.referential.TaxonGroupVO;
30  import org.nuiton.version.Version;
31  import org.nuiton.version.VersionBuilder;
32  import org.slf4j.Logger;
33  import org.slf4j.LoggerFactory;
34  import org.springframework.beans.factory.annotation.Autowired;
35  import org.springframework.stereotype.Service;
36  
37  import javax.annotation.PostConstruct;
38  import java.util.List;
39  import java.util.stream.Collectors;
40  
41  @Service("taxonGroupService")
42  public class TaxonGroupServiceImpl implements TaxonGroupService {
43  
44      private static final Logger log = LoggerFactory.getLogger(TaxonGroupServiceImpl.class);
45  
46      @Autowired
47      protected TaxonGroupRepository taxonGroupRepository;
48  
49      @Autowired
50      protected TaxonGroupService self;
51  
52      @Autowired
53      protected DatabaseSchemaService databaseSchemaService;
54  
55      @PostConstruct
56      protected void afterPropertiesSet() {
57  
58          // Check version
59          Version minVersion = VersionBuilder.create("0.15.0").build();
60          Version dbVersion = databaseSchemaService.getDbVersion();
61  
62          if (dbVersion == null) {
63              log.info("/!\\ Skipping taxon group hierarchy update, because database schema version is unknown. Please restart after schema update.");
64          }
65  
66          else if (dbVersion.before(minVersion)) {
67              log.info("/!\\ Skipping taxon group hierarchy update, because database schema version < 0.15.0. Please restart after schema update.");
68          }
69  
70          // Fill taxon group hierarchy
71          else {
72              self.updateTaxonGroupHierarchies();
73          }
74      }
75  
76      @Override
77      public void updateTaxonGroupHierarchies() {
78  
79          taxonGroupRepository.updateTaxonGroupHierarchies();
80      }
81  
82      @Override
83      public List<TaxonGroupVO> findTargetSpeciesByFilter(ReferentialFilterVO filter,
84                                             int offset,
85                                             int size,
86                                             String sortAttribute,
87                                             SortDirection sortDirection) {
88          return taxonGroupRepository.findTargetSpeciesByFilter(filter, offset, size, sortAttribute, sortDirection);
89      }
90  }