use of com.microsoft.tooling.msservices.model.storage.TableEntity in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method getTableEntities.
@NotNull
public List<TableEntity> getTableEntities(@NotNull StorageAccount storageAccount, @NotNull Table table, @NotNull String filter) throws AzureCmdException {
List<TableEntity> teList = new ArrayList<TableEntity>();
try {
CloudTableClient client = getCloudTableClient(storageAccount);
String tableName = table.getName();
CloudTable cloudTable = client.getTableReference(tableName);
TableQuery<DynamicTableEntity> tableQuery = TableQuery.from(DynamicTableEntity.class);
if (!filter.isEmpty()) {
tableQuery.where(filter);
}
TableRequestOptions tro = new TableRequestOptions();
tro.setTablePayloadFormat(TablePayloadFormat.JsonFullMetadata);
for (DynamicTableEntity dte : cloudTable.execute(tableQuery, tro, null)) {
teList.add(getTableEntity(tableName, dte));
}
return teList;
} catch (Throwable t) {
throw new AzureCmdException("Error retrieving the Table Entity list", t);
}
}
use of com.microsoft.tooling.msservices.model.storage.TableEntity in project azure-tools-for-java by Microsoft.
the class TableFileEditor method editEntity.
private void editEntity() {
TableEntity[] selectedEntities = getSelectedEntities();
if (selectedEntities != null && selectedEntities.length > 0) {
final TableEntity selectedEntity = selectedEntities[0];
final TableEntityForm form = new TableEntityForm(PluginUtil.getParentShell(), "Edit Entity");
form.setTableName(table.getName());
form.setStorageAccount(storageAccount);
form.setTableEntity(selectedEntity);
form.setOnFinish(new Runnable() {
@Override
public void run() {
// tableEntities.set(entitiesTable.getSelectedRow(), form.getTableEntity());
refreshGrid();
}
});
form.open();
}
}
use of com.microsoft.tooling.msservices.model.storage.TableEntity in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method getTableEntity.
@NotNull
private static TableEntity getTableEntity(@NotNull String tableName, @NotNull DynamicTableEntity dte) {
String partitionKey = Strings.nullToEmpty(dte.getPartitionKey());
String rowKey = Strings.nullToEmpty(dte.getRowKey());
String eTag = Strings.nullToEmpty(dte.getEtag());
Calendar timestamp = new GregorianCalendar();
if (dte.getTimestamp() != null) {
timestamp.setTime(dte.getTimestamp());
}
Map<String, Property> properties = new HashMap<String, Property>();
if (dte.getProperties() != null) {
for (Entry<String, EntityProperty> entry : dte.getProperties().entrySet()) {
if (entry.getKey() != null && entry.getValue() != null) {
String key = entry.getKey();
Property property;
switch(entry.getValue().getEdmType()) {
case BOOLEAN:
property = new Property(entry.getValue().getValueAsBooleanObject());
break;
case DATE_TIME:
Calendar value = new GregorianCalendar();
value.setTime(entry.getValue().getValueAsDate());
property = new Property(value);
break;
case DOUBLE:
property = new Property(entry.getValue().getValueAsDoubleObject());
break;
case GUID:
property = new Property(entry.getValue().getValueAsUUID());
break;
case INT32:
property = new Property(entry.getValue().getValueAsIntegerObject());
break;
case INT64:
property = new Property(entry.getValue().getValueAsLongObject());
break;
case STRING:
property = new Property(entry.getValue().getValueAsString());
break;
default:
property = new Property(entry.getValue().getValueAsString());
break;
}
properties.put(key, property);
}
}
}
return new TableEntity(partitionKey, rowKey, tableName, eTag, timestamp, properties);
}
use of com.microsoft.tooling.msservices.model.storage.TableEntity in project azure-tools-for-java by Microsoft.
the class TableFileEditor method getSelectedEntities.
private TableEntity[] getSelectedEntities() {
if (tableEntities == null) {
return null;
}
int partitionIdIndex = -1;
int rowIdIndex = -1;
for (int i = 0; i < entitiesTable.getColumnCount(); i++) {
String columnName = entitiesTable.getColumnName(i);
if (columnName.equals(PARTITION_KEY)) {
partitionIdIndex = i;
}
if (columnName.equals(ROW_KEY)) {
rowIdIndex = i;
}
}
ArrayList<TableEntity> selectedEntities = new ArrayList<TableEntity>();
for (int i : entitiesTable.getSelectedRows()) {
for (TableEntity tableEntity : tableEntities) {
String partitionValue = entitiesTable.getValueAt(i, partitionIdIndex).toString();
String rowIdValue = entitiesTable.getValueAt(i, rowIdIndex).toString();
if (tableEntity.getPartitionKey().equals(partitionValue) && tableEntity.getRowKey().equals(rowIdValue)) {
selectedEntities.add(tableEntity);
}
}
}
return selectedEntities.toArray(new TableEntity[selectedEntities.size()]);
}
use of com.microsoft.tooling.msservices.model.storage.TableEntity in project azure-tools-for-java by Microsoft.
the class TableFileEditor method refreshGrid.
private void refreshGrid() {
AzureTaskManager.getInstance().runLater(() -> {
Map<String, List<String>> columnData = new LinkedHashMap<String, List<String>>();
columnData.put(PARTITION_KEY, new ArrayList<String>());
columnData.put(ROW_KEY, new ArrayList<String>());
columnData.put(TIMESTAMP, new ArrayList<String>());
for (TableEntity tableEntity : tableEntities) {
columnData.get(PARTITION_KEY).add(tableEntity.getPartitionKey());
columnData.get(ROW_KEY).add(tableEntity.getRowKey());
columnData.get(TIMESTAMP).add(new SimpleDateFormat().format(tableEntity.getTimestamp().getTime()));
for (String entityColumn : tableEntity.getProperties().keySet()) {
if (!columnData.keySet().contains(entityColumn)) {
columnData.put(entityColumn, new ArrayList<String>());
}
}
}
for (TableEntity tableEntity : tableEntities) {
for (String column : columnData.keySet()) {
if (!column.equals(PARTITION_KEY) && !column.equals(ROW_KEY) && !column.equals(TIMESTAMP)) {
columnData.get(column).add(tableEntity.getProperties().containsKey(column) ? getFormattedProperty(tableEntity.getProperties().get(column)) : "");
}
}
}
DefaultTableModel model = new DefaultTableModel() {
@Override
public boolean isCellEditable(int i, int i1) {
return false;
}
};
for (String column : columnData.keySet()) {
model.addColumn(column, columnData.get(column).toArray());
}
entitiesTable.setModel(model);
for (int i = 0; i != entitiesTable.getColumnCount(); i++) {
entitiesTable.getColumnModel().getColumn(i).setPreferredWidth(100);
}
});
}
Aggregations