List of usage examples for org.apache.shiro SecurityUtils getSubject
public static Subject getSubject()
From source file:au.org.theark.report.web.component.dataextraction.form.DetailForm.java
License:Open Source License
@SuppressWarnings("unchecked") private void initBiospecimenCustomFieldDisplaysModulePalette() { CompoundPropertyModel<SearchVO> searchCPM = (CompoundPropertyModel<SearchVO>) containerForm.getModel(); IChoiceRenderer<String> renderer = new ChoiceRenderer<String>("customField.name", "id"); PropertyModel<Collection<CustomFieldDisplay>> selectedBiospecimenCustomFieldDisplaysPm = new PropertyModel<Collection<CustomFieldDisplay>>( searchCPM, "selectedBiospecimenCustomFieldDisplays");// "selectedDemographicFields"); Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); ArkFunction arkFunction = iArkCommonService .getArkFunctionByName(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_LIMS_CUSTOM_FIELD); CustomFieldType customFieldType = iArkCommonService .getCustomFieldTypeByName(au.org.theark.core.Constants.BIOSPECIMEN); Collection<CustomFieldDisplay> availableBiospecimenCustomFieldDisplays = iArkCommonService .getCustomFieldDisplaysInLIMS(study, arkFunction, customFieldType); containerForm.getModelObject()//w w w . j a v a2 s . c o m .setAvailableBiospecimenCustomFieldDisplays(availableBiospecimenCustomFieldDisplays); PropertyModel<Collection<CustomFieldDisplay>> availableBiospecimenCustomFieldDisplayPm = new PropertyModel<Collection<CustomFieldDisplay>>( searchCPM, "availableBiospecimenCustomFieldDisplays"); biospecimenCustomFieldDisplaysToReturnPalette = new ArkPalette("selectedBiospecimenCustomFieldDisplays", selectedBiospecimenCustomFieldDisplaysPm, availableBiospecimenCustomFieldDisplayPm, renderer, PALETTE_ROWS, false); biospecimenCustomFieldDisplaysToReturnPalette.setOutputMarkupId(true); }
From source file:au.org.theark.report.web.component.dataextraction.form.DetailForm.java
License:Open Source License
@SuppressWarnings("unchecked") private void initBiocollectionCustomFieldDisplaysModulePalette() { CompoundPropertyModel<SearchVO> searchCPM = (CompoundPropertyModel<SearchVO>) containerForm.getModel(); IChoiceRenderer<String> renderer = new ChoiceRenderer<String>("customField.name", "id"); PropertyModel<Collection<CustomFieldDisplay>> selectedBiocollectionCustomFieldDisplaysPm = new PropertyModel<Collection<CustomFieldDisplay>>( searchCPM, "selectedBiocollectionCustomFieldDisplays");// "selectedDemographicFields"); Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); ArkFunction arkFunction = iArkCommonService .getArkFunctionByName(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_LIMS_CUSTOM_FIELD); CustomFieldType customFieldType = iArkCommonService .getCustomFieldTypeByName(au.org.theark.core.Constants.BIOCOLLECTION); Collection<CustomFieldDisplay> availableBiocollectionCustomFieldDisplays = iArkCommonService .getCustomFieldDisplaysInLIMS(study, arkFunction, customFieldType); containerForm.getModelObject()// ww w . j av a2 s . c o m .setAvailableBiocollectionCustomFieldDisplays(availableBiocollectionCustomFieldDisplays); PropertyModel<Collection<CustomFieldDisplay>> availableBiocollectionCustomFieldDisplayPm = new PropertyModel<Collection<CustomFieldDisplay>>( searchCPM, "availableBiocollectionCustomFieldDisplays"); biocollectionCustomFieldDisplaysToReturnPalette = new ArkPalette("selectedBiocollectionCustomFieldDisplays", selectedBiocollectionCustomFieldDisplaysPm, availableBiocollectionCustomFieldDisplayPm, renderer, PALETTE_ROWS, false); biocollectionCustomFieldDisplaysToReturnPalette.setOutputMarkupId(true); }
From source file:au.org.theark.report.web.component.dataextraction.form.DetailForm.java
License:Open Source License
private void createSearchFile() { FileUpload fileSubjectFile = fileUploadField.getFileUpload(); if (fileSubjectFile != null) { Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); try {/*ww w . j av a 2s. c om*/ if (containerForm.getModelObject().getSearchFile() == null) { containerForm.getModelObject().setSearchFile(new SearchFile()); } // store search file attachment if (fileSubjectFile != null) { byte[] byteArray = fileSubjectFile.getMD5(); String checksum = getHex(byteArray); containerForm.getModelObject().getSearchFile().setStudy(study); containerForm.getModelObject().getSearchFile() .setSearch(containerForm.getModelObject().getSearch()); containerForm.getModelObject().getSearchFile() .setPayload(IOUtils.toByteArray(fileSubjectFile.getInputStream())); containerForm.getModelObject().getSearchFile().setFilename(fileSubjectFile.getClientFileName()); containerForm.getModelObject().getSearchFile().setChecksum(checksum); containerForm.getModelObject().getSearchFile() .setFileId(iArkCommonService.generateArkFileId(fileSubjectFile.getClientFileName())); containerForm.getModelObject().getSearchFile() .setUserId(SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal().toString()); } // Save reportService.create(containerForm.getModelObject().getSearchFile(), au.org.theark.report.web.Constants.REPORT_DATA_EXTRACTION_SUBJECT_UID_RESTRICT_FILE); } catch (IOException ioe) { log.error("Failed to save the uploaded file: " + ioe); } catch (ArkSystemException e) { log.error("Failed to save the uploaded file: " + e); } } }
From source file:au.org.theark.report.web.component.dataextraction.form.SearchForm.java
License:Open Source License
/** * //w ww .java 2 s.c om * @param id * @param cpmModel * @param arkCrudContainerVO * @param feedBackPanel * @param listView */ public SearchForm(String id, CompoundPropertyModel<SearchVO> cpmModel, ArkCrudContainerVO arkCrudContainerVO, FeedbackPanel feedBackPanel, PageableListView<Search> listView) { super(id, cpmModel, feedBackPanel, arkCrudContainerVO); this.arkCrudContainerVO = arkCrudContainerVO; this.feedbackPanel = feedBackPanel; this.listView = listView; initialiseSearchForm(); addSearchComponentsToForm(); Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); //Add the study for model object not sure why ignores................. getModelObject().getSearch().setStudy(iArkCommonService.getStudy(sessionStudyId)); disableSearchForm(sessionStudyId, "There is no study selected. Please select a study."); }
From source file:au.org.theark.report.web.component.dataextraction.form.SearchForm.java
License:Open Source License
@Override protected void onNew(AjaxRequestTarget target) { // getModelObject().setMode(Constants.MODE_NEW); // getModelObject().getStudyComponent().setId(null); SearchVO searchVo = new SearchVO();// containerForm.getModelObject(); //searchVo.setMode(Constants.MODE_EDIT); searchVo.setSearch(new Search());// Sets the selected object into the model Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); Search search = searchVo.getSearch(); search.setStudy(study);//from www. ja v a 2 s . co m Collection<DemographicField> availableDemographicFields = iArkCommonService.getAllDemographicFields(); this.getModelObject().setAvailableDemographicFields(availableDemographicFields); Collection<DemographicField> selectedDemographicFields = new ArrayList<DemographicField>();//iArkCommonService.getSelectedDemographicFieldsForSearch(search);//, true); this.getModelObject().setSelectedDemographicFields(selectedDemographicFields); Collection<BiospecimenField> availableBiospecimenFields = iArkCommonService.getAllBiospecimenFields(); this.getModelObject().setAvailableBiospecimenFields(availableBiospecimenFields); Collection<BiospecimenField> selectedBiospecimenFields = new ArrayList<BiospecimenField>();//iArkCommonService.getSelectedBiospecimenFieldsForSearch(search);//, true); this.getModelObject().setSelectedBiospecimenFields(selectedBiospecimenFields); Collection<BiocollectionField> availableBiocollectionFields = iArkCommonService.getAllBiocollectionFields(); this.getModelObject().setAvailableBiocollectionFields(availableBiocollectionFields); Collection<BiocollectionField> selectedBiocollectionFields = new ArrayList<BiocollectionField>();//iArkCommonService.getSelectedBiocollectionFieldsForSearch(search);//, true); this.getModelObject().setSelectedBiocollectionFields(selectedBiocollectionFields); ArkFunction arkFunctionPheno = iArkCommonService .getArkFunctionByName(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_PHENO_COLLECTION); //ArkFunction arkFunctionBiocollection = iArkCommonService.getArkFunctionByName(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_LIMS_COLLECTION); ArkFunction arkFunctionBiocollection = iArkCommonService .getArkFunctionByName(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_LIMS_CUSTOM_FIELD); ArkFunction arkFunctionBiospecimen = iArkCommonService .getArkFunctionByName(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_BIOSPECIMEN); ArkFunction arkFunctionSubject = iArkCommonService .getArkFunctionByName(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_SUBJECT_CUSTOM_FIELD); Collection<PhenoDataSetFieldDisplay> availablePhenoDataSetFieldDisplays = iPhenoService .getPhenoFieldDisplaysIn(study, arkFunctionPheno); this.getModelObject().setAvailablePhenoDataSetFieldDisplays(availablePhenoDataSetFieldDisplays); Collection<PhenoDataSetFieldDisplay> selectedPhenoCustomFieldDisplays = new ArrayList<PhenoDataSetFieldDisplay>();//iArkCommonService.getSelectedPhenoCustomFieldDisplaysForSearch(search);//, true); this.getModelObject().setSelectedPhenoDataSetFieldDisplays(selectedPhenoCustomFieldDisplays); Collection<CustomFieldDisplay> availableSubjectCustomFieldDisplays = iArkCommonService .getCustomFieldDisplaysIn(study, arkFunctionSubject); this.getModelObject().setAvailableSubjectCustomFieldDisplays(availableSubjectCustomFieldDisplays); Collection<CustomFieldDisplay> selectedSubjectCustomFieldDisplays = new ArrayList<CustomFieldDisplay>();//iArkCommonService.getSelectedSubjectCustomFieldDisplaysForSearch(search);//, true); this.getModelObject().setSelectedSubjectCustomFieldDisplays(selectedSubjectCustomFieldDisplays); Collection<CustomFieldDisplay> availableBiocollectionCustomFieldDisplays = iArkCommonService .getCustomFieldDisplaysIn(study, arkFunctionBiocollection); this.getModelObject() .setAvailableBiocollectionCustomFieldDisplays(availableBiocollectionCustomFieldDisplays); Collection<CustomFieldDisplay> selectedBiocollectionCustomFieldDisplays = new ArrayList<CustomFieldDisplay>();//iArkCommonService.getSelectedBiocollectionCustomFieldDisplaysForSearch(search);//, true); this.getModelObject().setSelectedBiocollectionCustomFieldDisplays(selectedBiocollectionCustomFieldDisplays); Collection<CustomFieldDisplay> availableBiospecimenCustomFieldDisplays = iArkCommonService .getCustomFieldDisplaysIn(study, arkFunctionBiospecimen); this.getModelObject().setAvailableBiospecimenCustomFieldDisplays(availableBiospecimenCustomFieldDisplays); Collection<CustomFieldDisplay> selectedBiospecimenCustomFieldDisplays = new ArrayList<CustomFieldDisplay>();//iArkCommonService.getSelectedBiospecimenCustomFieldDisplaysForSearch(search);//, true); this.getModelObject().setSelectedBiospecimenCustomFieldDisplays(selectedBiospecimenCustomFieldDisplays); preProcessDetailPanel(target); }
From source file:au.org.theark.report.web.component.dataextraction.SearchResultListPanel.java
License:Open Source License
@SuppressWarnings({ "unchecked", "serial" }) private AjaxLink buildLink(final Search search) { ArkBusyAjaxLink link = new ArkBusyAjaxLink("search.name") { @Override//ww w. ja va 2 s .c om public void onClick(AjaxRequestTarget target) { SearchVO searchVo = containerForm.getModelObject(); //searchVo.setMode(Constants.MODE_EDIT); searchVo.setSearch(search);// Sets the selected object into the model Collection<DemographicField> availableDemographicFields = iArkCommonService .getAllDemographicFields(); containerForm.getModelObject().setAvailableDemographicFields(availableDemographicFields); Collection<DemographicField> selectedDemographicFields = iArkCommonService .getSelectedDemographicFieldsForSearch(search);//, true); containerForm.getModelObject().setSelectedDemographicFields(selectedDemographicFields); Collection<ConsentStatusField> availableConsentStatusFields = iArkCommonService .getAllConsentStatusFields(); containerForm.getModelObject().setAvailableConsentStatusFields(availableConsentStatusFields); Collection<ConsentStatusField> selectedConsentStatusFields = iArkCommonService .getSelectedConsentStatusFieldsForSearch(search); containerForm.getModelObject().setSelectedConsentStatusFields(selectedConsentStatusFields); Collection<BiospecimenField> availableBiospecimenFields = iArkCommonService .getAllBiospecimenFields(); containerForm.getModelObject().setAvailableBiospecimenFields(availableBiospecimenFields); Collection<BiospecimenField> selectedBiospecimenFields = iArkCommonService .getSelectedBiospecimenFieldsForSearch(search);//, true); containerForm.getModelObject().setSelectedBiospecimenFields(selectedBiospecimenFields); Collection<BiocollectionField> availableBiocollectionFields = iArkCommonService .getAllBiocollectionFields(); containerForm.getModelObject().setAvailableBiocollectionFields(availableBiocollectionFields); Collection<BiocollectionField> selectedBiocollectionFields = iArkCommonService .getSelectedBiocollectionFieldsForSearch(search);//, true); containerForm.getModelObject().setSelectedBiocollectionFields(selectedBiocollectionFields); Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); ArkFunction arkFunctionPheno = iArkCommonService .getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_DATA_DICTIONARY); ArkFunction arkFunctionLIMS = iArkCommonService .getArkFunctionByName(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_LIMS_CUSTOM_FIELD); CustomFieldType cusFldTypeBioCollection = iArkCommonService .getCustomFieldTypeByName(au.org.theark.core.Constants.BIOCOLLECTION); CustomFieldType cusFldTypeBiospecimen = iArkCommonService .getCustomFieldTypeByName(au.org.theark.core.Constants.BIOSPECIMEN); ArkFunction arkFunctionSubject = iArkCommonService .getArkFunctionByName(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_SUBJECT_CUSTOM_FIELD); SearchFile searchFile = reportService.getSearchFileByStudyAndSearch(study, search); containerForm.getModelObject().setSearchFile(searchFile); Collection<PhenoDataSetFieldDisplay> availablePhenoDataSetFieldDisplays = iPhenoService .getPhenoFieldDisplaysIn(study, arkFunctionPheno); containerForm.getModelObject() .setAvailablePhenoDataSetFieldDisplays(availablePhenoDataSetFieldDisplays); Collection<PhenoDataSetFieldDisplay> selectedPhenoDataSetFieldDisplays = iArkCommonService .getSelectedPhenoDataSetFieldDisplaysForSearch(search);//, true); containerForm.getModelObject() .setSelectedPhenoDataSetFieldDisplays(selectedPhenoDataSetFieldDisplays); Collection<CustomFieldDisplay> availableSubjectCustomFieldDisplays = iArkCommonService .getCustomFieldDisplaysIn(study, arkFunctionSubject); containerForm.getModelObject() .setAvailableSubjectCustomFieldDisplays(availableSubjectCustomFieldDisplays); Collection<CustomFieldDisplay> selectedSubjectCustomFieldDisplays = iArkCommonService .getSelectedSubjectCustomFieldDisplaysForSearch(search);//, true); containerForm.getModelObject() .setSelectedSubjectCustomFieldDisplays(selectedSubjectCustomFieldDisplays); Collection<CustomFieldDisplay> availableBiocollectionCustomFieldDisplays = iArkCommonService .getCustomFieldDisplaysInLIMS(study, arkFunctionLIMS, cusFldTypeBioCollection); containerForm.getModelObject() .setAvailableBiocollectionCustomFieldDisplays(availableBiocollectionCustomFieldDisplays); Collection<CustomFieldDisplay> selectedBiocollectionCustomFieldDisplays = iArkCommonService .getSelectedLIMSCustomFieldDisplaysForSearchOnCustomFieldType(search, cusFldTypeBioCollection); containerForm.getModelObject() .setSelectedBiocollectionCustomFieldDisplays(selectedBiocollectionCustomFieldDisplays); Collection<CustomFieldDisplay> availableBiospecimenCustomFieldDisplays = iArkCommonService .getCustomFieldDisplaysInLIMS(study, arkFunctionLIMS, cusFldTypeBiospecimen); containerForm.getModelObject() .setAvailableBiospecimenCustomFieldDisplays(availableBiospecimenCustomFieldDisplays); Collection<CustomFieldDisplay> selectedBiospecimenCustomFieldDisplays = iArkCommonService .getSelectedLIMSCustomFieldDisplaysForSearchOnCustomFieldType(search, cusFldTypeBiospecimen);//, true); containerForm.getModelObject() .setSelectedBiospecimenCustomFieldDisplays(selectedBiospecimenCustomFieldDisplays); //Update the Create Filter button. AjaxButton ajaxButton = (AjaxButton) arkCrudContainerVO.getDetailPanelFormContainer() .get("createFilters"); ajaxButton.add(new AttributeModifier("value", new Model<String>( iArkCommonService.isAnyFilterAddedForSearch(search) ? "Edit Filters" : "Create Filters"))); target.add(ajaxButton); target.add(arkCrudContainerVO.getDetailPanelFormContainer()); // Render the UI ArkCRUDHelper.preProcessDetailPanelOnSearchResults(target, arkCrudContainerVO); } }; // Add the label for the link Label nameLinkLabel = new Label("nameLbl", search.getName()); link.add(nameLinkLabel); return link; }
From source file:au.org.theark.report.web.component.dataextraction.SearchResultListPanel.java
License:Open Source License
private AjaxButton buildRunSearchButton(final Search search) { AjaxButton ajaxButton = new AjaxButton(au.org.theark.report.web.Constants.RUN_BATCH_QUERY) { private static final long serialVersionUID = 1L; @Override/*from w w w .j a va 2 s . c o m*/ protected void onSubmit(AjaxRequestTarget target, Form<?> form) { //TODO ASAP : this will be replaced by call to job //iArkCommonService.runSearch(search.getId()); try { SecurityUtils.getSubject(); search.setStartTime(new java.util.Date(System.currentTimeMillis())); search.setStatus("RUNNING"); search.setFinishTime(null); iArkCommonService.update(search); String currentUser = SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal() .toString(); DataExtractionUploadExecutor task = new DataExtractionUploadExecutor(iArkCommonService, search.getId(), currentUser);//, studyId); task.run(); target.add(SearchResultListPanel.this); target.appendJavaScript( "alert('Data files are being created as a background job. You may download when complete.');"); } catch (Exception e) { // TODO Auto-generated catch block System.out.println("TODO: decent logging and handling" + e.getMessage()); e.printStackTrace(); } finally { } } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { this.error("A system error occurred. Could not process download request"); }; @Override public boolean isVisible() { //TODO return correct status return search.getStatus() != null && !search.getStatus().equalsIgnoreCase("RUNNING"); //return search.getStatus() != null && search.getStatus().equalsIgnoreCase("READY TO RUN") || true; } }; //ajaxButton.setVisible(true); ajaxButton.setDefaultFormProcessing(false); //log.warn("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n how many times is this run?"); //TODO move back //if (upload.getPayload() == null) //if (data == null) //ajaxButton.setVisible(false); return ajaxButton; }
From source file:au.org.theark.report.web.component.viewReport.consentDetails.filterForm.ConsentDetailsFilterForm.java
License:Open Source License
protected void onGenerateProcess(AjaxRequestTarget target) { Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(sessionStudyId); cpModel.getObject().getLinkSubjectStudy().setStudy(study); String reportTitle = study.getName() + " - Study Component Consent Details Report"; if (cpModel.getObject().getStudyComp() != null) { String studyComponent = cpModel.getObject().getStudyComp().getName(); reportTitle += " - " + studyComponent; }//from w ww.j a va2s . c om ReportTemplate reportTemplate = cpModel.getObject().getSelectedReportTemplate(); ReportOutputFormat reportOutputFormat = cpModel.getObject().getSelectedOutputFormat(); // show report ServletContext context = ((WebApplication) getApplication()).getServletContext(); File reportFile = null; reportFile = new File(context.getRealPath("/reportTemplates/" + reportTemplate.getTemplatePath())); JasperDesign design = null; JasperReport report = null; try { design = JRXmlLoader.load(reportFile); // System.out.println(" design -- created " ); if (design != null) { design.setName(reportTitle); // set the output file name to match report title if (reportOutputFormat.getName().equals(au.org.theark.report.service.Constants.CSV_REPORT_FORMAT)) { design.setIgnorePagination(true); // don't paginate CSVs } report = JasperCompileManager.compileReport(design); // System.out.println(" design -- compiled " ); } } catch (JRException e) { reportFile = null; e.printStackTrace(); } // templateIS = getClass().getResourceAsStream("/reportTemplates/WebappReport.jrxml"); final Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("BaseDir", new File(context.getRealPath("/reportTemplates"))); parameters.put("ReportTitle", reportTitle); Subject currentUser = SecurityUtils.getSubject(); String userName = "(unknown)"; if (currentUser.getPrincipal() != null) { userName = (String) currentUser.getPrincipal(); } parameters.put("UserName", userName); ConsentDetailsReportDataSource reportDS = new ConsentDetailsReportDataSource(reportService, cpModel.getObject()); JRResource reportResource = null; if (reportOutputFormat.getName().equals(au.org.theark.report.service.Constants.PDF_REPORT_FORMAT)) { final JRResource pdfResource = new JRConcreteResource<PdfResourceHandler>(new PdfResourceHandler()); pdfResource.setJasperReport(report); pdfResource.setReportParameters(parameters).setReportDataSource(reportDS); // This code would emulate a file download as if clicked the user // clicked on the download link, but unfortunately it seems to // stuff up the Indicator (not hidden upon completion). // ResourceReference ref = new ResourceReference(study.getName() + "/" + report.getName() + "." + reportOutputFormat.getName()) { // protected Resource newResource() { // return pdfResource; // } // }; // String url = getRequestCycle().urlFor(ref).toString(); // getRequestCycle().setRequestTarget(new RedirectRequestTarget(url)); // add(new ResourceLink<Void>("linkToPdf", pdfResource)); reportResource = pdfResource; } else if (reportOutputFormat.getName().equals(au.org.theark.report.service.Constants.CSV_REPORT_FORMAT)) { final JRResource csvResource = new JRConcreteResource<CsvResourceHandler>(new CsvResourceHandler()); csvResource.setJasperReport(report); csvResource.setReportParameters(parameters).setReportDataSource(reportDS); // This code would emulate a file download as if clicked the user // clicked on the download link, but unfortunately it seems to // stuff up the Indicator (not hidden upon completion). // ResourceReference ref = new ResourceReference(study.getName() + "/" + report.getName() + "." + reportOutputFormat.getName()) { // protected Resource newResource() { // return csvResource; // } // }; // String url = getRequestCycle().urlFor(ref).toString(); // getRequestCycle().setRequestTarget(new RedirectRequestTarget(url)); // add(new ResourceLink<Void>("linkToCsv", csvResource)); reportResource = csvResource; } if (reportResource != null) { reportOutputPanel.setReportResource(reportResource); reportOutputPanel.setVisible(true); target.add(reportOutputPanel); } }
From source file:au.org.theark.report.web.component.viewReport.consentDetails.filterForm.ConsentDetailsFilterForm.java
License:Open Source License
protected void initialiseConsentCompDropDown() { Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(sessionStudyId); List<StudyComp> consentStatusList = new ArrayList<StudyComp>(study.getStudyComps()); ChoiceRenderer<StudyComp> defaultChoiceRenderer = new ChoiceRenderer<StudyComp>("name", "id"); ddcStudyComp = new DropDownChoice<StudyComp>(Constants.STUDY_COMP, consentStatusList, defaultChoiceRenderer);/* w w w .ja v a 2 s .c o m*/ ddcStudyComp.setRequired(true); add(ddcStudyComp); }
From source file:au.org.theark.report.web.component.viewReport.phenoFieldDetails.filterForm.FieldDetailsFilterForm.java
License:Open Source License
protected void onGenerateProcess(AjaxRequestTarget target) { PhenoDataSetFieldDisplay cfd = cpModel.getObject().getPhenoDataSetFieldDisplay(); Study study = cpModel.getObject().getStudy(); String reportTitle = study.getName() + " - Phenotypic Field Details Report"; if (cfd.getPhenoDataSetGroup() != null) { String questionnaire = cfd.getPhenoDataSetGroup().getName(); reportTitle += " - " + questionnaire; }/*from w w w. j a v a 2s . c om*/ ReportTemplate reportTemplate = cpModel.getObject().getSelectedReportTemplate(); ReportOutputFormat reportOutputFormat = cpModel.getObject().getSelectedOutputFormat(); // show report ServletContext context = ((WebApplication) getApplication()).getServletContext(); File reportFile = null; reportFile = new File(context.getRealPath("/reportTemplates/" + reportTemplate.getTemplatePath())); JasperDesign design = null; JasperReport report = null; try { design = JRXmlLoader.load(reportFile); // System.out.println(" design -- created " ); if (design != null) { design.setName(reportTitle); // set the output file name to match report title if (reportOutputFormat.getName().equals(au.org.theark.report.service.Constants.CSV_REPORT_FORMAT)) { design.setIgnorePagination(true); // don't paginate CSVs } report = JasperCompileManager.compileReport(design); // System.out.println(" design -- compiled " ); } } catch (JRException e) { reportFile = null; e.printStackTrace(); } // templateIS = getClass().getResourceAsStream("/reportTemplates/WebappReport.jrxml"); final Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("BaseDir", new File(context.getRealPath("/reportTemplates"))); parameters.put("ReportTitle", reportTitle); Subject currentUser = SecurityUtils.getSubject(); String userName = "(unknown)"; if (currentUser.getPrincipal() != null) { userName = (String) currentUser.getPrincipal(); } parameters.put("UserName", userName); PhenoDataSetFieldDetailsReportDataSource reportDS = new PhenoDataSetFieldDetailsReportDataSource( reportService, cpModel.getObject()); JRResource reportResource = null; if (reportOutputFormat.getName().equals(au.org.theark.report.service.Constants.PDF_REPORT_FORMAT)) { final JRResource pdfResource = new JRConcreteResource<PdfResourceHandler>(new PdfResourceHandler()); pdfResource.setJasperReport(report); pdfResource.setReportParameters(parameters).setReportDataSource(reportDS); // This code would emulate a file download as if clicked the user // clicked on the download link, but unfortunately it seems to // stuff up the Indicator (not hidden upon completion). // ResourceReference ref = new ResourceReference(study.getName() + "/" + report.getName() + "." + reportOutputFormat.getName()) { // protected Resource newResource() { // return pdfResource; // } // }; // String url = getRequestCycle().urlFor(ref).toString(); // getRequestCycle().setRequestTarget(new RedirectRequestTarget(url)); // add(new ResourceLink<Void>("linkToPdf", pdfResource)); reportResource = pdfResource; } else if (reportOutputFormat.getName().equals(au.org.theark.report.service.Constants.CSV_REPORT_FORMAT)) { final JRResource csvResource = new JRConcreteResource<CsvResourceHandler>(new CsvResourceHandler()); csvResource.setJasperReport(report); csvResource.setReportParameters(parameters).setReportDataSource(reportDS); // This code would emulate a file download as if clicked the user // clicked on the download link, but unfortunately it seems to // stuff up the Indicator (not hidden upon completion). // ResourceReference ref = new ResourceReference(study.getName() + "/" + report.getName() + "." + reportOutputFormat.getName()) { // protected Resource newResource() { // return csvResource; // } // }; // String url = getRequestCycle().urlFor(ref).toString(); // getRequestCycle().setRequestTarget(new RedirectRequestTarget(url)); // add(new ResourceLink<Void>("linkToCsv", csvResource)); reportResource = csvResource; } if (reportResource != null) { reportOutputPanel.setReportResource(reportResource); reportOutputPanel.setVisible(true); target.add(reportOutputPanel); } }