diff --git a/pom.xml b/pom.xml
index 77946dbc35c10e78938ea0703653736716f49816..ad09745bc80d45934de08825c575aadb9746138e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -44,7 +44,12 @@
 			<artifactId>javax.mail</artifactId>
 			<version>1.6.0</version>
 		</dependency>
-
+		<!-- https://mvnrepository.com/artifact/com.opencsv/opencsv -->
+		<dependency>
+			<groupId>com.opencsv</groupId>
+			<artifactId>opencsv</artifactId>
+			<version>5.7.1</version>
+		</dependency>
 		<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
 		<dependency>
 			<groupId>org.apache.poi</groupId>
diff --git a/src/main/java/com/tarento/formservice/controllers/FormsController.java b/src/main/java/com/tarento/formservice/controllers/FormsController.java
index 7e52c02f8602bf188910dec3be8cd5cf09f9d962..ab41ae9749a187f657243c9e4bcad73197c63609 100644
--- a/src/main/java/com/tarento/formservice/controllers/FormsController.java
+++ b/src/main/java/com/tarento/formservice/controllers/FormsController.java
@@ -6,6 +6,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import com.tarento.formservice.model.*;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.tomcat.util.codec.binary.Base64;
 import org.slf4j.Logger;
@@ -28,16 +29,6 @@ import org.springframework.web.multipart.MultipartFile;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.google.gson.Gson;
-import com.tarento.formservice.model.AssignApplication;
-import com.tarento.formservice.model.Consent;
-import com.tarento.formservice.model.FormData;
-import com.tarento.formservice.model.IncomingData;
-import com.tarento.formservice.model.KeyValue;
-import com.tarento.formservice.model.KeyValueList;
-import com.tarento.formservice.model.SearchObject;
-import com.tarento.formservice.model.SearchRequestDto;
-import com.tarento.formservice.model.Status;
-import com.tarento.formservice.model.UserInfo;
 import com.tarento.formservice.models.Form;
 import com.tarento.formservice.models.FormDetail;
 import com.tarento.formservice.service.FormsService;
@@ -173,6 +164,21 @@ public class FormsController {
 		return ResponseGenerator.failureResponse(Constants.ResponseMessages.ERROR_MESSAGE);
 	}
 
+	@PostMapping(value = PathRoutes.FormServiceApi.GET_INSTITUTE_DATA, produces = MediaType.APPLICATION_JSON_VALUE)
+	public String getInstituteData(
+			@RequestHeader(value = Constants.Parameters.X_USER_INFO, required = false) String xUserInfo,
+			@RequestBody InstituteDownloadRequestDto instituteDownloadRequestDto) throws JsonProcessingException {
+		UserInfo userInfo = null;
+		if (StringUtils.isNotBlank(xUserInfo)) {
+			userInfo = new Gson().fromJson(xUserInfo, UserInfo.class);
+		}
+		String responseData = formsService.getInstitutesData(userInfo, instituteDownloadRequestDto);
+		if (responseData != null) {
+			return ResponseGenerator.successResponse(responseData);
+		}
+		return ResponseGenerator.failureResponse(Constants.ResponseMessages.ERROR_MESSAGE);
+	}
+
 	@GetMapping(value = PathRoutes.FormServiceApi.GET_APPLICATIONS_STATUS_COUNT, produces = MediaType.APPLICATION_JSON_VALUE)
 	public String getApplicationsStatusCount(
 			@RequestHeader(value = Constants.Parameters.X_USER_INFO, required = false) String xUserInfo)
diff --git a/src/main/java/com/tarento/formservice/model/CSVDataDto.java b/src/main/java/com/tarento/formservice/model/CSVDataDto.java
new file mode 100644
index 0000000000000000000000000000000000000000..36d2c9fc25b44ed413222ac342fd10975656207d
--- /dev/null
+++ b/src/main/java/com/tarento/formservice/model/CSVDataDto.java
@@ -0,0 +1,26 @@
+package com.tarento.formservice.model;
+
+import lombok.*;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+@ToString
+public class CSVDataDto {
+
+    private String applicationId;
+    private Long formId;
+    private String title;
+    private String section;
+    private String question;
+    private String instituteAnswer;
+    private String inspectionAnswer;
+    private String updatedBy;
+    private String updatedDate;
+    private String createdDate;
+    private Integer version;
+    private String status;
+    private String inspectionCompletionDate;
+
+}
diff --git a/src/main/java/com/tarento/formservice/model/InstituteCSVResponseDto.java b/src/main/java/com/tarento/formservice/model/InstituteCSVResponseDto.java
new file mode 100644
index 0000000000000000000000000000000000000000..21991bc1d98c92bad65d2eb590f41990040d2c32
--- /dev/null
+++ b/src/main/java/com/tarento/formservice/model/InstituteCSVResponseDto.java
@@ -0,0 +1,11 @@
+package com.tarento.formservice.model;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class InstituteCSVResponseDto {
+
+    private String data;
+}
diff --git a/src/main/java/com/tarento/formservice/model/InstituteDownloadRequestDto.java b/src/main/java/com/tarento/formservice/model/InstituteDownloadRequestDto.java
new file mode 100644
index 0000000000000000000000000000000000000000..ecb7fc35d4925ce4370d51dad551795579850974
--- /dev/null
+++ b/src/main/java/com/tarento/formservice/model/InstituteDownloadRequestDto.java
@@ -0,0 +1,15 @@
+package com.tarento.formservice.model;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.List;
+
+@Getter
+@Setter
+public class InstituteDownloadRequestDto {
+
+    private Integer page;
+    private Integer size;
+}
+
diff --git a/src/main/java/com/tarento/formservice/repository/ElasticSearchRepository.java b/src/main/java/com/tarento/formservice/repository/ElasticSearchRepository.java
index 43cbd793bc49ad553ec5b015322e669ca61ce594..9b2f7d0c563dddddd70be71f4aba9b2aac4571ee 100644
--- a/src/main/java/com/tarento/formservice/repository/ElasticSearchRepository.java
+++ b/src/main/java/com/tarento/formservice/repository/ElasticSearchRepository.java
@@ -25,6 +25,8 @@ import org.elasticsearch.client.RequestOptions;
 import org.elasticsearch.client.RestClient;
 import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback;
 import org.elasticsearch.client.RestHighLevelClient;
+import org.elasticsearch.client.core.CountRequest;
+import org.elasticsearch.client.core.CountResponse;
 import org.elasticsearch.common.xcontent.XContentType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -268,4 +270,15 @@ public class ElasticSearchRepository {
 		}
 		return response;
 	}
+
+	public CountResponse executeCountRequest(CountRequest countRequest) {
+		CountResponse response = null;
+		try {
+			response = client.count(countRequest, RequestOptions.DEFAULT);
+		} catch (IOException e) {
+			LOGGER.error(marker, "Encountered an error while connecting : ", e);
+			LOGGER.error(marker, "Error Message to report : {}", e.getMessage());
+		}
+		return response;
+	}
 }
diff --git a/src/main/java/com/tarento/formservice/service/FormsService.java b/src/main/java/com/tarento/formservice/service/FormsService.java
index 34b5a6e615a904115180aae3fa440dbec34a38a7..7204e9287b78e54112a1f48cb272bcafebcf69fb 100644
--- a/src/main/java/com/tarento/formservice/service/FormsService.java
+++ b/src/main/java/com/tarento/formservice/service/FormsService.java
@@ -6,17 +6,9 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentMap;
 
+import com.tarento.formservice.model.*;
 import org.springframework.web.multipart.MultipartFile;
 
-import com.tarento.formservice.model.AssignApplication;
-import com.tarento.formservice.model.Consent;
-import com.tarento.formservice.model.IncomingData;
-import com.tarento.formservice.model.KeyValueList;
-import com.tarento.formservice.model.ResponseData;
-import com.tarento.formservice.model.SearchRequestDto;
-import com.tarento.formservice.model.State;
-import com.tarento.formservice.model.StateMatrix;
-import com.tarento.formservice.model.UserInfo;
 import com.tarento.formservice.models.Form;
 import com.tarento.formservice.models.FormDetail;
 
