Search in sources :

Example 1 with TableEntity

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);
    }
}
Also used : AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) TableEntity(com.microsoft.tooling.msservices.model.storage.TableEntity) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 2 with TableEntity

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();
    }
}
Also used : TableEntityForm(com.microsoft.azuretools.azureexplorer.forms.TableEntityForm) TableEntity(com.microsoft.tooling.msservices.model.storage.TableEntity)

Example 3 with TableEntity

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);
}
Also used : TableEntity(com.microsoft.tooling.msservices.model.storage.TableEntity) Property(com.microsoft.tooling.msservices.model.storage.TableEntity.Property) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 4 with TableEntity

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()]);
}
Also used : ArrayList(java.util.ArrayList) TableEntity(com.microsoft.tooling.msservices.model.storage.TableEntity)

Example 5 with TableEntity

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);
        }
    });
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) TableEntity(com.microsoft.tooling.msservices.model.storage.TableEntity) ArrayList(java.util.ArrayList) List(java.util.List) SimpleDateFormat(java.text.SimpleDateFormat) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

TableEntity (com.microsoft.tooling.msservices.model.storage.TableEntity)8 NotNull (com.microsoft.azuretools.azurecommons.helpers.NotNull)2 ArrayList (java.util.ArrayList)2 DefaultTableModel (javax.swing.table.DefaultTableModel)2 ValidationInfo (com.intellij.openapi.ui.ValidationInfo)1 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)1 TableEntityForm (com.microsoft.azuretools.azureexplorer.forms.TableEntityForm)1 TableEntityForm (com.microsoft.intellij.forms.TableEntityForm)1 Property (com.microsoft.tooling.msservices.model.storage.TableEntity.Property)1 SimpleDateFormat (java.text.SimpleDateFormat)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 TableModel (javax.swing.table.TableModel)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 Nullable (org.jetbrains.annotations.Nullable)1