Merge "added test file to test ExternalkeyValidator.java"
[ccsdk/apps.git] / ms / neng / src / main / java / org / onap / ccsdk / apps / ms / neng / core / persistence / NamePersister.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK.apps
4  * ================================================================================
5  * Copyright (C) 2018 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.ccsdk.apps.ms.neng.core.persistence;
22
23 import org.onap.ccsdk.apps.ms.neng.persistence.entity.GeneratedName;
24 import org.onap.ccsdk.apps.ms.neng.persistence.repository.GeneratedNameRespository;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.stereotype.Component;
27
28 /**
29  * Manages the persistence of generated names using a DB.
30  */
31 @Component
32 public class NamePersister {
33     @Autowired
34     GeneratedNameRespository repository;
35
36     /**
37      * Persist the given name.
38      */
39     public void persist(GeneratedName name) throws Exception {
40         repository.save(name);
41     }
42
43     /**
44      * Finds a name stored in the DB of the given type, name, and the 'isReleased' flag. 
45      * 
46      * @param elementType    The type of the name
47      * @param name           A name
48      * @param isReleased     An Y/N flag indicating if the name is released or not
49      */
50     public GeneratedName findByElementTypeAndNameAndReleased(String elementType, String name, String isReleased) {
51         return repository.findByElementTypeAndNameAndIsReleased(elementType, name, isReleased);
52     }
53
54     /**
55      * Finds a name stored in the DB of the given external ID and type.
56      * 
57      * @param externalId     The external ID
58      * @param elementType    The type of the name
59      */
60     public GeneratedName findByExternalIdAndElementType(String externalId, String elementType) {
61         return repository.findByExternalIdAndRelaxedElementType(externalId, elementType);
62     }
63 }