List of usage examples for org.apache.wicket.markup.html.basic MultiLineLabel MultiLineLabel
public MultiLineLabel(final String id, IModel<?> model)
From source file:au.org.theark.core.web.component.customfieldupload.CustomFieldUploadStep2.java
License:Open Source License
private void initialiseDetailForm() { setValidationMessage(containerForm.getModelObject().getValidationMessagesAsString()); addOrReplace(new MultiLineLabel("multiLineLabel", getValidationMessage())); add(downloadValMsgButton);//from w ww. j av a 2 s. c o m }
From source file:au.org.theark.core.web.component.customfieldupload.CustomFieldUploadStep2.java
License:Open Source License
@Override public void onStepInNext(AbstractWizardForm<?> form, AjaxRequestTarget target) { //root acording to the field and category File temp = containerForm.getModelObject().getTempFile(); if (temp != null && temp.exists()) { InputStream inputStream = null; try {//from w w w . j a va 2 s. co m String filename = containerForm.getModelObject().getFileUpload().getClientFileName(); String fileFormat = filename.substring(filename.lastIndexOf('.') + 1).toUpperCase(); char delimChar = containerForm.getModelObject().getUpload().getDelimiterType() .getDelimiterCharacter(); // Only allow csv, txt or xls if (!(fileFormat.equalsIgnoreCase("CSV") || fileFormat.equalsIgnoreCase("TXT") || fileFormat.equalsIgnoreCase("XLS"))) { throw new FileFormatException(); } inputStream = new BufferedInputStream(new FileInputStream(temp)); // Field upload if (containerForm.getModelObject().getUpload().getUploadLevel().getName() .equalsIgnoreCase(Constants.UPLOAD_LEVEL_FIELD)) { CustomFieldImportValidator fieldvalidator = new CustomFieldImportValidator(iArkCommonService, containerForm.getModelObject()); validationMessages = fieldvalidator.validateCustomDataMatrixFileFormat(inputStream, fileFormat, delimChar); } //Categoty upload else if (containerForm.getModelObject().getUpload().getUploadLevel().getName() .equalsIgnoreCase(Constants.UPLOAD_LEVEL_CATEGORY)) { CustomFieldCategoryImportValidator categoryValidator = new CustomFieldCategoryImportValidator( iArkCommonService, containerForm.getModelObject()); validationMessages = categoryValidator.validateCustomDataMatrixFileFormat(inputStream, fileFormat, delimChar); } inputStream.close(); inputStream = null; containerForm.getModelObject().setValidationMessages(validationMessages); validationMessage = containerForm.getModelObject().getValidationMessagesAsString(); addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage)); if (validationMessage != null && validationMessage.length() > 0) { 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); } // Show file data FileUpload fileUpload = containerForm.getModelObject().getFileUpload(); inputStream = new BufferedInputStream(new FileInputStream(temp)); 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()); inputStream.close(); inputStream = null; arkExcelWorkSheetAsGrid.setOutputMarkupId(true); form.setArkExcelWorkSheetAsGrid(arkExcelWorkSheetAsGrid); form.getWizardPanelFormContainer().addOrReplace(arkExcelWorkSheetAsGrid); target.add(form.getWizardPanelFormContainer()); } // TODO: Shouldn't catch NPEs because we should be checking for NULL in the first place (inherited from old code) catch (NullPointerException npe) { log.error("NullPointer " + npe.getMessage()); 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 (IOException ioe) { log.error("IOException " + ioe.getMessage()); 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) { log.error("FileFormatException " + ffe.getMessage()); 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()); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { log.error("Unable to close inputStream: " + e.getMessage()); } } } } else { // Stop progress because of missing temp file error("Unexpected erorr: Can not proceed due to missing temporary file."); form.getNextButton().setEnabled(false); } }
From source file:au.org.theark.core.web.component.customfieldupload.CustomFieldUploadStep3.java
License:Open Source License
private void initialiseDetailForm() { setValidationMessage(containerForm.getModelObject().getValidationMessagesAsString()); addOrReplace(new MultiLineLabel("multiLineLabel", getValidationMessage())); add(downloadValMsgButton);//from w w w . j a v a 2 s . c o m updateExistingDataContainer = new WebMarkupContainer("updateExistingDataContainer"); updateExistingDataContainer.setOutputMarkupId(true); updateChkBox = new CheckBox("updateChkBox"); updateChkBox.setVisible(true); containerForm.getModelObject().setUpdateChkBox(false); updateChkBox.add(new AjaxFormComponentUpdatingBehavior("onChange") { private static final long serialVersionUID = -4514605801401294450L; @Override protected void onUpdate(AjaxRequestTarget target) { if (containerForm.getModelObject().getUpdateChkBox()) { wizardForm.getNextButton().setEnabled(true); } else { wizardForm.getNextButton().setEnabled(false); } target.add(wizardForm.getWizardButtonContainer()); } }); updateExistingDataContainer.add(updateChkBox); add(updateExistingDataContainer); }
From source file:au.org.theark.core.web.component.customfieldupload.CustomFieldUploadStep3.java
License:Open Source License
/** * //w w w .j a v a 2 s .co m * @param form * @param target */ private void displayValidationMessagesAndButtons(AbstractWizardForm<?> form, AjaxRequestTarget target) { containerForm.getModelObject().setValidationMessages(validationMessages); validationMessage = containerForm.getModelObject().getValidationMessagesAsString(); addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage)); if (validationMessage != null && validationMessage.length() > 0) { 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); } }
From source file:au.org.theark.lims.web.component.biospecimenupload.BiospecimenUploadStep2.java
License:Open Source License
@Override public void onStepInNext(AbstractWizardForm<?> form, AjaxRequestTarget target) { try {// ww w .ja v a2 s. c o m InputStream inputStream = containerForm.getModelObject().getFileUpload().getInputStream(); FileUpload fileUpload = containerForm.getModelObject().getFileUpload(); String uploadType = containerForm.getModelObject().getUploadType(); log.info("so what is the upload type =" + uploadType); String filename = containerForm.getModelObject().getFileUpload().getClientFileName(); String fileFormat = filename.substring(filename.lastIndexOf('.') + 1).toUpperCase(); char delimChar = containerForm.getModelObject().getUpload().getDelimiterType().getDelimiterCharacter(); // Only allow csv, txt or xls if (!(fileFormat.equalsIgnoreCase("CSV") || fileFormat.equalsIgnoreCase("TXT") || fileFormat.equalsIgnoreCase("XLS"))) { throw new FileFormatException(); } BioCollectionSpecimenUploadValidator bioCollectionSpecimenUploadValidator = new BioCollectionSpecimenUploadValidator( containerForm.getModelObject().getUpload().getStudy(), iArkCommonService, iLimsService, iInventoryService); if (uploadType.equalsIgnoreCase(Constants.UPLOAD_TYPE_FOR_BIOCOLLECTION)) { validationMessages = bioCollectionSpecimenUploadValidator.validateLimsFileFormatAndHeaderDetail( containerForm.getModelObject(), au.org.theark.core.Constants.BIOCOLLECTION_TEMPLATE_HEADER); } else if (uploadType.equalsIgnoreCase(Constants.UPLOAD_TYPE_FOR_BIOSPECIMEN_INVENTARY)) { validationMessages = bioCollectionSpecimenUploadValidator.validateLimsFileFormatAndHeaderDetail( containerForm.getModelObject(), au.org.theark.core.Constants.BIOSPECIMEN_INVENTORY_TEMPLATE_HEADER); } else if (uploadType.equalsIgnoreCase(Constants.UPLOAD_TYPE_FOR_BIOSPECIMEN)) { validationMessages = bioCollectionSpecimenUploadValidator.validateLimsFileFormatAndHeaderDetail( containerForm.getModelObject(), au.org.theark.core.Constants.BIOSPECIMEN_TEMPLATE_HEADER); } containerForm.getModelObject().setValidationMessages(validationMessages); validationMessage = containerForm.getModelObject().getValidationMessagesAsString(); addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage)); ArkExcelWorkSheetAsGrid arkExcelWorkSheetAsGrid = new ArkExcelWorkSheetAsGrid("gridView", inputStream, fileFormat, delimChar, fileUpload, iArkCommonService .getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue()); 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.lims.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()); 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()); } }
From source file:au.org.theark.lims.web.component.biospecimenupload.BiospecimenUploadStep3.java
License:Open Source License
private void initialiseDetailForm() { setValidationMessage(containerForm.getModelObject().getValidationMessagesAsString()); addOrReplace(new MultiLineLabel("multiLineLabel", getValidationMessage())); add(downloadValMsgButton);/*from w w w . ja v a2 s.co m*/ updateExistingDataContainer = new WebMarkupContainer("updateExistingDataContainer"); updateExistingDataContainer.setOutputMarkupId(true); updateChkBox = new CheckBox("updateChkBox"); updateChkBox.setVisible(true); updateChkBox.add(new AjaxFormComponentUpdatingBehavior("onChange") { private static final long serialVersionUID = -4514605801401294450L; @Override protected void onUpdate(AjaxRequestTarget target) { if (containerForm.getModelObject().getUpdateChkBox()) { wizardForm.getNextButton().setEnabled(true); } else { wizardForm.getNextButton().setEnabled(false); } target.add(wizardForm.getWizardButtonContainer()); } }); updateExistingDataContainer.add(updateChkBox); add(updateExistingDataContainer); }
From source file:au.org.theark.lims.web.component.biospecimenupload.BiospecimenUploadStep3.java
License:Open Source License
@Override public void onStepInNext(AbstractWizardForm<?> form, AjaxRequestTarget target) { try {//from www . j a va 2 s . c om String filename = containerForm.getModelObject().getFileUpload().getClientFileName(); String fileFormat = filename.substring(filename.lastIndexOf('.') + 1).toUpperCase(); char delimiterChar = containerForm.getModelObject().getUpload().getDelimiterType() .getDelimiterCharacter(); InputStream inputStream = containerForm.getModelObject().getFileUpload().getInputStream(); String uploadType = containerForm.getModelObject().getUploadType(); BioCollectionSpecimenUploadValidator biospecimenUploadValidator = new BioCollectionSpecimenUploadValidator( containerForm.getModelObject().getUpload().getStudy(), iArkCommonService, iLimsService, iInventoryService); log.info("upload type ---=" + uploadType); if (uploadType.equalsIgnoreCase(Constants.UPLOAD_TYPE_FOR_BIOCOLLECTION)) { validationMessages = biospecimenUploadValidator .validateBiocollectionFileData(containerForm.getModelObject()); } else if (uploadType.equalsIgnoreCase(Constants.UPLOAD_TYPE_FOR_BIOSPECIMEN_INVENTARY)) { validationMessages = biospecimenUploadValidator .validateBiospecimenInvetoryFileData(containerForm.getModelObject()); } else if (uploadType.equalsIgnoreCase(Constants.UPLOAD_TYPE_FOR_BIOSPECIMEN)) { validationMessages = biospecimenUploadValidator .validateBiospecimenFileData(containerForm.getModelObject()); } this.containerForm.getModelObject().setValidationMessages(validationMessages); validationMessage = containerForm.getModelObject().getValidationMessagesAsString(); addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage)); HashSet<Integer> insertRows = new HashSet<Integer>(); HashSet<Integer> updateRows = new HashSet<Integer>(); HashSet<ArkGridCell> errorCells = new HashSet<ArkGridCell>(); insertRows = biospecimenUploadValidator.getInsertRows(); updateRows = biospecimenUploadValidator.getUpdateRows(); errorCells = biospecimenUploadValidator.getErrorCells(); // Show file data (and key reference) ArkExcelWorkSheetAsGrid arkExcelWorkSheetAsGrid = new ArkExcelWorkSheetAsGrid("gridView", inputStream, fileFormat, delimiterChar, containerForm.getModelObject().getFileUpload(), insertRows, updateRows, errorCells); arkExcelWorkSheetAsGrid.setOutputMarkupId(true); arkExcelWorkSheetAsGrid.getWizardDataGridKeyContainer().setVisible(true); form.setArkExcelWorkSheetAsGrid(arkExcelWorkSheetAsGrid); form.getWizardPanelFormContainer().addOrReplace(arkExcelWorkSheetAsGrid); // Repaint target.add(arkExcelWorkSheetAsGrid.getWizardDataGridKeyContainer()); target.add(form.getWizardPanelFormContainer()); if (updateRows.isEmpty()) { updateExistingDataContainer.setVisible(false); target.add(updateExistingDataContainer); } if (!errorCells.isEmpty()) { updateExistingDataContainer.setVisible(false); target.add(updateExistingDataContainer); form.getNextButton().setEnabled(false); target.add(form.getWizardButtonContainer()); this.containerForm.getModelObject().getUpload() .setUploadStatus(iArkCommonService.getUploadStatusFor( au.org.theark.lims.web.Constants.UPLOAD_STATUS_OF_ERROR_IN_DATA_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()); } else { this.containerForm.getModelObject().getUpload().setUploadStatus(iArkCommonService .getUploadStatusFor(au.org.theark.lims.web.Constants.UPLOAD_STATUS_OF_VALIDATED)); 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()); } } catch (IOException e) { validationMessage = "Error attempting to display the file. Please check the file and try again."; addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage)); } containerForm.getModelObject().setValidationMessages(validationMessages); validationMessage = containerForm.getModelObject().getValidationMessagesAsString(); addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage)); if (validationMessage != null && validationMessage.length() > 0) { 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); } }
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 a 2 s .c o m 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.lims.web.component.bioupload.BioUploadStep3.java
License:Open Source License
@Override public void onStepInNext(AbstractWizardForm<?> form, AjaxRequestTarget target) { try {//from w ww . j a va 2s . c om String filename = containerForm.getModelObject().getFileUpload().getClientFileName(); String fileFormat = filename.substring(filename.lastIndexOf('.') + 1).toUpperCase(); char delimiterChar = containerForm.getModelObject().getUpload().getDelimiterType() .getDelimiterCharacter(); InputStream inputStream = containerForm.getModelObject().getFileUpload().getInputStream(); HashSet<Integer> insertRows = new HashSet<Integer>(); HashSet<Integer> updateRows = new HashSet<Integer>(); HashSet<ArkGridCell> errorCells = new HashSet<ArkGridCell>(); //this is not the best way to do this fix TODO List<String> listOfUidsToUpdate = new ArrayList<String>(); //TODO remove hardcoding if (containerForm.getModelObject().getUpload().getUploadType().getName() .equalsIgnoreCase("Biospecimen Custom Data")) { BioCustomFieldUploadValidator customFieldUploadValidator = new BioCustomFieldUploadValidator( iArkCommonService, iLimsService); validationMessages = customFieldUploadValidator .validateBiospecimenCustomFieldFileData(containerForm.getModelObject(), listOfUidsToUpdate); containerForm.getModelObject().setUidsToUpload(listOfUidsToUpdate); insertRows = customFieldUploadValidator.getInsertRows(); updateRows = customFieldUploadValidator.getUpdateRows(); errorCells = customFieldUploadValidator.getErrorCells(); } //TODO remove hardcoding else if (containerForm.getModelObject().getUpload().getUploadType().getName() .equalsIgnoreCase("Biocollection Custom Data")) { BioCustomFieldUploadValidator customFieldUploadValidator = new BioCustomFieldUploadValidator( iArkCommonService, iLimsService); validationMessages = customFieldUploadValidator.validateBiocollectionCustomFieldFileData( containerForm.getModelObject(), listOfUidsToUpdate); containerForm.getModelObject().setUidsToUpload(listOfUidsToUpdate); //TODO consider if we want alternative way to do this - and maybe a superclass of uploadvalidator which draws out commonalities insertRows = customFieldUploadValidator.getInsertRows(); updateRows = customFieldUploadValidator.getUpdateRows(); errorCells = customFieldUploadValidator.getErrorCells(); } else { //TODO : Throw error back to user } this.containerForm.getModelObject().setValidationMessages(validationMessages); validationMessage = containerForm.getModelObject().getValidationMessagesAsString(); addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage)); // Show file data (and key reference) ArkExcelWorkSheetAsGrid arkExcelWorkSheetAsGrid = new ArkExcelWorkSheetAsGrid("gridView", inputStream, fileFormat, delimiterChar, containerForm.getModelObject().getFileUpload(), insertRows, updateRows, errorCells, containerForm.getModelObject().getUpload().getUploadType()); arkExcelWorkSheetAsGrid.setOutputMarkupId(true); arkExcelWorkSheetAsGrid.getWizardDataGridKeyContainer().setVisible(true); form.setArkExcelWorkSheetAsGrid(arkExcelWorkSheetAsGrid); form.getWizardPanelFormContainer().addOrReplace(arkExcelWorkSheetAsGrid); // Repaint target.add(arkExcelWorkSheetAsGrid.getWizardDataGridKeyContainer()); target.add(form.getWizardPanelFormContainer()); //TODO remove hardcoding if (updateRows.isEmpty() || containerForm.getModelObject().getUpload().getUploadType().getName() .equalsIgnoreCase("Study-specific (custom) Data")) { updateExistingDataContainer.setVisible(false); target.add(updateExistingDataContainer); } if (!errorCells.isEmpty()) { updateExistingDataContainer.setVisible(false); target.add(updateExistingDataContainer); form.getNextButton().setEnabled(false); target.add(form.getWizardButtonContainer()); } } catch (IOException e) { validationMessage = "Error attempting to display the file. Please check the file and try again."; addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage)); } containerForm.getModelObject().setValidationMessages(validationMessages); validationMessage = containerForm.getModelObject().getValidationMessagesAsString(); addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage)); if (validationMessage != null && validationMessage.length() > 0) { form.getNextButton().setEnabled(false); target.add(form.getWizardButtonContainer()); downloadValMsgButton = new ArkDownloadAjaxButton("downloadValMsg", "ValidationMessage", validationMessage, "txt") { /** * */ private static final long serialVersionUID = 343293022422099247L; @Override protected void onError(AjaxRequestTarget target, Form<?> form) { this.error("Unexpected Error: Download request could not be processed"); } }; addOrReplace(downloadValMsgButton); target.add(downloadValMsgButton); } }
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 {/*from ww w . jav 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(); } 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? }