Added oparent to sdc main
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / dao / cassandra / schema / tables / OperationalEnvironmentsTableDescription.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.dao.cassandra.schema.tables;
22
23 import com.datastax.driver.core.DataType;
24 import org.apache.commons.lang3.tuple.ImmutablePair;
25 import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription;
26 import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
27
28 import java.util.*;
29
30
31 public class OperationalEnvironmentsTableDescription implements ITableDescription {
32
33     private static final String OPERATIONAL_ENVIRONMENT_TABLE = "operationalEnvironment";
34     private static final String ENVIRONMENT_ID = "environment_id";
35
36     @Override
37     public List<ImmutablePair<String, DataType>> primaryKeys() {
38         List<ImmutablePair<String, DataType>> keys = new ArrayList<>();
39         keys.add(new ImmutablePair<>(ENVIRONMENT_ID, DataType.varchar()));
40         return keys;
41     }
42
43     @Override
44     public List<ImmutablePair<String, DataType>> clusteringKeys() {
45         return new LinkedList<>();
46     }
47
48     @Override
49     public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() {
50         Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>();
51         Arrays.stream(SdcOperationalEnvironmentFieldsDescription.values())
52                 .forEach(column -> columns.put(column.getFieldName(), ImmutablePair.of(column.getFieldType(), column.isIndexed())));
53         return columns;
54     }
55
56     @Override
57     public String getKeyspace() {
58         return AuditingTypesConstants.REPO_KEYSPACE;
59     }
60
61     @Override
62     public String getTableName() {
63         return OPERATIONAL_ENVIRONMENT_TABLE;
64     }
65
66     enum SdcOperationalEnvironmentFieldsDescription {
67         //there is also PK field "environmentID"
68         TENANT("tenant", DataType.varchar(), false),
69         IS_PRODUCTION("is_production", DataType.cboolean(), false),
70         ECOMP_WORKLOAD_CONTEXT("ecomp_workload_context", DataType.varchar(), false),
71         DMAAP_UEB_ADDRESS("dmaap_ueb_address", DataType.set(DataType.varchar()), false),
72         UEB_API_KEY("ueb_api_key",DataType.varchar(), false),
73         UEB_SECRET_KEY("ueb_secret_key",DataType.varchar(), false),
74         STATUS("status",DataType.varchar() ,true),
75         LAST_MODIFIED("last_modified",DataType.timestamp() ,false);
76
77         private String fieldName;
78         private boolean isIndexed;
79         private DataType fieldType;
80
81         SdcOperationalEnvironmentFieldsDescription(String fieldName, DataType dataType, boolean indexed ) {
82             this.fieldName = fieldName;
83             this.fieldType = dataType;
84             this.isIndexed = indexed;
85         }
86
87         public String getFieldName() {
88             return fieldName;
89         }
90
91         public boolean isIndexed() {
92             return isIndexed;
93         }
94
95         public DataType getFieldType() {
96             return fieldType;
97         }
98     }
99 }