Java tutorial
/** * (C) Copyright 2016 Johnson Controls, Inc * Use or Copying of all or any part of this program, except as * permitted by License Agreement, is prohibited. */ package com.jci.po.repo; import java.io.IOException; import java.net.URISyntaxException; import java.security.InvalidKeyException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Repository; //import org.springframework.transaction.annotation.Transactional; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.jci.po.azure.AzureStorage; import com.jci.po.azure.data.DataHelper; import com.jci.po.azure.data.DataUtil; import com.jci.po.azure.data.ResultSet; import com.jci.po.azure.query.PaginationParam; import com.jci.po.azure.query.ScrollingParam; import com.jci.po.dto.req.BatchUpdateReq; import com.jci.po.dto.res.BatchUpdateRes; import com.jci.po.entity.MiscDataEntity; import com.jci.po.entity.PoEntity; import com.jci.po.entity.UserDetailsEntity; import com.jci.po.utils.QueryBuilder; import com.microsoft.azure.storage.OperationContext; import com.microsoft.azure.storage.ResultContinuation; import com.microsoft.azure.storage.ResultSegment; import com.microsoft.azure.storage.StorageException; import com.microsoft.azure.storage.table.CloudTable; import com.microsoft.azure.storage.table.DynamicTableEntity; import com.microsoft.azure.storage.table.EntityProperty; import com.microsoft.azure.storage.table.TableBatchOperation; import com.microsoft.azure.storage.table.TableOperation; import com.microsoft.azure.storage.table.TableQuery; /** * <p> * <strong> The Class PoRepoImpl.</strong> * <p> * * @author csonisk */ @Repository @RefreshScope @Configuration public class PoRepoImpl implements PoRepo { // NO_UCD (unused code) /** The Constant LOG. */ private static final Logger LOG = LoggerFactory.getLogger(PoRepoImpl.class); /** The all erps. */ @Value("${all.erp.names}") private String allErps; @Value("${map.erp.names}") private String mapicsErp; /** The batch size. */ final int batchSize = 10; /** The azure storage. */ @Autowired private AzureStorage azureStorage; @Value("${azure.storage.potablename}") private String poTableName; @Value("${azure.storage.poitemtablename}") private String poItemTableName; @Value("${azure.storage.miscdatatablename}") private String miscDataTableName; @Value("${azure.storage.MAPmiscdatatablename}") private String MapmiscDataTableName; @Value("${azure.storage.usertablename}") private String userTableName; @Value("${azure.storage.partionkey.user.details}") private String userPk; /** * Creates the table. * * @param tableName the table name * @throws InvalidKeyException the invalid key exception * @throws StorageException the storage exception * @throws URISyntaxException the URI syntax exception */ public void createTable(String tableName) throws InvalidKeyException, StorageException, URISyntaxException { if (azureStorage.getTable(tableName).createIfNotExists()) { LOG.debug("table is created : " + tableName); } } /* (non-Javadoc) * @see com.jci.po.repo.PoRepo#getGraphData() */ @Override public HashMap<String, ArrayList<Integer>> getGraphData() throws InvalidKeyException, URISyntaxException, StorageException { String query = QueryBuilder.graphQuery("STATUS_COUNT", allErps); //String query = QueryBuilder.graphQuery(allErps); System.out.println("query--->" + query); TableQuery<MiscDataEntity> partitionQuery = TableQuery.from(MiscDataEntity.class).where(query); CloudTable cloudTable = azureStorage.getTable(miscDataTableName); System.out.println("MISC DATA TABLE" + miscDataTableName); ArrayList<Integer> list = null; HashMap<String, ArrayList<Integer>> erpToListMap = new HashMap<>(); for (MiscDataEntity entity : cloudTable.execute(partitionQuery)) { int intransitCount = 0; int successCount = 0; int errorCount = 0; String rowkey = entity.getRowKey(); //String erp = entity.getPartitionKey(); String erp = "SYMIX"; if (erpToListMap.containsKey(erp)) { list = erpToListMap.get(erp); intransitCount = list.get(0); successCount = list.get(1); errorCount = list.get(2); System.out.println("RowKey is" + rowkey); if ("SYMIX".equals(rowkey)) { intransitCount = intransitCount + (entity.getIntransitCount() == null ? 0 : entity.getIntransitCount()); successCount = successCount + (entity.getProcessedCount() == null ? 0 : entity.getProcessedCount()); errorCount = errorCount + (entity.getErrorCount() == null ? 0 : entity.getErrorCount()); } list = new ArrayList<>(); list.add(intransitCount); list.add(successCount); list.add(errorCount); erpToListMap.put(erp, list); } else { if ("SYMIX".equals(rowkey)) { intransitCount = intransitCount + (entity.getIntransitCount() == null ? 0 : entity.getIntransitCount()); successCount = successCount + (entity.getProcessedCount() == null ? 0 : entity.getProcessedCount()); errorCount = errorCount + (entity.getErrorCount() == null ? 0 : entity.getErrorCount()); } list = new ArrayList<>(); list.add(intransitCount); list.add(successCount); list.add(errorCount); System.out.println("ERP NAME" + erp); erpToListMap.put(erp, list); } int intransitCount_map = 0; int successCount_map = 0; int errorCount_map = 0; String rowkey_map = "MAPICS"; String erp_map = "MAPICS"; if (erpToListMap.containsKey(erp_map)) { list = erpToListMap.get(erp_map); intransitCount_map = list.get(0); successCount_map = list.get(1); errorCount_map = list.get(2); System.out.println("MAPICS RowKey is" + rowkey_map); if ("MAPICS".equals(rowkey)) { intransitCount_map = intransitCount_map + (entity.getIntransitCount() == null ? 0 : entity.getIntransitCount()); successCount_map = successCount_map + (entity.getProcessedCount() == null ? 0 : entity.getProcessedCount()); errorCount_map = errorCount_map + (entity.getErrorCount() == null ? 0 : entity.getErrorCount()); } System.out.println("Error count in if con for mapics " + errorCount_map); System.out.println("Success count for if con Mapics" + successCount_map); list = new ArrayList<>(); list.add(intransitCount_map); list.add(successCount_map); list.add(errorCount_map); erpToListMap.put(erp_map, list); } else { if ("MAPICS".equals(rowkey)) { intransitCount_map = intransitCount_map + (entity.getIntransitCount() == null ? 0 : entity.getIntransitCount()); successCount_map = successCount_map + (entity.getProcessedCount() == null ? 0 : entity.getProcessedCount()); errorCount_map = errorCount_map + (entity.getErrorCount() == null ? 0 : entity.getErrorCount()); } System.out.println("Error count in else con for mapics " + errorCount_map); System.out.println("Success count for else con Mapics" + successCount_map); list = new ArrayList<>(); list.add(intransitCount_map); list.add(successCount_map); list.add(errorCount_map); System.out.println("ERP NAME" + erp); erpToListMap.put(erp_map, list); } } return erpToListMap; } // Change By Bablu public HashMap<String, ArrayList<Integer>> getGraphDataMAP() throws InvalidKeyException, URISyntaxException, StorageException { String query = QueryBuilder.graphQuery("STATUS_COUNT", allErps); //String query = QueryBuilder.graphQuery("allErps"); //LOG.info("query--->" + query); TableQuery<MiscDataEntity> partitionQueryMAP = TableQuery.from(MiscDataEntity.class).where(query); //CloudTable cloudTableMAP = azureStorage.getTable(MapmiscDataTableName); TableQuery<MiscDataEntity> partitionQuerySymix = TableQuery.from(MiscDataEntity.class).where(query); CloudTable cloudTableSymix = azureStorage.getTable(miscDataTableName); ArrayList<Integer> list = null; HashMap<String, ArrayList<Integer>> erpToListMap = new HashMap<>(); System.out.println("Partition Query Symix" + partitionQuerySymix.toString()); for (MiscDataEntity entity : cloudTableSymix.execute(partitionQuerySymix)) { int intransitCount = 0; int successCount = 0; int errorCount = 0; String rowkey = entity.getRowKey(); String erp = entity.getPartitionKey(); if (erpToListMap.containsKey(erp)) { list = erpToListMap.get(erp); intransitCount = list.get(0); successCount = list.get(1); errorCount = list.get(2); if ("PO".equals(rowkey)) { intransitCount = intransitCount + (entity.getIntransitCount() == null ? 0 : entity.getIntransitCount()); successCount = successCount + (entity.getProcessedCount() == null ? 0 : entity.getProcessedCount()); errorCount = errorCount + (entity.getErrorCount() == null ? 0 : entity.getErrorCount()); } /*else if("GR".equals(rowkey)){ intransitCount = intransitCount+(entity.getIntransitGRCount() == null ? 0 : entity.getIntransitGRCount()); successCount = successCount+(entity.getProcessedGRCount() == null ? 0 : entity.getProcessedGRCount()); errorCount = errorCount+(entity.getErrorGRCount() == null ? 0 : entity.getErrorGRCount()); }else if("ITEM".equals(rowkey)){ intransitCount = intransitCount+(entity.getIntransitItemCount() == null ? 0 : entity.getIntransitItemCount()); successCount = successCount+(entity.getProcessedItemCount() == null ? 0 : entity.getProcessedItemCount()); errorCount = errorCount+(entity.getErrorItemCount() == null ? 0 : entity.getErrorItemCount()); }else if("SUPPLIER".equals(rowkey)){ intransitCount = intransitCount+(entity.getIntransitSupplierCount() == null ? 0 : entity.getIntransitSupplierCount()); successCount = successCount+(entity.getProcessedSupplierCount() == null ? 0 : entity.getProcessedSupplierCount()); errorCount = errorCount+(entity.getErrorSupplierCount() == null ? 0 : entity.getErrorSupplierCount()); }*/ list = new ArrayList<>(); list.add(intransitCount); list.add(successCount); list.add(errorCount); erpToListMap.put(erp, list); } else { if ("PO".equals(rowkey)) { intransitCount = intransitCount + (entity.getIntransitCount() == null ? 0 : entity.getIntransitCount()); successCount = successCount + (entity.getProcessedCount() == null ? 0 : entity.getProcessedCount()); errorCount = errorCount + (entity.getErrorCount() == null ? 0 : entity.getErrorCount()); } /*else if("GR".equals(rowkey)){ intransitCount = intransitCount+(entity.getIntransitGRCount() == null ? 0 : entity.getIntransitGRCount()); successCount = successCount+(entity.getProcessedGRCount() == null ? 0 : entity.getProcessedGRCount()); errorCount = errorCount+(entity.getErrorGRCount() == null ? 0 : entity.getErrorGRCount()); }else if("ITEM".equals(rowkey)){ intransitCount = intransitCount+(entity.getIntransitItemCount() == null ? 0 : entity.getIntransitItemCount()); successCount = successCount+(entity.getProcessedItemCount() == null ? 0 : entity.getProcessedItemCount()); errorCount = errorCount+(entity.getErrorItemCount() == null ? 0 : entity.getErrorItemCount()); }else if("SUPPLIER".equals(rowkey)){ intransitCount = intransitCount+(entity.getIntransitSupplierCount() == null ? 0 : entity.getIntransitSupplierCount()); successCount = successCount+(entity.getProcessedSupplierCount() == null ? 0 : entity.getProcessedSupplierCount()); errorCount = errorCount+(entity.getErrorSupplierCount() == null ? 0 : entity.getErrorSupplierCount()); }*/ list = new ArrayList<>(); list.add(intransitCount); list.add(successCount); list.add(errorCount); erpToListMap.put(erp, list); } } return erpToListMap; } /** * Gets the status count entity. * * @param partitionKey the partition key * @param rowKey the row key * @return the status count entity * @throws InvalidKeyException the invalid key exception * @throws URISyntaxException the URI syntax exception * @throws StorageException the storage exception */ public MiscDataEntity getStatusCountEntity(String partitionKey, String rowKey) throws InvalidKeyException, URISyntaxException, StorageException { CloudTable cloudTable = azureStorage.getTable(miscDataTableName); TableOperation entity = TableOperation.retrieve(partitionKey, rowKey, MiscDataEntity.class); return cloudTable.execute(entity).getResultAsType(); } /** * Update status count entity. * * @param entity the entity * @throws InvalidKeyException the invalid key exception * @throws URISyntaxException the URI syntax exception * @throws StorageException the storage exception */ public void updateStatusCountEntity(MiscDataEntity entity) throws InvalidKeyException, URISyntaxException, StorageException { CloudTable cloudTable = azureStorage.getTable(miscDataTableName); TableOperation insert = TableOperation.insertOrMerge(entity); cloudTable.execute(insert); } /** * Gets the error data. * * @param partitionKey the partition key * @return the error data * @throws InvalidKeyException the invalid key exception * @throws URISyntaxException the URI syntax exception * @throws StorageException the storage exception */ public List<HashMap<String, String>> getErrorData(String partitionKey) throws InvalidKeyException, URISyntaxException, StorageException { List<HashMap<String, String>> errorData = new ArrayList<>(); String query = QueryBuilder.errorQuery(partitionKey, allErps); TableQuery<PoEntity> partitionQuery = TableQuery.from(PoEntity.class).where(query); //multiplePartitionWhereCondition CloudTable cloudTable = azureStorage.getTable(poTableName); for (PoEntity entity : cloudTable.execute(partitionQuery)) { HashMap<String, String> map = new HashMap<>(); map.put("Status", String.valueOf(entity.getSupplierDeliveryState())); map.put("Description", String.valueOf(entity.getDescription())); map.put("OrderNumber", String.valueOf(entity.getRowKey())); map.put("SourceErpName", String.valueOf(entity.getErpName())); errorData.add(map); } return errorData; } /* (non-Javadoc) * @see com.jci.po.repo.PoRepo#getErrorPos(java.lang.String, java.util.List) */ @Override public Map<String, List<HashMap<String, Object>>> getErrorPos(String partitionKey, List<String> poList) throws InvalidKeyException, URISyntaxException, StorageException { String query = QueryBuilder.getErrorPosQuery(partitionKey, poList); CloudTable cloudTable = azureStorage.getTable(poItemTableName); OperationContext opContext = new OperationContext(); TableQuery<DynamicTableEntity> myQuery = TableQuery.from(DynamicTableEntity.class).where(query).take(1000);//Need to discuss this Iterator<DynamicTableEntity> rows = cloudTable.execute(myQuery, null, opContext).iterator(); DynamicTableEntity row; EntityProperty ep; HashMap<String, Object> hashmap; Map<String, List<HashMap<String, Object>>> poNumToItemListMap = new HashMap<>(); while (rows.hasNext()) { row = rows.next(); HashMap<String, EntityProperty> map = row.getProperties(); hashmap = new HashMap<>(); String poNum = map.get("OrderNumber").getValueAsString(); for (String key : map.keySet()) { ep = map.get(key); hashmap.put(key, ep.getValueAsString()); } if (poNumToItemListMap.containsKey(poNum)) { List<HashMap<String, Object>> list = poNumToItemListMap.get(poNum); list.add(hashmap); poNumToItemListMap.put(poNum, list); } else { List<HashMap<String, Object>> list = new ArrayList<>(); list.add(hashmap); poNumToItemListMap.put(poNum, list); } } return poNumToItemListMap; } /* (non-Javadoc) * @see com.jci.po.repo.PoRepo#getPoDetails(java.lang.String, java.util.List) */ @Override public List<PoEntity> getPoDetails(String partitionKey, List<String> poList) throws InvalidKeyException, URISyntaxException, StorageException { String query = QueryBuilder.processPosQuery(partitionKey, poList); List<PoEntity> errorData = new ArrayList<>(); TableQuery<PoEntity> partitionQuery = TableQuery.from(PoEntity.class).where(query); CloudTable cloudTable = azureStorage.getTable(poTableName); for (PoEntity entity : cloudTable.execute(partitionQuery)) { errorData.add(entity); } return errorData; } /* (non-Javadoc) * @see com.jci.po.repo.PoRepo#getSegmentedResultSet(com.jci.po.azure.query.ScrollingParam, com.jci.po.azure.data.DataHelper) */ @Override public ResultSet getSegmentedResultSet(ScrollingParam param, DataHelper request) throws InvalidKeyException, URISyntaxException, StorageException { ResultContinuation continuationToken = DataUtil.getContinuationToken(param); PaginationParam pagination = new PaginationParam(); if (continuationToken != null) { pagination.setLastPartition(param.getPartition()); pagination.setLastRow(param.getRow()); } // Create the query String whereCondition = null; if (request.isErrorDataRequired()) { whereCondition = QueryBuilder.errorDataQuery(request.getPartitionValue()); } else { whereCondition = QueryBuilder.partitionWhereCondition(request.getPartitionValue()); } LOG.debug("whereCo" + "ndition--->" + whereCondition); if (StringUtils.isBlank(whereCondition)) { return null; } TableQuery<DynamicTableEntity> query = TableQuery.from(DynamicTableEntity.class).where(whereCondition) .take(param.getSize()); CloudTable table = azureStorage.getTable(request.getTableName()); LOG.debug("getTableName--->" + request.getTableName()); LOG.debug("query--->" + query.getFilterString()); // segmented query ResultSegment<DynamicTableEntity> response = table.executeSegmented(query, continuationToken); // next continuation token continuationToken = response.getContinuationToken(); if (continuationToken != null) { pagination.setNextPartition(continuationToken.getNextPartitionKey()); pagination.setNextRow(continuationToken.getNextRowKey()); } HashMap<String, Object> hashmap; List<HashMap<String, Object>> series = new ArrayList<>(); DynamicTableEntity row; EntityProperty ep; Iterator<DynamicTableEntity> rows = response.getResults().iterator(); LOG.debug("rows size--->" + response.getLength()); while (rows.hasNext()) { row = rows.next(); HashMap<String, EntityProperty> map = row.getProperties(); hashmap = new HashMap<>(); if ((request.getTableName()).equals(userTableName)) { for (String key : map.keySet()) { ep = map.get(key); hashmap.put(key, ep.getValueAsString()); } hashmap.put("globalId", row.getRowKey()); hashmap.put("id", row.getTimestamp().getTime()); hashmap.put("creationDate", row.getTimestamp()); } else { hashmap.put("id", row.getRowKey()); hashmap.put("OrderNumber", row.getRowKey()); for (String key : map.keySet()) { ep = map.get(key); if (key.equals("SupplierDeliveryState")) { hashmap.put("Status", ep.getValueAsString()); } } } series.add(hashmap); } return new ResultSet(series, pagination); } /* (non-Javadoc) * @see com.jci.po.repo.PoRepo#batchUpdate(com.jci.po.dto.req.BatchUpdateReq) */ public BatchUpdateRes batchUpdate(BatchUpdateReq request) { BatchUpdateRes response = new BatchUpdateRes(); String erpName = request.getErpName(); HashMap<String, List<PoEntity>> tableNameToEntityMap = request.getTableNameToEntityMap(); List<String> errorList = new ArrayList<>(); List<String> successList = new ArrayList<>(); CloudTable cloudTable = null; PoEntity entity = null; int successCount = 0; for (Map.Entry<String, List<PoEntity>> entry : tableNameToEntityMap.entrySet()) { try { cloudTable = azureStorage.getTable(entry.getKey()); } catch (Exception e) { LOG.error("### Exception in PoRepoImpl.batchUpdate.getTable ###" + e); response.setError(true); response.setMessage("The Application has encountered an error! Table does not exist !"); continue; } // Define a batch operation. TableBatchOperation batchOperation = new TableBatchOperation(); List<PoEntity> value = entry.getValue(); for (int i = 0; i < value.size(); i++) { entity = value.get(i); entity.setGlobalId(request.getGlobalId()); entity.setUserName(request.getUserName()); entity.setComment(request.getComment()); entity.setSupplierDeliveryState(2); successCount = successCount + 1; successList.add(entity.getRowKey()); batchOperation.insertOrMerge(entity); if (i != 0 && (i % batchSize) == 0) { try { cloudTable.execute(batchOperation); batchOperation.clear(); } catch (Exception e) { response.setError(true); response.setMessage("The Application has encountered an error!"); successCount = successCount - 1; LOG.error("### Exception in PoRepoImpl.batchUpdate.execute ###" + e); continue; } } } if (batchOperation.size() > 0) { try { cloudTable.execute(batchOperation); } catch (Exception e) { response.setError(true); response.setMessage("The Application has encountered an error!"); successCount = successCount - 1; LOG.error("### Exception in PoRepoImpl.batchUpdate.execute ###" + e); continue; } } } response.setErrorList(errorList); response.setSuccessList(successList); //Insert MIsc data: need to make sure only for podetails MiscDataEntity miscEntity = null; try { miscEntity = getStatusCountEntity("STATUS_COUNT", erpName); } catch (InvalidKeyException | URISyntaxException | StorageException e) { LOG.error("### Exception in PoRepoImpl.batchUpdate ####", e); response.setError(true); response.setMessage("The Application has encountered an error!"); } if (successCount > 0) { int sum1 = miscEntity.getProcessedCount() + successCount; miscEntity.setProcessedCount(sum1); int sum2 = miscEntity.getErrorCount() - successCount; miscEntity.setErrorCount(sum2); try { updateStatusCountEntity(miscEntity); } catch (InvalidKeyException | URISyntaxException | StorageException e) { LOG.error("### Exception in PoRepoImpl.batchUpdate ####", e); response.setError(true); response.setMessage("The Application has encountered an error!"); } } return response; }//Ending batchUpdate /* (non-Javadoc) * @see com.jci.po.repo.PoRepo#getPoItemDetail(com.jci.po.azure.query.ScrollingParam, com.jci.po.azure.data.DataHelper) */ @Override public ResultSet getPoItemDetail(ScrollingParam param, DataHelper request) throws InvalidKeyException, URISyntaxException, StorageException { ResultContinuation continuationToken = DataUtil.getContinuationToken(param); PaginationParam pagination = new PaginationParam(); if (continuationToken != null) { pagination.setLastPartition(param.getPartition()); pagination.setLastRow(param.getRow()); } // Create the query String whereCondition = QueryBuilder.poItemDetailQuery(request); LOG.debug("whereCondition--->" + whereCondition); if (StringUtils.isBlank(whereCondition)) { return null; } TableQuery<DynamicTableEntity> query = TableQuery.from(DynamicTableEntity.class).where(whereCondition) .take(param.getSize()); CloudTable table = azureStorage.getTable(request.getTableName()); LOG.debug("getTableName--->" + request.getTableName()); // segmented query ResultSegment<DynamicTableEntity> response = table.executeSegmented(query, continuationToken); // next continuation token continuationToken = response.getContinuationToken(); if (continuationToken != null) { pagination.setNextPartition(continuationToken.getNextPartitionKey()); pagination.setNextRow(continuationToken.getNextRowKey()); } HashMap<String, Object> hashmap; List<HashMap<String, Object>> series = new ArrayList<>(); DynamicTableEntity row; EntityProperty ep; ObjectMapper mapper = new ObjectMapper(); TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() { }; Iterator<DynamicTableEntity> rows = response.getResults().iterator(); while (rows.hasNext()) { row = rows.next(); HashMap<String, EntityProperty> map = row.getProperties(); hashmap = new HashMap<>(); for (String key : map.keySet()) { ep = map.get(key); if ("POItemJsonString".equals(key) || "POJsonString".equals(key)) { try { hashmap = mapper.readValue(ep.getValueAsString(), typeRef); if ("POJsonString".equals(key) && hashmap.containsKey("itemList")) { hashmap.remove("itemList"); } hashmap.put("id", row.getRowKey()); } catch (IOException e) { LOG.error("### Exception in ####", e); } } } series.add(hashmap); } LOG.error("series--->" + series); return new ResultSet(series, pagination); } @Override public boolean isAdmin(String globalId) throws InvalidKeyException, URISyntaxException, StorageException { CloudTable cloudTable = azureStorage.getTable(userTableName); TableOperation entity = TableOperation.retrieve(userPk, globalId, UserDetailsEntity.class); UserDetailsEntity details = cloudTable.execute(entity).getResultAsType(); LOG.debug("details--->" + details); // LOG.debug("getAdmin--->" + details.getAdmin()); if ("Admin".equalsIgnoreCase(details.getRole())) { return true; } return false; } @Override public boolean updateUserDetails(UserDetailsEntity entity) throws InvalidKeyException, URISyntaxException, StorageException { // LOG.debug("entity--->" + entity.getAdmin()); LOG.debug("entity--->" + entity.getUserName()); CloudTable cloudTable = azureStorage.getTable(userTableName); TableOperation insert = TableOperation.insertOrMerge(entity); cloudTable.execute(insert); return true; } @Override public boolean deleteUserDetails(UserDetailsEntity entity) throws InvalidKeyException, URISyntaxException, StorageException { //LOG.debug("before entity--->" + entity.getAdmin()); LOG.debug("before entity--->" + entity.getUserName()); CloudTable cloudTable = azureStorage.getTable(userTableName); TableOperation userOper = TableOperation.retrieve(entity.getPartitionKey(), entity.getRowKey(), UserDetailsEntity.class); // Retrieve the entity with partition key of "Smith" and row key of "Jeff". UserDetailsEntity userEntity = cloudTable.execute(userOper).getResultAsType(); TableOperation insert = TableOperation.delete(userEntity); cloudTable.execute(insert); return true; } @Override public UserDetailsEntity getUserEntity(String partitionKey, String rowKey) throws InvalidKeyException, URISyntaxException, StorageException { CloudTable cloudTable = azureStorage.getTable(userTableName); TableOperation entity = TableOperation.retrieve(partitionKey, rowKey, UserDetailsEntity.class); return cloudTable.execute(entity).getResultAsType(); } }