/* * This file and a proportion of its content is copyright of Assa Abloy - 2017. All rights reserved. * Any redistribution or reproduction of part or all of the contents in any form is prohibited other than the following: * - you cannot print or download to a local hard disk extract contents either part or full for personal/ commercial/ * academic or any other use * - you may not copy the content to individual/ third parties for any type of use, either as compiled or source format * without the knowledge and consent of Assa Abloy * - You may not, except with our express written permission, distribute or commercially exploit the content. Nor may you * transmit it or store it in any other web site or other form of electronic retrieval system. */ package com.assaabloy.myassaabloy.client; import java.util.Map; import org.apache.commons.lang.StringUtils; import com.assaabloy.myassaabloy.client.constants.MYAssaAbloyConstants; import com.assaabloy.myassaabloy.client.factory.MyAssaAbloyClientFactory; import com.assaabloy.myassaabloy.client.presenter.orders.QuestionAnswerSubmitPresenter; import com.assaabloy.myassaabloy.client.util.AAClientCommonUtil; import com.assaabloy.myassaabloy.client.util.FileItemValidator; import com.assaabloy.myassaabloy.client.util.NotificationType; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.Cookies; import com.google.gwt.user.client.History; import com.google.gwt.user.client.ui.Widget; import com.smartgwt.client.data.Criteria; import com.smartgwt.client.data.DSCallback; import com.smartgwt.client.data.DSRequest; import com.smartgwt.client.data.DSResponse; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.rpc.RPCManager; import com.smartgwt.client.types.Alignment; import com.smartgwt.client.types.FormErrorOrientation; import com.smartgwt.client.util.Page; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.AutoFitTextAreaItem; import com.smartgwt.client.widgets.form.fields.ButtonItem; import com.smartgwt.client.widgets.form.fields.FileItem; import com.smartgwt.client.widgets.form.fields.FormItem; import com.smartgwt.client.widgets.form.fields.LinkItem; import com.smartgwt.client.widgets.form.fields.TextAreaItem; import com.smartgwt.client.widgets.form.fields.TextItem; import com.smartgwt.client.widgets.form.fields.events.HasClickHandlers; import com.smartgwt.client.widgets.form.validator.LengthRangeValidator; import com.smartgwt.client.widgets.form.validator.RegExpValidator; import com.smartgwt.client.widgets.form.validator.Validator; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.Layout; import com.smartgwt.client.widgets.layout.VLayout; /** * @author Nagarro * @Created On 31-Mar-2017 * @Purpose Question Answer submit view */ public class QuestionAnswerSubmitView extends VLayout implements QuestionAnswerSubmitPresenter.Display { private static final String EMAIL_VALIDATION_REGEX = "^[_A-Za-z0-9-+]+(\\.[_A-Za-z0-9-+]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; MyAssaAbloyClientFactory clientFactory = GWT.create(MyAssaAbloyClientFactory.class); private final AAClientLabels clientLabels = (AAClientLabels) GWT.create(AAClientLabels.class); private final AAClientErrorMessages clientErrors = (AAClientErrorMessages) GWT.create(AAClientErrorMessages.class); private DynamicForm submitAnswerForm; private ButtonItem submit; private ButtonItem cancel; private AutoFitTextAreaItem answer; private TextItem emailAddress; private final Label submitAnswerMsgPanel; private Layout quesSectionLayout; private final VLayout quesHistorylayout; private final ButtonItem questionLog = new ButtonItem(); private final String buCode; private final String orderNum; private final String locationId; private String firstName; private String lastName; /** * The constructor QuestionAnswerSubmitView class. * * @param bussinessUnitCode * @param orderNo */ public QuestionAnswerSubmitView(final String bussinessUnitCode, final String orderNo, final String locationId) { this.buCode = bussinessUnitCode; this.orderNum = orderNo; this.locationId = locationId; this.setWidth(MYAssaAbloyConstants.HUNDRED_PERCENT); this.setStyleName(MYAssaAbloyConstants.EXPD_FORM_SECTION_CSS); this.setLayoutBottomMargin(MYAssaAbloyConstants.TEN_INT); // Message box to show success or error message submitAnswerMsgPanel = new Label(); submitAnswerMsgPanel.setHeight(20); submitAnswerMsgPanel.setStyleName(MYAssaAbloyConstants.SUCCESS_MSG_TEXT_CSS); submitAnswerMsgPanel.hide(); // Start - Question history log section quesHistorylayout = new VLayout(); quesHistorylayout.hide(); quesHistorylayout.setWidth(MYAssaAbloyConstants.TWENTYFIVE_PERCENT); quesHistorylayout.setStyleName(MYAssaAbloyConstants.QUESTION_HISTORY_LOG_CSS); quesHistorylayout.setBorder("1px solid #cccccc"); final Label quesHistoryLogheader = new Label(); quesHistoryLogheader.setStyleName(MYAssaAbloyConstants.QUESTION_HISTORY_HEADER_CSS); quesHistoryLogheader.setHeight(20); quesHistoryLogheader.setWidth(MYAssaAbloyConstants.HUNDRED_PERCENT); quesHistoryLogheader.setContents(clientLabels.getQuestionLogHeading()); final Label quesHistoryLogContent = new Label(); quesHistoryLogContent.setPadding(10); quesHistorylayout.addMember(quesHistoryLogheader); quesHistorylayout.addMember(quesHistoryLogContent); quesHistorylayout.setMargin(10); quesSectionLayout = new HLayout(); // End - Question history log section // Setting the action url of the controller final String csrfCookie = Cookies.getCookie("XSRF-TOKEN"); RPCManager.setActionURL(GWT.getHostPageBaseURL() + MYAssaAbloyConstants.SUBMIT_ANSWER_URL + MYAssaAbloyConstants.QUESTION_MARK + MYAssaAbloyConstants.CSRF_REQUEST_PARAM + csrfCookie); final HLayout submitForm = new HLayout(); submitForm.addMember(submitForm(quesHistoryLogContent)); submitForm.setWidth(MYAssaAbloyConstants.HUNDRED_PERCENT); final int width = Page.getWidth(); if (!AAClientCommonUtil.getDeviceType().equals(MYAssaAbloyConstants.DESKTOP)) { quesSectionLayout = new VLayout(); quesHistorylayout.setWidth(width); } quesSectionLayout.addMember(submitForm); quesSectionLayout.addMember(quesHistorylayout); this.addMember(submitAnswerMsgPanel); this.addMember(quesSectionLayout); } /* * This method is used to create the form of submit answer. */ private DynamicForm submitForm(final Label quesHistoryLogContent) { final DataSource submitAnswerDataSource = DataSource.get(MYAssaAbloyConstants.SUBMIT_ANS_DATASOURCE); submitAnswerForm = new DynamicForm(); submitAnswerForm.setDataSource(submitAnswerDataSource); submitAnswerForm.setIsGroup(true); submitAnswerForm.setGroupTitle(clientLabels.getSubmitAnswerForm()); submitAnswerForm.setShowErrorText(true); submitAnswerForm.setErrorOrientation(FormErrorOrientation.BOTTOM); submitAnswerForm.setStyleName(MYAssaAbloyConstants.QUEST_ANS_FORM_CSS); submitAnswerForm.setMargin(MYAssaAbloyConstants.TEN_INT); submitAnswerForm.setCellPadding(MYAssaAbloyConstants.TEN_INT); submitAnswerForm.setAutoFocus(true); submitAnswerForm.setColWidths(MYAssaAbloyConstants.FORTY_PERCENT, MYAssaAbloyConstants.SIXTY_PERCENT); submitAnswerForm.setID(MYAssaAbloyConstants.ORDER); submitAnswerForm.setBackgroundColor(MYAssaAbloyConstants.COLOUR_WHITE); submitAnswerForm.setAutoFetchData(false); final String history = History.getToken(); final String[] tokenArray = history.split(MYAssaAbloyConstants.TILDE); final String isQuesAnswered = tokenArray[5]; String PONUMBERFLAG = MYAssaAbloyConstants.BLANK; if (History.getToken().contains(MYAssaAbloyConstants.ORDER_DETAIL_FLAG) && History.getToken().contains(MYAssaAbloyConstants.QUESTION_STATUS)) { PONUMBERFLAG = tokenArray[tokenArray.length-1]; } final TextItem firstNameField = new TextItem(); firstNameField.setName(MYAssaAbloyConstants.FIRST_NAME_FIELD); firstNameField.setTitle(clientLabels.getUserFirstName()); setTextFieldProperties(firstNameField); final TextItem lastNameField = new TextItem(); lastNameField.setName(MYAssaAbloyConstants.LAST_NAME_FIELD); lastNameField.setTitle(clientLabels.getUserLastName()); setTextFieldProperties(lastNameField); setUserFirstAndLastName(firstNameField, lastNameField); final Criteria criteria = new Criteria(); criteria.setAttribute(MYAssaAbloyConstants.ORDERNUMBER, orderNum); criteria.setAttribute(MYAssaAbloyConstants.BUSSINESS_UNIT_CODE, buCode); criteria.setAttribute(MYAssaAbloyConstants.LOCATION_ID, locationId); criteria.setAttribute("poNumberFlag",PONUMBERFLAG); criteria.setAttribute(MYAssaAbloyConstants.FIRST_NAME_FIELD, firstName); criteria.setAttribute(MYAssaAbloyConstants.LAST_NAME_FIELD, lastName); submitAnswerForm.fetchData(criteria, new DSCallback() { @Override public void execute(final DSResponse dsResponse, final Object data, final DSRequest dsRequest) { if(data.toString().contains("authorized")) { clientFactory.getNotificationPresenter().showNotificationMessage(data.toString(), NotificationType.FAILURE.getValue(), Boolean.TRUE); } String text = null; FormItem questionLogField = submitAnswerForm.getField(MYAssaAbloyConstants.QUESTION_LOG); if(null != questionLogField && null != questionLogField.getValue()) { text = questionLogField.getValue().toString(); } if (null != text && !text.isEmpty()) { quesHistoryLogContent.setContents(questionLogField.getValue().toString()); submitAnswerForm.getField(MYAssaAbloyConstants.QUESTION_LOG_NAME).show(); } else { submitAnswerForm.getField(MYAssaAbloyConstants.QUESTION_LOG_NAME).hide(); } } }); final TextItem customerNumber = new TextItem(); customerNumber.setName(MYAssaAbloyConstants.CUSTOMER_NO); customerNumber.setTitle(clientLabels.getShipAlertCustomerNumber()); customerNumber.setDisabled(true); customerNumber.setTextBoxStyle(MYAssaAbloyConstants.FORM_CONTROL); customerNumber.setTitleStyle(MYAssaAbloyConstants.FORM_LABEL); customerNumber.setWrapTitle(false); customerNumber.setErrorOrientation(FormErrorOrientation.BOTTOM); customerNumber.setWidth(MYAssaAbloyConstants.HUNDRED_PERCENT); final TextItem poNumber = new TextItem(); poNumber.setName(MYAssaAbloyConstants.PONO); poNumber.setTitle(clientLabels.getOrderDetailPoNoLabel()); poNumber.setDisabled(true); poNumber.setTextBoxStyle(MYAssaAbloyConstants.FORM_CONTROL); poNumber.setTitleStyle(MYAssaAbloyConstants.FORM_LABEL); poNumber.setWrapTitle(false); poNumber.setErrorOrientation(FormErrorOrientation.BOTTOM); poNumber.setWidth(MYAssaAbloyConstants.HUNDRED_PERCENT); final TextItem nortonOrderNumber = new TextItem(); nortonOrderNumber.setName(MYAssaAbloyConstants.ORDERNO); nortonOrderNumber.setTitle(clientLabels.getCommonOrderNumber()); nortonOrderNumber.setDisabled(true); nortonOrderNumber.setTextBoxStyle(MYAssaAbloyConstants.FORM_CONTROL); nortonOrderNumber.setTitleStyle(MYAssaAbloyConstants.FORM_LABEL); nortonOrderNumber.setWrapTitle(false); nortonOrderNumber.setErrorOrientation(FormErrorOrientation.BOTTOM); nortonOrderNumber.setWidth(MYAssaAbloyConstants.HUNDRED_PERCENT); final TextItem questionDate = new TextItem(); questionDate.setName(MYAssaAbloyConstants.QUESTIONDATE); questionDate.setTitle(clientLabels.getQuestionDate()); questionDate.setDisabled(true); questionDate.setTextBoxStyle(MYAssaAbloyConstants.FORM_CONTROL); questionDate.setTitleStyle(MYAssaAbloyConstants.FORM_LABEL); questionDate.setWrapTitle(false); questionDate.setErrorOrientation(FormErrorOrientation.BOTTOM); questionDate.setWidth(MYAssaAbloyConstants.HUNDRED_PERCENT); final TextItem businessUnit = new TextItem(); businessUnit.setName(MYAssaAbloyConstants.BUSINESS_UNIT_CODE); businessUnit.setHidden(true); questionDate.setErrorOrientation(FormErrorOrientation.BOTTOM); questionDate.setWidth(MYAssaAbloyConstants.HUNDRED_PERCENT); final TextItem cardId = new TextItem(); cardId.setName(MYAssaAbloyConstants.CARD_ID); cardId.setHidden(true); cardId.setErrorOrientation(FormErrorOrientation.BOTTOM); cardId.setWidth(MYAssaAbloyConstants.HUNDRED_PERCENT); final TextItem questionId = new TextItem(); questionId.setName(MYAssaAbloyConstants.QUESTION_ID); questionId.setHidden(true); questionId.setErrorOrientation(FormErrorOrientation.BOTTOM); questionId.setWidth(MYAssaAbloyConstants.HUNDRED_PERCENT); final TextItem questionHistory = new TextItem(); questionHistory.setName(MYAssaAbloyConstants.QUESTION_LOG); questionHistory.setHidden(true); questionHistory.setErrorOrientation(FormErrorOrientation.BOTTOM); questionHistory.setWidth(MYAssaAbloyConstants.HUNDRED_PERCENT); final AutoFitTextAreaItem question = new AutoFitTextAreaItem(); question.setName(MYAssaAbloyConstants.QUESTION); question.setTitle(clientLabels.getQuestions()); question.setTextBoxStyle(MYAssaAbloyConstants.SUBMIT_ANS_TEXT_BOX_CSS); question.setTitleStyle(MYAssaAbloyConstants.FORM_LABEL); question.setWrapTitle(false); question.setMaxHeight(200); question.setDisabled(true); question.setHeight(55); question.setErrorOrientation(FormErrorOrientation.BOTTOM); question.setWidth(MYAssaAbloyConstants.HUNDRED_PERCENT); //Adding document Url only for the EMTEK brand LinkItem documentUrl = new LinkItem(); documentUrl.setHidden(true); if (MYAssaAbloyConstants.BRAND_EMTEK_BUSINESS_UNIT_CODE.equals(buCode)) { documentUrl.setHidden(false); documentUrl.setLinkTitle(clientLabels.getQuestionDetailsLinkText()); documentUrl.setName(MYAssaAbloyConstants.QUESTION_DETAILS); documentUrl.setTitle(clientLabels.getQuestionDetails()); documentUrl.setTitleStyle(MYAssaAbloyConstants.FORM_LABEL); documentUrl.setCellStyle(MYAssaAbloyConstants.SUBMIT_ANS_DOCUMENT_URL); documentUrl.setWrap(true); documentUrl.setShowTitle(true); documentUrl.setWidth(MYAssaAbloyConstants.HUNDRED_PERCENT); } answer = new AutoFitTextAreaItem(); answer.setName(MYAssaAbloyConstants.ANSWER); answer.setTitle(clientLabels.getAnswer()); answer.setTextBoxStyle(MYAssaAbloyConstants.EXPEDITE_ORDER_MESSAGE_BOX_CSS); answer.setTitleStyle(MYAssaAbloyConstants.FORM_LABEL); answer.setRequired(Boolean.TRUE); answer.setRequiredMessage(clientErrors.getYourAnswerMsg()); answer.setValidateOnExit(Boolean.TRUE); if (MYAssaAbloyConstants.ZERO.equalsIgnoreCase(isQuesAnswered)) { answer.setRequired(Boolean.TRUE); answer.setCanEdit(true); final LengthRangeValidator ansLengthValidator = new LengthRangeValidator(); ansLengthValidator.setMax(2000); answer.setValidators(ansLengthValidator); } else if (MYAssaAbloyConstants.ONE.equalsIgnoreCase(isQuesAnswered)) { answer.setDefaultValue(clientLabels.getQuestionAnsweredMsg()); answer.setCanEdit(false); } answer.setMaxHeight(200); answer.setHeight(100); answer.setErrorOrientation(FormErrorOrientation.BOTTOM); answer.setWidth(MYAssaAbloyConstants.HUNDRED_PERCENT); final FileItem attachments = new FileItem(); attachments.setName(MYAssaAbloyConstants.ATTACHMENTS); attachments.setTitleStyle(MYAssaAbloyConstants.FORM_LABEL); attachments.setTitle(clientLabels.getUplaodFile1()); attachments.setMultiple(true); attachments.setType(MYAssaAbloyConstants.BINARY); attachments.setValidateOnChange(true); final Validator fileValidator = new Validator(); fileValidator.setType(MYAssaAbloyConstants.MAX_FILE_SIZE); fileValidator.setAttribute(MYAssaAbloyConstants.MAX_FILE_SIZE, MYAssaAbloyConstants.MAX_SIZE); fileValidator.setErrorMessage(clientErrors.getSubmitAnsMaxFileSizeError()); final FileItemValidator fileItemValidator = new FileItemValidator(attachments); attachments.setValidators(fileItemValidator, fileValidator); attachments.setErrorOrientation(FormErrorOrientation.BOTTOM); attachments.setWidth(MYAssaAbloyConstants.HUNDRED_PERCENT); final RegExpValidator regExpValidator = new RegExpValidator(); regExpValidator.setExpression(EMAIL_VALIDATION_REGEX); regExpValidator.setErrorMessage(clientErrors.getSubmitAnsEmailValidationError()); emailAddress = new TextItem(); emailAddress.setName(MYAssaAbloyConstants.EMAILADDRESS); emailAddress.setTitle(clientLabels.getEmailAddress()); emailAddress.setTextBoxStyle(MYAssaAbloyConstants.FORM_CONTROL); emailAddress.setTitleStyle(MYAssaAbloyConstants.FORM_LABEL); emailAddress.setWrapTitle(false); emailAddress.setDefaultValue(StringUtils.EMPTY); emailAddress.setErrorOrientation(FormErrorOrientation.BOTTOM); emailAddress.setWidth(MYAssaAbloyConstants.HUNDRED_PERCENT); submit = new ButtonItem(); submit.setTitle(clientLabels.getCommonSubmitButton()); submit.setBaseStyle(MYAssaAbloyConstants.BTN_PRIMARY); submit.setStartRow(false); submit.setEndRow(false); submit.setAlign(Alignment.RIGHT); cancel = new ButtonItem(); cancel.setTitle(clientLabels.getCommonCancelButton()); cancel.setBaseStyle(MYAssaAbloyConstants.BTN_DEFAULT); cancel.setStartRow(false); cancel.setEndRow(false); questionLog.setTitle(clientLabels.getQuestionLogButtonTitle()); questionLog.setName(MYAssaAbloyConstants.QUESTION_LOG_NAME); questionLog.setBaseStyle("btn btn-default btn-sm "); questionLog.hide(); questionLog.setStartRow(false); questionLog.setEndRow(false); if (MYAssaAbloyConstants.ZERO.equalsIgnoreCase(isQuesAnswered)) { emailAddress.setCanEdit(true); emailAddress.setValidators(regExpValidator); submit.setDisabled(false); submitAnswerForm.addStyleName("submitAnswer "); submitAnswerForm.removeStyleName("quesAnswered"); } else if (MYAssaAbloyConstants.ONE.equalsIgnoreCase(isQuesAnswered)) { emailAddress.setCanEdit(false); submit.setDisabled(true); submitAnswerForm.addStyleName("quesAnswered submitAnswer "); } submitAnswerForm.setFields(customerNumber, poNumber, nortonOrderNumber, questionDate, businessUnit, cardId, questionId, questionHistory, question,documentUrl, answer, firstNameField, lastNameField, emailAddress, attachments, submit, cancel, questionLog); final int width = Page.getWidth(); submitAnswerForm.setWidth(width); if (AAClientCommonUtil.getDeviceType().equals(MYAssaAbloyConstants.DESKTOP)) { submitAnswerForm.setWidth100(); } return submitAnswerForm; } private void setTextFieldProperties(TextItem textItem) { textItem.setTextBoxStyle(MYAssaAbloyConstants.FORM_CONTROL); textItem.setTitleStyle(MYAssaAbloyConstants.FORM_LABEL); textItem.setWrapTitle(false); textItem.setErrorOrientation(FormErrorOrientation.BOTTOM); textItem.setWidth(MYAssaAbloyConstants.HUNDRED_PERCENT); textItem.setDisabled(true); } private void setUserFirstAndLastName(TextItem firstNameField, TextItem lastNameField) { Map userPreferencesDetails = AAClientCommonUtil.getUserPreferencesDetails(); if (null != userPreferencesDetails) { String fullName = userPreferencesDetails.get("currentUserFullName"); if (null != fullName && !fullName.isEmpty()) { String[] nameTokens = fullName.split(MYAssaAbloyConstants.COMMA); firstName = nameTokens[nameTokens.length-1]; lastName = nameTokens[0]; firstNameField.setDefaultValue(firstName); lastNameField.setDefaultValue(lastName); } } } @Override public HasClickHandlers getSubmit() { return this.submit; } @Override public HasClickHandlers getCancel() { return this.cancel; } @Override public DynamicForm getSubmitAnswerForm() { return this.submitAnswerForm; } @Override public TextAreaItem getAnswer() { return this.answer; } @Override public TextItem getEmailAddress() { return this.emailAddress; } @Override public AAClientLabels getClientLabels() { return this.clientLabels; } @Override public Label getSubmitAnswerMsgPanel() { return this.submitAnswerMsgPanel; } @Override public Layout getQuesSectionLayout() { return this.quesSectionLayout; } @Override public ButtonItem getQuestionLog() { return this.questionLog; } @Override public VLayout getQuesHistorylayout() { return this.quesHistorylayout; } @Override public Widget asWidget() { return this; } } ############################################################################################################################################## @SuppressWarnings("rawtypes") @RequestMapping(value = { "/submit-answer" }, method = { RequestMethod.POST }) public ModelAndView handleQuesAnsRequest(final HttpServletRequest request, final HttpServletResponse response, final Locale locale) throws Exception { RPCManager rpc; boolean isSuccess = true; String errorMesage = null; final String[] params = new String[2]; try { rpc = new RPCManager(request, response); } catch (final Exception exception) { LOG.error(MyAssaWebAppConstants.EXCEPTION); LOG.error("-Exception occured ue to : {}",ExceptionHelper.printDetailStackTrace(exception)); return null; } final UserPrincipal currentUser = orderService.getCurrentUserDetails(); for (final Iterator i = rpc.getRequests().iterator(); i.hasNext();) { final Object req = i.next(); if (req instanceof RPCRequest) throw new Exception("RPC call expects only DSRequests"); final DSRequest dsRequest = (DSRequest) req; dsRequest.getUploadedFile("image");dsRequest.getUploadedFile("attachments"); //ISCFileItem i111 = (ISCFileItem) dsRequest.getUploadedFiles().g et(0); /*ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream) dsRequest.getValues().get("image"); BufferedImage bImage2 = ImageIO.read(byteArrayInputStream); ImageIO.write(bImage2, "jpg", new File("output.jpg") ); System.out.println("image created");*/ final String dsName = dsRequest.getDataSourceName(); LOG.debug("-DataSource Name is { " + dsName + " }"); final DSResponse dsResponse = new DSResponse(); dsResponse.setSuccess(); final String operationType = dsRequest.getOperationType(); LOG.debug("-operation type is { " + operationType + " }"); try { if ("QuestionSubmit".equalsIgnoreCase(dsName)) { if (DataSource.OP_FETCH.equalsIgnoreCase(operationType)) { final Map criteria = dsRequest.getCriteria(); if (criteria != null && criteria.containsKey(MYAssaAbloyConstants.ORDERNUMBER) && criteria.containsKey("bussinessUnitCode") ) { final String orderNumber = criteria.get(MYAssaAbloyConstants.ORDERNUMBER).toString(); final String bussinessUnitCode = criteria.get("bussinessUnitCode").toString(); String locations = criteria.get(LOCATION_ID).toString(); final String poNumber = criteria.get("poNumberFlag").toString(); HashMap paramsMap=new HashMap(); paramsMap.put(LOCATION_ID, locations); removeHTML(paramsMap); locations = paramsMap.get(LOCATION_ID); if(!isEmployee() && !matchLocation(locations)) { String userNotAuthMsg = msgSource.getMessage(MyAssaWebAppConstants.MYASSAABLOY_SERVICE_ERROR + MyAssaErrorCodes.USER_NOT_AUTHORIZED_ERROR_WEBSHOP, null, locale); dsResponse.setData(userNotAuthMsg); }else { final List questionAnswerInfo = getQuestionOrdersList( currentUser.getUserID(), locations, orderNumber, bussinessUnitCode,poNumber, currentUser.getEmailID()); if (!CollectionUtils.isEmpty(questionAnswerInfo)) { dsResponse.setData(questionAnswerInfo); } else { dsResponse.setData(Collections.emptyList()); } } } }else if (operationType.equals(DataSource.OP_UPDATE) || operationType.equals(DataSource.OP_ADD)) { final QuestionAnswerInfoDTO submitAnswer = new QuestionAnswerInfoDTO(); MultipartFile[] attachments = null; ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory()); List parseRequest = upload.parseRequest(request); for (FileItem fileItem : parseRequest) { if(fileItem.isFormField()) continue; String fileName = fileItem.getName(); if(null != fileName) { FilenameUtils.getName(fileName); } File uploadFile = new File("E:\\pdfPath\\" ,fileName); if(uploadFile.createNewFile()) { fileItem.write(uploadFile); } } if (ServletFileUpload.isMultipartContent(request)) { multipartResolver.resolveMultipart(request); final DefaultMultipartHttpServletRequest defaultMultipartHttpServletRequest = (DefaultMultipartHttpServletRequest) request; final LinkedMultiValueMap map = (LinkedMultiValueMap) defaultMultipartHttpServletRequest .getMultiFileMap(); final LinkedList files = (LinkedList) map.get("attachments"); if (CollectionUtils.isNotEmpty(files) && files.size() <= MXA_FILE_COUNT) { attachments = files.toArray(new MultipartFile[files.size()]); File uploadFile = new File("E:\\pdfPath\\" ,attachments[0].getOriginalFilename()); System.out.println("File is created"); // fileItem.write(uploadFile); FileOutputStream out = new FileOutputStream("E:\\pdfPath\\file1234.pdf"); out.write(attachments[0].getBytes()); out.close(); File convFile = new File("E:\\pdfPath\\file9999.pdf"); attachments[0].transferTo(convFile); //return convFile; } } if (isSuccess) { DataTools.setProperties(dsRequest.getValues(), submitAnswer); final String bussinessUnitCode = submitAnswer.getBusinessUnitCode(); final String cardId = submitAnswer.getCardID(); final String questionId = submitAnswer.getQuestionID(); final String emailAddress = submitAnswer.getEmailAddress(); final String message = submitAnswer.getAnswer(); params[0] = bussinessUnitCode; params[1] = cardId; LOG.info( "Method: submitAnswerRequest, sending request for Card Id {} and bussiness Unit Code {}", cardId, bussinessUnitCode); if (StringUtils.isNotEmpty(bussinessUnitCode) && StringUtils.isNotEmpty(cardId) && StringUtils.isNotEmpty(questionId) && StringUtils.isNotEmpty(emailAddress) && StringUtils.isNotEmpty(message)) { orderDetailsMap.clear(); final QuestionAnswerUpdateResponse updateResponse = questionAnswerService .updateQuestionAnswer(bussinessUnitCode, cardId, questionId, submitAnswer, attachments); if (updateResponse.getStatusInfo() != null) { dsResponse.setData(submitAnswer); }else{ dsResponse.setData(Collections.EMPTY_LIST); } LOG.info( "Method: submitAnswerRequest, received return for Card Id {} and bussiness Unit Code {}}", cardId, bussinessUnitCode); } else { isSuccess = false; LOG.error("handleQuesAnsRequest : The Mandatory Input is either blank or null."); errorMesage = msgSource.getMessage(MyAssaWebAppConstants.MYASSAABLOY_SERVICE_ERROR + MyAssaErrorCodes.SER_VALIDATION_ERR_0020, params, locale); } } } } else { LOG.debug("-Unknown Operation Type so setting DSResponse Failure-"); dsResponse.setFailure(); dsResponse.setData(UNKNOWN_OPERATION_TYPE + operationType); } } catch (final ApplicationException appException) { LOG.error(MyAssaWebAppConstants.APPLICATION_EXCEPTION); LOG.error(TEXT_APLLICATION_EXCEPTION, ExceptionHelper.printDetailStackTrace(appException)); isSuccess = false; errorMesage = msgSource.getMessage(appException.getErrorCode(), appException.getParams(), locale); LOG.error(errorMesage); } if (!isSuccess) { dsResponse.setFailure(); dsResponse.setData(errorMesage); } LOG.debug(LOG_DS_RESPONSE + dsResponse); rpc.send(dsRequest, dsResponse); } return null; } ##################################################################################################################### ds.xml