Added oparent to sdc main
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / dao / cassandra / schema / tables / MigrationTasksTableDescription.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 import static org.openecomp.sdc.be.dao.cassandra.schema.tables.MigrationTasksTableDescription.SdcRepoFieldsDescription.MAJOR_VERSION;
31 import static org.openecomp.sdc.be.dao.cassandra.schema.tables.MigrationTasksTableDescription.SdcRepoFieldsDescription.MINOR_VERSION;
32
33 public class MigrationTasksTableDescription implements ITableDescription {
34
35     private static final String MIGRATION_TASKS_TABLE = "migrationTasks";
36
37     @Override
38     public List<ImmutablePair<String, DataType>> primaryKeys() {
39         return Collections.singletonList(ImmutablePair.of(MAJOR_VERSION.getFieldName(), MAJOR_VERSION.getFieldType()));
40     }
41
42     @Override
43     public List<ImmutablePair<String, DataType>> clusteringKeys() {
44         return Collections.singletonList(ImmutablePair.of(MINOR_VERSION.getFieldName(), MINOR_VERSION.getFieldType()));
45     }
46
47     @Override
48     public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() {
49         Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>();
50         Arrays.stream(SdcRepoFieldsDescription.values())
51                 .filter(column -> !column.equals(MAJOR_VERSION) && !column.equals(MINOR_VERSION))
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 MIGRATION_TASKS_TABLE;
64     }
65
66     enum SdcRepoFieldsDescription {
67         MAJOR_VERSION("major_version", DataType.bigint(), true),
68         MINOR_VERSION("minor_version", DataType.bigint(), false),
69         TIMESTAMP("timestamp", DataType.timestamp(), false),
70         NAME("task_name", DataType.varchar(), false),
71         STATUS("task_status", DataType.varchar(), false),
72         MESSAGE("msg", DataType.varchar(), false),
73         DESCRIPTION("description", DataType.varchar(), false),
74         EXECUTION_TIME("execution_time", DataType.cdouble(), false);
75
76         private String fieldName;
77         private boolean isIndexed;
78         private DataType fieldType;
79
80         SdcRepoFieldsDescription(String fieldName, DataType dataType, boolean indexed ) {
81             this.fieldName = fieldName;
82             this.fieldType = dataType;
83             this.isIndexed = indexed;
84         }
85
86         public String getFieldName() {
87             return fieldName;
88         }
89
90         public boolean isIndexed() {
91             return isIndexed;
92         }
93
94         public DataType getFieldType() {
95             return fieldType;
96         }
97     }
98 }