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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
21 package org.oran.smo.teiv.pgsqlgenerator.schema.consumerdata;
24 import java.io.IOException;
25 import java.nio.file.Files;
26 import java.nio.file.Path;
27 import java.nio.file.Paths;
28 import java.nio.file.StandardCopyOption;
29 import java.util.List;
31 import lombok.RequiredArgsConstructor;
32 import lombok.extern.slf4j.Slf4j;
33 import org.springframework.beans.factory.annotation.Value;
34 import org.springframework.stereotype.Component;
35 import org.oran.smo.teiv.pgsqlgenerator.Entity;
36 import org.oran.smo.teiv.pgsqlgenerator.Module;
37 import org.oran.smo.teiv.pgsqlgenerator.PgSchemaGeneratorException;
38 import org.oran.smo.teiv.pgsqlgenerator.Relationship;
39 import org.oran.smo.teiv.pgsqlgenerator.schema.BackwardCompatibilityChecker;
40 import org.oran.smo.teiv.pgsqlgenerator.schema.SchemaGenerator;
41 import org.springframework.util.ResourceUtils;
45 @RequiredArgsConstructor
46 public class ConsumerDataSchemaGenerator extends SchemaGenerator {
47 private final BackwardCompatibilityChecker backwardCompatibilityChecker;
49 @Value("${schema.consumer-data.baseline}")
50 private String baselineConsumerDataSchema;
51 @Value("${schema.consumer-data.output}")
52 private String outputConsumerDataSchema;
53 @Value("${schema.consumer-data.skeleton}")
54 private String skeletonConsumerDataSchema;
57 protected void prepareSchema() {
59 final File skeletonFile = ResourceUtils.getFile("classpath:" + skeletonConsumerDataSchema);
60 backwardCompatibilityChecker.checkForNBCChangesInConsumerDataSchema(baselineConsumerDataSchema, skeletonFile
63 final Path destinationPath = Paths.get(outputConsumerDataSchema);
64 Files.copy(skeletonFile.toPath(), destinationPath, StandardCopyOption.REPLACE_EXISTING);
65 this.schema = destinationPath.toFile();
66 } catch (IOException exception) {
67 throw PgSchemaGeneratorException.prepareBaselineException("ties.consumer-data", exception);
72 protected void setSqlStatements(List<Module> modules, List<Entity> entities, List<Relationship> relationships) {