Add models imports endpoint and persistence structure
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / dao / cassandra / schema / tables / ToscaImportByModelTableDescription.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation
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.openecomp.sdc.be.dao.cassandra.schema.tables;
21
22 import com.datastax.driver.core.DataType;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.stream.Collectors;
27 import java.util.stream.Stream;
28 import lombok.AllArgsConstructor;
29 import lombok.Getter;
30 import org.apache.commons.lang3.tuple.ImmutablePair;
31 import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription;
32 import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
33
34 public class ToscaImportByModelTableDescription implements ITableDescription {
35
36     private static final String MODEL_ID = "model_id";
37     private static final String FULL_PATH = "full_path";
38
39     @Override
40     public List<ImmutablePair<String, DataType>> primaryKeys() {
41         return List.of(
42             new ImmutablePair<>(MODEL_ID, DataType.varchar()),
43             new ImmutablePair<>(FULL_PATH, DataType.varchar())
44         );
45     }
46
47     @Override
48     public List<ImmutablePair<String, DataType>> clusteringKeys() {
49         return Collections.emptyList();
50     }
51
52     @Override
53     public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() {
54         return Stream.of(SdcSchemaFilesFieldsDescription.values())
55             .collect(Collectors.toMap(SdcSchemaFilesFieldsDescription::getName, field -> new ImmutablePair<>(field.type, field.indexed)));
56     }
57
58     @Override
59     public String getKeyspace() {
60         return AuditingTypesConstants.ARTIFACT_KEYSPACE;
61     }
62
63     @Override
64     public String getTableName() {
65         return "tosca_import_by_model";
66     }
67
68     @Getter
69     @AllArgsConstructor
70     enum SdcSchemaFilesFieldsDescription {
71         MODEL_ID("model_id", DataType.varchar(), true),
72         CONTENT("content", DataType.varchar(), false);
73
74         private final String name;
75         private final DataType type;
76         private final boolean indexed;
77     }
78 }