Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added miscellaneous purpose application api to book an appointment #551

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public ResponseEntity<MainResponseDTO<ApplicationResponseDTO>> addLostUinApplica
"In pre-registration LostUINController for createNewApplication with json object" + jsonObject);
requestValidator.validateId(LOST_UIN_CREATE_ID, jsonObject.getId(), errors);
DataValidationUtil.validate(errors, LOST_UIN_CREATE_ID);
return ResponseEntity.status(HttpStatus.OK).body(applicationService.addLostOrUpdateApplication(jsonObject,
return ResponseEntity.status(HttpStatus.OK).body(applicationService.addLostOrUpdateOrMiscellaneousApplication(jsonObject,
BookingTypeCodes.LOST_FORGOTTEN_UIN.toString()));
}

Expand All @@ -104,7 +104,7 @@ public ResponseEntity<MainResponseDTO<DeleteApplicationDTO>> deleteLostUinApplic
@PathVariable("applicationId") String applicationId) {
log.info("sessionId", "idType", "id",
"In pre-registration LostUINController for deleteApplication with preId " + applicationId);
return ResponseEntity.status(HttpStatus.OK).body(applicationService.deleteLostOrUpdateApplication(applicationId,
return ResponseEntity.status(HttpStatus.OK).body(applicationService.deleteLostOrUpdateOrMiscellaneousApplication(applicationId,
BookingTypeCodes.LOST_FORGOTTEN_UIN.toString()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package io.mosip.preregistration.application.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.Errors;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import io.mosip.kernel.core.logger.spi.Logger;
import io.mosip.preregistration.application.dto.ApplicationResponseDTO;
import io.mosip.preregistration.application.dto.DeleteApplicationDTO;
import io.mosip.preregistration.application.dto.MiscApplicationRequestDTO;
import io.mosip.preregistration.application.service.ApplicationServiceIntf;
import io.mosip.preregistration.core.code.BookingTypeCodes;
import io.mosip.preregistration.core.common.dto.MainRequestDTO;
import io.mosip.preregistration.core.common.dto.MainResponseDTO;
import io.mosip.preregistration.core.config.LoggerConfiguration;
import io.mosip.preregistration.core.util.DataValidationUtil;
import io.mosip.preregistration.core.util.RequestValidator;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import springfox.documentation.annotations.ApiIgnore;

/**
* Pre-registration miscellaneous purpose controller class.
*
* @author Ritik Jain
*/
@RestController
@Tag(name = "miscellaneous-appointment-controller", description = "Miscellaneous Appointment Controller")
public class MiscellaneousAppointmentController {

private Logger log = LoggerConfiguration.logConfig(MiscellaneousAppointmentController.class);

/** The Constant CREATE_MISCELLANEOUS_PURPOSE application. */
private static final String MISCELLANEOUS_PURPOSE_CREATE_ID = "preregistration.miscellaneouspurpose.create";

@Autowired
private RequestValidator requestValidator;

@Autowired
ApplicationServiceIntf applicationService;

/**
* Inits the binder.
*
* @param binder the binder
*/
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.addValidators(requestValidator);
}

/**
* This Post API is use to create a new application with booking type as
* MISCELLANEOUS_PURPOSE
*
* @param jsonObject
* @param errors
* @return List of response dto containing pre-id and group-id
*/
@PreAuthorize("hasAnyRole(@authorizedRoles.getPostapplications())")
@PostMapping(path = "/applications/miscpurpose", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "addMiscellaneousPurposeApplication", description = "Creates a new application with Booking Type as MISCELLANEOUS_PURPOSE", tags = "miscellaneous-appointment-controller")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "New application with booking type as MISCELLANEOUS_PURPOSE successfully Created"),
@ApiResponse(responseCode = "201", description = "Created", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(schema = @Schema(hidden = true))) })
public ResponseEntity<MainResponseDTO<ApplicationResponseDTO>> addMiscellaneousPurposeApplication(
@Validated @RequestBody(required = true) MainRequestDTO<MiscApplicationRequestDTO> jsonObject,
@ApiIgnore Errors errors) {
log.info("sessionId", "idType", "id",
"In pre-registration MiscellaneousAppointmentController for createNewApplication with json object"
+ jsonObject);
String purpose = jsonObject.getRequest().getPurpose();
requestValidator.validatePurpose(purpose, errors);
requestValidator.validateId(MISCELLANEOUS_PURPOSE_CREATE_ID, jsonObject.getId(), errors);
DataValidationUtil.validate(errors, MISCELLANEOUS_PURPOSE_CREATE_ID);
return ResponseEntity.status(HttpStatus.OK).body(applicationService.addLostOrUpdateOrMiscellaneousApplication(
jsonObject, BookingTypeCodes.MISCELLANEOUS_PURPOSE.toString() + "-" + purpose));
}

/**
* This method is used to delete the application with booking type as
* MISCELLANEOUS_PURPOSE
*
* @param applicationId
* @return the deletion status of application for a applicationId
*/
@PreAuthorize("hasAnyRole(@authorizedRoles.getDeleteapplications())")
@DeleteMapping(path = "/applications/miscpurpose/{applicationId}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "deleteMiscellaneousPurposeApplication", description = "Delete application with booking type MISCELLANEOUS_PURPOSE.", tags = "miscellaneous-appointment-controller")
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Deletion of application is successful"),
@ApiResponse(responseCode = "204", description = "No Content"),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true))), })
public ResponseEntity<MainResponseDTO<DeleteApplicationDTO>> deleteMiscellaneousPurposeApplication(
@PathVariable("applicationId") String applicationId) {
log.info("sessionId", "idType", "id",
"In pre-registration MiscellaneousAppointmentController for deleteApplication with preId "
+ applicationId);
return ResponseEntity.status(HttpStatus.OK)
.body(applicationService.deleteLostOrUpdateOrMiscellaneousApplication(applicationId,
BookingTypeCodes.MISCELLANEOUS_PURPOSE.toString()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public ResponseEntity<MainResponseDTO<ApplicationResponseDTO>> addUpdateRegistra
+ jsonObject);
requestValidator.validateId(UPDATE_REGISTRATION_CREATE_ID, jsonObject.getId(), errors);
DataValidationUtil.validate(errors, UPDATE_REGISTRATION_CREATE_ID);
return ResponseEntity.status(HttpStatus.OK).body(applicationService.addLostOrUpdateApplication(jsonObject,
return ResponseEntity.status(HttpStatus.OK).body(applicationService.addLostOrUpdateOrMiscellaneousApplication(jsonObject,
BookingTypeCodes.UPDATE_REGISTRATION.toString()));
}

Expand All @@ -105,9 +105,9 @@ public ResponseEntity<MainResponseDTO<ApplicationResponseDTO>> addUpdateRegistra
public ResponseEntity<MainResponseDTO<DeleteApplicationDTO>> deleteUpdateRegistration(
@PathVariable("applicationId") String applicationId) {
log.info("sessionId", "idType", "id",
"In pre-registration LostUINController for deleteApplication with preId " + applicationId);
"In pre-registration UpdateRegistrationController for deleteApplication with preId " + applicationId);

return ResponseEntity.status(HttpStatus.OK).body(applicationService.deleteLostOrUpdateApplication(applicationId,
return ResponseEntity.status(HttpStatus.OK).body(applicationService.deleteLostOrUpdateOrMiscellaneousApplication(applicationId,
BookingTypeCodes.UPDATE_REGISTRATION.toString()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ public class ApplicationService implements ApplicationServiceIntf {
*/
@Value("${mosip.id.preregistration.updateregistration.delete}")
private String updateRegistrationDeleteId;

/**
* Reference for ${miscellaneousPurposeDeleteId} from property file
*/
@Value("${mosip.id.preregistration.miscellaneouspurpose.delete}")
private String miscellaneousPurposeDeleteId;

/**
* Autowired reference for {@link #DemographicServiceUtil}
Expand Down Expand Up @@ -269,17 +275,17 @@ public MainResponseDTO<List<ApplicationDetailResponseDTO>> getBookingsForRegCent

/**
* This method is used to create the a new application with booking type as
* UPDATE_REGISTRATION or LOST_FORGOTTEN_UIN
* UPDATE_REGISTRATION or LOST_FORGOTTEN_UIN or MISCELLANEOUS_PURPOSE
*
* @param request
* @param bookingType
* @return MainResponseDTO<ApplicationResponseDTO>
*/
@SuppressWarnings({ "unchecked" })
@Override
public MainResponseDTO<ApplicationResponseDTO> addLostOrUpdateApplication(
MainRequestDTO<ApplicationRequestDTO> request, String bookingType) {
log.info("sessionId", "idType", "id", "In addLostOrUpdateApplication method of pre-registration service ");
public MainResponseDTO<ApplicationResponseDTO> addLostOrUpdateOrMiscellaneousApplication(
MainRequestDTO<? extends ApplicationRequestDTO> request, String bookingType) {
log.info("sessionId", "idType", "id", "In addLostOrUpdateOrMiscellaneousApplication method of pre-registration service ");
log.info("sessionId", "idType", "id",
"Add Application start time : " + DateUtils.getUTCCurrentDateTimeString());
MainResponseDTO<ApplicationResponseDTO> mainResponseDTO = null;
Expand Down Expand Up @@ -312,13 +318,13 @@ public MainResponseDTO<ApplicationResponseDTO> addLostOrUpdateApplication(
} catch (HttpServerErrorException | HttpClientErrorException e) {
log.error("sessionId", "idType", "id", ExceptionUtils.getStackTrace(e));
log.error("sessionId", "idType", "id",
"In pre-registration service of addLostOrUpdateApplication - " + e.getResponseBodyAsString());
"In pre-registration service of addLostOrUpdateOrMiscellaneousApplication - " + e.getResponseBodyAsString());
List<ServiceError> errorList = ExceptionUtils.getServiceErrorList(e.getResponseBodyAsString());
new DemographicExceptionCatcher().handle(new DemographicServiceException(errorList, null), mainResponseDTO);
} catch (Exception ex) {
log.error("sessionId", "idType", "id", ExceptionUtils.getStackTrace(ex));
log.error("sessionId", "idType", "id",
"In pre-registration service of addLostOrUpdateApplication- " + ex.getMessage());
"In pre-registration service of addLostOrUpdateOrMiscellaneousApplication- " + ex.getMessage());
new DemographicExceptionCatcher().handle(ex, mainResponseDTO);
} finally {
if (isSuccess) {
Expand Down Expand Up @@ -363,16 +369,16 @@ public void createAuditValues(String eventId, String eventName, String eventType

/**
* This method is used to delete the application with booking type as
* UPDATE_REGISTRATION or LOST_FORGOTTEN_UIN
* UPDATE_REGISTRATION or LOST_FORGOTTEN_UIN or MISCELLANEOUS_PURPOSE
*
* @param applicationId
* @param bookingType UPDATE_REGISTRATION or LOST_FORGOTTEN_UIN
* @param bookingType UPDATE_REGISTRATION or LOST_FORGOTTEN_UIN or MISCELLANEOUS_PURPOSE
* @return MainResponseDTO<DeleteApplicationDTO>
*/
@Override
public MainResponseDTO<DeleteApplicationDTO> deleteLostOrUpdateApplication(String applicationId,
public MainResponseDTO<DeleteApplicationDTO> deleteLostOrUpdateOrMiscellaneousApplication(String applicationId,
String bookingType) {
log.info("sessionId", "idType", "id", "In deleteLostOrUpdateApplication method of pre-registration service ");
log.info("sessionId", "idType", "id", "In deleteLostOrUpdateOrMiscellaneousApplication method of pre-registration service ");
MainResponseDTO<DeleteApplicationDTO> response = new MainResponseDTO<>();
DeleteApplicationDTO deleteDto = new DeleteApplicationDTO();
Map<String, String> requestParamMap = new HashMap<>();
Expand All @@ -383,13 +389,17 @@ public MainResponseDTO<DeleteApplicationDTO> deleteLostOrUpdateApplication(Strin
if (bookingType.equals(BookingTypeCodes.UPDATE_REGISTRATION.toString())) {
response.setId(updateRegistrationDeleteId);
}
if (bookingType.equals(BookingTypeCodes.MISCELLANEOUS_PURPOSE.toString())) {
response.setId(miscellaneousPurposeDeleteId);
}
response.setVersion(version);
try {
requestParamMap.put(RequestCodes.APPLICATION_ID.getCode(), applicationId);
if (validationUtil.requstParamValidator(requestParamMap)) {
ApplicationEntity applicationEntity = serviceUtil.findApplicationById(applicationId);
if (bookingType.equals(BookingTypeCodes.LOST_FORGOTTEN_UIN.toString())
|| bookingType.equals(BookingTypeCodes.UPDATE_REGISTRATION.toString())) {
|| bookingType.equals(BookingTypeCodes.UPDATE_REGISTRATION.toString())
|| bookingType.equals(BookingTypeCodes.MISCELLANEOUS_PURPOSE.toString())) {
//userValidation(applicationEntity);
if (!authUserDetails().getUserId().trim().equals(applicationEntity.getCrBy().trim())) {
throw new PreIdInvalidForUserIdException(ApplicationErrorCodes.PRG_APP_015.getCode(),
Expand All @@ -416,7 +426,7 @@ public MainResponseDTO<DeleteApplicationDTO> deleteLostOrUpdateApplication(Strin
} catch (Exception ex) {
log.error("sessionId", "idType", "id", ExceptionUtils.getStackTrace(ex));
log.error("sessionId", "idType", "id",
"In pre-registration deleteLostOrUpdateApplication service- " + ex.getMessage());
"In pre-registration deleteLostOrUpdateOrMiscellaneousApplication service- " + ex.getMessage());
new DemographicExceptionCatcher().handle(ex, response);
} finally {
response.setResponsetime(serviceUtil.getCurrentResponseTime());
Expand Down Expand Up @@ -545,7 +555,8 @@ public MainResponseDTO<ApplicationsListDTO> getAllApplicationsForUserForBookingT
try {
if (!type.equalsIgnoreCase(BookingTypeCodes.NEW_PREREGISTRATION.toString())
&& !type.equalsIgnoreCase(BookingTypeCodes.LOST_FORGOTTEN_UIN.toString())
&& !type.equalsIgnoreCase(BookingTypeCodes.UPDATE_REGISTRATION.toString())) {
&& !type.equalsIgnoreCase(BookingTypeCodes.UPDATE_REGISTRATION.toString())
&& !type.equalsIgnoreCase(BookingTypeCodes.MISCELLANEOUS_PURPOSE.toString())) {
throw new InvalidPreRegistrationIdException(ApplicationErrorCodes.PRG_APP_016.getCode(),
ApplicationErrorMessages.INVALID_BOOKING_TYPE.getMessage());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,22 @@ MainResponseDTO<List<ApplicationDetailResponseDTO>> getBookingsForRegCenter(Stri

/**
* This method is used to create the a new application with booking type as
* UPDATE_REGISTRATION or LOST_FORGOTTEN_UIN
* UPDATE_REGISTRATION or LOST_FORGOTTEN_UIN or MISCELLANEOUS_PURPOSE
*
* @param request
* @param bookingType
* @return MainResponseDTO<ApplicationResponseDTO>
*/
MainResponseDTO<ApplicationResponseDTO> addLostOrUpdateApplication(MainRequestDTO<ApplicationRequestDTO> request,
MainResponseDTO<ApplicationResponseDTO> addLostOrUpdateOrMiscellaneousApplication(MainRequestDTO<? extends ApplicationRequestDTO> request,
String bookingType);

/**
* This method is used to delete the application with booking type as
* UPDATE_REGISTRATION or LOST_FORGOTTEN_UIN
* UPDATE_REGISTRATION or LOST_FORGOTTEN_UIN or MISCELLANEOUS_PURPOSE
*
* @param applicationId
* @param bookingType UPDATE_REGISTRATION or LOST_FORGOTTEN_UIN
* @param bookingType UPDATE_REGISTRATION or LOST_FORGOTTEN_UIN or MISCELLANEOUS_PURPOSE
* @return MainResponseDTO<DeleteApplicationDTO>
*/
MainResponseDTO<DeleteApplicationDTO> deleteLostOrUpdateApplication(String applicationId, String bookingType);
MainResponseDTO<DeleteApplicationDTO> deleteLostOrUpdateOrMiscellaneousApplication(String applicationId, String bookingType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ private ApplicationEntity updateApplicationEntity(String preRegistrationId, Book
applicationEntity.setSlotToTime(null);
applicationEntity.setRegistrationCenterId(null);
if ((applicationEntity.getBookingType().equals(BookingTypeCodes.LOST_FORGOTTEN_UIN.toString())
|| applicationEntity.getBookingType()
.equals(BookingTypeCodes.UPDATE_REGISTRATION.toString()))
|| applicationEntity.getBookingType().equals(BookingTypeCodes.UPDATE_REGISTRATION.toString())
|| applicationEntity.getBookingType().contains(BookingTypeCodes.MISCELLANEOUS_PURPOSE.toString()))
&& newStatus != null) {
applicationEntity.setBookingStatusCode(newStatus);
}
Expand All @@ -396,8 +396,8 @@ private ApplicationEntity updateApplicationEntity(String preRegistrationId, Book
LocalTime.parse(bookingInfo.getSlotToTime(), DateTimeFormatter.ofPattern("H:mm:ss")));
applicationEntity.setRegistrationCenterId(bookingInfo.getRegistrationCenterId());
if ((applicationEntity.getBookingType().equals(BookingTypeCodes.LOST_FORGOTTEN_UIN.toString())
|| applicationEntity.getBookingType()
.equals(BookingTypeCodes.UPDATE_REGISTRATION.toString()))
|| applicationEntity.getBookingType().equals(BookingTypeCodes.UPDATE_REGISTRATION.toString())
|| applicationEntity.getBookingType().contains(BookingTypeCodes.MISCELLANEOUS_PURPOSE.toString()))
&& newStatus != null) {
applicationEntity.setBookingStatusCode(newStatus);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ mosip.id.preregistration.lostuin.create=mosip.pre-registration.lostuin.create
mosip.id.preregistration.lostuin.delete=mosip.pre-registration.lostuin.delete
mosip.id.preregistration.updateregistration.create=mosip.pre-registration.updateregistration.create
mosip.id.preregistration.updateregistration.delete=mosip.pre-registration.updateregistration.delete
mosip.id.preregistration.miscellaneouspurpose.create=mosip.pre-registration.miscellaneouspurpose.create
mosip.id.preregistration.miscellaneouspurpose.delete=mosip.pre-registration.miscellaneouspurpose.delete
mosip.preregistration.miscellaneouspurpose.length=200
mosip.preregistration.demographic.id.create=mosip.pre-registration.demographic.create
mosip.preregistration.demographic.id.update=mosip.pre-registration.demographic.update
mosip.preregistration.demographic.id.retrieve.date=mosip.pre-registration.demographic.retrieve.date
Expand Down
Loading