diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/config/PropertiesManager.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/config/PropertiesManager.java index dd0fb1ee4c6..a5db11ba8d9 100644 --- a/core-services/egov-hrms/src/main/java/org/egov/hrms/config/PropertiesManager.java +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/config/PropertiesManager.java @@ -134,4 +134,8 @@ public class PropertiesManager { @Value("${egov.hrms.auto.generate.password}") private boolean autoGeneratePassword; + + @Value("${egov.mdmsLegacy.search.endpoint}") + public String mdmsLegacySearchEndpoint; + } \ No newline at end of file diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/service/IndividualService.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/service/IndividualService.java index 07b315bf1bc..36f5a1eb42a 100644 --- a/core-services/egov-hrms/src/main/java/org/egov/hrms/service/IndividualService.java +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/service/IndividualService.java @@ -1,5 +1,6 @@ package org.egov.hrms.service; + import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Collections; @@ -15,18 +16,9 @@ import lombok.extern.slf4j.Slf4j; import org.egov.common.contract.request.RequestInfo; import org.egov.common.models.core.Role; -import org.egov.common.models.individual.Address; -import org.egov.common.models.individual.AddressType; -import org.egov.common.models.individual.Gender; -import org.egov.common.models.individual.Identifier; -import org.egov.common.models.individual.Individual; -import org.egov.common.models.individual.IndividualBulkResponse; -import org.egov.common.models.individual.IndividualRequest; -import org.egov.common.models.individual.IndividualResponse; -import org.egov.common.models.individual.IndividualSearch; -import org.egov.common.models.individual.IndividualSearchRequest; -import org.egov.common.models.individual.Name; -import org.egov.common.models.individual.UserDetails; + +import org.egov.common.models.individual.*; + import org.egov.hrms.config.PropertiesManager; import org.egov.hrms.repository.RestCallRepository; import org.egov.hrms.utils.HRMSConstants; @@ -35,6 +27,12 @@ import org.egov.hrms.web.contract.UserResponse; import org.springframework.beans.factory.annotation.Autowired; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + + import static org.egov.hrms.utils.HRMSConstants.SYSTEM_GENERATED; @Slf4j @@ -161,19 +159,15 @@ private static IndividualRequest mapToIndividualRequest(UserRequest userRequest) /* * FIXME (HCM specific change) clientReferenceId is the primary key in the individual table of the FrontEnd Worker Application's local database. */ - // Generating a unique client reference ID using UUID .clientReferenceId(String.valueOf(UUID.randomUUID())) // Creating a list of identifiers .identifiers(Collections.singletonList( - // Building a unique identifier Identifier.builder() - // Generating a unique client reference ID using UUID for the identifier .clientReferenceId(String.valueOf(UUID.randomUUID())) - // Generating a unique identifier ID using UUID .identifierId(String.valueOf(UUID.randomUUID())) - // Specifying the type of identifier as SYSTEM_GENERATED .identifierType(SYSTEM_GENERATED) .build())) + .userDetails(UserDetails.builder() .username(userRequest.getUser().getUserName()) .password(userRequest.getUser().getPassword()) diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/service/MDMSService.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/service/MDMSService.java index 9b2d8df55c3..dd3cbe0e3e7 100644 --- a/core-services/egov-hrms/src/main/java/org/egov/hrms/service/MDMSService.java +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/service/MDMSService.java @@ -27,12 +27,18 @@ public class MDMSService { @Autowired private RestTemplate restTemplate; - + + @Value("${egov.mdmslegacy.host}") + private String mdmsLegacyHost; + @Value("${egov.mdms.host}") private String mdmsHost; @Value("${egov.mdms.search.endpoint}") private String mdmsEndpoint; + + @Value("${egov.mdmslegacy.search.endpoint}") + private String mdmsLegacyEndpoint; /** @@ -180,7 +186,8 @@ public MdmsCriteriaReq prepareMDMSRequestLoc(StringBuilder uri, RequestInfo requ moduleDetail.setMasterDetails(masterDetails); moduleDetails.add(moduleDetail); } - uri.append(mdmsHost).append(mdmsEndpoint); + + uri.append(mdmsLegacyHost).append(mdmsLegacyEndpoint); MdmsCriteria mdmsCriteria = MdmsCriteria.builder().tenantId(tenantId).moduleDetails(moduleDetails).build(); return MdmsCriteriaReq.builder().requestInfo(requestInfo).mdmsCriteria(mdmsCriteria).build(); diff --git a/health-services/attendance/Attendace Service Postman Scripts.postman_collection.json b/health-services/attendance/Attendace Service Postman Scripts.postman_collection.json new file mode 100644 index 00000000000..4f63c0b7820 --- /dev/null +++ b/health-services/attendance/Attendace Service Postman Scripts.postman_collection.json @@ -0,0 +1,3633 @@ +{ + "info": { + "_postman_id": "25632b98-5918-4908-8a85-9500d8a81afa", + "name": "Attendace Service Postman Scripts", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "Attendance Register", + "item": [ + { + "name": "Create Attendance Register - Success - Single Register", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendance Registers are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendanceRegister).to.not.be.undefined;", + " pm.expect(req.attendanceRegister).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.tenantId).to.be.not.null;", + " pm.expect(register.tenantId).to.be.not.undefined;", + " pm.expect(register.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Register Name is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.name).to.be.not.null;", + " pm.expect(register.name).to.be.not.undefined;", + " pm.expect(register.name).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Register start date is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.startDate).to.be.not.null;", + " pm.expect(register.startDate).to.be.not.undefined;", + " pm.expect(register.startDate).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Start date should be less than end date\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " if (Number.isFinite(register.endDate) && (register.endDate != undefined || register.endDate != null )) {", + " pm.expect(register.endDate).to.be.not.below(register.startDate);", + " }", + " }", + ");", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Register Number is enriched\", function () {", + " var res = pm.response.json();", + " var registerNumber = res.attendanceRegister[0].registerNumber;", + " pm.expect(registerNumber.substring(0,2)).to.eql(\"WR\");", + " }", + ");", + "", + "pm.test(\"Register status is set to Active if status not passed\", function () {", + " var res = pm.response.json();", + " var status = res.attendanceRegister[0].status;", + " pm.expect(status).to.eql(\"ACTIVE\");", + " }", + ");", + "", + "pm.test(\"Staff is created for register\", function () {", + " var res = pm.response.json();", + " var staff = res.attendanceRegister[0].staff;", + " pm.expect(staff).to.be.not.null;", + " pm.expect(staff).to.be.not.undefined;", + " pm.expect(staff.length).to.eql(1);", + " }", + ");", + "", + "pm.test(\"Staff created have same userId as UUID of user\", function () {", + " var res = pm.response.json();", + " var userInRequest = res.attendanceRegister[0].auditDetails.createdBy;", + " var staff = res.attendanceRegister[0].staff;", + " pm.expect(staff[0].userId).to.eql(userInRequest);", + " }", + ");", + "", + "let responseData = pm.response.json();", + "pm.collectionVariables.set(\"tenantId\", responseData.attendanceRegister[0].tenantId);", + "pm.collectionVariables.set(\"stateLevelTenant\", responseData.attendanceRegister[0].tenantId.split('.', 1)[0]);", + "pm.collectionVariables.set(\"registerId\", responseData.attendanceRegister[0].id);", + "pm.collectionVariables.set(\"registerNumber\", responseData.attendanceRegister[0].registerNumber);", + "", + "pm.collectionVariables.set(\"registerStartDate\", responseData.attendanceRegister[0].startDate);", + "pm.collectionVariables.set(\"registerEndDate\", responseData.attendanceRegister[0].endDate);", + "pm.collectionVariables.set(\"invalidRegisterEndDate\", responseData.attendanceRegister[0].endDate+24*60*60*1000);", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.collectionVariables.set(\"tenantId\", \"pg.citya\");", + "// pm.collectionVariables.set(\"individualId\", \"2d12b93a-829b-4aef-9073-5418e2315355\");", + "//dev", + "pm.collectionVariables.set(\"individualId-1\", \"6731ed44-2407-457d-aa3e-70ffbd1d6d21\");", + "pm.collectionVariables.set(\"individualId-2\", \"311b13c2-0029-4679-8723-fe6f57870a35\");", + "", + "", + "//qa", + "// pm.collectionVariables.set(\"individualId-1\", \"3ff2861e-8bbd-4431-a6b4-6f6a1c116356\");", + "// pm.collectionVariables.set(\"individualId-2\", \"a7d7ec01-68e0-428d-8762-c81e2fd5c864\");", + "", + "", + "pm.collectionVariables.set(\"referenceId\", \"test_contract_number_01\");", + "pm.collectionVariables.set(\"serviceCode\", \"WORKS-CONTRACT\");", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_01\",\n \"referenceId\": \"{{referenceId}}+{{$randomPhoneNumber}}\",\n \"serviceCode\": \"{{serviceCode}}\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Success - Multiple Registers", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendance Registers are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendanceRegister).to.not.be.undefined;", + " pm.expect(req.attendanceRegister).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.tenantId).to.be.not.null;", + " pm.expect(register.tenantId).to.be.not.undefined;", + " pm.expect(register.tenantId).not.to.eql(\"\");", + " });", + " }", + ");", + "", + "pm.test(\"Register Name is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.name).to.be.not.null;", + " pm.expect(register.name).to.be.not.undefined;", + " pm.expect(register.name).not.to.eql(\"\");", + " });", + " }", + ");", + "", + "pm.test(\"Register start date is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.startDate).to.be.not.null;", + " pm.expect(register.startDate).to.be.not.undefined;", + " pm.expect(register.startDate).not.to.eql(\"\");", + " });", + " }", + ");", + " ", + "", + "pm.test(\"Start date should be less than end date\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " if (Number.isFinite(register.endDate) && (register.endDate != undefined || register.endDate != null )) {", + " pm.expect(register.endDate).to.be.not.below(register.startDate);", + " }", + " });", + " }", + ");", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Register Number is enriched\", function () {", + " var res = pm.response.json();", + " res.attendanceRegister.forEach(register => {", + " var registerNumber = register.registerNumber;", + " pm.expect(registerNumber.substring(0,2)).to.eql(\"WR\");", + " });", + " }", + ");", + "", + "pm.test(\"Staff is created for register\", function () {", + " var res = pm.response.json();", + " res.attendanceRegister.forEach(register => {", + " var staff = register.staff;", + " pm.expect(staff).to.be.not.null;", + " pm.expect(staff).to.be.not.undefined;", + " pm.expect(staff.length).to.eql(1);", + " }); ", + " }", + ");", + "", + "pm.test(\"Staff created have same userId as UUID of user\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var res = pm.response.json();", + " res.attendanceRegister.forEach(register => {", + " var userInRequest = register.auditDetails.createdBy;", + " var staff =register.staff;", + " pm.expect(staff[0].userId).to.eql(userInRequest);", + " }); ", + " }", + ");", + "", + "let responseData = pm.response.json();", + "pm.collectionVariables.set(\"registerId2\", responseData.attendanceRegister[1].id);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_01\",\n \"referenceId\": \"{{referenceId}}+{{$randomPhoneNumber}}\",\n \"serviceCode\": \"{{serviceCode}}\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000\n },\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_02\",\n \"referenceId\": \"{{referenceId}}+{{$randomPhoneNumber}}\",\n \"serviceCode\": \"{{serviceCode}}\",\n \"startDate\": 1640995200000,\n \"additionalDetails\": {}\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Validation Error - Registers not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"ATTENDANCE_REGISTER\");", + " pm.expect(message).to.eql(\"Attendance Register is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": []\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Validation Error - TenantId not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"TENANT_ID\");", + " pm.expect(message).to.eql(\"Tenant is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"name\": \"TestRegister_01\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Validation Error - Name not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"NAME\");", + " pm.expect(message).to.eql(\"Name is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"referenceId\": \"{{referenceId}}+{{$randomPhoneNumber}}\",\n \"serviceCode\": \"{{serviceCode}}\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Validation Error - Start Date not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"START_DATE\");", + " pm.expect(message).to.eql(\"Start date is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_01\",\n \"endDate\": 1703980800000\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Validation Error - Start Date greater than End Date", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"DATE\");", + " pm.expect(message).to.eql(\"Start date should be less than end date\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_01\",\n \"startDate\": 1803980800000,\n \"endDate\": 1703980800000\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Validation Error - Start Date Equal to 0", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"START_DATE\");", + " pm.expect(message).to.eql(\"Start date is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_01\",\n \"startDate\": 0,\n \"endDate\": 1703980800000\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Success", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200)));", + "", + "pm.test(\"Register Search response is received\", function () {", + " var res = pm.response.json();", + " var id = res.attendanceRegister[0].id;", + " pm.expect(id).to.eql(pm.collectionVariables.get(\"registerId\"));", + " }", + ");" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"{{token}}\"\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?tenantId={{tenantId}}&ids={{registerId}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + }, + { + "key": "ids", + "value": "{{registerId}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Success - Unassociated AttendeeId", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200)));", + "", + "pm.test(\"Register Search response is received\", function () {", + " var res = pm.response.json();", + " pm.expect(res.attendanceRegister.length).to.equal(0);", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"{{token}}\"\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?tenantId={{tenantId}}&ids={{registerId}}&attendeeId={{$guid}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + }, + { + "key": "ids", + "value": "{{registerId}}" + }, + { + "key": "attendeeId", + "value": "{{$guid}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Success - Unassociated StaffId", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200)));", + "", + "pm.test(\"Register Search response is received\", function () {", + " var res = pm.response.json();", + " pm.expect(res.attendanceRegister.length).to.equal(0);", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"{{token}}\"\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?tenantId={{tenantId}}&ids={{registerId}}&staffId={{$guid}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + }, + { + "key": "ids", + "value": "{{registerId}}" + }, + { + "key": "staffId", + "value": "{{$guid}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Success - SuperUser - Non existing RegisterID", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200)));", + "", + "pm.test(\"Register Search response is received\", function () {", + " var res = pm.response.json();", + " pm.expect(res.attendanceRegister.length).to.equal(0);", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"{{token}}\"\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?tenantId={{tenantId}}&ids={{$guid}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + }, + { + "key": "ids", + "value": "{{$guid}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Validation Error - Unassociated Register Id", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200)));", + "", + "pm.test(\"Register Search response is received\", function () {", + " var res = pm.response.json();", + " var code = res.attendanceRegister.length;", + " pm.expect(code).to.eql(0);", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"{{token}}\"\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?tenantId={{tenantId}}&ids=96d1055c-0251-498d-b98d-26d6c232925f", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + }, + { + "key": "ids", + "value": "96d1055c-0251-498d-b98d-26d6c232925f" + } + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Validation Error - Tenant Id not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"TENANT_ID\");", + " pm.expect(message).to.eql(\"Tenant is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"{{token}}\"\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?ids={{registerId}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "ids", + "value": "{{registerId}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Update Attendance Register - Success - Single Register", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "", + "pm.test(\"Attendance Registers are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendanceRegister).to.not.be.undefined;", + " pm.expect(req.attendanceRegister).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.tenantId).to.be.not.null;", + " pm.expect(register.tenantId).to.be.not.undefined;", + " pm.expect(register.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Register Id is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.id).to.be.not.null;", + " pm.expect(register.id).to.be.not.undefined;", + " pm.expect(register.id).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Register Name is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.name).to.be.not.null;", + " pm.expect(register.name).to.be.not.undefined;", + " pm.expect(register.name).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Register start date is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.startDate).to.be.not.null;", + " pm.expect(register.startDate).to.be.not.undefined;", + " pm.expect(register.startDate).not.to.eql(\"\");", + " }", + ");", + " ", + "", + "pm.test(\"Start date should be less than end date\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " if (Number.isFinite(register.endDate) && (register.endDate != undefined || register.endDate != null )) {", + " pm.expect(register.endDate).to.be.not.below(register.startDate);", + " }", + " }", + ");", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Staff is created for register\", function () {", + " var res = pm.response.json();", + " var staff = res.attendanceRegister[0].staff;", + " pm.expect(staff).to.be.not.null;", + " pm.expect(staff).to.be.not.undefined;", + " pm.expect(staff.length).to.eql(1);", + " }", + ");", + "", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"id\": \"{{registerId}}\",\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_010\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000,\n \"status\": \"ACTIVE\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Update Attendance Register - Success - Multiple Registers", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "", + "pm.test(\"Attendance Registers are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendanceRegister).to.not.be.undefined;", + " pm.expect(req.attendanceRegister).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.tenantId).to.be.not.null;", + " pm.expect(register.tenantId).to.be.not.undefined;", + " pm.expect(register.tenantId).not.to.eql(\"\");", + " });", + " }", + ");", + "", + "pm.test(\"Register Id is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.id).to.be.not.null;", + " pm.expect(register.id).to.be.not.undefined;", + " pm.expect(register.id).not.to.eql(\"\");", + " });", + " }", + ");", + "", + "pm.test(\"Register Name is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.name).to.be.not.null;", + " pm.expect(register.name).to.be.not.undefined;", + " pm.expect(register.name).not.to.eql(\"\");", + " });", + " }", + ");", + "", + "pm.test(\"Register start date is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.startDate).to.be.not.null;", + " pm.expect(register.startDate).to.be.not.undefined;", + " pm.expect(register.startDate).not.to.eql(\"\");", + " });", + " }", + ");", + " ", + "", + "pm.test(\"Start date should be less than end date\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " if (Number.isFinite(register.endDate) && (register.endDate != undefined || register.endDate != null )) {", + " pm.expect(register.endDate).to.be.not.below(register.startDate);", + " }", + " });", + " }", + ");", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"id\": \"{{registerId}}\",\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_010\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000,\n \"status\": \"ACTIVE\"\n },\n {\n \"id\": \"{{registerId2}}\",\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_020\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000,\n \"status\": \"INACTIVE\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Update Attendance Register - Validation Error - Register Id not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"ATTENDANCE_REGISTER_ID\");", + " pm.expect(message).to.eql(\"Attendance register id is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_010\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000,\n \"status\": \"ACTIVE\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Update Attendance Register - Validation Error - Tenant Id not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"TENANT_ID\");", + " pm.expect(message).to.eql(\"Tenant is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"id\": \"{{registerId}}\",\n \"name\": \"TestRegister_010\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000,\n \"status\": \"ACTIVE\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Update Attendance Register - Validation Error - Name not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"NAME\");", + " pm.expect(message).to.eql(\"Name is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"id\": \"{{registerId}}\",\n \"tenantId\": \"{{tenantId}}\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000,\n \"status\": \"ACTIVE\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Update Attendance Register - Validation Error - Start Date not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"START_DATE\");", + " pm.expect(message).to.eql(\"Start date is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"id\": \"{{registerId}}\",\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_010\",\n \"endDate\": 1703980800000,\n \"status\": \"ACTIVE\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_update" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Register Permission", + "item": [ + { + "name": "Staff - Enroll - Single Staff", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Enrollment date is enriched\", function () {", + " var res = pm.response.json();", + " var enrollmentDate = res.staff[0].enrollmentDate;", + " pm.expect(enrollmentDate).to.be.not.null;", + " }", + ");", + "", + "// let requestData = JSON.parse(pm.request.body.raw);", + "// pm.collectionVariables.set(\"userId\", requestData.staff[0].userId);", + "", + "let responseData = pm.response.json();", + "pm.collectionVariables.set(\"userId\", responseData.staff[0].userId);", + "console.log(pm.collectionVariables.get(\"userId\"));", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Enroll the user to register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{$randomUUID}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Enroll - Validation Error - Staff already enrolled to the register", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"response is 400. Staff is already enrolled to the register\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "console.log(pm.collectionVariables.get(\"userId\"))" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Enroll the user to register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Enroll - Validation Error - Duplicate staff objects not allowed in enrollment request", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + "", + " req.staff.forEach(staff => {", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }); ", + "", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "", + "pm.test(\"Response is 400. Duplicate objects in request\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Enroll the user to register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"928ca23a-9bec-11ed-a8fc-0242ac120002\",\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"928ca23a-9bec-11ed-a8fc-0242ac120002\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Enroll - Multiple staff", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + "", + " req.staff.forEach(staff => {", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }); ", + "", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Enrollment date is enriched\", function () {", + " var res = pm.response.json();", + " res.staff.forEach(staff => {", + " pm.expect(staff.enrollmentDate).to.be.not.null;", + " }); ", + " }", + ");", + "", + "let requestData = JSON.parse(pm.request.body.raw);", + "pm.collectionVariables.set(\"userId-1\", requestData.staff[0].userId);", + "pm.collectionVariables.set(\"userId-2\", requestData.staff[1].userId);", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Enroll the user to register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{$randomUUID}}\",\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{$randomUUID}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Deenroll - Single staff", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Deenrollment date is enriched\", function () {", + " var res = pm.response.json();", + " var deenrollmentDate = res.staff[0].deenrollmentDate;", + " pm.expect(deenrollmentDate).to.be.not.null;", + " }", + ");", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Deenroll staff from register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_delete" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Deenroll - Validation Error - Staff already denrolled from the register", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is 400. Staff already deenrolled from the register\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Deenroll staff from register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_delete" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Deenroll - Validation Error - Duplicate staff objects in deenrollment request", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + "", + " req.staff.forEach(staff => {", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }); ", + "", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Response is 400. Duplicate staff objects in de enrollment request\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Deenroll staff from register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId-1}}\",\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId-1}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_delete" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Deenroll - Multiple staff", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + "", + " req.staff.forEach(staff => {", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }); ", + "", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Deenrollment date is enriched\", function () {", + " var res = pm.response.json();", + " res.staff.forEach(staff => {", + " pm.expect(staff.deenrollmentDate).to.be.not.null;", + " }); ", + " }", + ");", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Deenroll staff from register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId-1}}\",\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId-2}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_delete" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Individual Enrollment", + "item": [ + { + "name": "Attendee - Enroll - Attendee", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendee are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Enrollment date is enriched\", function () {", + " var res = pm.response.json();", + " var enrollmentDate = res.attendees[0].enrollmentDate;", + " pm.expect(enrollmentDate).to.be.not.null;", + " }", + ");", + "", + "// let requestData = JSON.parse(pm.request.body.raw);", + "// pm.collectionVariables.set(\"individualId\", requestData.attendees[0].individualId);", + "let responseData = pm.response.json();", + "pm.collectionVariables.set(\"attendeeEnrollmentDate\", responseData.attendees[0].enrollmentDate);", + "", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Enroll attendee to register\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId-1}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n } \n\n ]\n\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Enroll - Validation Error - Attendee already enrolled", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendee are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is 400. Attendee already enrolled to the register\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Enroll attendee to register\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId-1}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n } \n\n ]\n\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Enroll - Validation Error - Duplicate attendee objects not allowed in request", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendee are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "", + "pm.test(\"Response is 400. Duplicate attendee objects in the request\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Enroll attendee to register\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId-1}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId-1}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n } \n\n ]\n\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Deenroll- Single Attendee", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendees are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Deenrollment date is enriched\", function () {", + " var res = pm.response.json();", + " var deenrollmentDate = res.attendees[0].deenrollmentDate;", + " pm.expect(deenrollmentDate).to.be.not.null;", + " }", + ");", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"search with from and to values\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId-1}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_delete" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Deenroll- Validation Error - Attendee already deenrolled from the register", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendees are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is 400. Attendee already deenrolled from the register\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"search with from and to values\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId-1}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_delete" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Enroll - Multiple Attendees", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendee are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Enrollment date is enriched\", function () {", + " var res = pm.response.json();", + " res.attendees.forEach(attendee => {", + " pm.expect(attendee.enrollmentDate).to.be.not.null;", + " }); ", + " }", + ");", + "", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Enroll attendee to register\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId-1}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId-2}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n } \n\n ]\n\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Deenroll- Validation Error - Duplicate attendee objects in deenrollment request", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendees are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "", + "pm.test(\"Response is 400. Duplicate attendee objects in deenrollment request.\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"search with from and to values\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId-1}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId-1}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_delete" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Deenroll- Multiple Attendees", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendees are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Deenrollment date is enriched\", function () {", + " var res = pm.response.json();", + " res.attendees.forEach(attendee => {", + " pm.expect(attendee.denrollmentDate).to.be.not.null;", + " }); ", + " }", + ");", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"search with from and to values\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId-1}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId-2}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_delete" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Attendance Log", + "item": [ + { + "name": "Attendance Log - Create - Success", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + " setTimeout( () => {", + "", + " pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var id = res.attendance[0].id;", + " pm.expect(id).to.be.not.null;", + " }", + ");", + " ", + " }, 1000);", + "", + "", + "", + "let responseData = pm.response.json();", + "pm.collectionVariables.set(\"attendanceLogId\", responseData.attendance[0].id);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId-1}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Update - Success", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Attendance Log updated successfully\", function () {", + " var res = pm.response.json();", + " var status = res.attendance[0].status;", + " pm.expect(status).to.eql(\"INACTIVE\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"id\": \"{{attendanceLogId}}\",\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId-1}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"INACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ],\r\n \"auditDetails\": {\r\n \"createdBy\": \"47b5ea82-249c-4435-9646-16167fec06df\",\r\n \"lastModifiedBy\": \"47b5ea82-249c-4435-9646-16167fec06df\",\r\n \"createdTime\": 1671090269007,\r\n \"lastModifiedTime\": 1671090269007\r\n }\r\n \r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Update - fail - attendanceId is not valid", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log updated successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"ATTENDANCE_LOG\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"id\": \"{{$randomUUID}}\",\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"INACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ],\r\n \"auditDetails\": {\r\n \"createdBy\": \"47b5ea82-249c-4435-9646-16167fec06df\",\r\n \"lastModifiedBy\": \"47b5ea82-249c-4435-9646-16167fec06df\",\r\n \"createdTime\": 1671090269007,\r\n \"lastModifiedTime\": 1671090269007\r\n }\r\n \r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Create - Fail - All logs should belong to same tenantId", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"MULTIPLE_TENANTIDS\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n },\r\n {\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"tenant.id\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Create - Fail - Validate Attendance Log time", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"INVALID_ATTENDANCE_TIME\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{invalidRegisterEndDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Create - Fail - Register should belongs to tenenatId", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": \"{{$randomUUID}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Create - Fail - All logs should belong to same registerId", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"MULTIPLE_REGISTERIDS\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n },\r\n {\r\n \"registerId\": \"{{$randomUUID}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Create - Fail - User is not authorised", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"UNAUTHORISED_USER\");", + " }", + ");" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": \"{{$randomUUID}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Rearch - Fail - TenantId is required", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"TENANT_ID\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n }\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_search", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_search" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Rearch - Fail - RegisterId is required", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"REGISTER_ID\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n }\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_search?tenantId={{tenantId}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Rearch - Success", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " pm.expect(res.attendance).to.be.not.null;", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n }\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_search?tenantId={{tenantId}}®isterId={{registerId}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + }, + { + "key": "registerId", + "value": "{{registerId}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Create - Fail - required fields are missing", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Register Search response is received\", function () {", + " var res = pm.response.json();", + " pm.expect(res.Errors.length).to.equal(5);", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": null,\r\n \"individualId\": null,\r\n \"time\": null,\r\n \"type\": null,\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": null,\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + } + ] + } + ], + "event": [ + { + "listen": "prerequest", + "script": { + "type": "text/javascript", + "exec": [ + "if (pm.environment.get(\"base_url\").includes(\"localhost\")) {", + "", + " var tenantId = \"pb.amritsar\";", + " var id = 1;", + " var uuid = \"11b0e02b-0145-4de2-bc42-c97b96264807\";", + "", + " var roles = [{", + " \"code\": \"SUPERUSER\",", + " \"name\": \"SUPER USER\",", + " \"tenantId\": tenantId", + " }];", + "", + " var userInfo = {", + " \"id\": id,", + " \"uuid\": uuid,", + " \"userName\": \"\",", + " \"name\": \"\",", + " \"mobileNumber\": \"\",", + " \"emailId\": \"\",", + " \"type\": \"\",", + " \"roles\": roles,", + " \"active\": true,", + " \"tenantId\": \"pb.amritsar\"", + " };", + "", + " pm.request.body.raw = pm.request.body.raw.replace('\"{{token}}\"', '\"\", \\n \"userInfo\": ' + JSON.stringify(userInfo));", + "}" + ] + } + }, + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ], + "variable": [ + { + "key": "tenantId", + "value": "" + }, + { + "key": "stateLevelTenant", + "value": "" + }, + { + "key": "registerId", + "value": "" + }, + { + "key": "registerNumber", + "value": "" + }, + { + "key": "registerId2", + "value": "" + }, + { + "key": "registerStartDate", + "value": "" + }, + { + "key": "registerEndDate", + "value": "" + }, + { + "key": "invalidRegisterEndDate", + "value": "" + }, + { + "key": "userId", + "value": "" + }, + { + "key": "userId-1", + "value": "" + }, + { + "key": "userId-2", + "value": "" + }, + { + "key": "individualId", + "value": "" + }, + { + "key": "attendeeEnrollmentDate", + "value": "" + }, + { + "key": "individualId-1", + "value": "" + }, + { + "key": "individualId-2", + "value": "" + }, + { + "key": "attendanceLogId", + "value": "" + }, + { + "key": "referenceId", + "value": "" + }, + { + "key": "serviceCode", + "value": "" + } + ] +} \ No newline at end of file diff --git a/health-services/attendance/Attendance-Service-1.0.0.yaml b/health-services/attendance/Attendance-Service-1.0.0.yaml new file mode 100644 index 00000000000..7a3c97e43fb --- /dev/null +++ b/health-services/attendance/Attendance-Service-1.0.0.yaml @@ -0,0 +1,666 @@ +openapi: 3.0.0 +info: + version: 1.0.0 + title: Attendance Service + description: '' + +paths: + + /attendance/v1/_create: + post: + tags: + - Attendance Register + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/AttendanceRegisterRequest' + responses: + '202': + description: 'Request to create a register has been accepted.' + content: + application/json: + schema: + $ref: '#/components/schemas/AttendanceRegisterResponse' + '400': + description: Invalid input. + content: + '*/*': + schema: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/master/core-services/docs/common-contract.yml#/components/schemas/ErrorRes' + + /attendance/v1/_update: + post: + tags: + - Attendance Register + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/AttendanceRegisterRequest' + responses: + '202': + description: 'Request to update the register has been accepted.' + content: + application/json: + schema: + $ref: '#/components/schemas/AttendanceRegisterResponse' + '400': + description: Invalid input. + content: + '*/*': + schema: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/master/core-services/docs/common-contract.yml#/components/schemas/ErrorRes' + + /attendance/v1/_search: + post: + tags: + - Attendance Register + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/RequestInfoWrapper' + parameters: + - $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/master/core-services/docs/common-contract.yml#/components/parameters/tenantId' + - name: ids + description: List of register ids + in: query + schema: + type: array + items: + type: string + - name: registerNumber + description: Custom formatted Register id + in: query + schema: + type: string + - name: name + description: Name of the register + in: query + schema: + type: string + - name: referenceId + description: Reference Id + in: query + schema: + type: string + - name: serviceCode + description: Service Code + in: query + schema: + type: string + - name: fromDate + description: Return registers with any overlap in the given time period + in: query + schema: + type: number + - name: toDate + description: Return registers with any overlap in the given time period + in: query + schema: + type: number + - name: status + description: Status of the register. This can't be the only query param. It should be paired with some other search param. + in: query + schema: + type: string + - name: attendeeId + description: Get all the registers where the given Individual was registered. + in: query + schema: + type: string + - name: staffId + description: Get all the registers where the given staff was registered. + in: query + schema: + type: string + - name: sortBy + in: query + description: sort the search results by fields + schema: + type: string + enum: + - fromDate + - toDate + - lastModifiedTime + - name: sortOrder + in: query + description: sorting order of the search resulsts + schema: + type: string + enum: + - asc + - desc + - name: limit + in: query + description: limit on the resulsts + schema: + type: number + - name: offset + in: query + description: offset index of the overall search resulsts + schema: + type: number + responses: + '200': + description: 'Search results' + content: + application/json: + schema: + $ref: '#/components/schemas/AttendanceRegisterResponse' + '400': + description: Invalid input. + content: + '*/*': + schema: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/master/core-services/docs/common-contract.yml#/components/schemas/ErrorRes' + + /attendance/staff/v1/_create: + post: + description: Grant permission to a user to access and modify an attendance register. This user can enroll / denroll individuals. They will add attendance entries for the attendees. + tags: + - Register Permission + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/StaffPermissionRequest' + responses: + '202': + description: 'Grant permission request accepted' + content: + application/json: + schema: + $ref: '#/components/schemas/StaffPermissionResponse' + '400': + description: Invalid input. + content: + '*/*': + schema: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/master/core-services/docs/common-contract.yml#/components/schemas/ErrorRes' + + /attendance/staff/v1/_delete: + post: + description: Revoke permission to a user to access and modify an attendance register. This user can enroll / denroll individuals. They will add attendance entries for the attendees. + tags: + - Register Permission + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/StaffPermissionRequest' + responses: + '202': + description: 'Revoke permission request accepted' + content: + application/json: + schema: + $ref: '#/components/schemas/StaffPermissionResponse' + '400': + description: Invalid input. + content: + '*/*': + schema: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/master/core-services/docs/common-contract.yml#/components/schemas/ErrorRes' + + /attendance/attendee/v1/_create: + post: + description: Users with permission to access the register can enroll / denroll attendees. + tags: + - Individual Enrollment + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/AttendeeCreateRequest' + responses: + '202': + description: 'Attendee Create request accepted' + content: + application/json: + schema: + $ref: '#/components/schemas/AttendeeCreateResponse' + '400': + description: Invalid input. + content: + '*/*': + schema: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/master/core-services/docs/common-contract.yml#/components/schemas/ErrorRes' + + /attendance/attendee/v1/_delete: + post: + description: Users with permission to access the register can enroll / denroll attendees. + tags: + - Individual Enrollment + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/AttendeeDeleteRequest' + responses: + '202': + description: 'Attendee Delete request accepted' + content: + application/json: + schema: + $ref: '#/components/schemas/AttendeeDeleteResponse' + '400': + description: Invalid input. + content: + '*/*': + schema: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/master/core-services/docs/common-contract.yml#/components/schemas/ErrorRes' + + /attendance/log/v1/_create: + post: + tags: + - Attendance Log + description: It creates a new attendance record. + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/AttendanceLogRequest' + responses: + '202': + description: 'Attendance Records Create Request accepted.' + content: + application/json: + schema: + $ref: '#/components/schemas/AttendanceLogResponse' + '400': + description: Invalid input. + content: + '*/*': + schema: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/master/core-services/docs/common-contract.yml#/components/schemas/ErrorRes' + + /attendance/log/v1/_update: + post: + tags: + - Attendance Log + description: It updates an attendance record. + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/AttendanceLogRequest' + responses: + '202': + description: 'Attendance Records Update Request accepted.' + content: + application/json: + schema: + $ref: '#/components/schemas/AttendanceLogResponse' + '400': + description: Invalid input. + content: + '*/*': + schema: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/master/core-services/docs/common-contract.yml#/components/schemas/ErrorRes' + + /attendance/log/v1/_search: + post: + tags: + - Attendance Log + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/RequestInfoWrapper' + parameters: + - $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/master/core-services/docs/common-contract.yml#/components/parameters/tenantId' + - name: registerId + in: query + required: true + description: Id of the register + schema: + type: string + - name: fromTime + in: query + description: Starting time from which the attendance needs to be searched + schema: + type: number + - name: toTime + in: query + description: End time till which the attendance needs to be searched + schema: + type: number + - name: individualIds + in: query + description: List of individual ids + schema: + type: array + items: + type: string + - name: ids + in: query + description: List of ids + schema: + type: array + items: + type: string + - name: status + in: query + description: The status of the attendance log. + schema: + type: string + enum: + - ACTIVE + - INACTIVE + responses: + '200': + description: 'Complete table of attendance entries.' + content: + application/json: + schema: + $ref: '#/components/schemas/AttendanceLogResponse' + +components: + schemas: + AttendanceRegister: + type: object + properties: + id: + type: string + format: uuid + example: 64e33343-7b4c-4353-9abf-4de8f5bcd732 + description: System generated unique identifier of the register + readOnly: true + tenantId: + type: string + example: pb.amritsar + description: Tenant Id of the register + registerNumber: + type: string + example: REG/2022-23/001 + description: System generated id with custom formatting + readOnly: true + name: + type: string + example: Class-10-E Physics + description: Name of the register + maxLength: 140 + referenceId: + type: string + example: 64e33343-7b4c-4353-9abf-4de8f5bcd732 + description: Id of the entity to which register is associated. Example ContractId + maxLength: 256 + serviceCode: + type: string + example: WORKS-CONTRACT + description: Service to which register is associated. + maxLength: 64 + startDate: + type: number + format: timestamp + example: 1665497225000 + description: Timestamp of the start date in milliseconds + endDate: + type: number + format: timestamp + example: 1665497271000 + description: Timestamp of the end date in milliseconds. After the end date no modifications will be allowed to the register. + status: + type: string + enum: + - ACTIVE + - INACTIVE + description: Stores if the register is active or not. Inactive registers can be archieved later. + staff: + readOnly: true + type: array + items: + allOf: + - $ref: '#/components/schemas/StaffPermission' + - description: 'Entries of the staff members of the register.' + attendees: + readOnly: true + type: array + items: + allOf: + - $ref: '#/components/schemas/IndividualEntry' + - description: 'Entries of the attendees of the register.' + auditDetails: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/master/core-services/docs/common-contract.yml#/components/schemas/AuditDetails' + additionalDetails: + type: object + description: Any additional details of the register + required: + - tenantId + - name + - referenceId + - serviceCode + + AttendanceRegisterRequest: + type: object + properties: + requestInfo: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/subhashini_devguide_changes/core-services/docs/common-contract.yml#/definitions/RequestInfo' + attendanceRegister: + type: array + items: + allOf: + - $ref: '#/components/schemas/AttendanceRegister' + - description: 'Entries of the attendance register to be created.' + + AttendanceRegisterResponse: + type: object + properties: + responseInfo: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/subhashini_devguide_changes/core-services/docs/common-contract.yml#/definitions/ResponseInfo' + attendanceRegister: + type: array + items: + $ref: '#/components/schemas/AttendanceRegister' + + IndividualEntry: + type: object + properties: + id: + type: string + format: uuid + example: 64e33343-7b4c-4353-9abf-4de8f5bcd732 + description: Primary identifier of the enrollment record + readOnly: true + registerId: + type: string + format: uuid + example: 32e33343-7b4c-4353-9abf-4de8f5bcd764 + description: This field will not be shown when this object is part of the register object. It is present so that we can reuse this object for enroll and denroll requests. + individualId: + type: string + format: uuid + example: 2bafdd8d-5673-4690-b3d0-e13d7ac0cf24 + description: Reference from the Individual Registry + enrollmentDate: + type: number + description: The timestamp of the date on which the individual is enrolled onto the register. Defaults to current time. + denrollmentDate: + type: number + description: The timestamp of the date on which the individual is denrolled from the register. Defaults to current time. + tenantId: + type: string + example: pb.amritsar + description: Tenant Id + + AttendeeCreateRequest: + type: object + properties: + requestInfo: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/subhashini_devguide_changes/core-services/docs/common-contract.yml#/definitions/RequestInfo' + attendees: + type: array + items: + allOf: + - $ref: '#/components/schemas/IndividualEntry' + - required: + - registerId + - individualId + - enrollmentDate + - tenantId + + AttendeeCreateResponse: + type: object + properties: + responseInfo: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/subhashini_devguide_changes/core-services/docs/common-contract.yml#/definitions/ResponseInfo' + attendees: + type: array + items: + $ref: '#/components/schemas/IndividualEntry' + + AttendeeDeleteRequest: + type: object + properties: + requestInfo: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/subhashini_devguide_changes/core-services/docs/common-contract.yml#/definitions/RequestInfo' + attendees: + type: array + items: + allOf: + - $ref: '#/components/schemas/IndividualEntry' + - required: + - registerId + - individualId + - denrollmentDate + - tenantId + + AttendeeDeleteResponse: + type: object + properties: + responseInfo: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/subhashini_devguide_changes/core-services/docs/common-contract.yml#/definitions/ResponseInfo' + attendees: + type: array + items: + $ref: '#/components/schemas/IndividualEntry' + + StaffPermission: + type: object + properties: + id: + type: string + format: uuid + description: System generated unique identifier for the granted permission request + readOnly: true + registerId: + type: string + description: Identifier of the register. This field will not be shown when this object is part of the register object. It is present so that we can reuse this object for access permission requests. + userId: + type: string + description: Identifier of the user of the system + tenantId: + type: string + format: string + example: pb.amritsar + description: Tenant Id to which the staff belongs + enrollmentDate: + readOnly: true + type: number + description: The timestamp at which the permission is granted. It is set to the current time when the create api is called. + denrollmentDate: + readOnly: true + type: number + description: The timestamp at which the access permission is revoked. It is set to the current time when the delete api is called. + required: + - registerId + - userId + + StaffPermissionRequest: + type: object + properties: + requestInfo: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/subhashini_devguide_changes/core-services/docs/common-contract.yml#/definitions/RequestInfo' + staff: + type: array + items: + allOf: + - $ref: '#/components/schemas/StaffPermission' + - required: + - registerId + - userId + - tenantId + + StaffPermissionResponse: + type: object + properties: + responseInfo: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/subhashini_devguide_changes/core-services/docs/common-contract.yml#/definitions/ResponseInfo' + staff: + type: array + items: + $ref: '#/components/schemas/StaffPermission' + + AttendanceLog: + type: object + properties: + id: + type: string + format: uuid + description: System generated unique identifier for the entry + readOnly: true + registerId: + type: string + description: Unique identifier of the register + individualId: + type: string + format: uuid + description: The individual for which the attendance is being marked + tenantId: + type: string + example: pb.amritsar + description: Tenant Id of the register + time: + type: number + format: timestamp + description: The timestamp at which the event has been recorded. + type: + type: string + description: Configurable in MDMS. [ENTRY/EXIT/...] + status: + type: string + enum: + - ACTIVE + - INACTIVE + description: The attendance log of the cancelled event can be marked as inactive. + documentIds: + description: Used to store file store ids. Need to verify validity of them using file store service. + type: array + items: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/master/core-services/docs/common-contract.yml#/components/schemas/Document' + additionalDetails: + type: object + required: + - registerId + - individualId + - tenantId + - time + - type + + AttendanceLogRequest: + type: object + properties: + requestInfo: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/subhashini_devguide_changes/core-services/docs/common-contract.yml#/definitions/RequestInfo' + attendance: + type: array + items: + $ref: '#/components/schemas/AttendanceLog' + + AttendanceLogResponse: + type: object + properties: + responseInfo: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/subhashini_devguide_changes/core-services/docs/common-contract.yml#/definitions/ResponseInfo' + attendance: + type: array + items: + $ref: '#/components/schemas/AttendanceLog' + + RequestInfoWrapper: + type: object + properties: + requestInfo: + $ref: 'https://raw.githubusercontent.com/egovernments/DIGIT-OSS/subhashini_devguide_changes/core-services/docs/common-contract.yml#/definitions/RequestInfo' \ No newline at end of file diff --git a/health-services/attendance/CHANGELOG.md b/health-services/attendance/CHANGELOG.md new file mode 100644 index 00000000000..e5a50979d1d --- /dev/null +++ b/health-services/attendance/CHANGELOG.md @@ -0,0 +1,6 @@ + +All notable changes to this module will be documented in this file. + +## 0.1.0 - 2023-04-17 + +- Base version \ No newline at end of file diff --git a/health-services/attendance/LOCALSETUP.md b/health-services/attendance/LOCALSETUP.md new file mode 100644 index 00000000000..dbbd2382297 --- /dev/null +++ b/health-services/attendance/LOCALSETUP.md @@ -0,0 +1,42 @@ +# Local Setup + +To set up the muster roll service in your local system, clone the git repo(https://github.com/egovernments/DIGIT-Works). + +## Dependencies + +- MDMS +- IDGen +- Workflow service +- Individual + + +### Infra Dependency + +- [X] Postgres DB +- [ ] Redis +- [ ] Elasticsearch (needed if there is indexer +- [X] Kafka + +## Running Locally + +To run the service locally, you need to port forward below services. + +```bash +function kgpt(){kubectl get pods -n egov --selector=app=$1 --no-headers=true | head -n1 | awk '{print $1}'} + +kubectl port-forward -n egov $(kgpt egov-user) 8085:8080 +kubectl port-forward -n egov $(kgpt egov-idgen) 8086:8080 +kubectl port-forward -n egov $(kgpt egov-mdms-service) 8087:8080 +kubectl port-forward -n egov $(kgpt egov-workflow) 8088:8080 +kubectl port-forward -n works $(kgpt project-management-service) 8089:8080 +``` + +Update below listed properties in `application.properties` before running the project: + +```ini +egov.idgen.hostname = http://127.0.0.1:8086 + +# can use non port forwarded environment host as well +egov.mdms.host = http://127.0.0.1:8087 +egov.workflow.host = http://127.0.0.1:8088 +``` diff --git a/health-services/attendance/README.md b/health-services/attendance/README.md new file mode 100644 index 00000000000..c8866f16367 --- /dev/null +++ b/health-services/attendance/README.md @@ -0,0 +1,29 @@ +# Attendance Service + +The attendance service provides generic attendance logging functionality based on "in" and "out" timestamps. +IN and OUT timestamps are recorded per individual. Aggregating and calculating attendance based on these timestamps +is the function of the muster roll service. + + +### Service Dependencies + +- DIGIT backbone services +- Individual +- MDMS +- ID-GEN +- Persister +- Indexer + +## Service Details + +- Allows creation/updation/search of an attendance register +- Allows mapping of staff and attendees to a register and enforces permissions. +- Logs entry and exit timestamps in epoch time for a referenced entity + +### API Specs + +https://raw.githubusercontent.com/egovernments/DIGIT-Specs/master/Domain%20Services/Works/Attendance-Service-v1.0.0.yaml + +### Postman Collection + +https://raw.githubusercontent.com/egovernments/DIGIT-Works/master/backend/attendance/Attendace%20Service%20Postman%20Scripts.postman_collection.json \ No newline at end of file diff --git a/health-services/attendance/pom.xml b/health-services/attendance/pom.xml new file mode 100644 index 00000000000..7f37268b040 --- /dev/null +++ b/health-services/attendance/pom.xml @@ -0,0 +1,141 @@ + + 4.0.0 + org.egov + attendance + jar + attendance + 0.2.0 + + 1.8 + ${java.version} + ${java.version} + 42.4.1 + 2.17.1 + + + org.springframework.boot + spring-boot-starter-parent + 2.2.13.RELEASE + + + src/main/java + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-jdbc + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-test + test + + + + io.swagger + swagger-core + 1.5.18 + + + + org.egov.services + tracer + 2.0.0-SNAPSHOT + + + org.egov.services + services-common + 1.1.1-SNAPSHOT + + + org.egov.services + digit-models + 1.0.0-SNAPSHOT + + + org.egov.common + health-services-models + 1.0.6-SNAPSHOT + compile + + + org.egov + mdms-client + 0.0.4-SNAPSHOT + + + org.postgresql + postgresql + + + org.jsoup + jsoup + 1.15.3 + + + org.flywaydb + flyway-core + + + + org.projectlombok + lombok + true + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + + javax.validation + validation-api + + + org.egov.common + health-services-common + 1.0.15-SNAPSHOT + compile + + + + + repo.digit.org.snapshots + eGov ERP SNAPSHOT Repository + https://nexus-repo.digit.org/nexus/content/repositories/snapshots/ + + + repo.digit.org + eGov ERP Releases Repository + https://nexus-repo.digit.org/nexus/content/repositories/releases/ + + + repo.digit.org.public + eGov Public Repository Group + https://nexus-repo.digit.org/nexus/content/groups/public/ + + + diff --git a/health-services/attendance/postman-test-suite-Attendace-service.json b/health-services/attendance/postman-test-suite-Attendace-service.json new file mode 100644 index 00000000000..d64786c344c --- /dev/null +++ b/health-services/attendance/postman-test-suite-Attendace-service.json @@ -0,0 +1,3796 @@ +{ + "info": { + "_postman_id": "25632b98-5918-4908-8a85-9500d8a81afa", + "name": "Attendace Service Postman Scripts", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "Attendance Register", + "item": [ + { + "name": "Create Attendance Register - Success - Single Register", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendance Registers are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendanceRegister).to.not.be.undefined;", + " pm.expect(req.attendanceRegister).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.tenantId).to.be.not.null;", + " pm.expect(register.tenantId).to.be.not.undefined;", + " pm.expect(register.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Register Name is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.name).to.be.not.null;", + " pm.expect(register.name).to.be.not.undefined;", + " pm.expect(register.name).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Register start date is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.startDate).to.be.not.null;", + " pm.expect(register.startDate).to.be.not.undefined;", + " pm.expect(register.startDate).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Start date should be less than end date\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " if (Number.isFinite(register.endDate) && (register.endDate != undefined || register.endDate != null )) {", + " pm.expect(register.endDate).to.be.not.below(register.startDate);", + " }", + " }", + ");", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Register Number is enriched\", function () {", + " var res = pm.response.json();", + " var registerNumber = res.attendanceRegister[0].registerNumber;", + " pm.expect(registerNumber.substring(0,2)).to.eql(\"WR\");", + " }", + ");", + "", + "pm.test(\"Register status is set to Active if status not passed\", function () {", + " var res = pm.response.json();", + " var status = res.attendanceRegister[0].status;", + " pm.expect(status).to.eql(\"ACTIVE\");", + " }", + ");", + "", + "pm.test(\"Staff is created for register\", function () {", + " var res = pm.response.json();", + " var staff = res.attendanceRegister[0].staff;", + " pm.expect(staff).to.be.not.null;", + " pm.expect(staff).to.be.not.undefined;", + " pm.expect(staff.length).to.eql(1);", + " }", + ");", + "", + "pm.test(\"Staff created have same userId as UUID of user\", function () {", + " var res = pm.response.json();", + " var userInRequest = res.attendanceRegister[0].auditDetails.createdBy;", + " var staff = res.attendanceRegister[0].staff;", + " pm.expect(staff[0].userId).to.eql(userInRequest);", + " }", + ");", + "", + "let responseData = pm.response.json();", + "pm.collectionVariables.set(\"tenantId\", responseData.attendanceRegister[0].tenantId);", + "pm.collectionVariables.set(\"stateLevelTenant\", responseData.attendanceRegister[0].tenantId.split('.', 1)[0]);", + "pm.collectionVariables.set(\"registerId\", responseData.attendanceRegister[0].id);", + "pm.collectionVariables.set(\"registerNumber\", responseData.attendanceRegister[0].registerNumber);", + "", + "pm.collectionVariables.set(\"registerStartDate\", responseData.attendanceRegister[0].startDate);", + "pm.collectionVariables.set(\"registerEndDate\", responseData.attendanceRegister[0].endDate);", + "pm.collectionVariables.set(\"invalidRegisterEndDate\", responseData.attendanceRegister[0].endDate+24*60*60*1000);" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.collectionVariables.set(\"tenantId\", \"pb.amritsar\");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_01\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Success - Multiple Registers", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"UserInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo.userInfo).to.not.be.null;", + " pm.expect(req.RequestInfo.userInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"UUID is required in UserInfo\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo.userInfo.uuid).to.not.be.null;", + " pm.expect(req.RequestInfo.userInfo.uuid).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendance Registers are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendanceRegister).to.not.be.undefined;", + " pm.expect(req.attendanceRegister).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.tenantId).to.be.not.null;", + " pm.expect(register.tenantId).to.be.not.undefined;", + " pm.expect(register.tenantId).not.to.eql(\"\");", + " });", + " }", + ");", + "", + "pm.test(\"Register Name is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.name).to.be.not.null;", + " pm.expect(register.name).to.be.not.undefined;", + " pm.expect(register.name).not.to.eql(\"\");", + " });", + " }", + ");", + "", + "pm.test(\"Register start date is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.startDate).to.be.not.null;", + " pm.expect(register.startDate).to.be.not.undefined;", + " pm.expect(register.startDate).not.to.eql(\"\");", + " });", + " }", + ");", + " ", + "", + "pm.test(\"Start date should be less than end date\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " if (Number.isFinite(register.endDate) && (register.endDate != undefined || register.endDate != null )) {", + " pm.expect(register.endDate).to.be.not.below(register.startDate);", + " }", + " });", + " }", + ");", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Register Number is enriched\", function () {", + " var res = pm.response.json();", + " res.attendanceRegister.forEach(register => {", + " var registerNumber = register.registerNumber;", + " pm.expect(registerNumber.substring(0,2)).to.eql(\"WR\");", + " });", + " }", + ");", + "", + "pm.test(\"Staff is created for register\", function () {", + " var res = pm.response.json();", + " res.attendanceRegister.forEach(register => {", + " var staff = register.staff;", + " pm.expect(staff).to.be.not.null;", + " pm.expect(staff).to.be.not.undefined;", + " pm.expect(staff.length).to.eql(1);", + " }); ", + " }", + ");", + "", + "pm.test(\"Staff created have same userId as UUID of user\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var res = pm.response.json();", + " res.attendanceRegister.forEach(register => {", + " var userInRequest = register.auditDetails.createdBy;", + " var staff =register.staff;", + " pm.expect(staff[0].userId).to.eql(userInRequest);", + " }); ", + " }", + ");", + "", + "let responseData = pm.response.json();", + "pm.collectionVariables.set(\"registerId2\", responseData.attendanceRegister[1].id);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_01\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000\n },\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_02\",\n \"startDate\": 1640995200000,\n \"additionalDetails\": {}\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Validation Error - Registers not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"ATTENDANCE_REGISTER\");", + " pm.expect(message).to.eql(\"Attendance Register is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": []\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Validation Error - TenantId not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"TENANT_ID\");", + " pm.expect(message).to.eql(\"Tenant is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"name\": \"TestRegister_01\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Validation Error - Name not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"NAME\");", + " pm.expect(message).to.eql(\"Name is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Validation Error - Start Date not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"START_DATE\");", + " pm.expect(message).to.eql(\"Start date is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_01\",\n \"endDate\": 1703980800000\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Validation Error - Start Date greater than End Date", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"DATE\");", + " pm.expect(message).to.eql(\"Start date should be less than end date\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_01\",\n \"startDate\": 1803980800000,\n \"endDate\": 1703980800000\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Validation Error - Start Date Equal to 0", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"START_DATE\");", + " pm.expect(message).to.eql(\"Start date is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_01\",\n \"startDate\": 0,\n \"endDate\": 1703980800000\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Success", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200)));", + "", + "pm.test(\"Register Search response is received\", function () {", + " var res = pm.response.json();", + " var id = res.attendanceRegister[0].id;", + " pm.expect(id).to.eql(pm.collectionVariables.get(\"registerId\"));", + " }", + ");" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"{{token}}\"\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?tenantId={{tenantId}}&ids={{registerId}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + }, + { + "key": "ids", + "value": "{{registerId}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Success - State level tenant", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200)));", + "", + "pm.test(\"Register Search response is received\", function () {", + " var res = pm.response.json();", + " var id = res.attendanceRegister[0].id;", + " pm.expect(id).to.eql(pm.collectionVariables.get(\"registerId\"));", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"{{token}}\"\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?tenantId={{stateLevelTenant}}&ids={{registerId}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{stateLevelTenant}}" + }, + { + "key": "ids", + "value": "{{registerId}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Success - Unassociated AttendeeId", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200)));", + "", + "pm.test(\"Register Search response is received\", function () {", + " var res = pm.response.json();", + " pm.expect(res.attendanceRegister.length).to.equal(0);", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"\",\n \"userInfo\": {\n \"id\": 1,\n \"uuid\": \"11b0e02b-0145-4de2-bc42-c97b96264807\",\n \"userName\": \"\",\n \"name\": \"\",\n \"mobileNumber\": \"\",\n \"emailId\": \"\",\n \"type\": \"\",\n \"roles\": [\n {\n \"code\": \"ORG_ADMIN\",\n \"name\": \"Organization admin\",\n \"tenantId\": \"pb.amritsar\"\n },\n {\n \"code\": \"ORG_STAFF\",\n \"name\": \"Organization staff\",\n \"tenantId\": \"pb.amritsar\"\n }\n ],\n \"active\": true,\n \"tenantId\": \"pb.amritsar\"\n }\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?tenantId={{tenantId}}&ids={{registerId}}&attendeeId={{$guid}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + }, + { + "key": "ids", + "value": "{{registerId}}" + }, + { + "key": "attendeeId", + "value": "{{$guid}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Success - Unassociated StaffId", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200)));", + "", + "pm.test(\"Register Search response is received\", function () {", + " var res = pm.response.json();", + " pm.expect(res.attendanceRegister.length).to.equal(0);", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"\",\n \"userInfo\": {\n \"id\": 1,\n \"uuid\": \"11b0e02b-0145-4de2-bc42-c97b96264807\",\n \"userName\": \"\",\n \"name\": \"\",\n \"mobileNumber\": \"\",\n \"emailId\": \"\",\n \"type\": \"\",\n \"roles\": [\n {\n \"code\": \"ORG_ADMIN\",\n \"name\": \"Organization admin\",\n \"tenantId\": \"pb.amritsar\"\n },\n {\n \"code\": \"ORG_STAFF\",\n \"name\": \"Organization staff\",\n \"tenantId\": \"pb.amritsar\"\n }\n ],\n \"active\": true,\n \"tenantId\": \"pb.amritsar\"\n }\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?tenantId={{tenantId}}&ids={{registerId}}&staffId={{$guid}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + }, + { + "key": "ids", + "value": "{{registerId}}" + }, + { + "key": "staffId", + "value": "{{$guid}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Success - User not associated with any register - empty response array", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200)));", + "", + "pm.test(\"User not associated with any register\", function () {", + " var res = pm.response.json();", + " pm.expect(res.attendanceRegister.length).to.equal(0);", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"\",\n \"userInfo\": {\n \"id\": 1,\n \"uuid\": \"{{$guid}}\",\n \"userName\": \"\",\n \"name\": \"\",\n \"mobileNumber\": \"\",\n \"emailId\": \"\",\n \"type\": \"\",\n \"roles\": [\n {\n \"code\": \"ORG_ADMIN\",\n \"name\": \"Organization admin\",\n \"tenantId\": \"pb.amritsar\"\n },\n {\n \"code\": \"ORG_STAFF\",\n \"name\": \"Organization staff\",\n \"tenantId\": \"pb.amritsar\"\n }\n ],\n \"active\": true,\n \"tenantId\": \"pb.amritsar\"\n }\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?tenantId={{tenantId}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Success - SuperUser - Non existing RegisterID", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200)));", + "", + "pm.test(\"Register Search response is received\", function () {", + " var res = pm.response.json();", + " pm.expect(res.attendanceRegister.length).to.equal(0);", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"\",\n \"userInfo\": {\n \"id\": 1,\n \"uuid\": \"11b0e02b-0145-4de2-bc42-c97b96264807\",\n \"userName\": \"\",\n \"name\": \"\",\n \"mobileNumber\": \"\",\n \"emailId\": \"\",\n \"type\": \"\",\n \"roles\": [\n {\n \"code\": \"SUPERUSER\",\n \"name\": \"Super User\",\n \"tenantId\": \"pb.amritsar\"\n }\n ],\n \"active\": true,\n \"tenantId\": \"pb.amritsar\"\n }\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?tenantId={{tenantId}}&ids={{$guid}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + }, + { + "key": "ids", + "value": "{{$guid}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Validation Error - Unassociated Register Id", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Register Search response is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"INVALID_REGISTER_ID\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"\",\n \"userInfo\": {\n \"id\": 1,\n \"uuid\": \"11b0e02b-0145-4de2-bc42-c97b96264807\",\n \"userName\": \"\",\n \"name\": \"\",\n \"mobileNumber\": \"\",\n \"emailId\": \"\",\n \"type\": \"\",\n \"roles\": [\n {\n \"code\": \"ORG_ADMIN\",\n \"name\": \"Organization admin\",\n \"tenantId\": \"pb.amritsar\"\n },\n {\n \"code\": \"ORG_STAFF\",\n \"name\": \"Organization staff\",\n \"tenantId\": \"pb.amritsar\"\n }\n ],\n \"active\": true,\n \"tenantId\": \"pb.amritsar\"\n }\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?tenantId={{tenantId}}&ids={{$guid}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + }, + { + "key": "ids", + "value": "{{$guid}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Validation Error - Tenant Id not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"TENANT_ID\");", + " pm.expect(message).to.eql(\"Tenant is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"{{token}}\"\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?ids={{registerId}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "ids", + "value": "{{registerId}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Update Attendance Register - Success - Single Register", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"UserInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo.userInfo).to.not.be.null;", + " pm.expect(req.RequestInfo.userInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"UUID is required in UserInfo\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo.userInfo.uuid).to.not.be.null;", + " pm.expect(req.RequestInfo.userInfo.uuid).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendance Registers are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendanceRegister).to.not.be.undefined;", + " pm.expect(req.attendanceRegister).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.tenantId).to.be.not.null;", + " pm.expect(register.tenantId).to.be.not.undefined;", + " pm.expect(register.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Register Id is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.id).to.be.not.null;", + " pm.expect(register.id).to.be.not.undefined;", + " pm.expect(register.id).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Register Name is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.name).to.be.not.null;", + " pm.expect(register.name).to.be.not.undefined;", + " pm.expect(register.name).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Register start date is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.startDate).to.be.not.null;", + " pm.expect(register.startDate).to.be.not.undefined;", + " pm.expect(register.startDate).not.to.eql(\"\");", + " }", + ");", + " ", + "", + "pm.test(\"Start date should be less than end date\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " if (Number.isFinite(register.endDate) && (register.endDate != undefined || register.endDate != null )) {", + " pm.expect(register.endDate).to.be.not.below(register.startDate);", + " }", + " }", + ");", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Staff is created for register\", function () {", + " var res = pm.response.json();", + " var staff = res.attendanceRegister[0].staff;", + " pm.expect(staff).to.be.not.null;", + " pm.expect(staff).to.be.not.undefined;", + " pm.expect(staff.length).to.eql(1);", + " }", + ");", + "", + "pm.test(\"Staff created have same userId as UUID of user\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var userInRequest = req.RequestInfo.userInfo.uuid;", + " var res = pm.response.json();", + " var staff = res.attendanceRegister[0].staff;", + " pm.expect(staff[0].userId).to.eql(userInRequest);", + " }", + ");", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"id\": \"{{registerId}}\",\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_010\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000,\n \"status\": \"ACTIVE\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Update Attendance Register - Success - Multiple Registers", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"UserInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo.userInfo).to.not.be.null;", + " pm.expect(req.RequestInfo.userInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"UUID is required in UserInfo\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo.userInfo.uuid).to.not.be.null;", + " pm.expect(req.RequestInfo.userInfo.uuid).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendance Registers are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendanceRegister).to.not.be.undefined;", + " pm.expect(req.attendanceRegister).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.tenantId).to.be.not.null;", + " pm.expect(register.tenantId).to.be.not.undefined;", + " pm.expect(register.tenantId).not.to.eql(\"\");", + " });", + " }", + ");", + "", + "pm.test(\"Register Id is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.id).to.be.not.null;", + " pm.expect(register.id).to.be.not.undefined;", + " pm.expect(register.id).not.to.eql(\"\");", + " });", + " }", + ");", + "", + "pm.test(\"Register Name is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.name).to.be.not.null;", + " pm.expect(register.name).to.be.not.undefined;", + " pm.expect(register.name).not.to.eql(\"\");", + " });", + " }", + ");", + "", + "pm.test(\"Register start date is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.startDate).to.be.not.null;", + " pm.expect(register.startDate).to.be.not.undefined;", + " pm.expect(register.startDate).not.to.eql(\"\");", + " });", + " }", + ");", + " ", + "", + "pm.test(\"Start date should be less than end date\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " if (Number.isFinite(register.endDate) && (register.endDate != undefined || register.endDate != null )) {", + " pm.expect(register.endDate).to.be.not.below(register.startDate);", + " }", + " });", + " }", + ");", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Staff is created for register\", function () {", + " var res = pm.response.json();", + " res.attendanceRegister.forEach(register => {", + " var staff = register.staff;", + " pm.expect(staff).to.be.not.null;", + " pm.expect(staff).to.be.not.undefined;", + " pm.expect(staff.length).to.eql(1);", + " }); ", + " }", + ");", + "", + "pm.test(\"Staff created have same userId as UUID of user\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var userInRequest = req.RequestInfo.userInfo.uuid;", + " var res = pm.response.json();", + " res.attendanceRegister.forEach(register => {", + " var staff =register.staff;", + " pm.expect(staff[0].userId).to.eql(userInRequest);", + " }); ", + " }", + ");", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"id\": \"{{registerId}}\",\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_010\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000,\n \"status\": \"ACTIVE\"\n },\n {\n \"id\": \"{{registerId2}}\",\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_020\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000,\n \"status\": \"INACTIVE\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Update Attendance Register - Validation Error - Register Id not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"ATTENDANCE_REGISTER_ID\");", + " pm.expect(message).to.eql(\"Attendance register id is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_010\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000,\n \"status\": \"ACTIVE\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Update Attendance Register - Validation Error - Tenant Id not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"TENANT_ID\");", + " pm.expect(message).to.eql(\"Tenant is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"id\": \"{{registerId}}\",\n \"name\": \"TestRegister_010\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000,\n \"status\": \"ACTIVE\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Update Attendance Register - Validation Error - Name not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"NAME\");", + " pm.expect(message).to.eql(\"Name is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"id\": \"{{registerId}}\",\n \"tenantId\": \"{{tenantId}}\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000,\n \"status\": \"ACTIVE\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Update Attendance Register - Validation Error - Start Date not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"START_DATE\");", + " pm.expect(message).to.eql(\"Start date is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"id\": \"{{registerId}}\",\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_010\",\n \"endDate\": 1703980800000,\n \"status\": \"ACTIVE\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_update" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Register Permission", + "item": [ + { + "name": "Staff - Enroll - Single Staff", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Enrollment date is enriched\", function () {", + " var res = pm.response.json();", + " var enrollmentDate = res.staff[0].enrollmentDate;", + " pm.expect(enrollmentDate).to.be.not.null;", + " }", + ");", + "", + "// let requestData = JSON.parse(pm.request.body.raw);", + "// pm.collectionVariables.set(\"userId\", requestData.staff[0].userId);", + "", + "let responseData = pm.response.json();", + "pm.collectionVariables.set(\"userId\", responseData.staff[0].userId);", + "console.log(pm.collectionVariables.get(\"userId\"));", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Enroll the user to register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{$randomUUID}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Enroll - Validation Error - Staff already enrolled to the register", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"response is 400. Staff is already enrolled to the register\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "console.log(pm.collectionVariables.get(\"userId\"))" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Enroll the user to register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Enroll - Validation Error - Duplicate staff objects not allowed in enrollment request", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + "", + " req.staff.forEach(staff => {", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }); ", + "", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "", + "pm.test(\"Response is 400. Duplicate objects in request\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Enroll the user to register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"928ca23a-9bec-11ed-a8fc-0242ac120002\",\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"928ca23a-9bec-11ed-a8fc-0242ac120002\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Enroll - Multiple staff", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + "", + " req.staff.forEach(staff => {", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }); ", + "", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Enrollment date is enriched\", function () {", + " var res = pm.response.json();", + " res.staff.forEach(staff => {", + " pm.expect(staff.enrollmentDate).to.be.not.null;", + " }); ", + " }", + ");", + "", + "let requestData = JSON.parse(pm.request.body.raw);", + "pm.collectionVariables.set(\"userId-1\", requestData.staff[0].userId);", + "pm.collectionVariables.set(\"userId-2\", requestData.staff[1].userId);", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Enroll the user to register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{$randomUUID}}\",\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{$randomUUID}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Deenroll - Single staff", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Deenrollment date is enriched\", function () {", + " var res = pm.response.json();", + " var deenrollmentDate = res.staff[0].deenrollmentDate;", + " pm.expect(deenrollmentDate).to.be.not.null;", + " }", + ");", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Deenroll staff from register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_delete" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Deenroll - Validation Error - Staff already denrolled from the register", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is 400. Staff already deenrolled from the register\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Deenroll staff from register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_delete" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Deenroll - Validation Error - Duplicate staff objects in deenrollment request", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + "", + " req.staff.forEach(staff => {", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }); ", + "", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Response is 400. Duplicate staff objects in de enrollment request\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Deenroll staff from register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId-1}}\",\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId-1}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_delete" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Deenroll - Multiple staff", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + "", + " req.staff.forEach(staff => {", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }); ", + "", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Deenrollment date is enriched\", function () {", + " var res = pm.response.json();", + " res.staff.forEach(staff => {", + " pm.expect(staff.deenrollmentDate).to.be.not.null;", + " }); ", + " }", + ");", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Deenroll staff from register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId-1}}\",\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId-2}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_delete" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Individual Enrollment", + "item": [ + { + "name": "Attendee - Enroll - Attendee", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendee are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Enrollment date is enriched\", function () {", + " var res = pm.response.json();", + " var enrollmentDate = res.attendees[0].enrollmentDate;", + " pm.expect(enrollmentDate).to.be.not.null;", + " }", + ");", + "", + "// let requestData = JSON.parse(pm.request.body.raw);", + "// pm.collectionVariables.set(\"individualId\", requestData.attendees[0].individualId);", + "let responseData = pm.response.json();", + "pm.collectionVariables.set(\"individualId\", responseData.attendees[0].individualId);", + "pm.collectionVariables.set(\"attendeeEnrollmentDate\", responseData.attendees[0].enrollmentDate);", + "", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Enroll attendee to register\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{$randomUUID}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n } \n\n ]\n\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Enroll - Validation Error - Attendee already enrolled", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendee are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is 400. Attendee already enrolled to the register\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Enroll attendee to register\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n } \n\n ]\n\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Enroll - Validation Error - Duplicate attendee objects not allowed in request", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendee are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "", + "pm.test(\"Response is 400. Duplicate attendee objects in the request\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Enroll attendee to register\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"928ca23a-9bec-11ed-a8fc-0242ac120002\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"928ca23a-9bec-11ed-a8fc-0242ac120002\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n } \n\n ]\n\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Enroll - Multiple Attendees", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendee are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Enrollment date is enriched\", function () {", + " var res = pm.response.json();", + " res.attendees.forEach(attendee => {", + " pm.expect(attendee.enrollmentDate).to.be.not.null;", + " }); ", + " }", + ");", + "", + "let requestData = JSON.parse(pm.request.body.raw);", + "pm.collectionVariables.set(\"individualId-1\", requestData.attendees[0].individualId);", + "pm.collectionVariables.set(\"individualId-2\", requestData.attendees[1].individualId);", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Enroll attendee to register\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{$randomUUID}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{$randomUUID}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n } \n\n ]\n\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Deenroll- Single Attendee", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendees are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Deenrollment date is enriched\", function () {", + " var res = pm.response.json();", + " var deenrollmentDate = res.attendees[0].deenrollmentDate;", + " pm.expect(deenrollmentDate).to.be.not.null;", + " }", + ");", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"search with from and to values\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_delete" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Deenroll- Validation Error - Attendee already deenrolled from the register", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendees are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is 400. Attendee already deenrolled from the register\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"search with from and to values\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_delete" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Deenroll- Validation Error - Duplicate attendee objects in deenrollment request", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendees are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "", + "pm.test(\"Response is 400. Duplicate attendee objects in deenrollment request.\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"search with from and to values\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId-1}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId-1}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_delete" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Deenroll- Multiple Attendees", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendees are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Deenrollment date is enriched\", function () {", + " var res = pm.response.json();", + " res.attendees.forEach(attendee => {", + " pm.expect(attendee.denrollmentDate).to.be.not.null;", + " }); ", + " }", + ");", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"search with from and to values\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId-1}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId-2}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_delete" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Attendance Log", + "item": [ + { + "name": "Attendance Log - Create - Success", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + " setTimeout( () => {", + "", + " pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var id = res.attendance[0].id;", + " pm.expect(id).to.be.not.null;", + " }", + ");", + " ", + " }, 1000);", + "", + "", + "", + "let responseData = pm.response.json();", + "pm.collectionVariables.set(\"attendanceLogId\", responseData.attendance[0].id);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Update - Success", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Attendance Log updated successfully\", function () {", + " var res = pm.response.json();", + " var status = res.attendance[0].status;", + " pm.expect(status).to.eql(\"INACTIVE\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"id\": \"{{attendanceLogId}}\",\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"INACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ],\r\n \"auditDetails\": {\r\n \"createdBy\": \"47b5ea82-249c-4435-9646-16167fec06df\",\r\n \"lastModifiedBy\": \"47b5ea82-249c-4435-9646-16167fec06df\",\r\n \"createdTime\": 1671090269007,\r\n \"lastModifiedTime\": 1671090269007\r\n }\r\n \r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Update - fail - attendanceId is not valid", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log updated successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"ATTENDANCE_LOG\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"id\": \"{{$randomUUID}}\",\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"INACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ],\r\n \"auditDetails\": {\r\n \"createdBy\": \"47b5ea82-249c-4435-9646-16167fec06df\",\r\n \"lastModifiedBy\": \"47b5ea82-249c-4435-9646-16167fec06df\",\r\n \"createdTime\": 1671090269007,\r\n \"lastModifiedTime\": 1671090269007\r\n }\r\n \r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Create - Fail - All logs should belong to same tenantId", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"MULTIPLE_TENANTIDS\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n },\r\n {\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"tenant.id\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Create - Fail - Validate Attendance Log time", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"INVALID_ATTENDANCE_TIME\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{invalidRegisterEndDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Create - Fail - Register should belongs to tenenatId", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"INVALID_TENANTID\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"tenant.Id\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Create - Fail - All logs should belong to same registerId", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"MULTIPLE_REGISTERIDS\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n },\r\n {\r\n \"registerId\": \"{{$randomUUID}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Create - Fail - User is not authorised", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"UNAUTHORISED_USER\");", + " }", + ");" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": \"{{$randomUUID}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Rearch - Fail - TenantId is required", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"TENANT_ID\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n }\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_search", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_search" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Rearch - Fail - RegisterId is required", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"REGISTER_ID\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n }\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_search?tenantId={{tenantId}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Rearch - Success", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " pm.expect(res.attendance).to.be.not.null;", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n }\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_search?tenantId={{tenantId}}®isterId={{registerId}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + }, + { + "key": "registerId", + "value": "{{registerId}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Create - Fail - required fields are missing", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Register Search response is received\", function () {", + " var res = pm.response.json();", + " pm.expect(res.Errors.length).to.equal(5);", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": null,\r\n \"individualId\": null,\r\n \"time\": null,\r\n \"type\": null,\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": null,\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + } + ] + } + ], + "event": [ + { + "listen": "prerequest", + "script": { + "type": "text/javascript", + "exec": [ + "if (pm.environment.get(\"base_url\").includes(\"localhost\")) {", + "", + " var tenantId = \"pb.amritsar\";", + " var id = 1;", + " var uuid = \"11b0e02b-0145-4de2-bc42-c97b96264807\";", + "", + " var roles = [{", + " \"code\": \"SUPERUSER\",", + " \"name\": \"SUPER USER\",", + " \"tenantId\": tenantId", + " }];", + "", + " var userInfo = {", + " \"id\": id,", + " \"uuid\": uuid,", + " \"userName\": \"\",", + " \"name\": \"\",", + " \"mobileNumber\": \"\",", + " \"emailId\": \"\",", + " \"type\": \"\",", + " \"roles\": roles,", + " \"active\": true,", + " \"tenantId\": \"pb.amritsar\"", + " };", + "", + " pm.request.body.raw = pm.request.body.raw.replace('\"{{token}}\"', '\"\", \\n \"userInfo\": ' + JSON.stringify(userInfo));", + "}" + ] + } + }, + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ], + "variable": [ + { + "key": "tenantId", + "value": "" + }, + { + "key": "stateLevelTenant", + "value": "" + }, + { + "key": "registerId", + "value": "" + }, + { + "key": "registerNumber", + "value": "" + }, + { + "key": "registerId2", + "value": "" + }, + { + "key": "registerStartDate", + "value": "" + }, + { + "key": "registerEndDate", + "value": "" + }, + { + "key": "invalidRegisterEndDate", + "value": "" + }, + { + "key": "userId", + "value": "" + }, + { + "key": "userId-1", + "value": "" + }, + { + "key": "userId-2", + "value": "" + }, + { + "key": "individualId", + "value": "" + }, + { + "key": "attendeeEnrollmentDate", + "value": "" + }, + { + "key": "individualId-1", + "value": "" + }, + { + "key": "individualId-2", + "value": "" + }, + { + "key": "attendanceLogId", + "value": "" + } + ] +} \ No newline at end of file diff --git a/health-services/attendance/src/main/java/org/egov/Main.java b/health-services/attendance/src/main/java/org/egov/Main.java new file mode 100644 index 00000000000..efe5addd85e --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/Main.java @@ -0,0 +1,15 @@ +package org.egov; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +@SpringBootApplication +@ComponentScan(basePackages = {"org.egov", "org.egov.web.controllers", "org.egov.config"}) +public class Main { + + public static void main(String[] args) throws Exception { + SpringApplication.run(Main.class, args); + } + +} diff --git a/health-services/attendance/src/main/java/org/egov/config/AttendanceLogConfiguration.java b/health-services/attendance/src/main/java/org/egov/config/AttendanceLogConfiguration.java new file mode 100644 index 00000000000..5c392dec8fe --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/config/AttendanceLogConfiguration.java @@ -0,0 +1,28 @@ +package org.egov.config; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.egov.tracer.config.TracerConfiguration; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Import; +import org.springframework.stereotype.Component; + +@Import({TracerConfiguration.class}) +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +@Component +public class AttendanceLogConfiguration { + + @Value("${attendance.log.kafka.consumer.bulk.create.topic}") + private String createAttendanceLogBulkTopic; + + @Value("${attendance.log.kafka.consumer.bulk.update.topic}") + private String updateAttendanceLogBulkTopic; + +} diff --git a/health-services/attendance/src/main/java/org/egov/config/AttendanceServiceConfiguration.java b/health-services/attendance/src/main/java/org/egov/config/AttendanceServiceConfiguration.java new file mode 100644 index 00000000000..ede3010f452 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/config/AttendanceServiceConfiguration.java @@ -0,0 +1,107 @@ +package org.egov.config; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.egov.tracer.config.TracerConfiguration; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Import; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.TimeZone; + +@Component +@Data +@Import({TracerConfiguration.class}) +@NoArgsConstructor +@AllArgsConstructor +public class AttendanceServiceConfiguration { + + @Value("${app.timezone}") + private String timeZone; + //Idgen Config + @Value("${egov.idgen.host}") + private String idGenHost; + @Value("${egov.idgen.path}") + private String idGenPath; + @Value("${egov.idgen.attendance.register.number.name}") + private String idgenAttendanceRegisterNumberName; + //MDMS + @Value("${egov.mdms.host}") + private String mdmsHost; + @Value("${egov.mdms.search.endpoint}") + private String mdmsEndPoint; + //Topic + @Value("${attendance.register.kafka.create.topic}") + private String saveAttendanceRegisterTopic; + @Value("${attendance.register.kafka.update.topic}") + private String updateAttendanceRegisterTopic; + + //Topic + @Value("${attendance.staff.kafka.create.topic}") + private String saveStaffTopic; + @Value("${attendance.staff.kafka.update.topic}") + private String updateStaffTopic; + + //Topic + @Value("${attendance.attendee.kafka.create.topic}") + private String saveAttendeeTopic; + @Value("${attendance.attendee.kafka.update.topic}") + private String updateAttendeeTopic; + + @PostConstruct + public void initialize() { + TimeZone.setDefault(TimeZone.getTimeZone(timeZone)); + } + + // kafka topics + @Value("${attendance.log.kafka.create.topic}") + private String createAttendanceLogTopic; + + @Value("${attendance.log.kafka.update.topic}") + private String updateAttendanceLogTopic; + + // service integration config + @Value("${attendance.individual.service.integration.required}") + private String individualServiceIntegrationRequired; + + @Value("${attendance.staff.service.integration.required}") + private String staffServiceIntegrationRequired; + + @Value("${attendance.document.id.verification.required}") + private String documentIdVerificationRequired; + + //attendance service log search config + + //@Value("${attendance.service.log.default.offset}") + //private Integer attendanceLogDefaultOffset; + + //@Value("${attendance.service.log.default.limit}") + //private Integer attendanceLogDefaultLimit; + + //@Value("${attendance.service.log.search.max.limit}") + //private Integer attendanceLogMaxLimit; + + //attendance service register search config + @Value("${attendance.register.default.offset}") + private Integer attendanceRegisterDefaultOffset; + + @Value("${attendance.register.default.limit}") + private Integer attendanceRegisterDefaultLimit; + + @Value("${attendance.register.search.max.limit}") + private Integer attendanceRegisterMaxLimit; + + @Value("${attendance.register.open.search.enabled.roles}") + private String registerOpenSearchEnabledRoles; + + //Individual servcie + @Value("${works.individual.host}") + private String individualHost; + @Value("${works.individual.search.endpoint}") + private String individualSearchEndpoint; + +} + + diff --git a/health-services/attendance/src/main/java/org/egov/config/MainConfiguration.java b/health-services/attendance/src/main/java/org/egov/config/MainConfiguration.java new file mode 100644 index 00000000000..9e1c5cb6380 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/config/MainConfiguration.java @@ -0,0 +1,93 @@ +package org.egov.config; + +import java.util.TimeZone; +import javax.annotation.PostConstruct; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import org.egov.tracer.config.TracerConfiguration; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.RedisStandaloneConfiguration; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; + + +@Import({TracerConfiguration.class}) +@Configuration +@ComponentScan(basePackages = {"org.egov"}) +public class MainConfiguration { + + @Value("${app.timezone}") + private String timeZone; + + @PostConstruct + public void initialize() { + TimeZone.setDefault(TimeZone.getTimeZone(timeZone)); + } + + @Value("${spring.redis.host}") + private String redisHost; + @Bean(name = "objectMapper") + public ObjectMapper objectMapper(){ + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).setTimeZone(TimeZone.getTimeZone(timeZone)); + objectMapper.registerModule(new JavaTimeModule()); + return objectMapper; + } + + @Bean + @Autowired + public MappingJackson2HttpMessageConverter jacksonConverter(ObjectMapper objectMapper) { + MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); + converter.setObjectMapper(objectMapper); + return converter; + } + @Bean + @Qualifier("redisObjectMapper") + public ObjectMapper redisObjectMapper() { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); + objectMapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, + ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.WRAPPER_ARRAY); + objectMapper.registerModule(new JavaTimeModule()); + return objectMapper; + } + + @Bean + public RedisConnectionFactory redisConnectionFactory() { + RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(); + redisStandaloneConfiguration.setHostName(redisHost); + return new JedisConnectionFactory(redisStandaloneConfiguration); + } + + + @Bean + public RedisTemplate redisTemplate(@Qualifier("redisObjectMapper") ObjectMapper redisObjectMapper, + RedisConnectionFactory redisConnectionFactory) { + Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer<>(Object.class); + serializer.setObjectMapper(redisObjectMapper); + RedisTemplate redisTemplate = new RedisTemplate<>(); + redisTemplate.setConnectionFactory(redisConnectionFactory); + redisTemplate.setKeySerializer(new StringRedisSerializer()); + redisTemplate.setValueSerializer(serializer); + redisTemplate.setHashKeySerializer(new StringRedisSerializer()); + redisTemplate.setHashValueSerializer(serializer); + redisTemplate.afterPropertiesSet(); + return redisTemplate; + } +} \ No newline at end of file diff --git a/health-services/attendance/src/main/java/org/egov/enrichment/AttendanceLogEnrichment.java b/health-services/attendance/src/main/java/org/egov/enrichment/AttendanceLogEnrichment.java new file mode 100644 index 00000000000..4495897ed64 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/enrichment/AttendanceLogEnrichment.java @@ -0,0 +1,80 @@ +package org.egov.enrichment; + +import digit.models.coremodels.AuditDetails; +import lombok.extern.slf4j.Slf4j; +import org.egov.common.contract.request.RequestInfo; +import org.egov.config.AttendanceServiceConfiguration; +import org.egov.util.AttendanceServiceUtil; +import org.egov.web.models.AttendanceLog; +import org.egov.web.models.AttendanceLogRequest; +import org.egov.web.models.AttendanceLogSearchCriteria; +import org.egov.web.models.Document; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +@Component +@Slf4j +public class AttendanceLogEnrichment { + @Autowired + private AttendanceServiceUtil attendanceServiceUtil; + @Autowired + private AttendanceServiceConfiguration config; + + public void enrichAttendanceLogCreateRequest(AttendanceLogRequest attendanceLogRequest) { + String registerId = attendanceLogRequest.getAttendance().get(0).getRegisterId(); + log.info("Enriching attendance log create request for register ["+registerId+"]"); + List attendanceLogs = attendanceLogRequest.getAttendance(); + String byUser = attendanceLogRequest.getRequestInfo().getUserInfo().getUuid(); + AuditDetails auditDetails = attendanceServiceUtil.getAuditDetails(byUser, null, true); + for (AttendanceLog attendanceLog : attendanceLogs) { + attendanceLog.setAuditDetails(auditDetails); + String attendanceLogId = String.valueOf(UUID.randomUUID()); + attendanceLog.setId(attendanceLogId); + List documentIds = attendanceLog.getDocumentIds(); + if(!CollectionUtils.isEmpty(documentIds)) { + for (Document documentId : documentIds) { + documentId.setId(String.valueOf(UUID.randomUUID())); + } + } + } + log.info("Enriched attendance log create request for register ["+registerId+"]"); + } + + public void enrichAttendanceLogUpdateRequest(AttendanceLogRequest attendanceLogRequest) { + String registerId = attendanceLogRequest.getAttendance().get(0).getRegisterId(); + log.info("Enriching attendance log update request for register ["+registerId+"]"); + List attendanceLogs = attendanceLogRequest.getAttendance(); + String byUser = attendanceLogRequest.getRequestInfo().getUserInfo().getUuid(); + for (AttendanceLog attendanceLog : attendanceLogs) { + AuditDetails auditDetails = attendanceServiceUtil.getAuditDetails(byUser, attendanceLog.getAuditDetails(), false); + attendanceLog.setAuditDetails(auditDetails); + // enrich the documentId if not present + List documentIds = attendanceLog.getDocumentIds(); + for (Document documentId : documentIds) { + if (documentId.getId() == null) { + documentId.setId(String.valueOf(UUID.randomUUID())); + } + } + } + + log.info("Enriched attendance log update request for register ["+registerId+"]"); + } + + public void enrichAttendanceLogSearchRequest(RequestInfo requestInfo, AttendanceLogSearchCriteria searchCriteria) { + +// if (searchCriteria.getLimit() == null) +// searchCriteria.setLimit(config.getAttendanceLogDefaultLimit()); +// +// if (searchCriteria.getOffset() == null) +// searchCriteria.setOffset(config.getAttendanceLogDefaultOffset()); +// +// if (searchCriteria.getLimit() != null && searchCriteria.getLimit() > config.getAttendanceLogMaxLimit()) +// searchCriteria.setLimit(config.getAttendanceLogMaxLimit()); + + } +} diff --git a/health-services/attendance/src/main/java/org/egov/enrichment/AttendeeEnrichmentService.java b/health-services/attendance/src/main/java/org/egov/enrichment/AttendeeEnrichmentService.java new file mode 100644 index 00000000000..6a7547020ab --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/enrichment/AttendeeEnrichmentService.java @@ -0,0 +1,65 @@ +package org.egov.enrichment; + +import digit.models.coremodels.AuditDetails; +import org.egov.common.contract.request.RequestInfo; +import org.egov.util.AttendanceServiceUtil; +import org.egov.web.models.AttendeeCreateRequest; +import org.egov.web.models.AttendeeDeleteRequest; +import org.egov.web.models.IndividualEntry; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.List; +import java.util.UUID; + +@Service +public class AttendeeEnrichmentService { + + @Autowired + private AttendanceServiceUtil attendanceServiceUtil; + + public void enrichAttendeeOnCreate(AttendeeCreateRequest attendeeCreateRequest) { + RequestInfo requestInfo = attendeeCreateRequest.getRequestInfo(); + List attendeeListFromRequest = attendeeCreateRequest.getAttendees(); + + for (IndividualEntry attendee : attendeeListFromRequest) { + AuditDetails auditDetails = attendanceServiceUtil.getAuditDetails(requestInfo.getUserInfo().getUuid(), attendee.getAuditDetails(), true); + attendee.setAuditDetails(auditDetails); + attendee.setId(UUID.randomUUID().toString()); + attendee.setDenrollmentDate(null); + if (attendee.getEnrollmentDate() == null) { + BigDecimal enrollmentDate = new BigDecimal(System.currentTimeMillis()); + attendee.setEnrollmentDate(enrollmentDate); + } + + } + } + + public void enrichAttendeeOnDelete(AttendeeDeleteRequest attendeeDeleteRequest, List attendeesFromDB) { + RequestInfo requestInfo = attendeeDeleteRequest.getRequestInfo(); + List attendeesListFromRequest = attendeeDeleteRequest.getAttendees(); + + for (IndividualEntry attendee : attendeesListFromRequest) { + for (IndividualEntry attendeeFromDB : attendeesFromDB) { + if (attendeeFromDB.getIndividualId().equals(attendee.getIndividualId()) + && attendeeFromDB.getRegisterId().equals(attendee.getRegisterId())) { + + attendee.setId(attendeeFromDB.getId()); + attendee.setEnrollmentDate(attendeeFromDB.getEnrollmentDate()); + + AuditDetails auditDetails = attendanceServiceUtil.getAuditDetails(requestInfo.getUserInfo().getUuid(), attendeeFromDB.getAuditDetails(), false); + attendee.setAuditDetails(auditDetails); + + + if (attendee.getDenrollmentDate() == null) { + BigDecimal deEnrollmentDate = new BigDecimal(System.currentTimeMillis()); + attendee.setDenrollmentDate(deEnrollmentDate); + } + } + } + } + + + } +} diff --git a/health-services/attendance/src/main/java/org/egov/enrichment/RegisterEnrichment.java b/health-services/attendance/src/main/java/org/egov/enrichment/RegisterEnrichment.java new file mode 100644 index 00000000000..241527068c6 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/enrichment/RegisterEnrichment.java @@ -0,0 +1,153 @@ +package org.egov.enrichment; + +import digit.models.coremodels.AuditDetails; +import digit.models.coremodels.IdResponse; +import lombok.extern.slf4j.Slf4j; +import org.egov.common.contract.request.RequestInfo; +import org.egov.common.models.individual.Individual; +import org.egov.common.utils.MultiStateInstanceUtil; +import org.egov.config.AttendanceServiceConfiguration; +import org.egov.repository.IdGenRepository; +import org.egov.tracer.model.CustomException; +import org.egov.util.AttendanceServiceUtil; +import org.egov.util.IndividualServiceUtil; +import org.egov.web.models.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.math.BigDecimal; +import java.util.Collections; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class RegisterEnrichment { + + @Autowired + private AttendanceServiceUtil attendanceServiceUtil; + @Autowired + private IdGenRepository idGenRepository; + @Autowired + private AttendanceServiceConfiguration config; + @Autowired + private IndividualServiceUtil individualServiceUtil; + @Autowired + private MultiStateInstanceUtil multiStateInstanceUtil; + + /* Enrich Attendance Register on Create Request */ + public void enrichRegisterOnCreate(AttendanceRegisterRequest attendanceRegisterRequest) { + RequestInfo requestInfo = attendanceRegisterRequest.getRequestInfo(); + List attendanceRegisters = attendanceRegisterRequest.getAttendanceRegister(); + + String rootTenantId = attendanceRegisters.get(0).getTenantId().split("\\.")[0]; + + //Get Register Numbers from IdGen Service for number of registers present in AttendanceRegisters + List registerNumbers = getIdList(requestInfo, rootTenantId + , config.getIdgenAttendanceRegisterNumberName(), "", attendanceRegisters.size()); //idFormat will be fetched by idGen service + + for (int i = 0; i < attendanceRegisters.size(); i++) { + + if (registerNumbers != null && !registerNumbers.isEmpty()) { + attendanceRegisters.get(i).setRegisterNumber(registerNumbers.get(i)); + log.info("Register number " + registerNumbers.get(i) + " assigned to register " + attendanceRegisters.get(i)); + } else { + log.error("Error occurred while generating attendance register numbers from IdGen service"); + throw new CustomException("ATTENDANCE_REGISTER_NUMBER_NOT_GENERATED","Error occurred while generating attendance register numbers from IdGen service"); + } + + //Enrich attendance register id and audit details + attendanceRegisters.get(i).setId(UUID.randomUUID().toString()); + log.info("Attendance register assigned with register Id " + attendanceRegisters.get(i).getId()); + AuditDetails auditDetails = attendanceServiceUtil.getAuditDetails(requestInfo.getUserInfo().getUuid(), null, true); + attendanceRegisters.get(i).setAuditDetails(auditDetails); + log.info("Enriched register " + attendanceRegisters.get(i).getId() + " with Audit details"); + // User who creates the register, by default gets enrolled as the first staff for that register. + enrichRegisterFirstStaff(attendanceRegisters.get(i), requestInfo, auditDetails); + } + } + + /* Enrich first staff details while creating register*/ + private void enrichRegisterFirstStaff(AttendanceRegister attendanceRegister, RequestInfo requestInfo, AuditDetails auditDetails) { + String tenantId = attendanceRegister.getTenantId(); + Long userid = requestInfo.getUserInfo().getId(); + List individualList = individualServiceUtil.getIndividualDetailsFromUserId(userid, requestInfo, multiStateInstanceUtil.getStateLevelTenant(tenantId)); + String individualId = individualList.get(0).getId(); + + StaffPermission staffPermission = StaffPermission.builder() + .id(UUID.randomUUID().toString()) + .tenantId(attendanceRegister.getTenantId()) + .registerId(attendanceRegister.getId()) + .userId(individualId) + .enrollmentDate(new BigDecimal(System.currentTimeMillis())) + .auditDetails(auditDetails) + .build(); + attendanceRegister.setStaff(Collections.singletonList(staffPermission)); + log.info("First staff for attendance register is added in attendance register"); + log.info("The user " + requestInfo.getUserInfo().getUuid() + " is addedd as staff for the attendance register + " + staffPermission.getRegisterId()); + } + + /* Enrich Attendance Register on Update Request */ + public void enrichRegisterOnUpdate(AttendanceRegisterRequest attendanceRegisterRequest, List attendanceRegistersListFromDB) { + RequestInfo requestInfo = attendanceRegisterRequest.getRequestInfo(); + List attendanceRegistersListInUpdateReq = attendanceRegisterRequest.getAttendanceRegister(); + + for (AttendanceRegister attendanceRegisterInUpdateReq : attendanceRegistersListInUpdateReq) { + log.info("Enriching register " + attendanceRegisterInUpdateReq.getId()); + String registerId = String.valueOf(attendanceRegisterInUpdateReq.getId()); + AttendanceRegister attendanceRegisterFromDB = attendanceRegistersListFromDB.stream().filter(ar -> registerId.equals(String.valueOf(ar.getId()))).findFirst().orElse(null); + + // Set read only values i.e register number, attendees, staff to the attendance register update request as in attendance register from DB + attendanceRegisterInUpdateReq.setRegisterNumber(attendanceRegisterFromDB.getRegisterNumber()); + attendanceRegisterInUpdateReq.setAttendees(attendanceRegisterFromDB.getAttendees()); + attendanceRegisterInUpdateReq.setStaff(attendanceRegisterFromDB.getStaff()); + log.info("Update attendance register request for register " + attendanceRegisterInUpdateReq.getId() + " enriched with register number, attendees and staff"); + + // Set audit details for register update request + attendanceRegisterInUpdateReq.setAuditDetails(attendanceRegisterFromDB.getAuditDetails()); + AuditDetails auditDetails = attendanceServiceUtil.getAuditDetails(requestInfo.getUserInfo().getUuid(), attendanceRegisterFromDB.getAuditDetails(), false); + attendanceRegisterInUpdateReq.setAuditDetails(auditDetails); + log.info("Update attendance register request for register " + attendanceRegisterInUpdateReq.getId() + " enriched with audit details"); + } + } + + /* Adds staff details to the associated attendance register */ + public void enrichStaffInRegister(List attendanceRegisters, StaffPermissionRequest staffPermissionResponse) { + for (AttendanceRegister attendanceRegister : attendanceRegisters) { + String registerId = String.valueOf(attendanceRegister.getId()); + List staff = staffPermissionResponse.getStaff().stream().filter(st -> registerId.equals(st.getRegisterId())).collect(Collectors.toList()); + attendanceRegister.setStaff(staff); + log.info("Created staff details associated with attendance register " + attendanceRegister.getId() + " in create request"); + } + } + + /* Get id list from IdGen service */ + private List getIdList(RequestInfo requestInfo, String tenantId, String idKey, + String idformat, int count) { + List idResponses = idGenRepository.getId(requestInfo, tenantId, idKey, idformat, count).getIdResponses(); + + if (CollectionUtils.isEmpty(idResponses)) { + log.error("No ids returned from idgen Service"); + throw new CustomException("IDGEN ERROR", "No ids returned from idgen Service"); + } + + return idResponses.stream() + .map(IdResponse::getId).collect(Collectors.toList()); + } + + + public void enrichSearchRegisterRequest(RequestInfo requestInfo, AttendanceRegisterSearchCriteria searchCriteria) { + + if (searchCriteria.getLimit() == null) + searchCriteria.setLimit(config.getAttendanceRegisterDefaultLimit()); + + if (searchCriteria.getOffset() == null) + searchCriteria.setOffset(config.getAttendanceRegisterDefaultOffset()); + + if (searchCriteria.getLimit() != null && searchCriteria.getLimit() > config.getAttendanceRegisterMaxLimit()) + searchCriteria.setLimit(config.getAttendanceRegisterMaxLimit()); + + } +} diff --git a/health-services/attendance/src/main/java/org/egov/enrichment/StaffEnrichmentService.java b/health-services/attendance/src/main/java/org/egov/enrichment/StaffEnrichmentService.java new file mode 100644 index 00000000000..abbb77fbf72 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/enrichment/StaffEnrichmentService.java @@ -0,0 +1,60 @@ +package org.egov.enrichment; + +import digit.models.coremodels.AuditDetails; +import org.egov.common.contract.request.RequestInfo; +import org.egov.util.AttendanceServiceUtil; +import org.egov.web.models.StaffPermission; +import org.egov.web.models.StaffPermissionRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.List; +import java.util.UUID; + +@Service +public class StaffEnrichmentService { + + @Autowired + private AttendanceServiceUtil attendanceServiceUtil; + + public void enrichStaffPermissionOnCreate(StaffPermissionRequest request) { + RequestInfo requestInfo = request.getRequestInfo(); + List staffPermissionListFromRequest = request.getStaff(); + + for (StaffPermission staffPermissionFromRequest : staffPermissionListFromRequest) { + AuditDetails auditDetails = attendanceServiceUtil.getAuditDetails(requestInfo.getUserInfo().getUuid(), staffPermissionFromRequest.getAuditDetails(), true); + staffPermissionFromRequest.setAuditDetails(auditDetails); + staffPermissionFromRequest.setId(UUID.randomUUID().toString()); + BigDecimal enrollmentDate = new BigDecimal(System.currentTimeMillis()); + staffPermissionFromRequest.setEnrollmentDate(enrollmentDate); + } + } + + public void enrichStaffPermissionOnDelete(StaffPermissionRequest request, List staffPermissionListFromDB) { + RequestInfo requestInfo = request.getRequestInfo(); + List staffPermissionListFromRequest = request.getStaff(); + + for (StaffPermission staffPermissionFromRequest : staffPermissionListFromRequest) { + for (StaffPermission staffPermissionFromDB : staffPermissionListFromDB) { + if (staffPermissionFromDB.getUserId().equals(staffPermissionFromRequest.getUserId()) + && staffPermissionFromDB.getRegisterId().equals(staffPermissionFromRequest.getRegisterId()) + && staffPermissionFromDB.getDenrollmentDate() == null) { + staffPermissionFromRequest.setId(staffPermissionFromDB.getId()); + staffPermissionFromRequest.setEnrollmentDate(staffPermissionFromDB.getEnrollmentDate()); + + AuditDetails auditDetails = attendanceServiceUtil.getAuditDetails(requestInfo.getUserInfo().getUuid(), staffPermissionFromDB.getAuditDetails(), false); + + staffPermissionFromRequest.setAuditDetails(auditDetails); + + BigDecimal deenrollmentDate = new BigDecimal(System.currentTimeMillis()); + staffPermissionFromRequest.setDenrollmentDate(deenrollmentDate); + } + } + } + + + } + + +} diff --git a/health-services/attendance/src/main/java/org/egov/kafka/AttendanceLogConsumer.java b/health-services/attendance/src/main/java/org/egov/kafka/AttendanceLogConsumer.java new file mode 100644 index 00000000000..8f3e0f3067c --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/kafka/AttendanceLogConsumer.java @@ -0,0 +1,57 @@ +package org.egov.kafka; + +import java.util.Map; + +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.egov.service.AttendanceLogService; +import org.egov.tracer.model.CustomException; +import org.egov.web.models.AttendanceLogRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.kafka.annotation.KafkaListener; +import org.springframework.kafka.support.KafkaHeaders; +import org.springframework.messaging.handler.annotation.Header; +import org.springframework.stereotype.Component; + + +@Component +@Slf4j +public class AttendanceLogConsumer { + + @Autowired + private AttendanceLogService attendanceLogService; + + @Autowired + @Qualifier("objectMapper") + private ObjectMapper objectMapper; + + @KafkaListener(topics = "${attendance.log.kafka.consumer.bulk.create.topic}") + public void bulkCreate(Map consumerRecord, + @Header(KafkaHeaders.RECEIVED_TOPIC) String topic) { + System.out.println("kafka listener started"); + try { + AttendanceLogRequest request = objectMapper.convertValue(consumerRecord, AttendanceLogRequest.class); + attendanceLogService.createAttendanceLog(request); + } catch (Exception exception) { + log.error("Error in Attendance Log consumer bulk create", exception); + log.error("Exception trace: ", ExceptionUtils.getStackTrace(exception)); + throw new CustomException("HCM_ATTENDANCE_LOG_CREATE", exception.getMessage()); + } + } + + @KafkaListener(topics = "${attendance.log.kafka.consumer.bulk.update.topic}") + public void bulkUpdate(Map consumerRecord, + @Header(KafkaHeaders.RECEIVED_TOPIC) String topic) { + try { + AttendanceLogRequest request = objectMapper.convertValue(consumerRecord, AttendanceLogRequest.class); + attendanceLogService.updateAttendanceLog(request); + } catch (Exception exception) { + log.error("Error in Attendance Log consumer bulk update", exception); + log.error("Exception trace: ", ExceptionUtils.getStackTrace(exception)); + throw new CustomException("HCM_ATTENDANCE_LOG_UPDATE", exception.getMessage()); + } + } + +} diff --git a/health-services/attendance/src/main/java/org/egov/kafka/Consumer.java b/health-services/attendance/src/main/java/org/egov/kafka/Consumer.java new file mode 100644 index 00000000000..8b5094ede05 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/kafka/Consumer.java @@ -0,0 +1,65 @@ +package org.egov.kafka; + + +import org.egov.common.contract.request.RequestInfo; +import org.egov.service.AttendanceRegisterService; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.egov.service.OrganisationContactDetailsStaffUpdateService; +import org.egov.service.StaffService; +import org.egov.web.models.Organisation.OrgContactUpdateDiff; +import org.egov.web.models.StaffPermission; +import org.egov.web.models.StaffPermissionRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.kafka.annotation.KafkaListener; +import org.springframework.kafka.support.KafkaHeaders; +import org.springframework.messaging.handler.annotation.Header; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.util.Collections; +import java.util.Map; + +@Component +@Slf4j +public class Consumer { + + @Autowired + private ObjectMapper objectMapper; + @Autowired + private OrganisationContactDetailsStaffUpdateService organisationContactDetailsStaffUpdateService; + @Autowired + private AttendanceRegisterService attendanceRegisterService; + + @KafkaListener(topics = "${organisation.contact.details.update.topic}") + public void updateAttendanceStaff(String consumerRecord, + @Header(KafkaHeaders.RECEIVED_TOPIC) String topic){ + try { + OrgContactUpdateDiff orgContactUpdateDiff = objectMapper.readValue(consumerRecord, OrgContactUpdateDiff.class); + organisationContactDetailsStaffUpdateService.updateStaffPermissionsForContactDetails(orgContactUpdateDiff); + } catch(Exception e){ + log.error("Error updating staff permissions for update in organisation contact details", e); + } + } + + /** + * Update end date for approved time extension request + * @param consumerRecord + * @param topic + */ + @KafkaListener(topics = "${contracts.revision.topic}") + public void updateEndDate(String consumerRecord, @Header(KafkaHeaders.RECEIVED_TOPIC) String topic) { + try { + JsonNode attendanceContractRevisionRequest = objectMapper.readValue(consumerRecord, JsonNode.class); + RequestInfo requestInfo = objectMapper.convertValue(attendanceContractRevisionRequest.get("RequestInfo"), RequestInfo.class); + String tenantId = attendanceContractRevisionRequest.get("tenantId").asText(); + String referenceId = attendanceContractRevisionRequest.get("referenceId").asText(); + BigDecimal endDate = attendanceContractRevisionRequest.get("endDate").decimalValue(); + attendanceRegisterService.updateEndDateForRevisedContract(requestInfo, tenantId, referenceId, endDate); + }catch (Exception e) { + log.error("Error end date for contract"); + } + } + +} diff --git a/health-services/attendance/src/main/java/org/egov/kafka/Producer.java b/health-services/attendance/src/main/java/org/egov/kafka/Producer.java new file mode 100644 index 00000000000..e13cd3d7fab --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/kafka/Producer.java @@ -0,0 +1,16 @@ +package org.egov.kafka; + +import org.egov.tracer.kafka.CustomKafkaTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +//@Component +public class Producer { + + @Autowired + private CustomKafkaTemplate kafkaTemplate; + + public void push(String topic, Object value) { + kafkaTemplate.send(topic, value); + } +} diff --git a/health-services/attendance/src/main/java/org/egov/repository/AttendanceLogRepository.java b/health-services/attendance/src/main/java/org/egov/repository/AttendanceLogRepository.java new file mode 100644 index 00000000000..b15c8208f55 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/repository/AttendanceLogRepository.java @@ -0,0 +1,54 @@ +package org.egov.repository; + +import lombok.extern.slf4j.Slf4j; +import org.egov.common.data.query.builder.SelectQueryBuilder; +import org.egov.common.data.repository.GenericRepository; +import org.egov.common.producer.Producer; +import org.egov.repository.querybuilder.AttendanceLogQueryBuilder; +import org.egov.repository.rowmapper.AttendanceLogRowMapper; +import org.egov.web.models.AttendanceLog; +import org.egov.web.models.AttendanceLogSearchCriteria; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; +import org.springframework.stereotype.Repository; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +@Repository +@Slf4j +public class AttendanceLogRepository extends GenericRepository { + private final AttendanceLogRowMapper rowMapper; + private final AttendanceLogQueryBuilder queryBuilder; + private final JdbcTemplate jdbcTemplate; + + @Autowired + protected AttendanceLogRepository( + Producer producer, + NamedParameterJdbcTemplate namedParameterJdbcTemplate, + RedisTemplate redisTemplate, + SelectQueryBuilder selectQueryBuilder, + AttendanceLogRowMapper rowMapper, + JdbcTemplate jdbcTemplate) { + super(producer, namedParameterJdbcTemplate, redisTemplate, selectQueryBuilder, null, Optional.of("abc")); + this.rowMapper = rowMapper; + this.queryBuilder = new AttendanceLogQueryBuilder(); + this.jdbcTemplate = jdbcTemplate; + } + + + public List getAttendanceLogs(AttendanceLogSearchCriteria searchCriteria) { + List preparedStmtList = new ArrayList<>(); + log.info("Fetching Attendance Log list. RegisterId ["+searchCriteria.getRegisterId()+"]"); + String query = queryBuilder.getAttendanceLogSearchQuery(searchCriteria, preparedStmtList); + log.info("Query build successfully. RegisterId ["+searchCriteria.getRegisterId()+"]"); + List attendanceLogList = jdbcTemplate.query(query, rowMapper, preparedStmtList.toArray()); + log.info("Fetched Attendance Log list. RegisterId ["+searchCriteria.getRegisterId()+"]"); + return attendanceLogList; + } +} diff --git a/health-services/attendance/src/main/java/org/egov/repository/AttendeeRepository.java b/health-services/attendance/src/main/java/org/egov/repository/AttendeeRepository.java new file mode 100644 index 00000000000..c9fc386bef0 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/repository/AttendeeRepository.java @@ -0,0 +1,31 @@ +package org.egov.repository; + +import org.egov.repository.querybuilder.AttendeeQueryBuilder; +import org.egov.repository.rowmapper.AttendeeRowMapper; +import org.egov.web.models.AttendeeSearchCriteria; +import org.egov.web.models.IndividualEntry; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Repository; + +import java.util.ArrayList; +import java.util.List; + +@Repository +public class AttendeeRepository { + @Autowired + private AttendeeRowMapper attendeeRowMapper; + + @Autowired + private AttendeeQueryBuilder queryBuilder; + + @Autowired + private JdbcTemplate jdbcTemplate; + + public List getAttendees(AttendeeSearchCriteria searchCriteria) { + List preparedStmtList = new ArrayList<>(); + String query = queryBuilder.getAttendanceAttendeeSearchQuery(searchCriteria, preparedStmtList); + List attendanceStaffList = jdbcTemplate.query(query, attendeeRowMapper, preparedStmtList.toArray()); + return attendanceStaffList; + } +} diff --git a/health-services/attendance/src/main/java/org/egov/repository/IdGenRepository.java b/health-services/attendance/src/main/java/org/egov/repository/IdGenRepository.java new file mode 100644 index 00000000000..da28aa64584 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/repository/IdGenRepository.java @@ -0,0 +1,59 @@ +package org.egov.repository; + +import digit.models.coremodels.IdGenerationRequest; +import digit.models.coremodels.IdGenerationResponse; +import digit.models.coremodels.IdRequest; +import org.egov.common.contract.request.RequestInfo; +import org.egov.config.AttendanceServiceConfiguration; +import org.egov.tracer.model.CustomException; +import org.egov.tracer.model.ServiceCallException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestTemplate; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Repository +public class IdGenRepository { + + @Autowired + private RestTemplate restTemplate; + + @Autowired + private AttendanceServiceConfiguration config; + + /** + * Call iDgen to generateIds + * + * @param requestInfo The rquestInfo of the request + * @param tenantId The tenantiD of the service request + * @param name Name of the foramt + * @param format Format of the ids + * @param count Total Number of idGen ids required + * @return + */ + public IdGenerationResponse getId(RequestInfo requestInfo, String tenantId, String name, String format, int count) { + + List reqList = new ArrayList<>(); + for (int i = 0; i < count; i++) { + reqList.add(IdRequest.builder().idName(name).format(format).tenantId(tenantId).build()); + } + IdGenerationRequest req = IdGenerationRequest.builder().idRequests(reqList).requestInfo(requestInfo).build(); + IdGenerationResponse response = null; + try { + response = restTemplate.postForObject(config.getIdGenHost() + config.getIdGenPath(), req, IdGenerationResponse.class); + } catch (HttpClientErrorException e) { + throw new ServiceCallException(e.getResponseBodyAsString()); + } catch (Exception e) { + Map map = new HashMap<>(); + map.put(e.getCause().getClass().getName(), e.getMessage()); + throw new CustomException(map); + } + return response; + } + +} diff --git a/health-services/attendance/src/main/java/org/egov/repository/RegisterRepository.java b/health-services/attendance/src/main/java/org/egov/repository/RegisterRepository.java new file mode 100644 index 00000000000..a4de6ea2422 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/repository/RegisterRepository.java @@ -0,0 +1,37 @@ +package org.egov.repository; + +import lombok.extern.slf4j.Slf4j; +import org.egov.repository.querybuilder.RegisterQueryBuilder; +import org.egov.repository.rowmapper.RegisterRowMapper; +import org.egov.web.models.AttendanceRegister; +import org.egov.web.models.AttendanceRegisterSearchCriteria; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Repository; + +import java.util.ArrayList; +import java.util.List; + +@Repository +@Slf4j +public class RegisterRepository { + + @Autowired + private RegisterRowMapper rowMapper; + + @Autowired + private RegisterQueryBuilder queryBuilder; + + @Autowired + private JdbcTemplate jdbcTemplate; + + public List getRegister(AttendanceRegisterSearchCriteria searchCriteria) { + List preparedStmtList = new ArrayList<>(); + String query = queryBuilder.getAttendanceRegisterSearchQuery(searchCriteria, preparedStmtList); + log.info("Query of get register : " + query); + log.info("preparedStmtList of get register : " + preparedStmtList.toString()); + List attendanceRegisterList = jdbcTemplate.query(query, rowMapper, preparedStmtList.toArray()); + return attendanceRegisterList; + } + +} diff --git a/health-services/attendance/src/main/java/org/egov/repository/ServiceRequestRepository.java b/health-services/attendance/src/main/java/org/egov/repository/ServiceRequestRepository.java new file mode 100644 index 00000000000..644e99c7df0 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/repository/ServiceRequestRepository.java @@ -0,0 +1,41 @@ +package org.egov.repository; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import lombok.extern.slf4j.Slf4j; +import org.egov.tracer.model.ServiceCallException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Repository; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestTemplate; + +import java.util.Map; + +@Repository +@Slf4j +public class ServiceRequestRepository { + + @Autowired + @Qualifier("objectMapper") + private ObjectMapper mapper; + + @Autowired + private RestTemplate restTemplate; + + + public Object fetchResult(StringBuilder uri, Object request) { + mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); + Object response = null; + try { + response = restTemplate.postForObject(uri.toString(), request, Map.class); + } catch (HttpClientErrorException e) { + log.error("External Service threw an Exception: ", e); + throw new ServiceCallException(e.getResponseBodyAsString()); + } catch (Exception e) { + log.error("Exception while fetching from searcher: ", e); + } + + return response; + } +} diff --git a/health-services/attendance/src/main/java/org/egov/repository/StaffRepository.java b/health-services/attendance/src/main/java/org/egov/repository/StaffRepository.java new file mode 100644 index 00000000000..6d83e146dc1 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/repository/StaffRepository.java @@ -0,0 +1,40 @@ +package org.egov.repository; + +import lombok.extern.slf4j.Slf4j; +import org.egov.repository.querybuilder.StaffQueryBuilder; +import org.egov.repository.rowmapper.StaffRowMapper; +import org.egov.web.models.StaffSearchCriteria; +import org.egov.web.models.StaffPermission; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Repository; + +import java.util.ArrayList; +import java.util.List; + +@Repository +@Slf4j +public class StaffRepository { + @Autowired + private StaffRowMapper rowMapper; + + @Autowired + private StaffQueryBuilder queryBuilder; + + @Autowired + private JdbcTemplate jdbcTemplate; + + public List getActiveStaff(StaffSearchCriteria searchCriteria) { + List preparedStmtList = new ArrayList<>(); + String query = queryBuilder.getActiveAttendanceStaffSearchQuery(searchCriteria, preparedStmtList); + List attendanceStaffList = jdbcTemplate.query(query, rowMapper, preparedStmtList.toArray()); + return attendanceStaffList; + } + + public List getAllStaff(StaffSearchCriteria searchCriteria) { + List preparedStmtList = new ArrayList<>(); + String query = queryBuilder.getAttendanceStaffSearchQuery(searchCriteria, preparedStmtList); + List attendanceStaffList = jdbcTemplate.query(query, rowMapper, preparedStmtList.toArray()); + return attendanceStaffList; + } +} diff --git a/health-services/attendance/src/main/java/org/egov/repository/querybuilder/AttendanceLogQueryBuilder.java b/health-services/attendance/src/main/java/org/egov/repository/querybuilder/AttendanceLogQueryBuilder.java new file mode 100644 index 00000000000..ad589427476 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/repository/querybuilder/AttendanceLogQueryBuilder.java @@ -0,0 +1,164 @@ +package org.egov.repository.querybuilder; + +import org.apache.commons.lang3.StringUtils; +import org.egov.tracer.model.CustomException; +import org.egov.web.models.AttendanceLogSearchCriteria; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.time.Instant; +import java.util.Collection; +import java.util.List; + +@Component +public class AttendanceLogQueryBuilder { + + private static final String ATTENDANCE_LOG_SELECT_QUERY = " SELECT log.id as logid, " + + "log.individual_id as logIndividualId, " + + "log.clientreferenceid as logClientReferenceId, " + + "log.tenantId as logTenantId, " + + "log.register_id as logRegisterId, " + + "log.status as logStatus, " + + "log.time as logTime, " + + "log.event_type as logEventType, " + + "log.additionaldetails as logAdditionalDetails, " + + "log.createdby as logCreatedBy, " + + "log.lastmodifiedby as logLastModifiedBy, " + + "log.createdtime as logCreatedTime, " + + "log.lastmodifiedtime as logLastModifiedTime, " + + "log.clientcreatedby as logClientCreatedBy, " + + "log.clientlastmodifiedby as logClientLastModifiedBy, " + + "log.clientcreatedtime as logClientCreatedTime, " + + "log.clientlastmodifiedtime as logClientLastModifiedTime, " + + "doc.id as docId, " + + "doc.filestore_id as docFileStoreId, " + + "doc.document_type as docDocumentType, " + + "doc.attendance_log_id as docAttendanceLogId, " + + "doc.tenantid as docTenantId, " + + "doc.status as docStatus, " + + "doc.additionaldetails as docAdditionalDetails, " + + "doc.createdby as docCreatedBy, " + + "doc.lastmodifiedby as docLastModifiedBy, " + + "doc.createdtime as docCreatedTime, " + + "doc.lastmodifiedtime as docLastModifiedTime " + + "FROM eg_wms_attendance_log AS log " + + "LEFT JOIN " + + "eg_wms_attendance_document AS doc " + + "ON (log.id=doc.attendance_log_id) "; + + + public String getAttendanceLogSearchQuery(AttendanceLogSearchCriteria criteria, List preparedStmtList) { + StringBuilder query = new StringBuilder(ATTENDANCE_LOG_SELECT_QUERY); + + List ids = criteria.getIds(); + if (ids != null && !ids.isEmpty()) { + addClauseIfRequired(query, preparedStmtList); + query.append(" log.id IN (").append(createQuery(ids)).append(")"); + addToPreparedStatement(preparedStmtList, ids); + } + + List clientReferenceIds = criteria.getClientReferenceIds(); + if (clientReferenceIds != null && !clientReferenceIds.isEmpty()) { + addClauseIfRequired(query, preparedStmtList); + query.append(" log.clientReferenceId IN (").append(createQuery(clientReferenceIds)).append(")"); + addToPreparedStatement(preparedStmtList, clientReferenceIds); + } + + if (StringUtils.isNotBlank(criteria.getTenantId())) { + addClauseIfRequired(query, preparedStmtList); + query.append(" log.tenantid=? "); + preparedStmtList.add(criteria.getTenantId()); + } + + if (StringUtils.isNotBlank(criteria.getRegisterId())) { + addClauseIfRequired(query, preparedStmtList); + query.append(" log.register_id=? "); + preparedStmtList.add(criteria.getRegisterId()); + } + + if (criteria.getFromTime() != null) { + addClauseIfRequired(query, preparedStmtList); + + //If user does not specify toDate, take today's date as toDate by default. + if (criteria.getToTime() == null) { + criteria.setToTime(BigDecimal.valueOf(Instant.now().toEpochMilli())); + } + + query.append(" log.time BETWEEN ? AND ?"); + preparedStmtList.add(criteria.getFromTime()); + preparedStmtList.add(criteria.getToTime()); + + } else { + //if only toDate is provided as parameter without fromDate parameter, throw an exception. + if (criteria.getToTime() != null) { + throw new CustomException("INVALID_SEARCH_PARAM", "Cannot specify getToTime without a getFromTime"); + } + } + + List individualIds = criteria.getIndividualIds(); + if (individualIds != null && !individualIds.isEmpty()) { + addClauseIfRequired(query, preparedStmtList); + query.append(" log.individual_id IN (").append(createQuery(individualIds)).append(")"); + addToPreparedStatement(preparedStmtList, individualIds); + } + + if (criteria.getStatus() != null) { + addClauseIfRequired(query, preparedStmtList); + query.append(" log.status=? "); + preparedStmtList.add(criteria.getStatus().toString()); + } + + addOrderByClause(query, criteria); + + addLimitAndOffset(query, criteria, preparedStmtList); + + return query.toString(); + } + + private void addOrderByClause(StringBuilder queryBuilder, AttendanceLogSearchCriteria criteria) { + + //default + if (criteria.getSortBy() == null || StringUtils.isEmpty(criteria.getSortBy().name())) { + queryBuilder.append(" ORDER BY log.lastmodifiedtime "); + } + + if (criteria.getSortOrder() == AttendanceLogSearchCriteria.SortOrder.ASC) + queryBuilder.append(" ASC "); + else queryBuilder.append(" DESC "); + } + + private void addLimitAndOffset(StringBuilder queryBuilder, AttendanceLogSearchCriteria criteria, List preparedStmtList) { + queryBuilder.append(" OFFSET ? "); + preparedStmtList.add(criteria.getOffset()); + + queryBuilder.append(" LIMIT ? "); + preparedStmtList.add(criteria.getLimit()); + + } + + private String createQuery(Collection ids) { + StringBuilder builder = new StringBuilder(); + int length = ids.size(); + for (int i = 0; i < length; i++) { + builder.append(" ? "); + if (i != length - 1) builder.append(","); + } + return builder.toString(); + } + + private void addClauseIfRequired(StringBuilder query, List preparedStmtList) { + if (preparedStmtList.isEmpty()) { + query.append(" WHERE "); + } else { + query.append(" AND "); + } + } + + private void addToPreparedStatement(List preparedStmtList, Collection ids) { +// ids.forEach(id -> { +// preparedStmtList.add(id); +// }); + + preparedStmtList.addAll(ids); + } +} diff --git a/health-services/attendance/src/main/java/org/egov/repository/querybuilder/AttendeeQueryBuilder.java b/health-services/attendance/src/main/java/org/egov/repository/querybuilder/AttendeeQueryBuilder.java new file mode 100644 index 00000000000..1e963ef6bad --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/repository/querybuilder/AttendeeQueryBuilder.java @@ -0,0 +1,104 @@ +package org.egov.repository.querybuilder; + +import org.egov.tracer.model.CustomException; +import org.egov.web.models.AttendeeSearchCriteria; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.time.Instant; +import java.util.Collection; +import java.util.List; + +@Component +public class AttendeeQueryBuilder { + + private static final String ATTENDANCE_ATTENDEE_SELECT_QUERY = " SELECT att.id, " + + "att.individual_id, " + + "att.register_id, " + + "att.enrollment_date , " + + "att.deenrollment_date, " + + "att.additionaldetails, " + + "att.createdby, " + + "att.lastmodifiedby, " + + "att.createdtime, " + + "att.lastmodifiedtime, " + + "att.tenantid " + + "FROM eg_wms_attendance_attendee att "; + + public String getAttendanceAttendeeSearchQuery(AttendeeSearchCriteria criteria, List preparedStmtList) { + StringBuilder query = new StringBuilder(ATTENDANCE_ATTENDEE_SELECT_QUERY); + + List ids=criteria.getIds(); + if (ids!=null && !ids.isEmpty()) { + addClauseIfRequired(query, preparedStmtList); + query.append(" att.id IN (").append(createQuery(ids)).append(")"); + addToPreparedStatement(preparedStmtList, ids); + } + + List individualIds=criteria.getIndividualIds(); + if (individualIds!=null && !individualIds.isEmpty()) { + addClauseIfRequired(query, preparedStmtList); + query.append(" att.individual_id IN (").append(createQuery(individualIds)).append(")"); + addToPreparedStatement(preparedStmtList, individualIds); + } + + List registerIds = criteria.getRegisterIds(); + if (registerIds != null && !registerIds.isEmpty()) { + addClauseIfRequired(query, preparedStmtList); + query.append(" att.register_id IN (").append(createQuery(registerIds)).append(")"); + addToPreparedStatement(preparedStmtList, registerIds); + } + + if (criteria.getEnrollmentDate() != null) { + addClauseIfRequired(query, preparedStmtList); + + //If user does not specify toDate, take today's date as toDate by default. + if (criteria.getDenrollmentDate() == null) { + criteria.setDenrollmentDate(BigDecimal.valueOf(Instant.now().toEpochMilli())); + } + + query.append(" att.enrollment_date BETWEEN ? AND ?"); + preparedStmtList.add(criteria.getEnrollmentDate()); + preparedStmtList.add(criteria.getDenrollmentDate()); + + } else { + //if only toDate is provided as parameter without fromDate parameter, throw an exception. + if (criteria.getDenrollmentDate() != null) { + throw new CustomException("INVALID_SEARCH_PARAM", "Cannot specify getEnrollmentDate without a getEnrollmentDate"); + } + } + + addLimitAndOffset(query, criteria, preparedStmtList); + + return query.toString(); + } + private void addLimitAndOffset(StringBuilder query, AttendeeSearchCriteria criteria, List preparedStmtList) { + query.append(" OFFSET ? "); + preparedStmtList.add(criteria.getOffset()); + + query.append(" LIMIT ? "); + preparedStmtList.add(criteria.getLimit()); + + } + + private String createQuery(Collection ids) { + StringBuilder builder = new StringBuilder(); + int length = ids.size(); + for (int i = 0; i < length; i++) { + builder.append(" ? "); + if (i != length - 1) builder.append(","); + } + return builder.toString(); + } + private void addClauseIfRequired(StringBuilder query, List preparedStmtList) { + if (preparedStmtList.isEmpty()) { + query.append(" WHERE "); + } else { + query.append(" AND "); + } + } + + private void addToPreparedStatement(List preparedStmtList, Collection ids) { + preparedStmtList.addAll(ids); + } +} diff --git a/health-services/attendance/src/main/java/org/egov/repository/querybuilder/RegisterQueryBuilder.java b/health-services/attendance/src/main/java/org/egov/repository/querybuilder/RegisterQueryBuilder.java new file mode 100644 index 00000000000..551c2a33819 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/repository/querybuilder/RegisterQueryBuilder.java @@ -0,0 +1,198 @@ +package org.egov.repository.querybuilder; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.egov.config.AttendanceServiceConfiguration; +import org.egov.tracer.model.CustomException; +import org.egov.web.models.AttendanceLogSearchCriteria; +import org.egov.web.models.AttendanceRegisterSearchCriteria; +import org.egov.web.models.Status; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.ObjectUtils; + +import java.math.BigDecimal; +import java.time.Instant; +import java.util.Collection; +import java.util.List; + +@Component +@Slf4j +public class RegisterQueryBuilder { + + @Autowired + private AttendanceServiceConfiguration config; + + private static final String ATTENDANCE_REGISTER_SELECT_QUERY = " SELECT reg.id, " + + "reg.tenantid, " + + "reg.registernumber, " + + "reg.name , " + + "reg.startdate, " + + "reg.enddate, " + + "reg.status, " + + "reg.additionaldetails, " + + "reg.createdby, " + + "reg.lastmodifiedby, " + + "reg.createdtime, " + + "reg.lastmodifiedtime, " + + "reg.referenceid, " + + "reg.servicecode " + + "FROM eg_wms_attendance_register reg "; + + + private final String paginationWrapper = "SELECT * FROM " + + "(SELECT *, DENSE_RANK() OVER (ORDER BY lastmodifiedtime DESC , id) offset_ FROM " + + "({})" + + " result) result_offset " + + "WHERE offset_ > ? AND offset_ <= ?"; + + + public String getAttendanceRegisterSearchQuery(AttendanceRegisterSearchCriteria searchCriteria, List preparedStmtList) { + + log.info("Search criteria of attendance search : " + searchCriteria.toString()); + StringBuilder query = new StringBuilder(ATTENDANCE_REGISTER_SELECT_QUERY); + + if (!ObjectUtils.isEmpty(searchCriteria.getTenantId())) { + addClauseIfRequired(query, preparedStmtList); + query.append(" reg.tenantid like ? "); + preparedStmtList.add(searchCriteria.getTenantId()+"%"); + } + + List registerIds = searchCriteria.getIds(); + if (registerIds != null && !registerIds.isEmpty()) { + addClauseIfRequired(query, preparedStmtList); + query.append(" reg.id IN (").append(createQuery(registerIds)).append(")"); + preparedStmtList.addAll(registerIds); + } + + if (!ObjectUtils.isEmpty(searchCriteria.getRegisterNumber())) { + String registerNumber = searchCriteria.getRegisterNumber(); + addClauseIfRequired(query, preparedStmtList); + query.append(" reg.registernumber = ? "); + preparedStmtList.add(registerNumber); + } + + if (!ObjectUtils.isEmpty(searchCriteria.getReferenceId())) { + String referenceId = searchCriteria.getReferenceId(); + addClauseIfRequired(query, preparedStmtList); + query.append(" reg.referenceid = ? "); + preparedStmtList.add(referenceId); + } + + if (!ObjectUtils.isEmpty(searchCriteria.getServiceCode())) { + String serviceCode = searchCriteria.getServiceCode(); + addClauseIfRequired(query, preparedStmtList); + query.append(" reg.servicecode = ? "); + preparedStmtList.add(serviceCode); + } + + if (!ObjectUtils.isEmpty(searchCriteria.getName())) { + String name = searchCriteria.getName(); + addClauseIfRequired(query, preparedStmtList); + query.append(" reg.name = ? "); + preparedStmtList.add(name); + } + + if (searchCriteria.getFromDate() != null) { + addClauseIfRequired(query, preparedStmtList); + + //If user does not specify toDate, take today's date as toDate by default. + if (searchCriteria.getToDate() == null) { + searchCriteria.setToDate(BigDecimal.valueOf(Instant.now().toEpochMilli())); + } + + query.append(" reg.startdate BETWEEN ? AND ?"); + preparedStmtList.add(searchCriteria.getFromDate()); + preparedStmtList.add(searchCriteria.getToDate()); + + } else { + //if only toDate is provided as parameter without fromDate parameter, throw an exception. + if (searchCriteria.getToDate() != null) { + throw new CustomException("INVALID_SEARCH_PARAM", "Cannot specify toDate without a fromDate"); + } + } + + if (!ObjectUtils.isEmpty(searchCriteria.getStatus())) { + Status status = searchCriteria.getStatus(); + addClauseIfRequired(query, preparedStmtList); + query.append(" reg.status = ? "); + preparedStmtList.add(status.toString()); + } + + addOrderByClause(query, searchCriteria); + //addLimitAndOffset(query, searchCriteria, preparedStmtList); + return addPaginationWrapper(query.toString(), preparedStmtList, searchCriteria); + } + + private String addPaginationWrapper(String query,List preparedStmtList, + AttendanceRegisterSearchCriteria criteria){ + int limit = config.getAttendanceRegisterDefaultLimit(); + int offset = config.getAttendanceRegisterDefaultOffset(); + + String finalQuery = paginationWrapper.replace("{}",query); + + if(criteria.getLimit()!=null && criteria.getLimit()<=config.getAttendanceRegisterMaxLimit()) + limit = criteria.getLimit(); + + if(criteria.getLimit()!=null && criteria.getLimit()>config.getAttendanceRegisterMaxLimit()) + limit = config.getAttendanceRegisterMaxLimit(); + + if(criteria.getOffset()!=null) + offset = criteria.getOffset(); + + preparedStmtList.add(offset); + preparedStmtList.add(limit+offset); + + return finalQuery; + } + + private void addOrderByClause(StringBuilder queryBuilder, AttendanceRegisterSearchCriteria criteria) { + //default + if (criteria.getSortBy() == null || StringUtils.isEmpty(criteria.getSortBy().name())) { + queryBuilder.append(" ORDER BY reg.lastmodifiedtime "); + } else { + switch (AttendanceRegisterSearchCriteria.SortBy.valueOf(criteria.getSortBy().name())) { + case fromDate: + queryBuilder.append(" ORDER BY reg.startdate "); + break; + case toDate: + queryBuilder.append(" ORDER BY reg.enddate "); + break; + default: + queryBuilder.append(" ORDER BY reg.lastmodifiedtime "); + break; + } + } + + if (criteria.getSortOrder() == AttendanceRegisterSearchCriteria.SortOrder.ASC) + queryBuilder.append(" ASC "); + else queryBuilder.append(" DESC "); + } + + private void addLimitAndOffset(StringBuilder queryBuilder, AttendanceRegisterSearchCriteria criteria, List preparedStmtList) { + queryBuilder.append(" OFFSET ? "); + preparedStmtList.add(criteria.getOffset()); + + queryBuilder.append(" LIMIT ? "); + preparedStmtList.add(criteria.getLimit()); + + } + + private String createQuery(Collection ids) { + StringBuilder builder = new StringBuilder(); + int length = ids.size(); + for (int i = 0; i < length; i++) { + builder.append(" ? "); + if (i != length - 1) builder.append(","); + } + return builder.toString(); + } + + private void addClauseIfRequired(StringBuilder query, List preparedStmtList) { + if (preparedStmtList.isEmpty()) { + query.append(" WHERE "); + } else { + query.append(" AND "); + } + } +} diff --git a/health-services/attendance/src/main/java/org/egov/repository/querybuilder/StaffQueryBuilder.java b/health-services/attendance/src/main/java/org/egov/repository/querybuilder/StaffQueryBuilder.java new file mode 100644 index 00000000000..7e093724b68 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/repository/querybuilder/StaffQueryBuilder.java @@ -0,0 +1,88 @@ +package org.egov.repository.querybuilder; + +import org.egov.web.models.StaffSearchCriteria; +import org.springframework.stereotype.Component; +import org.springframework.util.ObjectUtils; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +@Component +public class StaffQueryBuilder { + + private static final String ATTENDANCE_STAFF_SELECT_QUERY = " SELECT stf.id, " + + "stf.individual_id, " + + "stf.register_id, " + + "stf.tenantid, " + + "stf.enrollment_date , " + + "stf.deenrollment_date, " + + "stf.additionaldetails, " + + "stf.createdby, " + + "stf.lastmodifiedby, " + + "stf.createdtime, " + + "stf.lastmodifiedtime, " + + "stf.tenantid " + + "FROM eg_wms_attendance_staff stf "; + + public String getActiveAttendanceStaffSearchQuery(StaffSearchCriteria criteria, List preparedStmtList) { + StringBuilder query = new StringBuilder(getAttendanceStaffSearchQuery(criteria, preparedStmtList)); + addClauseIfRequired(query, preparedStmtList); + query.append(" stf.deenrollment_date is null "); + + return query.toString(); + } + + public String getAttendanceStaffSearchQuery(StaffSearchCriteria criteria, List preparedStmtList) { + StringBuilder query = new StringBuilder(ATTENDANCE_STAFF_SELECT_QUERY); + + List staffUserIds = criteria.getIndividualIds(); + if (staffUserIds != null && !staffUserIds.isEmpty()) { + addClauseIfRequired(query, preparedStmtList); + query.append(" stf.individual_id IN (").append(createQuery(staffUserIds)).append(")"); + preparedStmtList.addAll(criteria.getIndividualIds()); + } + + List registerIds = criteria.getRegisterIds(); + if (registerIds != null && !registerIds.isEmpty()) { + addClauseIfRequired(query, preparedStmtList); + query.append(" stf.register_id IN (").append(createQuery(registerIds)).append(")"); + preparedStmtList.addAll(criteria.getRegisterIds()); + } + + String tenantId = criteria.getTenantId(); + if (tenantId != null && !tenantId.isEmpty()) { + addClauseIfRequired(query, preparedStmtList); + query.append(" stf.tenantid IN (").append(createQuery(Collections.singletonList(tenantId))).append(")"); + preparedStmtList.add(criteria.getTenantId()); + } + return query.toString(); + } + private void addClauseIfRequired(StringBuilder query, List preparedStmtList) { + if (preparedStmtList.isEmpty()) { + query.append(" WHERE "); + } else { + query.append(" AND "); + } + } + + private String createQuery(Collection ids) { + StringBuilder builder = new StringBuilder(); + int length = ids.size(); + for (int i = 0; i < length; i++) { + builder.append(" ? "); + if (i != length - 1) builder.append(","); + } + return builder.toString(); + } + + + private void addLimitAndOffset(StringBuilder query, StaffSearchCriteria criteria, List preparedStmtList) { + query.append(" OFFSET ? "); + preparedStmtList.add(criteria.getOffset()); + + query.append(" LIMIT ? "); + preparedStmtList.add(criteria.getLimit()); + + } +} diff --git a/health-services/attendance/src/main/java/org/egov/repository/rowmapper/AttendanceLogRowMapper.java b/health-services/attendance/src/main/java/org/egov/repository/rowmapper/AttendanceLogRowMapper.java new file mode 100644 index 00000000000..98ec0fe582b --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/repository/rowmapper/AttendanceLogRowMapper.java @@ -0,0 +1,126 @@ +package org.egov.repository.rowmapper; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import digit.models.coremodels.AuditDetails; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.egov.tracer.model.CustomException; +import org.egov.web.models.AttendanceLog; +import org.egov.web.models.Document; +import org.egov.web.models.Status; +import org.postgresql.util.PGobject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.ResultSetExtractor; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.math.BigDecimal; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.*; + +@Component +@Slf4j +public class AttendanceLogRowMapper implements ResultSetExtractor> { + + @Autowired + @Qualifier("objectMapper") + private ObjectMapper mapper; + + @Override + public List extractData(ResultSet rs) throws SQLException, DataAccessException { + + Map attendanceLogMap = new LinkedHashMap<>(); + + while (rs.next()) { + String id = rs.getString("logid"); + String clientReferenceId = rs.getString("logClientReferenceId"); + String individualId = rs.getString("logIndividualId"); + String tenantId = rs.getString("logTenantId"); + String registerId = rs.getString("logRegisterId"); + String status = rs.getString("logStatus"); + BigDecimal time = rs.getBigDecimal("logTime"); + String eventType = rs.getString("logEventType"); + String createdby = rs.getString("logCreatedBy"); + String lastmodifiedby = rs.getString("logLastModifiedBy"); + Long createdtime = rs.getLong("logCreatedTime"); + Long lastmodifiedtime = rs.getLong("logLastModifiedTime"); + String clientcreatedby = rs.getString("logClientCreatedBy"); + String clientlastmodifiedby = rs.getString("logClientLastModifiedBy"); + Long clientcreatedtime = rs.getLong("logClientCreatedTime"); + Long clientlastmodifiedtime = rs.getLong("logClientLastModifiedTime"); + AuditDetails auditDetails = AuditDetails.builder().createdBy(createdby).createdTime(createdtime) + .lastModifiedBy(lastmodifiedby).lastModifiedTime(lastmodifiedtime) + .build(); + AuditDetails clientAuditDetails = AuditDetails.builder().createdBy(clientcreatedby).createdTime(clientcreatedtime) + .lastModifiedBy(clientlastmodifiedby).lastModifiedTime(clientlastmodifiedtime) + .build(); + JsonNode additionalDetails = getAdditionalDetail("logAdditionalDetails", rs); + + AttendanceLog attendanceLog = AttendanceLog.builder() + .id(id) + .clientReferenceId(clientReferenceId) + .individualId(individualId) + .tenantId(tenantId) + .registerId(registerId) + .status(Status.fromValue(status)) + .time(time) + .type(eventType) + .additionalDetails(additionalDetails) + .auditDetails(auditDetails) + .clientAuditDetails(clientAuditDetails) + .build(); + + if (!attendanceLogMap.containsKey(id)) { + attendanceLogMap.put(id, attendanceLog); + } + + addDocumentsDetails(rs, attendanceLogMap.get(id)); + } + return new ArrayList<>(attendanceLogMap.values()); + } + + private void addDocumentsDetails(ResultSet rs, AttendanceLog attendanceLog) throws SQLException { + String documentId = rs.getString("docId"); + String attendanceLogId = rs.getString("docAttendanceLogId"); + if (StringUtils.isNotBlank(documentId) && attendanceLogId.equalsIgnoreCase(attendanceLog.getId().toString())) { + Document document = Document.builder() + .id(documentId) + .documentType(rs.getString("docDocumentType")) + .fileStore(rs.getString("docFileStoreId")) + .documentUid(rs.getString("docFileStoreId")) + .status(Status.fromValue(rs.getString("docStatus"))) + .build(); + + JsonNode additionalDetails = getAdditionalDetail("docAdditionalDetails", rs); + document.setAdditionalDetails(additionalDetails); + + if (attendanceLog.getDocumentIds() == null || attendanceLog.getDocumentIds().isEmpty()) { + List documentIdList = new LinkedList<>(); + documentIdList.add(document); + attendanceLog.setDocumentIds(documentIdList); + } else { + attendanceLog.getDocumentIds().add(document); + } + } + } + + private JsonNode getAdditionalDetail(String columnName, ResultSet rs) throws SQLException { + JsonNode additionalDetails = null; + try { + PGobject obj = (PGobject) rs.getObject(columnName); + if (obj != null) { + additionalDetails = mapper.readTree(obj.getValue()); + } + } catch (IOException e) { + log.error("Failed to parse additionalDetail object"); + throw new CustomException("PARSING_ERROR", "Failed to parse additionalDetail object"); + } + if (additionalDetails.isEmpty()) + additionalDetails = null; + return additionalDetails; + } +} diff --git a/health-services/attendance/src/main/java/org/egov/repository/rowmapper/AttendeeRowMapper.java b/health-services/attendance/src/main/java/org/egov/repository/rowmapper/AttendeeRowMapper.java new file mode 100644 index 00000000000..b6c0bcdbd0c --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/repository/rowmapper/AttendeeRowMapper.java @@ -0,0 +1,83 @@ +package org.egov.repository.rowmapper; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import digit.models.coremodels.AuditDetails; +import org.egov.tracer.model.CustomException; +import org.egov.web.models.IndividualEntry; +import org.postgresql.util.PGobject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.ResultSetExtractor; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.math.BigDecimal; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.*; + +@Component +public class AttendeeRowMapper implements ResultSetExtractor> { + + @Autowired + @Qualifier("objectMapper") + private ObjectMapper mapper; + + @Override + public List extractData(ResultSet rs) throws SQLException, DataAccessException { + Map attendanceAttendeeMap = new LinkedHashMap<>(); + while (rs.next()) { + String id = rs.getString("id"); + String registerId = rs.getString("register_id"); + String individuaId = rs.getString("individual_id"); + String tenantId= rs.getString("tenantid"); + BigDecimal enrollmentDate = rs.getBigDecimal("enrollment_date"); + BigDecimal deenrollmentDate = rs.getBigDecimal("deenrollment_date"); + String createdby = rs.getString("createdby"); + String lastmodifiedby = rs.getString("lastmodifiedby"); + Long createdtime = rs.getLong("createdtime"); + Long lastmodifiedtime = rs.getLong("lastmodifiedtime"); + + AuditDetails auditDetails = AuditDetails.builder().createdBy(createdby).createdTime(createdtime) + .lastModifiedBy(lastmodifiedby).lastModifiedTime(lastmodifiedtime) + .build(); + + JsonNode additionalDetails = getAdditionalDetail("additionaldetails", rs); + + IndividualEntry attendanceAttendee = IndividualEntry.builder() + .additionalDetails(additionalDetails) + .id(id) + .individualId(individuaId) + .registerId(registerId) + .tenantId(tenantId) + .additionalDetails(additionalDetails) + .enrollmentDate(enrollmentDate) + .denrollmentDate(deenrollmentDate) + .auditDetails(auditDetails) + .build(); + + if (!attendanceAttendeeMap.containsKey(id)) { + attendanceAttendeeMap.put(id, attendanceAttendee); + } + } + return new ArrayList<>(attendanceAttendeeMap.values()); + + } + + private JsonNode getAdditionalDetail(String columnName, ResultSet rs) throws SQLException { + JsonNode additionalDetails = null; + try { + PGobject obj = (PGobject) rs.getObject(columnName); + if (obj != null) { + additionalDetails = mapper.readTree(obj.getValue()); + } + } catch (IOException e) { + throw new CustomException("PARSING ERROR", "Failed to parse additionalDetail object"); + } + if (additionalDetails.isEmpty()) + additionalDetails = null; + return additionalDetails; + } +} diff --git a/health-services/attendance/src/main/java/org/egov/repository/rowmapper/RegisterRowMapper.java b/health-services/attendance/src/main/java/org/egov/repository/rowmapper/RegisterRowMapper.java new file mode 100644 index 00000000000..90e44065b72 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/repository/rowmapper/RegisterRowMapper.java @@ -0,0 +1,94 @@ +package org.egov.repository.rowmapper; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import digit.models.coremodels.AuditDetails; +import org.egov.tracer.model.CustomException; +import org.egov.web.models.AttendanceRegister; +import org.egov.web.models.Status; +import org.postgresql.util.PGobject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.ResultSetExtractor; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.math.BigDecimal; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +@Component +public class RegisterRowMapper implements ResultSetExtractor> { + + @Autowired + @Qualifier("objectMapper") + private ObjectMapper mapper; + + @Override + public List extractData(ResultSet rs) throws SQLException, DataAccessException { + + Map attendanceRegisterMap = new LinkedHashMap<>(); + + while (rs.next()) { + String id = rs.getString("id"); + String tenantId = rs.getString("tenantid"); + String registerNumber = rs.getString("registernumber"); + String name = rs.getString("name"); + BigDecimal startDate = rs.getBigDecimal("startdate"); + BigDecimal endDate = rs.getBigDecimal("enddate"); + String status = rs.getString("status"); + String createdby = rs.getString("createdby"); + String lastmodifiedby = rs.getString("lastmodifiedby"); + Long createdtime = rs.getLong("createdtime"); + Long lastmodifiedtime = rs.getLong("lastmodifiedtime"); + String referenceId = rs.getString("referenceid"); + String serviceCode = rs.getString("servicecode"); + + AuditDetails auditDetails = AuditDetails.builder().createdBy(createdby).createdTime(createdtime) + .lastModifiedBy(lastmodifiedby).lastModifiedTime(lastmodifiedtime) + .build(); + + JsonNode additionalDetails = getAdditionalDetail("additionaldetails", rs); + + AttendanceRegister attendanceRegister = AttendanceRegister.builder() + .additionalDetails(additionalDetails) + .id(id) + .tenantId(tenantId) + .status(Status.fromValue(status)) + .registerNumber(registerNumber) + .referenceId(referenceId) + .serviceCode(serviceCode) + .name(name) + .startDate(startDate) + .endDate(endDate) + .auditDetails(auditDetails) + .build(); + + if (!attendanceRegisterMap.containsKey(id)) { + attendanceRegisterMap.put(id, attendanceRegister); + } + } + return new ArrayList<>(attendanceRegisterMap.values()); + + } + + private JsonNode getAdditionalDetail(String columnName, ResultSet rs) throws SQLException { + JsonNode additionalDetails = null; + try { + PGobject obj = (PGobject) rs.getObject(columnName); + if (obj != null) { + additionalDetails = mapper.readTree(obj.getValue()); + } + } catch (IOException e) { + throw new CustomException("PARSING ERROR", "Failed to parse additionalDetail object"); + } + if (additionalDetails.isEmpty()) + additionalDetails = null; + return additionalDetails; + } +} diff --git a/health-services/attendance/src/main/java/org/egov/repository/rowmapper/StaffRowMapper.java b/health-services/attendance/src/main/java/org/egov/repository/rowmapper/StaffRowMapper.java new file mode 100644 index 00000000000..38b99cad257 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/repository/rowmapper/StaffRowMapper.java @@ -0,0 +1,86 @@ +package org.egov.repository.rowmapper; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import digit.models.coremodels.AuditDetails; +import org.egov.tracer.model.CustomException; +import org.egov.web.models.StaffPermission; +import org.postgresql.util.PGobject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.ResultSetExtractor; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.math.BigDecimal; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +@Component +public class StaffRowMapper implements ResultSetExtractor> { + + @Autowired + @Qualifier("objectMapper") + private ObjectMapper mapper; + + @Override + public List extractData(ResultSet rs) throws SQLException, DataAccessException { + Map attendanceStaffMap = new LinkedHashMap<>(); + while (rs.next()) { + String id = rs.getString("id"); + String tenantId = rs.getString("tenantid"); + String individuaId = rs.getString("individual_id"); + String registerId = rs.getString("register_id"); + BigDecimal enrollmentDate = rs.getBigDecimal("enrollment_date"); + BigDecimal deenrollmentDate = rs.getBigDecimal("deenrollment_date"); + String createdby = rs.getString("createdby"); + String lastmodifiedby = rs.getString("lastmodifiedby"); + Long createdtime = rs.getLong("createdtime"); + Long lastmodifiedtime = rs.getLong("lastmodifiedtime"); + + AuditDetails auditDetails = AuditDetails.builder().createdBy(createdby).createdTime(createdtime) + .lastModifiedBy(lastmodifiedby).lastModifiedTime(lastmodifiedtime) + .build(); + + JsonNode additionalDetails = getAdditionalDetail("additionaldetails", rs); + + StaffPermission attendanceStaff = StaffPermission.builder() + .additionalDetails(additionalDetails) + .id(id) + .tenantId(tenantId) + .userId(individuaId) + .registerId(registerId) + .additionalDetails(additionalDetails) + .enrollmentDate(enrollmentDate) + .denrollmentDate(deenrollmentDate) + .auditDetails(auditDetails) + .build(); + + if (!attendanceStaffMap.containsKey(id)) { + attendanceStaffMap.put(id, attendanceStaff); + } + } + return new ArrayList<>(attendanceStaffMap.values()); + } + + + private JsonNode getAdditionalDetail(String columnName, ResultSet rs) throws SQLException { + JsonNode additionalDetails = null; + try { + PGobject obj = (PGobject) rs.getObject(columnName); + if (obj != null) { + additionalDetails = mapper.readTree(obj.getValue()); + } + } catch (IOException e) { + throw new CustomException("PARSING ERROR", "Failed to parse additionalDetail object"); + } + if (additionalDetails.isEmpty()) + additionalDetails = null; + return additionalDetails; + } +} diff --git a/health-services/attendance/src/main/java/org/egov/service/AttendanceLogService.java b/health-services/attendance/src/main/java/org/egov/service/AttendanceLogService.java new file mode 100644 index 00000000000..a55dd69aebb --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/service/AttendanceLogService.java @@ -0,0 +1,108 @@ +package org.egov.service; + +import lombok.extern.slf4j.Slf4j; +import org.egov.common.contract.response.ResponseInfo; +import org.egov.config.AttendanceServiceConfiguration; +import org.egov.enrichment.AttendanceLogEnrichment; +import org.egov.common.producer.Producer; +import org.egov.web.models.AttendanceLogSearchCriteria; +import org.egov.repository.AttendanceLogRepository; +import org.egov.util.ResponseInfoFactory; +import org.egov.validator.AttendanceLogServiceValidator; +import org.egov.web.models.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@Slf4j +public class AttendanceLogService { + @Autowired + private AttendanceLogServiceValidator attendanceLogServiceValidator; + + @Autowired + private ResponseInfoFactory responseInfoFactory; + + + @Autowired + private AttendanceLogEnrichment attendanceLogEnricher; + + @Autowired + private Producer producer; + + @Autowired + private AttendanceServiceConfiguration config; + + @Autowired + private AttendanceLogRepository attendanceLogRepository; + + /** + * Create Attendance Log + * + * @param attendanceLogRequest + * @return attendanceLogResponse + */ + public AttendanceLogResponse createAttendanceLog(AttendanceLogRequest attendanceLogRequest) { + //Validate the incoming request + attendanceLogServiceValidator.validateCreateAttendanceLogRequest(attendanceLogRequest); + //Enrich the incoming request + attendanceLogEnricher.enrichAttendanceLogCreateRequest(attendanceLogRequest); + // Push the request object to the topic for persister to listen and persist + producer.push(config.getCreateAttendanceLogTopic(), attendanceLogRequest); + // Create the response + ResponseInfo responseInfo = responseInfoFactory.createResponseInfoFromRequestInfo(attendanceLogRequest.getRequestInfo(), true); + AttendanceLogResponse attendanceLogResponse = AttendanceLogResponse.builder().responseInfo(responseInfo).attendance(attendanceLogRequest.getAttendance()).build(); + String registerId = attendanceLogRequest.getAttendance().get(0).getRegisterId(); + log.info("Attendance logs created successfully for register ["+registerId+"]"); + return attendanceLogResponse; + } + + /** + * Search attendace logs based on given search criteria + * + * @param requestInfoWrapper + * @param searchCriteria + * @return attendanceLogResponse + */ + public AttendanceLogResponse searchAttendanceLog(RequestInfoWrapper requestInfoWrapper, AttendanceLogSearchCriteria searchCriteria) { + //Validate the incoming request + attendanceLogServiceValidator.validateSearchAttendanceLogRequest(requestInfoWrapper, searchCriteria); + //Enrich the incoming request + attendanceLogEnricher.enrichAttendanceLogSearchRequest(requestInfoWrapper.getRequestInfo(), searchCriteria); + //Fetch attendance logs from registry + List attendanceLogs = attendanceLogRepository.getAttendanceLogs(searchCriteria); + // Create the response + ResponseInfo responseInfo = responseInfoFactory.createResponseInfoFromRequestInfo(requestInfoWrapper.getRequestInfo(), true); + AttendanceLogResponse attendanceLogResponse = AttendanceLogResponse.builder().responseInfo(responseInfo).attendance(attendanceLogs).build(); + log.info("Attendance log response created for register ["+searchCriteria.getRegisterId()+"]"); + return attendanceLogResponse; + } + + /** + * Update the given attendance log details + * + * @param attendanceLogRequest + * @return AttendanceLogResponse + */ + public AttendanceLogResponse updateAttendanceLog(AttendanceLogRequest attendanceLogRequest) { + //Validate the incoming request + attendanceLogServiceValidator.validateUpdateAttendanceLogRequest(attendanceLogRequest); + //Enrich the incoming request + attendanceLogEnricher.enrichAttendanceLogUpdateRequest(attendanceLogRequest); + // Push the request object to the topic for persister to listen and persist + producer.push(config.getUpdateAttendanceLogTopic(), attendanceLogRequest); + // Create the response + ResponseInfo responseInfo = responseInfoFactory.createResponseInfoFromRequestInfo(attendanceLogRequest.getRequestInfo(), true); + AttendanceLogResponse attendanceLogResponse = AttendanceLogResponse.builder().responseInfo(responseInfo).attendance(attendanceLogRequest.getAttendance()).build(); + String registerId = attendanceLogRequest.getAttendance().get(0).getRegisterId(); + log.info("Attendance logs updated successfully for register ["+registerId+"]"); + return attendanceLogResponse; + } + + public void putInCache(List attendanceLogs) { + log.info("putting {} Attendance Logs in cache", attendanceLogs.size()); + attendanceLogRepository.putInCache(attendanceLogs); + log.info("successfully put Attendance Logs in cache"); + } +} diff --git a/health-services/attendance/src/main/java/org/egov/service/AttendanceRegisterService.java b/health-services/attendance/src/main/java/org/egov/service/AttendanceRegisterService.java new file mode 100644 index 00000000000..706bccd09b4 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/service/AttendanceRegisterService.java @@ -0,0 +1,366 @@ +package org.egov.service; + +import digit.models.coremodels.RequestInfoWrapper; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.egov.common.contract.request.RequestInfo; +import org.egov.common.contract.request.Role; +import org.egov.config.AttendanceServiceConfiguration; +import org.egov.enrichment.RegisterEnrichment; +import org.egov.enrichment.StaffEnrichmentService; +import org.egov.common.producer.Producer; +import org.egov.repository.AttendeeRepository; +import org.egov.repository.RegisterRepository; +import org.egov.tracer.model.CustomException; +import org.egov.util.IndividualServiceUtil; +import org.egov.util.ResponseInfoFactory; +import org.egov.validator.AttendanceServiceValidator; +import org.egov.web.models.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.*; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class AttendanceRegisterService { + @Autowired + private AttendanceServiceValidator attendanceServiceValidator; + + @Autowired + private ResponseInfoFactory responseInfoFactory; + + @Autowired + private Producer producer; + + @Autowired + private AttendanceServiceConfiguration attendanceServiceConfiguration; + + @Autowired + private RegisterEnrichment registerEnrichment; + + + @Autowired + private StaffService staffService; + + @Autowired + private RegisterRepository registerRepository; + + @Autowired + private AttendeeRepository attendeeRepository; + + @Autowired + private StaffEnrichmentService staffEnrichmentService; + @Autowired + private IndividualServiceUtil individualServiceUtil; + + /** + * Create Attendance register + * + * @param request + * @return + */ + public AttendanceRegisterRequest createAttendanceRegister(AttendanceRegisterRequest request) { + attendanceServiceValidator.validateCreateAttendanceRegister(request); + registerEnrichment.enrichRegisterOnCreate(request); + log.info("Enriched Register with Register number, Ids, first staff and audit details"); + producer.push(attendanceServiceConfiguration.getSaveAttendanceRegisterTopic(), request); + log.info("Pushed create attendance register request to kafka"); + return request; + } + + /** + * Search attendance register based on given search criteria + * + * @param requestInfoWrapper + * @param searchCriteria + * @return + */ + public List searchAttendanceRegister(RequestInfoWrapper requestInfoWrapper, AttendanceRegisterSearchCriteria searchCriteria) { + //Validate the requested parameters + attendanceServiceValidator.validateSearchRegisterRequest(requestInfoWrapper, searchCriteria); + + //Enrich requested search criteria + registerEnrichment.enrichSearchRegisterRequest(requestInfoWrapper.getRequestInfo(),searchCriteria); + + //Get the logged-in user roles + Set userRoles = getUserRoleCodes(requestInfoWrapper.getRequestInfo()); + + //Get the roles enabled for open serach + Set openSearchEnabledRoles = getRegisterOpenSearchEnabledRoles(); + + List resultAttendanceRegisters = new ArrayList<>(); + + if(isUserEnabledForOpenSearch(userRoles,openSearchEnabledRoles)){ + /* + User having the role to perform open search on attendance register. + */ + log.info("Searching registers for Superuser or Engineer"); + fetchAndFilterRegisters(searchCriteria, resultAttendanceRegisters); + }else{ + /* + Make sure response register list should contain only those register for which logged-in is associated. + */ + Long userId = requestInfoWrapper.getRequestInfo().getUserInfo().getId(); + + String individualId = individualServiceUtil.getIndividualDetailsFromUserId(userId,requestInfoWrapper.getRequestInfo(), searchCriteria.getTenantId()).get(0).getId(); + Set registers = fetchRegistersAssociatedToLoggedInStaffUser(individualId); + updateSearchCriteriaAndFetchAndFilterRegisters(registers, searchCriteria, resultAttendanceRegisters); + } + return resultAttendanceRegisters; + } + + private boolean isUserEnabledForOpenSearch(Set userRoles, Set openSearchEnabledRoles) { + for(String userRole : userRoles){ + if(openSearchEnabledRoles.contains(userRole)){ + return true; + } + } + return false; + } + + private Set getRegisterOpenSearchEnabledRoles() { + Set openSearchEnabledRoles = new HashSet<>(); + String registerOpenSearchEnabledRoles = attendanceServiceConfiguration.getRegisterOpenSearchEnabledRoles(); + if(!StringUtils.isBlank(registerOpenSearchEnabledRoles)){ + String[] roles = registerOpenSearchEnabledRoles.split(","); + for(String role :roles){ + if(!StringUtils.isBlank(role)){ + openSearchEnabledRoles.add(role); + } + } + } + return openSearchEnabledRoles; + } + + /** + * Update the search criteria with list of registerIds if it does not contain registerId + * then fetch the all registers based on the search criteria + * but keep only those registers at last which contains attendees or staff in given search criteria + * + * @param registers + * @param searchCriteria + * @param resultAttendanceRegisters + */ + public void updateSearchCriteriaAndFetchAndFilterRegisters(Set registers, AttendanceRegisterSearchCriteria searchCriteria, List resultAttendanceRegisters) { + + if (registers == null || registers.isEmpty()) { + log.info("Registers are empty or null"); + return; + } + if (searchCriteria.getIds() == null) { + log.info("Register search criteria does not contain any register ids"); + List registerIds = new ArrayList<>(); + registerIds.addAll(registers); + searchCriteria.setIds(registerIds); + } else { + log.info("Register search criteria does contains register ids"); + for (String id : searchCriteria.getIds()) { + if (!registers.contains(id)) { + log.error( "User can search only associated registers"); + throw new CustomException("INVALID_REGISTER_ID", "User can search only associated registers"); + } + } + } + fetchAndFilterRegisters(searchCriteria, resultAttendanceRegisters); + } + + /** + * Fetch the all registers based on the supplied search criteria + * but keep only those registers which contains attendees or staff given in search criteria + * + * @param searchCriteria + * @param resultAttendanceRegisters + */ + private void fetchAndFilterRegisters(AttendanceRegisterSearchCriteria searchCriteria, List resultAttendanceRegisters) { + log.info("Fetching registers based on supplied search criteria"); + // Fetch the all registers based on the supplied search criteria + List attendanceRegisters = registerRepository.getRegister(searchCriteria); + // Create a map with key as registerId and corresponding register list as value + Map> registerIdVsAttendanceRegisters = attendanceRegisters.stream().collect(Collectors.groupingBy(AttendanceRegister::getId)); + + List registerIdsToSearch = new ArrayList<>(); + registerIdsToSearch.addAll(registerIdVsAttendanceRegisters.keySet()); + + // Fetch and filer staff members based on the supplied search criteria. + log.info("Fetch all staff members based on the supplied search criteria"); + List staffMembers = fetchAllStaffMembersAssociatedToRegisterIds(registerIdsToSearch,searchCriteria); + // Create a map with key as registerId and corresponding staff list as value + Map> registerIdStaffMapping = staffMembers.stream().collect(Collectors.groupingBy(StaffPermission::getRegisterId)); + + // If staffId present in search criteria then update the registerIDToSearch list with new set of registerIds + if (searchCriteria.getStaffId() != null){ + registerIdsToSearch.clear(); + registerIdsToSearch.addAll(registerIdStaffMapping.keySet()); + } + + // Fetch and filer attendees based on the supplied search criteria. + List attendees = fetchAllAttendeesAssociatedToRegisterIds(registerIdsToSearch,searchCriteria); + // Create a map with key as registerId and corresponding attendee list as value + Map> registerIdAttendeeMapping = attendees.stream().collect(Collectors.groupingBy(IndividualEntry::getRegisterId)); + + // If AttendeeId present in search criteria then update the registerIDToSearch list with new set of registerIds + if(searchCriteria.getAttendeeId() != null){ + List registerIdsAssociatedToAttendees = new ArrayList<>(); + registerIdsAssociatedToAttendees.addAll(registerIdAttendeeMapping.keySet()); + registerIdsToSearch.clear(); + registerIdsToSearch.addAll(registerIdsAssociatedToAttendees); + } + + // Populate final list of registers to be return + for(String registerId : registerIdsToSearch ){ + List registers = registerIdVsAttendanceRegisters.get(registerId); + for(AttendanceRegister register : registers){ + register.setStaff(registerIdStaffMapping.get(registerId)); + register.setAttendees(registerIdAttendeeMapping.get(registerId)); + resultAttendanceRegisters.add(register); + } + } + } + + private List fetchAllAttendeesAssociatedToRegisterIds(List registerIdsToSearch, AttendanceRegisterSearchCriteria searchCriteria) { + AttendeeSearchCriteria attendeeSearchCriteria = null; + if(searchCriteria.getAttendeeId() != null){ + attendeeSearchCriteria = AttendeeSearchCriteria.builder().registerIds(registerIdsToSearch).individualIds(Collections.singletonList(searchCriteria.getAttendeeId())).build(); + } else { + attendeeSearchCriteria = AttendeeSearchCriteria.builder().registerIds(registerIdsToSearch).build(); + } + return attendeeRepository.getAttendees(attendeeSearchCriteria); + } + + /* Get all staff members associated for the register */ + private List fetchAllStaffMembersAssociatedToRegisterIds(List registerIdsToSearch, AttendanceRegisterSearchCriteria searchCriteria) { + StaffSearchCriteria staffSearchCriteria = null ; + if(searchCriteria.getStaffId() != null){ + staffSearchCriteria = StaffSearchCriteria.builder().registerIds(registerIdsToSearch).individualIds(Collections.singletonList(searchCriteria.getStaffId())).build(); + } else { + staffSearchCriteria = StaffSearchCriteria.builder().registerIds(registerIdsToSearch).build(); + } + return staffService.getAllStaff(staffSearchCriteria); + } + + /* Returns list of user roles */ + private Set getUserRoleCodes(RequestInfo requestInfo) { + Set userRoles = new HashSet<>(); + List roles = requestInfo.getUserInfo().getRoles(); + if(roles == null) + return userRoles; + return roles.stream().map(e->e.getCode()).collect(Collectors.toSet()); + } + + /* Get all registers associated for the logged in staff */ + private Set fetchRegistersAssociatedToLoggedInStaffUser(String uuid) { + List individualIds = new ArrayList<>(); + individualIds.add(uuid); + StaffSearchCriteria staffSearchCriteria = StaffSearchCriteria.builder().individualIds(individualIds).build(); + List staffMembers = staffService.getAllStaff(staffSearchCriteria); + return staffMembers.stream().map(e -> e.getRegisterId()).collect(Collectors.toSet()); + } + + /* Get all registers associated for the logged in attendee */ + private Set fetchRegistersAssociatedToLoggedInAttendeeUser(String uuid) { + AttendeeSearchCriteria attendeeSearchCriteria = AttendeeSearchCriteria.builder().individualIds(Collections.singletonList(uuid)).build(); + List attendees = attendeeRepository.getAttendees(attendeeSearchCriteria); + return attendees.stream().map(e -> e.getRegisterId()).collect(Collectors.toSet()); + } + + /** + * Update the given attendance register details + * + * @param attendanceRegisterRequest + * @return + */ + public AttendanceRegisterRequest updateAttendanceRegister(AttendanceRegisterRequest attendanceRegisterRequest) { + attendanceServiceValidator.validateUpdateAttendanceRegisterRequest(attendanceRegisterRequest); + log.info("Validated update attendance register request"); + + //Create requestInfoWrapper from attendanceRegister request, collect ids in list for search attendance register request parameters + RequestInfoWrapper requestInfoWrapper = RequestInfoWrapper.builder().requestInfo(attendanceRegisterRequest.getRequestInfo()).build(); + List registerIds = getAttendanceRegisterIdList(attendanceRegisterRequest); + String tenantId = attendanceRegisterRequest.getAttendanceRegister().get(0).getTenantId(); + //Get Attendance registers from DB based on register ids, tenantId and requestInfo + List attendanceRegistersFromDB = getAttendanceRegisters(requestInfoWrapper, registerIds, tenantId); + log.info("Fetched attendance registers for update request"); + + //Validate Update attendance register request against attendance registers fetched from database + attendanceServiceValidator.validateUpdateAgainstDB(attendanceRegisterRequest, attendanceRegistersFromDB); + + registerEnrichment.enrichRegisterOnUpdate(attendanceRegisterRequest, attendanceRegistersFromDB); + log.info("Enriched with register Number, Ids and AuditDetails"); + producer.push(attendanceServiceConfiguration.getUpdateAttendanceRegisterTopic(), attendanceRegisterRequest); + log.info("Pushed update attendance register request to kafka"); + + return attendanceRegisterRequest; + } + + public List getAttendanceRegisters(RequestInfoWrapper requestInfoWrapper, List registerIds, String tenantId) { + + //Search criteria for attendance register search request + AttendanceRegisterSearchCriteria searchCriteria = AttendanceRegisterSearchCriteria.builder().ids(registerIds) + .tenantId(tenantId).build(); + List attendanceRegisterList; + + // Calls search attendance register with created request. If some error in searching attendance register, throws error + try { + attendanceRegisterList = searchAttendanceRegister(requestInfoWrapper, searchCriteria); + log.info("Attendance register search successful"); + } catch (Exception e) { + log.info("Error in searching attendance register", e); + throw new CustomException("SEARCH_ATTENDANCE_REGISTER", "Error in searching attendance register"); + } + + return attendanceRegisterList; + } + + /* Get attendance registers Id list from attendance register request */ + private List getAttendanceRegisterIdList(AttendanceRegisterRequest request) { + List attendanceRegisters = request.getAttendanceRegister(); + + List registerIds = new ArrayList<>(); + for (AttendanceRegister attendanceRegister : attendanceRegisters) { + registerIds.add(String.valueOf(attendanceRegister.getId())); + } + return registerIds; + } + + /** + * Validate and update the end date of Attendance register as per revised contract + * @param requestInfo + * @param tenantId + * @param referenceId + * @param endDate + */ + public void updateEndDateForRevisedContract(RequestInfo requestInfo, String tenantId, String referenceId, BigDecimal endDate) { + AttendanceRegisterSearchCriteria attendanceRegisterSearchCriteria = AttendanceRegisterSearchCriteria.builder() + .tenantId(tenantId) + .referenceId(referenceId) + .limit(attendanceServiceConfiguration.getAttendanceRegisterDefaultLimit()) + .offset(attendanceServiceConfiguration.getAttendanceRegisterDefaultOffset()).build(); + + + List attendanceRegisters = registerRepository.getRegister(attendanceRegisterSearchCriteria); + + if (attendanceRegisters != null && !attendanceRegisters.isEmpty()) { + for (AttendanceRegister attendanceRegister : attendanceRegisters) { + int comparisonResult = endDate.compareTo(attendanceRegister.getEndDate()); + if (comparisonResult < 0) { + throw new CustomException("END_DATE_NOT_EXTENDED","End date should not be earlier than previous end date"); + } + + attendanceRegister.setEndDate(endDate); + AttendanceRegisterRequest attendanceRegisterRequest = AttendanceRegisterRequest.builder() + .attendanceRegister(Collections.singletonList(attendanceRegister)). + requestInfo(requestInfo).build(); + + registerEnrichment.enrichRegisterOnUpdate(attendanceRegisterRequest, Collections.singletonList(attendanceRegister)); + producer.push(attendanceServiceConfiguration.getUpdateAttendanceRegisterTopic(), attendanceRegisterRequest); + } + }else { + throw new CustomException("ATTENDANCE_REGISTER_NOT_FOUND", "Attendance registers not found for the referenceId"); + } + + } + +} diff --git a/health-services/attendance/src/main/java/org/egov/service/AttendeeService.java b/health-services/attendance/src/main/java/org/egov/service/AttendeeService.java new file mode 100644 index 00000000000..25720638704 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/service/AttendeeService.java @@ -0,0 +1,191 @@ +package org.egov.service; + +import digit.models.coremodels.RequestInfoWrapper; +import lombok.extern.slf4j.Slf4j; +import org.egov.config.AttendanceServiceConfiguration; +import org.egov.enrichment.AttendeeEnrichmentService; +import org.egov.common.producer.Producer; +import org.egov.repository.AttendeeRepository; +import org.egov.util.ResponseInfoFactory; +import org.egov.validator.AttendanceServiceValidator; +import org.egov.validator.AttendeeServiceValidator; +import org.egov.web.models.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +@Slf4j +public class AttendeeService { + @Autowired + private AttendeeServiceValidator attendeeServiceValidator; + + @Autowired + private ResponseInfoFactory responseInfoFactory; + + @Autowired + private AttendeeRepository attendeeRepository; + + @Autowired + private AttendanceRegisterService attendanceRegisterService; + + @Autowired + private AttendanceServiceValidator attendanceServiceValidator; + + @Autowired + private AttendeeEnrichmentService attendeeEnrichmentService; + + @Autowired + private AttendanceServiceConfiguration attendanceServiceConfiguration; + + @Autowired + private Producer producer; + + + /** + * Create Attendee + * + * @param attendeeCreateRequest + * @return + */ + public AttendeeCreateRequest createAttendee(AttendeeCreateRequest attendeeCreateRequest) { + //incoming createRequest validation + log.info("validating create attendee request parameters"); + attendeeServiceValidator.validateAttendeeCreateRequestParameters(attendeeCreateRequest); + + //extract registerIds and attendee IndividualIds from client request + String tenantId = attendeeCreateRequest.getAttendees().get(0).getTenantId(); + List attendeeIds = extractAttendeeIdsFromCreateRequest(attendeeCreateRequest); + List registerIds = extractRegisterIdsFromCreateRequest(attendeeCreateRequest); + + //db call to get the attendeeList data + List attendeeListFromDB = getAttendees(registerIds,attendeeIds); + + //db call to get registers from db + List attendanceRegisterListFromDB = getAttendanceRegisters(attendeeCreateRequest,registerIds,tenantId); + + //validate registers from request with registers from DB + log.info("validating register ids from request against DB"); + attendanceServiceValidator.validateRegisterAgainstDB(registerIds, attendanceRegisterListFromDB, tenantId); + + + //validator call by passing attendee request and the data from db call + log.info("attendeeServiceValidator called to validate Create attendee request"); + attendeeServiceValidator.validateAttendeeOnCreate(attendeeCreateRequest, attendeeListFromDB, attendanceRegisterListFromDB); + + //enrichment call by passing attendee request and data from db call + log.info("attendeeServiceValidator called to enrich Create attendee request"); + attendeeEnrichmentService.enrichAttendeeOnCreate(attendeeCreateRequest); + + //push to producer + log.info("attendee objects pushed via producer"); + producer.push(attendanceServiceConfiguration.getSaveAttendeeTopic(), attendeeCreateRequest); + log.info("attendees present in Create attendee request are enrolled to the registers"); + return attendeeCreateRequest; + } + + public List getAttendees(List registerIds,List attendeeIds){ + AttendeeSearchCriteria attendeeSearchCriteria = AttendeeSearchCriteria.builder().registerIds(registerIds).individualIds(attendeeIds).build(); + List attendeeListFromDB = attendeeRepository.getAttendees(attendeeSearchCriteria); + log.info("attendee List received From DB : " + attendeeListFromDB.size()); + return attendeeListFromDB; + } + + public List getAttendanceRegisters(AttendeeCreateRequest attendeeCreateRequest,List registerIds,String tenantId){ + RequestInfoWrapper requestInfoWrapper = RequestInfoWrapper.builder().requestInfo(attendeeCreateRequest.getRequestInfo()).build(); + List attendanceRegisterListFromDB = attendanceRegisterService.getAttendanceRegisters(requestInfoWrapper, registerIds, tenantId); + log.info("attendance register List received From DB : " + attendanceRegisterListFromDB.size()); + return attendanceRegisterListFromDB; + } + + public List getAttendanceRegisters(AttendeeDeleteRequest attendeeDeleteRequest,List registerIds,String tenantId){ + RequestInfoWrapper requestInfoWrapper = RequestInfoWrapper.builder().requestInfo(attendeeDeleteRequest.getRequestInfo()).build(); + List attendanceRegisterListFromDB = attendanceRegisterService.getAttendanceRegisters(requestInfoWrapper, registerIds, tenantId); + log.info("attendance register List received From DB : " + attendanceRegisterListFromDB.size()); + return attendanceRegisterListFromDB; + } + + /** + * Update(Soft Delete) the given attendee + * + * @param + * @return + */ + public AttendeeDeleteRequest deleteAttendee(AttendeeDeleteRequest attendeeDeleteRequest) { + //incoming deleteRequest validation + log.info("validating delete attendee request parameters"); + Map errorMap = new HashMap<>(); + attendeeServiceValidator.validateAttendeeDeleteRequestParameters(attendeeDeleteRequest, errorMap); + + //extract registerIds and attendee IndividualIds from client request + String tenantId = attendeeDeleteRequest.getAttendees().get(0).getTenantId(); + List attendeeIds = extractAttendeeIdsFromDeleteRequest(attendeeDeleteRequest); + List registerIds = extractRegisterIdsFromDeleteRequest(attendeeDeleteRequest); + + //db call to get the attendeeList data + List attendeeListFromDB = getAttendees(registerIds,attendeeIds); + + //db call to get registers from db + List attendanceRegisterListFromDB = getAttendanceRegisters(attendeeDeleteRequest,registerIds,tenantId); + + //validate request registers with registers from DB + log.info("validating register ids from request against DB"); + attendanceServiceValidator.validateRegisterAgainstDB(registerIds, attendanceRegisterListFromDB, tenantId); + + + //validator call by passing attendee request and the data from db call + log.info("validating delete attendee request"); + attendeeServiceValidator.validateAttendeeOnDelete(attendeeDeleteRequest, attendeeListFromDB, attendanceRegisterListFromDB); + + //enrichment call by passing attendee request and data from db call + log.info("enriching delete attendee request"); + attendeeEnrichmentService.enrichAttendeeOnDelete(attendeeDeleteRequest, attendeeListFromDB); + + //push to producer + log.info("attendee objects updated via producer"); + producer.push(attendanceServiceConfiguration.getUpdateAttendeeTopic(), attendeeDeleteRequest); + log.info("attendees present in delete attendee request are deenrolled from the registers"); + return attendeeDeleteRequest; + } + + + private List extractRegisterIdsFromCreateRequest(AttendeeCreateRequest attendeeCreateRequest) { + List attendeeListFromRequest = attendeeCreateRequest.getAttendees(); + List registerIds = new ArrayList<>(); + for (IndividualEntry attendee : attendeeListFromRequest) { + registerIds.add(attendee.getRegisterId()); + } + return registerIds; + } + + private List extractAttendeeIdsFromCreateRequest(AttendeeCreateRequest attendeeCreateRequest) { + List attendeeListFromRequest = attendeeCreateRequest.getAttendees(); + List attendeeIds = new ArrayList<>(); + for (IndividualEntry attendee : attendeeListFromRequest) { + attendeeIds.add(attendee.getIndividualId()); + } + return attendeeIds; + } + + private List extractRegisterIdsFromDeleteRequest(AttendeeDeleteRequest attendeeDeleteRequest) { + List attendeeListFromRequest = attendeeDeleteRequest.getAttendees(); + List registerIds = new ArrayList<>(); + for (IndividualEntry attendee : attendeeListFromRequest) { + registerIds.add(attendee.getRegisterId()); + } + return registerIds; + } + + private List extractAttendeeIdsFromDeleteRequest(AttendeeDeleteRequest attendeeDeleteRequest) { + List attendeeListFromRequest = attendeeDeleteRequest.getAttendees(); + List attendeeIds = new ArrayList<>(); + for (IndividualEntry attendee : attendeeListFromRequest) { + attendeeIds.add(attendee.getIndividualId()); + } + return attendeeIds; + } +} diff --git a/health-services/attendance/src/main/java/org/egov/service/OrganisationContactDetailsStaffUpdateService.java b/health-services/attendance/src/main/java/org/egov/service/OrganisationContactDetailsStaffUpdateService.java new file mode 100644 index 00000000000..57f296542e6 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/service/OrganisationContactDetailsStaffUpdateService.java @@ -0,0 +1,97 @@ +package org.egov.service; + +import digit.models.coremodels.RequestInfoWrapper; +import lombok.extern.slf4j.Slf4j; +import org.egov.common.contract.request.RequestInfo; +import org.egov.common.models.individual.Individual; +import org.egov.config.AttendanceServiceConfiguration; +import org.egov.util.IndividualServiceUtil; +import org.egov.web.models.AttendanceRegister; +import org.egov.web.models.AttendanceRegisterSearchCriteria; +import org.egov.web.models.Organisation.ContactDetails; +import org.egov.web.models.Organisation.OrgContactUpdateDiff; +import org.egov.web.models.StaffPermission; +import org.egov.web.models.StaffPermissionRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.*; + +@Slf4j +@Service +public class OrganisationContactDetailsStaffUpdateService { + + @Autowired + private AttendanceRegisterService attendanceRegisterService; + @Autowired + private StaffService staffService; + @Autowired + private IndividualServiceUtil individualServiceUtil; + + @Autowired + private AttendanceServiceConfiguration configuration; + + public void updateStaffPermissionsForContactDetails(OrgContactUpdateDiff orgContactUpdateDiff) { + RequestInfoWrapper requestInfoWrapper = RequestInfoWrapper.builder().requestInfo(orgContactUpdateDiff.getRequestInfo()).build(); + String tenantId = orgContactUpdateDiff.getTenantId(); + List oldContacts = orgContactUpdateDiff.getOldContacts(); + + for(ContactDetails oldContact : oldContacts) { + AttendanceRegisterSearchCriteria attendanceRegisterSearchCriteria = + AttendanceRegisterSearchCriteria.builder().tenantId(tenantId).staffId(oldContact.getIndividualId()).limit(configuration.getAttendanceRegisterMaxLimit()).build(); + List attendanceRegisterList = attendanceRegisterService.searchAttendanceRegister(requestInfoWrapper, attendanceRegisterSearchCriteria); + if(CollectionUtils.isEmpty(attendanceRegisterList)) { + try { + String userUuid = individualServiceUtil.getIndividualDetails(Collections.singletonList(oldContact.getIndividualId()), requestInfoWrapper.getRequestInfo(), tenantId).get(0).getUserUuid(); + attendanceRegisterSearchCriteria = AttendanceRegisterSearchCriteria.builder().tenantId(tenantId).staffId(userUuid).limit(configuration.getAttendanceRegisterMaxLimit()).build(); + attendanceRegisterList = attendanceRegisterService.searchAttendanceRegister(requestInfoWrapper, attendanceRegisterSearchCriteria); + }catch (Exception e){ + log.error(e.toString()); + } + } + List newContacts = orgContactUpdateDiff.getNewContacts(); + grantPermission(attendanceRegisterList, newContacts, orgContactUpdateDiff.getRequestInfo()); + revokePermission(attendanceRegisterList, oldContact.getIndividualId(), orgContactUpdateDiff.getRequestInfo()); + } + } + + private void revokePermission(List attendanceRegisters, String individualOrUserId, RequestInfo requestInfo) { + if(attendanceRegisters.isEmpty()) { + log.info("No attendance registers to revoke permissions on"); + return; + } + List staffPermissionList = new ArrayList<>(); + for(AttendanceRegister attendanceRegister : attendanceRegisters) { + String tenantId = attendanceRegister.getTenantId(); + StaffPermission staffPermission = StaffPermission.builder() + .tenantId(tenantId).registerId(attendanceRegister.getId()).userId(individualOrUserId).build(); + staffPermissionList.add(staffPermission); + } + StaffPermissionRequest staffPermissionRequest = StaffPermissionRequest.builder() + .requestInfo(requestInfo).staff(staffPermissionList).build(); + staffService.deleteAttendanceStaff(staffPermissionRequest); + log.info("Revoked permission for: " + individualOrUserId + " on " + attendanceRegisters.size() + " registers."); + } + + private void grantPermission(List attendanceRegisters, List newContacts, RequestInfo requestInfo) { + if(attendanceRegisters.isEmpty()) { + log.info("No attendance registers to grant permission on"); + return; + } + List staffPermissionList = new ArrayList<>(); + for(AttendanceRegister attendanceRegister : attendanceRegisters) { + String tenantId = attendanceRegister.getTenantId(); + for(ContactDetails newContact : newContacts) { + StaffPermission staffPermission = StaffPermission.builder().tenantId(tenantId) + .registerId(attendanceRegister.getId()).userId(newContact.getIndividualId()).build(); + staffPermissionList.add(staffPermission); + } + } + StaffPermissionRequest staffPermissionRequest = StaffPermissionRequest.builder() + .requestInfo(requestInfo).staff(staffPermissionList).build(); + staffService.createAttendanceStaff(staffPermissionRequest, true); + log.info("Granted permission on " + attendanceRegisters.size() + " registers for " + newContacts.size() + " new contacts."); + } + +} diff --git a/health-services/attendance/src/main/java/org/egov/service/StaffService.java b/health-services/attendance/src/main/java/org/egov/service/StaffService.java new file mode 100644 index 00000000000..8f9b4cbd562 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/service/StaffService.java @@ -0,0 +1,179 @@ +package org.egov.service; + +import digit.models.coremodels.RequestInfoWrapper; +import lombok.extern.slf4j.Slf4j; +import org.egov.config.AttendanceServiceConfiguration; +import org.egov.enrichment.StaffEnrichmentService; +import org.egov.common.producer.Producer; +import org.egov.repository.RegisterRepository; +import org.egov.repository.StaffRepository; +import org.egov.util.ResponseInfoFactory; +import org.egov.validator.AttendanceServiceValidator; +import org.egov.validator.StaffServiceValidator; +import org.egov.web.models.AttendanceRegister; +import org.egov.web.models.StaffPermission; +import org.egov.web.models.StaffPermissionRequest; +import org.egov.web.models.StaffSearchCriteria; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +@Slf4j +public class StaffService { + @Autowired + private StaffServiceValidator staffServiceValidator; + + @Autowired + private ResponseInfoFactory responseInfoFactory; + + @Autowired + private StaffEnrichmentService staffEnrichmentService; + + @Autowired + private StaffRepository staffRepository; + + @Autowired + private RegisterRepository registerRepository; + + + @Autowired + private Producer producer; + + @Autowired + private AttendanceServiceConfiguration serviceConfiguration; + + @Autowired + private AttendanceRegisterService attendanceRegisterService; + + @Autowired + private AttendanceServiceValidator attendanceServiceValidator; + + + /** + * Create attendance staff + * + * @param staffPermissionRequest + * @return + */ + public StaffPermissionRequest createAttendanceStaff(StaffPermissionRequest staffPermissionRequest, Boolean cboMigrationReq) { + //incoming createRequest validation + log.info("Validating incoming staff request"); + staffServiceValidator.validateStaffPermissionRequestParameters(staffPermissionRequest); + + //extract registerIds and staffUserIds from client request + String tenantId = staffPermissionRequest.getStaff().get(0).getTenantId(); + List staffIds = extractStaffIdsFromRequest(staffPermissionRequest); + List registerIds = extractRegisterIdsFromRequest(staffPermissionRequest); + + //db call to get the staffList data whose de enrollment date is null + List staffPermissionListFromDB = getActiveStaff(registerIds, staffIds, tenantId); + + //db call to get registers from db + List attendanceRegisterListFromDB = getRegistersFromDB(staffPermissionRequest, registerIds, tenantId); + + //validate request registers with DB registers + attendanceServiceValidator.validateRegisterAgainstDB(registerIds, attendanceRegisterListFromDB, tenantId); + + //validator call by passing staff request and the data from db call + log.info("staffServiceValidator called to validate Create StaffPermission request"); + // When changing the CBO skip this validation + if (!cboMigrationReq) { + staffServiceValidator.validateStaffPermissionOnCreate(staffPermissionRequest, staffPermissionListFromDB, attendanceRegisterListFromDB); + } + + //enrichment call by passing staff request and data from db call + log.info("staffEnrichmentService called to enrich Create StaffPermission request"); + staffEnrichmentService.enrichStaffPermissionOnCreate(staffPermissionRequest); + + //push to producer + log.info("staff objects pushed via producer"); + producer.push(serviceConfiguration.getSaveStaffTopic(), staffPermissionRequest); + log.info("staff present in Create StaffPermission request are enrolled to the register"); + return staffPermissionRequest; + } + + public List getActiveStaff(List registerIds, List staffIds, String tenantId) { + StaffSearchCriteria staffSearchCriteria = StaffSearchCriteria.builder().registerIds(registerIds).individualIds(staffIds).tenantId(tenantId).build(); + List staffPermissionListFromDB = staffRepository.getActiveStaff(staffSearchCriteria); + log.info("size of active staffPermission List received From DB :" + staffPermissionListFromDB.size()); + return staffPermissionListFromDB; + } + + public List getRegistersFromDB(StaffPermissionRequest staffPermissionRequest, List registerIds, String tenantId) { + RequestInfoWrapper requestInfoWrapper = RequestInfoWrapper.builder().requestInfo(staffPermissionRequest.getRequestInfo()).build(); + List attendanceRegisterListFromDB = attendanceRegisterService.getAttendanceRegisters(requestInfoWrapper, registerIds, tenantId); + log.info("size of Attendance Registers list received from DB : " + attendanceRegisterListFromDB.size()); + return attendanceRegisterListFromDB; + } + + /** + * Update(Soft Delete) the given attendance staff + * + * @param staffPermissionRequest + * @return + */ + public StaffPermissionRequest deleteAttendanceStaff(StaffPermissionRequest staffPermissionRequest) { + //incoming deleteRequest validation + log.info("Validating incoming staff request"); + staffServiceValidator.validateStaffPermissionRequestParameters(staffPermissionRequest); + + //extract registerIds and staffUserIds from client request + String tenantId = staffPermissionRequest.getStaff().get(0).getTenantId(); + List staffIds = extractStaffIdsFromRequest(staffPermissionRequest); + List registerIds = extractRegisterIdsFromRequest(staffPermissionRequest); + + //db call to get registers from db + List attendanceRegisterListFromDB = getRegistersFromDB(staffPermissionRequest, registerIds, tenantId); + + + //validate request registers against registers from DB + log.info("Validating register ids from request against the DB"); + attendanceServiceValidator.validateRegisterAgainstDB(registerIds, attendanceRegisterListFromDB, tenantId); + + + // db call to get staff data + StaffSearchCriteria staffSearchCriteria = StaffSearchCriteria.builder().registerIds(registerIds).tenantId(tenantId).build(); + List staffPermissionListFromDB = getAllStaff(staffSearchCriteria); + + + //validator call by passing staff request and the data from db call + log.info("staffServiceValidator called to validate Delete StaffPermission request"); + staffServiceValidator.validateStaffPermissionOnDelete(staffPermissionRequest, staffPermissionListFromDB, attendanceRegisterListFromDB); + + log.info("staffEnrichmentService called to enrich Delete StaffPermission request"); + staffEnrichmentService.enrichStaffPermissionOnDelete(staffPermissionRequest, staffPermissionListFromDB); + + log.info("staff objects pushed via producer"); + producer.push(serviceConfiguration.getUpdateStaffTopic(), staffPermissionRequest); + log.info("staff present in Delete StaffPermission request are deenrolled from the register"); + return staffPermissionRequest; + } + + public List getAllStaff(StaffSearchCriteria staffSearchCriteria) { + List staffPermissionListFromDB = staffRepository.getAllStaff(staffSearchCriteria); + log.info("size of staffPermission list received from DB : " + staffPermissionListFromDB.size()); + return staffPermissionListFromDB; + } + + private List extractRegisterIdsFromRequest(StaffPermissionRequest staffPermissionRequest) { + List staffPermissionListFromRequest = staffPermissionRequest.getStaff(); + List registerIds = new ArrayList<>(); + for (StaffPermission staffPermission : staffPermissionListFromRequest) { + registerIds.add(staffPermission.getRegisterId()); + } + return registerIds; + } + + private List extractStaffIdsFromRequest(StaffPermissionRequest staffPermissionRequest) { + List staffPermissionListFromRequest = staffPermissionRequest.getStaff(); + List staffIds = new ArrayList<>(); + for (StaffPermission staffPermission : staffPermissionListFromRequest) { + staffIds.add(staffPermission.getUserId()); + } + return staffIds; + } + +} diff --git a/health-services/attendance/src/main/java/org/egov/util/AttendanceServiceConstants.java b/health-services/attendance/src/main/java/org/egov/util/AttendanceServiceConstants.java new file mode 100644 index 00000000000..702bc4ba0be --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/util/AttendanceServiceConstants.java @@ -0,0 +1,6 @@ +package org.egov.util; + +public class AttendanceServiceConstants { + public static final String MASTER_TENANTS = "tenants"; + public static final String MDMS_TENANT_MODULE_NAME = "tenant"; +} diff --git a/health-services/attendance/src/main/java/org/egov/util/AttendanceServiceUtil.java b/health-services/attendance/src/main/java/org/egov/util/AttendanceServiceUtil.java new file mode 100644 index 00000000000..daf344e8ac0 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/util/AttendanceServiceUtil.java @@ -0,0 +1,16 @@ +package org.egov.util; + +import digit.models.coremodels.AuditDetails; +import org.springframework.stereotype.Component; + +@Component +public class AttendanceServiceUtil { + public AuditDetails getAuditDetails(String by, AuditDetails auditDetails, Boolean isCreate) { + Long time = System.currentTimeMillis(); + if (isCreate) + return AuditDetails.builder().createdBy(by).lastModifiedBy(by).createdTime(time).lastModifiedTime(time).build(); + else + return AuditDetails.builder().createdBy(auditDetails.getCreatedBy()).lastModifiedBy(by) + .createdTime(auditDetails.getCreatedTime()).lastModifiedTime(time).build(); + } +} diff --git a/health-services/attendance/src/main/java/org/egov/util/IndividualServiceUtil.java b/health-services/attendance/src/main/java/org/egov/util/IndividualServiceUtil.java new file mode 100644 index 00000000000..891a87e6919 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/util/IndividualServiceUtil.java @@ -0,0 +1,117 @@ +package org.egov.util; + +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.egov.common.contract.request.RequestInfo; +import org.egov.common.models.individual.Individual; +import org.egov.common.models.individual.IndividualBulkResponse; +import org.egov.common.models.individual.IndividualSearch; +import org.egov.common.models.individual.IndividualSearchRequest; +import org.egov.common.utils.MultiStateInstanceUtil; +import org.egov.config.AttendanceServiceConfiguration; +import org.egov.repository.ServiceRequestRepository; +import org.egov.tracer.model.CustomException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.HttpServerErrorException; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; + +import java.util.List; +import java.util.stream.Collectors; + +import static java.lang.Long.parseLong; + +@Component +@Slf4j +public class IndividualServiceUtil { + + @Autowired + private ServiceRequestRepository serviceRequestRepository; + + @Autowired + private AttendanceServiceConfiguration config; + + @Autowired + @Qualifier("objectMapper") + private ObjectMapper mapper; + + @Autowired + private RestTemplate restTemplate; + @Autowired + private MultiStateInstanceUtil multiStateInstanceUtil; + + public List fetchIndividualIds(List individualIds, RequestInfo requestInfo, String tenantId) { + + List individualList = getIndividualDetails(individualIds, requestInfo, tenantId); + + List ids = null; + try { + ids = individualList.stream().map(Individual::getId).collect(Collectors.toList()); + } catch (Exception e) { + throw new CustomException("PARSING_ERROR", "Failed to parse Individual service response"); + } + log.info("Individual search fetched successfully"); + return ids; + } + + public List getIndividualDetails(List individualIds, RequestInfo requestInfo, String tenantId) { + + String uri = getSearchURLWithParams(tenantId).toUriString(); + + IndividualSearch individualSearch = IndividualSearch.builder().id(individualIds).build(); + IndividualSearchRequest individualSearchRequest = IndividualSearchRequest.builder() + .requestInfo(requestInfo).individual(individualSearch).build(); + + IndividualBulkResponse response = null; + log.info("call individual search with tenantId::" + tenantId + "::individual ids::" + individualIds); + + try { + response = restTemplate.postForObject(uri, individualSearchRequest, IndividualBulkResponse.class); + } catch (HttpClientErrorException | HttpServerErrorException httpClientOrServerExc) { + log.error("Error thrown from individual search service::" + httpClientOrServerExc.getStatusCode()); + throw new CustomException("INDIVIDUAL_SEARCH_SERVICE_EXCEPTION", "Error thrown from individual search service::" + httpClientOrServerExc.getStatusCode()); + } + if (response == null || CollectionUtils.isEmpty(response.getIndividual())) { + throw new CustomException("INDIVIDUAL_SEARCH_RESPONSE_IS_EMPTY", "Individuals not found"); + } + + return response.getIndividual(); + } + + private UriComponentsBuilder getSearchURLWithParams(String tenantId) { + StringBuilder uri = new StringBuilder(); + uri.append(config.getIndividualHost()).append(config.getIndividualSearchEndpoint()); + UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(uri.toString()) + .queryParam("limit", 100) + .queryParam("offset", 0) + .queryParam("tenantId", tenantId); + + return uriBuilder; + } + + public List getIndividualDetailsFromUserId(Long userId, RequestInfo requestInfo, String tenantId) { + String uri = getSearchURLWithParams(multiStateInstanceUtil.getStateLevelTenant(tenantId)).toUriString(); + IndividualSearch individualSearch = IndividualSearch.builder().userId(userId).build(); + IndividualSearchRequest individualSearchRequest = IndividualSearchRequest.builder() + .requestInfo(requestInfo).individual(individualSearch).build(); + + IndividualBulkResponse response = null; + log.info("call individual search with tenantId::" + tenantId + "::user id::" + userId); + + try { + response = restTemplate.postForObject(uri, individualSearchRequest, IndividualBulkResponse.class); + } catch (HttpClientErrorException | HttpServerErrorException httpClientOrServerExc) { + log.error("Error thrown from individual search service::" + httpClientOrServerExc.getStatusCode()); + throw new CustomException("INDIVIDUAL_SEARCH_SERVICE_EXCEPTION", "Error thrown from individual search service::" + httpClientOrServerExc.getStatusCode()); + } + if (response == null || CollectionUtils.isEmpty(response.getIndividual())) { + throw new CustomException("INDIVIDUAL_SEARCH_RESPONSE_IS_EMPTY", "Individuals not found"); + } + + return response.getIndividual(); + } +} diff --git a/health-services/attendance/src/main/java/org/egov/util/MDMSUtils.java b/health-services/attendance/src/main/java/org/egov/util/MDMSUtils.java new file mode 100644 index 00000000000..d8a48ac95b4 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/util/MDMSUtils.java @@ -0,0 +1,72 @@ +package org.egov.util; + +import lombok.extern.slf4j.Slf4j; +import org.egov.common.contract.request.RequestInfo; +import org.egov.config.AttendanceServiceConfiguration; +import org.egov.mdms.model.MasterDetail; +import org.egov.mdms.model.MdmsCriteria; +import org.egov.mdms.model.MdmsCriteriaReq; +import org.egov.mdms.model.ModuleDetail; +import org.egov.repository.ServiceRequestRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +import static org.egov.util.AttendanceServiceConstants.MASTER_TENANTS; +import static org.egov.util.AttendanceServiceConstants.MDMS_TENANT_MODULE_NAME; + +@Component +@Slf4j +public class MDMSUtils { + + @Autowired + private ServiceRequestRepository serviceRequestRepository; + + @Autowired + private AttendanceServiceConfiguration config; + + public static final String filterCode = "$.*.code"; + + public Object mDMSCall(RequestInfo requestInfo, String tenantId) { + MdmsCriteriaReq mdmsCriteriaReq = getMDMSRequest(requestInfo, tenantId); + Object result = serviceRequestRepository.fetchResult(getMdmsSearchUrl(), mdmsCriteriaReq); + return result; + } + + public MdmsCriteriaReq getMDMSRequest(RequestInfo requestInfo, String tenantId) { + + ModuleDetail tenantModuleDetail = getTenantModuleRequestData(); + + List moduleDetails = new LinkedList<>(); + moduleDetails.add(tenantModuleDetail); + + MdmsCriteria mdmsCriteria = MdmsCriteria.builder().moduleDetails(moduleDetails).tenantId(tenantId) + .build(); + + MdmsCriteriaReq mdmsCriteriaReq = MdmsCriteriaReq.builder().mdmsCriteria(mdmsCriteria) + .requestInfo(requestInfo).build(); + return mdmsCriteriaReq; + } + + public StringBuilder getMdmsSearchUrl() { + return new StringBuilder().append(config.getMdmsHost()).append(config.getMdmsEndPoint()); + } + + private ModuleDetail getTenantModuleRequestData() { + List tenantMasterDetails = new ArrayList<>(); + + MasterDetail tenantMasterDetail = MasterDetail.builder().name(MASTER_TENANTS) + .filter(filterCode).build(); + + tenantMasterDetails.add(tenantMasterDetail); + + ModuleDetail tenantModuleDetail = ModuleDetail.builder().masterDetails(tenantMasterDetails) + .moduleName(MDMS_TENANT_MODULE_NAME).build(); + + return tenantModuleDetail; + } + +} diff --git a/health-services/attendance/src/main/java/org/egov/util/ResponseInfoFactory.java b/health-services/attendance/src/main/java/org/egov/util/ResponseInfoFactory.java new file mode 100644 index 00000000000..8bcab7b536d --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/util/ResponseInfoFactory.java @@ -0,0 +1,25 @@ +package org.egov.util; + +import org.egov.common.contract.request.RequestInfo; +import org.egov.common.contract.response.ResponseInfo; +import org.springframework.stereotype.Component; + +@Component +public class ResponseInfoFactory { + + public ResponseInfo createResponseInfoFromRequestInfo(final RequestInfo requestInfo, final Boolean success) { + + final String apiId = requestInfo != null ? requestInfo.getApiId() : ""; + final String ver = requestInfo != null ? requestInfo.getVer() : ""; + Long ts = null; + if (requestInfo != null) + ts = requestInfo.getTs(); + final String resMsgId = "uief87324"; // FIXME : Hard-coded + final String msgId = requestInfo != null ? requestInfo.getMsgId() : ""; + final String responseStatus = success ? "successful" : "failed"; + + return ResponseInfo.builder().apiId(apiId).ver(ver).ts(ts).resMsgId(resMsgId).msgId(msgId).resMsgId(resMsgId) + .status(responseStatus).build(); + } + +} \ No newline at end of file diff --git a/health-services/attendance/src/main/java/org/egov/validator/AttendanceLogServiceValidator.java b/health-services/attendance/src/main/java/org/egov/validator/AttendanceLogServiceValidator.java new file mode 100644 index 00000000000..756daa36515 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/validator/AttendanceLogServiceValidator.java @@ -0,0 +1,491 @@ +package org.egov.validator; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.egov.common.contract.request.RequestInfo; +import org.egov.config.AttendanceServiceConfiguration; +import org.egov.util.IndividualServiceUtil; +import org.egov.web.models.AttendeeSearchCriteria; +import org.egov.web.models.AttendanceLogSearchCriteria; +import org.egov.web.models.AttendanceRegisterSearchCriteria; +import org.egov.web.models.StaffSearchCriteria; +import org.egov.repository.AttendanceLogRepository; +import org.egov.repository.AttendeeRepository; +import org.egov.repository.RegisterRepository; +import org.egov.repository.StaffRepository; +import org.egov.tracer.model.CustomException; +import org.egov.web.models.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.time.Instant; +import java.util.*; +import java.util.stream.Collectors; + +@Component +@Slf4j +public class AttendanceLogServiceValidator { + + @Autowired + private StaffRepository attendanceStaffRepository; + + @Autowired + private RegisterRepository attendanceRegisterRepository; + + @Autowired + private AttendeeRepository attendanceAttendeeRepository; + + @Autowired + private AttendanceLogRepository attendanceLogRepository; + + @Autowired + private AttendanceServiceConfiguration config; + + @Autowired + private IndividualServiceUtil individualServiceUtil; + + public void validateCreateAttendanceLogRequest(AttendanceLogRequest attendanceLogRequest) { + log.info("Validate attendance log create request"); + validateAttendanceLogRequest(attendanceLogRequest); + + // Verify all the attendance logs should below to same registerId + validateMultipleRegisterIds(attendanceLogRequest); + + // Verify all the attendance logs should below to same tenantId + validateMultipleTenantIds(attendanceLogRequest); + + // Verify the Logged-in user is associated to the given register. + validateLoggedInUser(attendanceLogRequest); + + // Verify given attendance log against register params + validateAttendanceLogsAgainstRegisterParams(attendanceLogRequest); + + // Verify if individuals are part of the given register and individuals were active during given attendance log time. + validateAttendees(attendanceLogRequest); + + // Verify provided documentIds are valid. + validateDocumentIds(attendanceLogRequest); + log.info("Attendance log create request validation done"); + } + + private void validateMultipleTenantIds(AttendanceLogRequest attendanceLogRequest) { + List attendanceLogs = attendanceLogRequest.getAttendance(); + Set tenantIds = new HashSet<>(); + for(AttendanceLog attendanceLog : attendanceLogs){ + String tenantId = attendanceLog.getTenantId(); + if(tenantIds.isEmpty()){ + tenantIds.add(tenantId); + }else{ + if(!tenantIds.contains(tenantId)){ + log.error("Attendance logs should below to same tenantId"); + throw new CustomException("MULTIPLE_TENANTIDS","Attendance logs should belong to same tenantId"); + } + } + } + } + + private void validateMultipleRegisterIds(AttendanceLogRequest attendanceLogRequest) { + List attendanceLogs = attendanceLogRequest.getAttendance(); + Set registerIds = new HashSet<>(); + for(AttendanceLog attendanceLog : attendanceLogs){ + String registerId = attendanceLog.getRegisterId(); + if(registerIds.isEmpty()){ + registerIds.add(registerId); + }else{ + if(!registerIds.contains(registerId)){ + log.error("Attendance logs should below to same registerId"); + throw new CustomException("MULTIPLE_REGISTERIDS","Attendance logs should belong to same registerId"); + } + } + } + } + + public void validateUpdateAttendanceLogRequest(AttendanceLogRequest attendanceLogRequest) { + log.info("Validate attendance log update request"); + validateAttendanceLogRequest(attendanceLogRequest); + + // Verify all the attendance logs should below to same registerId + validateMultipleRegisterIds(attendanceLogRequest); + + // Verify all the attendance logs should below to same tenantId + validateMultipleTenantIds(attendanceLogRequest); + + // Verify the Logged-in user is associated to the given register. + validateLoggedInUser(attendanceLogRequest); + + // Verify provided log ids are present + validateAttendanceLogIds(attendanceLogRequest); + + // Verify given attendance log against register params + validateAttendanceLogsAgainstRegisterParams(attendanceLogRequest); + + // Verify if individuals are part of the given register and individuals were active during given attendance log time. + validateAttendees(attendanceLogRequest); + + // Verify provided documentIds are valid. + validateDocumentIds(attendanceLogRequest); + + log.info("Attendance log update request validation done"); + } + + private void validateAttendanceLogsAgainstRegisterParams(AttendanceLogRequest attendanceLogRequest){ + String registerId = attendanceLogRequest.getAttendance().get(0).getRegisterId(); + String tenantId = attendanceLogRequest.getAttendance().get(0).getTenantId(); + + // Fetch register for given registerId + List attendanceRegisters = fetchRegisterWithId(registerId); + + // Check existence of register + checkRegisterExistence(attendanceRegisters,registerId); + + AttendanceRegister attendanceRegister = attendanceRegisters.get(0); + + // Check register is active ? + checkRegisterStatus(attendanceRegister); + + // Check register association with tenantId + validateTenantIdAssociationWithRegisterId(attendanceRegister,tenantId); + + // Check attendance log time against register start and end date + validateAttendanceLogTimeWithRegisterStartEndDate(attendanceRegister,attendanceLogRequest); + + log.info("Attendance log verification against register params are done. RegisterId ["+registerId+"]"); + } + + private void checkRegisterStatus(AttendanceRegister attendanceRegister) { + if(Status.INACTIVE.equals(attendanceRegister.getStatus())){ + String registerId = attendanceRegister.getId(); + log.error("Register ["+registerId+"] is inactive"); + throw new CustomException("INACTIVE_REGISTER", "Given RegisterId ["+registerId+"] is inactive"); + } + } + + private void checkRegisterExistence(List attendanceRegisters,String registerId) { + if (attendanceRegisters == null || attendanceRegisters.isEmpty()) { + log.error("Register ["+registerId+"] does not exists"); + throw new CustomException("REGISTER_NOT_FOUND", "Given RegisterId ["+registerId+"] does not exists"); + } + } + + private void validateTenantIdAssociationWithRegisterId(AttendanceRegister attendanceRegister,String tenantId) { + if(!tenantId.equals(attendanceRegister.getTenantId())){ + log.error("TenantId ["+tenantId+"] is not associated with register ["+attendanceRegister.getId()+"]"); + throw new CustomException("INVALID_TENANTID", "TenantId ["+tenantId+"] is not associated with register ["+attendanceRegister.getId()+"]"); + } + } + + private List fetchRegisterWithId(String registerId) { + AttendanceRegisterSearchCriteria searchCriteria = AttendanceRegisterSearchCriteria + .builder() + .ids(Collections.singletonList(registerId)) + .build(); + return attendanceRegisterRepository.getRegister(searchCriteria); + } + + private void validateAttendanceLogTimeWithRegisterStartEndDate(AttendanceRegister attendanceRegister,AttendanceLogRequest attendanceLogRequest) { + Instant registerStartTime = Instant.ofEpochMilli(attendanceRegister.getStartDate().longValue()); + + Instant registerEndTime = null; + if(attendanceRegister.getEndDate() != null) + registerEndTime = Instant.ofEpochMilli(attendanceRegister.getEndDate().longValue()); + + List attendanceLogs = attendanceLogRequest.getAttendance(); + + if(registerEndTime != null){ + for(AttendanceLog attendanceLog : attendanceLogs){ + Instant instantAttendanceAttendeeLogTime = Instant.ofEpochMilli(attendanceLog.getTime().longValue()); + if(!(instantAttendanceAttendeeLogTime.compareTo(registerStartTime) >=0 && instantAttendanceAttendeeLogTime.compareTo(registerEndTime) <=0)){ + log.error("Attendance time ["+instantAttendanceAttendeeLogTime+"] is invalid for register ["+attendanceRegister.getId()+"]"); + throw new CustomException("INVALID_ATTENDANCE_TIME", "Attendance time ["+instantAttendanceAttendeeLogTime+"] is invalid for register ["+attendanceRegister.getId()+"]"); + } + } + }else{ + for(AttendanceLog attendanceLog : attendanceLogs){ + Instant instantAttendanceAttendeeLogTime = Instant.ofEpochMilli(attendanceLog.getTime().longValue()); + if(!(instantAttendanceAttendeeLogTime.compareTo(registerStartTime) >=0)){ + log.error("Attendance time ["+instantAttendanceAttendeeLogTime+"] is invalid for register ["+attendanceRegister.getId()+"]"); + throw new CustomException("INVALID_ATTENDANCE_TIME", "Attendance time ["+instantAttendanceAttendeeLogTime+"] is invalid for register ["+attendanceRegister.getId()+"]"); + } + } + } + } + private void validateDocumentIds(AttendanceLogRequest attendanceLogRequest) { + if ("TRUE".equalsIgnoreCase(config.getDocumentIdVerificationRequired())) { + //TODO + // For now throwing exception. Later implementation will be done + log.error("Document service not integrated yet"); + throw new CustomException("SERVICE_UNAVAILABLE", "Service not integrated yet"); + } + } + + private void validateAttendanceLogIds(AttendanceLogRequest attendanceLogRequest) { + String registerId = attendanceLogRequest.getAttendance().get(0).getRegisterId(); + List attendance = attendanceLogRequest.getAttendance(); + List providedAttendanceLogIds = attendance.stream().map(e -> String.valueOf(e.getId())).collect(Collectors.toList()); + List fetchedAttendanceLogList = fetchAttendanceLogsByIds(providedAttendanceLogIds); + Set fetchedAttendanceLogIds = fetchedAttendanceLogList.stream().map(e -> String.valueOf(e.getId())).collect(Collectors.toSet()); + for (String providedAttendanceLogId : providedAttendanceLogIds) { + if (!fetchedAttendanceLogIds.contains(providedAttendanceLogId)) { + log.error("Provided attendance id ["+providedAttendanceLogId+"] is invalid for register ["+registerId+"]"); + throw new CustomException("ATTENDANCE_LOG", "Provided attendance id ["+providedAttendanceLogId+"] is invalid for register ["+registerId+"]"); + } + } + + log.info("Attendance Log Ids are validated successfully for register ["+registerId+"]"); + } + + private List fetchAttendanceLogsByIds(List ids) { + //AttendanceLogSearchCriteria searchCriteria = AttendanceLogSearchCriteria.builder().ids(ids).status(Status.ACTIVE).build(); + AttendanceLogSearchCriteria searchCriteria = AttendanceLogSearchCriteria.builder().ids(ids).build(); + return attendanceLogRepository.getAttendanceLogs(searchCriteria); + } + + private void validateAttendees(AttendanceLogRequest attendanceLogRequest) { + + /* + For now, we are validating attendees on below basis. + 1. Verify that each attendee is associated to given register. + 2. Make the entry in attendance log table only if attendee was active during the given attendance time. + + Future: + Once Individual service will be available will integrate it for further validation. + */ + + + if ("TRUE".equalsIgnoreCase(config.getIndividualServiceIntegrationRequired())) { + //TODO + // For now throwing exception. Since individual service is under discussion. + log.error("Individual service integration is under development"); + throw new CustomException("INTEGRATION_UNDERDEVELOPMENT", "Individual service integration is under development"); + } + + // Fetch all attendees for given register_id. + String registerId = attendanceLogRequest.getAttendance().get(0).getRegisterId(); + List fetchAttendanceAttendeeLst = fetchAllAttendeesEnrolledInARegister(registerId); + + log.info("All attendees are fetched successfully for register ["+registerId+"]"); + + // Convert the fetched Attendee List into a Map with individualId as key and corresponding Attendee list as value. + Map> attendanceAttendeeListMap = fetchAttendanceAttendeeLst + .stream() + .collect(Collectors.groupingBy(IndividualEntry::getIndividualId)); + + // Identify unassociated(Attendees not associated with given register) and ineligible attendees + identifyUnassociatedAndIneligibleAttendees(attendanceLogRequest, attendanceAttendeeListMap); + log.info("Attendee validation is done for register ["+registerId+"]"); + } + + private void identifyUnassociatedAndIneligibleAttendees(AttendanceLogRequest attendanceLogRequest, Map> attendanceAttendeeListMap) { + List unassociatedAttendees = new ArrayList<>(); + Set eligibleAttendanceAttendeeIdSet = new HashSet<>(); + + List attendanceLogs = attendanceLogRequest.getAttendance(); + for (AttendanceLog attendanceLog : attendanceLogs) { + String givenIndividualId = attendanceLog.getIndividualId(); + if (attendanceAttendeeListMap.containsKey(givenIndividualId)) { + List lst = attendanceAttendeeListMap.get(givenIndividualId); + for (IndividualEntry attendee : lst) { + Instant instantAttendanceAttendeeLogTime = Instant.ofEpochMilli(attendanceLog.getTime().longValue()); + Instant instantEnrollmentDate = Instant.ofEpochMilli(attendee.getEnrollmentDate().longValue()); + if (attendee.getDenrollmentDate()==null) { + if (instantAttendanceAttendeeLogTime.compareTo(instantEnrollmentDate) >= 0) { + eligibleAttendanceAttendeeIdSet.add(attendee.getIndividualId()); + } + } else { + Instant instantDenrollmentDate = Instant.ofEpochMilli(attendee.getDenrollmentDate().longValue()); + if (instantAttendanceAttendeeLogTime.compareTo(instantEnrollmentDate) >= 0 && instantAttendanceAttendeeLogTime.compareTo(instantDenrollmentDate) <= 0) { + eligibleAttendanceAttendeeIdSet.add(attendee.getIndividualId()); + } + } + } + } else { + unassociatedAttendees.add(givenIndividualId); + } + + } + + String registerId = attendanceLogRequest.getAttendance().get(0).getRegisterId(); + + if (!unassociatedAttendees.isEmpty()) { + log.error("Attendees are not enrolled against register ["+registerId+"]"); + throw new CustomException("UNENROLLED_ATTENDEES", "Attendees are not enrolled against register ["+registerId+"]"); + } + + //find ineligible list + Set inEligibleAttendanceAttendeeIdSet = new HashSet<>(); + for (AttendanceLog attendanceLog : attendanceLogs) { + if (!eligibleAttendanceAttendeeIdSet.contains(attendanceLog.getIndividualId())) { + inEligibleAttendanceAttendeeIdSet.add(attendanceLog.getIndividualId()); + } + } + + if (!inEligibleAttendanceAttendeeIdSet.isEmpty()) { + log.error("Attendees are ineligible for given date range for register ["+registerId+"]"); + throw new CustomException("INELIGIBLE_ATTENDEES", "Attendees are ineligible for given date range for register ["+registerId+"]"); + } + } + + private List fetchAllAttendeesEnrolledInARegister(String registerId) { + AttendeeSearchCriteria searchCriteria = AttendeeSearchCriteria + .builder() + .registerIds(Collections.singletonList(registerId)) + .build(); + + return attendanceAttendeeRepository.getAttendees(searchCriteria); + } + + private void validateLoggedInUser(AttendanceLogRequest attendanceLogRequest) { + /* + For now, we are validating logged-in user on below basis. + 1. Logged-in user should be active user for provided register_id. Query eg_wms_attendance_staff table for same. + + Future + Once Staff service will be available will integrate it for further validation. + */ + + if ("TRUE".equalsIgnoreCase(config.getStaffServiceIntegrationRequired())) { + //TODO + // For now throwing exception. Since Staff service is under development. + log.error("Staff service integration is under development"); + throw new CustomException("INTEGRATION_UNDERDEVELOPMENT", "Staff service integration is under development"); + } + + String userUUID = attendanceLogRequest.getRequestInfo().getUserInfo().getUuid(); + String registerId = attendanceLogRequest.getAttendance().get(0).getRegisterId(); + String individualId = individualServiceUtil.getIndividualDetailsFromUserId(attendanceLogRequest.getRequestInfo().getUserInfo().getId(), attendanceLogRequest.getRequestInfo(), attendanceLogRequest.getAttendance().get(0).getTenantId()).get(0).getId(); + validateLoggedInUser(individualId, registerId); + log.info("User ["+userUUID+"] validation is done for register ["+registerId+"]"); + } + + public void validateSearchAttendanceLogRequest(RequestInfoWrapper requestInfoWrapper, AttendanceLogSearchCriteria searchCriteria) { + + log.info("Validate attendance log search request"); + + // Verify given parameters + validateSearchAttendanceLogParameters(requestInfoWrapper, searchCriteria); + + // Fetch register for given Id + List attendanceRegisters = fetchRegisterWithId(searchCriteria.getRegisterId()); + + if (attendanceRegisters == null || attendanceRegisters.isEmpty()) { + throw new CustomException("INVALID_REGISTERID", "Register Not found "); + } + + // Verify TenantId association with register + validateTenantIdAssociationWithRegisterId(attendanceRegisters.get(0), searchCriteria.getTenantId()); + + // Verify the Logged-in user is associated to the given register. + String individualId = individualServiceUtil.getIndividualDetailsFromUserId(requestInfoWrapper.getRequestInfo().getUserInfo().getId(), requestInfoWrapper.getRequestInfo(), searchCriteria.getTenantId()).get(0).getId(); + validateLoggedInUser(individualId, searchCriteria.getRegisterId()); + + log.info("Attendance log search request validated successfully"); + } + + private void validateSearchAttendanceLogParameters(RequestInfoWrapper requestInfoWrapper, AttendanceLogSearchCriteria searchCriteria) { + if (searchCriteria == null || requestInfoWrapper == null) { + log.error("Attendance log search criteria and request info is mandatory"); + throw new CustomException("ATTENDANCE_LOG_SEARCH_REQUEST", "Attendance log search criteria and request info is mandatory"); + } + + Map errorMap = new HashMap<>(); + + validateRequestInfo(requestInfoWrapper.getRequestInfo(), errorMap); + + if (StringUtils.isBlank(searchCriteria.getTenantId())) { + log.error("Attendance log search, Tenant is mandatory"); + throw new CustomException("TENANT_ID", "Tenant is mandatory"); + } + if (StringUtils.isBlank(searchCriteria.getRegisterId())) { + log.error("Attendance log search, RegisterId is mandatory"); + throw new CustomException("REGISTER_ID", "RegisterId is mandatory"); + } + + // Throw exception if required parameters are missing + if (!errorMap.isEmpty()) + throw new CustomException(errorMap); + + if (searchCriteria.getIndividualIds() != null && !searchCriteria.getIndividualIds().isEmpty() && searchCriteria.getIndividualIds().size() > 10) { + log.error("Attendance log search, only 10 IndividualIds are allowed to search"); + throw new CustomException("INDIVIDUALIDS", "only 10 IndividualIds are allowed to search"); + } + } + + + + private void validateLoggedInUser(String userUUID, String registerId) { + StaffSearchCriteria searchCriteria = StaffSearchCriteria + .builder() + .individualIds(Collections.singletonList(userUUID)) + .registerIds(Collections.singletonList(registerId)) + .build(); + List attendanceStaff = attendanceStaffRepository.getActiveStaff(searchCriteria); + if (attendanceStaff == null || attendanceStaff.isEmpty()) { + log.error("User ["+userUUID+"] is not authorised for register ["+registerId+"]"); + throw new CustomException("UNAUTHORISED_USER", "User ["+userUUID+"] is not authorised for register ["+registerId+"]"); + } + } + + private void validateRequestInfo(RequestInfo requestInfo, Map errorMap) { + if (requestInfo == null) { + log.error("Request info is mandatory"); + throw new CustomException("REQUEST_INFO", "Request info is mandatory"); + } + if (requestInfo.getUserInfo() == null) { + log.error("UserInfo is mandatory"); + throw new CustomException("USERINFO", "UserInfo is mandatory"); + } + if (requestInfo.getUserInfo() != null && StringUtils.isBlank(requestInfo.getUserInfo().getUuid())) { + log.error("UUID is mandatory"); + throw new CustomException("USERINFO_UUID", "UUID is mandatory"); + } + + log.info("Request Info object validation done"); + } + + private void validateAttendanceLogRequest(AttendanceLogRequest attendanceLogRequest) { + + Map errorMap = new HashMap<>(); + // Validate the Request Info object + RequestInfo requestInfo = attendanceLogRequest.getRequestInfo(); + validateRequestInfo(requestInfo, errorMap); + + // Validate the Attendance Log parameters + validateAttendanceLogParameters(attendanceLogRequest.getAttendance(), errorMap); + + // Throw exception if required parameters are missing + if (!errorMap.isEmpty()){ + log.error("Attendance log request validation failed"); + throw new CustomException(errorMap); + } + } + + private void validateAttendanceLogParameters(List attendance, Map errorMap) { + if (attendance == null || attendance.isEmpty()) { + log.error("Attendance array is mandatory"); + throw new CustomException("ATTENDANCE", "Attendance array is mandatory"); + } + + for (AttendanceLog attendeeLog : attendance) { + if (StringUtils.isBlank(attendeeLog.getTenantId())) { + log.error("TenantId is mandatory"); + errorMap.put("ATTENDANCE.TENANTID", "TenantId is mandatory"); + } + if (StringUtils.isBlank(attendeeLog.getRegisterId())) { + log.error("Attendance registerid is mandatory"); + errorMap.put("ATTENDANCE.REGISTERID", "Attendance registerid is mandatory"); + } + if (StringUtils.isBlank(attendeeLog.getIndividualId() )) { + log.error("Attendance indidualid is mandatory"); + errorMap.put("ATTENDANCE.INDIVIDUALID", "Attendance indidualid is mandatory"); + } + if (StringUtils.isBlank(attendeeLog.getType())) { + log.error("Attendance type is mandatory"); + errorMap.put("ATTENDANCE.TYPE", "Attendance type is mandatory"); + } + if (attendeeLog.getTime() == null) { + log.error("Attendance time is mandatory"); + errorMap.put("ATTENDANCE.TIME", "Attendance time is mandatory"); + } + } + } +} diff --git a/health-services/attendance/src/main/java/org/egov/validator/AttendanceServiceValidator.java b/health-services/attendance/src/main/java/org/egov/validator/AttendanceServiceValidator.java new file mode 100644 index 00000000000..4204fece38d --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/validator/AttendanceServiceValidator.java @@ -0,0 +1,277 @@ +package org.egov.validator; + +import com.jayway.jsonpath.JsonPath; +import digit.models.coremodels.RequestInfoWrapper; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.egov.common.contract.request.RequestInfo; +import org.egov.repository.RegisterRepository; +import org.egov.tracer.model.CustomException; +import org.egov.util.IndividualServiceUtil; +import org.egov.util.MDMSUtils; +import org.egov.web.models.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import java.math.BigDecimal; +import java.util.*; +import java.util.stream.Collectors; + +import static org.egov.util.AttendanceServiceConstants.MASTER_TENANTS; +import static org.egov.util.AttendanceServiceConstants.MDMS_TENANT_MODULE_NAME; + +@Component +@Slf4j +public class AttendanceServiceValidator { + + @Autowired + private MDMSUtils mdmsUtils; + + @Autowired + private RegisterRepository registerRepository; + @Autowired + private IndividualServiceUtil individualServiceUtil; + + /* Validates create Attendance Register request body */ + public void validateCreateAttendanceRegister(AttendanceRegisterRequest request) { + Map errorMap = new HashMap<>(); + List attendanceRegisters = request.getAttendanceRegister(); + RequestInfo requestInfo = request.getRequestInfo(); + + //Verify if RequestInfo and UserInfo is present + validateRequestInfo(requestInfo, errorMap); + log.info("Request Info validated for attendance create request"); + + //Verify if attendance register request and mandatory fields are present + validateAttendanceRegisterRequest(attendanceRegisters, errorMap); + log.info("Attendance registers validated for create request"); + + //Verify referenceId and ServiceCode are present + validateReferenceIdAndServiceCodeParams(attendanceRegisters, errorMap); + log.info("Attendance registers referenceId and ServiceCode are validated"); + + String tenantId = attendanceRegisters.get(0).getTenantId(); + String rootTenantId = tenantId.split("\\.")[0]; + + //Get MDMS data using create attendance register request and tenantId + Object mdmsData = mdmsUtils.mDMSCall(requestInfo, rootTenantId); + validateMDMSData(attendanceRegisters, mdmsData, errorMap); + log.info("Request data validated with MDMS"); + + if (!errorMap.isEmpty()) + throw new CustomException(errorMap); + + //Verify that active attendance register is not already present for provided tenantId, referenceId and serviceCode + validateAttendanceRegisterAgainstDB(attendanceRegisters); + log.info("Attendance registers validated against DB"); + } + + private void validateAttendanceRegisterAgainstDB(List attendanceRegisters) { + for (AttendanceRegister attendanceRegister: attendanceRegisters) { + String tenantId = attendanceRegister.getTenantId(); + String referenceId = attendanceRegister.getReferenceId(); + String serviceCode = attendanceRegister.getServiceCode(); + + AttendanceRegisterSearchCriteria attendanceRegisterSearchCriteria = AttendanceRegisterSearchCriteria.builder() + .tenantId(tenantId) + .status(Status.ACTIVE) + .referenceId(referenceId) + .serviceCode(serviceCode) + .build(); + List registers = registerRepository.getRegister(attendanceRegisterSearchCriteria); + if(!registers.isEmpty()){ + log.error("Attendance register exists for provided referenceId ["+referenceId+"] and serviceCode ["+serviceCode+"]"); + throw new CustomException("REGISTER_ALREADY_EXISTS", "Register exists for provided referenceId ["+referenceId+"] and serviceCode ["+serviceCode+"]"); + } + } + } + + /* Validates Update Attendance register request body */ + public void validateUpdateAttendanceRegisterRequest(AttendanceRegisterRequest request) { + Map errorMap = new HashMap<>(); + List attendanceRegisters = request.getAttendanceRegister(); + RequestInfo requestInfo = request.getRequestInfo(); + + //Verify if RequestInfo and UserInfo is present + validateRequestInfo(requestInfo, errorMap); + log.info("Request Info validated for attendance update request"); + //Verify attendance register request and if mandatory fields are present + validateAttendanceRegisterRequest(attendanceRegisters, errorMap); + log.info("Attendance registers validated for update request"); + + for (AttendanceRegister attendanceRegister: attendanceRegisters) { + if (StringUtils.isBlank(attendanceRegister.getId())) { + log.error("Attendance register id is mandatory in register update request"); + errorMap.put("ATTENDANCE_REGISTER_ID", "Attendance register id is mandatory"); + } + } + + String tenantId = attendanceRegisters.get(0).getTenantId(); + String rootTenantId = tenantId.split("\\.")[0]; + + //Get MDMS data using create attendance register request and tenantId + Object mdmsData = mdmsUtils.mDMSCall(requestInfo, rootTenantId); + validateMDMSData(attendanceRegisters, mdmsData, errorMap); + log.info("Request data validated with MDMS"); + + if (!errorMap.isEmpty()) + throw new CustomException(errorMap); + } + + /* Validates attendance register data in update request against attendance register data fetched from database */ + public void validateUpdateAgainstDB(AttendanceRegisterRequest attendanceRegisterRequest, List attendanceRegistersFromDB) { + if (CollectionUtils.isEmpty(attendanceRegistersFromDB)) { + log.error("The record that you are trying to update does not exists in the system"); + throw new CustomException("INVALID_REGISTER_MODIFY", "The record that you are trying to update does not exists in the system"); + } + + for (AttendanceRegister registerFromRequest: attendanceRegisterRequest.getAttendanceRegister()) { + + AttendanceRegister registerFromDB = attendanceRegistersFromDB.stream().filter(ar -> ar.getId().equals(registerFromRequest.getId())).findFirst().orElse(null); + if (registerFromDB == null) { + log.error("The register Id " + registerFromRequest.getId() + " that you are trying to update does not exists in the system"); + throw new CustomException("INVALID_REGISTER_MODIFY", "The register Id " + registerFromRequest.getId() + " that you are trying to update does not exists in the system"); + } + + // If the user who is trying to update the register is not associated with the register, throw error that the user does not have permission to modify the attendance register + if (registerFromDB.getStaff() != null) { + Set staffUserIdsFromDB = registerFromDB.getStaff().stream().map(StaffPermission:: getUserId).collect(Collectors.toSet()); + String individualId = individualServiceUtil.getIndividualDetailsFromUserId(attendanceRegisterRequest.getRequestInfo().getUserInfo().getId(),attendanceRegisterRequest.getRequestInfo(), registerFromRequest.getTenantId()).get(0).getId(); + if (!staffUserIdsFromDB.contains(individualId)) { + log.error("The user " + attendanceRegisterRequest.getRequestInfo().getUserInfo().getUuid() + " does not have permission to modify the register " + registerFromDB.getId()); + throw new CustomException("INVALID_REGISTER_MODIFY", "The user " + attendanceRegisterRequest.getRequestInfo().getUserInfo().getUuid() + " does not have permission to modify the register " + registerFromDB.getId()); + } + } else { + log.error("The user " + attendanceRegisterRequest.getRequestInfo().getUserInfo().getUuid() + " does not have permission to modify the register " + registerFromDB.getId()); + throw new CustomException("INVALID_REGISTER_MODIFY", "The user " + attendanceRegisterRequest.getRequestInfo().getUserInfo().getUuid() + " does not have permission to modify the register " + registerFromDB.getId()); + } + } + } + + /* Validates Request Info and User Info */ + private void validateRequestInfo(RequestInfo requestInfo, Map errorMap) { + if (requestInfo == null) { + log.error("Request info is mandatory"); + throw new CustomException("REQUEST_INFO", "Request info is mandatory"); + } + if (requestInfo.getUserInfo() == null) { + log.error("UserInfo is mandatory"); + throw new CustomException("USERINFO", "UserInfo is mandatory"); + } + if (requestInfo.getUserInfo() != null && StringUtils.isBlank(requestInfo.getUserInfo().getUuid())) { + log.error("UUID is mandatory"); + throw new CustomException("USERINFO_UUID", "UUID is mandatory"); + } + } + + private void validateReferenceIdAndServiceCodeParams(List attendanceRegisters, Map errorMap) { + for (int i = 0; i < attendanceRegisters.size(); i++) { + if (StringUtils.isBlank(attendanceRegisters.get(i).getReferenceId())) { + log.error("ReferenceId is mandatory"); + errorMap.put("REFERENCE_ID", "ReferenceId is mandatory"); + } + + if (StringUtils.isBlank(attendanceRegisters.get(i).getServiceCode())) { + log.error("ServiceCode is mandatory"); + errorMap.put("SERVICE_CODE", "ServiceCode is mandatory"); + } + } + } + + /* Validates Attendance register request body for create and update apis */ + private void validateAttendanceRegisterRequest(List attendanceRegisters, Map errorMap) { + if (attendanceRegisters == null || attendanceRegisters.size() == 0) { + log.error("Attendance Register is mandatory"); + throw new CustomException("ATTENDANCE_REGISTER", "Attendance Register is mandatory"); + } + + for (int i = 0; i < attendanceRegisters.size(); i++) { + if (attendanceRegisters.get(i) == null) { + log.error("Attendance Register is mandatory"); + throw new CustomException("ATTENDANCE_REGISTER", "Attendance Register is mandatory"); + } + if (StringUtils.isBlank(attendanceRegisters.get(i).getTenantId())) { + log.error("Tenant is mandatory"); + throw new CustomException("TENANT_ID", "Tenant is mandatory"); + } + if (StringUtils.isBlank(attendanceRegisters.get(i).getName())) { + log.error("Name is mandatory"); + errorMap.put("NAME", "Name is mandatory"); + } + + if (attendanceRegisters.get(i).getStartDate() == null || + (attendanceRegisters.get(i).getStartDate() != null && attendanceRegisters.get(i).getStartDate().compareTo(BigDecimal.ZERO) == 0)) { + log.error("Start date is mandatory for attendance register " + attendanceRegisters.get(i).getName()); + throw new CustomException("START_DATE", "Start date is mandatory"); + } + if (attendanceRegisters.get(i).getStartDate().compareTo(BigDecimal.ZERO) < 0) { + log.error("Start date is less than zero " + attendanceRegisters.get(i).getName()); + throw new CustomException("START_DATE", "Start date should be valid"); + } + if (attendanceRegisters.get(i).getEndDate() != null && attendanceRegisters.get(i).getStartDate().compareTo(attendanceRegisters.get(i).getEndDate()) > 0) { + log.error("Start date should be less than end date for attendance register " + attendanceRegisters.get(i).getName()); + errorMap.put("DATE", "Start date should be less than end date"); + } + if (!attendanceRegisters.get(i).getTenantId().equals(attendanceRegisters.get(0).getTenantId())) { + log.error("All registers must have same tenant Id. Please create new request for different tenant id"); + throw new CustomException("MULTIPLE_TENANTS", "All registers must have same tenant Id. Please create new request for different tenant id"); + } + } + } + + private void validateMDMSData(List attendanceRegisters, Object mdmsData, Map errorMap) { + + final String jsonPathForTenants = "$.MdmsRes." + MDMS_TENANT_MODULE_NAME + "." + MASTER_TENANTS + ".*"; + + List tenantRes = null; + try { + tenantRes = JsonPath.read(mdmsData, jsonPathForTenants); + } catch (Exception e) { + log.error(e.getMessage()); + throw new CustomException("JSONPATH_ERROR", "Failed to parse mdms response"); + } + + if (CollectionUtils.isEmpty(tenantRes)){ + log.error("The tenant: " + attendanceRegisters.get(0).getTenantId() + " is not present in MDMS"); + errorMap.put("INVALID_TENANT", "The tenant: " + attendanceRegisters.get(0).getTenantId() + " is not present in MDMS"); + } + } + + public void validateSearchRegisterRequest(RequestInfoWrapper requestInfoWrapper, AttendanceRegisterSearchCriteria searchCriteria) { + if (searchCriteria == null || requestInfoWrapper == null) { + log.error("Register search criteria request is mandatory"); + throw new CustomException("REGISTER_SEARCH_CRITERIA_REQUEST", "Register search criteria request is mandatory"); + } + + Map errorMap = new HashMap<>(); + + validateRequestInfo(requestInfoWrapper.getRequestInfo(),errorMap); + + if (StringUtils.isBlank(searchCriteria.getTenantId())) { + log.error("Tenant is mandatory"); + throw new CustomException("TENANT_ID", "Tenant is mandatory"); + } + + // Throw exception if required parameters are missing + if (!errorMap.isEmpty()) + throw new CustomException(errorMap); + } + + public void validateRegisterAgainstDB(List registerIds, List attendanceRegisterListFromDB, String tenantId) { + + Set uniqueRegisterIdsFromRequest = new HashSet<>(registerIds); + + Set uniqueRegisterIdsFromDB = attendanceRegisterListFromDB.stream() + .map(register -> register.getId()).collect(Collectors.toSet()); + + //check if all register ids from request exist in db + for (String idFromRequest : uniqueRegisterIdsFromRequest) { + if (!uniqueRegisterIdsFromDB.contains(idFromRequest)) { + log.error("Attendance Registers with register id : " + idFromRequest + " does not exist for tenantId"); + throw new CustomException("REGISTER_ID", "Attendance Registers with register id : " + idFromRequest + " does not exist for tenantId"); + } + } + + } +} diff --git a/health-services/attendance/src/main/java/org/egov/validator/AttendeeServiceValidator.java b/health-services/attendance/src/main/java/org/egov/validator/AttendeeServiceValidator.java new file mode 100644 index 00000000000..57f990b1a0d --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/validator/AttendeeServiceValidator.java @@ -0,0 +1,379 @@ +package org.egov.validator; + +import com.jayway.jsonpath.JsonPath; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.egov.common.contract.request.RequestInfo; +import org.egov.tracer.model.CustomException; +import org.egov.util.IndividualServiceUtil; +import org.egov.util.MDMSUtils; +import org.egov.web.models.AttendanceRegister; +import org.egov.web.models.AttendeeCreateRequest; +import org.egov.web.models.AttendeeDeleteRequest; +import org.egov.web.models.IndividualEntry; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import java.math.BigDecimal; +import java.util.*; +import java.util.stream.Collectors; + +import static org.egov.util.AttendanceServiceConstants.MASTER_TENANTS; +import static org.egov.util.AttendanceServiceConstants.MDMS_TENANT_MODULE_NAME; + +@Component +@Slf4j +public class AttendeeServiceValidator { + + @Autowired + private MDMSUtils mdmsUtils; + + @Autowired + private IndividualServiceUtil individualServiceUtil; + + public void validateAttendeeCreateRequestParameters(AttendeeCreateRequest attendeeCreateRequest) { + List attendeeList = attendeeCreateRequest.getAttendees(); + Map errorMap = new HashMap<>(); + + if (attendeeList == null || attendeeList.isEmpty()) { + log.error("ATTENDEE Object is empty in attendee request"); + throw new CustomException("ATTENDEE", "ATTENDEE Object is empty in attendee request"); + } + + String tenantId = attendeeList.get(0).getTenantId(); + for (IndividualEntry attendee : attendeeList) { + + //validate request parameters for each attendee object + if (StringUtils.isBlank(attendee.getRegisterId())) { + log.error("register id is empty in attendee request"); + errorMap.put("REGISTER_ID", "Register id is mandatory"); + } + + if (StringUtils.isBlank(attendee.getIndividualId())) { + log.error("individual id is empty in attendee request"); + errorMap.put("INDIVIDUAL_ID", "Individual id is mandatory"); + } + + if (StringUtils.isBlank(attendee.getTenantId())) { + log.error("tenant id is empty in attendee request"); + errorMap.put("TENANT_ID", "Tenant id is mandatory"); + } + } + + if (!errorMap.isEmpty()) { + log.error("Attendee request validation failed"); + throw new CustomException(errorMap); + } + validateTenantIds(attendeeCreateRequest, tenantId); + validateDuplicateAttendeeObjects(attendeeCreateRequest); + + //validate tenantId with MDMS + log.info("validating tenant id from MDMS and Request info"); + validateMDMSAndRequestInfoForCreateAttendee(attendeeCreateRequest); + + //validate individualId with Individual Service + log.info("validating tenant id from MDMS and Request info"); + validateIndividualId(attendeeCreateRequest); + } + + private void validateIndividualId(AttendeeCreateRequest attendeeCreateRequest) { + RequestInfo requestInfo=attendeeCreateRequest.getRequestInfo(); + String tenantId=attendeeCreateRequest.getAttendees().get(0).getTenantId(); + List individualIds=attendeeCreateRequest.getAttendees().stream().map(attendee->attendee.getIndividualId()).collect(Collectors.toList()); + List ids= individualServiceUtil.fetchIndividualIds(individualIds,requestInfo,tenantId); + + for(String individualId:individualIds){ + if(!ids.contains(individualId)){ + throw new CustomException("INDIVIDUAL_ID_NOT_FOUND","Individual with id: "+individualId+" not found"); + } + } + } + + public void validateTenantIds(AttendeeCreateRequest attendeeCreateRequest, String tenantId) { + List attendeeList = attendeeCreateRequest.getAttendees(); + //validate if all attendee in the list have the same tenant id + for (IndividualEntry attendee : attendeeList) { + if (!attendee.getTenantId().equals(tenantId)) { + log.error("All attendees dont have the same tenant id in attendee request"); + throw new CustomException("TENANT_ID", "All Attendees to be enrolled or de enrolled must have the same tenant id. Please raise new request for different tenant id"); + } + } + + } + + public void validateDuplicateAttendeeObjects(AttendeeCreateRequest attendeeCreateRequest) { + List attendeeList = attendeeCreateRequest.getAttendees(); + + Set uniqueIds = new HashSet<>(); + for (IndividualEntry attendee : attendeeList) { + String uniqueId = attendee.getRegisterId() + attendee.getIndividualId(); + if (uniqueIds.isEmpty()) { + uniqueIds.add(attendee.getRegisterId() + attendee.getIndividualId()); + } else if (uniqueIds.contains(uniqueId)) { + log.error("Duplicate Attendee Objects found in request"); + throw new CustomException("ATTENDEE", "Duplicate attendee Objects present in request"); + } + uniqueIds.add(attendee.getRegisterId() + attendee.getIndividualId()); + } + } + + + public void validateAttendeeDeleteRequestParameters(AttendeeDeleteRequest attendeeDeleteRequest, Map errorMap) { + + List attendeeList = attendeeDeleteRequest.getAttendees(); + + if (attendeeList == null || attendeeList.isEmpty()) { + log.error("ATTENDEE Object is empty in attendee request"); + throw new CustomException("ATTENDEES", "ATTENDEE object is mandatory"); + } + + String tenantId = attendeeList.get(0).getTenantId(); + for (IndividualEntry attendee : attendeeList) { + + //validate request parameters for each attendee object + if (StringUtils.isBlank(attendee.getRegisterId())) { + log.error("REGISTER_ID is empty in attendee request"); + errorMap.put("REGISTER_ID", "Register id is mandatory"); + } + + if (StringUtils.isBlank(attendee.getIndividualId())) { + log.error("INDIVIDUAL_ID is empty in attendee request"); + errorMap.put("INDIVIDUAL_ID", "Individual id is mandatory"); + } + + if (StringUtils.isBlank(attendee.getTenantId())) { + log.error("TENANT_ID is empty in attendee request"); + errorMap.put("TENANT_ID", "Tenant id is mandatory"); + } + } + + if (!errorMap.isEmpty()) { + log.error("Attendee request validation failed"); + throw new CustomException(errorMap); + } + + validateTenantIds(attendeeDeleteRequest, tenantId); + validateDuplicateAttendeeObjects(attendeeDeleteRequest); + + //validate tenantId with MDMS + log.info("validating tenant id from MDMS and Request info"); + validateMDMSAndRequestInfoForDeleteAttendee(attendeeDeleteRequest); + + //validate individualId with Individual Service + log.info("validating tenant id from MDMS and Request info"); + validateIndividualId(attendeeDeleteRequest); + } + + private void validateIndividualId(AttendeeDeleteRequest attendeeDeleteRequest) { + RequestInfo requestInfo=attendeeDeleteRequest.getRequestInfo(); + String tenantId=attendeeDeleteRequest.getAttendees().get(0).getTenantId(); + List individualIds=attendeeDeleteRequest.getAttendees().stream().map(attendee->attendee.getIndividualId()).collect(Collectors.toList()); + List ids= individualServiceUtil.fetchIndividualIds(individualIds,requestInfo,tenantId); + + for(String individualId:individualIds){ + if(!ids.contains(individualId)){ + throw new CustomException("INDIVIDUAL_ID_NOT_FOUND","Individual with id: "+individualId+" not found"); + } + } + } + + public void validateTenantIds(AttendeeDeleteRequest attendeeDeleteRequest, String tenantId) { + List attendeeList = attendeeDeleteRequest.getAttendees(); + //validate if all attendee in the list have the same tenant id + for (IndividualEntry attendee : attendeeList) { + if (!attendee.getTenantId().equals(tenantId)) { + log.error("All attendees dont have the same tenant id in attendee request"); + throw new CustomException("TENANT_ID", "All Attendees to be enrolled or de enrolled must have the same tenant id. Please raise new request for different tenant id"); + } + } + + } + + public void validateDuplicateAttendeeObjects(AttendeeDeleteRequest attendeeDeleteRequest) { + List attendeeList = attendeeDeleteRequest.getAttendees(); + + Set uniqueIds = new HashSet<>(); + for (IndividualEntry attendee : attendeeList) { + String uniqueId = attendee.getRegisterId() + attendee.getIndividualId(); + if (uniqueIds.isEmpty()) { + uniqueIds.add(attendee.getRegisterId() + attendee.getIndividualId()); + } else if (uniqueIds.contains(uniqueId)) { + log.error("Duplicate Attendee Objects found in request"); + throw new CustomException("ATTENDEE", "Duplicate attendee Objects present in request"); + } + uniqueIds.add(attendee.getRegisterId() + attendee.getIndividualId()); + } + } + + public void validateMDMSAndRequestInfoForCreateAttendee(AttendeeCreateRequest attendeeCreateRequest) { + + RequestInfo requestInfo = attendeeCreateRequest.getRequestInfo(); + List attendeeListFromRequest = attendeeCreateRequest.getAttendees(); + Map errorMap = new HashMap<>(); + + String tenantId = attendeeListFromRequest.get(0).getTenantId(); + //split the tenantId + String rootTenantId = tenantId.split("\\.")[0]; + + Object mdmsData = mdmsUtils.mDMSCall(requestInfo, rootTenantId); + + //check tenant Id + log.info("validate tenantId with MDMS"); + validateMDMSData(tenantId, mdmsData, errorMap); + + + //validate request-info + log.info("validate request info coming from api request"); + validateRequestInfo(requestInfo, errorMap); + + if (!errorMap.isEmpty()) + throw new CustomException(errorMap); + } + + public void validateMDMSAndRequestInfoForDeleteAttendee(AttendeeDeleteRequest attendeeDeleteRequest) { + + RequestInfo requestInfo = attendeeDeleteRequest.getRequestInfo(); + List attendeeListFromRequest = attendeeDeleteRequest.getAttendees(); + Map errorMap = new HashMap<>(); + + String tenantId = attendeeListFromRequest.get(0).getTenantId(); + //split the tenantId + String rootTenantId = tenantId.split("\\.")[0]; + + Object mdmsData = mdmsUtils.mDMSCall(requestInfo, rootTenantId); + + //check tenant Id + log.info("validate tenantId with MDMS"); + validateMDMSData(tenantId, mdmsData, errorMap); + + + //validate request-info + log.info("validate request info coming from api request"); + validateRequestInfo(requestInfo, errorMap); + + if (!errorMap.isEmpty()) + throw new CustomException(errorMap); + } + + + public void validateAttendeeOnCreate(AttendeeCreateRequest attendeeCreateRequest + , List attendeeListFromDB, List attendanceRegisterListFromDB) { + + List attendeeListFromRequest = attendeeCreateRequest.getAttendees(); + + + // attendee cannot be added to register if register's end date has passed + log.info("verifying that attendee cannot be added to register if register's end date has passed"); + BigDecimal currentDate = new BigDecimal(System.currentTimeMillis()); + for (AttendanceRegister attendanceRegister : attendanceRegisterListFromDB) { + int dateComparisonResult = attendanceRegister.getEndDate().compareTo(currentDate); + if (dateComparisonResult < 0) { + throw new CustomException("END_DATE", "Attendee cannot be enrolled as END_DATE of register id " + attendanceRegister.getId() + " has already passed."); + } + } + + //attendee enrollment date, if present in request should be after start date and before end date of register + log.info("checking attendee enrollment date should be after start date and before end date of register"); + for (AttendanceRegister attendanceRegister : attendanceRegisterListFromDB) { + for (IndividualEntry attendeeFromRequest : attendeeListFromRequest) { + if (attendanceRegister.getId().equals(attendeeFromRequest.getRegisterId())) { + if (attendeeFromRequest.getEnrollmentDate() != null) { + int startDateCompare = attendeeFromRequest.getEnrollmentDate().compareTo(attendanceRegister.getStartDate()); + int endDateCompare = attendanceRegister.getEndDate().compareTo(attendeeFromRequest.getEnrollmentDate()); + if (startDateCompare < 0 || endDateCompare < 0) { + throw new CustomException("ENROLLMENT_DATE" + , "Enrollment date for attendee : " + attendeeFromRequest.getIndividualId() + " must be within start and end date of the register"); + } + } + } + } + } + + //check if attendee is already enrolled to the register + log.info("checking if attendee is already enrolled to the register"); + for (IndividualEntry attendeeFromRequest : attendeeListFromRequest) { + for (IndividualEntry attendeeFromDB : attendeeListFromDB) { + if (attendeeFromRequest.getRegisterId().equals(attendeeFromDB.getRegisterId()) + && attendeeFromRequest.getIndividualId().equals(attendeeFromDB.getIndividualId())) {//attendee present in db + if (attendeeFromDB.getDenrollmentDate() == null) { // already enrolled to the register + throw new CustomException("INDIVIDUAL_ID", "Attendee " + attendeeFromRequest.getIndividualId() + " is already enrolled in the register " + attendeeFromRequest.getRegisterId()); + + } + } + } + } + } + + public void validateAttendeeOnDelete(AttendeeDeleteRequest attendeeDeleteRequest, + List attendeeListFromDB, List attendanceRegisterListFromDB) { + + List attendeeListFromRequest = attendeeDeleteRequest.getAttendees(); + + + //attendee de-enrollment date, if present in request should be before end date and after start date of register + log.info("verifying attendee de-enrollment date, if present in request should be before end date and after start date of register"); + for (AttendanceRegister attendanceRegister : attendanceRegisterListFromDB) { + for (IndividualEntry attendeeFromRequest : attendeeListFromRequest) { + if (attendeeFromRequest.getDenrollmentDate() != null) { + int startDateCompare = attendeeFromRequest.getDenrollmentDate().compareTo(attendanceRegister.getStartDate()); + int endDateCompare = attendanceRegister.getEndDate().compareTo(attendeeFromRequest.getDenrollmentDate()); + if (startDateCompare < 0 || endDateCompare < 0) { + throw new CustomException("DE ENROLLMENT_DATE" + , "De enrollment date for attendee : " + attendeeFromRequest.getIndividualId() + " must be between start date and end date of the register"); + } + } + } + } + + //check if attendee is already de-enrolled from the register + log.info("checking if attendee is already de-enrolled from the register"); + boolean attendeeDeEnrolled = true; + for (IndividualEntry attendeeFromRequest : attendeeListFromRequest) { + for (IndividualEntry attendeeFromDB : attendeeListFromDB) { + if (attendeeFromRequest.getRegisterId().equals(attendeeFromDB.getRegisterId()) && attendeeFromDB.getIndividualId().equals(attendeeFromRequest.getIndividualId())) { //attendee present in db + if (attendeeFromDB.getDenrollmentDate() == null) { + attendeeDeEnrolled = false; + break; + } + } + } + if (attendeeDeEnrolled) { + throw new CustomException("INDIVIDUAL_ID", "Attendee " + attendeeFromRequest.getIndividualId() + " is already de enrolled from the register " + attendeeFromRequest.getRegisterId()); + } + } + + } + + private void validateRequestInfo(RequestInfo requestInfo, Map errorMap) { + if (requestInfo == null) { + log.error("Request info is null"); + throw new CustomException("REQUEST_INFO", "Request info is mandatory"); + } + if (requestInfo.getUserInfo() == null) { + log.error("User info is null"); + throw new CustomException("USERINFO", "UserInfo is mandatory"); + } + if (requestInfo.getUserInfo() != null && StringUtils.isBlank(requestInfo.getUserInfo().getUuid())) { + log.error("User's UUID field is empty"); + throw new CustomException("USERINFO_UUID", "User's UUID is mandatory"); + } + } + + private void validateMDMSData(String tenantId, Object mdmsData, Map errorMap) { + final String jsonPathForTenants = "$.MdmsRes." + MDMS_TENANT_MODULE_NAME + "." + MASTER_TENANTS + ".*"; + + List tenantRes = null; + try { + tenantRes = JsonPath.read(mdmsData, jsonPathForTenants); + } catch (Exception e) { + log.error(e.getMessage()); + throw new CustomException("JSONPATH_ERROR", "Failed to parse mdms response"); + } + + if (CollectionUtils.isEmpty(tenantRes)) + errorMap.put("INVALID_TENANT", "The tenant: " + tenantId + " is not present in MDMS"); + } +} + + diff --git a/health-services/attendance/src/main/java/org/egov/validator/StaffServiceValidator.java b/health-services/attendance/src/main/java/org/egov/validator/StaffServiceValidator.java new file mode 100644 index 00000000000..f47d853d512 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/validator/StaffServiceValidator.java @@ -0,0 +1,267 @@ +package org.egov.validator; + +import com.jayway.jsonpath.JsonPath; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.egov.common.contract.request.RequestInfo; +import org.egov.service.AttendanceRegisterService; +import org.egov.tracer.model.CustomException; +import org.egov.util.MDMSUtils; +import org.egov.web.models.AttendanceRegister; +import org.egov.web.models.StaffPermission; +import org.egov.web.models.StaffPermissionRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import java.math.BigDecimal; +import java.util.*; + +import static org.egov.util.AttendanceServiceConstants.MASTER_TENANTS; +import static org.egov.util.AttendanceServiceConstants.MDMS_TENANT_MODULE_NAME; + + +@Component +@Slf4j +public class StaffServiceValidator { + + @Autowired + private MDMSUtils mdmsUtils; + + @Autowired + private AttendanceRegisterService attendanceRegisterService; + + + public void validateMDMSAndRequestInfoForStaff(StaffPermissionRequest request) { + RequestInfo requestInfo = request.getRequestInfo(); + List staffPermissionListFromRequest = request.getStaff(); + Map errorMap = new HashMap<>(); + + String tenantId = staffPermissionListFromRequest.get(0).getTenantId(); + //split the tenantId + String rootTenantId = tenantId.split("\\.")[0]; + + Object mdmsData = mdmsUtils.mDMSCall(requestInfo, rootTenantId); + + //validate request-info + log.info("validate request info coming from api request"); + validateRequestInfo(requestInfo, errorMap); + + //check tenant Id + log.info("validate tenantId with MDMS"); + validateMDMSData(tenantId, mdmsData, errorMap); + + if (!errorMap.isEmpty()) + throw new CustomException(errorMap); + } + + private void validateRequestInfo(RequestInfo requestInfo, Map errorMap) { + if (requestInfo == null) { + log.error("Request info is null"); + throw new CustomException("REQUEST_INFO", "Request info is mandatory"); + } + if (requestInfo.getUserInfo() == null) { + log.error("UserInfo is null"); + throw new CustomException("USERINFO", "UserInfo is mandatory"); + } + if (requestInfo.getUserInfo() != null && StringUtils.isBlank(requestInfo.getUserInfo().getUuid())) { + log.error("User's UUID field is empty"); + throw new CustomException("USERINFO_UUID", "User's UUID is mandatory"); + } + } + + + public void validateStaffPermissionRequestParameters(StaffPermissionRequest staffPermissionRequest) { + List staffPermissionList = staffPermissionRequest.getStaff(); + Map errorMap = new HashMap<>(); + + if (staffPermissionList == null || staffPermissionList.isEmpty()) { + log.error("Staff Object is empty in staff request"); + throw new CustomException("STAFF", "Staff is mandatory"); + } + + String baseTenantId = staffPermissionList.get(0).getTenantId(); + for (StaffPermission staffPermission : staffPermissionList) { + + //validate request parameters for each staff object + if (StringUtils.isBlank(staffPermission.getRegisterId())) { + log.error("Register id is empty in staff request"); + errorMap.put("REGISTER_ID", "Register id is mandatory"); + } + + if (StringUtils.isBlank(staffPermission.getUserId())) { + log.error("User id is empty in staff request"); + errorMap.put("USER_ID", "User id is mandatory"); + } + + if (StringUtils.isBlank(staffPermission.getTenantId())) { + log.error("Tenant id is empty in staff request"); + errorMap.put("TENANT_ID", "Tenant id is mandatory"); + } + } + + if (!errorMap.isEmpty()) { + log.error("Attendee request validation failed"); + throw new CustomException(errorMap); + } + + validateTenantIds(staffPermissionRequest, baseTenantId); + validateDuplicateStaffObjects(staffPermissionRequest); + + + //validate tenant id with mdms and request info + log.info("validating tenant id from MDMS and Request info"); + validateMDMSAndRequestInfoForStaff(staffPermissionRequest); + } + + public void validateTenantIds(StaffPermissionRequest staffPermissionRequest, String tenantId) { + List staffPermissionList = staffPermissionRequest.getStaff(); + //validate if all staff in the list have the same tenant id + for (StaffPermission staffPermission : staffPermissionList) { + if (!staffPermission.getTenantId().equals(tenantId)) { + log.error("All staff objects do not have the same tenant id"); + throw new CustomException("TENANT_ID", "All Staff to be enrolled or de enrolled must have the same tenant id. Please raise new request for different tenant id"); + } + } + + } + + public void validateDuplicateStaffObjects(StaffPermissionRequest staffPermissionRequest) { + List staffPermissionList = staffPermissionRequest.getStaff(); + + Set uniqueIds = new HashSet<>(); + for (StaffPermission staffPermission : staffPermissionList) { + String uniqueId = staffPermission.getRegisterId() + staffPermission.getUserId(); + if (uniqueIds.isEmpty()) { + uniqueIds.add(staffPermission.getRegisterId() + staffPermission.getUserId()); + } else if (uniqueIds.contains(uniqueId)) { + log.error("Duplicate Staff Objects found in request"); + throw new CustomException("STAFF", "Duplicate Staff Objects present in request"); + } + uniqueIds.add(staffPermission.getRegisterId() + staffPermission.getUserId()); + } + } + + public void validateStaffPermissionOnCreate(StaffPermissionRequest request, List staffPermissionListFromDB, + List attendanceRegisterListFromDB) { + + List staffPermissionListFromRequest = request.getStaff(); + + // staff cannot be added to register if register's end date has passed + log.info("checking that staff cannot be added to register if register's end date has passed"); + BigDecimal enrollmentDate = new BigDecimal(System.currentTimeMillis()); + for (AttendanceRegister attendanceRegister : attendanceRegisterListFromDB) { + int dateComparisonResult = attendanceRegister.getEndDate().compareTo(enrollmentDate); + if (dateComparisonResult < 0) { + log.error("Staff cannot be enrolled as END_DATE of register id " + attendanceRegister.getId() + " has already passed."); + throw new CustomException("END_DATE", "Staff cannot be enrolled as END_DATE of register id " + attendanceRegister.getId() + " has already passed."); + } + } + + //check if staff user id exists in staff table for the given register id. If yes check the deenrollment date. If staffId does not exist new staff can still be enrolled to the register + if (staffPermissionListFromDB != null) { + for (StaffPermission staffFromRequest : staffPermissionListFromRequest) {//list of staff from request + StaffPermission staff = staffPermissionListFromDB.stream() + .filter(s -> s.getUserId().equals(staffFromRequest.getUserId()) && s.getRegisterId().equals(staffFromRequest.getRegisterId())) + .findFirst().orElse(null); + if (staff != null && staff.getDenrollmentDate() == null) { + throw new CustomException("USER_id", "Staff " + staff.getUserId() + " is already enrolled in the register " + staff.getRegisterId()); + } + } + } + + } + + + public void validateStaffPermissionOnDelete(StaffPermissionRequest staffPermissionRequest + , List staffPermissionListFromDB, List attendanceRegisterListFromDB) { + + RequestInfo requestInfo = staffPermissionRequest.getRequestInfo(); + List staffPermissionListFromRequest = staffPermissionRequest.getStaff(); + + boolean staffExists = false; + boolean staffDeenrolled = true; + + + //check is staff user id exists in staff table. If yes check if the de enrollment date is null + log.info("checking if the de enrollment date of staff is null"); + for (StaffPermission staffPermissionFromRequest : staffPermissionListFromRequest) { + for (StaffPermission staffPermissionFromDB : staffPermissionListFromDB) { + if (staffPermissionFromRequest.getRegisterId().equals(staffPermissionFromDB.getRegisterId()) && + staffPermissionFromRequest.getUserId().equals(staffPermissionFromDB.getUserId())) { + staffExists = true; + if (staffPermissionFromDB.getDenrollmentDate() == null) { + staffDeenrolled = false; + break; + } + } + } + if (!staffExists) + throw new CustomException("USER_ID", "Staff with the given user id: " + staffPermissionFromRequest.getUserId() + " is not linked with the given register id");//handled + if (staffDeenrolled) + throw new CustomException("USER_ID", "Staff with the given user id : " + staffPermissionFromRequest.getUserId() + " is already de enrolled from the register"); + } + + + //staff list size associated with the register (At least one staff should remain with a register before de enrollment) + //initialize request and DB hashmaps with registerId as key + log.info("checking that atleast one staff should remain enrolled to a register before de enrollment"); + HashMap staffCountInEachRegisterIdFromRequest = new HashMap<>(); + HashMap staffCountInEachRegisterIdFromDB = new HashMap<>(); + for (AttendanceRegister attendanceRegister : attendanceRegisterListFromDB) { + staffCountInEachRegisterIdFromRequest.put(attendanceRegister.getId().toString(), 0); + staffCountInEachRegisterIdFromDB.put(attendanceRegister.getId().toString(), 0); + } + + + // from staffRequest - number of de enrollments from each register + for (StaffPermission staffPermissionFromRequest : staffPermissionListFromRequest) { + String staffRegisterId = staffPermissionFromRequest.getRegisterId(); + if (staffCountInEachRegisterIdFromRequest.containsKey(staffRegisterId)) { + int count = staffCountInEachRegisterIdFromRequest.get(staffRegisterId); + count++; + staffCountInEachRegisterIdFromRequest.put(staffRegisterId, count); + } + } + + + // from StaffDB data number of staff enrolled to each register in db + for (StaffPermission staffPermissionFromDB : staffPermissionListFromDB) { + String staffRegisterId = staffPermissionFromDB.getRegisterId(); + if (staffCountInEachRegisterIdFromDB.containsKey(staffRegisterId) && staffPermissionFromDB.getDenrollmentDate() == null) { + int count = staffCountInEachRegisterIdFromDB.get(staffRegisterId); + count++; + staffCountInEachRegisterIdFromDB.put(staffRegisterId, count); + } + } + + //match the regitser ids between request and db. subtract the staff, If <1 throw error + for (String registerId : staffCountInEachRegisterIdFromRequest.keySet()) { + if (staffCountInEachRegisterIdFromDB.containsKey(registerId)) { + int result = staffCountInEachRegisterIdFromDB.get(registerId) - staffCountInEachRegisterIdFromRequest.get(registerId); + if (result < 1) { + throw new CustomException("MIN_STAFF_REQUIRED", "Atleast one staff should be associated" + + "with the register. Number of staff in register id : " + registerId + " after de enrollment operation would be " + result); + } + } + } + } + + + private void validateMDMSData(String tenantId, Object mdmsData, Map errorMap) { + final String jsonPathForTenants = "$.MdmsRes." + MDMS_TENANT_MODULE_NAME + "." + MASTER_TENANTS + ".*"; + + List tenantRes = null; + try { + tenantRes = JsonPath.read(mdmsData, jsonPathForTenants); + } catch (Exception e) { + log.error(e.getMessage()); + throw new CustomException("JSONPATH_ERROR", "Failed to parse mdms response"); + } + + if (CollectionUtils.isEmpty(tenantRes)) + errorMap.put("INVALID_TENANT", "The tenant: " + tenantId + " is not present in MDMS"); + } + + +} diff --git a/health-services/attendance/src/main/java/org/egov/web/controllers/AttendanceApiController.java b/health-services/attendance/src/main/java/org/egov/web/controllers/AttendanceApiController.java new file mode 100644 index 00000000000..08c07365b32 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/controllers/AttendanceApiController.java @@ -0,0 +1,71 @@ +package org.egov.web.controllers; + + +import com.fasterxml.jackson.databind.ObjectMapper; +import digit.models.coremodels.RequestInfoWrapper; +import io.swagger.annotations.ApiParam; +import org.egov.common.contract.response.ResponseInfo; +import org.egov.service.AttendanceRegisterService; +import org.egov.util.ResponseInfoFactory; +import org.egov.web.models.AttendanceRegister; +import org.egov.web.models.AttendanceRegisterRequest; +import org.egov.web.models.AttendanceRegisterResponse; +import org.egov.web.models.AttendanceRegisterSearchCriteria; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.util.List; + +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2022-11-14T14:44:21.051+05:30") + +@Controller +@RequestMapping("/v1") +public class AttendanceApiController { + + @Autowired + private ObjectMapper objectMapper; + + @Autowired + private HttpServletRequest request; + + @Autowired + private ResponseInfoFactory responseInfoCreator; + + @Autowired + private AttendanceRegisterService attendanceRegisterService; + @Autowired + private ResponseInfoFactory responseInfoFactory; + + @RequestMapping(value = "/_create", method = RequestMethod.POST) + public ResponseEntity createAttendanceRegister(@ApiParam(value = "", allowableValues = "application/json") @RequestHeader(value = "Content-Type", required = false) String contentType, @ApiParam(value = "") @Valid @RequestBody AttendanceRegisterRequest attendanceRegisterRequest) { + AttendanceRegisterRequest enrichedAttendanceRegisterRequest = attendanceRegisterService.createAttendanceRegister(attendanceRegisterRequest); + + ResponseInfo responseInfo = responseInfoFactory.createResponseInfoFromRequestInfo(attendanceRegisterRequest.getRequestInfo(), true); + AttendanceRegisterResponse attendanceRegisterResponse = AttendanceRegisterResponse.builder().responseInfo(responseInfo).attendanceRegister(enrichedAttendanceRegisterRequest.getAttendanceRegister()).build(); + return new ResponseEntity(attendanceRegisterResponse, HttpStatus.OK); + } + + @RequestMapping(value = "/_search", method = RequestMethod.POST) + public ResponseEntity searchAttendanceRegister(@Valid @ModelAttribute AttendanceRegisterSearchCriteria searchCriteria, @Valid @RequestBody RequestInfoWrapper requestInfoWrapper) { + List attendanceRegisterList = attendanceRegisterService.searchAttendanceRegister(requestInfoWrapper, searchCriteria); + ResponseInfo responseInfo = responseInfoCreator.createResponseInfoFromRequestInfo(requestInfoWrapper.getRequestInfo(), true); + AttendanceRegisterResponse attendanceRegisterResponse = AttendanceRegisterResponse.builder().responseInfo(responseInfo).attendanceRegister(attendanceRegisterList).build(); + return new ResponseEntity(attendanceRegisterResponse, HttpStatus.OK); + } + + @RequestMapping(value = "/_update", method = RequestMethod.POST) + public ResponseEntity updateAttendanceRegister(@ApiParam(value = "", allowableValues = "application/json") @RequestHeader(value = "Content-Type", required = false) String contentType, @ApiParam(value = "") @Valid @RequestBody AttendanceRegisterRequest attendanceRegisterRequest) { + AttendanceRegisterRequest enrichedAttendanceRegisterRequest = attendanceRegisterService.updateAttendanceRegister(attendanceRegisterRequest); + + ResponseInfo responseInfo = responseInfoFactory.createResponseInfoFromRequestInfo(attendanceRegisterRequest.getRequestInfo(), true); + AttendanceRegisterResponse attendanceRegisterResponse = AttendanceRegisterResponse.builder().responseInfo(responseInfo).attendanceRegister(enrichedAttendanceRegisterRequest.getAttendanceRegister()).build(); + return new ResponseEntity(attendanceRegisterResponse, HttpStatus.OK); + } + + +} diff --git a/health-services/attendance/src/main/java/org/egov/web/controllers/AttendanceLogApiController.java b/health-services/attendance/src/main/java/org/egov/web/controllers/AttendanceLogApiController.java new file mode 100644 index 00000000000..d1983fcd971 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/controllers/AttendanceLogApiController.java @@ -0,0 +1,82 @@ +package org.egov.web.controllers; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.annotations.ApiParam; +import org.egov.common.contract.response.ResponseInfo; +import org.egov.config.AttendanceLogConfiguration; +import org.egov.common.producer.Producer; +import org.egov.service.AttendanceLogService; +import org.egov.util.ResponseInfoFactory; +import org.egov.web.models.AttendanceLogRequest; +import org.egov.web.models.AttendanceLogResponse; +import org.egov.web.models.AttendanceLogSearchCriteria; +import org.egov.web.models.RequestInfoWrapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; + +@Controller +@RequestMapping("/log/v1") +public class AttendanceLogApiController { + + + @Autowired + private ObjectMapper objectMapper; + + @Autowired + private HttpServletRequest request; + + @Autowired + private AttendanceLogService attendanceLogService; + + @Autowired + private ResponseInfoFactory responseInfoFactory; + + @Autowired + private AttendanceLogConfiguration attendanceLogConfiguration; + + @Autowired + private HttpServletRequest httpServletRequest; + + @Autowired + private Producer producer; + + @RequestMapping(value = "/_create", method = RequestMethod.POST) + public ResponseEntity attendanceLogV1CreatePOST(@ApiParam(value = "", allowableValues = "application/json") @RequestHeader(value = "Content-Type", required = false) String contentType, @ApiParam(value = "") @Valid @RequestBody AttendanceLogRequest attendanceLogRequest) { + AttendanceLogResponse attendanceLogResponse = attendanceLogService.createAttendanceLog(attendanceLogRequest); + return new ResponseEntity(attendanceLogResponse, HttpStatus.OK); + } + + @RequestMapping(value = "/bulk/_create", method = RequestMethod.POST) + public ResponseEntity attendanceLogV1BulkCreatePost(@ApiParam(value = "", allowableValues = "application/json") @RequestHeader(value = "Content-Type", required = false) String contentType, @ApiParam(value = "") @Valid @RequestBody AttendanceLogRequest attendanceLogRequest) { + attendanceLogRequest.getRequestInfo().setApiId(httpServletRequest.getRequestURI()); + attendanceLogService.putInCache(attendanceLogRequest.getAttendance()); + producer.push(attendanceLogConfiguration.getCreateAttendanceLogBulkTopic(), attendanceLogRequest); + return ResponseEntity.status(HttpStatus.ACCEPTED).body(responseInfoFactory.createResponseInfoFromRequestInfo(attendanceLogRequest.getRequestInfo(), true)); + } + @RequestMapping(value = "/_search", method = RequestMethod.POST) + public ResponseEntity attendanceLogV1SearchPOST(@Valid @ModelAttribute AttendanceLogSearchCriteria searchCriteria, @ApiParam(value = "") @Valid @RequestBody RequestInfoWrapper requestInfoWrapper) { + AttendanceLogResponse attendanceLogResponse = attendanceLogService.searchAttendanceLog(requestInfoWrapper, searchCriteria); + return new ResponseEntity(attendanceLogResponse, HttpStatus.OK); + } + + @RequestMapping(value = "/_update", method = RequestMethod.POST) + public ResponseEntity attendanceLogV1UpdatePOST(@ApiParam(value = "", allowableValues = "application/json") @RequestHeader(value = "Content-Type", required = false) String contentType, @ApiParam(value = "") @Valid @RequestBody AttendanceLogRequest attendanceLogRequest) { + AttendanceLogResponse attendanceLogResponse = attendanceLogService.updateAttendanceLog(attendanceLogRequest); + return new ResponseEntity(attendanceLogResponse, HttpStatus.OK); + } + + @RequestMapping(value = "/bulk/_update", method = RequestMethod.POST) + public ResponseEntity attendanceLogV1BulkUpdatePost(@ApiParam(value = "", allowableValues = "application/json") @RequestHeader(value = "Content-Type", required = false) String contentType, @ApiParam(value = "") @Valid @RequestBody AttendanceLogRequest attendanceLogRequest) { + attendanceLogRequest.getRequestInfo().setApiId(httpServletRequest.getRequestURI()); + attendanceLogService.putInCache(attendanceLogRequest.getAttendance()); + producer.push(attendanceLogConfiguration.getUpdateAttendanceLogBulkTopic(), attendanceLogRequest); + return ResponseEntity.status(HttpStatus.ACCEPTED).body(responseInfoFactory.createResponseInfoFromRequestInfo(attendanceLogRequest.getRequestInfo(), true)); + } + +} diff --git a/health-services/attendance/src/main/java/org/egov/web/controllers/AttendeeApiController.java b/health-services/attendance/src/main/java/org/egov/web/controllers/AttendeeApiController.java new file mode 100644 index 00000000000..60844961927 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/controllers/AttendeeApiController.java @@ -0,0 +1,57 @@ +package org.egov.web.controllers; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.annotations.ApiParam; +import org.egov.common.contract.response.ResponseInfo; +import org.egov.service.AttendeeService; +import org.egov.util.ResponseInfoFactory; +import org.egov.web.models.AttendeeCreateRequest; +import org.egov.web.models.AttendeeCreateResponse; +import org.egov.web.models.AttendeeDeleteRequest; +import org.egov.web.models.AttendeeDeleteResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; + +@Controller +@RequestMapping("/attendee/v1") +public class AttendeeApiController { + + @Autowired + private ObjectMapper objectMapper; + + @Autowired + private HttpServletRequest request; + + @Autowired + private AttendeeService attendeeService; + + @Autowired + private ResponseInfoFactory responseInfoFactory; + + @RequestMapping(value = "/_create", method = RequestMethod.POST) + public ResponseEntity createAttendee(@ApiParam(value = "", allowableValues = "application/json") @RequestHeader(value = "Content-Type", required = false) String contentType, @ApiParam(value = "") @Valid @RequestBody AttendeeCreateRequest attendeeCreateRequest) { + AttendeeCreateRequest enrichedRequest = attendeeService.createAttendee(attendeeCreateRequest); + ResponseInfo responseInfo = responseInfoFactory.createResponseInfoFromRequestInfo(attendeeCreateRequest.getRequestInfo(), true); + AttendeeCreateResponse attendeeCreateResponse = AttendeeCreateResponse.builder().responseInfo(responseInfo).attendees(enrichedRequest.getAttendees()).build(); + return new ResponseEntity(attendeeCreateResponse, HttpStatus.OK); + } + + + @RequestMapping(value = "/_delete", method = RequestMethod.POST) + public ResponseEntity deleteAttendee(@ApiParam(value = "", allowableValues = "application/json") @RequestHeader(value = "Content-Type", required = false) String contentType, @ApiParam(value = "") @Valid @RequestBody AttendeeDeleteRequest attendeeDeleteRequest) { + AttendeeDeleteRequest enrichedRequest = attendeeService.deleteAttendee(attendeeDeleteRequest); + ResponseInfo responseInfo = responseInfoFactory.createResponseInfoFromRequestInfo(attendeeDeleteRequest.getRequestInfo(), true); + AttendeeDeleteResponse attendeeDeleteResponse = AttendeeDeleteResponse.builder().responseInfo(responseInfo).attendees(enrichedRequest.getAttendees()).build(); + return new ResponseEntity(attendeeDeleteResponse, HttpStatus.OK); + } + +} diff --git a/health-services/attendance/src/main/java/org/egov/web/controllers/StaffApiController.java b/health-services/attendance/src/main/java/org/egov/web/controllers/StaffApiController.java new file mode 100644 index 00000000000..523fdeddb77 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/controllers/StaffApiController.java @@ -0,0 +1,57 @@ +package org.egov.web.controllers; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.annotations.ApiParam; +import org.egov.common.contract.response.ResponseInfo; +import org.egov.service.StaffService; +import org.egov.util.ResponseInfoFactory; +import org.egov.web.models.StaffPermissionRequest; +import org.egov.web.models.StaffPermissionResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; + +@Controller +@RequestMapping("/staff/v1") +public class StaffApiController { + + + @Autowired + private ObjectMapper objectMapper; + + @Autowired + private HttpServletRequest request; + + @Autowired + private StaffService staffService; + + @Autowired + private ResponseInfoFactory responseInfoFactory; + + @RequestMapping(value = "/_create", method = RequestMethod.POST) + public ResponseEntity createStaff(@ApiParam(value = "", allowableValues = "application/json") @RequestHeader(value = "Content-Type", required = false) String contentType, @ApiParam(value = "") @Valid @RequestBody StaffPermissionRequest staffPermissionRequest) { + StaffPermissionRequest enrichedRequest = staffService.createAttendanceStaff(staffPermissionRequest, false); + ResponseInfo responseInfo = responseInfoFactory.createResponseInfoFromRequestInfo(staffPermissionRequest.getRequestInfo(), true); + StaffPermissionResponse staffPermissionResponse = StaffPermissionResponse.builder().responseInfo(responseInfo) + .staff(enrichedRequest.getStaff()).build(); + return new ResponseEntity(staffPermissionResponse, HttpStatus.OK); + } + + @RequestMapping(value = "/_delete", method = RequestMethod.POST) + public ResponseEntity deleteStaff(@ApiParam(value = "", allowableValues = "application/json") @RequestHeader(value = "Content-Type", required = false) String contentType, @ApiParam(value = "") @Valid @RequestBody StaffPermissionRequest staffPermissionRequest) { + StaffPermissionRequest enrichedRequest = staffService.deleteAttendanceStaff(staffPermissionRequest); + ResponseInfo responseInfo = responseInfoFactory.createResponseInfoFromRequestInfo(staffPermissionRequest.getRequestInfo(), true); + StaffPermissionResponse staffPermissionResponse = StaffPermissionResponse.builder().responseInfo(responseInfo) + .staff(enrichedRequest.getStaff()).build(); + return new ResponseEntity(staffPermissionResponse, HttpStatus.OK); + } + +} diff --git a/health-services/attendance/src/main/java/org/egov/web/models/AttendanceLog.java b/health-services/attendance/src/main/java/org/egov/web/models/AttendanceLog.java new file mode 100644 index 00000000000..1ece72e8399 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/AttendanceLog.java @@ -0,0 +1,73 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import digit.models.coremodels.AuditDetails; +import lombok.*; +import org.springframework.validation.annotation.Validated; + +import javax.validation.Valid; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + * AttendanceLog + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2022-11-14T14:44:21.051+05:30") + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class AttendanceLog { + @JsonProperty("id") + private String id = null; + + @JsonProperty("clientReferenceId") + private String clientReferenceId = null; + + @JsonProperty("registerId") + private String registerId = null; + + @JsonProperty("individualId") + private String individualId = null; + + @JsonProperty("tenantId") + private String tenantId = null; + + @JsonProperty("time") + private BigDecimal time = null; + + @JsonProperty("type") + private String type = null; + + @JsonProperty("status") + private Status status = null; + + @JsonProperty("documentIds") + @Valid + private List documentIds = null; + + @JsonProperty("auditDetails") + private AuditDetails auditDetails = null; + + @JsonProperty("clientAuditDetails") + private AuditDetails clientAuditDetails = null; + + @JsonProperty("additionalDetails") + private Object additionalDetails = null; + + + public AttendanceLog addDocumentIdsItem(Document documentIdsItem) { + if (this.documentIds == null) { + this.documentIds = new ArrayList<>(); + } + this.documentIds.add(documentIdsItem); + return this; + } + +} + diff --git a/health-services/attendance/src/main/java/org/egov/web/models/AttendanceLogRequest.java b/health-services/attendance/src/main/java/org/egov/web/models/AttendanceLogRequest.java new file mode 100644 index 00000000000..ba275614a4b --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/AttendanceLogRequest.java @@ -0,0 +1,41 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; +import org.egov.common.contract.request.RequestInfo; +import org.springframework.validation.annotation.Validated; + +import javax.validation.Valid; +import java.util.ArrayList; +import java.util.List; + +/** + * AttendanceLogRequest + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2022-11-14T14:44:21.051+05:30") + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class AttendanceLogRequest { + @JsonProperty("RequestInfo") + private RequestInfo requestInfo = null; + + @JsonProperty("attendance") + @Valid + private List attendance = null; + + + public AttendanceLogRequest addAttendanceItem(AttendanceLog attendanceItem) { + if (this.attendance == null) { + this.attendance = new ArrayList<>(); + } + this.attendance.add(attendanceItem); + return this; + } + +} + diff --git a/health-services/attendance/src/main/java/org/egov/web/models/AttendanceLogResponse.java b/health-services/attendance/src/main/java/org/egov/web/models/AttendanceLogResponse.java new file mode 100644 index 00000000000..1a0c4776cc8 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/AttendanceLogResponse.java @@ -0,0 +1,41 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; +import org.egov.common.contract.response.ResponseInfo; +import org.springframework.validation.annotation.Validated; + +import javax.validation.Valid; +import java.util.ArrayList; +import java.util.List; + +/** + * AttendanceLogResponse + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2022-11-14T14:44:21.051+05:30") + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class AttendanceLogResponse { + @JsonProperty("ResponseInfo") + private ResponseInfo responseInfo = null; + + @JsonProperty("attendance") + @Valid + private List attendance = null; + + + public AttendanceLogResponse addAttendanceItem(AttendanceLog attendanceItem) { + if (this.attendance == null) { + this.attendance = new ArrayList<>(); + } + this.attendance.add(attendanceItem); + return this; + } + +} + diff --git a/health-services/attendance/src/main/java/org/egov/web/models/AttendanceLogSearchCriteria.java b/health-services/attendance/src/main/java/org/egov/web/models/AttendanceLogSearchCriteria.java new file mode 100644 index 00000000000..1db3162b112 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/AttendanceLogSearchCriteria.java @@ -0,0 +1,62 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; +import org.egov.web.models.Status; + +import java.math.BigDecimal; +import java.util.List; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class AttendanceLogSearchCriteria { + + @JsonProperty("ids") + private List ids; + + @JsonProperty("clientReferenceIds") + private List clientReferenceIds; + + @JsonProperty("tenantId") + private String tenantId; + + @JsonProperty("registerId") + private String registerId; + + @JsonProperty("fromTime") + private BigDecimal fromTime; + + @JsonProperty("toTime") + private BigDecimal toTime; + + @JsonProperty("individualIds") + private List individualIds; + + @JsonProperty("status") + private Status status; + + @JsonProperty("limit") + private Integer limit; + + @JsonProperty("offset") + private Integer offset; + + @JsonProperty("sortBy") + private SortBy sortBy; + + @JsonProperty("sortOrder") + private SortOrder sortOrder; + + public enum SortOrder { + ASC, + DESC + } + + public enum SortBy { + lastModifiedTime + } + +} diff --git a/health-services/attendance/src/main/java/org/egov/web/models/AttendanceRegister.java b/health-services/attendance/src/main/java/org/egov/web/models/AttendanceRegister.java new file mode 100644 index 00000000000..637a41d0d23 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/AttendanceRegister.java @@ -0,0 +1,84 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import digit.models.coremodels.AuditDetails; +import lombok.*; +import org.springframework.validation.annotation.Validated; + +import javax.validation.Valid; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +/** + * AttendanceRegister + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2022-11-14T14:44:21.051+05:30") + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class AttendanceRegister { + @JsonProperty("id") + private String id = null; + + @JsonProperty("tenantId") + private String tenantId = null; + + @JsonProperty("registerNumber") + private String registerNumber = null; + + @JsonProperty("name") + private String name = null; + + @JsonProperty("referenceId") + private String referenceId; + + @JsonProperty("serviceCode") + private String serviceCode; + + @JsonProperty("startDate") + private BigDecimal startDate = null; + + @JsonProperty("endDate") + private BigDecimal endDate = null; + + @JsonProperty("status") + private Status status = Status.ACTIVE; + + @JsonProperty("staff") + @Valid + private List staff = null; + + @JsonProperty("attendees") + @Valid + private List attendees = null; + + @JsonProperty("auditDetails") + private AuditDetails auditDetails = null; + + @JsonProperty("additionalDetails") + private Object additionalDetails = null; + + + public AttendanceRegister addStaffItem(StaffPermission staffItem) { + if (this.staff == null) { + this.staff = new ArrayList<>(); + } + this.staff.add(staffItem); + return this; + } + + public AttendanceRegister addAttendeesItem(IndividualEntry attendeesItem) { + if (this.attendees == null) { + this.attendees = new ArrayList<>(); + } + this.attendees.add(attendeesItem); + return this; + } + +} + diff --git a/health-services/attendance/src/main/java/org/egov/web/models/AttendanceRegisterRequest.java b/health-services/attendance/src/main/java/org/egov/web/models/AttendanceRegisterRequest.java new file mode 100644 index 00000000000..7359b59d984 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/AttendanceRegisterRequest.java @@ -0,0 +1,30 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; +import org.egov.common.contract.request.RequestInfo; +import org.springframework.validation.annotation.Validated; + +import java.util.List; + +/** + * AttendanceRegisterRequest + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2022-11-14T14:44:21.051+05:30") + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class AttendanceRegisterRequest { + @JsonProperty("RequestInfo") + private RequestInfo requestInfo = null; + + @JsonProperty("attendanceRegister") + private List attendanceRegister = null; + + +} + diff --git a/health-services/attendance/src/main/java/org/egov/web/models/AttendanceRegisterResponse.java b/health-services/attendance/src/main/java/org/egov/web/models/AttendanceRegisterResponse.java new file mode 100644 index 00000000000..973a4fa253d --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/AttendanceRegisterResponse.java @@ -0,0 +1,41 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; +import org.egov.common.contract.response.ResponseInfo; +import org.springframework.validation.annotation.Validated; + +import javax.validation.Valid; +import java.util.ArrayList; +import java.util.List; + +/** + * AttendanceRegisterResponse + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2022-11-14T14:44:21.051+05:30") + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class AttendanceRegisterResponse { + @JsonProperty("ResponseInfo") + private ResponseInfo responseInfo = null; + + @JsonProperty("attendanceRegister") + @Valid + private List attendanceRegister = null; + + + public AttendanceRegisterResponse addAttendanceRegisterItem(AttendanceRegister attendanceRegisterItem) { + if (this.attendanceRegister == null) { + this.attendanceRegister = new ArrayList<>(); + } + this.attendanceRegister.add(attendanceRegisterItem); + return this; + } + +} + diff --git a/health-services/attendance/src/main/java/org/egov/web/models/AttendanceRegisterSearchCriteria.java b/health-services/attendance/src/main/java/org/egov/web/models/AttendanceRegisterSearchCriteria.java new file mode 100644 index 00000000000..141598881bc --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/AttendanceRegisterSearchCriteria.java @@ -0,0 +1,75 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; + +import java.math.BigDecimal; +import java.util.List; + + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +@ToString +public class AttendanceRegisterSearchCriteria { + + @JsonProperty("tenantId") + private String tenantId; + + @JsonProperty("ids") + private List ids; + + @JsonProperty("registerNumber") + private String registerNumber; + + @JsonProperty("name") + private String name; + + @JsonProperty("fromDate") + private BigDecimal fromDate; + + @JsonProperty("toDate") + private BigDecimal toDate; + + @JsonProperty("status") + private Status status; + + @JsonProperty("attendeeId") + private String attendeeId; + + @JsonProperty("staffId") + private String staffId; + + @JsonProperty("referenceId") + private String referenceId; + + @JsonProperty("serviceCode") + private String serviceCode; + + @JsonProperty("limit") + private Integer limit; + + @JsonProperty("offset") + private Integer offset; + + @JsonProperty("sortBy") + private SortBy sortBy; + + @JsonProperty("sortOrder") + private SortOrder sortOrder; + + public enum SortOrder { + ASC, + DESC + } + + public enum SortBy { + lastModifiedTime, + fromDate, + toDate + } + +} diff --git a/health-services/attendance/src/main/java/org/egov/web/models/AttendeeCreateRequest.java b/health-services/attendance/src/main/java/org/egov/web/models/AttendeeCreateRequest.java new file mode 100644 index 00000000000..6a0096d7e15 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/AttendeeCreateRequest.java @@ -0,0 +1,40 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; +import org.egov.common.contract.request.RequestInfo; +import org.springframework.validation.annotation.Validated; + +import javax.validation.Valid; +import java.util.ArrayList; +import java.util.List; + +/** + * AttendeeCreateRequest + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2022-11-14T14:44:21.051+05:30") + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class AttendeeCreateRequest { + @JsonProperty("RequestInfo") + private RequestInfo requestInfo = null; + + @JsonProperty("attendees") + @Valid + private List attendees = null; + + public AttendeeCreateRequest addAttendeesItem(IndividualEntry attendeesItem) { + if (this.attendees == null) { + this.attendees = new ArrayList<>(); + } + this.attendees.add(attendeesItem); + return this; + } + +} + diff --git a/health-services/attendance/src/main/java/org/egov/web/models/AttendeeCreateResponse.java b/health-services/attendance/src/main/java/org/egov/web/models/AttendeeCreateResponse.java new file mode 100644 index 00000000000..9e708dff0af --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/AttendeeCreateResponse.java @@ -0,0 +1,41 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; +import org.egov.common.contract.response.ResponseInfo; +import org.springframework.validation.annotation.Validated; + +import javax.validation.Valid; +import java.util.ArrayList; +import java.util.List; + +/** + * AttendeeCreateResponse + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2022-11-14T14:44:21.051+05:30") + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class AttendeeCreateResponse { + @JsonProperty("ResponseInfo") + private ResponseInfo responseInfo = null; + + @JsonProperty("attendees") + @Valid + private List attendees = null; + + + public AttendeeCreateResponse addAttendeesItem(IndividualEntry attendeesItem) { + if (this.attendees == null) { + this.attendees = new ArrayList<>(); + } + this.attendees.add(attendeesItem); + return this; + } + +} + diff --git a/health-services/attendance/src/main/java/org/egov/web/models/AttendeeDeleteRequest.java b/health-services/attendance/src/main/java/org/egov/web/models/AttendeeDeleteRequest.java new file mode 100644 index 00000000000..156ddc71d24 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/AttendeeDeleteRequest.java @@ -0,0 +1,40 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; +import org.egov.common.contract.request.RequestInfo; +import org.springframework.validation.annotation.Validated; + +import javax.validation.Valid; +import java.util.ArrayList; +import java.util.List; + +/** + * AttendeeDeleteRequest + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2022-11-14T14:44:21.051+05:30") + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class AttendeeDeleteRequest { + @JsonProperty("RequestInfo") + private RequestInfo requestInfo = null; + + @JsonProperty("attendees") + @Valid + private List attendees = null; + + public AttendeeDeleteRequest addAttendeesItem(IndividualEntry attendeesItem) { + if (this.attendees == null) { + this.attendees = new ArrayList<>(); + } + this.attendees.add(attendeesItem); + return this; + } + +} + diff --git a/health-services/attendance/src/main/java/org/egov/web/models/AttendeeDeleteResponse.java b/health-services/attendance/src/main/java/org/egov/web/models/AttendeeDeleteResponse.java new file mode 100644 index 00000000000..e3ddd4e3a92 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/AttendeeDeleteResponse.java @@ -0,0 +1,41 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; +import org.egov.common.contract.response.ResponseInfo; +import org.springframework.validation.annotation.Validated; + +import javax.validation.Valid; +import java.util.ArrayList; +import java.util.List; + +/** + * AttendeeDeleteResponse + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2022-11-14T14:44:21.051+05:30") + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class AttendeeDeleteResponse { + @JsonProperty("ResponseInfo") + private ResponseInfo responseInfo; + + @JsonProperty("attendees") + @Valid + private List attendees = null; + + + public AttendeeDeleteResponse addAttendeesItem(IndividualEntry attendeesItem) { + if (this.attendees == null) { + this.attendees = new ArrayList<>(); + } + this.attendees.add(attendeesItem); + return this; + } + +} + diff --git a/health-services/attendance/src/main/java/org/egov/web/models/AttendeeSearchCriteria.java b/health-services/attendance/src/main/java/org/egov/web/models/AttendeeSearchCriteria.java new file mode 100644 index 00000000000..411c22eaa2a --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/AttendeeSearchCriteria.java @@ -0,0 +1,36 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; + +import java.math.BigDecimal; +import java.util.List; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class AttendeeSearchCriteria { + + @JsonProperty("ids") + private List ids; + + @JsonProperty("individualIds") + private List individualIds; + + @JsonProperty("registerIds") + private List registerIds; + + @JsonProperty("enrollmentDate") + private BigDecimal enrollmentDate = null; + + @JsonProperty("denrollmentDate") + private BigDecimal denrollmentDate = null; + + @JsonProperty("limit") + private Integer limit; + + @JsonProperty("offset") + private Integer offset; +} diff --git a/health-services/attendance/src/main/java/org/egov/web/models/Document.java b/health-services/attendance/src/main/java/org/egov/web/models/Document.java new file mode 100644 index 00000000000..f2b17520e75 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/Document.java @@ -0,0 +1,30 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class Document { + @JsonProperty("id") + private String id = null; + + @JsonProperty("documentType") + private String documentType = null; + + @JsonProperty("fileStore") + private String fileStore = null; + + @JsonProperty("documentUid") + private String documentUid = null; + + @JsonProperty("additionalDetails") + private Object additionalDetails = null; + + @JsonProperty("status") + @Builder.Default + private Status status = Status.ACTIVE; +} \ No newline at end of file diff --git a/health-services/attendance/src/main/java/org/egov/web/models/IndividualEntry.java b/health-services/attendance/src/main/java/org/egov/web/models/IndividualEntry.java new file mode 100644 index 00000000000..cea0ddfa0f2 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/IndividualEntry.java @@ -0,0 +1,49 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import digit.models.coremodels.AuditDetails; +import lombok.*; +import org.springframework.validation.annotation.Validated; + +import java.math.BigDecimal; +import java.util.UUID; + +/** + * IndividualEntry + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2022-11-14T14:44:21.051+05:30") + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class IndividualEntry { + @JsonProperty("id") + private String id = null; + + @JsonProperty("tenantId") + private String tenantId = null; + + @JsonProperty("registerId") + private String registerId = null; + + @JsonProperty("individualId") + private String individualId = null; + + @JsonProperty("enrollmentDate") + private BigDecimal enrollmentDate = null; + + @JsonProperty("denrollmentDate") + private BigDecimal denrollmentDate = null; + + @JsonProperty("auditDetails") + private AuditDetails auditDetails = null; + + @JsonProperty("additionalDetails") + private Object additionalDetails = null; + + +} + diff --git a/health-services/attendance/src/main/java/org/egov/web/models/Organisation/ContactDetails.java b/health-services/attendance/src/main/java/org/egov/web/models/Organisation/ContactDetails.java new file mode 100644 index 00000000000..da1b95c2785 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/Organisation/ContactDetails.java @@ -0,0 +1,83 @@ +package org.egov.web.models.Organisation; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.egov.common.models.core.Role; +import org.springframework.validation.annotation.Validated; + +import javax.validation.Valid; +import javax.validation.constraints.Size; +import java.util.List; + +/** + * Captures details of a contact person + */ +@ApiModel(description = "Captures details of a contact person") +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2023-02-15T14:49:42.141+05:30") + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class ContactDetails { + + @JsonProperty("id") + @Valid + private String id = null; + + @JsonProperty("tenantId") + private String tenantId = null; + + @JsonProperty("individualId") + private String individualId = null; + + @JsonProperty("orgId") + private String orgId = null; + + @JsonProperty("contactName") + @Size(min = 2, max = 64) + private String contactName = null; + + @JsonProperty("contactMobileNumber") + @Size(max = 20) + private String contactMobileNumber = null; + + @JsonProperty("contactEmail") + @Size(min = 5, max = 200) + private String contactEmail = null; + + @JsonProperty("active") + private Boolean active; + + @JsonProperty("roles") + @Valid + private List roles; + + @Size(max=50) + @JsonProperty("type") + private String type; + + @Size(max=64) + //@DiffIgnore + @JsonProperty("createdBy") + private String createdBy; + + //@DiffIgnore + @JsonProperty("createdDate") + private Long createdDate; + + @Size(max=64) + //@DiffIgnore + @JsonProperty("lastModifiedBy") + private String lastModifiedBy; + + //@DiffIgnore + @JsonProperty("lastModifiedDate") + private Long lastModifiedDate; + +} diff --git a/health-services/attendance/src/main/java/org/egov/web/models/Organisation/OrgContactUpdateDiff.java b/health-services/attendance/src/main/java/org/egov/web/models/Organisation/OrgContactUpdateDiff.java new file mode 100644 index 00000000000..607c587adfb --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/Organisation/OrgContactUpdateDiff.java @@ -0,0 +1,30 @@ +package org.egov.web.models.Organisation; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.egov.common.contract.request.RequestInfo; + +import java.util.List; +import java.util.Set; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class OrgContactUpdateDiff { + + @JsonProperty("RequestInfo") + private RequestInfo requestInfo; + + private String tenantId; + + private String organisationId; + + private List oldContacts; + + private List newContacts; + +} diff --git a/health-services/attendance/src/main/java/org/egov/web/models/RequestInfoWrapper.java b/health-services/attendance/src/main/java/org/egov/web/models/RequestInfoWrapper.java new file mode 100644 index 00000000000..4727044bdd3 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/RequestInfoWrapper.java @@ -0,0 +1,25 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; +import org.egov.common.contract.request.RequestInfo; +import org.springframework.validation.annotation.Validated; + +/** + * RequestInfoWrapper + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2022-11-14T14:44:21.051+05:30") + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class RequestInfoWrapper { + @JsonProperty("RequestInfo") + private RequestInfo requestInfo = null; + + +} + diff --git a/health-services/attendance/src/main/java/org/egov/web/models/StaffPermission.java b/health-services/attendance/src/main/java/org/egov/web/models/StaffPermission.java new file mode 100644 index 00000000000..d07cc0999f1 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/StaffPermission.java @@ -0,0 +1,48 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import digit.models.coremodels.AuditDetails; +import lombok.*; +import org.springframework.validation.annotation.Validated; + +import java.math.BigDecimal; + +/** + * StaffPermission + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2022-11-14T14:44:21.051+05:30") + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class StaffPermission { + @JsonProperty("id") + private String id = null; + + @JsonProperty("tenantId") + private String tenantId = null; + + @JsonProperty("registerId") + private String registerId = null; + + @JsonProperty("userId") + private String userId = null; + + @JsonProperty("enrollmentDate") + private BigDecimal enrollmentDate = null; + + @JsonProperty("denrollmentDate") + private BigDecimal denrollmentDate = null; + + @JsonProperty("auditDetails") + private AuditDetails auditDetails = null; + + @JsonProperty("additionalDetails") + private Object additionalDetails = null; + + +} + diff --git a/health-services/attendance/src/main/java/org/egov/web/models/StaffPermissionRequest.java b/health-services/attendance/src/main/java/org/egov/web/models/StaffPermissionRequest.java new file mode 100644 index 00000000000..578ab41e775 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/StaffPermissionRequest.java @@ -0,0 +1,30 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; +import org.egov.common.contract.request.RequestInfo; +import org.springframework.validation.annotation.Validated; + +import java.util.List; + +/** + * StaffPermissionRequest + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2022-11-14T14:44:21.051+05:30") + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class StaffPermissionRequest { + @JsonProperty("RequestInfo") + private RequestInfo requestInfo = null; + + @JsonProperty("staff") + private List staff = null; + + +} + diff --git a/health-services/attendance/src/main/java/org/egov/web/models/StaffPermissionResponse.java b/health-services/attendance/src/main/java/org/egov/web/models/StaffPermissionResponse.java new file mode 100644 index 00000000000..6ec9dca4e65 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/StaffPermissionResponse.java @@ -0,0 +1,30 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; +import org.egov.common.contract.response.ResponseInfo; +import org.springframework.validation.annotation.Validated; + +import java.util.List; + +/** + * StaffPermissionResponse + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2022-11-14T14:44:21.051+05:30") + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class StaffPermissionResponse { + @JsonProperty("ResponseInfo") + private ResponseInfo responseInfo = null; + + @JsonProperty("staff") + private List staff = null; + + +} + diff --git a/health-services/attendance/src/main/java/org/egov/web/models/StaffSearchCriteria.java b/health-services/attendance/src/main/java/org/egov/web/models/StaffSearchCriteria.java new file mode 100644 index 00000000000..1d29186d364 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/StaffSearchCriteria.java @@ -0,0 +1,29 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; + +import java.util.List; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class StaffSearchCriteria { + + @JsonProperty("tenantId") + private String tenantId; + + @JsonProperty("individualIds") + private List individualIds; + + @JsonProperty("registerIds") + private List registerIds; + + @JsonProperty("limit") + private Integer limit; + + @JsonProperty("offset") + private Integer offset; +} diff --git a/health-services/attendance/src/main/java/org/egov/web/models/Status.java b/health-services/attendance/src/main/java/org/egov/web/models/Status.java new file mode 100644 index 00000000000..1f86601f113 --- /dev/null +++ b/health-services/attendance/src/main/java/org/egov/web/models/Status.java @@ -0,0 +1,37 @@ +package org.egov.web.models; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Stores if the register is active or not. Inactive registers can be archieved later. + */ +public enum Status { + + ACTIVE("ACTIVE"), + + INACTIVE("INACTIVE"); + + private final String value; + + Status(String value) { + this.value = value; + } + + @Override + @JsonValue + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static Status fromValue(String text) { + for (Status b : Status.values()) { + if (String.valueOf(b.value).equals(text)) { + return b; + } + } + return null; + } +} + diff --git a/health-services/attendance/src/main/resources/Attendace Service Postman Scripts.postman_scripts_collection.json b/health-services/attendance/src/main/resources/Attendace Service Postman Scripts.postman_scripts_collection.json new file mode 100644 index 00000000000..d27e9f0effc --- /dev/null +++ b/health-services/attendance/src/main/resources/Attendace Service Postman Scripts.postman_scripts_collection.json @@ -0,0 +1,3671 @@ +{ + "info": { + "_postman_id": "25632b98-5918-4908-8a85-9500d8a81afa", + "name": "Attendace Service Postman Scripts", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "Attendance Register", + "item": [ + { + "name": "Create Attendance Register - Success - Single Register", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendance Registers are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendanceRegister).to.not.be.undefined;", + " pm.expect(req.attendanceRegister).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.tenantId).to.be.not.null;", + " pm.expect(register.tenantId).to.be.not.undefined;", + " pm.expect(register.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Register Name is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.name).to.be.not.null;", + " pm.expect(register.name).to.be.not.undefined;", + " pm.expect(register.name).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Register start date is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.startDate).to.be.not.null;", + " pm.expect(register.startDate).to.be.not.undefined;", + " pm.expect(register.startDate).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Start date should be less than end date\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " if (Number.isFinite(register.endDate) && (register.endDate != undefined || register.endDate != null )) {", + " pm.expect(register.endDate).to.be.not.below(register.startDate);", + " }", + " }", + ");", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Register Number is enriched\", function () {", + " var res = pm.response.json();", + " var registerNumber = res.attendanceRegister[0].registerNumber;", + " pm.expect(registerNumber.substring(0,2)).to.eql(\"WR\");", + " }", + ");", + "", + "pm.test(\"Register status is set to Active if status not passed\", function () {", + " var res = pm.response.json();", + " var status = res.attendanceRegister[0].status;", + " pm.expect(status).to.eql(\"ACTIVE\");", + " }", + ");", + "", + "pm.test(\"Staff is created for register\", function () {", + " var res = pm.response.json();", + " var staff = res.attendanceRegister[0].staff;", + " pm.expect(staff).to.be.not.null;", + " pm.expect(staff).to.be.not.undefined;", + " pm.expect(staff.length).to.eql(1);", + " }", + ");", + "", + "pm.test(\"Staff created have same userId as UUID of user\", function () {", + " var res = pm.response.json();", + " var userInRequest = res.attendanceRegister[0].auditDetails.createdBy;", + " var staff = res.attendanceRegister[0].staff;", + " pm.expect(staff[0].userId).to.eql(userInRequest);", + " }", + ");", + "", + "let responseData = pm.response.json();", + "pm.collectionVariables.set(\"tenantId\", responseData.attendanceRegister[0].tenantId);", + "pm.collectionVariables.set(\"stateLevelTenant\", responseData.attendanceRegister[0].tenantId.split('.', 1)[0]);", + "pm.collectionVariables.set(\"registerId\", responseData.attendanceRegister[0].id);", + "pm.collectionVariables.set(\"registerNumber\", responseData.attendanceRegister[0].registerNumber);", + "", + "pm.collectionVariables.set(\"registerStartDate\", responseData.attendanceRegister[0].startDate);", + "pm.collectionVariables.set(\"registerEndDate\", responseData.attendanceRegister[0].endDate);", + "pm.collectionVariables.set(\"invalidRegisterEndDate\", responseData.attendanceRegister[0].endDate+24*60*60*1000);" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "pm.collectionVariables.set(\"tenantId\", \"pb.amritsar\");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_01\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Success - Multiple Registers", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendance Registers are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendanceRegister).to.not.be.undefined;", + " pm.expect(req.attendanceRegister).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.tenantId).to.be.not.null;", + " pm.expect(register.tenantId).to.be.not.undefined;", + " pm.expect(register.tenantId).not.to.eql(\"\");", + " });", + " }", + ");", + "", + "pm.test(\"Register Name is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.name).to.be.not.null;", + " pm.expect(register.name).to.be.not.undefined;", + " pm.expect(register.name).not.to.eql(\"\");", + " });", + " }", + ");", + "", + "pm.test(\"Register start date is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.startDate).to.be.not.null;", + " pm.expect(register.startDate).to.be.not.undefined;", + " pm.expect(register.startDate).not.to.eql(\"\");", + " });", + " }", + ");", + " ", + "", + "pm.test(\"Start date should be less than end date\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " if (Number.isFinite(register.endDate) && (register.endDate != undefined || register.endDate != null )) {", + " pm.expect(register.endDate).to.be.not.below(register.startDate);", + " }", + " });", + " }", + ");", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Register Number is enriched\", function () {", + " var res = pm.response.json();", + " res.attendanceRegister.forEach(register => {", + " var registerNumber = register.registerNumber;", + " pm.expect(registerNumber.substring(0,2)).to.eql(\"WR\");", + " });", + " }", + ");", + "", + "pm.test(\"Staff is created for register\", function () {", + " var res = pm.response.json();", + " res.attendanceRegister.forEach(register => {", + " var staff = register.staff;", + " pm.expect(staff).to.be.not.null;", + " pm.expect(staff).to.be.not.undefined;", + " pm.expect(staff.length).to.eql(1);", + " }); ", + " }", + ");", + "", + "pm.test(\"Staff created have same userId as UUID of user\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var res = pm.response.json();", + " res.attendanceRegister.forEach(register => {", + " var userInRequest = register.auditDetails.createdBy;", + " var staff =register.staff;", + " pm.expect(staff[0].userId).to.eql(userInRequest);", + " }); ", + " }", + ");", + "", + "let responseData = pm.response.json();", + "pm.collectionVariables.set(\"registerId2\", responseData.attendanceRegister[1].id);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_01\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000\n },\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_02\",\n \"startDate\": 1640995200000,\n \"additionalDetails\": {}\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Validation Error - Registers not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"ATTENDANCE_REGISTER\");", + " pm.expect(message).to.eql(\"Attendance Register is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": []\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Validation Error - TenantId not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"TENANT_ID\");", + " pm.expect(message).to.eql(\"Tenant is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"name\": \"TestRegister_01\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Validation Error - Name not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"NAME\");", + " pm.expect(message).to.eql(\"Name is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Validation Error - Start Date not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"START_DATE\");", + " pm.expect(message).to.eql(\"Start date is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_01\",\n \"endDate\": 1703980800000\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Validation Error - Start Date greater than End Date", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"DATE\");", + " pm.expect(message).to.eql(\"Start date should be less than end date\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_01\",\n \"startDate\": 1803980800000,\n \"endDate\": 1703980800000\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Create Attendance Register - Validation Error - Start Date Equal to 0", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"START_DATE\");", + " pm.expect(message).to.eql(\"Start date is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_01\",\n \"startDate\": 0,\n \"endDate\": 1703980800000\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Success", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200)));", + "", + "pm.test(\"Register Search response is received\", function () {", + " var res = pm.response.json();", + " var id = res.attendanceRegister[0].id;", + " pm.expect(id).to.eql(pm.collectionVariables.get(\"registerId\"));", + " }", + ");" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"{{token}}\"\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?tenantId={{tenantId}}&ids={{registerId}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + }, + { + "key": "ids", + "value": "{{registerId}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Success - State level tenant", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200)));", + "", + "pm.test(\"Register Search response is received\", function () {", + " var res = pm.response.json();", + " var id = res.attendanceRegister[0].id;", + " pm.expect(id).to.eql(pm.collectionVariables.get(\"registerId\"));", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"{{token}}\"\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?tenantId={{stateLevelTenant}}&ids={{registerId}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{stateLevelTenant}}" + }, + { + "key": "ids", + "value": "{{registerId}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Success - Unassociated AttendeeId", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200)));", + "", + "pm.test(\"Register Search response is received\", function () {", + " var res = pm.response.json();", + " pm.expect(res.attendanceRegister.length).to.equal(0);", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"{{token}}\"\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?tenantId={{tenantId}}&ids={{registerId}}&attendeeId={{$guid}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + }, + { + "key": "ids", + "value": "{{registerId}}" + }, + { + "key": "attendeeId", + "value": "{{$guid}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Success - Unassociated StaffId", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200)));", + "", + "pm.test(\"Register Search response is received\", function () {", + " var res = pm.response.json();", + " pm.expect(res.attendanceRegister.length).to.equal(0);", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"{{token}}\"\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?tenantId={{tenantId}}&ids={{registerId}}&staffId={{$guid}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + }, + { + "key": "ids", + "value": "{{registerId}}" + }, + { + "key": "staffId", + "value": "{{$guid}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Success - SuperUser - Non existing RegisterID", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200)));", + "", + "pm.test(\"Register Search response is received\", function () {", + " var res = pm.response.json();", + " pm.expect(res.attendanceRegister.length).to.equal(0);", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"{{token}}\"\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?tenantId={{tenantId}}&ids={{$guid}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + }, + { + "key": "ids", + "value": "{{$guid}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Validation Error - Unassociated Register Id", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200)));", + "", + "pm.test(\"Register Search response is received\", function () {", + " var res = pm.response.json();", + " var code = res.attendanceRegister.length;", + " pm.expect(code).to.eql(0);", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"{{token}}\"\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?tenantId={{tenantId}}&ids=96d1055c-0251-498d-b98d-26d6c232925f", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + }, + { + "key": "ids", + "value": "96d1055c-0251-498d-b98d-26d6c232925f" + } + ] + } + }, + "response": [] + }, + { + "name": "Search Attendance Register - Validation Error - Tenant Id not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"TENANT_ID\");", + " pm.expect(message).to.eql(\"Tenant is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"action\": \"\",\n \"did\": 1,\n \"key\": \"\",\n \"msgId\": \"20170310130900|en_IN\",\n \"requesterId\": \"\",\n \"ts\": 1513579888683,\n \"ver\": \".01\",\n \"authToken\": \"{{token}}\"\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_search?ids={{registerId}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_search" + ], + "query": [ + { + "key": "ids", + "value": "{{registerId}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Update Attendance Register - Success - Single Register", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "", + "pm.test(\"Attendance Registers are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendanceRegister).to.not.be.undefined;", + " pm.expect(req.attendanceRegister).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.tenantId).to.be.not.null;", + " pm.expect(register.tenantId).to.be.not.undefined;", + " pm.expect(register.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Register Id is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.id).to.be.not.null;", + " pm.expect(register.id).to.be.not.undefined;", + " pm.expect(register.id).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Register Name is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.name).to.be.not.null;", + " pm.expect(register.name).to.be.not.undefined;", + " pm.expect(register.name).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Register start date is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " pm.expect(register.startDate).to.be.not.null;", + " pm.expect(register.startDate).to.be.not.undefined;", + " pm.expect(register.startDate).not.to.eql(\"\");", + " }", + ");", + " ", + "", + "pm.test(\"Start date should be less than end date\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var register = req.attendanceRegister[0];", + " if (Number.isFinite(register.endDate) && (register.endDate != undefined || register.endDate != null )) {", + " pm.expect(register.endDate).to.be.not.below(register.startDate);", + " }", + " }", + ");", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Staff is created for register\", function () {", + " var res = pm.response.json();", + " var staff = res.attendanceRegister[0].staff;", + " pm.expect(staff).to.be.not.null;", + " pm.expect(staff).to.be.not.undefined;", + " pm.expect(staff.length).to.eql(1);", + " }", + ");", + "", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"id\": \"{{registerId}}\",\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_010\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000,\n \"status\": \"ACTIVE\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Update Attendance Register - Success - Multiple Registers", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "", + "pm.test(\"Attendance Registers are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendanceRegister).to.not.be.undefined;", + " pm.expect(req.attendanceRegister).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.tenantId).to.be.not.null;", + " pm.expect(register.tenantId).to.be.not.undefined;", + " pm.expect(register.tenantId).not.to.eql(\"\");", + " });", + " }", + ");", + "", + "pm.test(\"Register Id is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.id).to.be.not.null;", + " pm.expect(register.id).to.be.not.undefined;", + " pm.expect(register.id).not.to.eql(\"\");", + " });", + " }", + ");", + "", + "pm.test(\"Register Name is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.name).to.be.not.null;", + " pm.expect(register.name).to.be.not.undefined;", + " pm.expect(register.name).not.to.eql(\"\");", + " });", + " }", + ");", + "", + "pm.test(\"Register start date is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " pm.expect(register.startDate).to.be.not.null;", + " pm.expect(register.startDate).to.be.not.undefined;", + " pm.expect(register.startDate).not.to.eql(\"\");", + " });", + " }", + ");", + " ", + "", + "pm.test(\"Start date should be less than end date\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendanceRegister.forEach(register => {", + " if (Number.isFinite(register.endDate) && (register.endDate != undefined || register.endDate != null )) {", + " pm.expect(register.endDate).to.be.not.below(register.startDate);", + " }", + " });", + " }", + ");", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"id\": \"{{registerId}}\",\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_010\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000,\n \"status\": \"ACTIVE\"\n },\n {\n \"id\": \"{{registerId2}}\",\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_020\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000,\n \"status\": \"INACTIVE\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Update Attendance Register - Validation Error - Register Id not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"ATTENDANCE_REGISTER_ID\");", + " pm.expect(message).to.eql(\"Attendance register id is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_010\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000,\n \"status\": \"ACTIVE\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Update Attendance Register - Validation Error - Tenant Id not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"TENANT_ID\");", + " pm.expect(message).to.eql(\"Tenant is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"id\": \"{{registerId}}\",\n \"name\": \"TestRegister_010\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000,\n \"status\": \"ACTIVE\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Update Attendance Register - Validation Error - Name not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"NAME\");", + " pm.expect(message).to.eql(\"Name is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"id\": \"{{registerId}}\",\n \"tenantId\": \"{{tenantId}}\",\n \"startDate\": 1640995200000,\n \"endDate\": 1703980800000,\n \"status\": \"ACTIVE\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Update Attendance Register - Validation Error - Start Date not provided", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Correct Error with message and code is received\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " var message = res.Errors[0].message;", + " pm.expect(code).to.eql(\"START_DATE\");", + " pm.expect(message).to.eql(\"Start date is mandatory\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Create Attendance Register\",\n \"authToken\": \"{{token}}\"\n },\n \"attendanceRegister\": [\n {\n \"id\": \"{{registerId}}\",\n \"tenantId\": \"{{tenantId}}\",\n \"name\": \"TestRegister_010\",\n \"endDate\": 1703980800000,\n \"status\": \"ACTIVE\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "v1", + "_update" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Register Permission", + "item": [ + { + "name": "Staff - Enroll - Single Staff", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Enrollment date is enriched\", function () {", + " var res = pm.response.json();", + " var enrollmentDate = res.staff[0].enrollmentDate;", + " pm.expect(enrollmentDate).to.be.not.null;", + " }", + ");", + "", + "// let requestData = JSON.parse(pm.request.body.raw);", + "// pm.collectionVariables.set(\"userId\", requestData.staff[0].userId);", + "", + "let responseData = pm.response.json();", + "pm.collectionVariables.set(\"userId\", responseData.staff[0].userId);", + "console.log(pm.collectionVariables.get(\"userId\"));", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Enroll the user to register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{$randomUUID}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Enroll - Validation Error - Staff already enrolled to the register", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"response is 400. Staff is already enrolled to the register\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "console.log(pm.collectionVariables.get(\"userId\"))" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Enroll the user to register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Enroll - Validation Error - Duplicate staff objects not allowed in enrollment request", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + "", + " req.staff.forEach(staff => {", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }); ", + "", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "", + "pm.test(\"Response is 400. Duplicate objects in request\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Enroll the user to register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"928ca23a-9bec-11ed-a8fc-0242ac120002\",\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"928ca23a-9bec-11ed-a8fc-0242ac120002\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Enroll - Multiple staff", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + "", + " req.staff.forEach(staff => {", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }); ", + "", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Enrollment date is enriched\", function () {", + " var res = pm.response.json();", + " res.staff.forEach(staff => {", + " pm.expect(staff.enrollmentDate).to.be.not.null;", + " }); ", + " }", + ");", + "", + "let requestData = JSON.parse(pm.request.body.raw);", + "pm.collectionVariables.set(\"userId-1\", requestData.staff[0].userId);", + "pm.collectionVariables.set(\"userId-2\", requestData.staff[1].userId);", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Enroll the user to register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{$randomUUID}}\",\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{$randomUUID}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Deenroll - Single staff", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Deenrollment date is enriched\", function () {", + " var res = pm.response.json();", + " var deenrollmentDate = res.staff[0].deenrollmentDate;", + " pm.expect(deenrollmentDate).to.be.not.null;", + " }", + ");", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Deenroll staff from register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_delete" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Deenroll - Validation Error - Staff already denrolled from the register", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var staff = req.staff[0];", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is 400. Staff already deenrolled from the register\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Deenroll staff from register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_delete" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Deenroll - Validation Error - Duplicate staff objects in deenrollment request", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + "", + " req.staff.forEach(staff => {", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }); ", + "", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Response is 400. Duplicate staff objects in de enrollment request\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Deenroll staff from register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId-1}}\",\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId-1}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_delete" + ] + } + }, + "response": [] + }, + { + "name": "Staff - Deenroll - Multiple staff", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Staff are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.staff).to.not.be.undefined;", + " pm.expect(req.staff).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + "", + " req.staff.forEach(staff => {", + " pm.expect(staff.tenantId).to.be.not.null;", + " pm.expect(staff.tenantId).to.be.not.undefined;", + " pm.expect(staff.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Staff registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.registerId).to.be.not.null;", + " pm.expect(staff.registerId).to.be.not.undefined;", + " pm.expect(staff.registerId).not.to.eql(\"\");", + " }); ", + "", + " }", + ");", + "", + "pm.test(\"Staff userId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.staff.forEach(staff => {", + " pm.expect(staff.userId).to.be.not.null;", + " pm.expect(staff.userId).to.be.not.undefined;", + " pm.expect(staff.userId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Deenrollment date is enriched\", function () {", + " var res = pm.response.json();", + " res.staff.forEach(staff => {", + " pm.expect(staff.deenrollmentDate).to.be.not.null;", + " }); ", + " }", + ");", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"Deenroll staff from register\",\n \"authToken\":\"{{token}}\"\n },\n \"staff\":[\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId-1}}\",\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\":\"{{registerId}}\",\n \"userId\":\"{{userId-2}}\",\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/staff/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "staff", + "v1", + "_delete" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Individual Enrollment", + "item": [ + { + "name": "Attendee - Enroll - Attendee", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendee are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Enrollment date is enriched\", function () {", + " var res = pm.response.json();", + " var enrollmentDate = res.attendees[0].enrollmentDate;", + " pm.expect(enrollmentDate).to.be.not.null;", + " }", + ");", + "", + "// let requestData = JSON.parse(pm.request.body.raw);", + "// pm.collectionVariables.set(\"individualId\", requestData.attendees[0].individualId);", + "let responseData = pm.response.json();", + "pm.collectionVariables.set(\"individualId\", responseData.attendees[0].individualId);", + "pm.collectionVariables.set(\"attendeeEnrollmentDate\", responseData.attendees[0].enrollmentDate);", + "", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Enroll attendee to register\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{$randomUUID}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n } \n\n ]\n\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Enroll - Validation Error - Attendee already enrolled", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendee are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is 400. Attendee already enrolled to the register\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Enroll attendee to register\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n } \n\n ]\n\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Enroll - Validation Error - Duplicate attendee objects not allowed in request", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendee are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "", + "pm.test(\"Response is 400. Duplicate attendee objects in the request\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Enroll attendee to register\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"928ca23a-9bec-11ed-a8fc-0242ac120002\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"928ca23a-9bec-11ed-a8fc-0242ac120002\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n } \n\n ]\n\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Enroll - Multiple Attendees", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendee are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Enrollment date is enriched\", function () {", + " var res = pm.response.json();", + " res.attendees.forEach(attendee => {", + " pm.expect(attendee.enrollmentDate).to.be.not.null;", + " }); ", + " }", + ");", + "", + "let requestData = JSON.parse(pm.request.body.raw);", + "pm.collectionVariables.set(\"individualId-1\", requestData.attendees[0].individualId);", + "pm.collectionVariables.set(\"individualId-2\", requestData.attendees[1].individualId);", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\": {\n \"apiId\": \"mukta-services\",\n \"ver\": null,\n \"ts\": null,\n \"action\": null,\n \"did\": null,\n \"key\": null,\n \"msgId\": \"Enroll attendee to register\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{$randomUUID}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{$randomUUID}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n } \n\n ]\n\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Deenroll- Single Attendee", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendees are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Deenrollment date is enriched\", function () {", + " var res = pm.response.json();", + " var deenrollmentDate = res.attendees[0].deenrollmentDate;", + " pm.expect(deenrollmentDate).to.be.not.null;", + " }", + ");", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"search with from and to values\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_delete" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Deenroll- Validation Error - Attendee already deenrolled from the register", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendees are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " var attendee = req.attendees[0];", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }", + ");", + "", + "", + "pm.test(\"Response is 400. Attendee already deenrolled from the register\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"search with from and to values\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_delete" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Deenroll- Validation Error - Duplicate attendee objects in deenrollment request", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendees are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "", + "pm.test(\"Response is 400. Duplicate attendee objects in deenrollment request.\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"search with from and to values\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId-1}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId-1}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_delete" + ] + } + }, + "response": [] + }, + { + "name": "Attendee - Deenroll- Multiple Attendees", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"RequestInfo is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.RequestInfo).to.not.be.null;", + " pm.expect(req.RequestInfo).to.not.be.undefined;", + " }", + ");", + "", + "pm.test(\"Attendees are required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " pm.expect(req.attendees).to.not.be.undefined;", + " pm.expect(req.attendees).to.not.be.null;", + " }", + ");", + "", + "pm.test(\"TenantId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.tenantId).to.be.not.null;", + " pm.expect(attendee.tenantId).to.be.not.undefined;", + " pm.expect(attendee.tenantId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee registerId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.registerId).to.be.not.null;", + " pm.expect(attendee.registerId).to.be.not.undefined;", + " pm.expect(attendee.registerId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "pm.test(\"Attendee individualId is required\", function () {", + " var req = JSON.parse(pm.request.body.raw);", + " req.attendees.forEach(attendee => {", + " pm.expect(attendee.individualId).to.be.not.null;", + " pm.expect(attendee.individualId).to.be.not.undefined;", + " pm.expect(attendee.individualId).not.to.eql(\"\");", + " }); ", + " }", + ");", + "", + "", + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Deenrollment date is enriched\", function () {", + " var res = pm.response.json();", + " res.attendees.forEach(attendee => {", + " pm.expect(attendee.denrollmentDate).to.be.not.null;", + " }); ", + " }", + ");", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RequestInfo\":{\n \"apiId\":\"mukta-services\",\n \"ver\":null,\n \"ts\":null,\n \"action\":null,\n \"did\":null,\n \"key\":null,\n \"msgId\":\"search with from and to values\",\n \"authToken\":\"{{token}}\"\n },\n \"attendees\":[\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId-1}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n },\n {\n \"registerId\": \"{{registerId}}\",\n \"individualId\": \"{{individualId-2}}\",\n \"enrollmentDate\":null,\n \"denrollmentDate\":null,\n \"tenantId\":\"{{tenantId}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/attendee/v1/_delete", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "attendee", + "v1", + "_delete" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Attendance Log", + "item": [ + { + "name": "Attendance Log - Create - Success", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + " setTimeout( () => {", + "", + " pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var id = res.attendance[0].id;", + " pm.expect(id).to.be.not.null;", + " }", + ");", + " ", + " }, 1000);", + "", + "", + "", + "let responseData = pm.response.json();", + "pm.collectionVariables.set(\"attendanceLogId\", responseData.attendance[0].id);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Update - Success", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Attendance Log updated successfully\", function () {", + " var res = pm.response.json();", + " var status = res.attendance[0].status;", + " pm.expect(status).to.eql(\"INACTIVE\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"id\": \"{{attendanceLogId}}\",\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"INACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ],\r\n \"auditDetails\": {\r\n \"createdBy\": \"47b5ea82-249c-4435-9646-16167fec06df\",\r\n \"lastModifiedBy\": \"47b5ea82-249c-4435-9646-16167fec06df\",\r\n \"createdTime\": 1671090269007,\r\n \"lastModifiedTime\": 1671090269007\r\n }\r\n \r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Update - fail - attendanceId is not valid", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log updated successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"ATTENDANCE_LOG\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"id\": \"{{$randomUUID}}\",\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"INACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ],\r\n \"auditDetails\": {\r\n \"createdBy\": \"47b5ea82-249c-4435-9646-16167fec06df\",\r\n \"lastModifiedBy\": \"47b5ea82-249c-4435-9646-16167fec06df\",\r\n \"createdTime\": 1671090269007,\r\n \"lastModifiedTime\": 1671090269007\r\n }\r\n \r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_update", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_update" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Create - Fail - All logs should belong to same tenantId", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"MULTIPLE_TENANTIDS\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n },\r\n {\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"tenant.id\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Create - Fail - Validate Attendance Log time", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"INVALID_ATTENDANCE_TIME\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{invalidRegisterEndDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Create - Fail - Register should belongs to tenenatId", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": \"{{$randomUUID}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Create - Fail - All logs should belong to same registerId", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"MULTIPLE_REGISTERIDS\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": \"{{registerId}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n },\r\n {\r\n \"registerId\": \"{{$randomUUID}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Create - Fail - User is not authorised", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"UNAUTHORISED_USER\");", + " }", + ");" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": \"{{$randomUUID}}\",\r\n \"individualId\": \"{{individualId}}\",\r\n \"time\": {{attendeeEnrollmentDate}},\r\n \"type\": \"ENTRY\",\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": \"{{tenantId}}\",\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Rearch - Fail - TenantId is required", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"TENANT_ID\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n }\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_search", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_search" + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Rearch - Fail - RegisterId is required", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " var code = res.Errors[0].code;", + " pm.expect(code).to.eql(\"REGISTER_ID\");", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n }\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_search?tenantId={{tenantId}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Rearch - Success", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(200))", + ");", + "", + "pm.test(\"Attendance Log created successfully\", function () {", + " var res = pm.response.json();", + " pm.expect(res.attendance).to.be.not.null;", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n }\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_search?tenantId={{tenantId}}®isterId={{registerId}}", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_search" + ], + "query": [ + { + "key": "tenantId", + "value": "{{tenantId}}" + }, + { + "key": "registerId", + "value": "{{registerId}}" + } + ] + } + }, + "response": [] + }, + { + "name": "Attendance Log - Create - Fail - required fields are missing", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response is successful\", () => ", + " pm.expect(pm.response.to.have.status(400)));", + "", + "pm.test(\"Register Search response is received\", function () {", + " var res = pm.response.json();", + " pm.expect(res.Errors.length).to.equal(5);", + " }", + ");" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"RequestInfo\": {\r\n \"apiId\": \"mukta-services\",\r\n \"action\": \"\",\r\n \"did\": 1,\r\n \"key\": \"\",\r\n \"msgId\": \"20170310130900|en_IN\",\r\n \"requesterId\": \"\",\r\n \"ts\": 1513579888683,\r\n \"ver\": \".01\",\r\n \"authToken\":\"{{token}}\"\r\n },\r\n \"attendance\": [\r\n {\r\n \"registerId\": null,\r\n \"individualId\": null,\r\n \"time\": null,\r\n \"type\": null,\r\n \"status\": \"ACTIVE\",\r\n \"tenantId\": null,\r\n \"documentIds\":[\r\n {\r\n \"documentType\": \"documentType\",\r\n \"fileStore\": \"fileStore\",\r\n \"documentUid\": \"documentUid\"\r\n }\r\n \r\n ]\r\n }\r\n ]\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{base_url}}/attendance/log/v1/_create", + "host": [ + "{{base_url}}" + ], + "path": [ + "attendance", + "log", + "v1", + "_create" + ] + } + }, + "response": [] + } + ] + } + ], + "event": [ + { + "listen": "prerequest", + "script": { + "type": "text/javascript", + "exec": [ + "if (pm.environment.get(\"base_url\").includes(\"localhost\")) {", + "", + " var tenantId = \"pb.amritsar\";", + " var id = 1;", + " var uuid = \"11b0e02b-0145-4de2-bc42-c97b96264807\";", + "", + " var roles = [{", + " \"code\": \"SUPERUSER\",", + " \"name\": \"SUPER USER\",", + " \"tenantId\": tenantId", + " }];", + "", + " var userInfo = {", + " \"id\": id,", + " \"uuid\": uuid,", + " \"userName\": \"\",", + " \"name\": \"\",", + " \"mobileNumber\": \"\",", + " \"emailId\": \"\",", + " \"type\": \"\",", + " \"roles\": roles,", + " \"active\": true,", + " \"tenantId\": \"pb.amritsar\"", + " };", + "", + " pm.request.body.raw = pm.request.body.raw.replace('\"{{token}}\"', '\"\", \\n \"userInfo\": ' + JSON.stringify(userInfo));", + "}" + ] + } + }, + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ], + "variable": [ + { + "key": "tenantId", + "value": "" + }, + { + "key": "stateLevelTenant", + "value": "" + }, + { + "key": "registerId", + "value": "" + }, + { + "key": "registerNumber", + "value": "" + }, + { + "key": "registerId2", + "value": "" + }, + { + "key": "registerStartDate", + "value": "" + }, + { + "key": "registerEndDate", + "value": "" + }, + { + "key": "invalidRegisterEndDate", + "value": "" + }, + { + "key": "userId", + "value": "" + }, + { + "key": "userId-1", + "value": "" + }, + { + "key": "userId-2", + "value": "" + }, + { + "key": "individualId", + "value": "" + }, + { + "key": "attendeeEnrollmentDate", + "value": "" + }, + { + "key": "individualId-1", + "value": "" + }, + { + "key": "individualId-2", + "value": "" + }, + { + "key": "attendanceLogId", + "value": "" + } + ] +} \ No newline at end of file diff --git a/health-services/attendance/src/main/resources/application.properties b/health-services/attendance/src/main/resources/application.properties new file mode 100644 index 00000000000..0d78a344b0f --- /dev/null +++ b/health-services/attendance/src/main/resources/application.properties @@ -0,0 +1,111 @@ +server.contextPath=/attendance +server.servlet.contextPath=/attendance +server.port=8023 +app.timezone=UTC +org.egov.detailed.tracing.enabled=true + +#-----------------KAFKA SERVER CONFIGURATIONS--------------------------------# +# KAFKA SERVER CONFIGURATIONS +kafka.config.bootstrap_server_config=localhost:9092 +spring.kafka.consumer.value-deserializer=org.egov.tracer.kafka.deserializer.HashMapDeserializer +spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer +spring.kafka.consumer.group-id=egov-pgr-services +spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer +spring.kafka.producer.value-serializer=org.springframework.kafka.support.serializer.JsonSerializer +# KAFKA CONSUMER CONFIGURATIONS +kafka.consumer.config.auto_commit=true +kafka.consumer.config.auto_commit_interval=100 +kafka.consumer.config.session_timeout=15000 +kafka.consumer.config.auto_offset_reset=earliest +spring.kafka.listener.missing-topics-fatal=false +spring.kafka.consumer.properties.spring.json.use.type.headers=false +# KAFKA PRODUCER CONFIGURATIONS +kafka.producer.config.retries_config=0 +kafka.producer.config.batch_size_config=16384 +kafka.producer.config.linger_ms_config=1 +kafka.producer.config.buffer_memory_config=33554432 +#org.egov.detailed.tracing.enabled = false + +logging.level.org.springframework.web: ERROR + +#----------------Postgres Configurations----------------# +spring.datasource.driver-class-name=org.postgresql.Driver +spring.datasource.url=jdbc:postgresql://localhost:5432/postgres +spring.datasource.username=postgres +spring.datasource.password=postgres + +#----------------flyway config----------------# +spring.flyway.enabled=true +spring.flyway.table=attendance_service_schema +spring.flyway.baseline-on-migrate=true + +#----------------MDMS config---------------------# +egov.mdms.host=https://unified-dev.digit.org +egov.mdms.search.endpoint=/egov-mdms-service/v1/_search +egov.mdmslegacy.search.endpoint=egov-mdms-service-legacy/v1/_search +egov.mdmslegacy.host=egov-mdms-service-legacy + +#----------------Idgen Config---------------------# +egov.idgen.host=https://unified-dev.digit.org +egov.idgen.path=/egov-idgen/id/_generate +egov.idgen.attendance.register.number.name=attendance.register.number + +#---------------Individual service----------------# +works.individual.host=https://unified-dev.digit.org/ +#works.individual.host=http://localhost:9090 +works.individual.search.endpoint=health-individual/v1/_search + + +#----------Individual/Staff service integration--------------# +attendance.individual.service.integration.required=false +attendance.staff.service.integration.required=false + +#----------Document Id Verification ----------------------# +attendance.document.id.verification.required=false + +#---------- Attendance log Search config ------------------# +#attendance.service.log.default.offset=0 +#attendance.service.log.default.limit=100 +#attendance.service.log.search.max.limit=200 + +#---------------- Attendance log Topic Config----------------# +attendance.log.kafka.create.topic=save-attendance-log +attendance.log.kafka.update.topic=update-attendance-log +attendance.log.kafka.consumer.bulk.create.topic=save-attendance-log-bulk-health +attendance.log.kafka.consumer.bulk.update.topic=update-attendance-log-bulk-health + +#--------------Attendance Register Topic Config------------------# +attendance.register.kafka.create.topic=save-attendance +attendance.register.kafka.update.topic=update-attendance +attendance.register.default.offset=0 +attendance.register.default.limit=10 +attendance.register.search.max.limit=1000 + +#-------------- Staff Topic Config------------------# +attendance.staff.kafka.create.topic=save-staff +attendance.staff.kafka.update.topic=update-staff + +#-------------- Attendee Topic Config------------------# +attendance.attendee.kafka.create.topic=save-attendee +attendance.attendee.kafka.update.topic=update-attendee + +# The value of the following field should be changed to service specific name +kafka.topics.consumer=health-attendance-consumer-topic + +#-------------- Update staff for change in contact detail of an organisation------------------# +organisation.contact.details.update.topic=organisation.contact.details.update + +#------------------------Attendance Register Time Extension topic------------------------------# +contracts.revision.topic=contracts-revision + +#------------------------------------------------------------------------------------------------# +#---Attendance Register Search : Comma separated roles that can do open search ------------------# +#------------------------------------------------------------------------------------------------# +attendance.register.open.search.enabled.roles=SUPERUSER,EMPLOYEE + +#-------------- Redis Config ------------------# +spring.redis.host=radis.backbone +spring.redis.port=6379 +spring.cache.type=redis +spring.cache.redis.time-to-live=60 +spring.cache.autoexpiry=true \ No newline at end of file diff --git a/health-services/attendance/src/main/resources/attendance-service-db-schema.png b/health-services/attendance/src/main/resources/attendance-service-db-schema.png new file mode 100644 index 00000000000..8fc615db963 Binary files /dev/null and b/health-services/attendance/src/main/resources/attendance-service-db-schema.png differ diff --git a/health-services/attendance/src/main/resources/attendance-service-test-coverage-report.png b/health-services/attendance/src/main/resources/attendance-service-test-coverage-report.png new file mode 100644 index 00000000000..a4246e0442f Binary files /dev/null and b/health-services/attendance/src/main/resources/attendance-service-test-coverage-report.png differ diff --git a/health-services/attendance/src/main/resources/db/Dockerfile b/health-services/attendance/src/main/resources/db/Dockerfile new file mode 100644 index 00000000000..a5699ff7d99 --- /dev/null +++ b/health-services/attendance/src/main/resources/db/Dockerfile @@ -0,0 +1,9 @@ +FROM egovio/flyway:4.1.2 + +COPY ./migration/main /flyway/sql + +COPY migrate.sh /usr/bin/migrate.sh + +RUN chmod +x /usr/bin/migrate.sh + +CMD ["/usr/bin/migrate.sh"] diff --git a/health-services/attendance/src/main/resources/db/migrate.sh b/health-services/attendance/src/main/resources/db/migrate.sh new file mode 100644 index 00000000000..43960b25cdb --- /dev/null +++ b/health-services/attendance/src/main/resources/db/migrate.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +flyway -url=$DB_URL -table=$SCHEMA_TABLE -user=$FLYWAY_USER -password=$FLYWAY_PASSWORD -locations=$FLYWAY_LOCATIONS -baselineOnMigrate=true -outOfOrder=true -ignoreMissingMigrations=true migrate \ No newline at end of file diff --git a/health-services/attendance/src/main/resources/db/migration/main/V20221122105730__create_attendance_table.sql b/health-services/attendance/src/main/resources/db/migration/main/V20221122105730__create_attendance_table.sql new file mode 100644 index 00000000000..749f02fee46 --- /dev/null +++ b/health-services/attendance/src/main/resources/db/migration/main/V20221122105730__create_attendance_table.sql @@ -0,0 +1,91 @@ +CREATE TABLE eg_wms_attendance_register( +id character varying(256), +tenantid character varying(64) NOT NULL, +registernumber character varying(128) NOT NULL, +name character varying(128), +startdate bigint NOT NULL, +enddate bigint NOT NULL, +status character varying(64) NOT NULL, +additionaldetails JSONB, +createdby character varying(256) NOT NULL, +lastmodifiedby character varying(256), +createdtime bigint, +lastmodifiedtime bigint, +CONSTRAINT uk_eg_wms_attendance_register UNIQUE (registernumber), +CONSTRAINT pk_eg_wms_attendance_register PRIMARY KEY (id) +); + +CREATE TABLE eg_wms_attendance_staff( +id character varying(256), +individual_id character varying(64) NOT NULL, +register_id character varying(64) NOT NULL, +enrollment_date bigint NOT NULL, +deenrollment_date bigint NOT NULL, +additionaldetails JSONB, +createdby character varying(256) NOT NULL, +lastmodifiedby character varying(256), +createdtime bigint, +lastmodifiedtime bigint, +CONSTRAINT pk_eg_wms_attendance_staff PRIMARY KEY (id), +CONSTRAINT fk_eg_wms_attendance_staff FOREIGN KEY (register_id) REFERENCES eg_wms_attendance_register (id) +); + +CREATE TABLE eg_wms_staff_permissions( +id character varying(256), +permission_type character varying(64) NOT NULL, +staff_id character varying(64) NOT NULL, +register_id character varying(64) NOT NULL, +additionaldetails JSONB, +createdby character varying(256) NOT NULL, +lastmodifiedby character varying(256), +createdtime bigint, +lastmodifiedtime bigint, +CONSTRAINT pk_eg_wms_staff_permissions PRIMARY KEY (id), +CONSTRAINT fk_eg_wms_register_staff_permissions FOREIGN KEY (register_id) REFERENCES eg_wms_attendance_register (id), +CONSTRAINT fk_eg_wms_staff_permissions FOREIGN KEY (staff_id) REFERENCES eg_wms_attendance_staff (id) +); + +CREATE TABLE eg_wms_attendance_attendee( +id character varying(256), +individual_id character varying(64) NOT NULL, +register_id character varying(64) NOT NULL, +enrollment_date bigint NOT NULL, +deenrollment_date bigint NOT NULL, +additionaldetails JSONB, +createdby character varying(256) NOT NULL, +lastmodifiedby character varying(256), +createdtime bigint, +lastmodifiedtime bigint, +CONSTRAINT pk_eg_wms_attendance_attendee PRIMARY KEY (id), +CONSTRAINT fk_eg_wms_attendance_attendee FOREIGN KEY (register_id) REFERENCES eg_wms_attendance_register (id) +); + +CREATE TABLE eg_wms_attendance_log( +id character varying(256), +individual_id character varying(64) NOT NULL, +register_id character varying(64) NOT NULL, +status character varying(64), +time bigint NOT NULL, +event_type character varying(64), +additionaldetails JSONB, +createdby character varying(256) NOT NULL, +lastmodifiedby character varying(256), +createdtime bigint, +lastmodifiedtime bigint, +CONSTRAINT pk_eg_wms_attendance_log PRIMARY KEY (id), +CONSTRAINT fk_eg_wms_attendance_log FOREIGN KEY (register_id) REFERENCES eg_wms_attendance_register (id) +); + +CREATE TABLE eg_wms_attendance_document( +id character varying(256), +filestore_id character varying(64) NOT NULL, +document_type character varying(64), +attendance_log_id character varying(64) NOT NULL, +additionaldetails JSONB, +createdby character varying(256) NOT NULL, +lastmodifiedby character varying(256), +createdtime bigint, +lastmodifiedtime bigint, +CONSTRAINT pk_eg_wms_attendance_document PRIMARY KEY (id), +CONSTRAINT fk_eg_wms_attendance_document FOREIGN KEY (attendance_log_id) REFERENCES eg_wms_attendance_log (id) +); \ No newline at end of file diff --git a/health-services/attendance/src/main/resources/db/migration/main/V20221124154130__alter_attendance_table.sql b/health-services/attendance/src/main/resources/db/migration/main/V20221124154130__alter_attendance_table.sql new file mode 100644 index 00000000000..3d50ee881db --- /dev/null +++ b/health-services/attendance/src/main/resources/db/migration/main/V20221124154130__alter_attendance_table.sql @@ -0,0 +1,36 @@ +ALTER TABLE eg_wms_attendance_register ALTER COLUMN registernumber TYPE character varying(256); +ALTER TABLE eg_wms_attendance_register ALTER COLUMN name TYPE character varying(256); + +ALTER TABLE eg_wms_attendance_attendee ALTER COLUMN individual_id TYPE character varying(256); +ALTER TABLE eg_wms_attendance_attendee ALTER COLUMN register_id TYPE character varying(256); +ALTER TABLE eg_wms_attendance_attendee ADD COLUMN attendee_type character varying(256); +ALTER TABLE eg_wms_attendance_attendee ADD COLUMN permission_type character varying(256); +ALTER TABLE eg_wms_attendance_attendee ADD COLUMN tenantid character varying(64); + +ALTER TABLE eg_wms_attendance_log ALTER COLUMN individual_id TYPE character varying(256); +ALTER TABLE eg_wms_attendance_log ALTER COLUMN register_id TYPE character varying(256); +ALTER TABLE eg_wms_attendance_log ADD COLUMN tenantid character varying(64); + +ALTER TABLE eg_wms_attendance_document ALTER COLUMN filestore_id TYPE character varying(256); +ALTER TABLE eg_wms_attendance_document ALTER COLUMN attendance_log_id TYPE character varying(256); +ALTER TABLE eg_wms_attendance_document ALTER COLUMN document_type TYPE character varying(256); +ALTER TABLE eg_wms_attendance_document ADD COLUMN tenantid character varying(64); + + +CREATE INDEX IF NOT EXISTS index_eg_wms_attendance_log_tenantId ON eg_wms_attendance_log (tenantId); +CREATE INDEX IF NOT EXISTS index_eg_wms_attendance_log_register_id ON eg_wms_attendance_log (register_id); +CREATE INDEX IF NOT EXISTS index_eg_wms_attendance_log_time ON eg_wms_attendance_log (time); +CREATE INDEX IF NOT EXISTS index_eg_wms_attendance_log_individual_id ON eg_wms_attendance_log (individual_id); +CREATE INDEX IF NOT EXISTS index_eg_wms_attendance_log_status ON eg_wms_attendance_log (status); +CREATE INDEX IF NOT EXISTS index_eg_wms_attendance_log_createdtime ON eg_wms_attendance_log (createdtime); + +CREATE INDEX IF NOT EXISTS index_eg_wms_attendance_register_tenantId ON eg_wms_attendance_register (tenantId); +CREATE INDEX IF NOT EXISTS index_eg_wms_attendance_register_id ON eg_wms_attendance_register (id); +CREATE INDEX IF NOT EXISTS index_eg_wms_attendance_register_registernumber ON eg_wms_attendance_register (registernumber); +CREATE INDEX IF NOT EXISTS index_eg_wms_attendance_register_name ON eg_wms_attendance_register (name); +CREATE INDEX IF NOT EXISTS index_eg_wms_attendance_register_startdate ON eg_wms_attendance_register (startdate); +CREATE INDEX IF NOT EXISTS index_eg_wms_attendance_register_enddate ON eg_wms_attendance_register (enddate); +CREATE INDEX IF NOT EXISTS index_eg_wms_attendance_register_status ON eg_wms_attendance_register (status); +CREATE INDEX IF NOT EXISTS index_eg_wms_attendance_register_createdtime ON eg_wms_attendance_register (createdtime); + +DROP TABLE IF EXISTS eg_wms_attendance_staff, eg_wms_staff_permissions CASCADE; \ No newline at end of file diff --git a/health-services/attendance/src/main/resources/db/migration/main/V20221130172200__create_attendance_staff_table.sql b/health-services/attendance/src/main/resources/db/migration/main/V20221130172200__create_attendance_staff_table.sql new file mode 100644 index 00000000000..736d2802323 --- /dev/null +++ b/health-services/attendance/src/main/resources/db/migration/main/V20221130172200__create_attendance_staff_table.sql @@ -0,0 +1,17 @@ +CREATE TABLE eg_wms_attendance_staff( +id character varying(256), +individual_id character varying(256) NOT NULL, +register_id character varying(256) NOT NULL, +tenantid character varying(64), +enrollment_date bigint NOT NULL, +deenrollment_date bigint, +additionaldetails JSONB, +createdby character varying(256) NOT NULL, +lastmodifiedby character varying(256), +createdtime bigint, +lastmodifiedtime bigint, +CONSTRAINT pk_eg_wms_attendance_staff PRIMARY KEY (id), +CONSTRAINT fk_eg_wms_attendance_staff FOREIGN KEY (register_id) REFERENCES eg_wms_attendance_register (id) +); + +ALTER TABLE eg_wms_attendance_attendee ALTER COLUMN deenrollment_date DROP NOT NULL; \ No newline at end of file diff --git a/health-services/attendance/src/main/resources/db/migration/main/V20221208175400__alter_attendance_attendee_table.sql b/health-services/attendance/src/main/resources/db/migration/main/V20221208175400__alter_attendance_attendee_table.sql new file mode 100644 index 00000000000..65e87f7e6dc --- /dev/null +++ b/health-services/attendance/src/main/resources/db/migration/main/V20221208175400__alter_attendance_attendee_table.sql @@ -0,0 +1,4 @@ +ALTER TABLE eg_wms_attendance_attendee DROP COLUMN attendee_type; +ALTER TABLE eg_wms_attendance_attendee DROP COLUMN permission_type; +ALTER TABLE eg_wms_attendance_document ADD COLUMN status character varying(64); +ALTER TABLE eg_wms_attendance_register ALTER COLUMN enddate DROP NOT NULL; \ No newline at end of file diff --git a/health-services/attendance/src/main/resources/db/migration/main/V20230404011400__alter_attendance_attendee_table.sql b/health-services/attendance/src/main/resources/db/migration/main/V20230404011400__alter_attendance_attendee_table.sql new file mode 100644 index 00000000000..34641634808 --- /dev/null +++ b/health-services/attendance/src/main/resources/db/migration/main/V20230404011400__alter_attendance_attendee_table.sql @@ -0,0 +1,4 @@ +ALTER TABLE eg_wms_attendance_register ADD COLUMN referenceid character varying(256); +ALTER TABLE eg_wms_attendance_register ADD COLUMN servicecode character varying(64); +CREATE INDEX IF NOT EXISTS index_eg_wms_attendance_register_reference_id ON eg_wms_attendance_register (referenceid); +CREATE INDEX IF NOT EXISTS index_eg_wms_attendance_register_service_code ON eg_wms_attendance_register (servicecode); \ No newline at end of file diff --git a/health-services/attendance/src/main/resources/db/migration/main/V20240124104400__alter_attendance_log_table.sql b/health-services/attendance/src/main/resources/db/migration/main/V20240124104400__alter_attendance_log_table.sql new file mode 100644 index 00000000000..4505dbdb1c7 --- /dev/null +++ b/health-services/attendance/src/main/resources/db/migration/main/V20240124104400__alter_attendance_log_table.sql @@ -0,0 +1,5 @@ +ALTER TABLE eg_wms_attendance_log ADD COLUMN IF NOT EXISTS clientreferenceid character varying(256); +ALTER TABLE eg_wms_attendance_log ADD COLUMN IF NOT EXISTS clientcreatedby character varying(256); +ALTER TABLE eg_wms_attendance_log ADD COLUMN IF NOT EXISTS clientlastmodifiedby character varying(256); +ALTER TABLE eg_wms_attendance_log ADD COLUMN IF NOT EXISTS clientcreatedtime bigint; +ALTER TABLE eg_wms_attendance_log ADD COLUMN IF NOT EXISTS clientlastmodifiedtime bigint; \ No newline at end of file diff --git a/health-services/attendance/src/test/java/org/egov/TestConfiguration.java b/health-services/attendance/src/test/java/org/egov/TestConfiguration.java new file mode 100644 index 00000000000..d13056a19e6 --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/TestConfiguration.java @@ -0,0 +1,16 @@ +package org.egov; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.kafka.core.KafkaTemplate; + +import static org.mockito.Mockito.mock; + +@Configuration +public class TestConfiguration { + @Bean + @SuppressWarnings("unchecked") + public KafkaTemplate kafkaTemplate() { + return mock(KafkaTemplate.class); + } +} \ No newline at end of file diff --git a/health-services/attendance/src/test/java/org/egov/enrichment/AttendanceLogEnrichmentTest.java b/health-services/attendance/src/test/java/org/egov/enrichment/AttendanceLogEnrichmentTest.java new file mode 100644 index 00000000000..1c4a0a6c23f --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/enrichment/AttendanceLogEnrichmentTest.java @@ -0,0 +1,47 @@ +package org.egov.enrichment; + +import digit.models.coremodels.AuditDetails; +import lombok.extern.slf4j.Slf4j; +import org.egov.helper.AttendanceLogRequestTestBuilder; +import org.egov.util.AttendanceServiceUtil; +import org.egov.web.models.AttendanceLogRequest; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.internal.matchers.Null; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.lang.Nullable; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.when; + +@Slf4j +@ExtendWith(MockitoExtension.class) +public class AttendanceLogEnrichmentTest { + + @InjectMocks + private AttendanceLogEnrichment attendanceLogEnrichment; + + @Mock + private AttendanceServiceUtil attendanceServiceUtil; + + @DisplayName("Method validateAttendanceLogRequest: With good request") + @Test + public void enrichAttendanceLogCreateRequestTest_1(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addAttendanceLogWithoutIdAndAuditDetails().build(); + String byUser = attendanceLogRequest.getRequestInfo().getUserInfo().getUuid(); + Long time = System.currentTimeMillis(); + AuditDetails auditDetails = AuditDetails.builder().createdBy(byUser).lastModifiedBy(byUser).createdTime(time).lastModifiedTime(time).build(); + lenient().when(attendanceServiceUtil.getAuditDetails(any(String.class),eq(null),eq(true))).thenReturn(auditDetails); + attendanceLogEnrichment.enrichAttendanceLogCreateRequest(attendanceLogRequest); + assertNotNull(attendanceLogRequest.getAttendance().get(0).getId()); + assertNotNull(attendanceLogRequest.getAttendance().get(0).getAuditDetails()); + assertNotNull(attendanceLogRequest.getAttendance().get(0).getDocumentIds().get(0).getId()); + } +} diff --git a/health-services/attendance/src/test/java/org/egov/enrichment/AttendeeEnrichmentServiceTest.java b/health-services/attendance/src/test/java/org/egov/enrichment/AttendeeEnrichmentServiceTest.java new file mode 100644 index 00000000000..7516104c2e1 --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/enrichment/AttendeeEnrichmentServiceTest.java @@ -0,0 +1,42 @@ +package org.egov.enrichment; + +import lombok.extern.slf4j.Slf4j; +import org.egov.Main; +import org.egov.helper.AttendeeRequestBuilderTest; +import org.egov.util.AttendanceServiceUtil; +import org.egov.web.models.AttendeeCreateRequest; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.junit.jupiter.api.Assertions.*; +import org.mockito.*; +import org.springframework.boot.test.mock.mockito.MockBean; + +@Slf4j +@ExtendWith(MockitoExtension.class) +public class AttendeeEnrichmentServiceTest { + + @Mock + private AttendanceServiceUtil attendanceServiceUtil; + + + @InjectMocks + private AttendeeEnrichmentService attendeeEnrichmentService; + + + + @DisplayName("update enrollmentDate for attendee if enrollment date is null") + @Test + public void shouldEnrichEnrollmentDateWhenEnrollmentDateIsNull() { + AttendeeCreateRequest attendeeCreateRequest = AttendeeRequestBuilderTest.getAttendeeCreateRequest(); + + attendeeCreateRequest.getAttendees().get(0).setEnrollmentDate(null); + attendeeEnrichmentService.enrichAttendeeOnCreate(attendeeCreateRequest); + + assertNotNull(attendeeCreateRequest.getAttendees().get(0).getEnrollmentDate()); + } +} diff --git a/health-services/attendance/src/test/java/org/egov/enrichment/RegisterEnrichmentTest.java b/health-services/attendance/src/test/java/org/egov/enrichment/RegisterEnrichmentTest.java new file mode 100644 index 00000000000..8d9d9aae73b --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/enrichment/RegisterEnrichmentTest.java @@ -0,0 +1,102 @@ +package org.egov.enrichment; + +import digit.models.coremodels.AuditDetails; +import digit.models.coremodels.IdGenerationResponse; +import digit.models.coremodels.IdResponse; +import lombok.extern.slf4j.Slf4j; +import org.egov.common.models.individual.Individual; +import org.egov.config.AttendanceServiceConfiguration; +import org.egov.helper.AttendanceRegisterRequestBuilderTest; +import org.egov.helper.AuditDetailsTestBuilder; +import org.egov.helper.IndividualEntryBuilderTest; +import org.egov.repository.IdGenRepository; +import org.egov.tracer.model.CustomException; +import org.egov.util.AttendanceServiceUtil; +import org.egov.util.IndividualServiceUtil; +import org.egov.web.models.AttendanceRegisterRequest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +import static junit.framework.TestCase.assertTrue; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.when; + +@Slf4j +@ExtendWith(MockitoExtension.class) +public class RegisterEnrichmentTest { + + @InjectMocks + private RegisterEnrichment registerEnrichment; + + @Mock + private AttendanceServiceConfiguration config; + + @Mock + private IdGenRepository idGenRepository; + + @Mock + private AttendanceServiceUtil attendanceServiceUtil; + @Mock + private IndividualServiceUtil individualServiceUtil; + + @BeforeEach + void setupBeforeEach() { + when(config.getIdgenAttendanceRegisterNumberName()).thenReturn("attendance.register.number"); + // when(config.getIdgenAttendanceRegisterNumberFormat()).thenReturn("WR/[fy:yyyy-yy]/[cy:MM]/[cy:dd]/[SEQ_ATTENDANCE_REGISTER_NUM]"); + } + + + @DisplayName("Method enrichCreateAttendanceRegister: With IDGEN ERROR code") + @Test + public void enrichCreateAttendanceRegisterTest_1(){ + AttendanceRegisterRequest attendanceRegisterRequest = AttendanceRegisterRequestBuilderTest.builder().withRequestInfo().addGoodRegister().build(); + + List idResponses = new ArrayList<>(); + IdGenerationResponse idGenerationResponse = IdGenerationResponse.builder().idResponses(idResponses).build(); + + lenient().when(idGenRepository.getId(eq(attendanceRegisterRequest.getRequestInfo()), eq("pb"), eq("attendance.register.number"), eq(""), eq(1))) + .thenReturn(idGenerationResponse); + + CustomException exception = assertThrows(CustomException.class,()->registerEnrichment.enrichRegisterOnCreate(attendanceRegisterRequest)); + assertTrue(exception.getCode().contentEquals("IDGEN ERROR")); + } + + +// @DisplayName("Method enrichCreateAttendanceRegister: With IDGEN ERROR code") +// @Test +// public void enrichCreateAttendanceRegisterTest_2(){ +// AttendanceRegisterRequest attendanceRegisterRequest = AttendanceRegisterRequestBuilderTest.builder().withRequestInfo().attendanceRegistersWithoutIdAuditDetailsAndNumber().build(); +// +// IdResponse idResponse = IdResponse.builder().id("WR/2022-23/01/05/01").build(); +// List idResponses = new ArrayList<>(); +// idResponses.add(idResponse); +// IdGenerationResponse idGenerationResponse = IdGenerationResponse.builder().idResponses(idResponses).build(); +// +// lenient().when(idGenRepository.getId(eq(attendanceRegisterRequest.getRequestInfo()), eq("pb"), eq("attendance.register.number"), eq(""), eq(1))) +// .thenReturn(idGenerationResponse); +// +// AuditDetails auditDetails = AuditDetailsTestBuilder.builder().withAuditDetails().build(); +// when(attendanceServiceUtil.getAuditDetails(attendanceRegisterRequest.getRequestInfo().getUserInfo().getUuid(),null,true)).thenReturn(auditDetails); +// Individual dummyIndividual = Individual.builder().individualId(UUID.randomUUID().toString()).build(); +// when(individualServiceUtil.getIndividualDetails(any(), any(), any())).thenReturn(Collections.singletonList(dummyIndividual)); +// +// registerEnrichment.enrichRegisterOnCreate(attendanceRegisterRequest); +// +// assertTrue(attendanceRegisterRequest.getAttendanceRegister().get(0).getId()!=null); +// +// } + +} diff --git a/health-services/attendance/src/test/java/org/egov/enrichment/StaffEnrichmentServiceTest.java b/health-services/attendance/src/test/java/org/egov/enrichment/StaffEnrichmentServiceTest.java new file mode 100644 index 00000000000..e3fd8edc7c3 --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/enrichment/StaffEnrichmentServiceTest.java @@ -0,0 +1,41 @@ +package org.egov.enrichment; + +import lombok.extern.slf4j.Slf4j; +import org.egov.config.AttendanceServiceConfiguration; +import org.egov.helper.AttendeeRequestBuilderTest; +import org.egov.helper.StaffRequestBuilderTest; +import org.egov.service.AttendanceRegisterService; +import org.egov.util.AttendanceServiceUtil; +import org.egov.web.models.AttendeeCreateRequest; +import org.egov.web.models.StaffPermissionRequest; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.beans.factory.annotation.Autowired; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +@Slf4j +@ExtendWith(MockitoExtension.class) +public class StaffEnrichmentServiceTest { + + @Mock + private AttendanceServiceUtil attendanceServiceUtil; + + @InjectMocks + private StaffEnrichmentService staffEnrichmentService; + + @DisplayName("update enrollmentDate for staff") + @Test + public void shouldEnrichEnrollmentDateWhenEnrollmentDateIsNull() { + StaffPermissionRequest staffPermissionRequest = StaffRequestBuilderTest.getStaffPermissionRequest(); + + staffPermissionRequest.getStaff().get(0).setEnrollmentDate(null); + staffEnrichmentService.enrichStaffPermissionOnCreate(staffPermissionRequest); + + assertNotNull(staffPermissionRequest.getStaff().get(0).getEnrollmentDate()); + } +} diff --git a/health-services/attendance/src/test/java/org/egov/helper/AdditionalFields.java b/health-services/attendance/src/test/java/org/egov/helper/AdditionalFields.java new file mode 100644 index 00000000000..dac5d48b7bc --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/helper/AdditionalFields.java @@ -0,0 +1,40 @@ +package org.egov.helper; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; +import org.springframework.validation.annotation.Validated; + +import javax.validation.Valid; +import java.util.ArrayList; +import java.util.List; + +/** + * AdditionalFields + */ + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class AdditionalFields { + @JsonProperty("schema") + private String schema = null; + + @JsonProperty("version") + private Integer version = null; + + @JsonProperty("fields") + @Valid + private List fields = null; + + + public AdditionalFields addFieldsItem(Field fieldsItem) { + if (this.fields == null) { + this.fields = new ArrayList<>(); + } + this.fields.add(fieldsItem); + return this; + } + +} \ No newline at end of file diff --git a/health-services/attendance/src/test/java/org/egov/helper/AttendanceLogRequestTestBuilder.java b/health-services/attendance/src/test/java/org/egov/helper/AttendanceLogRequestTestBuilder.java new file mode 100644 index 00000000000..1e11a4ab2a6 --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/helper/AttendanceLogRequestTestBuilder.java @@ -0,0 +1,98 @@ +package org.egov.helper; + +import org.egov.web.models.AttendanceLog; +import org.egov.web.models.AttendanceLogRequest; + +import java.util.ArrayList; + +public class AttendanceLogRequestTestBuilder { + + private AttendanceLogRequest.AttendanceLogRequestBuilder builder ; + + public AttendanceLogRequestTestBuilder(){ + this.builder = AttendanceLogRequest.builder(); + } + + public static AttendanceLogRequestTestBuilder builder(){ + return new AttendanceLogRequestTestBuilder(); + } + + public AttendanceLogRequest build(){ + return this.builder.build(); + } + + public AttendanceLogRequestTestBuilder withRequestInfo(){ + this.builder.requestInfo(RequestInfoTestBuilder.builder().withCompleteRequestInfo().build()); + return this; + } + + public AttendanceLogRequestTestBuilder withoutRequestInfo(){ + this.builder.requestInfo(null); + return this; + } + + public AttendanceLogRequestTestBuilder withRequestInfoButWithoutUserInfo(){ + this.builder.requestInfo(RequestInfoTestBuilder.builder().requestInfoWithoutUserInfo().build()); + return this; + } + + public AttendanceLogRequestTestBuilder withRequestInfoWithUserInfoButWithOutUUID(){ + this.builder.requestInfo(RequestInfoTestBuilder.builder().requestInfoWithUserInfoButWithOutUUID().build()); + return this; + } + + public AttendanceLogRequestTestBuilder addGoodAttendanceLog(){ + ArrayList logs = new ArrayList<>(); + logs.add(AttendanceLogTestBuilder.builder().addGoodAttendanceLog().build()); + this.builder.attendance(logs); + return this; + } + + public AttendanceLogRequestTestBuilder addAttendanceLogWithoutIdAndAuditDetails(){ + ArrayList logs = new ArrayList<>(); + logs.add(AttendanceLogTestBuilder.builder().addAttendanceLogWithoutIdAndAuditDetails().build()); + this.builder.attendance(logs); + return this; + } + + public AttendanceLogRequestTestBuilder withoutAttendanceLog(){ + this.builder.attendance(null); + return this; + } + + public AttendanceLogRequestTestBuilder attendanceLogWithoutTenantId(){ + ArrayList logs = new ArrayList<>(); + logs.add(AttendanceLogTestBuilder.builder().attendanceLogWithoutTenantId().build()); + this.builder.attendance(logs); + return this; + } + + + public AttendanceLogRequestTestBuilder attendanceLogWithoutIndividualId(){ + ArrayList logs = new ArrayList<>(); + logs.add(AttendanceLogTestBuilder.builder().attendanceLogWithoutIndividualId().build()); + this.builder.attendance(logs); + return this; + } + + public AttendanceLogRequestTestBuilder attendanceLogWithoutType(){ + ArrayList logs = new ArrayList<>(); + logs.add(AttendanceLogTestBuilder.builder().attendanceLogWithoutType().build()); + this.builder.attendance(logs); + return this; + } + + public AttendanceLogRequestTestBuilder attendanceLogWithoutTime(){ + ArrayList logs = new ArrayList<>(); + logs.add(AttendanceLogTestBuilder.builder().attendanceLogWithoutTime().build()); + this.builder.attendance(logs); + return this; + } + + public AttendanceLogRequestTestBuilder attendanceLogWithoutRegisterId() { + ArrayList logs = new ArrayList<>(); + logs.add(AttendanceLogTestBuilder.builder().attendanceLogWithoutRegisterId().build()); + this.builder.attendance(logs); + return this; + } +} diff --git a/health-services/attendance/src/test/java/org/egov/helper/AttendanceLogTestBuilder.java b/health-services/attendance/src/test/java/org/egov/helper/AttendanceLogTestBuilder.java new file mode 100644 index 00000000000..de156321d8b --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/helper/AttendanceLogTestBuilder.java @@ -0,0 +1,125 @@ +package org.egov.helper; + +import org.apache.commons.lang3.StringUtils; +import org.egov.web.models.AttendanceLog; +import org.egov.web.models.Document; +import org.egov.web.models.Status; + +import java.math.BigDecimal; +import java.util.Collections; + +public class AttendanceLogTestBuilder { + private AttendanceLog.AttendanceLogBuilder builder ; + public AttendanceLogTestBuilder(){ + this.builder = AttendanceLog.builder(); + } + + public static AttendanceLogTestBuilder builder(){ + return new AttendanceLogTestBuilder(); + } + + public AttendanceLog build(){ + return this.builder.build(); + } + + public AttendanceLogTestBuilder addGoodAttendanceLog(){ + this.builder + .id("some-id") + .tenantId("some-tenantId") + .registerId("some-registerId") + .individualId("some-individualId") + .time(BigDecimal.valueOf(1672813896627L)) + .type("some-type") + .status(Status.ACTIVE) + .documentIds(Collections.singletonList(DocumentTestBuilder.builder().addGoodDocument().build())) + .auditDetails(AuditDetailsTestBuilder.builder().withAuditDetails().build()) + ; + return this; + } + + public AttendanceLogTestBuilder addAttendanceLogWithoutIdAndAuditDetails(){ + this.builder + .tenantId("some-tenantId") + .registerId("some-registerId") + .individualId("some-individualId") + .time(BigDecimal.valueOf(1672813896627L)) + .type("some-type") + .status(Status.ACTIVE) + .documentIds(Collections.singletonList(DocumentTestBuilder.builder().addDocumentWithoutId().build())) + .auditDetails(null) + ; + return this; + } + + public AttendanceLogTestBuilder attendanceLogWithoutTenantId(){ + this.builder + .id("some-id") + .registerId("some-registerId") + .individualId("some-individualId") + .time(BigDecimal.valueOf(1L)) + .type("some-type") + .status(Status.ACTIVE) + .documentIds(Collections.singletonList(DocumentTestBuilder.builder().addGoodDocument().build())) + .auditDetails(AuditDetailsTestBuilder.builder().withAuditDetails().build()) + ; + return this; + } + + public AttendanceLogTestBuilder attendanceLogWithoutRegisterId(){ + this.builder + .id("some-id") + .tenantId("some-tenantId") + .individualId("some-individualId") + .time(BigDecimal.valueOf(1L)) + .type("some-type") + .status(Status.ACTIVE) + .documentIds(Collections.singletonList(DocumentTestBuilder.builder().addGoodDocument().build())) + .auditDetails(AuditDetailsTestBuilder.builder().withAuditDetails().build()) + ; + return this; + } + + public AttendanceLogTestBuilder attendanceLogWithoutIndividualId(){ + this.builder + .id("some-id") + .tenantId("some-tenantId") + .registerId("some-registerId") + .time(BigDecimal.valueOf(1L)) + .type("some-type") + .status(Status.ACTIVE) + .documentIds(Collections.singletonList(DocumentTestBuilder.builder().addGoodDocument().build())) + .auditDetails(AuditDetailsTestBuilder.builder().withAuditDetails().build()) + ; + return this; + } + + public AttendanceLogTestBuilder attendanceLogWithoutType(){ + this.builder + .id("some-id") + .tenantId("some-tenantId") + .registerId("some-registerId") + .individualId("some-individualId") + .time(BigDecimal.valueOf(1L)) + .status(Status.ACTIVE) + .documentIds(Collections.singletonList(DocumentTestBuilder.builder().addGoodDocument().build())) + .auditDetails(AuditDetailsTestBuilder.builder().withAuditDetails().build()) + ; + return this; + } + + public AttendanceLogTestBuilder attendanceLogWithoutTime(){ + this.builder + .id("some-id") + .tenantId("some-tenantId") + .registerId("some-registerId") + .individualId("some-individualId") + .type("some-type") + .status(Status.ACTIVE) + .documentIds(Collections.singletonList(DocumentTestBuilder.builder().addGoodDocument().build())) + .auditDetails(AuditDetailsTestBuilder.builder().withAuditDetails().build()) + ; + return this; + } + + +} diff --git a/health-services/attendance/src/test/java/org/egov/helper/AttendanceRegisterBuilderTest.java b/health-services/attendance/src/test/java/org/egov/helper/AttendanceRegisterBuilderTest.java new file mode 100644 index 00000000000..5a45b759b80 --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/helper/AttendanceRegisterBuilderTest.java @@ -0,0 +1,107 @@ +package org.egov.helper; + +import digit.models.coremodels.AuditDetails; +import lombok.extern.slf4j.Slf4j; +import org.egov.common.contract.request.RequestInfo; +import org.egov.common.contract.request.Role; +import org.egov.common.contract.request.User; +import org.egov.common.contract.response.ResponseInfo; +import org.egov.web.models.AttendanceRegister; +import org.egov.web.models.IndividualEntry; +import org.egov.web.models.StaffPermission; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +@Slf4j +public class AttendanceRegisterBuilderTest { + + public static AttendanceRegister getAttendanceRegister(){ + AttendanceRegister attendanceRegister=AttendanceRegister.builder().id("97ed7da3-753e-426a-b0b0-95dd61029785") + .registerNumber("RGN-67124").name("self help3").startDate(new BigDecimal("1673740800000")) + .endDate(new BigDecimal("1692057600000")).auditDetails(getAuditDetails()).attendees(getAttendees()) + .tenantId("pb.amritsar").staff(getStaff()).build(); + return attendanceRegister; + } + + public static AttendanceRegister getAttendanceRegisterWithoutEndDate(){ + AttendanceRegister attendanceRegister=AttendanceRegister.builder().id("97ed7da3-753e-426a-b0b0-95dd61029785") + .registerNumber("RGN-67124").name("self help3").startDate(new BigDecimal("1673740800000")) + .auditDetails(getAuditDetails()).attendees(getAttendees()) + .tenantId("pb.amritsar").staff(getStaff()).build(); + return attendanceRegister; + } + public static List getAttendees() { + IndividualEntry attendeeOne = IndividualEntry.builder().tenantId("pb.amritsar").id("047dc725-3088-45b4-877a-6bfbaf377df9") + .individualId("8ybdd-3rdh3").registerId("97ed7da3-753e-426a-b0b0-95dd61029785").enrollmentDate(new BigDecimal("1672129633890")) + .denrollmentDate(null).auditDetails(getAuditDetails()).build(); + + IndividualEntry attendeeTwo = IndividualEntry.builder().tenantId("pb.amritsar").id("11b88488-9a7a-48da-b110-dfdc077ef467") + .individualId("8ybdd-3rdha").registerId("97ed7da3-753e-426a-b0b0-95dd61029785").enrollmentDate(new BigDecimal("1671701038563")) + .denrollmentDate(null).auditDetails(getAuditDetails()).build(); + + List attendees=new ArrayList<>(Arrays.asList(attendeeOne,attendeeTwo)); + return attendees; + } + + public static List getStaff(){ + StaffPermission staffOne=StaffPermission.builder().id("03901adb-07c3-4539-9346-4ee5c87e5e1c").userId("8ybdd-3rdhd") + .registerId("97ed7da3-753e-426a-b0b0-95dd61029785").tenantId("pb.amritsar").enrollmentDate(new BigDecimal("1670421853937")) + .denrollmentDate(null).auditDetails(getAuditDetails()).build(); + + StaffPermission staffTwo=StaffPermission.builder().id("156d07fd-2c0c-4882-be03-6b68b98fb15e").userId("8ybdd-3rdhe") + .registerId("97ed7da3-753e-426a-b0b0-95dd61029785").tenantId("pb.amritsar").enrollmentDate(new BigDecimal("1670424209106")) + .denrollmentDate(null).auditDetails(getAuditDetails()).build(); + + List staffList=new ArrayList<>(Arrays.asList(staffOne,staffTwo)); + return staffList; + } + + + + public static AuditDetails getAuditDetails(){ + AuditDetails auditDetails=AuditDetails.builder().createdBy("11b0e02b-0145-4de2-bc42-c97b96264807") + .lastModifiedBy("11b0e02b-0145-4de2-bc42-c97b96264807").createdTime(Long.valueOf("1672129633890")) + .lastModifiedTime(Long.valueOf("1672129855564")).build(); + return auditDetails; + } + + public static List getAttendanceRegisterList(){ + + AttendanceRegister attendanceRegisterOne=AttendanceRegister.builder().id("54215cb7-c7f7-4521-8965-09647454a1f0") + .registerNumber("RGN-67124").name("self help3").startDate(new BigDecimal("1673740800000")) + .endDate(new BigDecimal("1692057600000")).tenantId("pb.amritsar").auditDetails(getAuditDetails()).build(); + + AttendanceRegister attendanceRegisterTwo=AttendanceRegister.builder().id("54215cb7-c7f7-4521-8965-09647454a1f1") + .registerNumber("RGN-67124").name("self help3").startDate(new BigDecimal("1673740800000")) + .endDate(new BigDecimal("1692057600000")).auditDetails(getAuditDetails()).tenantId("pb.amritsar").build(); + + AttendanceRegister attendanceRegisterThree=AttendanceRegister.builder().id("54215cb7-c7f7-4521-8965-09647454a1f2") + .registerNumber("RGN-67124").name("self help3").startDate(new BigDecimal("1673740800000")) + .endDate(new BigDecimal("1692057600000")).auditDetails(getAuditDetails()).tenantId("pb.amritsar").build(); + + List attendanceRegisterList=new ArrayList<>(Arrays.asList(attendanceRegisterOne,attendanceRegisterTwo,attendanceRegisterThree)); + + return attendanceRegisterList; + + + } + + public static RequestInfo getRequestInfo(){ + Role role = new Role(1L,"Organization staff","ORG_STAFF","pb.amritsar"); + List roles = new ArrayList<>(); + roles.add(role); + User userInfo = User.builder().id(172L).uuid("5ce80dd3-b1c0-42fd-b8f6-a2be456db31c").userName("8070102021").name("test3").mobileNumber("8070102021") + .emailId("xyz@egovernments.org").type("EMPLOYEE").roles(roles).build(); + RequestInfo requestInfo = RequestInfo.builder().apiId("attendance-services").msgId("search with from and to values").userInfo(userInfo).build(); + return requestInfo; + } + + public static ResponseInfo getResponseInfo_Success() { + ResponseInfo responseInfo = ResponseInfo.builder().apiId("attendance-services").ver(null).ts(null).resMsgId(null).msgId("search with from and to values") + .status("successful").build(); + return responseInfo; + } +} diff --git a/health-services/attendance/src/test/java/org/egov/helper/AttendanceRegisterRequestBuilderTest.java b/health-services/attendance/src/test/java/org/egov/helper/AttendanceRegisterRequestBuilderTest.java new file mode 100644 index 00000000000..08a7274cf18 --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/helper/AttendanceRegisterRequestBuilderTest.java @@ -0,0 +1,178 @@ +package org.egov.helper; + +import org.egov.web.models.*; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Collections; + +public class AttendanceRegisterRequestBuilderTest { + + private AttendanceRegisterRequest.AttendanceRegisterRequestBuilder builder ; + + public AttendanceRegisterRequestBuilderTest(){ + this.builder = AttendanceRegisterRequest.builder(); + } + + public static AttendanceRegisterRequestBuilderTest builder(){ + return new AttendanceRegisterRequestBuilderTest(); + } + + public AttendanceRegisterRequest build(){ + return this.builder.build(); + } + + public AttendanceRegisterRequestBuilderTest withRequestInfo(){ + this.builder.requestInfo(RequestInfoTestBuilder.builder().withCompleteRequestInfo().build()); + return this; + } + + public AttendanceRegisterRequestBuilderTest requestInfoWithoutUserInfo(){ + this.builder.requestInfo(RequestInfoTestBuilder.builder().requestInfoWithoutUserInfo().build()); + return this; + } + + public AttendanceRegisterRequestBuilderTest requestInfoWithUserInfoButWithOutUUID(){ + this.builder.requestInfo(RequestInfoTestBuilder.builder().requestInfoWithUserInfoButWithOutUUID().build()); + return this; + } + + public AttendanceRegisterRequestBuilderTest addGoodRegister(){ + ArrayList registers = new ArrayList<>(); + AttendanceRegister attendanceRegister=AttendanceRegister.builder() + .id("97ed7da3-753e-426a-b0b0-95dd61029785") + .registerNumber("RGN-67124") + .tenantId("pb.amritsar") + .name("self help3") + .startDate(new BigDecimal("1673740800000")) + .endDate(new BigDecimal("1692057600000")) + .serviceCode("serviceCode") + .referenceId("referenceId") + .auditDetails(AuditDetailsTestBuilder.builder().build()) + .attendees(Collections.singletonList(IndividualEntry.builder().build())) + .staff(Collections.singletonList(StaffPermission.builder().build())) + .build(); + registers.add(attendanceRegister); + this.builder.attendanceRegister(registers); + return this; + } + + + public AttendanceRegisterRequestBuilderTest attendanceRegistersWithoutIdAuditDetailsAndNumber(){ + ArrayList registers = new ArrayList<>(); + AttendanceRegister attendanceRegister=AttendanceRegister.builder() + .tenantId("pb.amritsar") + .name("self help3") + .startDate(new BigDecimal("1673740800000")) + .endDate(new BigDecimal("1692057600000")) + .auditDetails(null) + .attendees(Collections.singletonList(IndividualEntry.builder().build())) + .staff(Collections.singletonList(StaffPermission.builder().build())) + .build(); + registers.add(attendanceRegister); + this.builder.attendanceRegister(registers); + return this; + } + + public AttendanceRegisterRequestBuilderTest attendanceRegistersWithMultipleTenantIds(){ + ArrayList registers = new ArrayList<>(); + AttendanceRegister attendanceRegister1=AttendanceRegister.builder() + .id("97ed7da3-753e-426a-b0b0-95dd61029785") + .registerNumber("RGN-67124") + .tenantId("pb.amritsar") + .name("self help3") + .startDate(new BigDecimal("1673740800000")) + .endDate(new BigDecimal("1692057600000")) + .auditDetails(AuditDetailsTestBuilder.builder().build()) + .attendees(Collections.singletonList(IndividualEntry.builder().build())) + .staff(Collections.singletonList(StaffPermission.builder().build())) + .build(); + + AttendanceRegister attendanceRegister2=AttendanceRegister.builder() + .id("97ed7da3-753e-426a-b0b0-95dd61029785") + .registerNumber("RGN-67124") + .tenantId("pb.jalandhar") + .name("self help3") + .startDate(new BigDecimal("1673740800000")) + .endDate(new BigDecimal("1692057600000")) + .auditDetails(AuditDetailsTestBuilder.builder().build()) + .attendees(Collections.singletonList(IndividualEntry.builder().build())) + .staff(Collections.singletonList(StaffPermission.builder().build())) + .build(); + + registers.add(attendanceRegister1); + registers.add(attendanceRegister2); + this.builder.attendanceRegister(registers); + return this; + } + + public AttendanceRegisterRequestBuilderTest attendanceRegisterWithoutTenantId(){ + ArrayList registers = new ArrayList<>(); + AttendanceRegister attendanceRegister=AttendanceRegister.builder() + .id("97ed7da3-753e-426a-b0b0-95dd61029785") + .registerNumber("RGN-67124") + .name("self help3") + .startDate(new BigDecimal("1673740800000")) + .endDate(new BigDecimal("1692057600000")) + .auditDetails(AuditDetailsTestBuilder.builder().build()) + .attendees(Collections.singletonList(IndividualEntry.builder().build())) + .staff(Collections.singletonList(StaffPermission.builder().build())) + .build(); + registers.add(attendanceRegister); + this.builder.attendanceRegister(registers); + return this; + } + + public AttendanceRegisterRequestBuilderTest attendanceRegisterWithoutName(){ + ArrayList registers = new ArrayList<>(); + AttendanceRegister attendanceRegister=AttendanceRegister.builder() + .id("97ed7da3-753e-426a-b0b0-95dd61029785") + .registerNumber("RGN-67124") + .tenantId("tenant.id") + .startDate(new BigDecimal("1673740800000")) + .endDate(new BigDecimal("1692057600000")) + .auditDetails(AuditDetailsTestBuilder.builder().build()) + .attendees(Collections.singletonList(IndividualEntry.builder().build())) + .staff(Collections.singletonList(StaffPermission.builder().build())) + .build(); + registers.add(attendanceRegister); + this.builder.attendanceRegister(registers); + return this; + } + + public AttendanceRegisterRequestBuilderTest attendanceRegisterWithoutStartDate(){ + ArrayList registers = new ArrayList<>(); + AttendanceRegister attendanceRegister=AttendanceRegister.builder() + .id("97ed7da3-753e-426a-b0b0-95dd61029785") + .registerNumber("RGN-67124") + .name("some-name") + .tenantId("tenant.id") + .endDate(new BigDecimal("1692057600000")) + .auditDetails(AuditDetailsTestBuilder.builder().build()) + .attendees(Collections.singletonList(IndividualEntry.builder().build())) + .staff(Collections.singletonList(StaffPermission.builder().build())) + .build(); + registers.add(attendanceRegister); + this.builder.attendanceRegister(registers); + return this; + } + + public AttendanceRegisterRequestBuilderTest attendanceRegisterWithStartDateGTEndDate(){ + ArrayList registers = new ArrayList<>(); + AttendanceRegister attendanceRegister=AttendanceRegister.builder() + .id("97ed7da3-753e-426a-b0b0-95dd61029785") + .registerNumber("RGN-67124") + .name("some-name") + .tenantId("tenant.id") + .startDate(new BigDecimal("1692057600000")) + .endDate(new BigDecimal("1673740800000")) + .auditDetails(AuditDetailsTestBuilder.builder().build()) + .attendees(Collections.singletonList(IndividualEntry.builder().build())) + .staff(Collections.singletonList(StaffPermission.builder().build())) + .build(); + registers.add(attendanceRegister); + this.builder.attendanceRegister(registers); + return this; + } + +} diff --git a/health-services/attendance/src/test/java/org/egov/helper/AttendeeRequestBuilderTest.java b/health-services/attendance/src/test/java/org/egov/helper/AttendeeRequestBuilderTest.java new file mode 100644 index 00000000000..ee49a09103f --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/helper/AttendeeRequestBuilderTest.java @@ -0,0 +1,97 @@ +package org.egov.helper; + +import com.fasterxml.jackson.databind.ObjectMapper; +import digit.models.coremodels.AuditDetails; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.FileUtils; +import org.egov.common.contract.request.RequestInfo; +import org.egov.common.contract.request.Role; +import org.egov.common.contract.request.User; +import org.egov.common.contract.response.ResponseInfo; +import org.egov.web.models.AttendeeCreateRequest; +import org.egov.web.models.IndividualEntry; + +import java.io.File; +import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +@Slf4j +public class AttendeeRequestBuilderTest { + + public static AttendeeCreateRequest getAttendeeCreateRequest(){ + AttendeeCreateRequest attendeeCreateRequest=AttendeeCreateRequest.builder().requestInfo(getRequestInfo()) + .attendees(getAttendees()).build(); + return attendeeCreateRequest; + } + + public static List getAttendees(){ + IndividualEntry attendeeOne=IndividualEntry.builder().tenantId("pb.amritsar").id("047dc725-3088-45b4-877a-6bfbaf377df9") + .individualId("8ybdd-3rdh3").registerId("97ed7da3-753e-426a-b0b0-95dd61029785").enrollmentDate(new BigDecimal("1676101018000")) + .denrollmentDate(new BigDecimal("1676073600000")).auditDetails(getAuditDetails()).build(); + + IndividualEntry attendeeTwo=IndividualEntry.builder().tenantId("pb.amritsar").id("11b88488-9a7a-48da-b110-dfdc077ef467") + .individualId("8ybdd-3rdha").registerId("97ed7da3-753e-426a-b0b0-95dd61029785").enrollmentDate(new BigDecimal("1676101018000")) + .denrollmentDate(new BigDecimal("1671707969802")).auditDetails(getAuditDetails()).build(); + + + + List attendeeList=new ArrayList<>(Arrays.asList(attendeeOne,attendeeTwo)); + return attendeeList; + } + + public static AuditDetails getAuditDetails(){ + AuditDetails auditDetails=AuditDetails.builder().createdBy("11b0e02b-0145-4de2-bc42-c97b96264807") + .lastModifiedBy("11b0e02b-0145-4de2-bc42-c97b96264807").createdTime(Long.valueOf("1672129633890")) + .lastModifiedTime(Long.valueOf("1672129855564")).build(); + return auditDetails; + } + + public static RequestInfo getRequestInfo(){ + Role role = new Role(1L,"Organization staff","ORG_STAFF","pb.amritsar"); + List roles = new ArrayList<>(); + roles.add(role); + User userInfo = User.builder().id(172L).uuid("5ce80dd3-b1c0-42fd-b8f6-a2be456db31c").userName("8070102021").name("test3").mobileNumber("8070102021") + .emailId("xyz@egovernments.org").type("EMPLOYEE").roles(roles).build(); + RequestInfo requestInfo = RequestInfo.builder().apiId("attendance-services").msgId("search with from and to values").userInfo(userInfo).build(); + return requestInfo; + } + + public static Object getMdmsResponseForValidTenant() { + + Object mdmsResponse = null; + + try { + ObjectMapper objectMapper = new ObjectMapper(); + File file = new File("src/test/resources/TenantMDMSData.json"); + String exampleRequest = FileUtils.readFileToString(file, StandardCharsets.UTF_8); + mdmsResponse = objectMapper.readValue(exampleRequest, Object.class); + } catch (Exception exception) { + log.error("AttendeeRequestBuilderTest::getMdmsResponse::Exception while parsing mdms json"); + } + return mdmsResponse; + } + + public static Object getMdmsResponseForInvalidTenant() { + + Object mdmsResponse = null; + + try { + ObjectMapper objectMapper = new ObjectMapper(); + File file = new File("src/test/resources/InvalidTenantMDMSData.json"); + String exampleRequest = FileUtils.readFileToString(file, StandardCharsets.UTF_8); + mdmsResponse = objectMapper.readValue(exampleRequest, Object.class); + } catch (Exception exception) { + log.error("AttendeeRequestBuilderTest::getMdmsResponse::Exception while parsing mdms json"); + } + return mdmsResponse; + } + + public static ResponseInfo getResponseInfo_Success() { + ResponseInfo responseInfo = ResponseInfo.builder().apiId("attendance-services").ver(null).ts(null).resMsgId(null).msgId("search with from and to values") + .status("successful").build(); + return responseInfo; + } +} diff --git a/health-services/attendance/src/test/java/org/egov/helper/AuditDetailsTestBuilder.java b/health-services/attendance/src/test/java/org/egov/helper/AuditDetailsTestBuilder.java new file mode 100644 index 00000000000..2dd9a6fa044 --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/helper/AuditDetailsTestBuilder.java @@ -0,0 +1,27 @@ +package org.egov.helper; + +import digit.models.coremodels.AuditDetails; + +public class AuditDetailsTestBuilder { + private AuditDetails.AuditDetailsBuilder builder; + + public AuditDetailsTestBuilder() { + this.builder = AuditDetails.builder(); + } + + public static AuditDetailsTestBuilder builder() { + return new AuditDetailsTestBuilder(); + } + + public AuditDetails build() { + return this.builder.build(); + } + + public AuditDetailsTestBuilder withAuditDetails() { + this.builder.createdTime(System.currentTimeMillis()) + .createdBy("some-uuid") + .lastModifiedTime(System.currentTimeMillis()) + .lastModifiedBy("some-uuid"); + return this; + } +} \ No newline at end of file diff --git a/health-services/attendance/src/test/java/org/egov/helper/DocumentTestBuilder.java b/health-services/attendance/src/test/java/org/egov/helper/DocumentTestBuilder.java new file mode 100644 index 00000000000..ef1a0872e51 --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/helper/DocumentTestBuilder.java @@ -0,0 +1,45 @@ +package org.egov.helper; + + +import org.egov.web.models.Document; +import org.egov.web.models.Status; + +public class DocumentTestBuilder { + private Document.DocumentBuilder builder; + + public DocumentTestBuilder(){ + this.builder = Document.builder(); + } + + public Document build(){ + return this.builder.build(); + } + + public static DocumentTestBuilder builder(){ + return new DocumentTestBuilder(); + } + + public DocumentTestBuilder addGoodDocument(){ + this.builder + .id("Id-1") + .fileStore("FileStore-1") + .documentUid("DocumentUid-1") + .additionalDetails(new Object()) + .status(Status.fromValue("ACTIVE")) + .additionalDetails(AdditionalFields.builder().build()); + + return this; + } + + public DocumentTestBuilder addDocumentWithoutId(){ + this.builder + .fileStore("FileStore-1") + .documentUid("DocumentUid-1") + .additionalDetails(new Object()) + .status(Status.fromValue("ACTIVE")) + .additionalDetails(AdditionalFields.builder().build()); + + return this; + } + +} diff --git a/health-services/attendance/src/test/java/org/egov/helper/Field.java b/health-services/attendance/src/test/java/org/egov/helper/Field.java new file mode 100644 index 00000000000..1a9dc3fafd7 --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/helper/Field.java @@ -0,0 +1,25 @@ +package org.egov.helper; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; +import org.springframework.validation.annotation.Validated; + +/** + * Field + */ + + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class Field { + @JsonProperty("key") + private String key = null; + + @JsonProperty("value") + private String value = null; + + +} \ No newline at end of file diff --git a/health-services/attendance/src/test/java/org/egov/helper/IndividualEntryBuilderTest.java b/health-services/attendance/src/test/java/org/egov/helper/IndividualEntryBuilderTest.java new file mode 100644 index 00000000000..484f9d5f7a3 --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/helper/IndividualEntryBuilderTest.java @@ -0,0 +1,34 @@ +package org.egov.helper; + + + +import org.egov.web.models.IndividualEntry; + +import java.math.BigDecimal; + +public class IndividualEntryBuilderTest { + private IndividualEntry.IndividualEntryBuilder builder; + public IndividualEntryBuilderTest() { + this.builder = IndividualEntry.builder(); + } + + public static StaffPermissionBuilderTest builder() { + return new StaffPermissionBuilderTest(); + } + + public IndividualEntry build() { + return this.builder.build(); + } + + public void addGoodStaffPermission(){ + this.builder.id("some_id") + .tenantId("some_tenantId") + .registerId("some_registerId") + .individualId("some_individualId") + .enrollmentDate(BigDecimal.valueOf(1640995200000L)) + .denrollmentDate(BigDecimal.valueOf(1703980800000L)) + .auditDetails(AuditDetailsTestBuilder.builder().withAuditDetails().build()) + .additionalDetails(AdditionalFields.builder().build()); + } + +} diff --git a/health-services/attendance/src/test/java/org/egov/helper/RequestInfoTestBuilder.java b/health-services/attendance/src/test/java/org/egov/helper/RequestInfoTestBuilder.java new file mode 100644 index 00000000000..a4173a112b3 --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/helper/RequestInfoTestBuilder.java @@ -0,0 +1,62 @@ +package org.egov.helper; + +import org.egov.common.contract.request.RequestInfo; + + +public class RequestInfoTestBuilder { + private RequestInfo.RequestInfoBuilder builder; + + public RequestInfoTestBuilder() { + this.builder = RequestInfo.builder(); + } + + public static RequestInfoTestBuilder builder() { + return new RequestInfoTestBuilder(); + } + + public RequestInfo build() { + return this.builder.build(); + } + + public RequestInfoTestBuilder withCompleteRequestInfo() { + this.builder.userInfo(UserTestBuilder.builder().withCompleteUserInfo().build()) + .action("create") + .apiId("some-api-id") + .authToken("some-auth-token") + .did("some-did") + .correlationId("some-correlation-id") + .key("some-key") + .msgId("some-msg-id") + .ts(System.currentTimeMillis()) + .ver("1"); + return this; + } + + public RequestInfoTestBuilder requestInfoWithUserInfoButWithOutUUID() { + this.builder.userInfo(UserTestBuilder.builder().userInfoWithOutUUID().build()) + .action("create") + .apiId("some-api-id") + .authToken("some-auth-token") + .did("some-did") + .correlationId("some-correlation-id") + .key("some-key") + .msgId("some-msg-id") + .ts(System.currentTimeMillis()) + .ver("1"); + return this; + } + + public RequestInfoTestBuilder requestInfoWithoutUserInfo() { + this.builder.userInfo(null) + .action("create") + .apiId("some-api-id") + .authToken("some-auth-token") + .did("some-did") + .correlationId("some-correlation-id") + .key("some-key") + .msgId("some-msg-id") + .ts(System.currentTimeMillis()) + .ver("1"); + return this; + } +} \ No newline at end of file diff --git a/health-services/attendance/src/test/java/org/egov/helper/StaffPermissionBuilderTest.java b/health-services/attendance/src/test/java/org/egov/helper/StaffPermissionBuilderTest.java new file mode 100644 index 00000000000..3d784d5235b --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/helper/StaffPermissionBuilderTest.java @@ -0,0 +1,33 @@ +package org.egov.helper; + +import org.egov.web.models.StaffPermission; + +import java.math.BigDecimal; + +public class StaffPermissionBuilderTest { + + private StaffPermission.StaffPermissionBuilder builder; + public StaffPermissionBuilderTest() { + this.builder = StaffPermission.builder(); + } + + public static StaffPermissionBuilderTest builder() { + return new StaffPermissionBuilderTest(); + } + + public StaffPermission build() { + return this.builder.build(); + } + + public void addGoodStaffPermission(){ + this.builder.id("some_id") + .tenantId("some_tenantId") + .registerId("some_registerId") + .userId("some_userId") + .enrollmentDate(BigDecimal.valueOf(1640995200000L)) + .denrollmentDate(BigDecimal.valueOf(1703980800000L)) + .auditDetails(AuditDetailsTestBuilder.builder().withAuditDetails().build()) + .additionalDetails(AdditionalFields.builder().build()); + } + +} diff --git a/health-services/attendance/src/test/java/org/egov/helper/StaffRequestBuilderTest.java b/health-services/attendance/src/test/java/org/egov/helper/StaffRequestBuilderTest.java new file mode 100644 index 00000000000..d0ab6f0b901 --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/helper/StaffRequestBuilderTest.java @@ -0,0 +1,97 @@ +package org.egov.helper; + +import com.fasterxml.jackson.databind.ObjectMapper; +import digit.models.coremodels.AuditDetails; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.FileUtils; +import org.egov.common.contract.request.RequestInfo; +import org.egov.common.contract.request.Role; +import org.egov.common.contract.request.User; +import org.egov.common.contract.response.ResponseInfo; +import org.egov.web.models.StaffPermission; +import org.egov.web.models.StaffPermissionRequest; + +import java.io.File; +import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +@Slf4j +public class StaffRequestBuilderTest { + + public static StaffPermissionRequest getStaffPermissionRequest() { + StaffPermissionRequest staffPermissionRequest = StaffPermissionRequest.builder().requestInfo(getRequestInfo()) + .staff(getStaff()).build(); + return staffPermissionRequest; + } + + + public static List getStaff() { + StaffPermission staffOne = StaffPermission.builder().id("03901adb-07c3-4539-9346-4ee5c87e5e1c").userId("8ybdd-3rdhd") + .registerId("97ed7da3-753e-426a-b0b0-95dd61029785").tenantId("pb.amritsar").enrollmentDate(new BigDecimal("1670421853937")) + .denrollmentDate(null).auditDetails(getAuditDetails()).build(); + + StaffPermission staffTwo = StaffPermission.builder().id("156d07fd-2c0c-4882-be03-6b68b98fb15e").userId("8ybdd-3rdhe") + .registerId("97ed7da3-753e-426a-b0b0-95dd61029785").tenantId("pb.amritsar").enrollmentDate(new BigDecimal("1670424209106")) + .denrollmentDate(null).auditDetails(getAuditDetails()).build(); + + List staffList = new ArrayList<>(Arrays.asList(staffOne, staffTwo)); + return staffList; + } + + + public static AuditDetails getAuditDetails() { + AuditDetails auditDetails = AuditDetails.builder().createdBy("11b0e02b-0145-4de2-bc42-c97b96264807") + .lastModifiedBy("11b0e02b-0145-4de2-bc42-c97b96264807").createdTime(Long.valueOf("1672129633890")) + .lastModifiedTime(Long.valueOf("1672129855564")).build(); + return auditDetails; + } + + public static RequestInfo getRequestInfo() { + Role role = new Role(1L, "Organization staff", "ORG_STAFF", "pb.amritsar"); + List roles = new ArrayList<>(); + roles.add(role); + User userInfo = User.builder().id(172L).uuid("5ce80dd3-b1c0-42fd-b8f6-a2be456db31c").userName("8070102021").name("test3").mobileNumber("8070102021") + .emailId("xyz@egovernments.org").type("EMPLOYEE").roles(roles).build(); + RequestInfo requestInfo = RequestInfo.builder().apiId("attendance-services").msgId("search with from and to values").userInfo(userInfo).build(); + return requestInfo; + } + + public static Object getMdmsResponseForValidTenant() { + + Object mdmsResponse = null; + + try { + ObjectMapper objectMapper = new ObjectMapper(); + File file = new File("src/test/resources/TenantMDMSData.json"); + String exampleRequest = FileUtils.readFileToString(file, StandardCharsets.UTF_8); + mdmsResponse = objectMapper.readValue(exampleRequest, Object.class); + } catch (Exception exception) { + log.error("AttendeeRequestBuilderTest::getMdmsResponse::Exception while parsing mdms json"); + } + return mdmsResponse; + } + + public static Object getMdmsResponseForInvalidTenant() { + + Object mdmsResponse = null; + + try { + ObjectMapper objectMapper = new ObjectMapper(); + File file = new File("src/test/resources/InvalidTenantMDMSData.json"); + String exampleRequest = FileUtils.readFileToString(file, StandardCharsets.UTF_8); + mdmsResponse = objectMapper.readValue(exampleRequest, Object.class); + } catch (Exception exception) { + log.error("AttendeeRequestBuilderTest::getMdmsResponse::Exception while parsing mdms json"); + } + return mdmsResponse; + } + + public static ResponseInfo getResponseInfo_Success() { + ResponseInfo responseInfo = ResponseInfo.builder().apiId("attendance-services").ver(null).ts(null).resMsgId(null).msgId("search with from and to values") + .status("successful").build(); + return responseInfo; + } +} diff --git a/health-services/attendance/src/test/java/org/egov/helper/UserTestBuilder.java b/health-services/attendance/src/test/java/org/egov/helper/UserTestBuilder.java new file mode 100644 index 00000000000..2aca7685ecc --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/helper/UserTestBuilder.java @@ -0,0 +1,58 @@ +package org.egov.helper; + +import org.egov.common.contract.request.Role; +import org.egov.common.contract.request.User; + +import java.util.ArrayList; +import java.util.List; + +public class UserTestBuilder { + private User.UserBuilder builder; + + public UserTestBuilder() { + this.builder = User.builder(); + } + + public static UserTestBuilder builder() { + return new UserTestBuilder(); + } + + public User build() { + return this.builder.build(); + } + + public UserTestBuilder withCompleteUserInfo() { + Role role = Role.builder() + .id(123L) + .name("System Administrator") + .build(); + List roles = new ArrayList<>(); + roles.add(role); + this.builder.userName("some-username") + .roles(roles) + .id(123L) + .name("some-name") + .type("EMPLOYEE") + .emailId("some-email-id") + .mobileNumber("9893212345") + .uuid("some-uuid"); + return this; + } + + public UserTestBuilder userInfoWithOutUUID() { + Role role = Role.builder() + .id(123L) + .name("System Administrator") + .build(); + List roles = new ArrayList<>(); + roles.add(role); + this.builder.userName("some-username") + .roles(roles) + .id(123L) + .name("some-name") + .type("EMPLOYEE") + .emailId("some-email-id") + .mobileNumber("9893212345"); + return this; + } +} \ No newline at end of file diff --git a/health-services/attendance/src/test/java/org/egov/service/AttendanceLogServiceTest.java b/health-services/attendance/src/test/java/org/egov/service/AttendanceLogServiceTest.java new file mode 100644 index 00000000000..2acd6629f48 --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/service/AttendanceLogServiceTest.java @@ -0,0 +1,67 @@ +package org.egov.service; + +import lombok.extern.slf4j.Slf4j; +import org.egov.config.AttendanceServiceConfiguration; +import org.egov.enrichment.AttendanceLogEnrichment; +import org.egov.helper.AttendanceLogRequestTestBuilder; +import org.egov.common.producer.Producer; +import org.egov.repository.AttendanceLogRepository; +import org.egov.tracer.model.CustomException; +import org.egov.util.ResponseInfoFactory; +import org.egov.validator.AttendanceLogServiceValidator; +import org.egov.web.models.AttendanceLogRequest; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import static org.hibernate.validator.internal.util.Contracts.assertNotNull; + + + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +@Slf4j +@ExtendWith(MockitoExtension.class) +public class AttendanceLogServiceTest { + + @InjectMocks + private AttendanceLogService attendanceLogService; + + @Mock + private AttendanceLogServiceValidator attendanceLogServiceValidator; + + + @Mock + private ResponseInfoFactory responseInfoFactory; + + + @Mock + private AttendanceLogEnrichment attendanceLogEnricher; + + @Mock + private Producer producer; + + @Mock + private AttendanceServiceConfiguration config; + + + @DisplayName("create attendance log successfully") + @Test + public void createAttendanceLogTest_1(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); + when(config.getCreateAttendanceLogTopic()).thenReturn("save-attendance-log"); + + attendanceLogService.createAttendanceLog(attendanceLogRequest); + + verify(attendanceLogServiceValidator, times(1)).validateCreateAttendanceLogRequest(attendanceLogRequest); + + verify(attendanceLogEnricher, times(1)).enrichAttendanceLogCreateRequest(attendanceLogRequest); + + verify(producer, times(1)).push(eq("save-attendance-log"), any(AttendanceLogRequest.class)); + + assertNotNull(attendanceLogRequest.getAttendance()); + } +} diff --git a/health-services/attendance/src/test/java/org/egov/validator/AttendanceLogServiceValidatorTest.java b/health-services/attendance/src/test/java/org/egov/validator/AttendanceLogServiceValidatorTest.java new file mode 100644 index 00000000000..fe4403af13d --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/validator/AttendanceLogServiceValidatorTest.java @@ -0,0 +1,453 @@ +package org.egov.validator; + +import lombok.extern.slf4j.Slf4j; +import org.egov.config.AttendanceServiceConfiguration; +import org.egov.helper.AdditionalFields; +import org.egov.helper.AttendanceLogRequestTestBuilder; +import org.egov.helper.AttendanceRegisterBuilderTest; +import org.egov.helper.AuditDetailsTestBuilder; +import org.egov.repository.AttendeeRepository; +import org.egov.repository.RegisterRepository; +import org.egov.repository.StaffRepository; +import org.egov.tracer.model.CustomException; +import org.egov.web.models.*; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.test.util.ReflectionTestUtils; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@Slf4j +@ExtendWith(MockitoExtension.class) +public class AttendanceLogServiceValidatorTest { + + @InjectMocks + private AttendanceLogServiceValidator attendanceLogServiceValidator; + + @Mock + private AttendanceServiceConfiguration config; + + @Mock + private StaffRepository attendanceStaffRepository; + + @Mock + private RegisterRepository attendanceRegisterRepository; + + @Mock + private AttendeeRepository attendanceAttendeeRepository; + + @DisplayName("Method validateAttendanceLogRequest: With good request") + @Test + public void validateCreateAttendanceLogRequest_validateAttendanceLogRequest_1(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); + assertDoesNotThrow(()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendanceLogRequest", attendanceLogRequest)); + } + + @DisplayName("Method validateAttendanceLogRequest: With null RequestInfo object") + @Test + public void validateCreateAttendanceLogRequest_validateAttendanceLogRequest_2(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withoutRequestInfo().addGoodAttendanceLog().build(); + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendanceLogRequest", attendanceLogRequest)); + assertTrue(exception.getCode().equals("REQUEST_INFO")); + } + + @DisplayName("Method validateAttendanceLogRequest: RequestInfo object with null UserInfo") + @Test + public void validateCreateAttendanceLogRequest_validateAttendanceLogRequest_3(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfoButWithoutUserInfo().addGoodAttendanceLog().build(); + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendanceLogRequest", attendanceLogRequest)); + assertTrue(exception.getCode().equals("USERINFO")); + } + + @DisplayName("Method validateAttendanceLogRequest: RequestInfo object with UserInfo but without UUID") + @Test + public void validateCreateAttendanceLogRequest_validateAttendanceLogRequest_4(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfoWithUserInfoButWithOutUUID().addGoodAttendanceLog().build(); + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendanceLogRequest", attendanceLogRequest)); + assertTrue(exception.getCode().equals("USERINFO_UUID")); + } + + @DisplayName("Method validateAttendanceLogRequest: RequestInfo object with UserInfo but without UUID") + @Test + public void validateCreateAttendanceLogRequest_validateAttendanceLogRequest_5(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfoWithUserInfoButWithOutUUID().addGoodAttendanceLog().build(); + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendanceLogRequest", attendanceLogRequest)); + assertTrue(exception.getCode().equals("USERINFO_UUID")); + } + + @DisplayName("Method validateAttendanceLogRequest: RequestInfo object with UserInfo but without Attendance Log list") + @Test + public void validateCreateAttendanceLogRequest_validateAttendanceLogRequest_6(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().withoutAttendanceLog().build(); + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendanceLogRequest", attendanceLogRequest)); + assertTrue(exception.getCode().equals("ATTENDANCE")); + } + + @DisplayName("Method validateAttendanceLogRequest: RequestInfo object with UserInfo but without Attendance Log TenantId") + @Test + public void validateCreateAttendanceLogRequest_validateAttendanceLogRequest_7(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().attendanceLogWithoutTenantId().build(); + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendanceLogRequest", attendanceLogRequest)); + assertTrue(exception.toString().contains("TenantId is mandatory")); + } + + @DisplayName("Method validateAttendanceLogRequest: RequestInfo object with UserInfo but without Attendance Log RegisterId") + @Test + public void validateCreateAttendanceLogRequest_validateAttendanceLogRequest_8(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().attendanceLogWithoutRegisterId().build(); + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendanceLogRequest", attendanceLogRequest)); + log.info(exception.toString()); + assertTrue(exception.toString().contains("Attendance registerid is mandatory")); + } + + @DisplayName("Method validateAttendanceLogRequest: RequestInfo object with UserInfo but without Attendance Log IndividualId") + @Test + public void validateCreateAttendanceLogRequest_validateAttendanceLogRequest_9(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().attendanceLogWithoutIndividualId().build(); + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendanceLogRequest", attendanceLogRequest)); + assertTrue(exception.toString().contains("Attendance indidualid is mandatory")); + } + + @DisplayName("Method validateAttendanceLogRequest: RequestInfo object with UserInfo but without Attendance Log Type") + @Test + public void validateCreateAttendanceLogRequest_validateAttendanceLogRequest_10(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().attendanceLogWithoutType().build(); + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendanceLogRequest", attendanceLogRequest)); + assertTrue(exception.toString().contains("Attendance type is mandatory")); + } + + @DisplayName("Method validateAttendanceLogRequest: RequestInfo object with UserInfo but without Attendance Log Time") + @Test + public void validateCreateAttendanceLogRequest_validateAttendanceLogRequest_11(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().attendanceLogWithoutTime().build(); + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendanceLogRequest", attendanceLogRequest)); + assertTrue(exception.toString().contains("Attendance time is mandatory")); + } + + + @DisplayName("Method validateLoggedInUser: should throw exception with code INTEGRATION_UNDERDEVELOPMENT") + @Test + public void validateCreateAttendanceLogRequest_validateLoggedInUser_1(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); + when(config.getStaffServiceIntegrationRequired()).thenReturn("TRUE"); + + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateLoggedInUser", attendanceLogRequest)); + assertTrue(exception.getCode().equals("INTEGRATION_UNDERDEVELOPMENT")); + } + +// @DisplayName("Method validateLoggedInUser: should through exception with error code UNAUTHORISED_USER") +// @Test +// public void validateCreateAttendanceLogRequest_validateLoggedInUser_2(){ +// AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); +// when(config.getStaffServiceIntegrationRequired()).thenReturn("FALSE"); +// when(attendanceStaffRepository.getActiveStaff(any(StaffSearchCriteria.class))).thenReturn(null); +// +// CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateLoggedInUser", attendanceLogRequest)); +// assertTrue(exception.getCode().equals("UNAUTHORISED_USER")); +// +// } + +// @DisplayName("Method validateLoggedInUser: should through exception with error code UNAUTHORISED_USER") +// @Test +// public void validateCreateAttendanceLogRequest_validateLoggedInUser_3(){ +// AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); +// when(config.getStaffServiceIntegrationRequired()).thenReturn("FALSE"); +// List attendanceStaff = new ArrayList<>(); +// when(attendanceStaffRepository.getActiveStaff(any(StaffSearchCriteria.class))).thenReturn(attendanceStaff); +// +// CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateLoggedInUser", attendanceLogRequest)); +// assertTrue(exception.getCode().equals("UNAUTHORISED_USER")); +// +// } + +// @DisplayName("Method validateLoggedInUser: should run successfully") +// @Test +// public void validateCreateAttendanceLogRequest_validateLoggedInUser_4(){ +// AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); +// when(config.getStaffServiceIntegrationRequired()).thenReturn("FALSE"); +// StaffPermission staff = StaffPermission.builder() +// .id("staff-uuid") +// .tenantId("tenantId") +// .userId("staffId") +// .registerId("registerId") +// .enrollmentDate(BigDecimal.valueOf(1L)) +// .denrollmentDate(BigDecimal.valueOf(1L)) +// .auditDetails(AuditDetailsTestBuilder.builder().withAuditDetails().build()) +// .additionalDetails(AdditionalFields.builder().build()) +// .build(); +// List attendanceStaff = new ArrayList<>(); +// attendanceStaff.add(staff); +// when(attendanceStaffRepository.getActiveStaff(any(StaffSearchCriteria.class))).thenReturn(attendanceStaff); +// +// assertDoesNotThrow(()->ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateLoggedInUser", attendanceLogRequest)); +// +// } + + @DisplayName("Method validateTenantIdAssociationWithRegisterId: should through exception with error code INVALID_TENANTID") + @Test + public void validateCreateAttendanceLogRequest_validateTenantIdAssociationWithRegisterId_1(){ + AttendanceRegister attendanceRegister = AttendanceRegisterBuilderTest.getAttendanceRegister(); + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateTenantIdAssociationWithRegisterId", attendanceRegister,"other.tenantId")); + assertTrue(exception.getCode().equals("INVALID_TENANTID")); + } + @DisplayName("Method validateTenantIdAssociationWithRegisterId: should run successfully") + @Test + public void validateCreateAttendanceLogRequest_validateTenantIdAssociationWithRegisterId_2(){ + AttendanceRegister attendanceRegister = AttendanceRegisterBuilderTest.getAttendanceRegister(); + assertDoesNotThrow(()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateTenantIdAssociationWithRegisterId", attendanceRegister,"pb.amritsar")); + } + + @DisplayName("Method validateAttendees: should through exception with error code INTEGRATION_UNDERDEVELOPMENT") + @Test + public void validateCreateAttendanceLogRequest_validateAttendees_1(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); + when(config.getIndividualServiceIntegrationRequired()).thenReturn("TRUE"); + + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendees", attendanceLogRequest)); + assertTrue(exception.getCode().equals("INTEGRATION_UNDERDEVELOPMENT")); + } + + @DisplayName("Method validateAttendees: should run successfully") + @Test + public void validateCreateAttendanceLogRequest_validateAttendees_2(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); + when(config.getIndividualServiceIntegrationRequired()).thenReturn("FALSE"); + + IndividualEntry individual = IndividualEntry.builder() + .registerId("some-registerId") + .id("uuid") + .individualId("some-individualId") + .enrollmentDate(BigDecimal.valueOf(1640995200000L)) + .denrollmentDate(BigDecimal.valueOf(1703980800000L)) + .build(); + List individualEntries = new ArrayList<>(); + individualEntries.add(individual); + when(attendanceAttendeeRepository.getAttendees(any(AttendeeSearchCriteria.class))).thenReturn(individualEntries); + assertDoesNotThrow( ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendees", attendanceLogRequest)); + } + + @DisplayName("Method validateAttendees: should run successfully") + @Test + public void validateCreateAttendanceLogRequest_validateAttendees_3(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); + when(config.getIndividualServiceIntegrationRequired()).thenReturn("FALSE"); + + IndividualEntry individual = IndividualEntry.builder() + .registerId("some-registerId") + .id("uuid") + .individualId("some-individualId") + .enrollmentDate(BigDecimal.valueOf(1640995200000L)) + .build(); + List individualEntries = new ArrayList<>(); + individualEntries.add(individual); + when(attendanceAttendeeRepository.getAttendees(any(AttendeeSearchCriteria.class))).thenReturn(individualEntries); + assertDoesNotThrow( ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendees", attendanceLogRequest)); + } + + @DisplayName("Method validateAttendees: should run successfully") + @Test + public void validateCreateAttendanceLogRequest_validateAttendees_4(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); + when(config.getIndividualServiceIntegrationRequired()).thenReturn("FALSE"); + + IndividualEntry individual = IndividualEntry.builder() + .registerId("some-registerId") + .id("uuid") + .individualId("some-individualId") + .enrollmentDate(BigDecimal.valueOf(1672813896627L)) + .build(); + List individualEntries = new ArrayList<>(); + individualEntries.add(individual); + when(attendanceAttendeeRepository.getAttendees(any(AttendeeSearchCriteria.class))).thenReturn(individualEntries); + assertDoesNotThrow( ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendees", attendanceLogRequest)); + } + + @DisplayName("Method validateAttendees: should through exception with error code INELIGIBLE_ATTENDEES") + @Test + public void validateCreateAttendanceLogRequest_validateAttendees_5(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); + when(config.getIndividualServiceIntegrationRequired()).thenReturn("FALSE"); + + IndividualEntry individual = IndividualEntry.builder() + .registerId("some-registerId") + .id("uuid") + .individualId("some-individualId") + .enrollmentDate(BigDecimal.valueOf(1705491134000L)) + .build(); + List individualEntries = new ArrayList<>(); + individualEntries.add(individual); + when(attendanceAttendeeRepository.getAttendees(any(AttendeeSearchCriteria.class))).thenReturn(individualEntries); + CustomException exception = assertThrows(CustomException.class, ( ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendees", attendanceLogRequest))); + assertTrue(exception.getCode().equals("INELIGIBLE_ATTENDEES")); + } + + @DisplayName("Method validateAttendees: should through exception with error code INELIGIBLE_ATTENDEES") + @Test + public void validateCreateAttendanceLogRequest_validateAttendees_6(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); + when(config.getIndividualServiceIntegrationRequired()).thenReturn("FALSE"); + + IndividualEntry individual = IndividualEntry.builder() + .registerId("some-registerId") + .id("uuid") + .individualId("some-individualId") + .enrollmentDate(BigDecimal.valueOf(1579260734000L)) + .denrollmentDate(BigDecimal.valueOf(1589715134000L)) + .build(); + List individualEntries = new ArrayList<>(); + individualEntries.add(individual); + when(attendanceAttendeeRepository.getAttendees(any(AttendeeSearchCriteria.class))).thenReturn(individualEntries); + CustomException exception = assertThrows(CustomException.class, ( ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendees", attendanceLogRequest))); + assertTrue(exception.getCode().equals("INELIGIBLE_ATTENDEES")); + } + + @DisplayName("Method validateDocumentIds: should through exception with error code SERVICE_UNAVAILABLE") + @Test + public void validateCreateAttendanceLogRequest_validateDocumentIds_1(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); + when(config.getDocumentIdVerificationRequired()).thenReturn("TRUE"); + CustomException exception = assertThrows(CustomException.class, ( ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateDocumentIds", attendanceLogRequest))); + assertTrue(exception.getCode().equals("SERVICE_UNAVAILABLE")); + } + + @DisplayName("Method validateDocumentIds: should run successfully") + @Test + public void validateCreateAttendanceLogRequest_validateDocumentIds_2(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); + when(config.getDocumentIdVerificationRequired()).thenReturn("FALSE"); + assertDoesNotThrow( ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateDocumentIds", attendanceLogRequest)); + } + + @DisplayName("Method validateAttendanceLogTimeWithRegisterStartEndDate: should run successfully") + @Test + public void validateCreateAttendanceLogRequest_validateAttendanceLogTimeWithRegisterStartEndDate_1(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); + AttendanceLog attendanceLog = attendanceLogRequest.getAttendance().get(0); + attendanceLog.setTime(new BigDecimal("1673740800000")); + AttendanceRegister attendanceRegister = AttendanceRegisterBuilderTest.getAttendanceRegister(); + assertDoesNotThrow( ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendanceLogTimeWithRegisterStartEndDate",attendanceRegister, attendanceLogRequest)); + } + + @DisplayName("Method validateAttendanceLogTimeWithRegisterStartEndDate: should through exception with error code INVALID_ATTENDANCE_TIME") + @Test + public void validateCreateAttendanceLogRequest_validateAttendanceLogTimeWithRegisterStartEndDate_2(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); + AttendanceLog attendanceLog = attendanceLogRequest.getAttendance().get(0); + attendanceLog.setTime(new BigDecimal("1573740800000")); + AttendanceRegister attendanceRegister = AttendanceRegisterBuilderTest.getAttendanceRegister(); + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendanceLogTimeWithRegisterStartEndDate",attendanceRegister, attendanceLogRequest)); + assertTrue(exception.getCode().equals("INVALID_ATTENDANCE_TIME")); + } + + @DisplayName("Method validateAttendanceLogTimeWithRegisterStartEndDate: should through exception with error code INVALID_ATTENDANCE_TIME") + @Test + public void validateCreateAttendanceLogRequest_validateAttendanceLogTimeWithRegisterStartEndDate_3(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); + AttendanceLog attendanceLog = attendanceLogRequest.getAttendance().get(0); + attendanceLog.setTime(new BigDecimal("1792057600000")); + AttendanceRegister attendanceRegister = AttendanceRegisterBuilderTest.getAttendanceRegister(); + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendanceLogTimeWithRegisterStartEndDate",attendanceRegister, attendanceLogRequest)); + assertTrue(exception.getCode().equals("INVALID_ATTENDANCE_TIME")); + } + + @DisplayName("Method validateAttendanceLogTimeWithRegisterStartEndDate: should run successfully") + @Test + public void validateCreateAttendanceLogRequest_validateAttendanceLogTimeWithRegisterStartEndDate_4(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); + AttendanceLog attendanceLog = attendanceLogRequest.getAttendance().get(0); + attendanceLog.setTime(new BigDecimal("1673740800000")); + AttendanceRegister attendanceRegister = AttendanceRegisterBuilderTest.getAttendanceRegister(); + assertDoesNotThrow(()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendanceLogTimeWithRegisterStartEndDate",attendanceRegister, attendanceLogRequest)); + } + + @DisplayName("Method validateAttendanceLogTimeWithRegisterStartEndDate: should run successfully") + @Test + public void validateCreateAttendanceLogRequest_validateAttendanceLogTimeWithRegisterStartEndDate_5(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); + AttendanceLog attendanceLog = attendanceLogRequest.getAttendance().get(0); + attendanceLog.setTime(new BigDecimal("1692057600000")); + AttendanceRegister attendanceRegister = AttendanceRegisterBuilderTest.getAttendanceRegister(); + assertDoesNotThrow(()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendanceLogTimeWithRegisterStartEndDate",attendanceRegister, attendanceLogRequest)); + } + + @DisplayName("Method validateAttendanceLogTimeWithRegisterStartEndDate: should run successfully") + @Test + public void validateCreateAttendanceLogRequest_validateAttendanceLogTimeWithRegisterStartEndDate_6(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); + AttendanceLog attendanceLog = attendanceLogRequest.getAttendance().get(0); + attendanceLog.setTime(new BigDecimal("1673740800000")); + AttendanceRegister attendanceRegister = AttendanceRegisterBuilderTest.getAttendanceRegisterWithoutEndDate(); + assertDoesNotThrow(()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendanceLogTimeWithRegisterStartEndDate",attendanceRegister, attendanceLogRequest)); + } + + @DisplayName("Method validateAttendanceLogTimeWithRegisterStartEndDate: should run successfully") + @Test + public void validateCreateAttendanceLogRequest_validateAttendanceLogTimeWithRegisterStartEndDate_7(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); + AttendanceLog attendanceLog = attendanceLogRequest.getAttendance().get(0); + attendanceLog.setTime(new BigDecimal("1773740800000")); + AttendanceRegister attendanceRegister = AttendanceRegisterBuilderTest.getAttendanceRegisterWithoutEndDate(); + assertDoesNotThrow(()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendanceLogTimeWithRegisterStartEndDate",attendanceRegister, attendanceLogRequest)); + } + + @DisplayName("Method validateAttendanceLogTimeWithRegisterStartEndDate: should run successfully") + @Test + public void validateCreateAttendanceLogRequest_validateAttendanceLogTimeWithRegisterStartEndDate_8(){ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); + AttendanceLog attendanceLog = attendanceLogRequest.getAttendance().get(0); + attendanceLog.setTime(new BigDecimal("1573740800000")); + AttendanceRegister attendanceRegister = AttendanceRegisterBuilderTest.getAttendanceRegisterWithoutEndDate(); + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "validateAttendanceLogTimeWithRegisterStartEndDate",attendanceRegister, attendanceLogRequest)); + assertTrue(exception.getCode().equals("INVALID_ATTENDANCE_TIME")); + } + @DisplayName("Method checkRegisterStatus: should run successfully") + @Test + public void validateCreateAttendanceLogRequest_checkRegisterStatus_1(){ + AttendanceRegister attendanceRegister = AttendanceRegisterBuilderTest.getAttendanceRegister(); + attendanceRegister.setStatus(Status.ACTIVE); + assertDoesNotThrow( ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "checkRegisterStatus",attendanceRegister)); + } + @DisplayName("Method checkRegisterStatus: should through exception with error code INACTIVE_REGISTER") + @Test + public void validateCreateAttendanceLogRequest_checkRegisterStatus_2(){ + AttendanceRegister attendanceRegister = AttendanceRegisterBuilderTest.getAttendanceRegister(); + attendanceRegister.setStatus(Status.INACTIVE); + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "checkRegisterStatus",attendanceRegister)); + assertTrue(exception.getCode().equals("INACTIVE_REGISTER")); + } + + @DisplayName("Method checkRegisterExistence: should run successfully") + @Test + public void validateCreateAttendanceLogRequest_checkRegisterExistence_1(){ + AttendanceRegister attendanceRegister = AttendanceRegisterBuilderTest.getAttendanceRegister(); + List attendanceRegisters = Collections.singletonList(attendanceRegister); + assertDoesNotThrow( ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "checkRegisterExistence",attendanceRegisters,"TestRegisterId")); + } + + @DisplayName("Method checkRegisterExistence: should through exception with error code REGISTER_NOT_FOUND") + @Test + public void validateCreateAttendanceLogRequest_checkRegisterExistence_2(){ + List attendanceRegisters = null; + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "checkRegisterExistence",attendanceRegisters,"TestRegisterId")); + assertTrue(exception.getCode().equals("REGISTER_NOT_FOUND")); + } + + @DisplayName("Method checkRegisterExistence: should through exception with error code REGISTER_NOT_FOUND") + @Test + public void validateCreateAttendanceLogRequest_checkRegisterExistence_3(){ + List attendanceRegisters = new ArrayList<>(); + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceLogServiceValidator, "checkRegisterExistence",attendanceRegisters,"TestRegisterId")); + assertTrue(exception.getCode().equals("REGISTER_NOT_FOUND")); + } +} diff --git a/health-services/attendance/src/test/java/org/egov/validator/AttendanceServiceValidatorTest.java b/health-services/attendance/src/test/java/org/egov/validator/AttendanceServiceValidatorTest.java new file mode 100644 index 00000000000..951a4deefa9 --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/validator/AttendanceServiceValidatorTest.java @@ -0,0 +1,180 @@ +package org.egov.validator; + +import lombok.extern.slf4j.Slf4j; +import org.egov.common.contract.request.RequestInfo; +import org.egov.helper.AttendanceLogRequestTestBuilder; +import org.egov.helper.AttendanceRegisterRequestBuilderTest; +import org.egov.helper.AttendeeRequestBuilderTest; +import org.egov.repository.RegisterRepository; +import org.egov.tracer.model.CustomException; +import org.egov.util.MDMSUtils; +import org.egov.web.models.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.when; + +@Slf4j +@ExtendWith(MockitoExtension.class) +public class AttendanceServiceValidatorTest { + + @InjectMocks + private AttendanceServiceValidator attendanceServiceValidator; + + @Mock + private MDMSUtils mdmsUtils; + + @Mock + private RegisterRepository registerRepository; + + @DisplayName("Method validateRequestInfo: With good request") + @Test + public void validateCreateAttendanceRegister_validateRequestInfo_1(){ + AttendanceRegisterRequest attendanceRegisterRequest = AttendanceRegisterRequestBuilderTest.builder().withRequestInfo().addGoodRegister().build(); + assertDoesNotThrow(()-> ReflectionTestUtils.invokeMethod(attendanceServiceValidator, "validateRequestInfo", attendanceRegisterRequest.getRequestInfo(), new HashMap<>())); + } + + @DisplayName("Method validateRequestInfo: Should throw exception with error code REQUEST_INFO") + @Test + public void validateCreateAttendanceRegister_validateRequestInfo_2(){ + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceServiceValidator, "validateRequestInfo", null,new HashMap<>())); + assertTrue(exception.getCode().equals("REQUEST_INFO")); + } + + @DisplayName("Method validateRequestInfo: Should throw exception with error code USERINFO") + @Test + public void validateCreateAttendanceRegister_validateRequestInfo_3(){ + AttendanceRegisterRequest attendanceRegisterRequest = AttendanceRegisterRequestBuilderTest.builder().requestInfoWithoutUserInfo().addGoodRegister().build(); + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceServiceValidator, "validateRequestInfo", attendanceRegisterRequest.getRequestInfo(),new HashMap<>())); + assertTrue(exception.getCode().equals("USERINFO")); + } + + @DisplayName("Method validateRequestInfo: Should throw exception with error code USERINFO") + @Test + public void validateCreateAttendanceRegister_validateRequestInfo_4(){ + AttendanceRegisterRequest attendanceRegisterRequest = AttendanceRegisterRequestBuilderTest.builder().requestInfoWithUserInfoButWithOutUUID().build(); + CustomException exception = assertThrows(CustomException.class, ()-> ReflectionTestUtils.invokeMethod(attendanceServiceValidator, "validateRequestInfo", attendanceRegisterRequest.getRequestInfo(),new HashMap<>())); + assertTrue(exception.getCode().equals("USERINFO_UUID")); + } + + @DisplayName("Method validateAttendanceRegisterRequest: Should run successfully") + @Test + public void validateCreateAttendanceRegister_validateAttendanceRegisterRequest_1(){ + AttendanceRegisterRequest attendanceRegisterRequest = AttendanceRegisterRequestBuilderTest.builder().addGoodRegister().build(); + assertDoesNotThrow(()-> ReflectionTestUtils.invokeMethod(attendanceServiceValidator, "validateAttendanceRegisterRequest", attendanceRegisterRequest.getAttendanceRegister(),new HashMap<>())); + } + + @DisplayName("Method validateAttendanceRegisterRequest: Should throw exception with error code ATTENDANCE_REGISTER") + @Test + public void validateCreateAttendanceRegister_validateAttendanceRegisterRequest_2(){ + CustomException exception = assertThrows(CustomException.class,()-> ReflectionTestUtils.invokeMethod(attendanceServiceValidator, "validateAttendanceRegisterRequest", null,new HashMap<>())); + assertTrue(exception.getCode().equals("ATTENDANCE_REGISTER")); + } + + @DisplayName("Method validateAttendanceRegisterRequest: Should throw exception with error code ATTENDANCE_REGISTER") + @Test + public void validateCreateAttendanceRegister_validateAttendanceRegisterRequest_3(){ + // Empty list + List attendanceRegisters = new ArrayList<>(); + CustomException exception = assertThrows(CustomException.class,()-> ReflectionTestUtils.invokeMethod(attendanceServiceValidator, "validateAttendanceRegisterRequest", attendanceRegisters,new HashMap<>())); + assertTrue(exception.getCode().equals("ATTENDANCE_REGISTER")); + } + + @DisplayName("Method validateAttendanceRegisterRequest: Error code TENANT_ID") + @Test + public void validateCreateAttendanceRegister_validateAttendanceRegisterRequest_4(){ + AttendanceRegisterRequest attendanceRegisterRequest = AttendanceRegisterRequestBuilderTest.builder().attendanceRegisterWithoutTenantId().build(); + List attendanceRegister = attendanceRegisterRequest.getAttendanceRegister(); + Map errorMap = new HashMap<>(); + CustomException exception = assertThrows(CustomException.class,()->ReflectionTestUtils.invokeMethod(attendanceServiceValidator, "validateAttendanceRegisterRequest", attendanceRegister, errorMap)); + assertTrue(exception.getCode().equals("TENANT_ID")); + } + + @DisplayName("Method validateAttendanceRegisterRequest: Error code NAME") + @Test + public void validateCreateAttendanceRegister_validateAttendanceRegisterRequest_5(){ + AttendanceRegisterRequest attendanceRegisterRequest = AttendanceRegisterRequestBuilderTest.builder().attendanceRegisterWithoutName().build(); + Map errorMap = new HashMap<>(); + ReflectionTestUtils.invokeMethod(attendanceServiceValidator, "validateAttendanceRegisterRequest", attendanceRegisterRequest.getAttendanceRegister(),errorMap); + assertTrue(errorMap.keySet().contains("NAME")); + } + + @DisplayName("Method validateAttendanceRegisterRequest: Error code START_DATE") + @Test + public void validateCreateAttendanceRegister_validateAttendanceRegisterRequest_6(){ + AttendanceRegisterRequest attendanceRegisterRequest = AttendanceRegisterRequestBuilderTest.builder().attendanceRegisterWithoutStartDate().build(); + Map errorMap = new HashMap<>(); + CustomException exception = assertThrows(CustomException.class,()->ReflectionTestUtils.invokeMethod(attendanceServiceValidator, "validateAttendanceRegisterRequest", attendanceRegisterRequest.getAttendanceRegister(),errorMap)); + assertTrue(exception.getCode().equals("START_DATE")); + } + + @DisplayName("Method validateAttendanceRegisterRequest: Error code DATE") + @Test + public void validateCreateAttendanceRegister_validateAttendanceRegisterRequest_7(){ + AttendanceRegisterRequest attendanceRegisterRequest = AttendanceRegisterRequestBuilderTest.builder().attendanceRegisterWithStartDateGTEndDate().build(); + Map errorMap = new HashMap<>(); + ReflectionTestUtils.invokeMethod(attendanceServiceValidator, "validateAttendanceRegisterRequest", attendanceRegisterRequest.getAttendanceRegister(),errorMap); + assertTrue(errorMap.keySet().contains("DATE")); + } + + @DisplayName("Method validateAttendanceRegisterRequest: Error code DATE") + @Test + public void validateCreateAttendanceRegister_validateMultipleTenantIds(){ + AttendanceRegisterRequest attendanceRegisterRequest = AttendanceRegisterRequestBuilderTest.builder().withRequestInfo().attendanceRegistersWithMultipleTenantIds().build(); + Map errorMap = new HashMap<>(); + CustomException exception = assertThrows(CustomException.class,()->ReflectionTestUtils.invokeMethod(attendanceServiceValidator, "validateCreateAttendanceRegister", attendanceRegisterRequest)); + assertTrue(exception.getCode().equals("MULTIPLE_TENANTS")); + } + + @DisplayName("Method validateCreateAttendanceRegister: run successfully") + @Test + public void validateCreateAttendanceRegister_validateCreateAttendanceRegister_1(){ + AttendanceRegisterRequest attendanceRegisterRequest = AttendanceRegisterRequestBuilderTest.builder().withRequestInfo().addGoodRegister().build(); + Object mdmsResponse = AttendeeRequestBuilderTest.getMdmsResponseForValidTenant(); + lenient().when(mdmsUtils.mDMSCall(any(RequestInfo.class), + any(String.class))).thenReturn(mdmsResponse); + List registers = new ArrayList<>(); + AttendanceRegister register = AttendanceRegister.builder().build(); + registers.add(register); + when(registerRepository.getRegister(any(AttendanceRegisterSearchCriteria.class))).thenReturn(registers); + CustomException exception = assertThrows(CustomException.class, ()->attendanceServiceValidator.validateCreateAttendanceRegister(attendanceRegisterRequest)); + assertTrue(exception.getCode().equals("REGISTER_ALREADY_EXISTS")); + } + + @Test + public void validateCreateAttendanceRegister_validateCreateAttendanceRegister_3(){ + AttendanceRegisterRequest attendanceRegisterRequest = AttendanceRegisterRequestBuilderTest.builder().withRequestInfo().addGoodRegister().build(); + Object mdmsResponse = AttendeeRequestBuilderTest.getMdmsResponseForValidTenant(); + lenient().when(mdmsUtils.mDMSCall(any(RequestInfo.class), + any(String.class))).thenReturn(mdmsResponse); + List registers = new ArrayList<>(); + when(registerRepository.getRegister(any(AttendanceRegisterSearchCriteria.class))).thenReturn(registers); + attendanceServiceValidator.validateCreateAttendanceRegister(attendanceRegisterRequest); + } + + @DisplayName("Method validateCreateAttendanceRegister: Error code INVALID_TENANT") + @Test + public void validateCreateAttendanceRegister_validateCreateAttendanceRegister_2(){ + AttendanceRegisterRequest attendanceRegisterRequest = AttendanceRegisterRequestBuilderTest.builder().withRequestInfo().addGoodRegister().build(); + Object mdmsResponse = AttendeeRequestBuilderTest.getMdmsResponseForInvalidTenant(); + lenient().when(mdmsUtils.mDMSCall(any(RequestInfo.class), + any(String.class))).thenReturn(mdmsResponse); + CustomException exception = assertThrows(CustomException.class,()->attendanceServiceValidator.validateCreateAttendanceRegister(attendanceRegisterRequest)); + assertTrue(exception.getMessage().contains("INVALID_TENANT")); + } +} diff --git a/health-services/attendance/src/test/java/org/egov/validator/AttendeeServiceValidatorTest.java b/health-services/attendance/src/test/java/org/egov/validator/AttendeeServiceValidatorTest.java new file mode 100644 index 00000000000..6cfca07e9e8 --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/validator/AttendeeServiceValidatorTest.java @@ -0,0 +1,177 @@ +package org.egov.validator; + + +import lombok.extern.slf4j.Slf4j; +import org.egov.common.contract.request.RequestInfo; +import org.egov.helper.AttendanceRegisterBuilderTest; +import org.egov.helper.AttendeeRequestBuilderTest; +import org.egov.tracer.model.CustomException; +import org.egov.util.MDMSUtils; +import org.egov.web.models.AttendanceRegister; +import org.egov.web.models.AttendeeCreateRequest; +import org.egov.web.models.IndividualEntry; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.math.BigDecimal; +import java.util.Collections; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.when; + +@Slf4j +@ExtendWith(MockitoExtension.class) +public class AttendeeServiceValidatorTest { + + @InjectMocks + private AttendeeServiceValidator attendeeServiceValidator; + + @Mock + private MDMSUtils mdmsUtils; + + + @BeforeEach + void setupBeforeEach() { + Object mdmsResponse = AttendeeRequestBuilderTest.getMdmsResponseForValidTenant(); + lenient().when(mdmsUtils.mDMSCall(any(RequestInfo.class), + any(String.class))).thenReturn(mdmsResponse); + } + + @DisplayName("attendees is null in attendee request") + @Test + void shouldThrowExceptionWhenAttendeesIsNull_InAttendeeRequest() { + + AttendeeCreateRequest attendeeCreateRequest = AttendeeRequestBuilderTest.getAttendeeCreateRequest(); + attendeeCreateRequest.setAttendees(null); + + assertThrows(CustomException.class, () -> attendeeServiceValidator.validateAttendeeCreateRequestParameters(attendeeCreateRequest)); + } + + @DisplayName("register id is null in attendee request") + @Test + void shouldThrowExceptionWhenRegisterIdIsNull_InAttendeeRequest() { + + IndividualEntry attendee = IndividualEntry.builder().tenantId("pb.amritsar").id("047dc725-3088-45b4-877a-6bfbaf377df9") + .individualId("8ybdd-3rdh3").registerId("").enrollmentDate(new BigDecimal("1672129633890")) + .denrollmentDate(new BigDecimal("1676073600000")).build(); + + AttendeeCreateRequest attendeeCreateRequest = AttendeeRequestBuilderTest.getAttendeeCreateRequest(); + attendeeCreateRequest.setAttendees(Collections.singletonList(attendee)); + + assertThrows(CustomException.class, () -> attendeeServiceValidator.validateAttendeeCreateRequestParameters(attendeeCreateRequest)); + } + + @DisplayName("individual id is null in attendee request") + @Test + void shouldThrowExceptionWhenIndividualIdIsNull_InAttendeeRequest() { + + IndividualEntry attendee = IndividualEntry.builder().tenantId("pb.amritsar").id("047dc725-3088-45b4-877a-6bfbaf377df9") + .individualId("").registerId("97ed7da3-753e-426a-b0b0-95dd61029785").enrollmentDate(new BigDecimal("1672129633890")) + .denrollmentDate(new BigDecimal("1676073600000")).build(); + + AttendeeCreateRequest attendeeCreateRequest = AttendeeRequestBuilderTest.getAttendeeCreateRequest(); + attendeeCreateRequest.setAttendees(Collections.singletonList(attendee)); + + assertThrows(CustomException.class, () -> attendeeServiceValidator.validateAttendeeCreateRequestParameters(attendeeCreateRequest)); + } + + @DisplayName("tenantId is null in attendee request") + @Test + void shouldThrowExceptionWhenTenantIdIsNull_InAttendeeRequest() { + + IndividualEntry attendee = IndividualEntry.builder().tenantId("").id("047dc725-3088-45b4-877a-6bfbaf377df9") + .individualId("8ybdd-3rdh3").registerId("97ed7da3-753e-426a-b0b0-95dd61029785").enrollmentDate(new BigDecimal("1672129633890")) + .denrollmentDate(new BigDecimal("1676073600000")).build(); + + AttendeeCreateRequest attendeeCreateRequest = AttendeeRequestBuilderTest.getAttendeeCreateRequest(); + attendeeCreateRequest.setAttendees(Collections.singletonList(attendee)); + + assertThrows(CustomException.class, () -> attendeeServiceValidator.validateAttendeeCreateRequestParameters(attendeeCreateRequest)); + } + + @DisplayName("tenantId is same for all attendees in the attendee request") + @Test + void shouldThrowExceptionWhenTenantIdsAreNotSame_InAttendeeRequest() { + + AttendeeCreateRequest attendeeCreateRequest = AttendeeRequestBuilderTest.getAttendeeCreateRequest(); + attendeeCreateRequest.getAttendees().get(0).setTenantId("od"); + + assertThrows(CustomException.class, () -> attendeeServiceValidator.validateAttendeeCreateRequestParameters(attendeeCreateRequest)); + } + + @DisplayName("verify tenantId with mdms when tenantId is present in mdms") + @Test + void shouldNotThrowExceptionWhenTenantIdPresent_InMDMS() { + + AttendeeCreateRequest attendeeCreateRequest = AttendeeRequestBuilderTest.getAttendeeCreateRequest(); + + assertDoesNotThrow(() -> attendeeServiceValidator.validateMDMSAndRequestInfoForCreateAttendee(attendeeCreateRequest)); + } + + @DisplayName("verify tenantId with mdms when tenantId is not present in mdms") + @Test + void shouldThrowExceptionWhenTenantIdNotPresent_InMDMS() { + + AttendeeCreateRequest attendeeCreateRequest = AttendeeRequestBuilderTest.getAttendeeCreateRequest(); + attendeeCreateRequest.getAttendees().get(0).setTenantId("od.odisha"); + + Object mdmsResponse = AttendeeRequestBuilderTest.getMdmsResponseForInvalidTenant(); + when(mdmsUtils.mDMSCall(any(RequestInfo.class), + any(String.class))).thenReturn(mdmsResponse); + + assertThrows(CustomException.class, () -> attendeeServiceValidator.validateMDMSAndRequestInfoForCreateAttendee(attendeeCreateRequest)); + } + + //tests for create attendee validation + + @DisplayName("attendee cannot be added to register if register's end date has passed") + @Test + void shouldThrowExceptionWhenRegisterEndDateHasPassed() { + + AttendeeCreateRequest attendeeCreateRequest = AttendeeRequestBuilderTest.getAttendeeCreateRequest(); + AttendanceRegister attendanceRegister = AttendanceRegisterBuilderTest.getAttendanceRegister(); + List attendees = attendanceRegister.getAttendees(); + + attendanceRegister.setEndDate(new BigDecimal("1578728218000")); //set a past date + + assertThrows(CustomException.class, () -> attendeeServiceValidator + .validateAttendeeOnCreate(attendeeCreateRequest, attendees, Collections.singletonList(attendanceRegister))); + } + + @DisplayName("attendee enrollment date should be after start date and before end date of register") + @Test + void shouldThrowExceptionWhenEnrollmentDateIsBeforeStartDateOfRegister() { + + AttendeeCreateRequest attendeeCreateRequest = AttendeeRequestBuilderTest.getAttendeeCreateRequest(); + AttendanceRegister attendanceRegister = AttendanceRegisterBuilderTest.getAttendanceRegister(); + List attendees = attendanceRegister.getAttendees(); + + attendeeCreateRequest.getAttendees().get(0).setEnrollmentDate(new BigDecimal("1673422618000")); + + assertThrows(CustomException.class, () -> attendeeServiceValidator + .validateAttendeeOnCreate(attendeeCreateRequest, attendees, Collections.singletonList(attendanceRegister))); + } + + @DisplayName("check if attendee is already enrolled to the register") + @Test + void shouldThrowExceptionWhenAttendeeAlreadyEnrolledToRegister() { + + AttendeeCreateRequest attendeeCreateRequest = AttendeeRequestBuilderTest.getAttendeeCreateRequest(); + AttendanceRegister attendanceRegister = AttendanceRegisterBuilderTest.getAttendanceRegister(); + List attendees = attendanceRegister.getAttendees(); + + assertThrows(CustomException.class, () -> attendeeServiceValidator + .validateAttendeeOnCreate(attendeeCreateRequest, attendees, Collections.singletonList(attendanceRegister))); + + } + +} diff --git a/health-services/attendance/src/test/java/org/egov/validator/StaffServiceValidatorTest.java b/health-services/attendance/src/test/java/org/egov/validator/StaffServiceValidatorTest.java new file mode 100644 index 00000000000..073f70199df --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/validator/StaffServiceValidatorTest.java @@ -0,0 +1,172 @@ +package org.egov.validator; + +import lombok.extern.slf4j.Slf4j; +import org.egov.common.contract.request.RequestInfo; +import org.egov.helper.AttendanceRegisterBuilderTest; +import org.egov.helper.AttendeeRequestBuilderTest; +import org.egov.helper.StaffRequestBuilderTest; +import org.egov.service.AttendanceRegisterService; +import org.egov.tracer.model.CustomException; +import org.egov.util.MDMSUtils; +import org.egov.web.models.AttendanceRegister; +import org.egov.web.models.StaffPermission; +import org.egov.web.models.StaffPermissionRequest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.math.BigDecimal; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.when; + +@Slf4j +@ExtendWith(MockitoExtension.class) +public class StaffServiceValidatorTest { + + @Mock + private MDMSUtils mdmsUtils; + + @Mock + private AttendanceRegisterService attendanceRegisterService; + + @InjectMocks + private StaffServiceValidator staffServiceValidator; + + @BeforeEach + void setupBeforeEach() { + Object mdmsResponse = AttendeeRequestBuilderTest.getMdmsResponseForValidTenant(); + lenient().when(mdmsUtils.mDMSCall(any(RequestInfo.class), + any(String.class))).thenReturn(mdmsResponse); + } + + + //validate staff request parameters + @DisplayName("staff is null in staff Permission request") + @Test + void shouldThrowExceptionWhenStaffIsNull_InStaffPermissionRequest() { + + StaffPermissionRequest staffPermissionRequest = StaffRequestBuilderTest.getStaffPermissionRequest(); + staffPermissionRequest.setStaff(null); + + assertThrows(CustomException.class, () -> staffServiceValidator.validateStaffPermissionRequestParameters(staffPermissionRequest)); + } + + @DisplayName("register id is null in staff Permission request") + @Test + void shouldThrowExceptionWhenRegisterIdIsNull_InStaffPermissionRequest() { + + StaffPermissionRequest staffPermissionRequest = StaffRequestBuilderTest.getStaffPermissionRequest(); + staffPermissionRequest.getStaff().get(0).setRegisterId(null); + + assertThrows(CustomException.class, () -> staffServiceValidator.validateStaffPermissionRequestParameters(staffPermissionRequest)); + } + + @DisplayName("tenant id is null in staff Permission request") + @Test + void shouldThrowExceptionWhenTenantIdIsNull_InStaffPermissionRequest() { + + StaffPermissionRequest staffPermissionRequest = StaffRequestBuilderTest.getStaffPermissionRequest(); + staffPermissionRequest.getStaff().get(0).setTenantId(null); + + assertThrows(CustomException.class, () -> staffServiceValidator.validateStaffPermissionRequestParameters(staffPermissionRequest)); + } + + @DisplayName("All staff must have same tenant id in staff Permission request") + @Test + void shouldThrowExceptionWhenTenantIdIsNotSame_InStaffPermissionRequest() { + + StaffPermissionRequest staffPermissionRequest = StaffRequestBuilderTest.getStaffPermissionRequest(); + staffPermissionRequest.getStaff().get(0).setTenantId("od"); + + assertThrows(CustomException.class, () -> staffServiceValidator.validateStaffPermissionRequestParameters(staffPermissionRequest)); + } + + @DisplayName("Duplicate staff objects in staff Permission request") + @Test + void shouldThrowExceptionWhenDuplicateStaffIsPresent_InStaffPermissionRequest() { + + StaffPermission staffOne = StaffPermission.builder().id("03901adb-07c3-4539-9346-4ee5c87e5e1c").userId("8ybdd-3rdhd") + .registerId("97ed7da3-753e-426a-b0b0-95dd61029785").tenantId("pb.amritsar").enrollmentDate(new BigDecimal("1670421853937")) + .denrollmentDate(null).build(); + + StaffPermissionRequest staffPermissionRequest = StaffRequestBuilderTest.getStaffPermissionRequest(); + staffPermissionRequest.getStaff().set(1, staffOne); + + assertThrows(CustomException.class, () -> staffServiceValidator.validateStaffPermissionRequestParameters(staffPermissionRequest)); + } + + + //validate tenant id with mdms + @DisplayName("verify tenantId with mdms when tenantId is present in mdms") + @Test + void shouldNotThrowExceptionWhenTenantIdPresent_InMDMS() { + + StaffPermissionRequest staffPermissionRequest = StaffRequestBuilderTest.getStaffPermissionRequest(); + + assertDoesNotThrow(() -> staffServiceValidator.validateMDMSAndRequestInfoForStaff(staffPermissionRequest)); + } + + @DisplayName("verify tenantId with mdms when tenantId is not present in mdms") + @Test + void shouldThrowExceptionWhenTenantIdNotPresent_InMDMS() { + + StaffPermissionRequest staffPermissionRequest = StaffRequestBuilderTest.getStaffPermissionRequest(); + staffPermissionRequest.getStaff().get(0).setTenantId("od.odisha"); + + Object mdmsResponse = AttendeeRequestBuilderTest.getMdmsResponseForInvalidTenant(); + when(mdmsUtils.mDMSCall(any(RequestInfo.class), + any(String.class))).thenReturn(mdmsResponse); + + assertThrows(CustomException.class, () -> staffServiceValidator.validateMDMSAndRequestInfoForStaff(staffPermissionRequest)); + } + + //check if staff tenant id is same as register tenant id + @DisplayName("check if staff tenant id is same as register tenant id") + @Test + void shouldThrowExceptionWhenStaffTenantIdNotSameAsRegisterTenantId() { + + StaffPermissionRequest staffPermissionRequest = StaffRequestBuilderTest.getStaffPermissionRequest(); + List staffPermissionList = AttendanceRegisterBuilderTest.getStaff(); + List attendanceRegisterList = AttendanceRegisterBuilderTest.getAttendanceRegisterList(); + + attendanceRegisterList.get(0).setTenantId("od.odisha"); + + assertThrows(CustomException.class, () -> staffServiceValidator.validateStaffPermissionOnCreate(staffPermissionRequest, staffPermissionList, attendanceRegisterList)); + } + + @DisplayName("check if register end date has passed") + @Test + void shouldThrowExceptionIfRegisterEndDateHasPassed() { + + StaffPermissionRequest staffPermissionRequest = StaffRequestBuilderTest.getStaffPermissionRequest(); + List staffPermissionList = AttendanceRegisterBuilderTest.getStaff(); + List attendanceRegisterList = AttendanceRegisterBuilderTest.getAttendanceRegisterList(); + + attendanceRegisterList.get(0).setEndDate(new BigDecimal("1547733538000")); + + assertThrows(CustomException.class, () -> staffServiceValidator.validateStaffPermissionOnCreate(staffPermissionRequest, staffPermissionList, attendanceRegisterList)); + } + + @DisplayName("check if staff is already enrolled to the given register") + @Test + void shouldThrowExceptionIfStaffIsAlreadyEnrolledToTheRegister() { + + StaffPermissionRequest staffPermissionRequest = StaffRequestBuilderTest.getStaffPermissionRequest(); + List staffPermissionList = AttendanceRegisterBuilderTest.getStaff(); + List attendanceRegisterList = AttendanceRegisterBuilderTest.getAttendanceRegisterList(); + + + assertThrows(CustomException.class, () -> staffServiceValidator.validateStaffPermissionOnCreate(staffPermissionRequest, staffPermissionList, attendanceRegisterList)); + } + + +} diff --git a/health-services/attendance/src/test/java/org/egov/web/controllers/AttendanceApiControllerTest.java b/health-services/attendance/src/test/java/org/egov/web/controllers/AttendanceApiControllerTest.java new file mode 100644 index 00000000000..068c0910681 --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/web/controllers/AttendanceApiControllerTest.java @@ -0,0 +1,126 @@ +package org.egov.web.controllers; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.egov.Main; +import org.egov.TestConfiguration; +import org.egov.common.contract.request.RequestInfo; +import org.egov.common.contract.response.ResponseInfo; +import org.egov.helper.AttendanceRegisterBuilderTest; +import org.egov.helper.AttendanceRegisterRequestBuilderTest; +import org.egov.repository.AttendanceLogRepository; +import org.egov.repository.AttendeeRepository; +import org.egov.repository.RegisterRepository; +import org.egov.repository.StaffRepository; +import org.egov.service.AttendanceRegisterService; +import org.egov.tracer.model.CustomException; +import org.egov.tracer.model.ErrorRes; +import org.egov.util.ResponseInfoFactory; +import org.egov.web.models.AttendanceRegisterRequest; +import org.egov.web.models.AttendanceRegisterResponse; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; +import org.springframework.http.MediaType; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; + +import javax.servlet.http.HttpServletRequest; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +/** + * API tests for AttendanceApiController + */ +@ContextConfiguration(classes = Main.class) +@WebMvcTest(AttendanceApiController.class) +@Import(TestConfiguration.class) +@AutoConfigureMockMvc +public class AttendanceApiControllerTest { + + @Autowired + private MockMvc mockMvc; + + @Autowired + private ObjectMapper objectMapper; + + @Autowired + private HttpServletRequest request; + + @MockBean + private ResponseInfoFactory responseInfoFactory; + + @MockBean + private AttendanceLogRepository attendanceLogRepository; + + @MockBean + private AttendanceRegisterService attendanceRegisterService; + + @MockBean + private AttendeeRepository attendeeRepository; + + @MockBean + private RegisterRepository registerRepository; + + @MockBean + private StaffRepository staffRepository; + + @MockBean + private JdbcTemplate jdbcTemplate; + + @Test + @DisplayName("should pass for correct API operation for create attendance register") + public void RegisterCreatePostSuccess() throws Exception { + + AttendanceRegisterRequest attendanceRegisterRequest = AttendanceRegisterRequestBuilderTest.builder().addGoodRegister() + .requestInfoWithoutUserInfo().build(); + ResponseInfo responseInfo = AttendanceRegisterBuilderTest.getResponseInfo_Success(); + + when(attendanceRegisterService.createAttendanceRegister(any(AttendanceRegisterRequest.class))).thenReturn(attendanceRegisterRequest); + when(responseInfoFactory.createResponseInfoFromRequestInfo(any(RequestInfo.class), eq(true))).thenReturn(responseInfo); + + ObjectMapper objectMapper = new ObjectMapper(); + String content = objectMapper.writeValueAsString(attendanceRegisterRequest); + MvcResult result = mockMvc.perform(post("/v1/_create").contentType(MediaType + .APPLICATION_JSON).content(content)) + .andExpect(status().isOk()).andReturn(); + String responseStr = result.getResponse().getContentAsString(); + + AttendanceRegisterResponse response = objectMapper.readValue(responseStr, AttendanceRegisterResponse.class); + + assertEquals("successful", response.getResponseInfo().getStatus()); + + } + + @Test + @DisplayName("should fail for incomplete attendance register object in API request") + public void RegisterCreatePostFailure() throws Exception { + + AttendanceRegisterRequest attendanceRegisterRequest = AttendanceRegisterRequestBuilderTest.builder().attendanceRegisterWithoutStartDate() + .withRequestInfo().build(); + + when(attendanceRegisterService.createAttendanceRegister(any(AttendanceRegisterRequest.class))) + .thenThrow(new CustomException("START_DATE", "Start date is mandatory")); + + ObjectMapper objectMapper = new ObjectMapper(); + String content = objectMapper.writeValueAsString(attendanceRegisterRequest); + MvcResult result = mockMvc.perform(post("/v1/_create").contentType(MediaType.APPLICATION_JSON).content(content)) + .andExpect(status().isBadRequest()).andReturn(); + + String responseStr = result.getResponse().getContentAsString(); + ErrorRes response = objectMapper.readValue(responseStr, + ErrorRes.class); + + assertEquals("Start date is mandatory", response.getErrors().get(0).getMessage()); + } +} diff --git a/health-services/attendance/src/test/java/org/egov/web/controllers/AttendanceLogApiControllerTest.java b/health-services/attendance/src/test/java/org/egov/web/controllers/AttendanceLogApiControllerTest.java new file mode 100644 index 00000000000..6fd284bce9f --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/web/controllers/AttendanceLogApiControllerTest.java @@ -0,0 +1,96 @@ +package org.egov.web.controllers; + +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.egov.Main; +import org.egov.TestConfiguration; +import org.egov.common.contract.response.ResponseInfo; +import org.egov.helper.AttendanceLogRequestTestBuilder; +import org.egov.common.producer.Producer; +import org.egov.repository.AttendanceLogRepository; +import org.egov.service.AttendanceLogService; +import org.egov.util.ResponseInfoFactory; +import org.egov.web.models.AttendanceLogRequest; +import org.egov.web.models.AttendanceLogResponse; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.DisplayName; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.http.MediaType; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.when; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + + + +@ContextConfiguration(classes = Main.class) +@WebMvcTest(AttendanceLogApiController.class) +@Import(TestConfiguration.class) +@AutoConfigureMockMvc + +public class AttendanceLogApiControllerTest { + @Autowired + private MockMvc mockMvc; + + @Autowired + private ObjectMapper objectMapper; + + @MockBean + private AttendanceLogService attendanceLogService; + + @MockBean + private ResponseInfoFactory responseInfoFactory; + + @MockBean + private Producer producer; + + @MockBean + private AttendanceLogRepository attendanceLogRepository; + + @MockBean + private JdbcTemplate jdbcTemplate; + + + @DisplayName("attendance log request should pass and create attendance log") + @Test + public void attendanceLogV1CreatePOSTSuccess() throws Exception{ + AttendanceLogRequest attendanceLogRequest = AttendanceLogRequestTestBuilder.builder().withRequestInfo().addGoodAttendanceLog().build(); + + ResponseInfo responseInfo = ResponseInfo.builder() + .apiId(attendanceLogRequest.getRequestInfo().getApiId()) + .ver(attendanceLogRequest.getRequestInfo().getVer()) + .ts(attendanceLogRequest.getRequestInfo().getTs()) + .resMsgId("uief87324") + .msgId(attendanceLogRequest.getRequestInfo().getMsgId()) + .status("successful").build(); + + AttendanceLogResponse attendanceLogResponse = AttendanceLogResponse.builder().responseInfo(responseInfo).attendance(attendanceLogRequest.getAttendance()).build(); + + + when(attendanceLogService.createAttendanceLog(any(AttendanceLogRequest.class))).thenReturn(attendanceLogResponse); + + MvcResult result = mockMvc.perform(post("/log/v1/_create").contentType(MediaType + .APPLICATION_JSON).content(objectMapper.writeValueAsString(attendanceLogRequest))) + .andExpect(status().isOk()).andReturn(); + + String responseStr = result.getResponse().getContentAsString(); + AttendanceLogResponse response = objectMapper.readValue(responseStr, + AttendanceLogResponse.class); + + assertEquals(1, response.getAttendance().size()); + assertNotNull(response.getAttendance().get(0).getId()); + assertEquals("successful", response.getResponseInfo().getStatus()); + } +} diff --git a/health-services/attendance/src/test/java/org/egov/web/controllers/AttendeeApiControllerTest.java b/health-services/attendance/src/test/java/org/egov/web/controllers/AttendeeApiControllerTest.java new file mode 100644 index 00000000000..12a219df83e --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/web/controllers/AttendeeApiControllerTest.java @@ -0,0 +1,130 @@ +package org.egov.web.controllers; + +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.egov.Main; +import org.egov.TestConfiguration; +import org.egov.common.contract.request.RequestInfo; +import org.egov.common.contract.response.ResponseInfo; +import org.egov.enrichment.StaffEnrichmentService; +import org.egov.helper.AttendeeRequestBuilderTest; +import org.egov.repository.AttendanceLogRepository; +import org.egov.repository.AttendeeRepository; +import org.egov.repository.RegisterRepository; +import org.egov.repository.StaffRepository; +import org.egov.service.AttendanceRegisterService; +import org.egov.service.AttendeeService; +import org.egov.service.StaffService; +import org.egov.tracer.model.CustomException; +import org.egov.tracer.model.ErrorRes; +import org.egov.util.ResponseInfoFactory; +import org.egov.web.models.AttendeeCreateRequest; +import org.egov.web.models.AttendeeCreateResponse; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.web.client.HttpStatusCodeException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@ContextConfiguration(classes=Main.class) +@WebMvcTest(AttendeeApiController.class) +@Import({TestConfiguration.class}) +//@SpringBootTest(classes = Main.class) +@AutoConfigureMockMvc +public class AttendeeApiControllerTest { + @Autowired + private MockMvc mockMvc; + + @Autowired + private ObjectMapper objectMapper; + + @MockBean + private AttendeeService attendeeService; + @MockBean + private ResponseInfoFactory responseInfoFactory; + + @MockBean + private AttendeeRepository attendeeRepository; + + @MockBean + private StaffEnrichmentService staffEnrichmentService; + + @MockBean + private AttendanceRegisterService attendanceRegisterService; + + @MockBean + private StaffRepository staffRepository; + + @MockBean + private StaffService staffService; + + @MockBean + private AttendanceLogRepository attendanceLogRepository; + + @MockBean + private RegisterRepository registerRepository; + + + @Test + @DisplayName("should pass for correct API operation") + public void attendeeCreatePostSuccess() throws Exception { + + AttendeeCreateRequest attendeeCreateRequest = AttendeeRequestBuilderTest.getAttendeeCreateRequest(); + ResponseInfo responseInfo = AttendeeRequestBuilderTest.getResponseInfo_Success(); + + when(attendeeService.createAttendee(any(AttendeeCreateRequest.class))).thenReturn(attendeeCreateRequest); + when(responseInfoFactory.createResponseInfoFromRequestInfo(any(RequestInfo.class), eq(true))).thenReturn(responseInfo); + + ObjectMapper objectMapper = new ObjectMapper(); + String content = objectMapper.writeValueAsString(attendeeCreateRequest); + MvcResult result = mockMvc.perform(post("/attendee/v1/_create").contentType(MediaType + .APPLICATION_JSON).content(content)) + .andExpect(status().isOk()).andReturn(); + String responseStr = result.getResponse().getContentAsString(); + + AttendeeCreateResponse response = objectMapper.readValue(responseStr, AttendeeCreateResponse.class); + + assertEquals("successful", response.getResponseInfo().getStatus()); + + } + + @Test + @DisplayName("should fail for incomplete attendee object in API request") + public void attendeeCreatePostFailure() throws Exception { + + AttendeeCreateRequest attendeeCreateRequest = AttendeeRequestBuilderTest.getAttendeeCreateRequest(); + + attendeeCreateRequest.getAttendees().get(0).setIndividualId(null); + + when(attendeeService.createAttendee(any(AttendeeCreateRequest.class))).thenThrow(new CustomException("ATTENDEE", "ATTENDEE is mandatory")); + + ObjectMapper objectMapper = new ObjectMapper(); + String content = objectMapper.writeValueAsString(attendeeCreateRequest); + MvcResult result=mockMvc.perform(post("/attendee/v1/_create").contentType(MediaType + .APPLICATION_JSON).content(content)) + .andExpect(status().isBadRequest()).andReturn(); + + String responseStr = result.getResponse().getContentAsString(); + ErrorRes response = objectMapper.readValue(responseStr, + ErrorRes.class); + + assertEquals("ATTENDEE is mandatory",response.getErrors().get(0).getMessage()); + } + +} diff --git a/health-services/attendance/src/test/java/org/egov/web/controllers/StaffApiControllerTest.java b/health-services/attendance/src/test/java/org/egov/web/controllers/StaffApiControllerTest.java new file mode 100644 index 00000000000..971aea08f43 --- /dev/null +++ b/health-services/attendance/src/test/java/org/egov/web/controllers/StaffApiControllerTest.java @@ -0,0 +1,110 @@ +package org.egov.web.controllers; + +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.egov.Main; +import org.egov.TestConfiguration; +import org.egov.common.contract.request.RequestInfo; +import org.egov.common.contract.response.ResponseInfo; +import org.egov.helper.StaffRequestBuilderTest; +import org.egov.repository.AttendanceLogRepository; +import org.egov.service.StaffService; +import org.egov.tracer.model.CustomException; +import org.egov.tracer.model.ErrorRes; +import org.egov.util.ResponseInfoFactory; +import org.egov.web.models.StaffPermissionRequest; +import org.egov.web.models.StaffPermissionResponse; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; +import org.springframework.http.MediaType; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; + +import javax.servlet.http.HttpServletRequest; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@ContextConfiguration(classes = Main.class) +@WebMvcTest(StaffApiController.class) +@Import(TestConfiguration.class) +@AutoConfigureMockMvc +public class StaffApiControllerTest { + + @Autowired + private MockMvc mockMvc; + + @Autowired + private ObjectMapper objectMapper; + + @Autowired + private HttpServletRequest request; + + @MockBean + private ResponseInfoFactory responseInfoFactory; + + @MockBean + private StaffService staffService; + + @MockBean + private AttendanceLogRepository attendanceLogRepository; + + @MockBean + private JdbcTemplate jdbcTemplate; + + @Test + @DisplayName("should pass for correct API operation") + public void staffCreatePostSuccess() throws Exception { + + StaffPermissionRequest staffPermissionRequest = StaffRequestBuilderTest.getStaffPermissionRequest(); + ResponseInfo responseInfo = StaffRequestBuilderTest.getResponseInfo_Success(); + + when(staffService.createAttendanceStaff(any(StaffPermissionRequest.class), eq(false))).thenReturn(staffPermissionRequest); + when(responseInfoFactory.createResponseInfoFromRequestInfo(any(RequestInfo.class), eq(true))).thenReturn(responseInfo); + + ObjectMapper objectMapper = new ObjectMapper(); + String content = objectMapper.writeValueAsString(staffPermissionRequest); + MvcResult result = mockMvc.perform(post("/staff/v1/_create").contentType(MediaType + .APPLICATION_JSON).content(content)) + .andExpect(status().isOk()).andReturn(); + String responseStr = result.getResponse().getContentAsString(); + + StaffPermissionResponse response = objectMapper.readValue(responseStr, StaffPermissionResponse.class); + + assertEquals("successful", response.getResponseInfo().getStatus()); + + } + + @Test + @DisplayName("should fail for incomplete staff object in API request") + public void staffCreatePostFailure() throws Exception { + + StaffPermissionRequest staffPermissionRequest = StaffRequestBuilderTest.getStaffPermissionRequest(); + staffPermissionRequest.setStaff(null); + + when(staffService.createAttendanceStaff(any(StaffPermissionRequest.class), eq(false))).thenThrow(new CustomException("STAFF", "Staff is mandatory")); + + ObjectMapper objectMapper = new ObjectMapper(); + String content = objectMapper.writeValueAsString(staffPermissionRequest); + MvcResult result=mockMvc.perform(post("/staff/v1/_create").contentType(MediaType.APPLICATION_JSON).content(content)) + .andExpect(status().isBadRequest()).andReturn(); + + String responseStr = result.getResponse().getContentAsString(); + ErrorRes response = objectMapper.readValue(responseStr, + ErrorRes.class); + + assertEquals("Staff is mandatory",response.getErrors().get(0).getMessage()); + } +} diff --git a/health-services/attendance/src/test/resources/AttendeeCreateRequest.json b/health-services/attendance/src/test/resources/AttendeeCreateRequest.json new file mode 100644 index 00000000000..e69de29bb2d diff --git a/health-services/attendance/src/test/resources/InvalidTenantMDMSData.json b/health-services/attendance/src/test/resources/InvalidTenantMDMSData.json new file mode 100644 index 00000000000..d510372f9e1 --- /dev/null +++ b/health-services/attendance/src/test/resources/InvalidTenantMDMSData.json @@ -0,0 +1,8 @@ +{ + "ResponseInfo": null, + "MdmsRes": { + "tenant": { + "tenants": [] + } + } +} \ No newline at end of file diff --git a/health-services/attendance/src/test/resources/TenantMDMSData.json b/health-services/attendance/src/test/resources/TenantMDMSData.json new file mode 100644 index 00000000000..a28cc965f7e --- /dev/null +++ b/health-services/attendance/src/test/resources/TenantMDMSData.json @@ -0,0 +1,402 @@ +{ + "ResponseInfo": null, + "MdmsRes": { + "tenant": { + "tenants": [ + { + "code": "pb", + "name": "Punjab", + "description": "Punjab", + "logoId": "https://s3.ap-south-1.amazonaws.com/pb-egov-assets/pb.jalandhar/logo.png", + "imageId": "https://s3.ap-south-1.amazonaws.com/pb-egov-assets/pb.jalandhar/logo.png", + "domainUrl": "www.mcjalandhar.in", + "type": "CITY", + "twitterUrl": "https://twitter.com/search?q=%23jalandhar", + "facebookUrl": "https://www.facebook.com/city/jalandhar-Punjab", + "emailId": "complaints.mcj@gmail.com", + "OfficeTimings": { + "Mon - Fri": "9.00 AM - 6.00 PM" + }, + "city": { + "name": "Punjab", + "localName": "Punjab", + "districtCode": "0", + "districtName": "Punjab", + "districtTenantCode": "pb.punjab", + "regionName": "Punjab", + "ulbGrade": "ST", + "longitude": 75.3412, + "latitude": 31.1471, + "shapeFileLocation": null, + "captcha": null, + "code": "0", + "ddrName": null + }, + "address": "5 Punjab Municipal Bhawan, 3, Dakshin Marg, 35A, Sector 35A, Chandigarh, 160022", + "pincode": [], + "contactNumber": "0181-2227015", + "pdfHeader": "PB_PDF_HEADER", + "pdfContactDetails": "PB_CONTACT_DETAILS" + }, + { + "code": "pb.jalandhar", + "name": "Jalandhar", + "description": "Jalandhar", + "logoId": "", + "imageId": "", + "domainUrl": "www.mcjalandhar.in", + "type": "CITY", + "twitterUrl": "https://twitter.com/search?q=%23jalandhar", + "facebookUrl": "https://www.facebook.com/city/jalandhar-Punjab", + "emailId": "complaints.mcj@gmail.com", + "OfficeTimings": { + "Mon - Fri": "9.00 AM - 6.00 PM" + }, + "city": { + "name": "Jalandhar", + "localName": "Janlandhar", + "districtCode": "10", + "districtName": "Jalandhar", + "districtTenantCode": "pb.jalandhar", + "regionName": "Jalandhar Region", + "ulbGrade": "Municipal Corporation", + "ulbType": "Municipal Corporation", + "longitude": 75.5761829, + "latitude": 31.3260152, + "shapeFileLocation": null, + "captcha": null, + "code": "1013", + "regionCode": "4", + "municipalityName": "Janlandhar", + "ddrName": "Jalandhar-MC" + }, + "address": "Municipal Corporation Office, Dr. B.R.Ambedkar Admin Complex, Nehru Garden, Jalandhar City-144001", + "pincode": [ + 144001, + 144002, + 144003, + 144004, + 144005, + 144006, + 144007, + 144008, + 144009, + 144010 + ], + "contactNumber": "0181-2227015", + "pdfHeader": "PB_JALANDHAR_PDF_HEADER", + "pdfContactDetails": "PB_JALANDHAR_CONTACT_DETAILS" + }, + { + "code": "pb.phagwara", + "name": "Phagwara", + "description": "Phagwara", + "logoId": "https://s3.ap-south-1.amazonaws.com/pb-egov-assets/pb.phagwara/logo.png", + "imageId": "https://s3.ap-south-1.amazonaws.com/pb-egov-assets/pb.phagwara/logo.png", + "domainUrl": "http://www.mcphagwara.com/index.php", + "type": "CITY", + "twitterUrl": null, + "facebookUrl": null, + "emailId": "comm.mcpgr@punjab.gov.in", + "OfficeTimings": { + "Mon - Fri": "9.00 AM - 6.00 PM" + }, + "city": { + "name": "Phagwara", + "localName": "Phagwara", + "districtCode": "10", + "districtName": "Jalandhar", + "districtTenantCode": "pb.jalandhar", + "regionName": "Jalandhar Region", + "ulbGrade": "Municipal Corporation", + "ulbType": "Municipal Corporation", + "longitude": 75.7708, + "latitude": 31.224, + "shapeFileLocation": null, + "captcha": null, + "code": "1014", + "regionCode": "4", + "municipalityName": "Phagwara", + "ddrName": "Phagwara-MC" + }, + "address": "Town Hall, Phagwara, Punjab - 144401", + "pincode": [ + 144401, + 144402, + 144403 + ], + "contactNumber": "01824-260426", + "pdfHeader": "PB_PHAGWARA_PDF_HEADER", + "pdfContactDetails": "PB_PHAGWARA_CONTACT_DETAILS" + }, + { + "code": "pb.amritsar", + "name": "Amritsar", + "description": null, + "logoId": "https://s3.ap-south-1.amazonaws.com/pb-egov-assets/pb.amritsar/logo.png", + "imageId": "/pb-egov-assets/pb.amritsar/logo.png", + "domainUrl": "www.amritsarcorp.com", + "type": "CITY", + "twitterUrl": "https://twitter.com/search?q=%23AMRITSAR", + "facebookUrl": "https://www.facebook.com/city/Amritsar-Punjab", + "emailId": "cmcasr@gmail.com", + "OfficeTimings": { + "Mon - Fri": "9.00 AM - 6.00 PM", + "Sat": "9.00 AM - 12.00 PM" + }, + "city": { + "name": "Amritsar", + "localName": "Amritsar", + "districtCode": "1", + "districtName": "Amritsar", + "districtTenantCode": "pb.amritsar", + "regionName": "Amritsar Region", + "ulbGrade": "Municipal Corporation", + "ulbType": "Municipal Corporation", + "longitude": 74.8723, + "latitude": 31.634, + "shapeFileLocation": null, + "captcha": null, + "code": "107", + "regionCode": "1", + "municipalityName": "Amritsar", + "ddrName": "Amritsar-MC" + }, + "address": "Municipal Corporation Amritsar, C Block, Ranjit Avenue, Amritsar, Punjab", + "pincode": [ + 143001, + 143002, + 143003, + 143004, + 143005, + 143006, + 143007, + 143008, + 143009, + 143010 + ], + "contactNumber": "0183-2545155", + "helpLineNumber": "0183-2210300", + "pdfHeader": "PB_AMRITSAR_PDF_HEADER", + "pdfContactDetails": "PB_AMRITSAR_CONTACT_DETAILS" + }, + { + "code": "pb.nawanshahr", + "name": "Nawanshahr", + "description": null, + "logoId": "https://s3.ap-south-1.amazonaws.com/pb-egov-assets/pb.nawanshahr/logo.png", + "imageId": "https://s3.ap-south-1.amazonaws.com/pb-egov-assets/pb.nawanshahr/logo.png", + "domainUrl": "www.nawanshahr.com", + "type": "CITY", + "twitterUrl": null, + "facebookUrl": null, + "emailId": "", + "OfficeTimings": { + "Mon - Fri": "9.00 AM - 6.00 PM" + }, + "city": { + "name": "Nawanshahr", + "localName": "Nawanshahr", + "districtCode": "17", + "districtName": "Nawanshar", + "districtTenantCode": "pb.nawanshar", + "regionName": "Jalandhar Region", + "ulbGrade": "MC Class I", + "ulbType": "Municipal Council", + "longitude": 76.0392, + "latitude": 31.0913, + "shapeFileLocation": null, + "captcha": null, + "code": "1703", + "regionCode": "4", + "municipalityName": "SBS Nagar", + "ddrName": "Jalandhar-DDR" + }, + "address": "Committee Bazar", + "pincode": [ + 144513, + 144514, + 144516, + 144517 + ], + "contactNumber": "1823220085", + "helpLineNumber": "", + "pdfHeader": "PB_NAWANSHAHR_PDF_HEADER", + "pdfContactDetails": "PB_NAWANSHAHR_CONTACT_DETAILS" + }, + { + "code": "pb.mohali", + "name": "Mohali", + "description": "Mohali", + "logoId": "https://s3.ap-south-1.amazonaws.com/pb-egov-assets/pb.mohali/logo.png", + "imageId": "https://s3.ap-south-1.amazonaws.com/pb-egov-assets/pb.mohali/logo.png", + "domainUrl": "www.mcjalandhar.in", + "type": "CITY", + "twitterUrl": "https://twitter.com/search?q=%23mohali", + "facebookUrl": "https://www.facebook.com/city/mohali-Punjab", + "emailId": "complaints.mcj@gmail.com", + "OfficeTimings": { + "Mon - Fri": "9.00 AM - 6.00 PM" + }, + "city": { + "name": "Mohali", + "localName": "Mohali", + "districtCode": "15", + "districtName": "Mohali", + "districtTenantCode": "pb.mohali", + "regionName": "Patiala Region", + "ulbGrade": "Municipal Corporation", + "ulbType": "Municipal Corporation", + "longitude": 76.7179, + "latitude": 30.7046, + "shapeFileLocation": null, + "captcha": null, + "code": "1508", + "regionCode": "6", + "municipalityName": "SAS Nagar", + "ddrName": "Mohali-MC" + }, + "address": "Sector 68, Sahibzada Ajit Singh Nagar, Punjab 160062", + "pincode": [ + 140301, + 140302, + 140303, + 140304, + 140305, + 140306, + 140307 + ], + "contactNumber": "0172-5044907", + "pdfHeader": "PB_MOHALI_PDF_HEADER", + "pdfContactDetails": "PB_MOHALI_CONTACT_DETAILS" + }, + { + "code": "pb.nayagaon", + "name": "Nayagaon", + "description": "Nayagaon", + "logoId": "https://s3.ap-south-1.amazonaws.com/pb-egov-assets/pb.nayagaon/logo.png", + "imageId": null, + "domainUrl": "http://lgpunjab.gov.in/eSewa/nayagaon", + "type": "CITY", + "twitterUrl": null, + "facebookUrl": null, + "emailId": "eonpnayagaon@ymail.com", + "OfficeTimings": { + "Mon - Fri": "9.00 AM - 5.00 PM" + }, + "city": { + "name": "Nayagaon", + "localName": "NayaGaon", + "districtCode": "15", + "districtName": "Mohali", + "districtTenantCode": "pb.mohali", + "regionName": "Patiala Region", + "ulbGrade": "MC Class II", + "ulbType": "Municipal Council", + "longitude": 76.7943, + "latitude": 30.7761, + "shapeFileLocation": null, + "captcha": null, + "code": "1506", + "regionCode": "6", + "municipalityName": "NayaGaon", + "ddrName": "Patiala-DDR" + }, + "address": "Not available", + "pincode": [ + 147001, + 147002, + 147003, + 147004, + 147005 + ], + "contactNumber": "Not available", + "pdfHeader": "PB_NAYAGAON_PDF_HEADER", + "pdfContactDetails": "PB_NAYAGAON_CONTACT_DETAILS" + }, + { + "code": "pb.derabassi", + "name": "Derabassi", + "description": "Derabassi", + "logoId": "https://s3.ap-south-1.amazonaws.com/pb-egov-assets/pb.derabassi/logo.png", + "imageId": null, + "domainUrl": "http://lgpunjab.gov.in/eSewa/derabassi", + "type": "CITY", + "twitterUrl": null, + "facebookUrl": null, + "emailId": "eomcdera@gmail.com", + "OfficeTimings": { + "Mon - Fri": "9.00 AM - 5.00 PM" + }, + "city": { + "name": "Derabassi", + "localName": "DeraBassi", + "districtCode": "15", + "districtName": "Mohali", + "districtTenantCode": "pb.mohali", + "regionName": "Patiala Region", + "ulbGrade": "MC Class I", + "ulbType": "Municipal Council", + "longitude": 76.8433, + "latitude": 30.5964, + "shapeFileLocation": null, + "captcha": null, + "code": "1502", + "regionCode": "6", + "municipalityName": "DerraBassi", + "ddrName": "Patiala-DDR" + }, + "address": "Not available", + "pincode": [ + 140506, + 140507 + ], + "contactNumber": "1762281025", + "pdfHeader": "PB_DERABASSI_PDF_HEADER", + "pdfContactDetails": "PB_DERABASSI_CONTACT_DETAILS" + }, + { + "code": "pb.patiala", + "name": "Patiala", + "description": "Patiala", + "logoId": "http://mseva.lgpunjab.gov.in/pb-egov-assets/pb.patiala/logo.png", + "imageId": null, + "domainUrl": "https://patiala.nic.in/", + "type": "CITY", + "twitterUrl": null, + "facebookUrl": null, + "emailId": "dc.ptl@punjab.gov.in", + "OfficeTimings": { + "Mon - Fri": "9.00 AM - 6.00 PM" + }, + "city": { + "name": "Patiala", + "localName": "Patiala", + "districtCode": "19", + "districtName": "Patiala", + "districtTenantCode": "pb.patiala", + "regionName": "Patiala Region", + "ulbGrade": "Municipal Corporation", + "ulbType": "Municipal Corporation", + "longitude": 76.3869, + "latitude": 30.3398, + "shapeFileLocation": null, + "captcha": null, + "code": "1910", + "regionCode": "6", + "municipalityName": "Patiala", + "ddrName": "Patiala-MC" + }, + "address": "Office of the Deputy Commissioner District Administrative Complex, Patiala-147001", + "contactNumber": "0175-2311300", + "pincode": [ + 140506, + 140507 + ], + "pdfHeader": "PB_PATIALA_PDF_HEADER", + "pdfContactDetails": "PB_PATIALA_CONTACT_DETAILS" + } + ] + } + } +} \ No newline at end of file