List of usage examples for org.apache.shiro SecurityUtils getSubject
public static Subject getSubject()
From source file:au.org.theark.study.web.component.address.form.DetailForm.java
License:Open Source License
@Override protected void onSave(Form<AddressVO> containerForm, AjaxRequestTarget target) { Long personSessionId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); StringBuffer feedBackMessageStr = new StringBuffer(); // Get the person and set it on the AddressVO. try {/* w ww .j a v a2 s.c om*/ Person person = iStudyService.getPerson(personSessionId); List<State> statesForThisCountry = iArkCommonService .getStates(containerForm.getModelObject().getAddress().getCountry()); if (statesForThisCountry.isEmpty()) { containerForm.getModelObject().getAddress().setState(null); } else { containerForm.getModelObject().getAddress().setOtherState(null); } // otherStateInvalidError.setVisible(false); // WebMarkupContainer wmcStateSelector = (WebMarkupContainer) arkCrudContainerVO.getDetailPanelFormContainer().get(Constants.STATE_SELECTOR_WMC); WebMarkupContainer wmcStateSelector = (WebMarkupContainer) arkCrudContainerVO.getDetailPanelContainer() .get("addressDetailPanel").get("addressDetailsForm").get("addressDetailFormContainer") .get(Constants.STATE_SELECTOR_WMC); Label otherStateInvalidError = (Label) wmcStateSelector.get("address.otherStateInvalidError"); otherStateInvalidError.setVisible(false); containerForm.getModelObject().getAddress().setPerson(person); if (containerForm.getModelObject().getAddress().getId() == null) { if (containerForm.getModelObject().getAddress().getPreferredMailingAddress()) { // Update any other preferredMailingAddresses to false iStudyService.setPreferredMailingAdressToFalse(person); } iStudyService.create(containerForm.getModelObject().getAddress()); //feedBackMessageStr.append("Address was successfully added and linked to Subject: "); this.saveInformation(); } else { if (containerForm.getModelObject().getAddress().getPreferredMailingAddress()) { // Update any other preferredMailingAddresses to false iStudyService.setPreferredMailingAdressToFalse(person); } iStudyService.update(containerForm.getModelObject().getAddress()); //feedBackMessageStr.append("Address was successfully updated and linked to Subject: "); this.updateInformation(); } if (person.getFirstName() != null && person.getLastName() != null) { feedBackMessageStr.append(person.getFirstName() + " " + person.getLastName()); } else { Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); String uid = iArkCommonService.getSubject(person.getId(), study).getSubjectUID(); feedBackMessageStr.append(uid); } this.info(feedBackMessageStr.toString()); processErrors(target); onSavePostProcess(target); // Invoke backend to persist the AddressVO } catch (EntityNotFoundException e) { this.error( "The specified subject is not longer available in the system. Please try the operation again."); } catch (ArkSystemException e) { this.error("A system error has occured. Please contact the system administrator."); } }
From source file:au.org.theark.study.web.component.address.form.SearchForm.java
License:Open Source License
/** * /* w w w . j a v a 2 s. co m*/ * @param id * @param cpmModel * @param arkCrudContainerVO * @param feedBackPanel * @param listView */ public SearchForm(String id, CompoundPropertyModel<AddressVO> cpmModel, ArkCrudContainerVO arkCrudContainerVO, FeedbackPanel feedBackPanel, PageableListView<Address> listView) { super(id, cpmModel, feedBackPanel, arkCrudContainerVO); this.arkCrudContainerVO = arkCrudContainerVO; this.feedbackPanel = feedBackPanel; this.listView = listView; Label generalTextLbl = new Label("generalLbl", new StringResourceModel("search.panel.text", new Model())); add(generalTextLbl); resetButton.setVisible(false); searchButton.setVisible(false); // initialiseSearchForm(); // addSearchComponentsToForm(); // TODO: Use Subject UID when they are not just contacts Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); disableSearchForm(sessionPersonId, "There is no subject or contact selected. Please select a subject or contact."); }
From source file:au.org.theark.study.web.component.address.form.SearchForm.java
License:Open Source License
@Override protected void onSearch(AjaxRequestTarget target) { target.add(feedbackPanel);// ww w . j a va2s . co m // Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession().getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); // String sessionPersonType = (String) SecurityUtils.getSubject().getSession().getAttribute(au.org.theark.core.Constants.PERSON_TYPE);// Subject // or contact placed insession try { // if(sessionPersonType.equalsIgnoreCase(au.org.theark.core.Constants.PERSON_CONTEXT_TYPE_SUBJECT)){ // // }else if(sessionPersonType.equalsIgnoreCase(au.org.theark.core.Constants.PERSON_CONTEXT_TYPE_CONTACT)){ // // } Address address = getModelObject().getAddress(); address.setPerson(studyService.getPerson(sessionPersonId)); Collection<Address> addressList = studyService.getPersonAddressList(sessionPersonId, address); if (addressList != null && addressList.size() == 0) { this.info("No records match the specified search criteria."); target.add(feedbackPanel); } getModelObject().setAddresses(addressList); listView.removeAll(); arkCrudContainerVO.getSearchResultPanelContainer().setVisible(true); target.add(arkCrudContainerVO.getSearchResultPanelContainer()); } catch (EntityNotFoundException entityNotFoundException) { this.warn("There are no addresses available for the specified search criteria."); target.add(feedbackPanel); } catch (ArkSystemException arkException) { this.error( "The Ark Application has encountered a system error. Please contact the system administrator."); target.add(feedbackPanel); } }
From source file:au.org.theark.study.web.component.address.form.SearchForm.java
License:Open Source License
@Override protected void onNew(AjaxRequestTarget target) { // ARK-108:: no longer do full reset to VO // Set a default Country on new when the Country field is empty if (getModelObject().getAddress() == null || getModelObject().getAddress().getCountry() == null) { // final List<Country> countryList = iArkCommonService.getCountries(); setDefaultCountry();//from w w w . j av a 2 s . c o m } // Force new address to be preferred if totally new address Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); try { getModelObject().setAddresses(studyService.getPersonAddressList(sessionPersonId, null)); } catch (ArkSystemException e) { e.printStackTrace(); } if (getModelObject().getAddresses().size() == 0) { getModelObject().getAddress().setPreferredMailingAddress(true); } updateDetailFormPrerender(getModelObject().getAddress()); preProcessDetailPanel(target); }
From source file:au.org.theark.study.web.component.attachments.AttachmentsContainerPanel.java
License:Open Source License
@Override protected WebMarkupContainer initialiseSearchResults() { SearchResultListPanel searchResultPanel = new SearchResultListPanel("searchResults", arkCrudContainerVO, containerForm);//from w ww . j ava 2 s.com iModel = new LoadableDetachableModel<Object>() { private static final long serialVersionUID = 1L; @Override protected Object load() { // Get the PersonId from session and get the subjectFileList from back end Collection<SubjectFile> subjectFileList = new ArrayList<SubjectFile>(); try { if (isActionPermitted()) { SubjectFile subjectFile = containerForm.getModelObject().getSubjectFile(); Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); if (sessionPersonId != null) { LinkSubjectStudy linkSubjectStudy = iArkCommonService.getSubject(sessionPersonId, study); subjectFile.setLinkSubjectStudy(linkSubjectStudy); subjectFileList = studyService.searchSubjectFile(subjectFile); } } } catch (EntityNotFoundException e) { containerForm.error("The person ID/Subject selected does not exist in the system."); } catch (ArkSystemException e) { containerForm.error("A system error has occurred. Please contact the system administrator."); } pageableListView.removeAll(); return subjectFileList; } }; pageableListView = searchResultPanel.buildPageableListView(iModel); pageableListView.setReuseItems(true); AjaxPagingNavigator pageNavigator = new AjaxPagingNavigator("navigator", pageableListView); searchResultPanel.add(pageNavigator); searchResultPanel.add(pageableListView); searchResultPanel.setOutputMarkupId(true); arkCrudContainerVO.getSearchResultPanelContainer().add(searchResultPanel); return arkCrudContainerVO.getSearchResultPanelContainer(); }
From source file:au.org.theark.study.web.component.attachments.form.DetailForm.java
License:Open Source License
@SuppressWarnings("unchecked") private void initialiseDropDownChoices() { // Initialise Drop Down Choices Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study studyInContext = iArkCommonService.getStudy(studyId); //List<StudyComp> studyCompList = iArkCommonService.getStudyComponentByStudy(studyInContext); Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); LinkSubjectStudy linkSubjectStudy;/*from www . j a v a 2 s.c o m*/ List<StudyComp> studyCompList = new ArrayList<StudyComp>(); try { if (sessionPersonId != null) { linkSubjectStudy = iArkCommonService.getSubject(sessionPersonId, studyInContext); studyCompList = iStudyService.getStudyComponentByStudyAndNotInLinkSubjectSubjectFile(studyInContext, linkSubjectStudy); } ChoiceRenderer<StudyComp> defaultChoiceRenderer = new ChoiceRenderer<StudyComp>(Constants.NAME, Constants.ID); studyComponentChoice = new DropDownChoice<StudyComp>(Constants.SUBJECT_FILE_STUDY_COMP, studyCompList, defaultChoiceRenderer); } catch (EntityNotFoundException e) { this.error("The record you tried to update is no longer available in the system"); } }
From source file:au.org.theark.study.web.component.attachments.form.DetailForm.java
License:Open Source License
@Override protected void onSave(Form<SubjectVO> containerForm, AjaxRequestTarget target) { LinkSubjectStudy linkSubjectStudy = null; Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); String userId = SecurityUtils.getSubject().getPrincipal().toString(); FileUpload fileSubjectFile = fileSubjectFileField.getFileUpload(); try {/*from ww w . j a v a 2s .c om*/ linkSubjectStudy = iArkCommonService.getSubject(sessionPersonId, study); containerForm.getModelObject().getSubjectFile().setLinkSubjectStudy(linkSubjectStudy); if (au.org.theark.core.Constants.MAXIMUM_PERMISSABLE_FILE_SIZE > fileSubjectFile.getSize()) { // Implement Save/Update if (containerForm.getModelObject().getSubjectFile().getId() == null) { // required for file uploads setMultiPart(true); // Retrieve file and store as Blob in database // TODO: AJAX-ified and asynchronous and hit database try { containerForm.getModelObject().getSubjectFile() .setPayload(IOUtils.toByteArray(fileSubjectFile.getInputStream())); } catch (IOException e) { log.error("IOException trying to convert inputstream" + e); } byte[] byteArray = fileSubjectFile.getMD5(); String checksum = getHex(byteArray); // Set details of ConsentFile object containerForm.getModelObject().getSubjectFile().setChecksum(checksum); containerForm.getModelObject().getSubjectFile() .setFilename(fileSubjectFile.getClientFileName()); containerForm.getModelObject().getSubjectFile().setUserId(userId); //if subject component assigned to attachment we consider it as a consent containerForm.getModelObject().getSubjectFile() .setIsConsentFile(isStudyCompAssignedToSubjectFile()); // Save iStudyService.create(containerForm.getModelObject().getSubjectFile(), isStudyCompAssignedToSubjectFile() ? Constants.ARK_SUBJECT_CONSENT_DIR : Constants.ARK_SUBJECT_ATTACHEMENT_DIR); this.saveInformation(); //processErrors(target); } else { //FileUpload fileSubjectFile = fileSubjectFileField.getFileUpload(); try { containerForm.getModelObject().getSubjectFile() .setPayload(IOUtils.toByteArray(fileSubjectFile.getInputStream())); } catch (IOException e) { log.error("IOException trying to convert inputstream" + e); } byte[] byteArray = fileSubjectFile.getMD5(); String checksum = getHex(byteArray); // Set details of ConsentFile object //containerForm.getModelObject().getSubjectFile().setChecksum(checksum); containerForm.getModelObject().getSubjectFile() .setFilename(fileSubjectFile.getClientFileName()); containerForm.getModelObject().getSubjectFile().setUserId(userId); // Update try { iStudyService.update(containerForm.getModelObject().getSubjectFile(), checksum); } catch (ArkFileNotFoundException e) { this.error("Couldn't find the file."); } this.updateInformation(); //this.info("Attachment " + containerForm.getModelObject().getSubjectFile().getFilename() + " was updated successfully"); } } else { this.error("The file size is larger than the maximum allowed size. Maximum allowed size =" + (int) (au.org.theark.core.Constants.MAXIMUM_PERMISSABLE_FILE_SIZE / Math.pow(10, 6)) + " MB and the file you tried to upload is " + (int) (fileSubjectFile.getSize() / Math.pow(10, 6)) + " MB"); } //processErrors(target); } catch (EntityNotFoundException e) { this.error("The record you tried to update is no longer available in the system."); } catch (ArkSystemException e) { this.error( "An error occurred while saving the file attachment. Please contact the system administrator."); } finally { processErrors(target); onSavePostProcess(target); AjaxButton deleteButton = (AjaxButton) arkCrudContainerVO.getEditButtonContainer().get("delete"); deleteButton.setEnabled(false); } }
From source file:au.org.theark.study.web.component.attachments.form.DetailForm.java
License:Open Source License
protected void onCancel(AjaxRequestTarget target) { SubjectVO subjectVo = new SubjectVO(); LinkSubjectStudy linkSubjectStudy = null; Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); try {//from w ww . j a v a2s . c o m linkSubjectStudy = iArkCommonService.getSubject(sessionPersonId, study); } catch (EntityNotFoundException e) { this.error( "The Person/Subject selected does not exist in the system. Please contact the system administrator."); } subjectVo.setLinkSubjectStudy(linkSubjectStudy); containerForm.setModelObject(subjectVo); processErrors(target); }
From source file:au.org.theark.study.web.component.attachments.form.SearchForm.java
License:Open Source License
public SearchForm(String id, CompoundPropertyModel<SubjectVO> model, ArkCrudContainerVO arkCrudContainerVO, FeedbackPanel feedBackPanel, PageableListView<SubjectFile> listView) { super(id, model, feedBackPanel, arkCrudContainerVO); this.cpmModel = model; this.pageableListView = listView; this.arkCrudContainerVO = arkCrudContainerVO; Label generalTextLbl = new Label("generalLbl", new StringResourceModel("search.panel.text", new Model<String>())); add(generalTextLbl);// w w w . j av a 2 s . com resetButton.setVisible(false); searchButton.setVisible(false); Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); disableSearchForm(sessionPersonId, au.org.theark.core.Constants.MESSAGE_NO_SUBJECT_IN_CONTEXT); }
From source file:au.org.theark.study.web.component.attachments.form.SearchForm.java
License:Open Source License
@SuppressWarnings("unchecked") private void initialiseDropDownChoices() { Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study studyInContext = iArkCommonService.getStudy(studyId); List<StudyComp> studyCompList = iArkCommonService.getStudyComponentByStudy(studyInContext); ChoiceRenderer<StudyComp> defaultChoiceRenderer = new ChoiceRenderer<StudyComp>(Constants.NAME, Constants.ID);// w w w .ja va 2 s .c o m studyComponentChoice = new DropDownChoice(Constants.SUBJECT_FILE_STUDY_COMP, studyCompList, defaultChoiceRenderer); }