From 0243115caed27e8106d2b0ece948100c94b57c06 Mon Sep 17 00:00:00 2001 From: Neelesh Thakur <NThakur4@slb.com> Date: Tue, 29 Sep 2020 12:00:40 -0500 Subject: [PATCH] add id for list all workflows --- .../azure/persistence/CloudTableStore.java | 29 +++++++-- .../persistence/PartitionTableStore.java | 63 ++++++++++++++----- .../descriptor/CreatePartitionDescriptor.java | 3 +- 3 files changed, 72 insertions(+), 23 deletions(-) diff --git a/provider/partition-azure/src/main/java/org/opengroup/osdu/partition/provider/azure/persistence/CloudTableStore.java b/provider/partition-azure/src/main/java/org/opengroup/osdu/partition/provider/azure/persistence/CloudTableStore.java index 7bb236a5b..588516b27 100644 --- a/provider/partition-azure/src/main/java/org/opengroup/osdu/partition/provider/azure/persistence/CloudTableStore.java +++ b/provider/partition-azure/src/main/java/org/opengroup/osdu/partition/provider/azure/persistence/CloudTableStore.java @@ -10,8 +10,6 @@ import org.springframework.stereotype.Component; @Component public class CloudTableStore { - private final String PARTITION_KEY = "PartitionKey"; - @Autowired private CloudTable cloudTableClient; @@ -28,10 +26,10 @@ public class CloudTableStore { } } - public Iterable<? extends TableEntity> queryByPartitionId(final Class<? extends TableEntity> clazzType, String value) { + public Iterable<? extends TableEntity> queryByKey(final Class<? extends TableEntity> clazzType, final String key, final String value) { String partitionFilter = TableQuery.generateFilterCondition( - PARTITION_KEY, + key, TableQuery.QueryComparisons.EQUAL, value); @@ -41,6 +39,29 @@ public class CloudTableStore { return this.cloudTableClient.execute(partitionQuery); } + public Iterable<? extends TableEntity> queryByCompoundKey(final Class<? extends TableEntity> clazzType, + final String rowKey, final String rowValue, + final String valueKey, final String value) { + + String rowFilter = TableQuery.generateFilterCondition( + rowKey, + TableQuery.QueryComparisons.EQUAL, + rowValue); + + String valueFilter = TableQuery.generateFilterCondition( + valueKey, + TableQuery.QueryComparisons.EQUAL, + value); + + String combinedFilter = TableQuery.combineFilters(rowFilter, + TableQuery.Operators.AND, valueFilter); + + TableQuery<? extends TableEntity> partitionQuery = TableQuery.from(clazzType) + .where(combinedFilter); + + return this.cloudTableClient.execute(partitionQuery); + } + public void insertBatchEntities(TableBatchOperation batchOperation) { try { this.cloudTableClient.execute(batchOperation); diff --git a/provider/partition-azure/src/main/java/org/opengroup/osdu/partition/provider/azure/persistence/PartitionTableStore.java b/provider/partition-azure/src/main/java/org/opengroup/osdu/partition/provider/azure/persistence/PartitionTableStore.java index 1090251ad..c9ed9854f 100644 --- a/provider/partition-azure/src/main/java/org/opengroup/osdu/partition/provider/azure/persistence/PartitionTableStore.java +++ b/provider/partition-azure/src/main/java/org/opengroup/osdu/partition/provider/azure/persistence/PartitionTableStore.java @@ -15,6 +15,13 @@ import java.util.Map; @Component public class PartitionTableStore { + private final static String ID = "id"; + private final static String VALUE = "value"; + private final static String SENSITIVE = "sensitive"; + + private final String PARTITION_KEY = "PartitionKey"; + private final String ROW_KEY = "RowKey"; + @Autowired private CloudTableStore cloudTableStore; @@ -22,6 +29,7 @@ public class PartitionTableStore { Map<String, Property> requestProperties = partitionInfo.getProperties(); TableBatchOperation batchOperation = new TableBatchOperation(); + batchOperation.insertOrReplace(this.getIdPartitionEntity(partitionId)); for (Map.Entry<String, Property> entry : requestProperties.entrySet()) { String key = entry.getKey(); Property property = entry.getValue(); @@ -32,8 +40,8 @@ public class PartitionTableStore { if (property.isSensitive()) { property.setValue(this.getTenantSafeSecreteId(partitionId, String.valueOf(property.getValue()))); } - properties.put("value", new EntityProperty(String.valueOf(property.getValue()))); - properties.put("sensitive", new EntityProperty(property.isSensitive())); + properties.put(VALUE, new EntityProperty(String.valueOf(property.getValue()))); + properties.put(SENSITIVE, new EntityProperty(property.isSensitive())); partitionEntity.setProperties(properties); batchOperation.insertOrReplace(partitionEntity); } @@ -42,15 +50,14 @@ public class PartitionTableStore { } public boolean partitionExists(String partitionId) { - - List<PartitionEntity> partitionEntities = this.queryByPartitionId(partitionId); - return !partitionEntities.isEmpty(); + List<PartitionEntity> partitionEntities = this.queryById(partitionId); + return partitionEntities.size() == 1; } public Map<String, Property> getPartition(String partitionId) { Map<String, Property> out = new HashMap<>(); - List<PartitionEntity> partitionEntities = this.queryByPartitionId(partitionId); + List<PartitionEntity> partitionEntities = this.getAllByPartitionId(partitionId); if (partitionEntities.isEmpty()) { return out; } @@ -58,33 +65,55 @@ public class PartitionTableStore { for (PartitionEntity pe : partitionEntities) { Property property = Property.builder().build(); HashMap<String, EntityProperty> properties = pe.getProperties(); - if (properties.containsKey("sensitive")) { - property.setSensitive(properties.get("sensitive").getValueAsBoolean()); + if (properties.containsKey(SENSITIVE)) { + property.setSensitive(properties.get(SENSITIVE).getValueAsBoolean()); } - if (properties.containsKey("value")) { - property.setValue(properties.get("value").getValueAsString()); + if (properties.containsKey(VALUE)) { + property.setValue(properties.get(VALUE).getValueAsString()); } out.put(pe.getRowKey(), property); } return out; } - public List<PartitionEntity> queryByPartitionId(String partitionId) { + public void deletePartition(String partitionId) { + Iterable<PartitionEntity> results = (Iterable<PartitionEntity>) this.cloudTableStore.queryByKey(PartitionEntity.class, + PARTITION_KEY, partitionId); + for (PartitionEntity tableEntity : results) { + this.cloudTableStore.deleteCloudTableEntity(PartitionEntity.class, tableEntity.getPartitionKey(), tableEntity.getRowKey()); + } + } + + private List<PartitionEntity> queryById(String partitionId) { List<PartitionEntity> out = new ArrayList<>(); - Iterable<PartitionEntity> results = (Iterable<PartitionEntity>) this.cloudTableStore.queryByPartitionId(PartitionEntity.class, partitionId); + Iterable<PartitionEntity> results = (Iterable<PartitionEntity>) this.cloudTableStore.queryByCompoundKey(PartitionEntity.class, + ROW_KEY, ID, + VALUE, partitionId); for (PartitionEntity tableEntity : results) { - tableEntity.setPartitionId(tableEntity.getPartitionKey()); - tableEntity.setName(tableEntity.getRowKey()); out.add(tableEntity); } return out; } - public void deletePartition(String partitionId) { - Iterable<PartitionEntity> results = (Iterable<PartitionEntity>) this.cloudTableStore.queryByPartitionId(PartitionEntity.class, partitionId); + private List<PartitionEntity> getAllByPartitionId(String partitionId) { + List<PartitionEntity> out = new ArrayList<>(); + Iterable<PartitionEntity> results = (Iterable<PartitionEntity>) this.cloudTableStore.queryByKey(PartitionEntity.class, + PARTITION_KEY, partitionId); for (PartitionEntity tableEntity : results) { - this.cloudTableStore.deleteCloudTableEntity(PartitionEntity.class, tableEntity.getPartitionKey(), tableEntity.getRowKey()); + tableEntity.setPartitionId(tableEntity.getPartitionKey()); + tableEntity.setName(tableEntity.getRowKey()); + out.add(tableEntity); } + return out; + } + + private PartitionEntity getIdPartitionEntity(String partitionId) { + PartitionEntity partitionEntity = new PartitionEntity(partitionId, ID); + HashMap<String, EntityProperty> properties = new HashMap<>(); + properties.put(VALUE, new EntityProperty(partitionId)); + properties.put(SENSITIVE, new EntityProperty(false)); + partitionEntity.setProperties(properties); + return partitionEntity; } private String getTenantSafeSecreteId(String partitionId, String secreteName) { diff --git a/testing/partition-test-core/src/main/java/org/opengroup/osdu/partition/api/descriptor/CreatePartitionDescriptor.java b/testing/partition-test-core/src/main/java/org/opengroup/osdu/partition/api/descriptor/CreatePartitionDescriptor.java index b4fab4493..fee0ffb55 100644 --- a/testing/partition-test-core/src/main/java/org/opengroup/osdu/partition/api/descriptor/CreatePartitionDescriptor.java +++ b/testing/partition-test-core/src/main/java/org/opengroup/osdu/partition/api/descriptor/CreatePartitionDescriptor.java @@ -36,10 +36,9 @@ public class CreatePartitionDescriptor extends RestDescriptor { StringBuffer sb = new StringBuffer(); sb.append("{\n"); sb.append(" \"properties\": {") - .append("\"id\": \"").append(this.arg()).append("\",") .append("\"elasticPassword\": {\"sensitive\":true,\"value\":\"test-password\"},") .append("\"serviceBusConnection\": {\"sensitive\":true,\"value\":\"test-service-bus-connection\"},") - .append("\"cosmosConnection\": \"test-cosmos-connection\"") + .append("\"complianceRuleSet\": {\"value\":\"shared\"}") .append("}\n") .append("}"); return sb.toString(); -- GitLab