6d432c443cd6bf7f4eab207a60b973a999f9fb0e
[so.git] / mso-catalog-db / src / main / java / org / onap / so / db / catalog / data / repository / ServiceRepository.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.db.catalog.data.repository;
22
23 import org.onap.so.db.catalog.beans.Service;
24 import org.onap.so.db.catalog.data.projections.InlineService;
25 import org.springframework.data.jpa.repository.JpaRepository;
26 import org.springframework.data.jpa.repository.Query;
27 import org.springframework.data.rest.core.annotation.RepositoryRestResource;
28
29 import java.util.List;
30
31 @RepositoryRestResource(collectionResourceRel = "service", path = "service", excerptProjection = InlineService.class)
32 public interface ServiceRepository extends JpaRepository<Service, String> {
33         List<Service> findByModelName(String modelName);
34
35         Service findOneByModelName(String modelName);
36
37         /**
38          * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
39          * @param modelName
40          * @return
41          */
42         @Query(value = "SELECT * FROM service WHERE MODEL_NAME = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC LIMIT 1;", nativeQuery = true)
43         Service findFirstByModelNameOrderByModelVersionDesc(String modelName);
44
45         /**
46          * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
47          * @param modelName
48          * @return
49          */
50         @Query(value = "SELECT * FROM service WHERE MODEL_NAME = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC LIMIT 1;", nativeQuery = true)
51         Service findByModelNameOrderByModelVersionDesc(String modelName);
52
53         Service findOneByModelNameAndModelVersion(String modelName, String modelVersion);
54
55         Service findByModelNameAndModelVersion(String modelName, String modelVersion);
56
57         Service findByServiceType(String serviceType);
58
59         /**
60          * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
61          * @param modelUUID
62          * @return
63          */
64         @Query(value = "SELECT * FROM service WHERE MODEL_UUID = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC LIMIT 1;", nativeQuery = true)
65         Service findFirstOneByModelUUIDOrderByModelVersionDesc(String modelUUID);
66
67         /**
68          * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
69          * @param modelUUID
70          * @return
71          */
72         @Query(value = "SELECT * FROM service WHERE MODEL_UUID = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC LIMIT 1;", nativeQuery = true)
73         Service findOneByModelUUIDOrderByModelVersionDesc(String modelUUID);
74
75         Service findFirstByModelVersionAndModelInvariantUUID(String modelVersion, String modelInvariantUUID);
76
77         /**
78          * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
79          * @param modelInvariantUUID
80          * @return
81          */
82         @Query(value = "SELECT * FROM service WHERE MODEL_INVARIANT_UUID = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC LIMIT 1;", nativeQuery = true)
83         Service findFirstByModelInvariantUUIDOrderByModelVersionDesc(String modelInvariantUUID);
84
85         List<Service> findByModelUUID(String modelUUID);
86
87         Service findOneByModelUUID(String modelUUID);
88
89         /**
90          * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
91          * @param modelInvariantUUID
92          * @return
93          */
94         @Query(value = "SELECT * FROM service WHERE MODEL_INVARIANT_UUID = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC;", nativeQuery = true)
95         List<Service> findByModelInvariantUUIDOrderByModelVersionDesc(String modelInvariantUUID);
96 }