@Test public void testUpdateTranslation() throws Exception { String API = L10NAPIV1.UPDATE_TRANSLATION_L10N.replace("{"+ APIParamName.PRODUCT_NAME + "}", "vCG").replace("{"+APIParamName.VERSION2+"}", "1.0.0"); MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); mockMvc.perform(MockMvcRequestBuilders.post(API) .content(Constants.UPDATETRANSLATIONAPIREQUESTBODY) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)).andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string(Constants.UPDATETRANSLATIONEXPECTRESULT)); }
@CrossOrigin @RequestMapping(value = L10NAPIV1.UPDATE_TRANSLATION_L10N, method = RequestMethod.POST, produces = { API.API_CHARSET }) @ResponseStatus(HttpStatus.OK) public APIResponseDTO updateTranslation( @RequestBody UpdateTranslationDTO updateTranslationDTO, @PathVariable(APIParamName.PRODUCT_NAME) String productName, @PathVariable(APIParamName.VERSION) String version, HttpServletRequest request) { LOGGER.info("The request url is " + request.getRequestURL() + (request.getQueryString() == null ? "" : "?" + request.getQueryString())); ObjectMapper mapper = new ObjectMapper(); String requestJson = ""; try { requestJson = mapper.writeValueAsString(updateTranslationDTO); } catch (JsonProcessingException e) { LOGGER.error(e.getMessage(), e); } LOGGER.info("The request content is {}", requestJson); APIResponseDTO response = new APIResponseDTO(); if (StringUtils.isEmpty(updateTranslationDTO) || StringUtils.isEmpty(updateTranslationDTO.getData()) || StringUtils.isEmpty(updateTranslationDTO.getData() .getTranslation())) { response.setResponse(APIResponseStatus.BAD_REQUEST); return response; } UpdateTranslationDataDTO updateTranslationDataDTO = updateTranslationDTO .getData(); List<TranslationDTO> translationList = updateTranslationDataDTO .getTranslation(); if (StringUtils.isEmpty(updateTranslationDataDTO.getProductName()) || !updateTranslationDataDTO.getProductName().equals( productName)) { response.setResponse(APIResponseStatus.BAD_REQUEST); return response; } if (StringUtils.isEmpty(updateTranslationDataDTO.getVersion()) || !updateTranslationDataDTO.getVersion().equals(version)) { response.setResponse(APIResponseStatus.BAD_REQUEST); return response; } List<ComponentMessagesDTO> componentMessagesDTOList = new ArrayList<ComponentMessagesDTO>(); for (TranslationDTO translationDTO : translationList) { if (StringUtils.isEmpty(translationDTO)) { response.setResponse(APIResponseStatus.BAD_REQUEST); return response; } ComponentMessagesDTO componentMessagesDTO = new ComponentMessagesDTO(); componentMessagesDTO.setProductName(updateTranslationDataDTO .getProductName()); componentMessagesDTO.setVersion(updateTranslationDataDTO .getVersion()); componentMessagesDTO.setComponent(translationDTO.getComponent()); componentMessagesDTO.setLocale(translationDTO.getLocale()); componentMessagesDTO.setMessages(translationDTO.getMessages()); componentMessagesDTO.setId(System.currentTimeMillis()); componentMessagesDTOList.add(componentMessagesDTO); } List<TranslationDTO> translationDTOList = null; try { translationDTOList = translationSyncServerService .updateBatchTranslation(componentMessagesDTOList); } catch (L10nAPIException e) { response.setResponse(APIResponseStatus.INTERNAL_SERVER_ERROR); LOGGER.error(e.getMessage(), e); } if (translationDTOList != null && translationDTOList.size() > 0) { response.setData(translationDTOList); response.setResponse(APIResponseStatus.OK); } saveCreationInfo(updateTranslationDTO); return response; }
TranslationSyncServerController { @CrossOrigin @RequestMapping(value = L10NAPIV1.UPDATE_TRANSLATION_L10N, method = RequestMethod.POST, produces = { API.API_CHARSET }) @ResponseStatus(HttpStatus.OK) public APIResponseDTO updateTranslation( @RequestBody UpdateTranslationDTO updateTranslationDTO, @PathVariable(APIParamName.PRODUCT_NAME) String productName, @PathVariable(APIParamName.VERSION) String version, HttpServletRequest request) { LOGGER.info("The request url is " + request.getRequestURL() + (request.getQueryString() == null ? "" : "?" + request.getQueryString())); ObjectMapper mapper = new ObjectMapper(); String requestJson = ""; try { requestJson = mapper.writeValueAsString(updateTranslationDTO); } catch (JsonProcessingException e) { LOGGER.error(e.getMessage(), e); } LOGGER.info("The request content is {}", requestJson); APIResponseDTO response = new APIResponseDTO(); if (StringUtils.isEmpty(updateTranslationDTO) || StringUtils.isEmpty(updateTranslationDTO.getData()) || StringUtils.isEmpty(updateTranslationDTO.getData() .getTranslation())) { response.setResponse(APIResponseStatus.BAD_REQUEST); return response; } UpdateTranslationDataDTO updateTranslationDataDTO = updateTranslationDTO .getData(); List<TranslationDTO> translationList = updateTranslationDataDTO .getTranslation(); if (StringUtils.isEmpty(updateTranslationDataDTO.getProductName()) || !updateTranslationDataDTO.getProductName().equals( productName)) { response.setResponse(APIResponseStatus.BAD_REQUEST); return response; } if (StringUtils.isEmpty(updateTranslationDataDTO.getVersion()) || !updateTranslationDataDTO.getVersion().equals(version)) { response.setResponse(APIResponseStatus.BAD_REQUEST); return response; } List<ComponentMessagesDTO> componentMessagesDTOList = new ArrayList<ComponentMessagesDTO>(); for (TranslationDTO translationDTO : translationList) { if (StringUtils.isEmpty(translationDTO)) { response.setResponse(APIResponseStatus.BAD_REQUEST); return response; } ComponentMessagesDTO componentMessagesDTO = new ComponentMessagesDTO(); componentMessagesDTO.setProductName(updateTranslationDataDTO .getProductName()); componentMessagesDTO.setVersion(updateTranslationDataDTO .getVersion()); componentMessagesDTO.setComponent(translationDTO.getComponent()); componentMessagesDTO.setLocale(translationDTO.getLocale()); componentMessagesDTO.setMessages(translationDTO.getMessages()); componentMessagesDTO.setId(System.currentTimeMillis()); componentMessagesDTOList.add(componentMessagesDTO); } List<TranslationDTO> translationDTOList = null; try { translationDTOList = translationSyncServerService .updateBatchTranslation(componentMessagesDTOList); } catch (L10nAPIException e) { response.setResponse(APIResponseStatus.INTERNAL_SERVER_ERROR); LOGGER.error(e.getMessage(), e); } if (translationDTOList != null && translationDTOList.size() > 0) { response.setData(translationDTOList); response.setResponse(APIResponseStatus.OK); } saveCreationInfo(updateTranslationDTO); return response; } }
TranslationSyncServerController { @CrossOrigin @RequestMapping(value = L10NAPIV1.UPDATE_TRANSLATION_L10N, method = RequestMethod.POST, produces = { API.API_CHARSET }) @ResponseStatus(HttpStatus.OK) public APIResponseDTO updateTranslation( @RequestBody UpdateTranslationDTO updateTranslationDTO, @PathVariable(APIParamName.PRODUCT_NAME) String productName, @PathVariable(APIParamName.VERSION) String version, HttpServletRequest request) { LOGGER.info("The request url is " + request.getRequestURL() + (request.getQueryString() == null ? "" : "?" + request.getQueryString())); ObjectMapper mapper = new ObjectMapper(); String requestJson = ""; try { requestJson = mapper.writeValueAsString(updateTranslationDTO); } catch (JsonProcessingException e) { LOGGER.error(e.getMessage(), e); } LOGGER.info("The request content is {}", requestJson); APIResponseDTO response = new APIResponseDTO(); if (StringUtils.isEmpty(updateTranslationDTO) || StringUtils.isEmpty(updateTranslationDTO.getData()) || StringUtils.isEmpty(updateTranslationDTO.getData() .getTranslation())) { response.setResponse(APIResponseStatus.BAD_REQUEST); return response; } UpdateTranslationDataDTO updateTranslationDataDTO = updateTranslationDTO .getData(); List<TranslationDTO> translationList = updateTranslationDataDTO .getTranslation(); if (StringUtils.isEmpty(updateTranslationDataDTO.getProductName()) || !updateTranslationDataDTO.getProductName().equals( productName)) { response.setResponse(APIResponseStatus.BAD_REQUEST); return response; } if (StringUtils.isEmpty(updateTranslationDataDTO.getVersion()) || !updateTranslationDataDTO.getVersion().equals(version)) { response.setResponse(APIResponseStatus.BAD_REQUEST); return response; } List<ComponentMessagesDTO> componentMessagesDTOList = new ArrayList<ComponentMessagesDTO>(); for (TranslationDTO translationDTO : translationList) { if (StringUtils.isEmpty(translationDTO)) { response.setResponse(APIResponseStatus.BAD_REQUEST); return response; } ComponentMessagesDTO componentMessagesDTO = new ComponentMessagesDTO(); componentMessagesDTO.setProductName(updateTranslationDataDTO .getProductName()); componentMessagesDTO.setVersion(updateTranslationDataDTO .getVersion()); componentMessagesDTO.setComponent(translationDTO.getComponent()); componentMessagesDTO.setLocale(translationDTO.getLocale()); componentMessagesDTO.setMessages(translationDTO.getMessages()); componentMessagesDTO.setId(System.currentTimeMillis()); componentMessagesDTOList.add(componentMessagesDTO); } List<TranslationDTO> translationDTOList = null; try { translationDTOList = translationSyncServerService .updateBatchTranslation(componentMessagesDTOList); } catch (L10nAPIException e) { response.setResponse(APIResponseStatus.INTERNAL_SERVER_ERROR); LOGGER.error(e.getMessage(), e); } if (translationDTOList != null && translationDTOList.size() > 0) { response.setData(translationDTOList); response.setResponse(APIResponseStatus.OK); } saveCreationInfo(updateTranslationDTO); return response; }  }
TranslationSyncServerController { @CrossOrigin @RequestMapping(value = L10NAPIV1.UPDATE_TRANSLATION_L10N, method = RequestMethod.POST, produces = { API.API_CHARSET }) @ResponseStatus(HttpStatus.OK) public APIResponseDTO updateTranslation( @RequestBody UpdateTranslationDTO updateTranslationDTO, @PathVariable(APIParamName.PRODUCT_NAME) String productName, @PathVariable(APIParamName.VERSION) String version, HttpServletRequest request) { LOGGER.info("The request url is " + request.getRequestURL() + (request.getQueryString() == null ? "" : "?" + request.getQueryString())); ObjectMapper mapper = new ObjectMapper(); String requestJson = ""; try { requestJson = mapper.writeValueAsString(updateTranslationDTO); } catch (JsonProcessingException e) { LOGGER.error(e.getMessage(), e); } LOGGER.info("The request content is {}", requestJson); APIResponseDTO response = new APIResponseDTO(); if (StringUtils.isEmpty(updateTranslationDTO) || StringUtils.isEmpty(updateTranslationDTO.getData()) || StringUtils.isEmpty(updateTranslationDTO.getData() .getTranslation())) { response.setResponse(APIResponseStatus.BAD_REQUEST); return response; } UpdateTranslationDataDTO updateTranslationDataDTO = updateTranslationDTO .getData(); List<TranslationDTO> translationList = updateTranslationDataDTO .getTranslation(); if (StringUtils.isEmpty(updateTranslationDataDTO.getProductName()) || !updateTranslationDataDTO.getProductName().equals( productName)) { response.setResponse(APIResponseStatus.BAD_REQUEST); return response; } if (StringUtils.isEmpty(updateTranslationDataDTO.getVersion()) || !updateTranslationDataDTO.getVersion().equals(version)) { response.setResponse(APIResponseStatus.BAD_REQUEST); return response; } List<ComponentMessagesDTO> componentMessagesDTOList = new ArrayList<ComponentMessagesDTO>(); for (TranslationDTO translationDTO : translationList) { if (StringUtils.isEmpty(translationDTO)) { response.setResponse(APIResponseStatus.BAD_REQUEST); return response; } ComponentMessagesDTO componentMessagesDTO = new ComponentMessagesDTO(); componentMessagesDTO.setProductName(updateTranslationDataDTO .getProductName()); componentMessagesDTO.setVersion(updateTranslationDataDTO .getVersion()); componentMessagesDTO.setComponent(translationDTO.getComponent()); componentMessagesDTO.setLocale(translationDTO.getLocale()); componentMessagesDTO.setMessages(translationDTO.getMessages()); componentMessagesDTO.setId(System.currentTimeMillis()); componentMessagesDTOList.add(componentMessagesDTO); } List<TranslationDTO> translationDTOList = null; try { translationDTOList = translationSyncServerService .updateBatchTranslation(componentMessagesDTOList); } catch (L10nAPIException e) { response.setResponse(APIResponseStatus.INTERNAL_SERVER_ERROR); LOGGER.error(e.getMessage(), e); } if (translationDTOList != null && translationDTOList.size() > 0) { response.setData(translationDTOList); response.setResponse(APIResponseStatus.OK); } saveCreationInfo(updateTranslationDTO); return response; }  @ExceptionHandler(Exception.class) @ResponseStatus(HttpStatus.OK) void processMethod(Exception e, HttpServletRequest request,
            HttpServletResponse response); @CrossOrigin @RequestMapping(value = L10NAPIV1.UPDATE_TRANSLATION_L10N, method = RequestMethod.POST, produces = { API.API_CHARSET }) @ResponseStatus(HttpStatus.OK) APIResponseDTO updateTranslation(
            @RequestBody UpdateTranslationDTO updateTranslationDTO,
            @PathVariable(APIParamName.PRODUCT_NAME) String productName,
            @PathVariable(APIParamName.VERSION) String version, HttpServletRequest request); }
