List of usage examples for org.apache.wicket.markup.html.form.upload FileUpload getClientFileName
public String getClientFileName()
From source file:au.org.theark.core.util.LoadCsvFileHelper.java
License:Open Source License
/** * Convert the specified fileUpload to CSV format, and save as a CsvBlob * // ww w. j ava 2s . c o m * @param fileUpload * @param delimiterCharacter */ public void convertToCSVAndWriteToFile(FileUpload fileUpload, char delimiterCharacter) { String filename = fileUpload.getClientFileName(); String fileFormat = filename.substring(filename.lastIndexOf('.') + 1).toUpperCase(); InputStream inputStream = null; try { // If Excel, convert to CSV for validation if (fileFormat.equalsIgnoreCase("XLS")) { inputStream = convertXlsInputStreamToCsv(fileUpload.getInputStream()); } else { inputStream = fileUpload.getInputStream(); } writeToTempFile(inputStream); } catch (IOException e) { log.error(".convertToCSVAndSave IOException: " + e.getMessage()); } this.columnNameList = getColumnsFromHeader(inputStream, delimiterCharacter); }
From source file:au.org.theark.core.web.component.customfieldupload.CustomFieldUploadStep1.java
License:Open Source License
private void saveFileInMemory() { // Set study in context Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); // Retrieve file and store as Blob in database // TODO: AJAX-ified and asynchronous and hit database FileUpload fileUpload = fileUploadField.getFileUpload(); containerForm.getModelObject().setFileUpload(fileUpload); InputStream inputStream = null; BufferedOutputStream outputStream = null; File temp = null;/* w w w . j a v a 2 s .c o m*/ try { // Copy all the contents of the file upload to a temp file (to read multiple times)... inputStream = containerForm.getModelObject().getFileUpload().getInputStream(); // Create temp file temp = File.createTempFile("customFieldUploadBlob", ".tmp"); containerForm.getModelObject().setTempFile(temp); // Delete temp file when program exits (just in case manual delete fails later) temp.deleteOnExit(); // Write to temp file outputStream = new BufferedOutputStream(new FileOutputStream(temp)); IOUtils.copy(inputStream, outputStream); } catch (IOException ioe) { log.error("IOException " + ioe.getMessage()); // Something failed, so there is temp file is not valid (step 2 should check for null) temp.delete(); temp = null; containerForm.getModelObject().setTempFile(temp); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { log.error("Unable to close inputStream: " + e.getMessage()); } } if (outputStream != null) { try { outputStream.flush(); outputStream.close(); } catch (IOException e) { log.error("Unable to close outputStream: " + e.getMessage()); } } } // Set details of Upload object containerForm.getModelObject().getUpload().setStudy(study); String filename = containerForm.getModelObject().getFileUpload().getClientFileName(); String fileFormatName = filename.substring(filename.lastIndexOf('.') + 1).toUpperCase(); FileFormat fileFormat = new FileFormat(); fileFormat = iArkCommonService.getFileFormatByName(fileFormatName); containerForm.getModelObject().getUpload().setFileFormat(fileFormat); byte[] byteArray = fileUpload.getMD5(); String checksum = getHex(byteArray); containerForm.getModelObject().getUpload().setChecksum(checksum); containerForm.getModelObject().getUpload().setFilename(fileUpload.getClientFileName()); wizardForm.setFileName(fileUpload.getClientFileName()); }
From source file:au.org.theark.lims.web.component.biospecimenupload.BiospecimenUploadStep1.java
License:Open Source License
private void saveFileInMemory(AjaxRequestTarget target) { // Retrieve file and store as Blob in database // TODO: AJAX-ified and asynchronous and hit database FileUpload fileUpload = fileUploadField.getFileUpload(); containerForm.getModelObject().setFileUpload(fileUpload); Payload payload = iArkCommonService.createPayload(fileUpload.getBytes()); containerForm.getModelObject().getUpload().setPayload(payload); // Set details of Upload object containerForm.getModelObject().getUpload().setStudy(studyDdc.getModelObject()); String filename = containerForm.getModelObject().getFileUpload().getClientFileName(); String fileFormatName = filename.substring(filename.lastIndexOf('.') + 1).toUpperCase(); au.org.theark.core.model.study.entity.FileFormat fileFormat = new au.org.theark.core.model.study.entity.FileFormat(); fileFormat = iArkCommonService.getFileFormatByName(fileFormatName); containerForm.getModelObject().getUpload().setFileFormat(fileFormat); byte[] byteArray = fileUpload.getMD5(); String checksum = getHex(byteArray); containerForm.getModelObject().getUpload().setChecksum(checksum); containerForm.getModelObject().getUpload().setFilename(fileUpload.getClientFileName()); containerForm.getModelObject().getUpload().setStartTime(new Date(System.currentTimeMillis())); containerForm.getModelObject().setUploadType( uploadTypeDdc.getModelObject() == null ? "Unknown" : uploadTypeDdc.getModelObject().getName()); containerForm.getModelObject().getUpload().setArkFunction( iArkCommonService.getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_BIOSPECIMEN_UPLOAD)); wizardForm.setFileName(fileUpload.getClientFileName()); containerForm.getModelObject().getUpload() .setUploadStatus(iArkCommonService.getUploadStatusFor(Constants.UPLOAD_STATUS_AWAITING_VALIDATION)); try {/*from www .j a v a2 s .c om*/ iArkCommonService.createUpload(containerForm.getModelObject().getUpload()); } catch (Exception e) { error("There is a problem during the upload process."); getWizardForm().onError(target, null); } }
From source file:au.org.theark.lims.web.component.biospecimenupload.form.DetailForm.java
License:Open Source License
@Override protected void onSave(Form<UploadVO> containerForm, AjaxRequestTarget target) { // Implement Save/Update if (containerForm.getModelObject().getUpload().getId() == null) { setMultiPart(true); // multipart required for file uploads // Set study in context Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); // TODO: AJAX-ified and asynchronous and hit database FileUpload fileUpload = fileUploadField.getFileUpload(); Payload payload = iArkCommonService.createPayload(fileUpload.getBytes()); containerForm.getModelObject().getUpload().setPayload(payload); // Set details of Upload object containerForm.getModelObject().getUpload().setStudy(study); byte[] byteArray = fileUpload.getMD5(); String checksum = getHex(byteArray); containerForm.getModelObject().getUpload().setChecksum(checksum); containerForm.getModelObject().getUpload().setFilename(fileUpload.getClientFileName()); // Save//from www . ja va 2 s .com containerForm.getModelObject().getUpload().setArkFunction(arkFunction); containerForm.getModelObject().getUpload() .setUploadStatus(iArkCommonService.getUploadStatusFor(Constants.UPLOAD_STATUS_COMPLETED)); try { iArkCommonService.createUpload(containerForm.getModelObject().getUpload()); } catch (Exception e) { error("There is a problem during the upload process."); processErrors(target); } this.info("Subject upload " + containerForm.getModelObject().getUpload().getFilename() + " was created successfully"); processErrors(target); } else { // Update containerForm.getModelObject().getUpload().setArkFunction(arkFunction); iArkCommonService.updateUpload(containerForm.getModelObject().getUpload()); this.info("Subject upload " + containerForm.getModelObject().getUpload().getFilename() + " was updated successfully"); processErrors(target); } onSavePostProcess(target); /* * TODO:(CE) To handle Business and System Exceptions here */ }
From source file:au.org.theark.lims.web.component.bioupload.BioUploadStep2.java
License:Open Source License
@Override public void onStepInNext(AbstractWizardForm<?> form, AjaxRequestTarget target) { try {/*from w w w .j a v a2 s. com*/ FileUpload fileUpload = containerForm.getModelObject().getFileUpload(); InputStream inputStream = fileUpload.getInputStream();//TODO : should something this big be thrown around model object in wicket? String filename = fileUpload.getClientFileName(); String fileFormat = filename.substring(filename.lastIndexOf('.') + 1).toUpperCase(); char delimChar = containerForm.getModelObject().getUpload().getDelimiterType().getDelimiterCharacter(); // Only allow csv, txt or xls TODO : if we are hardcoding things like this, why do we fetch file formats from db and store as a fk reference? if (!(fileFormat.equalsIgnoreCase("CSV") || fileFormat.equalsIgnoreCase("TXT") || fileFormat.equalsIgnoreCase("XLS"))) { throw new FileFormatException(); } //TODO: remove hardcode if (containerForm.getModelObject().getUpload().getUploadType().getName() .equalsIgnoreCase("Biospecimen Custom Data")) { BioCustomFieldUploadValidator subjectUploadValidator = new BioCustomFieldUploadValidator( iArkCommonService, iLimsService); validationMessages = subjectUploadValidator .validateBiospecimenCustomFieldFileFormat(containerForm.getModelObject()); } else if (containerForm.getModelObject().getUpload().getUploadType().getName() .equalsIgnoreCase("Biocollection Custom Data")) { //TODO : custom field validation BioCustomFieldUploadValidator customFieldUploadValidator = new BioCustomFieldUploadValidator( iArkCommonService, iLimsService); validationMessages = customFieldUploadValidator .validateBiocollectionCustomFieldFileFormat(containerForm.getModelObject()); } else { //TODO : Throw error back to user } ArkExcelWorkSheetAsGrid arkExcelWorkSheetAsGrid = new ArkExcelWorkSheetAsGrid("gridView", inputStream, fileFormat, delimChar, fileUpload, iArkCommonService .getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue(), containerForm.getModelObject().getUpload().getUploadType()); arkExcelWorkSheetAsGrid.setOutputMarkupId(true); WebMarkupContainer wizardDataGridKeyContainer = new WebMarkupContainer("wizardDataGridKeyContainer"); wizardDataGridKeyContainer.setVisible(false); wizardDataGridKeyContainer.setOutputMarkupId(true); form.setArkExcelWorkSheetAsGrid(arkExcelWorkSheetAsGrid); form.getWizardPanelFormContainer().addOrReplace(arkExcelWorkSheetAsGrid); form.setArkExcelWorkSheetAsGrid(arkExcelWorkSheetAsGrid); form.getWizardPanelFormContainer().addOrReplace(wizardDataGridKeyContainer); target.add(form.getWizardPanelFormContainer()); containerForm.getModelObject().setValidationMessages(validationMessages); validationMessage = containerForm.getModelObject().getValidationMessagesAsString(); addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage)); if (validationMessage != null && validationMessage.length() > 0) { log.warn("validation = " + validationMessage); form.getNextButton().setEnabled(false); target.add(form.getWizardButtonContainer()); downloadValMsgButton = new ArkDownloadAjaxButton("downloadValMsg", "ValidationMessage", validationMessage, "txt") { private static final long serialVersionUID = 1L; @Override protected void onError(AjaxRequestTarget target, Form<?> form) { this.error("Unexpected Error: Download request could not be processed"); } }; addOrReplace(downloadValMsgButton); target.add(downloadValMsgButton); } } catch (IOException e) { validationMessage = "Error attempting to display the file. Please check the file and try again."; addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage)); form.getNextButton().setEnabled(false); target.add(form.getWizardButtonContainer()); } catch (FileFormatException ffe) { validationMessage = "Error uploading file. You can only upload files of type: CSV (comma separated values), TXT (text), or XLS (Microsoft Excel file)"; addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage)); form.getNextButton().setEnabled(false); target.add(form.getWizardButtonContainer()); } //TODO : finally? close io? }
From source file:au.org.theark.phenotypic.web.component.phenodataupload.PhenoDataUploadStep2.java
License:Open Source License
@Override public void onStepInNext(AbstractWizardForm<?> form, AjaxRequestTarget target) { if (containerForm.getModelObject().getPreviousStepOutCompleted()) { try {//w w w.j a va 2 s .com FileUpload fileUpload = containerForm.getModelObject().getFileUpload(); InputStream inputStream = fileUpload.getInputStream();//TODO : should something this big be thrown around model object in wicket? String filename = fileUpload.getClientFileName(); String fileFormat = filename.substring(filename.lastIndexOf('.') + 1).toUpperCase(); char delimChar = containerForm.getModelObject().getUpload().getDelimiterType() .getDelimiterCharacter(); // Only allow csv, txt or xls TODO : if we are hardcoding things like this, why do we fetch file formats from db and store as a fk reference? if (!(fileFormat.equalsIgnoreCase("CSV") || fileFormat.equalsIgnoreCase("TXT") || fileFormat.equalsIgnoreCase("XLS"))) { throw new FileFormatException(); } PhenoDataUploadValidator phenoDataUploadValidator = new PhenoDataUploadValidator(iArkCommonService, iPhenotypicService); PhenoDataSetCollection phenoCollectionCriteria = containerForm.getModelObject() .getPhenoCollection(); PhenoDataSetGroup cfgSelected = containerForm.getModelObject().getPhenoDataSetGroup(); try { validationMessages = phenoDataUploadValidator.validateCustomFieldFileFormat( containerForm.getModelObject(), phenoCollectionCriteria, cfgSelected); } catch (ArkBaseException arkBaseException) { validationMessage = arkBaseException.getMessage(); } ArkExcelWorkSheetAsGrid arkExcelWorkSheetAsGrid = new ArkExcelWorkSheetAsGrid("gridView", inputStream, fileFormat, delimChar, fileUpload, iArkCommonService .getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue(), containerForm.getModelObject().getUpload().getUploadType()); arkExcelWorkSheetAsGrid.setOutputMarkupId(true); //WebMarkupContainer wizardDataGridKeyContainer = new WebMarkupContainer("wizardDataGridKeyContainer"); //wizardDataGridKeyContainer.setVisible(false); //wizardDataGridKeyContainer.setOutputMarkupId(true); form.setArkExcelWorkSheetAsGrid(arkExcelWorkSheetAsGrid); form.getWizardPanelFormContainer().addOrReplace(arkExcelWorkSheetAsGrid); form.setArkExcelWorkSheetAsGrid(arkExcelWorkSheetAsGrid); //form.getWizardPanelFormContainer().addOrReplace(wizardDataGridKeyContainer); target.add(form.getWizardPanelFormContainer()); containerForm.getModelObject().setValidationMessages(validationMessages); validationMessage = containerForm.getModelObject().getValidationMessagesAsString(); addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage)); if (validationMessage != null && validationMessage.length() > 0) { this.containerForm.getModelObject().getUpload() .setUploadStatus(iArkCommonService.getUploadStatusFor( au.org.theark.phenotypic.web.Constants.UPLOAD_STATUS_OF_ERROR_IN_FILE_VALIDATION)); this.containerForm.getModelObject().getUpload().setFilename(filename);//have to reset this because the container has the file name...luckily it never changes iArkCommonService.updateUpload(this.containerForm.getModelObject().getUpload()); log.warn("validation = " + validationMessage); form.getNextButton().setEnabled(false); target.add(form.getWizardButtonContainer()); downloadValMsgButton = new ArkDownloadAjaxButton("downloadValMsg", "ValidationMessage", validationMessage, "txt") { private static final long serialVersionUID = 1L; @Override protected void onError(AjaxRequestTarget target, Form<?> form) { this.error("Unexpected Error: Download request could not be processed"); } }; addOrReplace(downloadValMsgButton); target.add(downloadValMsgButton); } } catch (IOException e) { validationMessage = "Error attempting to display the file. Please check the file and try again."; addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage)); form.getNextButton().setEnabled(false); target.add(form.getWizardButtonContainer()); } catch (FileFormatException ffe) { validationMessage = "Error uploading file. You can only upload files of type: CSV (comma separated values), TXT (text), or XLS (Microsoft Excel file)"; addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage)); form.getNextButton().setEnabled(false); target.add(form.getWizardButtonContainer()); } } else { validationMessage = "Step 1 is not completed properly."; addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage)); form.getNextButton().setEnabled(false); target.add(form.getWizardButtonContainer()); } //TODO : finally? close io? }
From source file:au.org.theark.study.web.component.attachments.form.DetailForm.java
License:Open Source License
@Override protected void onSave(Form<SubjectVO> containerForm, AjaxRequestTarget target) { LinkSubjectStudy linkSubjectStudy = null; Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); String userId = SecurityUtils.getSubject().getPrincipal().toString(); try {/* w ww. j av a 2 s .c o m*/ linkSubjectStudy = iArkCommonService.getSubject(sessionPersonId, study); containerForm.getModelObject().getSubjectFile().setLinkSubjectStudy(linkSubjectStudy); // Implement Save/Update if (containerForm.getModelObject().getSubjectFile().getId() == null) { // required for file uploads setMultiPart(true); // Retrieve file and store as Blob in database // TODO: AJAX-ified and asynchronous and hit database FileUpload fileSubjectFile = fileSubjectFileField.getFileUpload(); try { containerForm.getModelObject().getSubjectFile() .setPayload(IOUtils.toByteArray(fileSubjectFile.getInputStream())); } catch (IOException e) { log.error("IOException trying to convert inputstream" + e); } byte[] byteArray = fileSubjectFile.getMD5(); String checksum = getHex(byteArray); // Set details of ConsentFile object containerForm.getModelObject().getSubjectFile().setChecksum(checksum); containerForm.getModelObject().getSubjectFile().setFilename(fileSubjectFile.getClientFileName()); containerForm.getModelObject().getSubjectFile().setUserId(userId); // Save iStudyService.create(containerForm.getModelObject().getSubjectFile()); this.info("Attachment " + containerForm.getModelObject().getSubjectFile().getFilename() + " was created successfully"); // processErrors(target); } else { FileUpload fileSubjectFile = fileSubjectFileField.getFileUpload(); try { containerForm.getModelObject().getSubjectFile() .setPayload(IOUtils.toByteArray(fileSubjectFile.getInputStream())); } catch (IOException e) { log.error("IOException trying to convert inputstream" + e); } byte[] byteArray = fileSubjectFile.getMD5(); String checksum = getHex(byteArray); // Set details of ConsentFile object //containerForm.getModelObject().getSubjectFile().setChecksum(checksum); containerForm.getModelObject().getSubjectFile().setFilename(fileSubjectFile.getClientFileName()); containerForm.getModelObject().getSubjectFile().setUserId(userId); // Update iStudyService.update(containerForm.getModelObject().getSubjectFile(), checksum); this.info("Attachment " + containerForm.getModelObject().getSubjectFile().getFilename() + " was updated successfully"); } processErrors(target); onSavePostProcess(target); AjaxButton deleteButton = (AjaxButton) arkCrudContainerVO.getEditButtonContainer().get("delete"); deleteButton.setEnabled(false); } catch (EntityNotFoundException e) { this.error("The record you tried to update is no longer available in the system"); } catch (ArkSystemException e) { this.error("Saving the file attachment failed. Please contact The Ark administrator."); } processErrors(target); }
From source file:au.org.theark.study.web.component.consent.form.DetailForm.java
License:Open Source License
private void createConsentFile() throws ArkSystemException { FileUpload fileSubjectFile = fileUploadField.getFileUpload(); if (fileSubjectFile != null) { LinkSubjectStudy linkSubjectStudy = null; Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); try {// w ww . jav a 2 s. c om linkSubjectStudy = iArkCommonService.getSubject(sessionPersonId, study); containerForm.getModelObject().getSubjectFile().setLinkSubjectStudy(linkSubjectStudy); containerForm.getModelObject().getSubjectFile() .setPayload(IOUtils.toByteArray(fileSubjectFile.getInputStream())); byte[] byteArray = fileSubjectFile.getMD5(); String checksum = getHex(byteArray); // Set details of Consent File object containerForm.getModelObject().getSubjectFile() .setStudyComp(containerForm.getModelObject().getConsent().getStudyComp()); containerForm.getModelObject().getSubjectFile() .setComments(containerForm.getModelObject().getConsent().getComments()); containerForm.getModelObject().getSubjectFile().setChecksum(checksum); containerForm.getModelObject().getSubjectFile().setFilename(fileSubjectFile.getClientFileName()); containerForm.getModelObject().getSubjectFile() .setUserId(SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal().toString()); // Save iStudyService.create(containerForm.getModelObject().getSubjectFile()); this.info("Consent file: " + containerForm.getModelObject().getSubjectFile().getFilename() + " was created successfully"); } catch (IOException ioe) { log.error("Failed to save the uploaded file: " + ioe); } catch (EntityNotFoundException e) { log.error(e.getMessage()); } } }
From source file:au.org.theark.study.web.component.correspondence.form.DetailForm.java
License:Open Source License
@Override protected void onSave(Form<CorrespondenceVO> containerForm, AjaxRequestTarget target) { CorrespondenceVO correspondenceVO = containerForm.getModelObject(); if (correspondenceVO.getCorrespondence().getId() == null) { if ((correspondenceVO.getWorkRequest() == null && correspondenceVO.getBillableItemType() != null)) { this.error("Work request must be set if a billable item type is specified"); processErrors(target);/*from w ww .ja v a2s . c o m*/ return; } if (correspondenceVO.getWorkRequest() != null && correspondenceVO.getBillableItemType() == null) { this.error("Billable item type must be set if a work request is specified"); processErrors(target); return; } } if (containerForm.getModelObject().getWorkRequest() != null && containerForm.getModelObject().getBillableItemType() != null) { BillableItem billableItem = createAutomatedBillableItem(); containerForm.getModelObject().getCorrespondence().setBillableItem(billableItem); } Long personSessionId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); // get the person and set it on the correspondence object try { // set the Person in context //Person person = studyService.getPerson(personSessionId); // set the Study in context Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); LinkSubjectStudy lss = studyService.getSubjectLinkedToStudy(personSessionId, study); containerForm.getModelObject().getCorrespondence().setLss(lss); //containerForm.getModelObject().getCorrespondence().setStudy(study); if (containerForm.getModelObject().getCorrespondence().getId() == null) { // store correspondence file attachment if (fileUploadField != null && fileUploadField.getFileUpload() != null) { FileUpload fileUpload = fileUploadField.getFileUpload(); byte[] byteArray = fileUpload.getMD5(); String checksum = getHex(byteArray); containerForm.getModelObject().getCorrespondence().setAttachmentPayload(fileUpload.getBytes()); containerForm.getModelObject().getCorrespondence() .setAttachmentFilename(fileUpload.getClientFileName()); containerForm.getModelObject().getCorrespondence().setAttachmentChecksum(checksum); } // save studyService.create(containerForm.getModelObject().getCorrespondence()); this.info("Correspondence was successfully added and linked to subject: " + lss.getSubjectUID()); processErrors(target); } else { // store correspondence file attachment String checksum = null; if (fileUploadField != null && fileUploadField.getFileUpload() != null) { // retrieve file and store as Blob in database FileUpload fileUpload = fileUploadField.getFileUpload(); byte[] byteArray = fileUpload.getMD5(); checksum = getHex(byteArray); containerForm.getModelObject().getCorrespondence().setAttachmentPayload(fileUpload.getBytes()); containerForm.getModelObject().getCorrespondence() .setAttachmentFilename(fileUpload.getClientFileName()); // containerForm.getModelObject().getCorrespondence().setAttachementChecksum(checksum); } studyService.update(containerForm.getModelObject().getCorrespondence(), checksum); this.info("Correspondence was successfully updated and linked to subject: " + lss.getSubjectUID()); processErrors(target); } // invoke backend to persist the correspondence workTrackingContainer.setVisible(false); onSavePostProcess(target); } catch (EntityNotFoundException ex) { ex.printStackTrace(); } catch (ArkSystemException ex) { ex.printStackTrace(); } }
From source file:au.org.theark.study.web.component.managestudy.form.DetailForm.java
License:Open Source License
@Override protected void onSave(Form<StudyModelVO> containerForm, AjaxRequestTarget target) { try {//ww w .j a va 2 s . c o m String message = "Estimated Year of Completion must be greater than Date Of Application"; boolean customValidationFlag = false; if (containerForm.getModelObject().getStudy().getEstimatedYearOfCompletion() != null) { customValidationFlag = validateEstYearOfComp( containerForm.getModelObject().getStudy().getEstimatedYearOfCompletion(), containerForm.getModelObject().getStudy().getDateOfApplication(), message, target); } // Store Study logo image if (fileUploadField != null && fileUploadField.getFileUpload() != null) { // Retrieve file and store as Blob in databasse FileUpload fileUpload = fileUploadField.getFileUpload(); // Copy file to Blob object Blob payload = util.createBlob(fileUpload.getInputStream(), fileUpload.getSize()); containerForm.getModelObject().getStudy().setStudyLogoBlob(payload); containerForm.getModelObject().getStudy().setFilename(fileUpload.getClientFileName()); } if (subjectFileUploadField != null && subjectFileUploadField.getFileUpload() != null) { FileUpload subjectFileUpload = subjectFileUploadField.getFileUpload(); Collection<SubjectVO> selectedSubjects = iArkCommonService.matchSubjectsFromInputFile( subjectFileUpload, containerForm.getModelObject().getStudy().getParentStudy()); // Link subjects in file to the selected study (where matched) containerForm.getModelObject().setSelectedSubjects(selectedSubjects); } if (containerForm.getModelObject().getStudy().getEstimatedYearOfCompletion() != null && customValidationFlag) { // If there was a value provided then upon successful validation proceed with save or update processSaveUpdate(containerForm.getModelObject(), target); } else if (containerForm.getModelObject().getStudy().getEstimatedYearOfCompletion() == null) { // If the value for estimate year of completion was not provided then we can proceed with save or update. processSaveUpdate(containerForm.getModelObject(), target); } } catch (EntityExistsException e) { this.error("The specified study already exists in the system."); log.error(e.getMessage()); } catch (EntityCannotBeRemoved e) { this.error("The Study cannot be removed from the system.There are participants linked to the study"); log.error(e.getMessage()); } catch (IOException e) { this.error("There was an error transferring the specified Study logo image."); log.error(e.getMessage()); } catch (ArkSystemException e) { this.error("A System exception has occurred. Please contact Support"); log.error(e.getMessage()); } catch (UnAuthorizedOperation e) { this.error("You (logged in user) is unauthorised to create/update or archive this study."); log.error(e.getMessage()); } catch (CannotRemoveArkModuleException e) { this.error( "You cannot remove the modules as part of the update. There are System Users who are associated with this study and modules."); log.error(e.getMessage()); } }