List of usage examples for org.apache.shiro SecurityUtils getSubject
public static Subject getSubject()
From source file:au.org.theark.study.web.component.global.subject.SubjectContainerPanel.java
License:Open Source License
@SuppressWarnings("unchecked") protected WebMarkupContainer initialiseSearchResults() { searchResultsPanel = new SearchResultListPanel("searchResults", arkContextMarkup, containerForm, arkCrudContainerVO, studyNameMarkup, studyLogoMarkup, mainTabs); Subject currentUser = SecurityUtils.getSubject(); ArkUser arkUser;/*from w w w . j a v a2 s. c o m*/ try { arkUser = iArkCommonService.getArkUser(currentUser.getPrincipal().toString()); ArkUserVO arkUserVo = new ArkUserVO(); arkUserVo.setArkUserEntity(arkUser); studyListForUser = iArkCommonService.getStudyListForUser(arkUserVo); //getParentAndChildStudies(sessionStudyId); } catch (EntityNotFoundException e) { e.printStackTrace(); } if (sessionStudyId != null) { LinkSubjectStudy linkSubjectStudy = new LinkSubjectStudy(); linkSubjectStudy.setStudy(study); //containerForm.getModelObject().setLinkSubjectStudy(linkSubjectStudy); } // Data providor to paginate resultList subjectProvider = new ArkDataProvider<SubjectVO, IArkCommonService>(iArkCommonService) { private static final long serialVersionUID = 1L; public int size() { return (int) service.getStudySubjectCount(model.getObject()); } public Iterator<SubjectVO> iterator(int first, int count) { List<SubjectVO> listSubjects = new ArrayList<SubjectVO>(); if (isActionPermitted()) { listSubjects = iArkCommonService.searchPageableSubjects(model.getObject(), first, count); } return listSubjects.iterator(); } }; TextField<OtherID> txtFld = ((TextField<OtherID>) containerForm .get("searchContainer:searchComponentPanel:searchForm:otherID")); String otherIDSearch = txtFld != null ? txtFld.getValue() : null; if (otherIDSearch != null) { OtherID o; o = new OtherID(); o.setOtherID(otherIDSearch); // List<OtherID> otherIDs = new ArrayList<OtherID>(); // otherIDs.add(o); cpModel.getObject().getLinkSubjectStudy().getPerson().getOtherIDs().clear();//setOtherIDs(otherIDs); cpModel.getObject().getLinkSubjectStudy().getPerson().getOtherIDs().add(o); } subjectProvider.setModel(this.cpModel); dataView = searchResultsPanel.buildDataView(subjectProvider); dataView.setItemsPerPage(iArkCommonService.getRowsPerPage()); if (containerForm.getModelObject().getStudyList().isEmpty()) { containerForm.getModelObject().setStudyList(studyListForUser); } IModel<String> amountModel = new Model<String>(Integer.toString(subjectProvider.size())); resultsWmc.add(new Label("total", amountModel) { private static final long serialVersionUID = 1L; protected void onBeforeRender() { amountModel.setObject(Integer.toString(subjectProvider.size())); super.onBeforeRender(); }; }); PagingNavigator pageNavigator = new PagingNavigator("navigator", dataView); resultsWmc.add(pageNavigator); List<IColumn<SubjectVO>> columns = new ArrayList<IColumn<SubjectVO>>(); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("SubjectUID"), "subjectUID")); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Study"), "linkSubjectStudy.study.name")); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Full Name"), "subjectFullName")); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Previous Last Names"), "linkSubjectStudy.person.descriptiveLastNameHistory")); columns.add(new ExportableDateColumn<SubjectVO>(Model.of("Date Of Birth"), "linkSubjectStudy.person.dateOfBirth", au.org.theark.core.Constants.DD_MM_YYYY)); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Vital Status"), "linkSubjectStudy.person.vitalStatus.name")); columns.add( new ExportableTextColumn<SubjectVO>(Model.of("Gender"), "linkSubjectStudy.person.genderType.name")); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Subject Status"), "linkSubjectStudy.subjectStatus.name")); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Consent Status"), "linkSubjectStudy.consentStatus.name")); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Other IDs"), "linkSubjectStudy.person.descriptiveOtherIDs")); DataTable table = new DataTable("datatable", columns, dataView.getDataProvider(), iArkCommonService.getRowsPerPage()); List<String> headers = new ArrayList<String>(0); headers.add("SubjectUID"); headers.add("Study"); headers.add("Full Name"); headers.add("Previous Last Names"); headers.add("Date of Birth"); headers.add("Vital Status"); headers.add("Gender"); headers.add("Subject Status"); headers.add("Consent Status"); headers.add("Other IDs"); String filename = "subjects"; RepeatingView toolbars = new RepeatingView("toolbars"); /*List<SubjectVO> listSubvo = new ArrayList<SubjectVO>(); if(subjectProvider.size() < 5000 ){ listSubvo=iArkCommonService.searchPageableSubjects(cpModel.getObject(), 0, subjectProvider.size()); }*/ ExportToolbar<String> exportToolBar = new ExportToolbar<String>(table, headers, filename); toolbars.add(new Component[] { exportToolBar }); resultsWmc.add(toolbars); resultsWmc.add(dataView); searchResultsPanel.add(resultsWmc); arkCrudContainerVO.getSearchResultPanelContainer().add(searchResultsPanel); return arkCrudContainerVO.getSearchResultPanelContainer(); }
From source file:au.org.theark.study.web.component.managestudy.form.DetailForm.java
License:Open Source License
@Override protected void attachValidators() { studyNameTxtFld.setRequired(true).setLabel( new StringResourceModel("error.study.name.required", this, new Model<String>("Study Name"))); // TODO Have to stop the validator posting the content with the error message studyDescriptionTxtArea.add(StringValidator.lengthBetween(1, 255)).setLabel(new StringResourceModel( "study.description.length.exceeded", this, new Model<String>("Study Synopsis"))); studyStatusDpChoices.setRequired(true).setLabel( new StringResourceModel("error.study.status.required", this, new Model<String>("Status"))); // Max dateOfApplicationDp can be only today dateOfApplicationDp.add(DateValidator.maximum(new Date())) .setLabel(new StringResourceModel(Constants.ERROR_STUDY_DOA_MAX_RANGE, this, null)); // TODO: Write CustomValidator to handle numeric validation // Estimated Year of completion a numeric year field, greater than dateOfApplicationDp // estYearOfCompletionTxtFld.add(new PatternValidator("^\\d{4}$")).setLabel(new StringResourceModel("error.study.yearOfCompletion", this, new // Model<String>("Estimated Year of Completion"))); chiefInvestigatorTxtFld.setRequired(true).setLabel( new StringResourceModel("error.study.chief", this, new Model<String>("Chief Investigator"))); chiefInvestigatorTxtFld.add(StringValidator.lengthBetween(3, 50)); coInvestigatorTxtFld.add(StringValidator.lengthBetween(3, 50)).setLabel( new StringResourceModel("error.study.co.investigator", this, new Model<String>("Co Investigator"))); // selectedApplicationsLmc.setRequired(true).setLabel( new StringResourceModel("error.study.selected.app", this, null)); subjectUidStartTxtFld.add(new RangeValidator<Integer>(1, Integer.MAX_VALUE)) .setLabel(new StringResourceModel("error.study.subject.key.prefix", this, null)); // file image validator, checking size, type etc fileUploadField.add(new StudyLogoValidator()); // Make parentStudy drop-down required for Study Administrators and study in context Subject currentUser = SecurityUtils.getSubject(); Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); if (studyId != null) { try {/* w ww.j a v a2s . c o m*/ if (!iArkCommonService.isSuperAdministrator(currentUser.getPrincipal().toString())) { parentStudyDdc.setRequired(true).setLabel(new StringResourceModel("study.parentStudy.required", this, new Model<String>("Parent Study"))); } } catch (EntityNotFoundException e) { log.error(e.getMessage()); } } }
From source file:au.org.theark.study.web.component.managestudy.form.DetailForm.java
License:Open Source License
private void processSaveUpdate(StudyModelVO studyModel, AjaxRequestTarget target) throws EntityExistsException, UnAuthorizedOperation, ArkSystemException, EntityCannotBeRemoved, CannotRemoveArkModuleException, IOException, Exception { Collection<ModuleVO> moduleVoCollection = studyModel.getModulesSelected(); // Convert to Set<String> this can be removed later by changing the interface Set<String> moduleList = new HashSet<String>(); for (ModuleVO moduleVO : moduleVoCollection) { moduleList.add(moduleVO.getModule()); }/*w w w.jav a 2s . co m*/ studyModel.setLmcSelectedApps(moduleList); if (studyModel.getStudy() != null && studyModel.getStudy().getId() == null) { // Store Study logo image if (fileUploadField != null && fileUploadField.getFileUpload() != null) { // Retrieve file and store as Blob in databasse FileUpload fileUpload = fileUploadField.getFileUpload(); byte[] byteArray = fileUpload.getMD5(); String checksum = getHex(byteArray); // Copy file to Blob object studyModel.getStudy().setStudyLogoBlob(IOUtils.toByteArray((fileUpload.getInputStream()))); studyModel.getStudy().setFilename(fileUpload.getClientFileName()); studyModel.getStudy().setStudyLogoChecksum(checksum); } Set<String> moduleNames = new HashSet<String>(); for (ArkModule arkModule : studyModel.getSelectedArkModules()) { moduleNames.add(arkModule.getName()); } // Always assign Study module if (moduleNames.isEmpty()) { moduleNames.add(ModuleConstants.ARK_MODULE_STUDY); } ArkUserVO arkUserVo = new ArkUserVO(); String currentUser = (String) SecurityUtils.getSubject().getPrincipal(); arkUserVo = iArkCommonService.getDefaultAdministratorRoles(currentUser, studyModel.getStudy(), moduleNames); if (!arkUserVo.getUserName().isEmpty()) { // Create new study and assign the current user iStudyService.createStudy(studyModel, arkUserVo); this.info("Study " + studyModel.getStudy().getName().toUpperCase() + " was saved successfully."); } else { // Create new study by default, without assignment of user iStudyService.createStudy(studyModel); this.info( "Study " + studyModel.getStudy().getName().toUpperCase() + " has been saved successfully."); } subjectUidExampleTxt = getSubjectUidExample(); target.add(subjectUidExampleLbl); onSavePostProcess(target, studyCrudVO); studyCrudVO.getSummaryContainer().setVisible(true);// added as part of refactoring } else { // Update String checksum = null; // This is related to study logo already setting we have to get it from the data store and update. checksum = addStudyLogoBlobDetailsToStudyModelFromfile(studyModel, checksum); if (fileUploadField != null && fileUploadField.getFileUpload() != null) { // Retrieve file and store as Blob in databasse FileUpload fileUpload = fileUploadField.getFileUpload(); byte[] byteArray = fileUpload.getMD5(); checksum = getHex(byteArray); // Copy file to Blob object studyModel.getStudy().setStudyLogoBlob(IOUtils.toByteArray(fileUpload.getInputStream())); studyModel.getStudy().setFilename(fileUpload.getClientFileName()); } iStudyService.updateStudy(studyModel, checksum); subjectUidExampleTxt = getSubjectUidExample(); target.add(subjectUidExampleLbl); this.info("Study " + studyModel.getStudy().getName().toUpperCase() + " was updated successfully."); onSavePostProcess(target, studyCrudVO); studyCrudVO.getSummaryContainer().setVisible(true); } SecurityUtils.getSubject().getSession().setAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID, studyModel.getStudy().getId()); SecurityUtils.getSubject().getSession().removeAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); SecurityUtils.getSubject().getSession().removeAttribute(au.org.theark.core.Constants.PERSON_TYPE); containerForm.getModelObject().setStudy(studyModel.getStudy()); // Set Study into context items ContextHelper contextHelper = new ContextHelper(); contextHelper.resetContextLabel(target, studyCrudVO.getArkContextMarkup()); contextHelper.setStudyContextLabel(target, studyModel.getStudy().getName(), studyCrudVO.getArkContextMarkup()); // Refresh Study Logo in header studyHelper = new StudyHelper(); studyHelper.setStudyLogo(studyModel.getStudy(), target, studyCrudVO.getStudyNameMarkup(), studyCrudVO.getStudyLogoMarkup(), iArkCommonService); target.add(studyCrudVO.getDetailPanelContainer()); target.add(studyCrudVO.getStudyLogoMarkup()); // Update summary long totalSubjects = iArkCommonService.getCountOfSubjects(studyModel.getStudy()); long totalSubjectsOfParent = iArkCommonService.getCountOfSubjects(studyModel.getStudy().getParentStudy()); studyModel.setTotalSubjects(totalSubjects); studyModel.setTotalSubjectsOfParent(totalSubjectsOfParent); target.add(totalSubjectsLabel); target.add(subjectUidContainer); target.add(bioCollectionUidContainer); target.add(biospecimenUidContainer); }
From source file:au.org.theark.study.web.component.managestudy.form.DetailForm.java
License:Open Source License
private void initStudyLogoDelete() { fileNameLbl = new Label(Constants.STUDY_FILENAME); fileNameLbl.setOutputMarkupId(true); ajaxDownload = new AJAXDownload() { @Override/* ww w . j ava 2 s . c o m*/ protected IResourceStream getResourceStream() { Study study = containerForm.getModelObject().getStudy(); File file = null; IResourceStream resStream = null; try { file = iArkCommonService.retriveArkFileAttachmentAsFile(study.getId(), null, Constants.ARK_STUDY_DIR, study.getStudyLogoFileId(), study.getStudyLogoChecksum()); resStream = new FileResourceStream(file); if (resStream == null) { containerForm .error("An unexpected error occurred. Download request could not be fulfilled."); } } catch (ArkSystemException e) { containerForm.error("An unexpected error occurred. Download request could not be fulfilled."); log.error(e.getMessage()); } catch (ArkFileNotFoundException e) { containerForm.error("File not found:" + e.getMessage()); log.error(e.getMessage()); } catch (ArkCheckSumNotSameException e) { containerForm.error("Check sum error:" + e.getMessage()); log.error(e.getMessage()); } return resStream; } @Override protected String getFileName() { return containerForm.getModelObject().getStudy().getFilename(); } }; fileNameLnk = new ArkBusyAjaxLink<String>(Constants.SUBJECT_LOGO_LINK) { @Override public void onClick(AjaxRequestTarget target) { ajaxDownload.initiate(target); processErrors(target); } }; fileNameLnk.add(fileNameLbl); deleteButton = new AjaxButton("deleteButton") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { try { //remove existing attachment file id and checksum StudyModelVO studyModel = containerForm.getModelObject(); String checksum = null; checksum = addStudyLogoBlobDetailsToStudyModelFromfile(studyModel, checksum); studyModel.getStudy().setStudyLogoBlob(null); iStudyService.updateStudy(studyModel, checksum); containerForm.info("The file has been successfully deleted."); onSavePostProcess(target, studyCrudVO); target.add(studyCrudVO.getStudyLogoMarkup()); target.add(studyCrudVO.getDetailPanelFormContainer()); } catch (ArkSystemException e) { containerForm.error("System error occure:" + e.getMessage()); } catch (ArkFileNotFoundException e) { containerForm.error("File not found:" + e.getMessage()); } catch (ArkCheckSumNotSameException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (CannotRemoveArkModuleException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { //containerForm.getModelObject().getSubjectFile().setFilename(null); this.setVisible(false); target.add(fileNameLnk); target.add(this); processErrors(target); } } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { containerForm.getModelObject().getStudy().setStudyLogoBlob(null); containerForm.getModelObject().getStudy().setFilename(null); this.setVisible(false); target.add(fileNameLnk); target.add(this); containerForm.error("Error occurred during the file deletion process."); processErrors(target); } @Override public boolean isVisible() { SecurityManager securityManager = ThreadContext.getSecurityManager(); Subject currentUser = SecurityUtils.getSubject(); if (Constants.YES.equalsIgnoreCase(iArkCommonService.getDemoMode().getPropertyValue())) { return (containerForm.getModelObject().getStudy() != null && containerForm.getModelObject().getStudy().getFilename() != null) && !containerForm.getModelObject().getStudy().getFilename().isEmpty() && securityManager.hasRole(currentUser.getPrincipals(), au.org.theark.core.security.RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR); } else { return (containerForm.getModelObject().getStudy() != null && containerForm.getModelObject().getStudy().getFilename() != null) && !containerForm.getModelObject().getStudy().getFilename().isEmpty(); } } }; deleteButton.add(new AttributeModifier("title", new Model<String>("Remove study logo only"))); deleteButton.setOutputMarkupId(true); }
From source file:au.org.theark.study.web.component.managestudy.form.SearchForm.java
License:Open Source License
/** * Constructor// w w w . j av a 2 s . co m * * @param id * @param model * @param studyCrudContainerVO * @param containerForm */ public SearchForm(String id, CompoundPropertyModel<StudyModelVO> studyModelVOCpm, StudyCrudContainerVO studyCrudContainerVO, final FeedbackPanel feedbackPanel, Container containerForm) { super(id, studyModelVOCpm, feedbackPanel, studyCrudContainerVO); this.containerForm = containerForm; this.studyCrudContainerVO = studyCrudContainerVO; this.feedbackPanel = feedbackPanel; setMultiPart(true); cpmModel = studyModelVOCpm; initialiseSearchForm(); addSearchComponentsToForm(); newButton.replaceWith(new ArkBusyAjaxButton(Constants.NEW) { private static final long serialVersionUID = 1666656098281624401L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { // Make the details panel visible, disabling delete button (if found) // AjaxButton ajaxButton = (AjaxButton) editButtonContainer.get("delete"); AjaxButton ajaxButton = (AjaxButton) arkCrudContainerVO.getEditButtonContainer().get("delete"); if (ajaxButton != null) { ajaxButton.setEnabled(false); target.add(ajaxButton); } // Call abstract method onNew(target); } @Override public boolean isVisible() { //log.debug("SecurityUtils.getSubject()" + SecurityUtils.getSubject().getPrincipal().toString()); return SecurityUtils.getSubject().hasRole(RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR); } @Override protected void onError(final AjaxRequestTarget target, Form<?> form) { target.add(feedbackPanel); } }); }
From source file:au.org.theark.study.web.component.managestudy.form.SearchForm.java
License:Open Source License
@SuppressWarnings("unchecked") protected void onSearch(AjaxRequestTarget target) { try {/*ww w. ja v a 2 s .c om*/ List<Study> studyListForUser = new ArrayList<Study>(0); // Search study Study searchStudyCriteria = containerForm.getModelObject().getStudy(); Subject currentUser = SecurityUtils.getSubject(); ArkUser arkUser = iArkCommonService.getArkUser(currentUser.getPrincipal().toString()); ArkUserVO arkUserVo = new ArkUserVO(); arkUserVo.setArkUserEntity(arkUser); arkUserVo.setStudy(searchStudyCriteria); studyListForUser = iArkCommonService.getStudyListForUser(arkUserVo); if (studyListForUser.size() == 0) { containerForm.getModelObject().setStudyList(studyListForUser); this.info("There are no records that matched your query. Please modify your filter"); target.add(feedbackPanel); } containerForm.getModelObject().setStudyList(studyListForUser); studyCrudContainerVO.getPageableListView().removeAll(); studyCrudContainerVO.getSearchResultPanelContainer().setVisible(true); target.add(studyCrudContainerVO.getSearchResultPanelContainer()); } catch (EntityNotFoundException e) { log.error(e.getMessage()); this.error("There are no records that matched your query. Please modify your filter"); target.add(feedbackPanel); } }
From source file:au.org.theark.study.web.component.managestudy.SearchResultListPanel.java
License:Open Source License
private AjaxLink<Study> buildLink(final Study study, final WebMarkupContainer searchResultsContainer) { ArkBusyAjaxLink<Study> link = new ArkBusyAjaxLink<Study>("studyName") { private static final long serialVersionUID = 1L; @SuppressWarnings("unchecked") @Override//from w w w . j a va2 s .c o m public void onClick(AjaxRequestTarget target) { Subject currentUser = SecurityUtils.getSubject(); // Place the selected study in session context for the user SecurityUtils.getSubject().getSession().setAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID, study.getId()); SecurityUtils.getSubject().getSession() .removeAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); SecurityUtils.getSubject().getSession().removeAttribute(au.org.theark.core.Constants.PERSON_TYPE); // Clear out any Subject UID placed in session via LIMS SecurityUtils.getSubject().getSession().removeAttribute(au.org.theark.core.Constants.SUBJECTUID); // Force clearing of Cache to re-load roles for the user for the study arkLdapRealm.clearCachedAuthorizationInfo(currentUser.getPrincipals()); aafRealm.clearCachedAuthorizationInfo(currentUser.getPrincipals()); Study searchStudy = iArkCommonService.getStudy(study.getId()); /************** * this is code which must not be commented out...was to be utilized to deal with data from WAGER ... //TODO ASAP Dont leave this nasty hack here iArkCommonService.convertLimsBiospecimenCustomDataValuesToKeysForThisStudy(searchStudy);~~~ //TODO ASAP Dont leave this nasty hack here iArkCommonService.convertLimsBiocollectionCustomDataValuesToKeysForThisStudy(searchStudy);~~~ ************/ Study parentStudy = searchStudy.getParentStudy(); // Check if the study has been linked to a Main Study and if so get a reference to the main study. // studyContainerForm.getModelObject().setLinkedToStudy(linkedToStudy) studyContainerForm.getModelObject().setStudy(searchStudy); studyContainerForm.getModelObject() .setSubjectUidExample(iArkCommonService.getSubjectUidExample(searchStudy)); WebMarkupContainer wmc = (WebMarkupContainer) studyCrudContainerVO.getDetailPanelContainer(); DetailPanel detailsPanel = (DetailPanel) wmc.get("detailPanel"); DetailForm detailForm = (DetailForm) detailsPanel.get("detailForm"); // All SubjectUID generator fields grouped within a container(s) WebMarkupContainer autoSubjectUidcontainer = detailForm.getAutoSubjectUidContainer(); WebMarkupContainer autoBiocollectionUidcontainer = detailForm.getAutoBiocollectionUidContainer(); WebMarkupContainer autoBiospecimenUidcontainer = detailForm.getAutoBiospecimenUidContainer(); WebMarkupContainer subjectUidcontainer = detailForm.getSubjectUidContainer(); // Disable all SubjectUID generation fields if subjects exist or is a child study if (iArkCommonService.studyHasSubjects(searchStudy) || parentStudy != null) { autoSubjectUidcontainer.setEnabled(false); subjectUidcontainer.setEnabled(false); } else { autoSubjectUidcontainer.setEnabled(true); if (studyContainerForm.getModelObject().getStudy().getAutoGenerateSubjectUid()) { subjectUidcontainer.setEnabled(true); } else { subjectUidcontainer.setEnabled(false); } } // Enable bioSpecimenUidContainer if there are no biospecimens created as yet WebMarkupContainer biospecimenUidContainer = detailForm.getBiospecimenUidContainer(); if (iArkCommonService.studyHasBiospecimen(studyContainerForm.getModelObject().getStudy())) { biospecimenUidContainer.setEnabled(false); autoBiospecimenUidcontainer.setEnabled(false); } else { biospecimenUidContainer.setEnabled(parentStudy == null); autoBiospecimenUidcontainer.setEnabled(parentStudy == null); } WebMarkupContainer bioCollectionUidContainer = detailForm.getBioCollectionUidContainer(); if (iArkCommonService.studyHasBioCollection(studyContainerForm.getModelObject().getStudy())) { bioCollectionUidContainer.setEnabled(false); autoBiocollectionUidcontainer.setEnabled(false); } else { bioCollectionUidContainer.setEnabled(parentStudy == null); autoBiocollectionUidcontainer.setEnabled(parentStudy == null); } // Get the Source Modules from database Collection<ArkModule> availableArkModules = iArkCommonService.getEntityList(ArkModule.class); // Hide Admin and Reporting modules from "Available" view availableArkModules.remove(iArkCommonService.getArkModuleByName(ModuleConstants.ARK_MODULE_ADMIN)); //availableArkModules.remove(iArkCommonService.getArkModuleByName(ModuleConstants.ARK_MODULE_REPORTING)); // Get the Modules for the Study from database Collection<ArkModule> arkModulesLinkedToStudy = iArkCommonService .getArkModulesLinkedWithStudy(searchStudy); studyContainerForm.getModelObject().setAvailableArkModules(availableArkModules); studyContainerForm.getModelObject().setSelectedArkModules(arkModulesLinkedToStudy); // Store module names linked to study in session for (Iterator iterator = arkModulesLinkedToStudy.iterator(); iterator.hasNext();) { ArkModule arkModule = (ArkModule) iterator.next(); SecurityUtils.getSubject().getSession().setAttribute(arkModule.getName(), arkModule.getName()); } studyCrudContainerVO.getSummaryContainer().setVisible(true); // Set Study Logo studyHelper = new StudyHelper(); studyHelper.setStudyLogo(study, target, studyCrudContainerVO.getStudyNameMarkup(), studyCrudContainerVO.getStudyLogoMarkup(), iArkCommonService); // Set Context items ContextHelper contextHelper = new ContextHelper(); contextHelper.resetContextLabel(target, studyCrudContainerVO.getArkContextMarkup()); contextHelper.setStudyContextLabel(target, searchStudy.getName(), studyCrudContainerVO.getArkContextMarkup()); target.add(studyCrudContainerVO.getSummaryContainer()); ArkCRUDHelper.preProcessDetailPanelOnSearchResults(target, studyCrudContainerVO); // Example auto-generated SubjectUID Label subjectUidExampleLbl = detailForm.getSubjectUidExampleLbl(); // Get the Biospecimen UID Pattern if present for the given study BiospecimenUidTemplate biospecimentUidTemplate = null; // Get the BioCollection UID pattern if present BioCollectionUidTemplate bioCollectionUidTemplate = null; if (parentStudy == null || searchStudy == parentStudy) { subjectUidExampleLbl.setDefaultModelObject(iArkCommonService.getSubjectUidExample(searchStudy)); biospecimentUidTemplate = iArkCommonService.getBiospecimenUidTemplate(searchStudy); bioCollectionUidTemplate = iArkCommonService.getBioCollectionUidTemplate(searchStudy); } else { // Disable parent study drop down detailForm.getLinkedToStudyDDContainer().setEnabled(false); subjectUidExampleLbl.setDefaultModelObject(iArkCommonService.getSubjectUidExample(parentStudy)); biospecimentUidTemplate = iArkCommonService.getBiospecimenUidTemplate(parentStudy); bioCollectionUidTemplate = iArkCommonService.getBioCollectionUidTemplate(parentStudy); } if (biospecimentUidTemplate != null) { studyContainerForm.getModelObject().setBiospecimenUidTemplate(biospecimentUidTemplate); } if (bioCollectionUidTemplate != null) { studyContainerForm.getModelObject().setBioCollectionUidTemplate(bioCollectionUidTemplate); } target.add(subjectUidExampleLbl); boolean isChildStudy = (parentStudy != null && parentStudy != searchStudy); detailForm.getSubjectFileUploadContainer().setVisible(isChildStudy); detailForm.getSubjectFileUploadContainer().setEnabled(isChildStudy); //Subject Status active/Subject =1 long activeSubjects = iArkCommonService.getCountOfSubjectsForSubjectStatus(searchStudy, 1); //Subject Status Withdrawn Subject =3 long withdrawnSubjects = iArkCommonService.getCountOfSubjectsForSubjectStatus(searchStudy, 3); //Subject Status Archive =4 long archivedSubjects = iArkCommonService.getCountOfSubjectsForSubjectStatus(searchStudy, 4); long totalSubjects = iArkCommonService.getCountOfSubjects(searchStudy); long totalSubjectsOfParent = iArkCommonService.getCountOfSubjects(searchStudy.getParentStudy()); studyContainerForm.getModelObject().setActiveSubjects(activeSubjects); studyContainerForm.getModelObject().setWithdrawnSubjects(withdrawnSubjects); studyContainerForm.getModelObject().setArchivedSubjects(archivedSubjects); studyContainerForm.getModelObject().setTotalSubjects(totalSubjects); studyContainerForm.getModelObject().setTotalSubjectsOfParent(totalSubjectsOfParent); // Refresh base container form to remove any feedBack messages target.add(autoSubjectUidcontainer); target.add(subjectUidcontainer); target.add(autoBiocollectionUidcontainer); target.add(bioCollectionUidContainer); target.add(autoBiospecimenUidcontainer); target.add(biospecimenUidContainer); target.add(studyContainerForm); target.add(moduleTabbedPanel); this.send(getWebPage(), Broadcast.DEPTH, new EventPayload(Constants.EVENT_RELOAD_LOGO_IMAGES, target)); } }; // Add the label for the link Label studyNameLinkLabel = new Label("studyNameLink", study.getName()); link.add(studyNameLinkLabel); return link; }
From source file:au.org.theark.study.web.component.managestudy.StudyContainerPanel.java
License:Open Source License
@Override protected WebMarkupContainer initialiseSearchResults() { searchResultsPanel = new SearchResultListPanel("searchResults", studyCrudContainerVO, containerForm, moduleTabbedPanel);/* www .ja va2s . co m*/ iModel = new LoadableDetachableModel<Object>() { private static final long serialVersionUID = 1L; @Override protected Object load() { List<Study> studyListForUser = new ArrayList<Study>(0); try { Subject currentUser = SecurityUtils.getSubject(); ArkUser arkUser = iArkCommonService.getArkUser(currentUser.getPrincipal().toString()); ArkUserVO arkUserVo = new ArkUserVO(); arkUserVo.setArkUserEntity(arkUser); arkUserVo.setStudy(containerForm.getModelObject().getStudy()); studyListForUser = iArkCommonService.getStudyListForUser(arkUserVo); if (studyListForUser.size() == 0) { StudyContainerPanel.this.error("There are no studies available."); } } catch (EntityNotFoundException e) { log.error(e.getMessage()); } studyCrudContainerVO.getPageableListView().removeAll(); return studyListForUser; } }; studyCrudContainerVO.setPageableListView(searchResultsPanel.buildPageableListView(iModel, studyCrudContainerVO.getSearchResultPanelContainer())); studyCrudContainerVO.getPageableListView().setReuseItems(true); PagingNavigator pageNavigator = new PagingNavigator("navigator", studyCrudContainerVO.getPageableListView()); searchResultsPanel.add(pageNavigator); searchResultsPanel.add(studyCrudContainerVO.getPageableListView());//todo more rows studyCrudContainerVO.getSearchResultPanelContainer().add(searchResultsPanel); return studyCrudContainerVO.getSearchResultPanelContainer(); }
From source file:au.org.theark.study.web.component.manageuser.form.DetailForm.java
License:Open Source License
@Override public void onBeforeRender() { if (!isNew()) { userNameTxtField.setEnabled(false); } else {//from w w w . j a v a2s.c om userNameTxtField.setEnabled(true); } Study study = containerForm.getModelObject().getStudy(); boolean hasChildStudies = (!containerForm.getModelObject().getAvailableChildStudies().isEmpty()); assignedChildStudiesLabel.setVisible(false); assignedChildStudiesPalette.setVisible(false); assignedChildStudiesNote .setVisible(study.getParentStudy() != null && !study.getParentStudy().equals(study)); boolean okToUpdate = false; try { // Super adminstrator can update any user's password // Current user can update their own, but the Study Administrator can also create a new user (gets access to New button on search form) String currentUsername = SecurityUtils.getSubject().getPrincipal().toString(); okToUpdate = (iArkCommonService.isSuperAdministrator(currentUsername) || (containerForm.getModelObject().getUserName() != null && containerForm.getModelObject().getUserName().equals(currentUsername)) || isNew()); userPasswordField.setRequired(isNew()); confirmPasswordField.setRequired(isNew()); } catch (EntityNotFoundException e) { // Shouldn't actually ever get here... } // disabling when not actual user emailTxtField.setEnabled(okToUpdate); firstNameTxtField.setEnabled(okToUpdate); lastNameTxtField.setEnabled(okToUpdate); groupPasswordContainer.setVisible(okToUpdate); containerForm.getModelObject().setChangePassword(okToUpdate); super.onBeforeRender(); }
From source file:au.org.theark.study.web.component.manageuser.form.DetailForm.java
License:Open Source License
@Override protected void onSave(Form<ArkUserVO> containerForm, AjaxRequestTarget target) { Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(sessionStudyId); containerForm.getModelObject().setStudy(study); if (containerForm.getModelObject().getMode() == Constants.MODE_NEW) { /******************************************* Added for handle the current user in the system but not showing for the *********************************/ ArkUser arkUser = getArkUserInDB(userNameTxtField.getModelObject()); //Checking for the data base if (arkUser != null) { //getCurrentLdapUser(*) will only set the First Name,Last name,Email address,etc and some basic properties only refer the mapper class. ArkUserVO ldapuser = getCurrentLdapUser(userNameTxtField.getModelObject()); if (ldapuser != null) { ldapuser.setArkUserRoleList(containerForm.getModelObject().getArkUserRoleList()); ldapuser.setArkUserEntity(arkUser); ldapuser.setStudy(study); @SuppressWarnings("unchecked") List<ArkUserRole> arkUserRoleLst = iArkCommonService.getArkRoleListByUserAndStudy(ldapuser, ldapuser.getStudy()); //Check for existing user in ldap server. if (arkUserRoleLst.size() < 1) { //containerForm.getModelObject().setMode(Constants.MODE_EDIT_USER_ROLE_ONLY); containerForm.setModelObject(ldapuser); target.add(containerForm); //formComponentAjaxCall(target, false); confirmModal.show(target); } else { this.error(new StringResourceModel("user.exists", this, null).getString()); }/*w ww .jav a2s . c om*/ } else { this.error(new StringResourceModel("user.not.properly.register", this, null).getString()); } } else { /********************************************************** end **********************************************************************************/ try { iUserService.createArkUser(containerForm.getModelObject()); reNewArkUserRoleForChildStudies(containerForm); containerForm.getModelObject().setMode(Constants.MODE_EDIT); userNameTxtField.setEnabled(false); onSavePostProcess(target); this.info(new StringResourceModel("user.saved", this, null).getString()); target.add(feedBackPanel); } catch (UserNameExistsException e) { this.error(new StringResourceModel("user.exists", this, null).getString()); } catch (ArkSystemException e) { this.error(new StringResourceModel("ark.system.error", this, null).getString()); } catch (Exception e) { this.error(new StringResourceModel("severe.system.error", this, null).getString()); } } } else if (containerForm.getModelObject().getMode() == Constants.MODE_EDIT) { try { // Update ArkUser for study in context iUserService.updateArkUser(containerForm.getModelObject()); reNewArkUserRoleForChildStudies(containerForm); onSavePostProcess(target); this.info(new StringResourceModel("user.updated", this, null).getString()); } catch (EntityNotFoundException e) { this.error(new StringResourceModel("user.notFound", this, null).getString()); } catch (ArkSystemException e) { this.error(new StringResourceModel("ark.system.error", this, null).getString()); } } target.add(this); target.add(feedBackPanel); }