re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / dao / cassandra / schema / tables / MigrationTasksTableDescription.java
1 package org.openecomp.sdc.be.dao.cassandra.schema.tables;
2
3 import com.datastax.driver.core.DataType;
4 import org.apache.commons.lang3.tuple.ImmutablePair;
5 import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription;
6 import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
7
8 import java.util.*;
9
10 import static org.openecomp.sdc.be.dao.cassandra.schema.tables.MigrationTasksTableDescription.SdcRepoFieldsDescription.MAJOR_VERSION;
11 import static org.openecomp.sdc.be.dao.cassandra.schema.tables.MigrationTasksTableDescription.SdcRepoFieldsDescription.MINOR_VERSION;
12
13 public class MigrationTasksTableDescription implements ITableDescription {
14
15     private static final String MIGRATION_TASKS_TABLE = "migrationTasks";
16
17     @Override
18     public List<ImmutablePair<String, DataType>> primaryKeys() {
19         return Collections.singletonList(ImmutablePair.of(MAJOR_VERSION.getFieldName(), MAJOR_VERSION.getFieldType()));
20     }
21
22     @Override
23     public List<ImmutablePair<String, DataType>> clusteringKeys() {
24         return Collections.singletonList(ImmutablePair.of(MINOR_VERSION.getFieldName(), MINOR_VERSION.getFieldType()));
25     }
26
27     @Override
28     public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() {
29         Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>();
30         Arrays.stream(SdcRepoFieldsDescription.values())
31                 .filter(column -> !column.equals(MAJOR_VERSION) && !column.equals(MINOR_VERSION))
32                 .forEach(column -> columns.put(column.getFieldName(), ImmutablePair.of(column.getFieldType(), column.isIndexed())));
33         return columns;
34     }
35
36     @Override
37     public String getKeyspace() {
38         return AuditingTypesConstants.REPO_KEYSPACE;
39     }
40
41     @Override
42     public String getTableName() {
43         return MIGRATION_TASKS_TABLE;
44     }
45
46     enum SdcRepoFieldsDescription {
47         MAJOR_VERSION("major_version", DataType.bigint(), true),
48         MINOR_VERSION("minor_version", DataType.bigint(), false),
49         TIMESTAMP("timestamp", DataType.timestamp(), false),
50         NAME("task_name", DataType.varchar(), false),
51         STATUS("task_status", DataType.varchar(), false),
52         MESSAGE("msg", DataType.varchar(), false),
53         DESCRIPTION("description", DataType.varchar(), false),
54         EXECUTION_TIME("execution_time", DataType.cdouble(), false);
55
56         private String fieldName;
57         private boolean isIndexed;
58         private DataType fieldType;
59
60         SdcRepoFieldsDescription(String fieldName, DataType dataType, boolean indexed ) {
61             this.fieldName = fieldName;
62             this.fieldType = dataType;
63             this.isIndexed = indexed;
64         }
65
66         public String getFieldName() {
67             return fieldName;
68         }
69
70         public boolean isIndexed() {
71             return isIndexed;
72         }
73
74         public DataType getFieldType() {
75             return fieldType;
76         }
77     }
78 }