Containerization feature of SO
[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 java.util.List;
24
25 import org.onap.so.db.catalog.beans.Service;
26 import org.onap.so.db.catalog.data.projections.InlineService;
27 import org.springframework.data.jpa.repository.JpaRepository;
28 import org.springframework.data.jpa.repository.Query;
29 import org.springframework.data.repository.query.Param;
30 import org.springframework.data.rest.core.annotation.RepositoryRestResource;
31
32 @RepositoryRestResource(collectionResourceRel = "service", path = "service", excerptProjection = InlineService.class)
33 public interface ServiceRepository extends JpaRepository<Service, String> {
34         List<Service> findByModelName(String modelName);
35
36         Service findOneByModelName(String modelName);
37
38         /**
39          * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
40          * @param modelName
41          * @return
42          */
43         @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)
44         Service findFirstByModelNameOrderByModelVersionDesc(String modelName);
45
46         /**
47          * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
48          * @param modelName
49          * @return
50          */
51         @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)
52         Service findByModelNameOrderByModelVersionDesc(String modelName);
53
54         Service findOneByModelNameAndModelVersion(String modelName, String modelVersion);
55
56         Service findByModelNameAndModelVersion(String modelName, String modelVersion);
57
58         Service findByServiceType(String serviceType);
59
60         /**
61          * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
62          * @param modelName
63          * @return
64          */
65         @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)
66         Service findFirstOneByModelUUIDOrderByModelVersionDesc(String modelUUID);
67
68         /**
69          * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
70          * @param modelName
71          * @return
72          */
73         @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)
74         Service findOneByModelUUIDOrderByModelVersionDesc(String modelUUID);
75
76         Service findByModelVersionAndModelInvariantUUID(@Param("MODEL_VERSION") String modelVersion,
77                         @Param("MODEL_INVARIANT_UUID") String modelInvariantUUID);
78
79         /**
80          * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
81          * @param modelName
82          * @return
83          */
84         @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)
85         Service findFirstByModelInvariantUUIDOrderByModelVersionDesc(String modelInvariantUUID);
86
87         List<Service> findByModelUUID(String modelUUID);
88
89         Service findOneByModelUUID(String modelUUID);
90
91         /**
92          * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
93          * @param modelInvariantId
94          * @return
95          */
96         @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)
97         List<Service> findByModelInvariantUUIDOrderByModelVersionDesc(String modelInvariantId);
98 }