/** * 2.2.7 Set User Language Location Code API IVR shall invoke this API to provide user * languageLocation preference to MoTech. /api/mobileacademy/languageLocationCode * * <p>3.2.3 Set User Language Location Code API IVR shall invoke this API to set the language * location code of the user in NMS database. /api/mobilekunji/languageLocationCode */ @RequestMapping( value = "/{serviceName}/languageLocationCode", // NO CHECKSTYLE Cyclomatic Complexity method = RequestMethod.POST, headers = {"Content-type=application/json"}) @ResponseStatus(HttpStatus.OK) @Transactional public void setUserLanguageLocationCode( @PathVariable String serviceName, @RequestBody UserLanguageRequest userLanguageRequest) { log( String.format("REQUEST: /%s/languageLocationCode (POST)", serviceName), LogHelper.nullOrString(userLanguageRequest)); Long callingNumber = userLanguageRequest.getCallingNumber(); Long callId = userLanguageRequest.getCallId(); String languageLocationCode = userLanguageRequest.getLanguageLocationCode(); StringBuilder failureReasons = validate(callingNumber, callId); validateFieldPresent( failureReasons, LANGUAGE_LOCATION_CODE, userLanguageRequest.getLanguageLocationCode()); if (!(MOBILE_ACADEMY.equals(serviceName) || MOBILE_KUNJI.equals(serviceName))) { failureReasons.append(String.format(INVALID, SERVICE_NAME)); } Service service = null; service = getServiceFromName(serviceName); if (failureReasons.length() > 0) { throw new IllegalArgumentException(failureReasons.toString()); } FrontLineWorker flw = frontLineWorkerService.getByContactNumber(callingNumber); if (flw == null) { flw = new FrontLineWorker(callingNumber); } Language language = languageService.getForCode(languageLocationCode); if (null == language) { throw new NotFoundException(String.format(NOT_FOUND, LANGUAGE_LOCATION_CODE)); } flw.setLanguage(language); State state = getStateForFrontLineWorker(flw, null); if (!serviceDeployedInUserState(service, state)) { throw new NotDeployedException(String.format(NOT_DEPLOYED, service)); } if (!frontLineWorkerAuthorizedForAccess(flw, state)) { throw new NotAuthorizedException(String.format(NOT_AUTHORIZED, CALLING_NUMBER)); } // MOTECH-1667 added to get an upsert method included if (flw.getId() == null) { frontLineWorkerService.add(flw); } else { frontLineWorkerService.update(flw); } }