859dab9a9f98d1c48c8d8998b2f559593fb25c5a
[cps.git] / cps-service / src / main / java / org / onap / cps / api / impl / YangTextSchemaSourceSetCache.java
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Pantheon.tech
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
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  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.onap.cps.api.impl;
21
22 import com.google.errorprone.annotations.CanIgnoreReturnValue;
23 import java.util.Map;
24 import org.onap.cps.spi.CpsModulePersistenceService;
25 import org.onap.cps.yang.YangTextSchemaSourceSet;
26 import org.onap.cps.yang.YangTextSchemaSourceSetBuilder;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.cache.annotation.CacheConfig;
29 import org.springframework.cache.annotation.CachePut;
30 import org.springframework.cache.annotation.Cacheable;
31 import org.springframework.stereotype.Service;
32
33 /**
34  * Provides cached YangTextSchemaSourceSet.
35  */
36 @Service
37 @CacheConfig(cacheNames = {"yangSchema"})
38 public class YangTextSchemaSourceSetCache {
39
40     @Autowired
41     private CpsModulePersistenceService cpsModulePersistenceService;
42
43     /**
44      * Cache YangTextSchemaSourceSet.
45      *
46      * @param dataspaceName dataspace name
47      * @param schemaSetName schema set name
48      * @return YangTextSchemaSourceSet
49      */
50     @Cacheable(key = "#p0.concat('-').concat(#p1)")
51     public YangTextSchemaSourceSet get(final String dataspaceName, final String schemaSetName) {
52         final Map<String, String> yangResourceNameToContent =
53                 cpsModulePersistenceService.getYangSchemaResources(dataspaceName, schemaSetName);
54         return YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent);
55     }
56
57     /**
58      * Updates cache YangTextSchemaSourceSet.
59      *
60      * @param dataspaceName dataspace name
61      * @param schemaSetName schema set name
62      * @param yangTextSchemaSourceSet yangTextSchemaSourceSet
63      * @return YangTextSchemaSourceSet
64      */
65     @CachePut(key = "#p0.concat('-').concat(#p1)")
66     @CanIgnoreReturnValue
67     public YangTextSchemaSourceSet updateCache(final String dataspaceName, final String schemaSetName,
68             final YangTextSchemaSourceSet yangTextSchemaSourceSet) {
69         return yangTextSchemaSourceSet;
70     }
71 }