List of usage examples for org.apache.shiro SecurityUtils getSubject
public static Subject getSubject()
From source file:au.org.theark.study.web.component.consent.form.DetailForm.java
License:Open Source License
/** * Initialise the Consent StudyComp Drop Down Choice Control *//*from www . j av a 2 s . c o m*/ @SuppressWarnings("unchecked") protected void initStudyComponentChoice() { 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); Study study = iArkCommonService.getStudy(sessionStudyId); LinkSubjectStudy linkSubjectStudy = null; try { if (sessionPersonId != null) { linkSubjectStudy = iStudyService.getSubjectLinkedToStudy(sessionPersonId, study); } else { throw new EntityNotFoundException("The subject selected does not exist in system."); } } catch (EntityNotFoundException e) { containerForm.error("The subject selected no longer exists in the system. Please re-do the operation."); } catch (ArkSystemException e) { containerForm.error("A system error has occurred. Please contact the system administrator."); } List<StudyComp> studyCompList = iArkCommonService.getStudyComponentByStudy(study); //Used a different approch on 2016-08-16 //List<StudyComp> studyCompList = iArkCommonService.getStudyComponentsNotInThisSubject(study,linkSubjectStudy); ChoiceRenderer<StudyComp> defaultChoiceRenderer = new ChoiceRenderer<StudyComp>(Constants.NAME, Constants.ID); studyComponentChoice = new DropDownChoice<StudyComp>(Constants.CONSENT_STUDY_COMP, studyCompList, defaultChoiceRenderer) { private static final long serialVersionUID = 1L; @Override protected void onBeforeRender() { if (isNew()) { setEnabled(true); } else { setEnabled(false); } super.onBeforeRender(); } }; studyComponentChoice.add(new ArkDefaultFormFocusBehavior()); studyComponentChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { 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); LinkSubjectStudy linkSubjectStudy = null; try { Study study = iArkCommonService.getStudy(sessionStudyId); Person subject = iStudyService.getPerson(sessionPersonId); if (sessionPersonId != null) { linkSubjectStudy = iStudyService.getSubjectLinkedToStudy(sessionPersonId, study); } else { throw new EntityNotFoundException("The subject selected does not exist in system."); } boolean isConsented = iArkCommonService .isSubjectConsentedToComponent(studyComponentChoice.getModelObject(), subject, study); processErrors(target); if (isConsented) { StringBuffer sb = new StringBuffer(); //sb.append("Please choose another component. The Subject has already consented to Component: "); //sb.append(studyComponentChoice.getModelObject().getName()); sb.append("A study component of this type already exists for subject "); sb.append(linkSubjectStudy.getSubjectUID()); containerForm.error(sb.toString()); //Stopping save with exsisting components. arkCrudContainerVO.getEditButtonContainer().get("save").setEnabled(false); target.add(arkCrudContainerVO.getEditButtonContainer()); processErrors(target); } else { arkCrudContainerVO.getEditButtonContainer().get("save").setEnabled(true); target.add(arkCrudContainerVO.getEditButtonContainer()); } } catch (EntityNotFoundException e) { containerForm.error( "The subject selected no longer exists in the system.Please re-do the operation."); } catch (ArkSystemException e) { containerForm.error("A system error has occurred. Please contact the system administrator."); } } }); }
From source file:au.org.theark.study.web.component.consent.form.DetailForm.java
License:Open Source License
@Override protected void onSave(Form<ConsentVO> containerForm, AjaxRequestTarget target) { boolean isOkToSave = true; boolean isOkToSaveOnAttachment = true; Consent exsistingConsent = containerForm.getModelObject().getConsent(); if (!isRequestedReceivedCompletedInOrder(exsistingConsent)) { isOkToSave = false;//from ww w . ja va2 s. c o m } //Check for the saving ability or update the consent according to the attached file. //Check for already attached file if (iStudyService.isAlreadyHasFileAttached(exsistingConsent.getLinkSubjectStudy(), exsistingConsent.getStudyComp())) { //New filed attached if (isNewFileAttached()) { // if attached check the new file and db recorded one equal and let them to save if (isSameCheckSumOfAttachedAgainstDbRecorded(exsistingConsent.getLinkSubjectStudy(), exsistingConsent.getStudyComp())) { isOkToSaveOnAttachment = true; //else do not allow to save } else { isOkToSaveOnAttachment = false; this.error("The Consent record you tried to update has already been assigned attachment."); processErrors(target); } // if not new attached let them to save with other conditions } else { isOkToSaveOnAttachment = true; } //if not already attached file in the db let them to save. } else { isOkToSaveOnAttachment = true; } if (isOkToSave && isOkToSaveOnAttachment) { try { // Study in Context Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); containerForm.getModelObject().getConsent().setStudy(study); if (containerForm.getModelObject().getConsent().getId() == null) { iStudyService.create(containerForm.getModelObject().getConsent()); this.saveInformation(); //this.info("Consent was successfuly created for the Subject "); createConsentFile(); processErrors(target); // Store session object (used for history) SecurityUtils.getSubject().getSession().setAttribute( au.org.theark.core.Constants.PERSON_CONTEXT_CONSENT_ID, containerForm.getModelObject().getConsent().getId()); } else { boolean consentFile = fileUploadField.getFileUpload() != null; iStudyService.update(containerForm.getModelObject().getConsent(), consentFile); if (isNewFileAttached() && !iStudyService.isAlreadyHasFileAttached(exsistingConsent.getLinkSubjectStudy(), exsistingConsent.getStudyComp())) { createConsentFile(); } //Check for consent file upload this.updateInformation(); //this.info("Consent was successfuly updated for the Subject "); processErrors(target); } } catch (EntityNotFoundException e) { this.error("The Consent record you tried to update is no longer available in the system."); processErrors(target); } catch (ArkSystemException e) { this.error(e.getMessage()); processErrors(target); } finally { onSavePostProcess(target); } } else { processErrors(target); } }
From source file:au.org.theark.study.web.component.consent.form.DetailForm.java
License:Open Source License
private void createConsentFile() throws ArkSystemException { FileUpload fileSubjectFile = fileUploadField.getFileUpload(); if (fileSubjectFile != null) { LinkSubjectStudy linkSubjectStudy = null; Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); try {//from w ww . j ava 2 s . c om linkSubjectStudy = iArkCommonService.getSubject(sessionPersonId, study); if (containerForm.getModelObject().getSubjectFile() == null) { containerForm.getModelObject().setSubjectFile(new SubjectFile()); } containerForm.getModelObject().getSubjectFile().setLinkSubjectStudy(linkSubjectStudy); containerForm.getModelObject().getSubjectFile() .setPayload(IOUtils.toByteArray(fileSubjectFile.getInputStream())); byte[] byteArray = fileSubjectFile.getMD5(); String checksum = getHex(byteArray); // Set details of Consent File object containerForm.getModelObject().getSubjectFile() .setStudyComp(containerForm.getModelObject().getConsent().getStudyComp()); containerForm.getModelObject().getSubjectFile() .setComments(containerForm.getModelObject().getConsent().getComments()); containerForm.getModelObject().getSubjectFile().setChecksum(checksum); containerForm.getModelObject().getSubjectFile().setFilename(fileSubjectFile.getClientFileName()); containerForm.getModelObject().getSubjectFile() .setUserId(SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal().toString()); containerForm.getModelObject().getSubjectFile().setIsConsentFile(true); // Save iStudyService.create(containerForm.getModelObject().getSubjectFile(), Constants.ARK_SUBJECT_CONSENT_DIR); //this.saveInformation(); //No need of this cause it's calling at the actual consent object creation or update. //this.info("Consent file: " + containerForm.getModelObject().getSubjectFile().getFilename() + " was created successfully"); } catch (IOException ioe) { log.error("Failed to save the uploaded file: " + ioe); } catch (EntityNotFoundException e) { log.error(e.getMessage()); } } }
From source file:au.org.theark.study.web.component.consent.form.SearchForm.java
License:Open Source License
public SearchForm(String id, PageableListView<Consent> listView, FeedbackPanel feedBackPanel, CompoundPropertyModel<ConsentVO> model, ArkCrudContainerVO arkCrudContainerVO) { super(id, model, feedBackPanel, arkCrudContainerVO); this.cpmModel = model; this.pageableListView = listView; // initialiseSearchForm(); // addSearchComponentsToForm(); Label generalTextLbl = new Label("generalLbl", new StringResourceModel("search.panel.text", new Model<String>())); add(generalTextLbl);/* w w w .j a v a 2 s . c o m*/ 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.consent.form.SearchForm.java
License:Open Source License
/** * Initialise the Consent StudyComp Drop Down Choice Control */// w ww . ja v a 2 s . co m protected void initialiseComponentChoice() { Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(sessionStudyId); List<StudyComp> studyCompList = iArkCommonService.getStudyComponentByStudy(study); ChoiceRenderer<StudyComp> defaultChoiceRenderer = new ChoiceRenderer<StudyComp>(Constants.NAME, Constants.ID); studyComponentChoice = new DropDownChoice<StudyComp>(Constants.CONSENT_STUDY_COMP, studyCompList, defaultChoiceRenderer); }
From source file:au.org.theark.study.web.component.consent.form.SearchForm.java
License:Open Source License
@Override protected void onSearch(AjaxRequestTarget target) { target.add(feedbackPanel);// w w w . ja va2 s . c o 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); // session Consent consent = getModelObject().getConsent(); try { Study study = iArkCommonService.getStudy(sessionStudyId); // Person subject = studyService.getPerson(sessionPersonId); // consent.setSubject(subject); // TODO Replace the above line with a call to LinkSubjectStudy consent.setStudy(study); // Look up based on criteria via back end. // Collection<Consent> consentList = studyService.searchConsent(getModelObject().getConsent()); LinkSubjectStudy subjectInContext = studyService.getSubjectLinkedToStudy(sessionPersonId, study); consent.setLinkSubjectStudy(subjectInContext); Collection<Consent> consentList = studyService.searchConsent(getModelObject()); if (consentList != null && consentList.size() == 0) { this.info("There are no consents for the specified search criteria."); target.add(feedbackPanel); } getModelObject().setConsentList(consentList); pageableListView.removeAll(); arkCrudContainerVO.getSearchResultPanelContainer().setVisible(true); target.add(arkCrudContainerVO.getSearchResultPanelContainer()); } catch (EntityNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ArkSystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:au.org.theark.study.web.component.consent.form.SearchForm.java
License:Open Source License
@Override protected void onNew(AjaxRequestTarget target) { // ARK-108:: no longer do full reset to VO // Remove session object super.onNew(target); SecurityUtils.getSubject().getSession() .removeAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_CONSENT_ID); preProcessDetailPanel(target);/*w w w . jav a 2 s . c om*/ }
From source file:au.org.theark.study.web.component.consent.SearchResultListPanel.java
License:Open Source License
private AjaxLink<String> buildLink(final Consent consent) { ArkBusyAjaxLink<String> link = new ArkBusyAjaxLink<String>("studyComp.name") { private static final long serialVersionUID = 1L; @Override//from w w w . j a va 2 s. c om public void onClick(AjaxRequestTarget target) { Long id = consent.getId(); try { Session.get().cleanupFeedbackMessages(); target.add(feedbackPanel); Consent consentFromBackend = studyService.getConsent(id); containerForm.getModelObject().setConsent(consentFromBackend); //Subject file need to be populated in here. containerForm.getModelObject().setSubjectFile(studyService.getSubjectFileParticularConsent( consentFromBackend.getLinkSubjectStudy(), consentFromBackend.getStudyComp())); // Add consentId into context (for use with consentFile(s)) SecurityUtils.getSubject().getSession().setAttribute( au.org.theark.core.Constants.PERSON_CONTEXT_CONSENT_ID, consentFromBackend.getId()); WebMarkupContainer wmcPlain = (WebMarkupContainer) arkCrudContainerVO .getDetailPanelFormContainer().get(Constants.WMC_PLAIN); WebMarkupContainer wmcRequested = (WebMarkupContainer) arkCrudContainerVO .getDetailPanelFormContainer().get(Constants.WMC_REQUESTED); WebMarkupContainer wmcRecieved = (WebMarkupContainer) arkCrudContainerVO .getDetailPanelFormContainer().get(Constants.WMC_RECIEVED); WebMarkupContainer wmcCompleted = (WebMarkupContainer) arkCrudContainerVO .getDetailPanelFormContainer().get(Constants.WMC_COMPLETED); new FormHelper().updateStudyCompStatusDates(target, consentFromBackend.getStudyComponentStatus().getName(), wmcPlain, wmcRequested, wmcRecieved, wmcCompleted); ArkCRUDHelper.preProcessDetailPanelOnSearchResults(target, arkCrudContainerVO); } catch (ArkSystemException e) { containerForm.error("A system error has occurred. Please contact the system administrator."); } } }; Label nameLinkLabel = new Label(Constants.CONSENT_COMPONENT_LABEL, consent.getStudyComp().getName()); link.add(nameLinkLabel); return link; }
From source file:au.org.theark.study.web.component.consenthistory.ConsentHistoryPanel.java
License:Open Source License
private void initConsentHistoryPanel() { IModel<Object> model = new LoadableDetachableModel<Object>() { private static final long serialVersionUID = 1L; @Override/*from ww w . j a va2 s . c o m*/ protected Object load() { List<ConsentHistory> consentHistoryList = new ArrayList<ConsentHistory>(); Consent consent = new Consent(); try { Long sessionConsentId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_CONSENT_ID); if (sessionConsentId != null) { consent = iStudyService.getConsent(sessionConsentId); } consentHistoryList = iStudyService.getConsentHistoryList(consent); } catch (ArkSystemException e) { e.printStackTrace(); } listView.removeAll(); return consentHistoryList; } }; listView = buildListView(model); pageNavigator = new PagingNavigator("navigator", listView); }
From source file:au.org.theark.study.web.component.consenthistory.LinkSubjectStudyConsentHistoryPanel.java
License:Open Source License
private void initConsentHistoryPanel() { IModel<Object> model = new LoadableDetachableModel<Object>() { private static final long serialVersionUID = 1L; @Override//from w w w. j av a 2s . c o m protected Object load() { List<LssConsentHistory> consentHistoryList = new ArrayList<LssConsentHistory>(); LinkSubjectStudy linkSubjectStudy = null; try { String subjectUid = (String) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.SUBJECTUID); Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); linkSubjectStudy = iArkCommonService.getSubjectByUID(subjectUid, iArkCommonService.getStudy(sessionStudyId)); consentHistoryList = iStudyService.getLssConsentHistoryList(linkSubjectStudy); } catch (EntityNotFoundException e) { e.printStackTrace(); } listView.removeAll(); return consentHistoryList; } }; listView = buildListView(model); pageNavigator = new PagingNavigator("navigator", listView); }