TranslationSyncServerController { @CrossOrigin @RequestMapping(value = L10NAPIV1.UPDATE_TRANSLATION_L10N, method = RequestMethod.POST, produces = { API.API_CHARSET }) @ResponseStatus(HttpStatus.OK) public APIResponseDTO updateTranslation( @RequestBody UpdateTranslationDTO updateTranslationDTO, @PathVariable(APIParamName.PRODUCT_NAME) String productName, @PathVariable(APIParamName.VERSION) String version, HttpServletRequest request) { LOGGER.info("The request url is " + request.getRequestURL() + (request.getQueryString() == null ? "" : "?" + request.getQueryString())); ObjectMapper mapper = new ObjectMapper(); String requestJson = ""; try { requestJson = mapper.writeValueAsString(updateTranslationDTO); } catch (JsonProcessingException e) { LOGGER.error(e.getMessage(), e); } LOGGER.info("The request content is {}", requestJson); APIResponseDTO response = new APIResponseDTO(); if (StringUtils.isEmpty(updateTranslationDTO) || StringUtils.isEmpty(updateTranslationDTO.getData()) || StringUtils.isEmpty(updateTranslationDTO.getData() .getTranslation())) { response.setResponse(APIResponseStatus.BAD_REQUEST); return response; } UpdateTranslationDataDTO updateTranslationDataDTO = updateTranslationDTO .getData(); List<TranslationDTO> translationList = updateTranslationDataDTO .getTranslation(); if (StringUtils.isEmpty(updateTranslationDataDTO.getProductName()) || !updateTranslationDataDTO.getProductName().equals( productName)) { response.setResponse(APIResponseStatus.BAD_REQUEST); return response; } if (StringUtils.isEmpty(updateTranslationDataDTO.getVersion()) || !updateTranslationDataDTO.getVersion().equals(version)) { response.setResponse(APIResponseStatus.BAD_REQUEST); return response; } List<ComponentMessagesDTO> componentMessagesDTOList = new ArrayList<ComponentMessagesDTO>(); for (TranslationDTO translationDTO : translationList) { if (StringUtils.isEmpty(translationDTO)) { response.setResponse(APIResponseStatus.BAD_REQUEST); return response; } ComponentMessagesDTO componentMessagesDTO = new ComponentMessagesDTO(); componentMessagesDTO.setProductName(updateTranslationDataDTO .getProductName()); componentMessagesDTO.setVersion(updateTranslationDataDTO .getVersion()); componentMessagesDTO.setComponent(translationDTO.getComponent()); componentMessagesDTO.setLocale(translationDTO.getLocale()); componentMessagesDTO.setMessages(translationDTO.getMessages()); componentMessagesDTO.setId(System.currentTimeMillis()); componentMessagesDTOList.add(componentMessagesDTO); } List<TranslationDTO> translationDTOList = null; try { translationDTOList = translationSyncServerService .updateBatchTranslation(componentMessagesDTOList); } catch (L10nAPIException e) { response.setResponse(APIResponseStatus.INTERNAL_SERVER_ERROR); LOGGER.error(e.getMessage(), e); } if (translationDTOList != null && translationDTOList.size() > 0) { response.setData(translationDTOList); response.setResponse(APIResponseStatus.OK); } saveCreationInfo(updateTranslationDTO); return response; }  @ExceptionHandler(Exception.class) @ResponseStatus(HttpStatus.OK) void processMethod(Exception e, HttpServletRequest request,
            HttpServletResponse response); @CrossOrigin @RequestMapping(value = L10NAPIV1.UPDATE_TRANSLATION_L10N, method = RequestMethod.POST, produces = { API.API_CHARSET }) @ResponseStatus(HttpStatus.OK) APIResponseDTO updateTranslation(
            @RequestBody UpdateTranslationDTO updateTranslationDTO,
            @PathVariable(APIParamName.PRODUCT_NAME) String productName,
            @PathVariable(APIParamName.VERSION) String version, HttpServletRequest request);  }