@@ -44,6 +36,8 @@ public interface FormsService {
 	
 	List<Map<String, Object>> getAllPlainForms();
 
+	String getInstitutesData(UserInfo userInfo, InstituteDownloadRequestDto instituteDownloadRequestDto);
+
 	KeyValueList getApplicationsStatusCount(UserInfo userInfo);
 
 	public Boolean saveFormSubmitv1(IncomingData incomingData, UserInfo userInfo, String action);
diff --git a/src/main/java/com/tarento/formservice/service/impl/FormsServiceImpl.java b/src/main/java/com/tarento/formservice/service/impl/FormsServiceImpl.java
index 476d021ea873470164c742641210348a67b504e0..da78424d794f5a3374cbe4bf715f72d012e62950 100644
--- a/src/main/java/com/tarento/formservice/service/impl/FormsServiceImpl.java
+++ b/src/main/java/com/tarento/formservice/service/impl/FormsServiceImpl.java
@@ -3,7 +3,18 @@ package com.tarento.formservice.service.impl;
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.FileWriter;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.*;
+import java.util.concurrent.ConcurrentMap;
+import java.util.stream.Collectors;
+
+import com.opencsv.CSVWriter;
+import com.tarento.formservice.model.*;
+import org.apache.commons.io.FileUtils;
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Calendar;
@@ -20,6 +31,8 @@ import org.apache.commons.lang3.StringUtils;
 import org.elasticsearch.action.search.MultiSearchResponse;
 import org.elasticsearch.action.search.SearchRequest;
 import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.client.core.CountRequest;
+import org.elasticsearch.client.core.CountResponse;
 import org.elasticsearch.index.query.BoolQueryBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.index.query.RangeQueryBuilder;
@@ -91,240 +104,242 @@ import com.tarento.formservice.utils.NotificationService.NotificationUtil;
 @Service(Constants.ServiceRepositories.FORM_SERVICE)
 public class FormsServiceImpl implements FormsService {
 
-	public static final Logger LOGGER = LoggerFactory.getLogger(FormsServiceImpl.class);
-
-	Gson gson = new Gson();
-	ObjectMapper objectMapper = new ObjectMapper();
-
-	@Autowired
-	private ElasticSearchRepository elasticRepository;
-
-	@Autowired
-	private FormsDao formsDao;
-
-	@Autowired
-	private AppConfiguration appConfig;
-
-	@Autowired
-	private ActivityService activityService;
-	
-	@Autowired
-	InstituteCoursesDao instituteCoursesDao;
-
-	@Override
-	public Form createForm(FormDetail newForm) throws IOException {
-		Boolean response = Boolean.FALSE;
-		if (newForm.getId() != null)
-			performVersionCheck(newForm);
-
-		if (newForm.getId() != null) {
-			newForm.setUpdatedDate(new Date().getTime());
-			response = formsDao.updateForm(newForm);
-		} else {
-			newForm.setId(new Date().getTime());
-			newForm.setUpdatedDate(new Date().getTime());
-			newForm.setVersion(1);
-			addAdditionalMandatoryFormFields(newForm);
-			response = formsDao.addForm(newForm);
-		}
-		return (response) ? newForm : null;
-
-	}
-
-	private void addAdditionalMandatoryFormFields(FormDetail newForm) {
-		String jsonContent = "[{\"refApi\":\"\",\"logicalGroupCode\":\"\",\"name\":\"heading\",\"fieldType\":\"heading\",\"values\":[{\"heading\":\"Inspection Summary\",\"subHeading\":\"Summary section where inspector is expected to add a detailed statement\",\"additionalProperties\":{}}],\"isRequired\":false,\"order\":1,\"additionalProperties\":{}},{\"refApi\":\"\",\"logicalGroupCode\":\"\",\"name\":\"Enter the summary of this inspection\",\"fieldType\":\"textarea\",\"values\":[],\"isRequired\":false,\"order\":2,\"additionalProperties\":{}},{\"refApi\":\"\",\"logicalGroupCode\":\"\",\"name\":\"Terms and Conditions\",\"fieldType\":\"checkbox\",\"values\":[{\"additionalProperties\":{\"value\":\"I accept the terms and conditions laid out by UP SMF\",\"key\":\"accept\"}}],\"isRequired\":false,\"order\":3,\"additionalProperties\":{}}]";
-		try {
-			List<Field> inspectionFields = objectMapper.readValue(jsonContent, new TypeReference<List<Field>>() {
-			});
-			newForm.setInspectionFields(inspectionFields);
-		} catch (Exception e) {
-			LOGGER.error("Encountered Error : {}", e.getMessage());
-
-		}
-
-	}
-
-	private void performVersionCheck(Form newForm) {
-		MultiSearchResponse response = elasticRepository
-				.executeMultiSearchRequest(createRequestForVersionCheck(newForm));
-		SearchResponse searchResponse = response.getResponses()[0].getResponse();
-		if (searchResponse != null) {
-			for (SearchHit hit : searchResponse.getHits()) {
-				Form existingForm = gson.fromJson(hit.getSourceAsString(), Form.class);
-				if (existingForm.getId().equals(newForm.getId()) && existingForm.getVersion() == newForm.getVersion()) {
-					int nextVersion = newForm.getVersion() + 1;
-					newForm.setVersion(nextVersion);
-				}
-			}
-		}
-
-	}
-
-	private SearchRequest createRequestForVersionCheck(Form newForm) {
-		SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(1000);
-		BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
-		boolBuilder.must().add(QueryBuilders.matchQuery(Constants.Parameters.ID, newForm.getId()));
-		searchSourceBuilder.query(boolBuilder);
-		SearchRequest sRequest;
-		sRequest = new SearchRequest(appConfig.getFormIndex()).source(searchSourceBuilder);
-		return sRequest;
-	}
-
-	@Override
-	public List<Form> getAllForms(UserInfo userInfo, Boolean isDetail) {
-		List<Form> formList = new ArrayList<>();
-		SearchRequest searchRequest = buildQueryForGetAllForms(userInfo);
-		MultiSearchResponse response = elasticRepository.executeMultiSearchRequest(searchRequest);
-		SearchResponse searchResponse = response.getResponses()[0].getResponse();
-		JsonNode responseNode = null;
-		if (searchResponse != null) {
-			responseNode = new ObjectMapper().convertValue(searchResponse.getAggregations(), JsonNode.class);
-			JsonNode aggregationNode = responseNode.findValue("UniqueFormId");
-			if (aggregationNode.has("buckets")) {
-				JsonNode buckets = aggregationNode.findValue("buckets");
-				for (JsonNode bucket : buckets) {
-					@SuppressWarnings("unused")
-					JsonNode latestVersionNode = bucket.findValue("LatestVersion");
-					JsonNode hitsNode = latestVersionNode.get("hits");
-					if (hitsNode.has("hits")) {
-						JsonNode innerHits = hitsNode.findValue("hits");
-						for (JsonNode eachInnerHit : innerHits) {
-							Form form = null;
-							if (isDetail != null && isDetail) {
-								form = gson.fromJson(eachInnerHit.findValue("sourceAsMap").toString(),
-										FormDetail.class);
-							} else {
-								form = gson.fromJson(eachInnerHit.findValue("sourceAsMap").toString(), Form.class);
-							}
-							form.setNumberOfRecords((long) randInt(1, 1000));
-							formList.add(form);
-						}
-					}
-				}
-			}
-			LOGGER.info("Form List: {}", gson.toJson(formList));
-		}
-		return formList;
-	}
-
-	public static int randInt(int min, int max) {
-		Random rand = new Random();
-		return rand.nextInt((max - min) + 1) + min;
-	}
-
-	@Override
-	public FormDetail getFormById(Long id) {
-		FormDetail form = new FormDetail();
-		SearchRequest searchRequest = buildQueryForGetQueryById(id);
-		MultiSearchResponse response = elasticRepository.executeMultiSearchRequest(searchRequest);
-		SearchResponse searchResponse = response.getResponses()[0].getResponse();
-		JsonNode responseNode = null;
-		if (searchResponse != null) {
-			responseNode = new ObjectMapper().convertValue(searchResponse.getAggregations(), JsonNode.class);
-			JsonNode aggregationNode = responseNode.findValue("UniqueFormId");
-			if (aggregationNode.has("buckets")) {
-				JsonNode buckets = aggregationNode.findValue("buckets");
-				for (JsonNode bucket : buckets) {
-					JsonNode latestVersionNode = bucket.findValue("LatestVersion");
-					JsonNode hitsNode = latestVersionNode.get("hits");
-					if (hitsNode.has("hits")) {
-						JsonNode innerHits = hitsNode.findValue("hits");
-						for (JsonNode eachInnerHit : innerHits) {
-							form = gson.fromJson(eachInnerHit.findValue("sourceAsMap").toString(), FormDetail.class);
-							LOGGER.info("Each Form : {}", gson.toJson(form));
-						}
-					}
-
-				}
-			}
-		}
-		return form;
-	}
-
-	private SearchRequest buildQueryForGetAllForms(UserInfo userInfo) {
-		SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(0).query(roleBasedFormQuery(userInfo))
-				.aggregation(AggregationBuilders.terms("UniqueFormId").field("id").size(100)
-						.order(BucketOrder.key(Boolean.TRUE))
-						.subAggregation(AggregationBuilders.topHits("LatestVersion").from(0).size(1)
-								.version(Boolean.FALSE).explain(Boolean.FALSE)
-								.sort(SortBuilders.fieldSort("version").order(SortOrder.DESC))));
-		return new SearchRequest(appConfig.getFormIndex()).source(searchSourceBuilder);
-	}
-
-	private BoolQueryBuilder roleBasedFormQuery(UserInfo userInfo) {
-		BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
-		if (userInfo != null) {
-			// Returning all the published & unpublished forms for regulator & inspector
-			// login and only published form for institute login
-			for (Role role : userInfo.getRoles()) {
-				if (role.getName().equalsIgnoreCase(Roles.INSTITUTION.name())) {
-					boolQuery.must(QueryBuilders.matchPhraseQuery(Constants.STATUS, Status.PUBLISH.name()));
-				} else if (role.getName().equalsIgnoreCase(Roles.REGULATOR.name())
-						|| role.getName().equalsIgnoreCase(Roles.INSPECTOR.name())) {
-					boolQuery
-							.should(QueryBuilders.boolQuery()
-									.mustNot(QueryBuilders.matchPhraseQuery(Constants.STATUS, Status.DRAFT.name())))
-							.should(QueryBuilders.boolQuery()
-									.must(QueryBuilders.matchPhraseQuery(Constants.STATUS, Status.DRAFT.name()))
-									.must(QueryBuilders.matchPhraseQuery(Constants.Parameters.UPDATED_BY,
-											userInfo.getId())));
-				}
-			}
-		} else {
-			boolQuery.must(QueryBuilders.matchPhraseQuery(Constants.STATUS, Status.PUBLISH.name()));
-		}
-
-		return boolQuery;
-	}
-
-	private SearchRequest buildQueryForGetQueryById(Long id) {
-		SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(0)
-				.query(QueryBuilders.boolQuery().must(QueryBuilders.matchQuery("id", id)))
-				.aggregation(AggregationBuilders.terms("UniqueFormId").field("id").size(100)
-						.subAggregation(AggregationBuilders.topHits("LatestVersion").from(0).size(1)
-								.version(Boolean.FALSE).explain(Boolean.FALSE)
-								.sort(SortBuilders.fieldSort("version").order(SortOrder.DESC))));
-		return new SearchRequest(appConfig.getFormIndex()).source(searchSourceBuilder);
-	}
-
-	@Override
-	public Boolean saveFormSubmit(IncomingData incomingData) throws IOException {
-		return formsDao.addFormData(incomingData);
-	}
-
-	@Override
-	public ResponseData fetchUserInfo(Long userId) {
-		try {
-			RestTemplate restTemplate = new RestTemplate();
-			final String uri = "http://localhost:8081/user/getUserById?id=" + userId + "&orgId=5001";
-			HttpHeaders headers = new HttpHeaders();
-			headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
-			UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(uri).queryParam("id", userId);
-			HttpEntity<?> entity = new HttpEntity<>(headers);
-			ResponseEntity<String> result = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity,
-					String.class);
-			if (result.getStatusCode() == HttpStatus.OK && !StringUtils.isEmpty(result.getBody())) {
-				Gson gson = new Gson();
-				Result rs = gson.fromJson(result.getBody(), Result.class);
-				if (rs.getResponseData() != null) {
-					return rs.getResponseData();
-				}
-			}
-		} catch (Exception e) {
-			LOGGER.error(String.format("Encountered an error while fetching user info object in userservice :  %s",
-					e.getMessage()));
-		}
-		return null;
-	}
-
-	public Boolean challengeFeedback(String id, String reason) throws IOException {
-		Map<String, Object> jsonMap = new HashMap<>();
-		jsonMap.put("challengeStatus", true);
-		jsonMap.put("reasonForChallenge", reason);
-		return formsDao.updateFormData(jsonMap, id);
-	}
-
-	@Override
+    public static final Logger LOGGER = LoggerFactory.getLogger(FormsServiceImpl.class);
+
+    Gson gson = new Gson();
+    ObjectMapper objectMapper = new ObjectMapper();
+
+    @Autowired
+    private ElasticSearchRepository elasticRepository;
+
+    @Autowired
+    private FormsDao formsDao;
+
+    @Autowired
+    private AppConfiguration appConfig;
+
+    @Autowired
+    private ActivityService activityService;
+    
+    @Autowired
+    InstituteCoursesDao instituteCoursesDao;
+
+    @Override
+    public Form createForm(FormDetail newForm) throws IOException {
+        Boolean response = Boolean.FALSE;
+        if (newForm.getId() != null)
+            performVersionCheck(newForm);
+
+        if (newForm.getId() != null) {
+            newForm.setUpdatedDate(new Date().getTime());
+            response = formsDao.updateForm(newForm);
+        } else {
+            newForm.setId(new Date().getTime());
+            newForm.setUpdatedDate(new Date().getTime());
+            newForm.setVersion(1);
+            addAdditionalMandatoryFormFields(newForm);
+            response = formsDao.addForm(newForm);
+        }
+        return (response) ? newForm : null;
+
+    }
+
+    private void addAdditionalMandatoryFormFields(FormDetail newForm) {
+        String jsonContent = "[{\"refApi\":\"\",\"logicalGroupCode\":\"\",\"name\":\"heading\",\"fieldType\":\"heading\",\"values\":[{\"heading\":\"Inspection Summary\",\"subHeading\":\"Summary section where inspector is expected to add a detailed statement\",\"additionalProperties\":{}}],\"isRequired\":false,\"order\":1,\"additionalProperties\":{}},{\"refApi\":\"\",\"logicalGroupCode\":\"\",\"name\":\"Enter the summary of this inspection\",\"fieldType\":\"textarea\",\"values\":[],\"isRequired\":false,\"order\":2,\"additionalProperties\":{}},{\"refApi\":\"\",\"logicalGroupCode\":\"\",\"name\":\"Terms and Conditions\",\"fieldType\":\"checkbox\",\"values\":[{\"additionalProperties\":{\"value\":\"I accept the terms and conditions laid out by UP SMF\",\"key\":\"accept\"}}],\"isRequired\":false,\"order\":3,\"additionalProperties\":{}}]";
+        try {
+            List<Field> inspectionFields = objectMapper.readValue(jsonContent, new TypeReference<List<Field>>() {
+            });
+            newForm.setInspectionFields(inspectionFields);
+        } catch (Exception e) {
+            LOGGER.error("Encountered Error : {}", e.getMessage());
+
+        }
+
+    }
+
+    private void performVersionCheck(Form newForm) {
+        MultiSearchResponse response = elasticRepository
+                .executeMultiSearchRequest(createRequestForVersionCheck(newForm));
+        SearchResponse searchResponse = response.getResponses()[0].getResponse();
+        if (searchResponse != null) {
+            for (SearchHit hit : searchResponse.getHits()) {
+                Form existingForm = gson.fromJson(hit.getSourceAsString(), Form.class);
+                if (existingForm.getId().equals(newForm.getId()) && existingForm.getVersion() == newForm.getVersion()) {
+                    int nextVersion = newForm.getVersion() + 1;
+                    newForm.setVersion(nextVersion);
+                }
+            }
+        }
+
+    }
+
+    private SearchRequest createRequestForVersionCheck(Form newForm) {
+        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(1000);
+        BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
+        boolBuilder.must().add(QueryBuilders.matchQuery(Constants.Parameters.ID, newForm.getId()));
+        searchSourceBuilder.query(boolBuilder);
+        SearchRequest sRequest;
+        sRequest = new SearchRequest(appConfig.getFormIndex()).source(searchSourceBuilder);
+        return sRequest;
+    }
+
+    @Override
+    public List<Form> getAllForms(UserInfo userInfo, Boolean isDetail) {
+        List<Form> formList = new ArrayList<>();
+        SearchRequest searchRequest = buildQueryForGetAllForms(userInfo);
+        MultiSearchResponse response = elasticRepository.executeMultiSearchRequest(searchRequest);
+        SearchResponse searchResponse = response.getResponses()[0].getResponse();
+        JsonNode responseNode = null;
+        if (searchResponse != null) {
+            responseNode = new ObjectMapper().convertValue(searchResponse.getAggregations(), JsonNode.class);
+            JsonNode aggregationNode = responseNode.findValue("UniqueFormId");
+            if (aggregationNode.has("buckets")) {
+                JsonNode buckets = aggregationNode.findValue("buckets");
+                for (JsonNode bucket : buckets) {
+                    @SuppressWarnings("unused")
+                    JsonNode latestVersionNode = bucket.findValue("LatestVersion");
+                    JsonNode hitsNode = latestVersionNode.get("hits");
+                    if (hitsNode.has("hits")) {
+                        JsonNode innerHits = hitsNode.findValue("hits");
+                        for (JsonNode eachInnerHit : innerHits) {
+                            Form form = null;
+                            if (isDetail != null && isDetail) {
+                                form = gson.fromJson(eachInnerHit.findValue("sourceAsMap").toString(),
+                                        FormDetail.class);
+                            } else {
+                                form = gson.fromJson(eachInnerHit.findValue("sourceAsMap").toString(), Form.class);
+                            }
+                            form.setNumberOfRecords((long) randInt(1, 1000));
+                            formList.add(form);
+                        }
+                    }
+                }
+            }
+            LOGGER.info("Form List: {}", gson.toJson(formList));
+        }
+        return formList;
+    }
+
+    public static int randInt(int min, int max) {
+        Random rand = new Random();
+        return rand.nextInt((max - min) + 1) + min;
+    }
+
+    @Override
+    public FormDetail getFormById(Long id) {
+        FormDetail form = new FormDetail();
+        SearchRequest searchRequest = buildQueryForGetQueryById(id);
+        MultiSearchResponse response = elasticRepository.executeMultiSearchRequest(searchRequest);
+        SearchResponse searchResponse = response.getResponses()[0].getResponse();
+        JsonNode responseNode = null;
+        if (searchResponse != null) {
+            responseNode = new ObjectMapper().convertValue(searchResponse.getAggregations(), JsonNode.class);
+            JsonNode aggregationNode = responseNode.findValue("UniqueFormId");
+            if (aggregationNode.has("buckets")) {
+                JsonNode buckets = aggregationNode.findValue("buckets");
+                for (JsonNode bucket : buckets) {
+                    JsonNode latestVersionNode = bucket.findValue("LatestVersion");
+                    JsonNode hitsNode = latestVersionNode.get("hits");
+                    if (hitsNode.has("hits")) {
+                        JsonNode innerHits = hitsNode.findValue("hits");
+                        for (JsonNode eachInnerHit : innerHits) {
+                            form = gson.fromJson(eachInnerHit.findValue("sourceAsMap").toString(), FormDetail.class);
+                            LOGGER.info("Each Form : {}", gson.toJson(form));
+                        }
+                    }
+
+                }
+            }
+        }
+        return form;
+    }
+
+    private SearchRequest buildQueryForGetAllForms(UserInfo userInfo) {
+        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(0).query(roleBasedFormQuery(userInfo))
+                .aggregation(AggregationBuilders.terms("UniqueFormId").field("id").size(100)
+                        .order(BucketOrder.key(Boolean.TRUE))
+                        .subAggregation(AggregationBuilders.topHits("LatestVersion").from(0).size(1)
+                                .version(Boolean.FALSE).explain(Boolean.FALSE)
+                                .sort(SortBuilders.fieldSort("version").order(SortOrder.DESC))));
+        return new SearchRequest(appConfig.getFormIndex()).source(searchSourceBuilder);
+    }
+
+    private BoolQueryBuilder roleBasedFormQuery(UserInfo userInfo) {
+        BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
+        if (userInfo != null) {
+            // Returning all the published & unpublished forms for regulator & inspector
+            // login and only published form for institute login
+            for (Role role : userInfo.getRoles()) {
+                if (role.getName().equalsIgnoreCase(Roles.INSTITUTION.name())) {
+                    boolQuery.must(QueryBuilders.matchPhraseQuery(Constants.STATUS, Status.PUBLISH.name()));
+                } else if (role.getName().equalsIgnoreCase(Roles.REGULATOR.name())
+                        || role.getName().equalsIgnoreCase(Roles.INSPECTOR.name())) {
+                    boolQuery
+                            .should(QueryBuilders.boolQuery()
+                                    .mustNot(QueryBuilders.matchPhraseQuery(Constants.STATUS, Status.DRAFT.name())))
+                            .should(QueryBuilders.boolQuery()
+                                    .must(QueryBuilders.matchPhraseQuery(Constants.STATUS, Status.DRAFT.name()))
+                                    .must(QueryBuilders.matchPhraseQuery(Constants.Parameters.UPDATED_BY,
+                                            userInfo.getId())));
+                }
+            }
+        } else {
+            boolQuery.must(QueryBuilders.matchPhraseQuery(Constants.STATUS, Status.PUBLISH.name()));
+        }
+
+        return boolQuery;
+    }
+
+    private SearchRequest buildQueryForGetQueryById(Long id) {
+        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(0)
+                .query(QueryBuilders.boolQuery().must(QueryBuilders.matchQuery("id", id)))
+                .aggregation(AggregationBuilders.terms("UniqueFormId").field("id").size(100)
+                        .subAggregation(AggregationBuilders.topHits("LatestVersion").from(0).size(1)
+                                .version(Boolean.FALSE).explain(Boolean.FALSE)
+                                .sort(SortBuilders.fieldSort("version").order(SortOrder.DESC))));
+        return new SearchRequest(appConfig.getFormIndex()).source(searchSourceBuilder);
+    }
+
+    @Override
+    public Boolean saveFormSubmit(IncomingData incomingData) throws IOException {
+        return formsDao.addFormData(incomingData);
+    }
+
+    @Override
+    public ResponseData fetchUserInfo(Long userId) {
+        try {
+            RestTemplate restTemplate = new RestTemplate();
+            final String uri = "http://localhost:8081/user/getUserById?id=" + userId + "&orgId=5001";
+            HttpHeaders headers = new HttpHeaders();
+            headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
+            UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(uri).queryParam("id", userId);
+            HttpEntity<?> entity = new HttpEntity<>(headers);
+            ResponseEntity<String> result = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity,
+                    String.class);
+            if (result.getStatusCode() == HttpStatus.OK && !StringUtils.isEmpty(result.getBody())) {
+                Gson gson = new Gson();
+                Result rs = gson.fromJson(result.getBody(), Result.class);
+                if (rs.getResponseData() != null) {
+                    return rs.getResponseData();
+                }
+            }
+        } catch (Exception e) {
+            LOGGER.error(String.format("Encountered an error while fetching user info object in userservice :  %s",
+                    e.getMessage()));
+        }
+        return null;
+    }
+
+    public Boolean challengeFeedback(String id, String reason) throws IOException {
+        Map<String, Object> jsonMap = new HashMap<>();
+        jsonMap.put("challengeStatus", true);
+        jsonMap.put("reasonForChallenge", reason);
+        return formsDao.updateFormData(jsonMap, id);
+    }
+
+   
+
+    @Override
 	public List<Map<String, Object>> getApplications(UserInfo userInfo, SearchRequestDto searchRequestDto) {
 		try {
 			// query builder
@@ -392,504 +407,693 @@ public class FormsServiceImpl implements FormsService {
 		return null;
 	}
 
-	/**
-	 * Add filters in search response
-	 */
-	private List<Map<String, Object>> filterSearchResults(List<Map<String, Object>> response,
-			List<SearchObject> filterObjects, UserInfo userInfo) throws Exception {
-		if (filterObjects != null && filterObjects.size() > 0) {
-			List<Map<String, Object>> filteredResponse = new ArrayList<>();
-			for (SearchObject searchObj : filterObjects) {
-				if (searchObj.getKey().equals(Constants.Parameters.TO_CONSENT)
-						&& searchObj.getValues().equals(Boolean.TRUE)) {
-					for (Map<String, Object> responseObj : response) {
-						IncomingData incomingData = objectMapper.convertValue(responseObj, IncomingData.class);
-						if (incomingData.getInspection() != null
-								&& incomingData.getInspection().getStatus().equals(Status.LEADINSCOMPLETED.name())
-								&& incomingData.getInspection().getAssignedTo() != null) {
-							for (Assignee assignee : incomingData.getInspection().getAssignedTo()) {
-								if (assignee.getId().equals(userInfo.getId())
-										&& StringUtils.isBlank(assignee.getStatus())) {
-									filteredResponse.add(responseObj);
-								}
-							}
-						}
-					}
-				}
-			}
-			return filteredResponse;
-		}
-		return response;
-	}
-
-	private void setRoleBasedSearchObject(UserInfo userInfo, SearchRequestDto searchRequestDto) {
-		if (userInfo != null && userInfo.getRoles() != null) {
-			for (Role role : userInfo.getRoles()) {
-				SearchObject roleBasedSearch = new SearchObject();
-				if (role.getName().equalsIgnoreCase(Roles.INSTITUTION.name())) {
-					roleBasedSearch.setKey(Constants.CREATED_BY);
-					roleBasedSearch.setValues(userInfo.getEmailId());
-				} else if (role.getName().equalsIgnoreCase(Roles.INSPECTOR.name())) {
-					roleBasedSearch.setKey(Constants.ASSIGNED_TO);
-					roleBasedSearch.setValues(userInfo.getId());
-				}
-				if (searchRequestDto.getSearchObjects() != null && StringUtils.isNotBlank(roleBasedSearch.getKey())) {
-					searchRequestDto.getSearchObjects().add(roleBasedSearch);
-				} else if (StringUtils.isNotBlank(roleBasedSearch.getKey())) {
-					List<SearchObject> searchObjectList = new ArrayList<>();
-					searchObjectList.add(roleBasedSearch);
-					searchRequestDto.setSearchObjects(searchObjectList);
-				}
-			}
-		}
-	}
-
-	private void setRoleBasedExcludeSearchObject(UserInfo userInfo, SearchRequestDto searchRequestDto) {
-		if (userInfo != null && userInfo.getRoles() != null) {
-			for (Role role : userInfo.getRoles()) {
-				if (role.getName().equalsIgnoreCase(Roles.REGULATOR.name())
-						|| role.getName().equalsIgnoreCase(Roles.INSPECTOR.name())) {
-					SearchObject roleBasedSearch = new SearchObject();
-					roleBasedSearch.setKey(Constants.STATUS);
-					roleBasedSearch.setValues(Status.DRAFT.name());
-					if (searchRequestDto.getExcludeObject() != null) {
-						searchRequestDto.getExcludeObject().add(roleBasedSearch);
-					} else if (StringUtils.isNotBlank(roleBasedSearch.getKey())) {
-						List<SearchObject> searchObjectList = new ArrayList<>();
-						searchObjectList.add(roleBasedSearch);
-						searchRequestDto.setExcludeObject(searchObjectList);
-					}
-				}
-
-			}
-		}
-	}
-
-	@Override
-	public KeyValueList getApplicationsStatusCount(UserInfo userInfo) {
-		try {
-			// query builder
-			if (userInfo != null && userInfo.getRoles() != null) {
-				for (Role role : userInfo.getRoles()) {
-					if (role.getName().equalsIgnoreCase(Roles.REGULATOR.name())) {
-						SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(0);
-						searchSourceBuilder.aggregation(AggregationBuilders.terms("Total Pending")
-								.field(Constants.ElasticSearchFields.MAPPING.get(Constants.STATUS)));
-						SearchRequest searchRequest = new SearchRequest(appConfig.getFormDataIndex())
-								.source(searchSourceBuilder);
-						LOGGER.info("Search Request : " + searchRequest);
-						List<Map<String, Object>> responseNode = formsDao.searchAggregationResponse(searchRequest,
-								"Total Pending");
-						return translateResponse(responseNode);
-					} else {
-						// Setting all prerequisites
-						List<Long> userIdList = new ArrayList<Long>();
-						userIdList.add(userInfo.getId());
-						Calendar cal = Calendar.getInstance();
-						cal.setTime(new Date());
-						KeyValueList finalList = new KeyValueList();
-						List<KeyValue> keyValueList = new ArrayList<>();
-						finalList.setKeyValues(keyValueList);
-						Calendar startOfTodayCal = Calendar.getInstance();
-						startOfTodayCal.setTime(new Date());
-						startOfTodayCal.add(Calendar.DAY_OF_YEAR, -1);
-						startOfTodayCal.set(Calendar.HOUR, 11);
-						startOfTodayCal.set(Calendar.AM_PM, Calendar.PM);
-						startOfTodayCal.set(Calendar.MINUTE, 59);
-
-						Calendar endOfTodayCal = Calendar.getInstance();
-						endOfTodayCal.setTime(new Date());
-						endOfTodayCal.set(Calendar.HOUR, 11);
-						endOfTodayCal.set(Calendar.AM_PM, Calendar.PM);
-						endOfTodayCal.set(Calendar.MINUTE, 59);
-
-						// Creating Search Request for Total Pending
-						TermsQueryBuilder userIdFilter = QueryBuilders.termsQuery(
-								Constants.ElasticSearchFields.MAPPING.get("inspectionLeadInspector"), userIdList);
-						TermQueryBuilder inspectionStatusFilter = QueryBuilders.termQuery(
-								Constants.ElasticSearchFields.MAPPING.get("inspectionStatus"),
-								Status.SENTFORINS.name());
-						TermQueryBuilder statusFilter = QueryBuilders.termQuery(
-								Constants.ElasticSearchFields.MAPPING.get("status"), Status.SENTFORINS.name());
-						BoolQueryBuilder filters = QueryBuilders.boolQuery().filter(userIdFilter)
-								.filter(inspectionStatusFilter).filter(statusFilter);
-						FilterAggregationBuilder totalPendingAggregationFilter = AggregationBuilders
-								.filter("Inspector Total Pending", filters)
-								.subAggregation(AggregationBuilders.cardinality("Count")
-										.field(Constants.ElasticSearchFields.MAPPING.get("inspectionApplicationId")));
-						SearchSourceBuilder totalPendingAggrSourceBuilder = new SearchSourceBuilder().size(0);
-						totalPendingAggrSourceBuilder.aggregation(totalPendingAggregationFilter);
-						SearchRequest totalPendingSearchRequest = new SearchRequest(appConfig.getFormDataIndex())
-								.source(totalPendingAggrSourceBuilder);
-						LOGGER.info("Search Request : " + totalPendingSearchRequest);
-						List<Map<String, Object>> totalPendingResponse = formsDao
-								.searchAggregationResponse(totalPendingSearchRequest, "Inspector Total Pending");
-						KeyValueList list = translateResponse(totalPendingResponse);
-						finalList.getKeyValues().addAll(list.getKeyValues());
-
-						// Creating Search Request for Received Today
-						RangeQueryBuilder assignedDateFilter = QueryBuilders
-								.rangeQuery(Constants.ElasticSearchFields.MAPPING.get("inspectionAssignedDate"))
-								.from(startOfTodayCal.getTime().getTime()).to(endOfTodayCal.getTime().getTime());
-						BoolQueryBuilder filters2 = QueryBuilders.boolQuery().filter(userIdFilter)
-								.filter(assignedDateFilter);
-						FilterAggregationBuilder receivedTodayAggregationFilter = AggregationBuilders
-								.filter("Received Today", filters2)
-								.subAggregation(AggregationBuilders.cardinality("Count")
-										.field(Constants.ElasticSearchFields.MAPPING.get("inspectionApplicationId")));
-						SearchSourceBuilder receivedTodayAggrSourceBuilder = new SearchSourceBuilder().size(0);
-						receivedTodayAggrSourceBuilder.aggregation(receivedTodayAggregationFilter);
-						SearchRequest receivedTodaySearchRequest = new SearchRequest(appConfig.getFormDataIndex())
-								.source(receivedTodayAggrSourceBuilder);
-						LOGGER.info("Search Request : " + receivedTodaySearchRequest);
-						List<Map<String, Object>> receivedTodayResponse = formsDao
-								.searchAggregationResponse(receivedTodaySearchRequest, "Received Today");
-						list = translateResponse(receivedTodayResponse);
-						finalList.getKeyValues().addAll(list.getKeyValues());
-
-						// Creating Search Request for Reviewed Today
-						RangeQueryBuilder updatedDateFilter = QueryBuilders.rangeQuery("inspectionDate")
-								.from(startOfTodayCal.getTime().getTime()).to(endOfTodayCal.getTime().getTime());
-						BoolQueryBuilder filters3 = QueryBuilders.boolQuery().filter(userIdFilter)
-								.filter(updatedDateFilter);
-						FilterAggregationBuilder reviewedTodayAggregationFilter = AggregationBuilders
-								.filter("Reviewed Today", filters3)
-								.subAggregation(AggregationBuilders.cardinality("Count")
-										.field(Constants.ElasticSearchFields.MAPPING.get("inspectionApplicationId")));
-						SearchSourceBuilder reviewedTodayAggrSourceBuilder = new SearchSourceBuilder().size(0);
-						reviewedTodayAggrSourceBuilder.aggregation(reviewedTodayAggregationFilter);
-						SearchRequest reviewedTodaySearchRequest = new SearchRequest(appConfig.getFormDataIndex())
-								.source(reviewedTodayAggrSourceBuilder);
-						LOGGER.info("Search Request : " + reviewedTodaySearchRequest);
-						List<Map<String, Object>> reviewedTodayResponse = formsDao
-								.searchAggregationResponse(reviewedTodaySearchRequest, "Reviewed Today");
-						list = translateResponse(reviewedTodayResponse);
-						finalList.getKeyValues().addAll(list.getKeyValues());
-
-						return finalList;
-
-					}
-				}
-			}
-
-		} catch (Exception ex) {
-			LOGGER.error(String.format(Constants.EXCEPTION, "getApplicationsStatusCount", ex.getMessage()));
-		}
-		return null;
-
-	}
-
-	KeyValueList translateResponse(List<Map<String, Object>> responseNode) {
-		KeyValueList list = new KeyValueList();
-		List<KeyValue> listOfKeyValuePairs = new ArrayList<KeyValue>();
-		for (Map<String, Object> eachMap : responseNode) {
-			List<KeyValue> keyValueList = eachMap.entrySet().stream().filter(entry -> !"DRAFT".equals(entry.getKey()))
-					.map(entry -> new KeyValue(entry.getKey().equals("NEW") ? "Total Pending" : entry.getKey(),
-							entry.getValue()))
-					.collect(Collectors.toList());
-			listOfKeyValuePairs.addAll(keyValueList);
-		}
-		list.setKeyValues(listOfKeyValuePairs);
-		return list;
-	}
-
-	KeyValueList translateInspectorResponse(List<Map<String, Object>> responseNode) {
-		KeyValueList list = new KeyValueList();
-		List<KeyValue> listOfKeyValuePairs = new ArrayList<KeyValue>();
-		for (Map<String, Object> eachMap : responseNode) {
-			List<KeyValue> keyValueList = eachMap.entrySet().stream()
-					.map(entry -> new KeyValue(entry.getKey(), entry.getValue())).collect(Collectors.toList());
-			listOfKeyValuePairs.addAll(keyValueList);
-		}
-		list.setKeyValues(listOfKeyValuePairs);
-		return list;
-	}
-
-	@Override
-	public Boolean saveFormSubmitv1(IncomingData incomingData, UserInfo userInfo, String action) {
-		Boolean indexed = Boolean.FALSE;
-		try {
-			if (StringUtils.isBlank(incomingData.getApplicationId())) {
-				incomingData.setTimestamp(DateUtils.getCurrentTimestamp());
-				incomingData.setCreatedDate(DateUtils.getYyyyMmDdInUTC());
-				indexed = formsDao.addFormData(incomingData);
-				appStatusTrack(indexed, objectMapper.convertValue(incomingData, Map.class), action, userInfo);
-			} else {
-				Map<String, Object> applicationObject = getApplicationById(incomingData.getApplicationId(), userInfo);
-				incomingData.setUpdatedDate(DateUtils.getYyyyMmDdInUTC());
-				indexed = formsDao.updateFormData(incomingData, incomingData.getApplicationId());
-				appStatusTrack(indexed, applicationObject, action, userInfo);
-			}
-		} catch (Exception e) {
-			LOGGER.error(String.format(Constants.EXCEPTION, "saveFormSubmitv1", e.getMessage()));
-		}
-		return indexed;
-	}
-
-	@Override
-	public Boolean savePlainForm(IncomingData incomingData) {
-		Boolean indexed = null;
-		try {
-			indexed = formsDao.addPlainFormData(incomingData);
-		} catch (Exception e) {
-			LOGGER.error(String.format(Constants.EXCEPTION, "savePlainForm", e.getMessage()));
-		}
-		return indexed;
-	}
-
-	@Override
-	public Map<String, Object> getApplicationById(String applicationId, UserInfo userInfo) {
-		SearchRequestDto searchRequestDto = new SearchRequestDto();
-		SearchObject sObject = new SearchObject();
-		sObject.setKey(Constants.APPLICATION_ID);
-		sObject.setValues(applicationId);
-		List<SearchObject> searchObjectList = new ArrayList<SearchObject>();
-		searchObjectList.add(sObject);
-		searchRequestDto.setSearchObjects(searchObjectList);
-		List<Map<String, Object>> responseData = getApplications(userInfo, searchRequestDto);
-		if (responseData != null) {
-			return (responseData.isEmpty()) ? new HashMap<>() : responseData.get(0);
-		}
-		return null;
-	}
-
-	@Override
-	public String fileUpload(MultipartFile multipartFile, String folderName) {
-		try {
-			String folderPath = Constants.UP_SMF;
-			if (StringUtils.isNotBlank(folderName)) {
-				folderPath = folderPath + "/" + folderName;
-			}
-			File file = new File(multipartFile.getOriginalFilename());
-			file.createNewFile();
-			FileOutputStream fos = new FileOutputStream(file);
-			fos.write(multipartFile.getBytes());
-			fos.close();
-			Map<String, String> uploadedFile = CloudStorage.uploadFile(folderPath, file);
-			file.delete();
-			return uploadedFile.get(Constants.URL);
-		} catch (Exception e) {
-			LOGGER.error(String.format(Constants.EXCEPTION, "fileUpload", e.getMessage()));
-			return null;
-		}
-	}
-
-	@Override
-	public Boolean deleteCloudFile(List<String> files) {
-		try {
-			for (String file : files) {
-				String fileName = file;
-				String[] nameList = file.split("/" + appConfig.getContainerName() + "/");
-				if (nameList.length > 1) {
-					fileName = nameList[1];
-				}
-				CloudStorage.deleteFile(fileName);
-			}
-			return Boolean.TRUE;
-		} catch (Exception e) {
-			LOGGER.error(String.format(Constants.EXCEPTION, "deleteCloudFile", e.getMessage()));
-		}
-		return Boolean.FALSE;
-	}
-
-	@Override
-	public Boolean reviewApplication(IncomingData incomingData, UserInfo userInfo) {
-		try {
-			SearchRequestDto srd = createSearchRequestObject(incomingData.getApplicationId());
-			List<Map<String, Object>> applicationMap = getApplications(userInfo, srd);
-			for (Map<String, Object> innerMap : applicationMap) {
-				if (innerMap.containsKey(Constants.STATUS)) {
-					incomingData.setStatus(innerMap.get(Constants.STATUS).toString());
-				}
-			}
-			incomingData.setReviewedDate(DateUtils.getYyyyMmDdInUTC());
-			WorkflowDto workflowDto = new WorkflowDto(incomingData, userInfo,
-					Constants.WorkflowActions.SAVE_FORM_NOTES);
-			WorkflowUtil.getNextStateForMyRequest(workflowDto);
-			incomingData.setStatus(workflowDto.getNextState());
-			return formsDao.updateFormData(incomingData, incomingData.getApplicationId());
-		} catch (Exception e) {
-			LOGGER.error(String.format(Constants.EXCEPTION, "reviewApplication", e.getMessage()));
-			return Boolean.FALSE;
-		}
-
-	}
-
-	public SearchRequestDto createSearchRequestObject(String applicationId) {
-		SearchRequestDto searchRequestDto = new SearchRequestDto();
-		SearchObject sObject = new SearchObject();
-		sObject.setKey(Constants.APPLICATION_ID);
-		sObject.setValues(applicationId);
-		List<SearchObject> searchObjectList = new ArrayList<SearchObject>();
-		searchObjectList.add(sObject);
-		searchRequestDto.setSearchObjects(searchObjectList);
-		return searchRequestDto;
-	}
-
-	@Override
-	public Boolean assignApplication(UserInfo userInfo, AssignApplication assign) {
-		try {
-			SearchRequestDto srd = createSearchRequestObject(assign.getApplicationId());
-			List<Map<String, Object>> applicationMap = getApplications(userInfo, srd);
-			for (Map<String, Object> innerMap : applicationMap) {
-				if (innerMap.containsKey(Constants.STATUS)) {
-					assign.setStatus(innerMap.get(Constants.STATUS).toString());
-				}
-				if (innerMap.containsKey(Constants.FORM_ID)) {
-					assign.setFormId(Long.parseLong(innerMap.get(Constants.FORM_ID).toString()));
-				}
-			}
-			WorkflowDto workflowDto = new WorkflowDto(assign, userInfo, Constants.WorkflowActions.ASSIGN_INSPECTOR);
-			WorkflowUtil.getNextStateForMyRequest(workflowDto);
-			assign.setStatus(workflowDto.getNextState());
-			if (assign.getLeadInspector() == null) {
-				assign.setLeadInspector(new ArrayList<>());
-			}
-			if (assign.getAssistingInspector() == null) {
-				assign.setAssistingInspector(new ArrayList<>());
-			}
-			if (assign.getAssistingInspector().size() > 0 || assign.getLeadInspector().size() > 0) {
-				List<Long> inspectorsId = new ArrayList<>();
-				inspectorsId.addAll(assign.getAssistingInspector());
-				inspectorsId.addAll(assign.getLeadInspector());
-				Map<String, Map<String, Object>> userMap = getUserDetails(inspectorsId, userInfo.getOrgId(),
-						userInfo.getAuthToken());
-				// set assigned user meta data
-				assign.setAssignedTo(new ArrayList<>());
-				for (Long userId : inspectorsId) {
-					Assignee assignee = new Assignee();
-					assignee.setId(userId);
-					String key = String.valueOf(userId);
-					if (userMap.containsKey(key)) {
-						assignee.setEmailId((String) userMap.get(key).get(Constants.Parameters.EMAIL_ID));
-						assignee.setFirstName((String) userMap.get(key).get(Constants.Parameters.FIRST_NAME));
-						assignee.setLastName((String) userMap.get(key).get(Constants.Parameters.LAST_NAME));
-						if (assign.getLeadInspector().contains(userId)) {
-							assignee.setLeadInspector(Boolean.TRUE);
-						}
-					}
-					assign.getAssignedTo().add(assignee);
-				}
-
-				IncomingData requestData = new IncomingData();
-				assign.setAssignedDate(DateUtils.getYyyyMmDdInUTC());
-				requestData.setInspection(assign);
-				requestData.setStatus(assign.getStatus());
-
-				
-				LOGGER.info(objectMapper.writeValueAsString(requestData));
-				LOGGER.info(objectMapper.writeValueAsString(assign));
-				Boolean response = formsDao.updateFormData(requestData, assign.getApplicationId());
-				appStatusTrack(response,
-						(applicationMap != null && applicationMap.size() > 0 ? applicationMap.get(0) : null),
-						Constants.WorkflowActions.ASSIGN_INSPECTOR, userInfo);
-				return response;
-			}
-			return Boolean.TRUE;
-		} catch (Exception e) {
-			LOGGER.error(String.format(Constants.EXCEPTION, "assignApplication", e.getMessage()));
-			return Boolean.FALSE;
-		}
-	}
-
-	/**
-	 * Makes rest call with user service to fetch the user details
-	 * 
-	 * @param userId
-	 *            Object
-	 * @param authToken
-	 *            String
-	 * @return
-	 */
-	private Map<String, Map<String, Object>> getUserDetails(Object userId, Object orgId, String authToken)
-			throws Exception {
-		Map<String, Object> requestBody = new HashMap<>();
-		requestBody.put(Constants.Parameters.ORG_ID, orgId);
-		requestBody.put(Constants.Parameters.SEARCH, new HashMap<String, Object>() {
-			{
-				put(Constants.Parameters.USER_ID, userId);
-			}
-		});
-		if (!authToken.toUpperCase().contains((Constants.Parameters.BEARER).toUpperCase())) {
-			authToken = Constants.Parameters.BEARER + authToken;
-		}
-		HttpHeaders headers = new HttpHeaders();
-		headers.add(Constants.Parameters.AUTHORIZATION, authToken);
-		Object response = RestService.postRequest(headers,
-				appConfig.getUserServiceHost() + appConfig.getGetAllUserApiPath(), requestBody);
-		if (response != null) {
-			List<Map<String, Object>> userList = objectMapper.convertValue(response,
-					new TypeReference<List<Map<String, Object>>>() {
-					});
-			return userList.stream()
-					.collect(Collectors.toMap(obj -> String.valueOf(obj.get(Constants.Parameters.ID)), obj -> obj));
-		}
-		return null;
-	}
-
-	public ConcurrentMap<Long, State> fetchAllStates() {
-		SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(1000);
-		// es call
-		SearchRequest searchRequest = new SearchRequest(appConfig.getFormStateIndex()).source(searchSourceBuilder);
-		LOGGER.info("Search Request : " + searchRequest);
-		return formsDao.fetchAllStates(searchRequest);
-	}
-
-	@Override
-	public ConcurrentMap<String, List<StateMatrix>> fetchAllStateMatrix() {
-		SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(1000);
-		// es call
-		SearchRequest searchRequest = new SearchRequest(appConfig.getFormStateMatrixIndex())
-				.source(searchSourceBuilder);
-		LOGGER.info("Search Request : " + searchRequest);
-		return formsDao.fetchAllStateMatrix(searchRequest);
-	}
-
-	@Override
-	public Boolean updateApplicationStatus(IncomingData incomingData, UserInfo userInfo, String status) {
-		try {
-			SearchRequestDto srd = createSearchRequestObject(incomingData.getApplicationId());
-			List<Map<String, Object>> applicationMap = getApplications(userInfo, srd);
-			for (Map<String, Object> innerMap : applicationMap) {
-				if (innerMap.containsKey(Constants.STATUS)) {
-					incomingData.setStatus(innerMap.get(Constants.STATUS).toString());
-					incomingData.setComments(
-							innerMap.containsKey(Constants.Parameters.COMMENTS) ? objectMapper.convertValue(
-									innerMap.get(Constants.Parameters.COMMENTS), new TypeReference<List<Object>>() {
-									}) : null);
-				}
-			}
-			incomingData.setReviewedDate(DateUtils.getYyyyMmDdInUTC());
-			WorkflowDto workflowDto = new WorkflowDto(incomingData, userInfo, status);
-			WorkflowUtil.getNextStateForMyRequest(workflowDto);
-			incomingData.setStatus(workflowDto.getNextState());
-			if (StringUtils.isNotBlank(incomingData.getNotes())) {
-				List<Object> commentsList = new ArrayList<>();
-				Map<String, Object> commentsMap = new HashMap<>();
-				commentsMap.put(Constants.TYPE, incomingData.getStatus().toLowerCase()
-						+ Constants.convertToTitleCase(Constants.Parameters.COMMENTS));
-				commentsMap.put(Constants.VALUE, incomingData.getNotes());
-				commentsMap.put(Constants.BY, userInfo.getId());
-				commentsMap.put(Constants.TIMESTAMP, DateUtils.getCurrentTimestamp());
-				if (incomingData.getComments() != null) {
-					commentsList = incomingData.getComments();
-				}
-				commentsList.add(commentsMap);
-				incomingData.setComments(commentsList);
-			}
-			Boolean response = formsDao.updateFormData(incomingData, incomingData.getApplicationId());
-			appStatusTrack(response,
-					(applicationMap != null && applicationMap.size() > 0 ? applicationMap.get(0) : null), status,
-					userInfo);
-			return response;
-		} catch (Exception e) {
-			LOGGER.error(String.format(Constants.EXCEPTION, "updateApplicationStatus", e.getMessage()));
-			return Boolean.FALSE;
-		}
-
-	}
-
-	@Override
+    @Override
+    public String getInstitutesData(UserInfo userInfo, InstituteDownloadRequestDto instituteDownloadRequestDto) {
+        try {
+            // count builder
+            CountRequest countRequest = new CountRequest(appConfig.getFormDataIndex()).query(QueryBuilders.matchAllQuery());
+            CountResponse countResponse = elasticRepository.executeCountRequest(countRequest);
+            LOGGER.debug("count Response : {}", countResponse);
+            if (countResponse == null || countResponse.getCount() <= 0) {
+                // no data in index
+                return null;
+            }
+            // query builder
+            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
+            // setting size and range in query
+            setSizeAndRangeLimit(instituteDownloadRequestDto, searchSourceBuilder, countResponse);
+            // creating bool query
+            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
+            boolBuilder.must(QueryBuilders.matchAllQuery());
+            searchSourceBuilder.query(boolBuilder).sort(Constants.TIMESTAMP, SortOrder.DESC);
+            // es call
+            SearchRequest searchRequest = new SearchRequest(appConfig.getFormDataIndex()).source(searchSourceBuilder);
+            LOGGER.info("Search Request : " + searchRequest);
+            List<Map<String, Object>> data = formsDao.searchResponse(searchRequest);
+            return createCSVFile(data);
+        } catch (Exception e) {
+            LOGGER.error(String.format(Constants.EXCEPTION, "getApplications", e.getMessage()));
+        }
+        return null;
+    }
+
+    private static void setSizeAndRangeLimit(InstituteDownloadRequestDto instituteDownloadRequestDto,
+                                             SearchSourceBuilder searchSourceBuilder,
+                                             CountResponse countResponse) {
+        // setting from limit if size is present in request
+        if (instituteDownloadRequestDto.getSize() != null && instituteDownloadRequestDto.getSize() > 0) {
+            searchSourceBuilder.size(instituteDownloadRequestDto.getSize());
+            int fromRange = 0;
+            if (instituteDownloadRequestDto.getPage() == 0) {
+                fromRange = instituteDownloadRequestDto.getSize() * (instituteDownloadRequestDto.getPage());
+            } else if (instituteDownloadRequestDto.getPage() > 0) {
+                fromRange = instituteDownloadRequestDto.getSize() * (instituteDownloadRequestDto.getPage() - 1);
+            }
+            searchSourceBuilder.from(fromRange);
+        } else {
+            int count = Long.valueOf(countResponse.getCount()).intValue();
+            searchSourceBuilder.size(count);
+        }
+    }
+
+    public String createCSVFile(List<Map<String, Object>> instituteData) {
+        File csvFile = null;
+        // create FileWriter object with file as parameter
+        FileWriter outputfile = null;
+        // create CSVWriter object filewriter object as parameter
+        CSVWriter writer = null;
+        try {
+            Path csvFilePath = Files.createTempFile("institute_data", ".csv");
+            csvFile = csvFilePath.toFile();
+            List<CSVDataDto> csvDataDtos = new ArrayList<>();
+            for (Map<String, Object> data : instituteData) {
+                String status = (String) data.get("status");
+
+                if (status != null && !status.isEmpty() && "INSCOMPLETED".equalsIgnoreCase(status)) {
+                    Map<String, Object> inspectionData = (Map<String, Object>) data.get("inspectorDataObject");
+                    if (inspectionData != null) {
+                        CSVDataDto.CSVDataDtoBuilder csvDataDtoBuilder = CSVDataDto.builder();
+                        csvDataDtoBuilder.status((String) data.get("status"));
+                        Map<String, Map<String, Map<String, Object>>> dataObject = (Map<String, Map<String, Map<String, Object>>>) inspectionData.get("dataObject");
+                        for (Map.Entry<String, Map<String, Map<String, Object>>> val1 : dataObject.entrySet()) {
+                            csvDataDtoBuilder.section(val1.getKey());
+                            for (Map.Entry<String, Map<String, Object>> val2 : val1.getValue().entrySet()) {
+                                csvDataDtoBuilder.question(val2.getKey());
+                                for (Map.Entry<String, Object> val3 : val2.getValue().entrySet()) {
+                                    csvDataDtoBuilder.instituteAnswer(val2.getKey());
+                                    if (val3.getValue() instanceof Map) {
+                                        Set<Map.Entry<String, Object>> val3Map = ((Map<String, Object>) val3.getValue()).entrySet();
+                                        for (Map.Entry<String, Object> val4 : val3Map) {
+                                            Object inspectionVal = val4.getValue();
+                                            if (inspectionVal instanceof String) {
+                                                csvDataDtoBuilder.inspectionAnswer((String) inspectionVal);
+                                                //csvDataDtoBuilder.version((Integer)inspectionData.get("version"));
+                                                csvDataDtoBuilder.applicationId((String) data.get("applicationId"));
+                                                csvDataDtoBuilder.formId((Long)data.get("formId"));
+                                                csvDataDtoBuilder.title((String) data.get("title"));
+                                                csvDataDtoBuilder.updatedBy((String) data.get("updatedBy"));
+                                                csvDataDtoBuilder.createdDate((String) data.get("createdDate"));
+                                                csvDataDtoBuilder.inspectionCompletionDate((String) data.get("inspectionCompletedDate"));
+                                                csvDataDtoBuilder.updatedDate((String) data.get("updatedDate"));
+                                                csvDataDtos.add(csvDataDtoBuilder.build());
+                                            }
+                                            if (inspectionVal instanceof Map) {
+                                                Set<Map.Entry<String, String>> map = ((Map<String, String>) inspectionVal).entrySet();
+                                                for (Map.Entry<String, String> val5 : map) {
+                                                    csvDataDtoBuilder.inspectionAnswer(val5.getValue());
+                                                }
+                                            }
+
+                                        }
+                                    }
+                                    if (val3.getValue() instanceof String) {
+                                        csvDataDtoBuilder.inspectionAnswer((String) val3.getValue());
+                                    }
+                                    //csvDataDtoBuilder.version((Integer)inspectionData.get("version"));
+                                    csvDataDtoBuilder.applicationId((String) data.get("applicationId"));
+                                    csvDataDtoBuilder.formId((Long)data.get("formId"));
+                                    csvDataDtoBuilder.title((String) data.get("title"));
+                                    csvDataDtoBuilder.updatedBy((String) data.get("updatedBy"));
+                                    csvDataDtoBuilder.createdDate((String) data.get("createdDate"));
+                                    csvDataDtoBuilder.inspectionCompletionDate((String) data.get("inspectionCompletedDate"));
+                                    csvDataDtoBuilder.updatedDate((String) data.get("updatedDate"));
+                                    csvDataDtos.add(csvDataDtoBuilder.build());
+                                }
+                            }
+                        }
+
+                    }
+                } else {
+                    Map<String, Map<String, Object>> questionData = (Map<String, Map<String, Object>>) data.get("dataObject");
+                    if (questionData != null) {
+                        CSVDataDto.CSVDataDtoBuilder csvDataDtoBuilder = CSVDataDto.builder();
+                        csvDataDtoBuilder.status((String) data.get("status"));
+                        for (Map.Entry<String, Map<String, Object>> qval1 : questionData.entrySet()) {
+                            csvDataDtoBuilder.section(qval1.getKey());
+                            for (Map.Entry<String, Object> qval2 : qval1.getValue().entrySet()) {
+                                csvDataDtoBuilder.question(qval2.getKey());
+                                if (qval2.getValue() instanceof Map) {
+                                    Map<String, Object> qval3 = (Map<String, Object>) qval2.getValue();
+                                    for (Map.Entry<String, Object> qval4 : qval3.entrySet()) {
+                                        if (qval4.getValue() instanceof String) {
+                                            csvDataDtoBuilder.instituteAnswer((String) qval4.getValue());
+                                        }
+
+                                    }
+                                }
+                                if (qval2.getValue() instanceof String) {
+                                    csvDataDtoBuilder.instituteAnswer((String) qval2.getValue());
+                                }
+                                csvDataDtoBuilder.inspectionAnswer("-");
+                                //csvDataDtoBuilder.version((Integer)inspectionData.get("version"));
+                                csvDataDtoBuilder.applicationId((String) data.get("applicationId"));
+                                csvDataDtoBuilder.formId((Long)data.get("formId"));
+                                csvDataDtoBuilder.title((String) data.get("title"));
+                                csvDataDtoBuilder.updatedBy((String) data.get("updatedBy"));
+                                csvDataDtoBuilder.createdDate((String) data.get("createdDate"));
+                                csvDataDtoBuilder.inspectionCompletionDate((String) data.get("inspectionCompletedDate"));
+                                csvDataDtoBuilder.updatedDate((String) data.get("updatedDate"));
+                                csvDataDtos.add(csvDataDtoBuilder.build());
+                            }
+                        }
+
+                    }
+                }
+
+            }
+            // create FileWriter object with file as parameter
+            outputfile = new FileWriter(csvFile);
+            // create CSVWriter object filewriter object as parameter
+            writer = new CSVWriter(outputfile);
+            // adding header to csv
+            String[] header = {"Application Id", "Form Id", "status", "title", "section", "question", "Institute Input", "Inspection Input","Inspection completion date", "Updated By", "Created Date", "Updated Date"};
+            writer.writeNext(header);
+            // writing data
+            for (CSVDataDto csvDataDto : csvDataDtos) {
+                writer.writeNext(new String[]{csvDataDto.getApplicationId(), String.valueOf(csvDataDto.getFormId()), csvDataDto.getStatus(),
+                        csvDataDto.getTitle(), csvDataDto.getSection(), csvDataDto.getQuestion(), csvDataDto.getInstituteAnswer(), csvDataDto.getInspectionAnswer(),
+                        csvDataDto.getInspectionCompletionDate(), csvDataDto.getUpdatedBy(), csvDataDto.getCreatedDate(), csvDataDto.getUpdatedDate()});
+            }
+            writer.flushQuietly();
+            return encodeFileToBase64Binary(csvFile);
+        } catch (Exception e) {
+            LOGGER.error(String.format(Constants.EXCEPTION, "getInstituteData", e.getMessage()));
+        } finally {
+            if(writer != null) {
+                writer = null;
+            }
+            if(outputfile != null) {
+                outputfile = null;
+            }
+        }
+
+        return null;
+    }
+
+    private static String encodeFileToBase64Binary(File file) throws IOException {
+        byte[] encoded = Base64.getEncoder().encode(FileUtils.readFileToByteArray(file));
+        return new String(encoded, StandardCharsets.US_ASCII);
+    }
+
+    /**
+     * Add filters in search response
+     */
+    private List<Map<String, Object>> filterSearchResults(List<Map<String, Object>> response,
+                                                          List<SearchObject> filterObjects, UserInfo userInfo) throws Exception {
+        if (filterObjects != null && filterObjects.size() > 0) {
+            List<Map<String, Object>> filteredResponse = new ArrayList<>();
+            for (SearchObject searchObj : filterObjects) {
+                if (searchObj.getKey().equals(Constants.Parameters.TO_CONSENT)
+                        && searchObj.getValues().equals(Boolean.TRUE)) {
+                    for (Map<String, Object> responseObj : response) {
+                        IncomingData incomingData = objectMapper.convertValue(responseObj, IncomingData.class);
+                        if (incomingData.getInspection() != null
+                                && incomingData.getInspection().getStatus().equals(Status.LEADINSCOMPLETED.name())
+                                && incomingData.getInspection().getAssignedTo() != null) {
+                            for (Assignee assignee : incomingData.getInspection().getAssignedTo()) {
+                                if (assignee.getId().equals(userInfo.getId())
+                                        && StringUtils.isBlank(assignee.getStatus())) {
+                                    filteredResponse.add(responseObj);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            return filteredResponse;
+        }
+        return response;
+    }
+
+    private void setRoleBasedSearchObject(UserInfo userInfo, SearchRequestDto searchRequestDto) {
+        if (userInfo != null && userInfo.getRoles() != null) {
+            for (Role role : userInfo.getRoles()) {
+                SearchObject roleBasedSearch = new SearchObject();
+                if (role.getName().equalsIgnoreCase(Roles.INSTITUTION.name())) {
+                    roleBasedSearch.setKey(Constants.CREATED_BY);
+                    roleBasedSearch.setValues(userInfo.getEmailId());
+                } else if (role.getName().equalsIgnoreCase(Roles.INSPECTOR.name())) {
+                    roleBasedSearch.setKey(Constants.ASSIGNED_TO);
+                    roleBasedSearch.setValues(userInfo.getId());
+                }
+                if (searchRequestDto.getSearchObjects() != null && StringUtils.isNotBlank(roleBasedSearch.getKey())) {
+                    searchRequestDto.getSearchObjects().add(roleBasedSearch);
+                } else if (StringUtils.isNotBlank(roleBasedSearch.getKey())) {
+                    List<SearchObject> searchObjectList = new ArrayList<>();
+                    searchObjectList.add(roleBasedSearch);
+                    searchRequestDto.setSearchObjects(searchObjectList);
+                }
+            }
+        }
+    }
+
+    private void setRoleBasedExcludeSearchObject(UserInfo userInfo, SearchRequestDto searchRequestDto) {
+        if (userInfo != null && userInfo.getRoles() != null) {
+            for (Role role : userInfo.getRoles()) {
+                if (role.getName().equalsIgnoreCase(Roles.REGULATOR.name())
+                        || role.getName().equalsIgnoreCase(Roles.INSPECTOR.name())) {
+                    SearchObject roleBasedSearch = new SearchObject();
+                    roleBasedSearch.setKey(Constants.STATUS);
+                    roleBasedSearch.setValues(Status.DRAFT.name());
+                    if (searchRequestDto.getExcludeObject() != null) {
+                        searchRequestDto.getExcludeObject().add(roleBasedSearch);
+                    } else if (StringUtils.isNotBlank(roleBasedSearch.getKey())) {
+                        List<SearchObject> searchObjectList = new ArrayList<>();
+                        searchObjectList.add(roleBasedSearch);
+                        searchRequestDto.setExcludeObject(searchObjectList);
+                    }
+                }
+
+            }
+        }
+    }
+
+    @Override
+    public KeyValueList getApplicationsStatusCount(UserInfo userInfo) {
+        try {
+            // query builder
+            if (userInfo != null && userInfo.getRoles() != null) {
+                for (Role role : userInfo.getRoles()) {
+                    if (role.getName().equalsIgnoreCase(Roles.REGULATOR.name())) {
+                        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(0);
+                        searchSourceBuilder.aggregation(AggregationBuilders.terms("Total Pending")
+                                .field(Constants.ElasticSearchFields.MAPPING.get(Constants.STATUS)));
+                        SearchRequest searchRequest = new SearchRequest(appConfig.getFormDataIndex())
+                                .source(searchSourceBuilder);
+                        LOGGER.info("Search Request : " + searchRequest);
+                        List<Map<String, Object>> responseNode = formsDao.searchAggregationResponse(searchRequest,
+                                "Total Pending");
+                        return translateResponse(responseNode);
+                    } else {
+                        // Setting all prerequisites
+                        List<Long> userIdList = new ArrayList<Long>();
+                        userIdList.add(userInfo.getId());
+                        Calendar cal = Calendar.getInstance();
+                        cal.setTime(new Date());
+                        KeyValueList finalList = new KeyValueList();
+                        List<KeyValue> keyValueList = new ArrayList<>();
+                        finalList.setKeyValues(keyValueList);
+                        Calendar startOfTodayCal = Calendar.getInstance();
+                        startOfTodayCal.setTime(new Date());
+                        startOfTodayCal.add(Calendar.DAY_OF_YEAR, -1);
+                        startOfTodayCal.set(Calendar.HOUR, 11);
+                        startOfTodayCal.set(Calendar.AM_PM, Calendar.PM);
+                        startOfTodayCal.set(Calendar.MINUTE, 59);
+
+                        Calendar endOfTodayCal = Calendar.getInstance();
+                        endOfTodayCal.setTime(new Date());
+                        endOfTodayCal.set(Calendar.HOUR, 11);
+                        endOfTodayCal.set(Calendar.AM_PM, Calendar.PM);
+                        endOfTodayCal.set(Calendar.MINUTE, 59);
+
+                        // Creating Search Request for Total Pending
+                        TermsQueryBuilder userIdFilter = QueryBuilders.termsQuery(
+                                Constants.ElasticSearchFields.MAPPING.get("inspectionLeadInspector"), userIdList);
+                        TermQueryBuilder inspectionStatusFilter = QueryBuilders.termQuery(
+                                Constants.ElasticSearchFields.MAPPING.get("inspectionStatus"),
+                                Status.SENTFORINS.name());
+                        TermQueryBuilder statusFilter = QueryBuilders.termQuery(
+                                Constants.ElasticSearchFields.MAPPING.get("status"), Status.SENTFORINS.name());
+                        BoolQueryBuilder filters = QueryBuilders.boolQuery().filter(userIdFilter)
+                                .filter(inspectionStatusFilter).filter(statusFilter);
+                        FilterAggregationBuilder totalPendingAggregationFilter = AggregationBuilders
+                                .filter("Inspector Total Pending", filters)
+                                .subAggregation(AggregationBuilders.cardinality("Count")
+                                        .field(Constants.ElasticSearchFields.MAPPING.get("inspectionApplicationId")));
+                        SearchSourceBuilder totalPendingAggrSourceBuilder = new SearchSourceBuilder().size(0);
+                        totalPendingAggrSourceBuilder.aggregation(totalPendingAggregationFilter);
+                        SearchRequest totalPendingSearchRequest = new SearchRequest(appConfig.getFormDataIndex())
+                                .source(totalPendingAggrSourceBuilder);
+                        LOGGER.info("Search Request : " + totalPendingSearchRequest);
+                        List<Map<String, Object>> totalPendingResponse = formsDao
+                                .searchAggregationResponse(totalPendingSearchRequest, "Inspector Total Pending");
+                        KeyValueList list = translateResponse(totalPendingResponse);
+                        finalList.getKeyValues().addAll(list.getKeyValues());
+
+                        // Creating Search Request for Received Today
+                        RangeQueryBuilder assignedDateFilter = QueryBuilders
+                                .rangeQuery(Constants.ElasticSearchFields.MAPPING.get("inspectionAssignedDate"))
+                                .from(startOfTodayCal.getTime().getTime()).to(endOfTodayCal.getTime().getTime());
+                        BoolQueryBuilder filters2 = QueryBuilders.boolQuery().filter(userIdFilter)
+                                .filter(assignedDateFilter);
+                        FilterAggregationBuilder receivedTodayAggregationFilter = AggregationBuilders
+                                .filter("Received Today", filters2)
+                                .subAggregation(AggregationBuilders.cardinality("Count")
+                                        .field(Constants.ElasticSearchFields.MAPPING.get("inspectionApplicationId")));
+                        SearchSourceBuilder receivedTodayAggrSourceBuilder = new SearchSourceBuilder().size(0);
+                        receivedTodayAggrSourceBuilder.aggregation(receivedTodayAggregationFilter);
+                        SearchRequest receivedTodaySearchRequest = new SearchRequest(appConfig.getFormDataIndex())
+                                .source(receivedTodayAggrSourceBuilder);
+                        LOGGER.info("Search Request : " + receivedTodaySearchRequest);
+                        List<Map<String, Object>> receivedTodayResponse = formsDao
+                                .searchAggregationResponse(receivedTodaySearchRequest, "Received Today");
+                        list = translateResponse(receivedTodayResponse);
+                        finalList.getKeyValues().addAll(list.getKeyValues());
+
+                        // Creating Search Request for Reviewed Today
+                        RangeQueryBuilder updatedDateFilter = QueryBuilders.rangeQuery("inspectionDate")
+                                .from(startOfTodayCal.getTime().getTime()).to(endOfTodayCal.getTime().getTime());
+                        BoolQueryBuilder filters3 = QueryBuilders.boolQuery().filter(userIdFilter)
+                                .filter(updatedDateFilter);
+                        FilterAggregationBuilder reviewedTodayAggregationFilter = AggregationBuilders
+                                .filter("Reviewed Today", filters3)
+                                .subAggregation(AggregationBuilders.cardinality("Count")
+                                        .field(Constants.ElasticSearchFields.MAPPING.get("inspectionApplicationId")));
+                        SearchSourceBuilder reviewedTodayAggrSourceBuilder = new SearchSourceBuilder().size(0);
+                        reviewedTodayAggrSourceBuilder.aggregation(reviewedTodayAggregationFilter);
+                        SearchRequest reviewedTodaySearchRequest = new SearchRequest(appConfig.getFormDataIndex())
+                                .source(reviewedTodayAggrSourceBuilder);
+                        LOGGER.info("Search Request : " + reviewedTodaySearchRequest);
+                        List<Map<String, Object>> reviewedTodayResponse = formsDao
+                                .searchAggregationResponse(reviewedTodaySearchRequest, "Reviewed Today");
+                        list = translateResponse(reviewedTodayResponse);
+                        finalList.getKeyValues().addAll(list.getKeyValues());
+
+                        return finalList;
+
+                    }
+                }
+            }
+
+        } catch (Exception ex) {
+            LOGGER.error(String.format(Constants.EXCEPTION, "getApplicationsStatusCount", ex.getMessage()));
+        }
+        return null;
+
+    }
+
+    KeyValueList translateResponse(List<Map<String, Object>> responseNode) {
+        KeyValueList list = new KeyValueList();
+        List<KeyValue> listOfKeyValuePairs = new ArrayList<KeyValue>();
+        for (Map<String, Object> eachMap : responseNode) {
+            List<KeyValue> keyValueList = eachMap.entrySet().stream().filter(entry -> !"DRAFT".equals(entry.getKey()))
+                    .map(entry -> new KeyValue(entry.getKey().equals("NEW") ? "Total Pending" : entry.getKey(),
+                            entry.getValue()))
+                    .collect(Collectors.toList());
+            listOfKeyValuePairs.addAll(keyValueList);
+        }
+        list.setKeyValues(listOfKeyValuePairs);
+        return list;
+    }
+
+    KeyValueList translateInspectorResponse(List<Map<String, Object>> responseNode) {
+        KeyValueList list = new KeyValueList();
+        List<KeyValue> listOfKeyValuePairs = new ArrayList<KeyValue>();
+        for (Map<String, Object> eachMap : responseNode) {
+            List<KeyValue> keyValueList = eachMap.entrySet().stream()
+                    .map(entry -> new KeyValue(entry.getKey(), entry.getValue())).collect(Collectors.toList());
+            listOfKeyValuePairs.addAll(keyValueList);
+        }
+        list.setKeyValues(listOfKeyValuePairs);
+        return list;
+    }
+
+    @Override
+    public Boolean saveFormSubmitv1(IncomingData incomingData, UserInfo userInfo, String action) {
+        Boolean indexed = Boolean.FALSE;
+        try {
+            if (StringUtils.isBlank(incomingData.getApplicationId())) {
+                incomingData.setTimestamp(DateUtils.getCurrentTimestamp());
+                incomingData.setCreatedDate(DateUtils.getYyyyMmDdInUTC());
+                indexed = formsDao.addFormData(incomingData);
+                appStatusTrack(indexed, objectMapper.convertValue(incomingData, Map.class), action, userInfo);
+            } else {
+                Map<String, Object> applicationObject = getApplicationById(incomingData.getApplicationId(), userInfo);
+                incomingData.setUpdatedDate(DateUtils.getYyyyMmDdInUTC());
+                indexed = formsDao.updateFormData(incomingData, incomingData.getApplicationId());
+                appStatusTrack(indexed, applicationObject, action, userInfo);
+            }
+        } catch (Exception e) {
+            LOGGER.error(String.format(Constants.EXCEPTION, "saveFormSubmitv1", e.getMessage()));
+        }
+        return indexed;
+    }
+
+    @Override
+    public Boolean savePlainForm(IncomingData incomingData) {
+        Boolean indexed = null;
+        try {
+            indexed = formsDao.addPlainFormData(incomingData);
+        } catch (Exception e) {
+            LOGGER.error(String.format(Constants.EXCEPTION, "savePlainForm", e.getMessage()));
+        }
+        return indexed;
+    }
+
+    @Override
+    public Map<String, Object> getApplicationById(String applicationId, UserInfo userInfo) {
+        SearchRequestDto searchRequestDto = new SearchRequestDto();
+        SearchObject sObject = new SearchObject();
+        sObject.setKey(Constants.APPLICATION_ID);
+        sObject.setValues(applicationId);
+        List<SearchObject> searchObjectList = new ArrayList<SearchObject>();
+        searchObjectList.add(sObject);
+        searchRequestDto.setSearchObjects(searchObjectList);
+        List<Map<String, Object>> responseData = getApplications(userInfo, searchRequestDto);
+        if (responseData != null) {
+            return (responseData.isEmpty()) ? new HashMap<>() : responseData.get(0);
+        }
+        return null;
+    }
+
+    @Override
+    public String fileUpload(MultipartFile multipartFile, String folderName) {
+        try {
+            String folderPath = Constants.UP_SMF;
+            if (StringUtils.isNotBlank(folderName)) {
+                folderPath = folderPath + "/" + folderName;
+            }
+            File file = new File(multipartFile.getOriginalFilename());
+            file.createNewFile();
+            FileOutputStream fos = new FileOutputStream(file);
+            fos.write(multipartFile.getBytes());
+            fos.close();
+            Map<String, String> uploadedFile = CloudStorage.uploadFile(folderPath, file);
+            file.delete();
+            return uploadedFile.get(Constants.URL);
+        } catch (Exception e) {
+            LOGGER.error(String.format(Constants.EXCEPTION, "fileUpload", e.getMessage()));
+            return null;
+        }
+    }
+
+    @Override
+    public Boolean deleteCloudFile(List<String> files) {
+        try {
+            for (String file : files) {
+                String fileName = file;
+                String[] nameList = file.split("/" + appConfig.getContainerName() + "/");
+                if (nameList.length > 1) {
+                    fileName = nameList[1];
+                }
+                CloudStorage.deleteFile(fileName);
+            }
+            return Boolean.TRUE;
+        } catch (Exception e) {
+            LOGGER.error(String.format(Constants.EXCEPTION, "deleteCloudFile", e.getMessage()));
+        }
+        return Boolean.FALSE;
+    }
+
+    @Override
+    public Boolean reviewApplication(IncomingData incomingData, UserInfo userInfo) {
+        try {
+            SearchRequestDto srd = createSearchRequestObject(incomingData.getApplicationId());
+            List<Map<String, Object>> applicationMap = getApplications(userInfo, srd);
+            for (Map<String, Object> innerMap : applicationMap) {
+                if (innerMap.containsKey(Constants.STATUS)) {
+                    incomingData.setStatus(innerMap.get(Constants.STATUS).toString());
+                }
+            }
+            incomingData.setReviewedDate(DateUtils.getYyyyMmDdInUTC());
+            WorkflowDto workflowDto = new WorkflowDto(incomingData, userInfo,
+                    Constants.WorkflowActions.SAVE_FORM_NOTES);
+            WorkflowUtil.getNextStateForMyRequest(workflowDto);
+            incomingData.setStatus(workflowDto.getNextState());
+            return formsDao.updateFormData(incomingData, incomingData.getApplicationId());
+        } catch (Exception e) {
+            LOGGER.error(String.format(Constants.EXCEPTION, "reviewApplication", e.getMessage()));
+            return Boolean.FALSE;
+        }
+
+    }
+
+    public SearchRequestDto createSearchRequestObject(String applicationId) {
+        SearchRequestDto searchRequestDto = new SearchRequestDto();
+        SearchObject sObject = new SearchObject();
+        sObject.setKey(Constants.APPLICATION_ID);
+        sObject.setValues(applicationId);
+        List<SearchObject> searchObjectList = new ArrayList<SearchObject>();
+        searchObjectList.add(sObject);
+        searchRequestDto.setSearchObjects(searchObjectList);
+        return searchRequestDto;
+    }
+
+    @Override
+    public Boolean assignApplication(UserInfo userInfo, AssignApplication assign) {
+        try {
+            SearchRequestDto srd = createSearchRequestObject(assign.getApplicationId());
+            List<Map<String, Object>> applicationMap = getApplications(userInfo, srd);
+            for (Map<String, Object> innerMap : applicationMap) {
+                if (innerMap.containsKey(Constants.STATUS)) {
+                    assign.setStatus(innerMap.get(Constants.STATUS).toString());
+                }
+                if (innerMap.containsKey(Constants.FORM_ID)) {
+                    assign.setFormId(Long.parseLong(innerMap.get(Constants.FORM_ID).toString()));
+                }
+            }
+            WorkflowDto workflowDto = new WorkflowDto(assign, userInfo, Constants.WorkflowActions.ASSIGN_INSPECTOR);
+            WorkflowUtil.getNextStateForMyRequest(workflowDto);
+            assign.setStatus(workflowDto.getNextState());
+            if (assign.getLeadInspector() == null) {
+                assign.setLeadInspector(new ArrayList<>());
+            }
+            if (assign.getAssistingInspector() == null) {
+                assign.setAssistingInspector(new ArrayList<>());
+            }
+            if (assign.getAssistingInspector().size() > 0 || assign.getLeadInspector().size() > 0) {
+                List<Long> inspectorsId = new ArrayList<>();
+                inspectorsId.addAll(assign.getAssistingInspector());
+                inspectorsId.addAll(assign.getLeadInspector());
+                Map<String, Map<String, Object>> userMap = getUserDetails(inspectorsId, userInfo.getOrgId(),
+                        userInfo.getAuthToken());
+                // set assigned user meta data
+                assign.setAssignedTo(new ArrayList<>());
+                for (Long userId : inspectorsId) {
+                    Assignee assignee = new Assignee();
+                    assignee.setId(userId);
+                    String key = String.valueOf(userId);
+                    if (userMap.containsKey(key)) {
+                        assignee.setEmailId((String) userMap.get(key).get(Constants.Parameters.EMAIL_ID));
+                        assignee.setFirstName((String) userMap.get(key).get(Constants.Parameters.FIRST_NAME));
+                        assignee.setLastName((String) userMap.get(key).get(Constants.Parameters.LAST_NAME));
+                        if (assign.getLeadInspector().contains(userId)) {
+                            assignee.setLeadInspector(Boolean.TRUE);
+                        }
+                    }
+                    assign.getAssignedTo().add(assignee);
+                }
+
+                IncomingData requestData = new IncomingData();
+                assign.setAssignedDate(DateUtils.getYyyyMmDdInUTC());
+                requestData.setInspection(assign);
+                requestData.setStatus(assign.getStatus());
+
+
+                LOGGER.info(objectMapper.writeValueAsString(requestData));
+                LOGGER.info(objectMapper.writeValueAsString(assign));
+                Boolean response = formsDao.updateFormData(requestData, assign.getApplicationId());
+                appStatusTrack(response,
+                        (applicationMap != null && applicationMap.size() > 0 ? applicationMap.get(0) : null),
+                        Constants.WorkflowActions.ASSIGN_INSPECTOR, userInfo);
+                return response;
+            }
+            return Boolean.TRUE;
+        } catch (Exception e) {
+            LOGGER.error(String.format(Constants.EXCEPTION, "assignApplication", e.getMessage()));
+            return Boolean.FALSE;
+        }
+    }
+
+    /**
+     * Makes rest call with user service to fetch the user details
+     *
+     * @param userId    Object
+     * @param authToken String
+     * @return
+     */
+    private Map<String, Map<String, Object>> getUserDetails(Object userId, Object orgId, String authToken)
+            throws Exception {
+        Map<String, Object> requestBody = new HashMap<>();
+        requestBody.put(Constants.Parameters.ORG_ID, orgId);
+        requestBody.put(Constants.Parameters.SEARCH, new HashMap<String, Object>() {
+            {
+                put(Constants.Parameters.USER_ID, userId);
+            }
+        });
+        if (!authToken.toUpperCase().contains((Constants.Parameters.BEARER).toUpperCase())) {
+            authToken = Constants.Parameters.BEARER + authToken;
+        }
+        HttpHeaders headers = new HttpHeaders();
+        headers.add(Constants.Parameters.AUTHORIZATION, authToken);
+        Object response = RestService.postRequest(headers,
+                appConfig.getUserServiceHost() + appConfig.getGetAllUserApiPath(), requestBody);
+        if (response != null) {
+            List<Map<String, Object>> userList = objectMapper.convertValue(response,
+                    new TypeReference<List<Map<String, Object>>>() {
+                    });
+            return userList.stream()
+                    .collect(Collectors.toMap(obj -> String.valueOf(obj.get(Constants.Parameters.ID)), obj -> obj));
+        }
+        return null;
+    }
+    
+
+    public ConcurrentMap<Long, State> fetchAllStates() {
+        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(1000);
+        // es call
+        SearchRequest searchRequest = new SearchRequest(appConfig.getFormStateIndex()).source(searchSourceBuilder);
+        LOGGER.info("Search Request : " + searchRequest);
+        return formsDao.fetchAllStates(searchRequest);
+    }
+
+    @Override
+    public ConcurrentMap<String, List<StateMatrix>> fetchAllStateMatrix() {
+        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(1000);
+        // es call
+        SearchRequest searchRequest = new SearchRequest(appConfig.getFormStateMatrixIndex())
+                .source(searchSourceBuilder);
+        LOGGER.info("Search Request : " + searchRequest);
+        return formsDao.fetchAllStateMatrix(searchRequest);
+    }
+    
+    @Override
+    public Boolean updateApplicationStatus(IncomingData incomingData, UserInfo userInfo, String status) {
+        try {
+            SearchRequestDto srd = createSearchRequestObject(incomingData.getApplicationId());
+            List<Map<String, Object>> applicationMap = getApplications(userInfo, srd);
+            for (Map<String, Object> innerMap : applicationMap) {
+                if (innerMap.containsKey(Constants.STATUS)) {
+                    incomingData.setStatus(innerMap.get(Constants.STATUS).toString());
+                    incomingData.setComments(
+                            innerMap.containsKey(Constants.Parameters.COMMENTS) ? objectMapper.convertValue(
+                                    innerMap.get(Constants.Parameters.COMMENTS), new TypeReference<List<Object>>() {
+                                    }) : null);
+                }
+            }
+            incomingData.setReviewedDate(DateUtils.getYyyyMmDdInUTC());
+            WorkflowDto workflowDto = new WorkflowDto(incomingData, userInfo, status);
+            WorkflowUtil.getNextStateForMyRequest(workflowDto);
+            incomingData.setStatus(workflowDto.getNextState());
+            if (StringUtils.isNotBlank(incomingData.getNotes())) {
+                List<Object> commentsList = new ArrayList<>();
+                Map<String, Object> commentsMap = new HashMap<>();
+                commentsMap.put(Constants.TYPE, incomingData.getStatus().toLowerCase()
+                        + Constants.convertToTitleCase(Constants.Parameters.COMMENTS));
+                commentsMap.put(Constants.VALUE, incomingData.getNotes());
+                commentsMap.put(Constants.BY, userInfo.getId());
+                commentsMap.put(Constants.TIMESTAMP, DateUtils.getCurrentTimestamp());
+                if (incomingData.getComments() != null) {
+                    commentsList = incomingData.getComments();
+                }
+                commentsList.add(commentsMap);
+                incomingData.setComments(commentsList);
+            }
+            Boolean response = formsDao.updateFormData(incomingData, incomingData.getApplicationId());
+            appStatusTrack(response,
+                    (applicationMap != null && applicationMap.size() > 0 ? applicationMap.get(0) : null), status,
+                    userInfo);
+            return response;
+        } catch (Exception e) {
+            LOGGER.error(String.format(Constants.EXCEPTION, "updateApplicationStatus", e.getMessage()));
+            return Boolean.FALSE;
+        }
+
+    }
+
+
+   
+    @Override
 	public Boolean submitInspection(IncomingData incomingData, UserInfo userInfo) {
 		try {
 			Boolean inspectionCompleted = incomingData.getInspectionCompleted();
@@ -954,185 +1158,195 @@ public class FormsServiceImpl implements FormsService {
 		return Boolean.FALSE;
 	}
 
-	/**
-	 * Creates an async operation to send notification & update activity logs on
-	 * application status changes
-	 */
-	private void appStatusTrack(Boolean response, Map<String, Object> applicationMap, String action,
-			UserInfo userInfo) {
-		new Thread(() -> {
-			try {
-				Thread.sleep(1000);
-				if (response != null && response) {
-					if (applicationMap != null && applicationMap.size() > 0) {
-						IncomingData applicationData = objectMapper.convertValue(applicationMap, IncomingData.class);
-						Map<String, Object> updatedAppMap = getApplicationById(applicationData.getApplicationId(),
-								userInfo);
-						IncomingData updatedAppData = objectMapper.convertValue(updatedAppMap, IncomingData.class);
-
-						// update activity logs
-						if (action.equalsIgnoreCase(Status.NEW.name())) {
-							activityService.applicationActivity(null, updatedAppData, userInfo);
-						} else {
-							activityService.applicationActivity(applicationData, updatedAppData, userInfo);
-						}
+    /**
+     * Creates an async operation to send notification & update activity logs on
+     * application status changes
+     */
+    private void appStatusTrack(Boolean response, Map<String, Object> applicationMap, String action,
+                                UserInfo userInfo) {
+        new Thread(() -> {
+            try {
+                Thread.sleep(1000);
+                if (response != null && response) {
+                    if (applicationMap != null && applicationMap.size() > 0) {
+                        IncomingData applicationData = objectMapper.convertValue(applicationMap, IncomingData.class);
+                        Map<String, Object> updatedAppMap = getApplicationById(applicationData.getApplicationId(),
+                                userInfo);
+                        IncomingData updatedAppData = objectMapper.convertValue(updatedAppMap, IncomingData.class);
+
+                        // update activity logs
+                        if (action.equalsIgnoreCase(Status.NEW.name())) {
+                            activityService.applicationActivity(null, updatedAppData, userInfo);
+                        } else {
+                            activityService.applicationActivity(applicationData, updatedAppData, userInfo);
+                        }
+
+                        // send notification
+                        if (action.equals(Constants.WorkflowActions.ASSIGN_INSPECTOR)) {
+                            NotificationUtil.SendNotification(updatedAppData, action, userInfo);
+                        } else {
+                            NotificationUtil.SendNotification(applicationData, action, userInfo);
+                        }
+                    }
+                }
+            } catch (Exception e) {
+                LOGGER.error(String.format(Constants.EXCEPTION, "appStatusTrack", e.getMessage()));
+            }
+        }).start();
+    }
+
+    @Override
+    public List<Map<String, Object>> getActivityLogs(String applicationId) {
+        try {
+            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(1000);
+            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
+            boolBuilder.must().add(QueryBuilders.matchQuery(Constants.Parameters.ID, applicationId));
+            boolBuilder.must().add(QueryBuilders.existsQuery("changes.status"));
+            searchSourceBuilder.query(boolBuilder).fetchSource(
+                    new String[]{Constants.Parameters.ID, Constants.Parameters.UPDATED_BY,
+                            Constants.Parameters.UPDATED_DATE, Constants.Parameters.UPDATED_BY_EMAIL,
+                            Constants.TIMESTAMP, "changes.status.ChangedTo", "changes.status.action"},
+                    new String[]{});
+            searchSourceBuilder.sort(SortBuilders.fieldSort(Constants.TIMESTAMP).order(SortOrder.DESC));
+            SearchRequest searchRequest = new SearchRequest(appConfig.getActivityLogIndex())
+                    .source(searchSourceBuilder);
+            return formsDao.searchResponse(searchRequest);
+        } catch (Exception e) {
+            LOGGER.error(String.format(Constants.EXCEPTION, "getActivityLogs", e.getMessage()));
+            return null;
+        }
+    }
+    
+
+    @Override
+    public Boolean consentApplication(Consent consent, UserInfo userInfo) {
+        try {
+            Map<String, Object> applicationMap = getApplicationById(consent.getApplicationId(), userInfo);
+            if (applicationMap != null) {
+                IncomingData applicationData = objectMapper.convertValue(applicationMap, IncomingData.class);
+                Boolean inspectionCompleted = Boolean.TRUE;
+                if (applicationData != null && applicationData.getInspection() != null
+                        && applicationData.getInspection().getAssignedTo() != null) {
+                    // get workflow next status
+                    WorkflowDto workflowDto = new WorkflowDto(applicationData, userInfo,
+                            Constants.WorkflowActions.COMPLETED_INSPECTION);
+                    WorkflowUtil.getNextStateForMyRequest(workflowDto);
+
+                    for (Assignee assignee : applicationData.getInspection().getAssignedTo()) {
+                        if (assignee.getId().equals(userInfo.getId())) {
+                            assignee.setConsentApplication(consent.getAgree());
+                            assignee.setComments(consent.getComments());
+                            assignee.setStatus(workflowDto.getNextState());
+                            assignee.setConsentDate(DateUtils.getYyyyMmDdInUTC());
+                        } else if (StringUtils.isBlank(assignee.getStatus())) {
+                            inspectionCompleted = Boolean.FALSE;
+                        }
+                    }
+
+                    // if all assisting inspector had given their consent, move the application to
+                    // next status
+                    if (inspectionCompleted) {
+                        applicationData.setStatus(workflowDto.getNextState());
+                        applicationData.getInspection().setStatus(workflowDto.getNextState());
+                        applicationData.setInspectionCompletedDate(DateUtils.getYyyyMmDdInUTC());
+                        applicationData.getInspection().setInspectionCompletedDate(DateUtils.getYyyyMmDdInUTC());
+                    }
+                    Boolean indexed = formsDao.updateFormData(applicationData, consent.getApplicationId());
+                    appStatusTrack(indexed, objectMapper.convertValue(applicationData, Map.class),
+                            inspectionCompleted ? Constants.WorkflowActions.COMPLETED_INSPECTION
+                                    : Constants.WorkflowActions.LEAD_INSPECTION_COMPLETED,
+                            userInfo);
+                    return indexed;
+                }
+            }
+        } catch (Exception e) {
+            LOGGER.error(String.format(Constants.EXCEPTION, "consentApplication", e.getMessage()));
+        }
+        return Boolean.FALSE;
+    }
+    
+    @Override
+    public void submitBulkInspection(List<IncomingData> inspectionDataList, UserInfo userInfo) {
+        new Thread(() -> {
+            try {
+                for (IncomingData incomingData : inspectionDataList) {
+                    submitInspection(incomingData, userInfo);
+                }
+            } catch (Exception e) {
+                LOGGER.error(String.format(Constants.EXCEPTION, "submitBulkInspection", e.getMessage()));
+            }
+        }).start();
+    }
+
+    @Override
+    public void consentBulkApplication(List<Consent> consentList, UserInfo userInfo) {
+        new Thread(() -> {
+            try {
+                for (Consent consent : consentList) {
+                    consentApplication(consent, userInfo);
+                }
+            } catch (Exception e) {
+                LOGGER.error(String.format(Constants.EXCEPTION, "consentBulkApplication", e.getMessage()));
+            }
+        }).start();
+    }
+    
+
+    @Override
+    public List<Map<String, Object>> getAllPlainForms() {
+        try {
+            // query builder
+            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(1000);
+            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
+            searchSourceBuilder.query(boolBuilder);
+            System.out.println(searchSourceBuilder);
+            // es call
+            SearchRequest searchRequest = new SearchRequest("fs-plain-form").source(searchSourceBuilder);
+            LOGGER.info("Search Request : " + searchRequest);
+            List<Map<String, Object>> response = formsDao.searchPlainFormResponse(searchRequest);
+            return response;
+
+        } catch (Exception e) {
+            LOGGER.error(String.format(Constants.EXCEPTION, "getApplications", e.getMessage()));
+        }
+        return null;
+    }
+    
+
+
+    @Override
+    public List<Map<String, Object>> getPlainFormsById(String id) {
+        try {
+            // query builder
+            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(1000);
+            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
+            boolBuilder.must().add(QueryBuilders.termsQuery("_id", id));
+            searchSourceBuilder.query(boolBuilder);
+            System.out.println(searchSourceBuilder);
+            // es call
+            SearchRequest searchRequest = new SearchRequest("fs-plain-form").source(searchSourceBuilder);
+            LOGGER.info("Search Request : " + searchRequest);
+            List<Map<String, Object>> response = formsDao.searchPlainFormResponse(searchRequest);
+            return response;
+
+        } catch (Exception e) {
+            LOGGER.error(String.format(Constants.EXCEPTION, "getApplications", e.getMessage()));
+        }
+        return null;
+    }
 
-						// send notification
-						if (action.equals(Constants.WorkflowActions.ASSIGN_INSPECTOR)) {
-							NotificationUtil.SendNotification(updatedAppData, action, userInfo);
-						} else {
-							NotificationUtil.SendNotification(applicationData, action, userInfo);
-						}
-					}
-				}
-			} catch (Exception e) {
-				LOGGER.error(String.format(Constants.EXCEPTION, "appStatusTrack", e.getMessage()));
-			}
-		}).start();
-	}
 
-	@Override
-	public List<Map<String, Object>> getActivityLogs(String applicationId) {
-		try {
-			SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(1000);
-			BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
-			boolBuilder.must().add(QueryBuilders.matchQuery(Constants.Parameters.ID, applicationId));
-			boolBuilder.must().add(QueryBuilders.existsQuery("changes.status"));
-			searchSourceBuilder.query(boolBuilder).fetchSource(
-					new String[] { Constants.Parameters.ID, Constants.Parameters.UPDATED_BY,
-							Constants.Parameters.UPDATED_DATE, Constants.Parameters.UPDATED_BY_EMAIL,
-							Constants.TIMESTAMP, "changes.status.ChangedTo", "changes.status.action" },
-					new String[] {});
-			searchSourceBuilder.sort(SortBuilders.fieldSort(Constants.TIMESTAMP).order(SortOrder.DESC));
-			SearchRequest searchRequest = new SearchRequest(appConfig.getActivityLogIndex())
-					.source(searchSourceBuilder);
-			return formsDao.searchResponse(searchRequest);
-		} catch (Exception e) {
-			LOGGER.error(String.format(Constants.EXCEPTION, "getActivityLogs", e.getMessage()));
-			return null;
-		}
-	}
-
-	@Override
-	public Boolean consentApplication(Consent consent, UserInfo userInfo) {
-		try {
-			Map<String, Object> applicationMap = getApplicationById(consent.getApplicationId(), userInfo);
-			if (applicationMap != null) {
-				IncomingData applicationData = objectMapper.convertValue(applicationMap, IncomingData.class);
-				Boolean inspectionCompleted = Boolean.TRUE;
-				if (applicationData != null && applicationData.getInspection() != null
-						&& applicationData.getInspection().getAssignedTo() != null) {
-					// get workflow next status
-					WorkflowDto workflowDto = new WorkflowDto(applicationData, userInfo,
-							Constants.WorkflowActions.COMPLETED_INSPECTION);
-					WorkflowUtil.getNextStateForMyRequest(workflowDto);
-
-					for (Assignee assignee : applicationData.getInspection().getAssignedTo()) {
-						if (assignee.getId().equals(userInfo.getId())) {
-							assignee.setConsentApplication(consent.getAgree());
-							assignee.setComments(consent.getComments());
-							assignee.setStatus(workflowDto.getNextState());
-							assignee.setConsentDate(DateUtils.getYyyyMmDdInUTC());
-						} else if (StringUtils.isBlank(assignee.getStatus())) {
-							inspectionCompleted = Boolean.FALSE;
-						}
-					}
-
-					// if all assisting inspector had given their consent, move the application to
-					// next status
-					if (inspectionCompleted) {
-						applicationData.setStatus(workflowDto.getNextState());
-						applicationData.getInspection().setStatus(workflowDto.getNextState());
-						applicationData.setInspectionCompletedDate(DateUtils.getYyyyMmDdInUTC());
-						applicationData.getInspection().setInspectionCompletedDate(DateUtils.getYyyyMmDdInUTC());
-					}
-					Boolean indexed = formsDao.updateFormData(applicationData, consent.getApplicationId());
-					appStatusTrack(indexed, objectMapper.convertValue(applicationData, Map.class),
-							inspectionCompleted ? Constants.WorkflowActions.COMPLETED_INSPECTION
-									: Constants.WorkflowActions.LEAD_INSPECTION_COMPLETED,
-							userInfo);
-					return indexed;
-				}
-			}
-		} catch (Exception e) {
-			LOGGER.error(String.format(Constants.EXCEPTION, "consentApplication", e.getMessage()));
-		}
-		return Boolean.FALSE;
-	}
-
-	@Override
-	public void submitBulkInspection(List<IncomingData> inspectionDataList, UserInfo userInfo) {
-		new Thread(() -> {
-			try {
-				for (IncomingData incomingData : inspectionDataList) {
-					submitInspection(incomingData, userInfo);
-				}
-			} catch (Exception e) {
-				LOGGER.error(String.format(Constants.EXCEPTION, "submitBulkInspection", e.getMessage()));
-			}
-		}).start();
-	}
-
-	@Override
-	public void consentBulkApplication(List<Consent> consentList, UserInfo userInfo) {
-		new Thread(() -> {
-			try {
-				for (Consent consent : consentList) {
-					consentApplication(consent, userInfo);
-				}
-			} catch (Exception e) {
-				LOGGER.error(String.format(Constants.EXCEPTION, "consentBulkApplication", e.getMessage()));
-			}
-		}).start();
-	}
-
-	@Override
-	public List<Map<String, Object>> getAllPlainForms() {
-		try {
-			// query builder
-			SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(1000);
-			BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
-			searchSourceBuilder.query(boolBuilder);
-			System.out.println(searchSourceBuilder);
-			// es call
-			SearchRequest searchRequest = new SearchRequest("fs-plain-form").source(searchSourceBuilder);
-			LOGGER.info("Search Request : " + searchRequest);
-			List<Map<String, Object>> response = formsDao.searchPlainFormResponse(searchRequest);
-			return response;
 
-		} catch (Exception e) {
-			LOGGER.error(String.format(Constants.EXCEPTION, "getApplications", e.getMessage()));
-		}
-		return null;
-	}
-
-	@Override
-	public List<Map<String, Object>> getPlainFormsById(String id) {
-		try {
-			// query builder
-			SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(1000);
-			BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
-			boolBuilder.must().add(QueryBuilders.termsQuery("_id", id));
-			searchSourceBuilder.query(boolBuilder);
-			System.out.println(searchSourceBuilder);
-			// es call
-			SearchRequest searchRequest = new SearchRequest("fs-plain-form").source(searchSourceBuilder);
-			LOGGER.info("Search Request : " + searchRequest);
-			List<Map<String, Object>> response = formsDao.searchPlainFormResponse(searchRequest);
-			return response;
+	
 
-		} catch (Exception e) {
-			LOGGER.error(String.format(Constants.EXCEPTION, "getApplications", e.getMessage()));
-		}
-		return null;
-	}
 	
 	@Override
 	 public ByteArrayInputStream getInstituteFormData(Long orgId) {
 		
 		List<InstituteFormDataDto> dataList = new ArrayList<InstituteFormDataDto>();
 		
-		    List<Object[]> dataListDto = instituteCoursesDao.findInstituteForm(orgId);
+		   
+			List<Object[]> dataListDto = instituteCoursesDao.findInstituteForm(orgId);
 		    
 		    for(Object[] dto : dataListDto) {
 		    	InstituteFormDataDto data = new InstituteFormDataDto();
diff --git a/src/main/java/com/tarento/formservice/utils/PathRoutes.java b/src/main/java/com/tarento/formservice/utils/PathRoutes.java
index 12a44a8d57cbee8a2701a10bda4edcf6ef89945e..7388ea9659d26090ca8a8e0e7506ddd5700c8c3d 100644
--- a/src/main/java/com/tarento/formservice/utils/PathRoutes.java
+++ b/src/main/java/com/tarento/formservice/utils/PathRoutes.java
@@ -11,6 +11,7 @@ public interface PathRoutes {
 		final String SAVE_FORM_SUBMIT_V1 = "/v1/saveFormSubmit";
 		final String SAVE_FORM_SUBMIT_BULK = "/saveFormSubmitBulk";
 		final String GET_ALL_APPLICATIONS = "/getAllApplications";
+		final String GET_INSTITUTE_DATA = "/getInstituteData";
 		final String GET_APPLICATIONS_BY_ID = "/getApplicationsById";
 		final String GET_APPLICATIONS_STATUS_COUNT = "/getApplicationsStatusCount";
 		final String FILE_UPLOAD = "/fileUpload";