You are on page 1of 2

package com.morrisons.supplychain.walltowall.

dao;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression;
import com.amazonaws.services.dynamodbv2.datamodeling.PaginatedQueryList;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.QueryRequest;
import com.amazonaws.services.dynamodbv2.model.QueryResult;

import com.morrisons.supplychain.walltowall.model.StoreList;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
public class DynamoDbDaoImpl implements IDynamoDbDao {
private static final Logger LOGGER =
LoggerFactory.getLogger(DynamoDbDaoImpl.class);
private static final String TABLE_NAME =
"STAGE.supplychain.walltowall.count.extract";

private DynamoDBMapper mapper ;


public void saveOrder(StoreList order) {
mapper.save(order);

@SuppressWarnings("unchecked")
@Override
public List<StoreList> getStoresById(BigDecimal sequenceId) {
LOGGER.info("Inside DynamoDbDaoImpl -> inside getStoresById() ->
sequenceId : {}", sequenceId);
return (List<StoreList>) mapper.load(StoreList.class, sequenceId);
}

@SuppressWarnings("unchecked")
@Override
public List<StoreList> getStoresByCountId(String countId,String sortId) {
LOGGER.info("Inside DynamoDbDaoImpl -> inside getStoresByCountId() ->
countId : {}", countId);
return (List<StoreList>) mapper.load(StoreList.class, countId,sortId);
}
public StoreList getStoresByCountId1(String countId,String sortId) {
LOGGER.info("Inside DynamoDbDaoImpl -> inside getStoresByCountId() ->
countId : {}", countId);
return mapper.load(StoreList.class, countId,sortId);
}
@Override
public List<StoreList> getStoresByDate(Date countStartDate, Date
countEndDate) {
LOGGER.info("Inside DynamoDbDaoImpl -> inside getStoresByDate() ->
countStartDate : {}", countStartDate);

LOGGER.info("Inside DynamoDbDaoImpl -> inside getStoresByDate() ->


countEndDate : {}", countEndDate);
Map<String, String> expressionAttributesNames = new HashMap<>();

expressionAttributesNames.put("#countDate", "countDate");
Map<String, AttributeValue> expressionAttributeValues = new
HashMap<>();

expressionAttributeValues.put(":countStartDate", new
AttributeValue().withS(countStartDate.toString()));
expressionAttributeValues.put(":countEndDate", new
AttributeValue().withS(countEndDate.toString()));

DynamoDBQueryExpression<StoreList> dynamoDBQueryExpression = new


DynamoDBQueryExpression<StoreList>()
.withKeyConditionExpression(" #countDate BETWEEN
:countStartDate AND :countEndDate ")
.withExpressionAttributeNames(expressionAttributesNames)
.withExpressionAttributeValues(expressionAttributeValues);

List<StoreList> storeList = mapper.query(StoreList.class,


dynamoDBQueryExpression);
LOGGER.info("Inside DynamoDbDaoImpl -> inside getStoresByDate() ->
storeList : {}", storeList);
return storeList;

You might also like