86a3254fd8810a24ad18a9f541ca68724a22f877
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021, 2025 OpenInfra Foundation Europe. All rights reserved.
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  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.clamp.models.acm.persistence.concepts;
22
23 import jakarta.persistence.AttributeConverter;
24 import jakarta.persistence.Converter;
25 import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate;
26
27 @Converter(autoApply = true)
28 public class StringToServiceTemplateConverter extends AbstractConverter
29         implements AttributeConverter<DocToscaServiceTemplate, String> {
30
31     @Override
32     public String convertToDatabaseColumn(DocToscaServiceTemplate serviceTemplate) {
33         return encode(serviceTemplate);
34     }
35
36     @Override
37     public DocToscaServiceTemplate convertToEntityAttribute(String dbData) {
38         if (dbData == null) {
39             return new DocToscaServiceTemplate();
40         }
41         return decode(dbData, DocToscaServiceTemplate.class);
42     }
43 }