com.microsoft.azure.storage.table.EntityProperty Java Examples

The following examples show how to use com.microsoft.azure.storage.table.EntityProperty. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AzureLoginAccess.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
private Map<String, EntityProperty> objectToProps(Login source) {
  ImmutableMap.Builder<String, EntityProperty> builder = ImmutableMap.<String, EntityProperty>builder()
    .put("username", new EntityProperty(source.getUsername()))
    .put("userPid", new EntityProperty(source.getUserPid()))
    .put("password", new EntityProperty(source.getPassword()))
    .put("salt", new EntityProperty(source.getSalt()));
  if (source.getGivenName() != null) {
    builder.put("givenName", new EntityProperty(source.getGivenName()));
  }
  if (source.getSurName() != null) {
    builder.put("surName", new EntityProperty(source.getSurName()));
  }
  if (source.getEmailAddress() != null) {
    builder.put("emailAddress", new EntityProperty(source.getEmailAddress()));
  }
  if (source.getOrganization() != null) {
    builder.put("organization", new EntityProperty(source.getOrganization()));
  }
  return builder.build();
}
 
Example #2
Source File: AzureStorageAvroRegistry.java    From components with Apache License 2.0 5 votes vote down vote up
protected Schema inferSchemaDynamicTableEntity(DynamicTableEntity entity) {
    List<Field> fields = new ArrayList<>();
    fields.add(new Field("PartitionKey", AvroUtils._string(), null, (Object) null));
    fields.add(new Field("RowKey", AvroUtils._string(), null, (Object) null));
    fields.add(new Field("Timestamp", AvroUtils._date(), null, (Object) null));

    // FIXME set tableName properly and manage nameMappings
    String tableName = "schemaInfered";
    for (Entry<String, EntityProperty> f : entity.getProperties().entrySet()) {
        String fieldName = f.getKey();
        Field field = getAvroMapping(fieldName, f.getValue());
        fields.add(field);
    }
    return Schema.createRecord(tableName, null, null, false, fields);
}
 
Example #3
Source File: AzureStorageAvroRegistryTest.java    From components with Apache License 2.0 5 votes vote down vote up
@Test
public void testDynamicTableEntityConversion() {

    DynamicTableEntity entity = new DynamicTableEntity();
    entity.setPartitionKey(pk_test1);
    entity.setRowKey(rk_test1);
    entity.getProperties().put("a_bool", new EntityProperty(true));
    entity.getProperties().put("a_int", new EntityProperty(1000));
    entity.getProperties().put("a_string", new EntityProperty(RandomStringUtils.random(10)));

    Schema s = registry.inferSchemaDynamicTableEntity(entity);
    assertEquals(6, s.getFields().size());

    recordConv.setSchema(s);
    IndexedRecord record = recordConv.convertToAvro(entity);
    assertEquals(pk_test1, record.get(0));
    assertEquals(rk_test1, record.get(1));
    assertTrue(record.get(2) instanceof Date);
    //
    assertEquals(true, record.get(s.getField("a_bool").pos()));
    assertEquals(1000, record.get(s.getField("a_int").pos()));
    assertTrue(record.get(s.getField("a_string").pos()) instanceof String);

    Map<String, String> nameMappings = new HashMap<>();
    nameMappings.put("a_bool", "booly");
    AzureStorageTableAdaptorFactory adaptor = new AzureStorageTableAdaptorFactory(nameMappings);
    adaptor.setSchema(s);

    //
    registry.inferSchemaDynamicTableEntity(entity);
    assertEquals(DynamicTableEntity.class, recordConv.getDatumClass());
    assertNull(recordConv.convertToDatum(record));
}
 
Example #4
Source File: AzureStorageAvroRegistryTest.java    From components with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @see org.talend.components.azurestorage.table.avro.AzureStorageAvroRegistry#getAvroMapping(String,EntityProperty)
 */
@Test
public void testGetAvroMapping() {
    String name = "field";
    assertEquals(new Field(name, AvroUtils._bytes(), null, (Object) null).toString(),
            registry.getAvroMapping(name, new EntityProperty(new byte[] {})).toString());

    assertEquals(new Field(name, AvroUtils._string(), null, (Object) null).toString(),
            registry.getAvroMapping(name, new EntityProperty("test")).toString());

    assertEquals(new Field(name, AvroUtils._boolean(), null, (Object) null).toString(),
            registry.getAvroMapping(name, new EntityProperty(true)).toString());

    assertEquals(new Field(name, AvroUtils._byte(), null, (Object) null).toString(),
            registry.getAvroMapping(name, new EntityProperty((byte) 11)).toString());

    assertEquals(new Field(name, AvroUtils._date(), null, (Object) null).toString(),
            registry.getAvroMapping(name, new EntityProperty(new Date())).toString());

    assertEquals(new Field(name, AvroUtils._date(), null, (Object) null).toString(),
            registry.getAvroMapping(name, new EntityProperty(new Date())).toString());

    assertEquals(new Field(name, AvroUtils._short(), null, (Object) null).toString(),
            registry.getAvroMapping(name, new EntityProperty((short) 12)).toString());

    assertEquals(new Field(name, AvroUtils._int(), null, (Object) null).toString(),
            registry.getAvroMapping(name, new EntityProperty((int) 12)).toString());

    assertEquals(new Field(name, AvroUtils._long(), null, (Object) null).toString(),
            registry.getAvroMapping(name, new EntityProperty((long) 12)).toString());

    assertEquals(new Field(name, AvroUtils._double(), null, (Object) null).toString(),
            registry.getAvroMapping(name, new EntityProperty((double) 12.0)).toString());

}
 
Example #5
Source File: AzureAccess.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
protected static byte[] getByteArrayOrEmpty(DynamicTableEntity entity, String key) {
  EntityProperty property = entity.getProperties().get(key);
  byte[] result = new byte[0];
  if (property != null) {
    result = property.getValueAsByteArray();
  }
  return result;
}
 
Example #6
Source File: AzureAccess.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
protected static String getStringOrNull(DynamicTableEntity entity, String key) {
  EntityProperty property = entity.getProperties().get(key);
  String result = null;
  if (property != null) {
    result = property.getValueAsString();
  }
  return result;
}
 
Example #7
Source File: AzureUserAccess.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
public Map<String, EntityProperty> objectToProps(User source) {
  Map<String, EntityProperty> result = new HashMap<>();
  if (source.getPersistentId() != null) {
    result.put("persistentId", new EntityProperty(source.getPersistentId()));
  }
  if (source.getDisplayName() != null) {
    result.put("displayName", new EntityProperty(source.getDisplayName()));
  }
  result.put("id", new EntityProperty(source.getId()));
  return result;
}
 
Example #8
Source File: AzureVreAuthorizationAccess.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
public Map<String, EntityProperty> objectToProps(VreAuthorization source) {
  return ImmutableMap.of(
    "vreId", new EntityProperty(source.getVreId()),
    "userId", new EntityProperty(source.getUserId()),
    "roles", new EntityProperty(String.join(",", source.getRoles()))
  );
}
 
Example #9
Source File: AzureAccess.java    From timbuctoo with GNU General Public License v3.0 4 votes vote down vote up
protected void create(String partitionKey, String rowKey, Map<String, EntityProperty> properties)
  throws StorageException {
  table.execute(TableOperation.insert(new DynamicTableEntity(partitionKey, rowKey, new HashMap<>(properties))));
}