d1ddac274c744b799e09acfd58f1ce4e9f72cee3
[smo/teiv.git] /
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2024 Ericsson
4  *  Modifications Copyright (C) 2024 OpenInfra Foundation Europe
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21 package org.oran.smo.teiv.pgsqlgenerator.schema.groups;
22
23 import org.oran.smo.teiv.pgsqlgenerator.Entity;
24 import org.oran.smo.teiv.pgsqlgenerator.FileHelper;
25 import org.oran.smo.teiv.pgsqlgenerator.Module;
26 import org.oran.smo.teiv.pgsqlgenerator.PgSchemaGeneratorException;
27 import org.oran.smo.teiv.pgsqlgenerator.Relationship;
28 import org.oran.smo.teiv.pgsqlgenerator.schema.BackwardCompatibilityChecker;
29 import org.oran.smo.teiv.pgsqlgenerator.schema.SchemaGenerator;
30 import lombok.RequiredArgsConstructor;
31 import lombok.extern.slf4j.Slf4j;
32 import org.springframework.beans.factory.annotation.Value;
33 import org.springframework.core.io.ClassPathResource;
34 import org.springframework.core.io.Resource;
35 import org.springframework.stereotype.Component;
36
37 import java.io.IOException;
38 import java.nio.file.Path;
39 import java.nio.file.Paths;
40 import java.util.List;
41
42 @Component
43 @Slf4j
44 @RequiredArgsConstructor
45 public class GroupsSchemaGenerator extends SchemaGenerator {
46     private final BackwardCompatibilityChecker backwardCompatibilityChecker;
47
48     @Value("${schema.groups.baseline}")
49     private String baselineGroupSchema;
50     @Value("${schema.groups.output}")
51     private String outputGroupSchema;
52     @Value("${schema.groups.skeleton}")
53     private String skeletonGroupSchema;
54
55     @Override
56     protected void prepareSchema() {
57         try {
58             Resource skeletonResource = new ClassPathResource(skeletonGroupSchema);
59             final Path destinationPath = Paths.get(outputGroupSchema);
60             backwardCompatibilityChecker.checkForNBCChangesInConsumerAndGroupsSchema(baselineGroupSchema, destinationPath
61                     .toFile().getAbsolutePath());
62             FileHelper.copyResourceToFile(skeletonResource, destinationPath.toFile());
63             this.schema = destinationPath.toFile();
64         } catch (IOException exception) {
65             throw PgSchemaGeneratorException.prepareBaselineException("ties.group", exception);
66         }
67     }
68
69     @Override
70     protected void setSqlStatements(List<Module> modules, List<Entity> entities, List<Relationship> relationships) {
71         //DO-NOTHING
72     }
73 }