AbstractDynamoDao extends AbstractDao<M,P,K,I> { protected Item toCreateItem(P partial, Instant createAt, I creatorId) { Item item = partialMapper.toItem(partial); Field id = getFieldData().getId(); if (id != null && item.get(id.getStorageName()) == null) { item.with(id.getStorageName(), toStorageValue(generatePrimaryKeyValue())); } Field createdByField = getFieldData().getCreatedBy(); if (createdByField != null && item.get(createdByField.getStorageName()) == null && creatorId != null) { item.with(createdByField.getStorageName(), toStorageValue(creatorId)); } Field createdAtField = getFieldData().getCreatedAt(); if (createdAtField != null && item.get(createdAtField.getStorageName()) == null && createAt != null) { item.with(createdAtField.getStorageName(), toStorageValue(createAt)); } Field updatedByField = getFieldData().getUpdatedBy(); if (updatedByField != null && !updatedByField.isOptional() && item.get(updatedByField.getStorageName()) == null && creatorId != null) { item.with(updatedByField.getStorageName(), toStorageValue(creatorId)); } Field updatedAtField = getFieldData().getUpdatedAt(); if (updatedAtField != null && !updatedAtField.isOptional() && item.get(updatedAtField.getStorageName()) == null && createAt != null) { item.with(updatedAtField.getStorageName(), toStorageValue(createAt)); } return item; } AbstractDynamoDao(Class<M> modelClass, Class<P> partialClass, AmazonDynamoDB db, String tableName);  AbstractDynamoDao(Class<M> modelClass, Class<P> partialClass, AmazonDynamoDB db, String tableName, ItemMapper<M> modelMapper, ItemMapper<P> partialMapper); String getTableName(); Table getTable(); Optional<M> loadOpt(K id); Optional<P> loadOpt(K id, Iterable<String> fields); @Override Iterable<M> iterateAll(); Results<M,K> scanAll(); @Override M create(P partial, Instant createAt, I creatorId); void update(K id, Update<P> update, Instant updateAt, I updaterId); M updateAndReturn(K id, Update<P> update, Instant updateAt, I updaterId); Update<P> updateOf(P partial); Update<P> updateOf(P partial, Iterable<String> removeFields); @Override void delete(K id); abstract List<KeySchemaElement> getKeySchema(); abstract List<AttributeDefinition> getAttributeDefinitions(); List<GlobalSecondaryIndex> getGlobalSecondaryIndexes(); void initTable(); void dropTable(); void copyTable(AmazonDynamoDB sourceDb, String sourceTable); void ensureIndexes();  }
@Test public void testToCreateItem() throws Exception { Instant now = Instant.now(); UUID creatorId = UUID.randomUUID(); Item item = dao.toCreateItem(TestModel.builder().name("Ian White").build(), now, creatorId); assertNotNull(item.get("id")); assertEquals(creatorId.toString(), item.get("createId")); assertEquals(new BigDecimal(now.toEpochMilli()), item.get("createAt")); }