Example usage for org.apache.shiro SecurityUtils getSubject

List of usage examples for org.apache.shiro SecurityUtils getSubject

Introduction

In this page you can find the example usage for org.apache.shiro SecurityUtils getSubject.

Prototype

public static Subject getSubject() 

Source Link

Document

Returns the currently accessible Subject available to the calling code depending on runtime environment.

Usage

From source file:au.org.theark.study.web.component.correspondence.form.SearchForm.java

License:Open Source License

@Override
protected void onSearch(AjaxRequestTarget target) {

    target.add(feedbackPanel);/*from w  w w .  ja v a  2  s  . c  om*/
    Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID);

    Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    Study study = iArkCommonService.getStudy(sessionStudyId);

    try {
        LinkSubjectStudy lss = studyService.getSubjectLinkedToStudy(sessionPersonId, study);
        Correspondences correspondence = getModelObject().getCorrespondence();
        correspondence.setLss(lss);
        Collection<Correspondences> correspondenceList = studyService.getCorrespondenceList(lss,
                correspondence);
        if (correspondenceList != null && correspondenceList.size() == 0) {
            this.info("Fields with the specified criteria do not exist in the system.");
            target.add(feedbackPanel);
        }

        getModelObject().setCorrespondenceList(correspondenceList);
        pageableListView.removeAll();

        arkCrudContainerVO.getSearchResultPanelContainer().setVisible(true);
        target.add(arkCrudContainerVO.getSearchResultPanelContainer());
    } catch (EntityNotFoundException ex) {
        this.warn("There are no correspondences available for the specified criteria.");
        target.add(feedbackPanel);
    } catch (ArkSystemException ex) {
        this.error("The Ark application has encountered a system error.");
        target.add(feedbackPanel);
    }
}

From source file:au.org.theark.study.web.component.correspondence.SearchResultListPanel.java

License:Open Source License

private AjaxButton buildDeleteButton(final Correspondences correspondences) {
    DeleteButton ajaxButton = new DeleteButton(correspondences, SearchResultListPanel.this) {

        private static final long serialVersionUID = 1L;

        @Override/*from  w ww . j av  a 2  s  .com*/
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            String filename = correspondences.getAttachmentFilename();
            // Attempt to delete attachment
            if (correspondences.getId() != null) {
                try {
                    correspondences.setAttachmentFilename(null);
                    correspondences.setAttachmentPayload(null);
                    studyService.update(correspondences);
                } catch (ArkSystemException e) {
                    log.error(e.getMessage());
                } catch (EntityNotFoundException e) {
                    log.error(e.getMessage());
                }
            }

            containerForm.info("Correspondence attachment " + filename + " was successfully deleted.");

            // Update the result panel
            // target.add(searchResultContainer);
            target.add(arkCrudContainerVO.getSearchResultPanelContainer());

            target.add(containerForm);
        }

        @Override
        public boolean isVisible() {
            SecurityManager securityManager = ThreadContext.getSecurityManager();
            Subject currentUser = SecurityUtils.getSubject();
            boolean flag = false;
            flag = (securityManager.isPermitted(currentUser.getPrincipals(), PermissionConstants.DELETE)
                    && (correspondences.getAttachmentFilename() != null));
            return flag;
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            this.error("An unexpected error occurred. The delete request could not be fulfilled.");
        }
    };

    ajaxButton.setDefaultFormProcessing(false);
    return ajaxButton;
}

From source file:au.org.theark.study.web.component.global.subject.form.SearchForm.java

License:Open Source License

@SuppressWarnings("unchecked")
private void initStudyDdc() {
    CompoundPropertyModel<SubjectVO> subjectCpm = cpmModel;
    PropertyModel<Study> studyPm = new PropertyModel<Study>(subjectCpm, "linkSubjectStudy.study");
    try {// www  .  jav a 2 s .  c o m
        Subject currentUser = SecurityUtils.getSubject();
        ArkUser arkUser = iArkCommonService.getArkUser(currentUser.getPrincipal().toString());
        ArkUserVO arkUserVo = new ArkUserVO();
        arkUserVo.setArkUserEntity(arkUser);

        //Long sessionArkModuleId = (Long) SecurityUtils.getSubject().getSession().getAttribute(au.org.theark.core.Constants.ARK_MODULE_KEY);
        //ArkModule arkModule = null;
        //arkModule = iArkCommonService.getArkModuleById(sessionArkModuleId);
        //studyListForUser = iArkCommonService.getStudyListForUserAndModule(arkUserVo, arkModule);

        Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
                .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
        studyListForUser = iArkCommonService.getStudyListForUser(arkUserVo); //getParentAndChildStudies(sessionStudyId);
        cpmModel.getObject().setStudyList(studyListForUser);
    } catch (EntityNotFoundException e) {
        log.error(e.getMessage());
    }
    ChoiceRenderer<Study> studyRenderer = new ChoiceRenderer<Study>(Constants.NAME, Constants.ID);
    studyDdc = new DropDownChoice<Study>("study", studyPm, (List<Study>) studyListForUser, studyRenderer);
    studyDdc.setNullValid(true);
    studyDdc.setDefaultModelObject(null);
    studyDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            Study study = studyDdc.getModelObject();
            if (study == null) {
                ContextHelper contextHelper = new ContextHelper();
                contextHelper.resetContextLabel(target, arkContextMarkup);
                StudyHelper studyHelper = new StudyHelper();
                studyHelper.setStudyLogo(new Study(), target, studyNameMarkup, studyLogoMarkup,
                        iArkCommonService);
            } else {
                SecurityUtils.getSubject().getSession()
                        .setAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID, study.getId());
                ContextHelper contextHelper = new ContextHelper();
                contextHelper.resetContextLabel(target, arkContextMarkup);
                contextHelper.setStudyContextLabel(target, study.getName(), arkContextMarkup);
                StudyHelper studyHelper = new StudyHelper();
                studyHelper.setStudyLogo(study, target, studyNameMarkup, studyLogoMarkup, iArkCommonService);
            }
            target.add(SearchForm.this);
        }
    });
}

From source file:au.org.theark.study.web.component.global.subject.form.SearchForm.java

License:Open Source License

@SuppressWarnings("unchecked")
protected void onNew(AjaxRequestTarget target) {
    // Disable SubjectUID if auto-generation set
    Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    Study studyInContext = iArkCommonService.getStudy(sessionStudyId);
    if ((studyInContext != null) && (studyInContext.getAutoGenerateSubjectUid())) {
        TextField<String> subjectUIDTxtFld = (TextField<String>) arkCrudContainerVO
                .getDetailPanelFormContainer().get(Constants.SUBJECT_UID);
        getModelObject().getLinkSubjectStudy().setSubjectUID(Constants.SUBJECT_AUTO_GENERATED);
        subjectUIDTxtFld.setEnabled(false);
        target.add(subjectUIDTxtFld);/* w w  w  . jav a2s  .  co  m*/
    } else {
        TextField<String> subjectUIDTxtFld = (TextField<String>) arkCrudContainerVO
                .getDetailPanelFormContainer().get(Constants.SUBJECT_UID);
        subjectUIDTxtFld.setEnabled(true);
        target.add(subjectUIDTxtFld);
    }

    // Available child studies
    List<Study> availableChildStudies = new ArrayList<Study>(0);
    if (studyInContext.getParentStudy() != null) {
        availableChildStudies = iStudyService.getChildStudyListOfParent(studyInContext);
    }
    getModelObject().setAvailableChildStudies(availableChildStudies);

    preProcessDetailPanel(target);
}

From source file:au.org.theark.study.web.component.global.subject.form.SearchForm.java

License:Open Source License

@Override
protected void onBeforeRender() {
    Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    //      Study study = iArkCommonService.getStudy(sessionStudyId);
    //      cpmModel.getObject().getLinkSubjectStudy().setStudy(study);
    //      boolean parentStudy = (study.getParentStudy() == null || (study.getParentStudy() == study)) && cpmModel.getObject().isEnableNewButton();
    //      newButton.setEnabled(parentStudy);
    newButton.setEnabled(false);//from ww  w . j a  v a2  s  .  c o m
    super.onBeforeRender();
}

From source file:au.org.theark.study.web.component.global.subject.SearchResultListPanel.java

License:Open Source License

private AjaxLink buildLink(final SubjectVO subject) {
    ArkBusyAjaxLink link = new ArkBusyAjaxLink(Constants.SUBJECT_UID) {
        @Override//from   w w w .  j  ava 2 s  .  co  m
        public void onClick(AjaxRequestTarget target) {
            Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
                    .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
            // subject.getLinkSubjectStudy().setStudy(iArkCommonService.getStudy(sessionStudyId));

            // We specify the type of person here as Subject
            SecurityUtils.getSubject().getSession().setAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID,
                    subject.getLinkSubjectStudy().getStudy().getId());
            SecurityUtils.getSubject().getSession().setAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID,
                    subject.getLinkSubjectStudy().getPerson().getId());
            SecurityUtils.getSubject().getSession().setAttribute(au.org.theark.core.Constants.PERSON_TYPE,
                    au.org.theark.core.Constants.PERSON_CONTEXT_TYPE_SUBJECT);

            SubjectVO subjectFromBackend = new SubjectVO();
            Collection<SubjectVO> subjects = iArkCommonService.getSubject(subject);
            for (SubjectVO subjectVO2 : subjects) {
                subjectFromBackend = subjectVO2;
                break;
            }

            // Available/assigned child studies
            List<Study> availableChildStudies = new ArrayList<Study>(0);
            List<Study> selectedChildStudies = new ArrayList<Study>(0);

            if (subjectFromBackend.getLinkSubjectStudy().getStudy().getParentStudy() != null) {
                availableChildStudies = iStudyService
                        .getChildStudyListOfParent(subjectFromBackend.getLinkSubjectStudy().getStudy());
                selectedChildStudies = iArkCommonService.getAssignedChildStudyListForPerson(
                        subjectFromBackend.getLinkSubjectStudy().getStudy(),
                        subjectFromBackend.getLinkSubjectStudy().getPerson());
            }

            //            ArkCRUDHelper.preProcessDetailPanelOnSearchResults(target, arkCrudContainerVO);            
            subjectFromBackend.setStudyList(subjectContainerForm.getModelObject().getStudyList());
            subjectContainerForm.setModelObject(subjectFromBackend);
            subjectContainerForm.getModelObject().setAvailableChildStudies(availableChildStudies);
            subjectContainerForm.getModelObject().setSelectedChildStudies(selectedChildStudies);

            // Set SubjectUID into context
            SecurityUtils.getSubject().getSession().setAttribute(au.org.theark.core.Constants.SUBJECTUID,
                    subjectFromBackend.getLinkSubjectStudy().getSubjectUID());
            ContextHelper contextHelper = new ContextHelper();
            contextHelper.setStudyContextLabel(target,
                    subjectFromBackend.getLinkSubjectStudy().getStudy().getName(), arkContextMarkup);
            contextHelper.setSubjectContextLabel(target,
                    subjectFromBackend.getLinkSubjectStudy().getSubjectUID(), arkContextMarkup);
            contextHelper.setSubjectNameContextLabel(target,
                    subjectFromBackend.getLinkSubjectStudy().getPerson().getFullName(), arkContextMarkup);

            // Set Study Logo
            StudyHelper studyHelper = new StudyHelper();
            studyHelper.setStudyLogo(subjectFromBackend.getLinkSubjectStudy().getStudy(), target,
                    studyNameMarkup, studyLogoMarkup, iArkCommonService);

            //Move to subject Tab
            ListIterator<ITab> lIter = mainTabs.getTabs().listIterator();
            while (lIter.hasNext()) {
                int index = lIter.nextIndex();
                ITab currentTab = lIter.next();
                System.out.println("TAB: " + currentTab.getTitle().toString());
                if (currentTab.getTitle().getObject() == au.org.theark.core.Constants.ARK_MODULE_SUBJECT) {
                    mainTabs.setSelectedTab(index);
                    break;
                }
            }
            target.add(mainTabs);
            this.send(target.getPage(), Broadcast.DEPTH,
                    new EventPayload(au.org.theark.core.Constants.EVENT_RELOAD_LOGO_IMAGES, target));
        }
    };
    Label nameLinkLabel = new Label(Constants.SUBJECT_KEY_LBL, subject.getLinkSubjectStudy().getSubjectUID());
    link.add(nameLinkLabel);
    return link;
}

From source file:au.org.theark.study.web.component.global.subject.SearchResultListPanel.java

License:Open Source License

/**
 * Check is the parent age is to be consider for the validation.
 * @param parentSubject//from  w  w  w. jav a2  s.co m
 * @return
 */
private boolean isConsiderParentAge(SubjectVO parentSubject) {
    boolean check = false;
    Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    Study study = iArkCommonService.getStudy(sessionStudyId);
    String subjectUID = (String) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.SUBJECTUID);
    SubjectVO criteriaSubjectVo = new SubjectVO();
    criteriaSubjectVo.getLinkSubjectStudy().setStudy(study);
    criteriaSubjectVo.getLinkSubjectStudy().setSubjectUID(subjectUID);
    Collection<SubjectVO> subjects = iArkCommonService.getSubject(criteriaSubjectVo);
    SubjectVO subjectVo = subjects.iterator().next();

    Date parentDOB = parentSubject.getLinkSubjectStudy().getPerson().getDateOfBirth();
    Date subjectDOB = subjectVo.getLinkSubjectStudy().getPerson().getDateOfBirth();

    if (parentDOB != null && subjectDOB != null && parentDOB.compareTo(subjectDOB) >= 0) {
        check = true;
    }
    return check;
}

From source file:au.org.theark.study.web.component.global.subject.SearchResultListPanel.java

License:Open Source License

/**After select a parent validate the pedigree for circular relationships and create new parent relationship in database.
 * @param subject// w w  w .j a  v a2s  .  co m
 * @param modalWindow
 * @param relatives
 * @param feedbackPanel
 * @param target
 */
private void processParentSelection(final SubjectVO subject, final AbstractDetailModalWindow modalWindow,
        final List<RelationshipVo> relatives, final FeedbackPanel feedbackPanel, AjaxRequestTarget target) {
    LinkSubjectPedigree pedigreeRelationship = new LinkSubjectPedigree();

    Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);

    Study study = iArkCommonService.getStudy(sessionStudyId);

    String subjectUID = (String) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.SUBJECTUID);

    String parentUID = subject.getLinkSubjectStudy().getSubjectUID();

    // Circular validation
    StringBuilder pedigree = new StringBuilder();
    ArrayList<String> dummyParents = new ArrayList<String>();
    boolean firstLine = true;

    List<RelationshipVo> existingRelatives = new ArrayList<RelationshipVo>();
    existingRelatives.addAll(relatives);

    RelationshipVo proband = new RelationshipVo();
    proband.setIndividualId(subjectUID);
    for (RelationshipVo relative : existingRelatives) {
        if ("Father".equalsIgnoreCase(relative.getRelationship())) {
            proband.setFatherId(relative.getIndividualId());
        }

        if ("Mother".equalsIgnoreCase(relative.getRelationship())) {
            proband.setMotherId(relative.getIndividualId());
        }
    }

    if (subject.getLinkSubjectStudy().getPerson().getGenderType().getName().startsWith("M")) {
        proband.setFatherId(parentUID);
    } else if (subject.getLinkSubjectStudy().getPerson().getGenderType().getName().startsWith("F")) {
        proband.setMotherId(parentUID);
    }
    existingRelatives.add(proband);

    List<RelationshipVo> newRelatives = iStudyService.generateSubjectPedigreeRelativeList(parentUID,
            sessionStudyId);

    RelationshipVo parent = new RelationshipVo();
    parent.setIndividualId(parentUID);
    for (RelationshipVo relative : newRelatives) {
        if ("Father".equalsIgnoreCase(relative.getRelationship())) {
            parent.setFatherId(relative.getIndividualId());
        }

        if ("Mother".equalsIgnoreCase(relative.getRelationship())) {
            parent.setMotherId(relative.getIndividualId());
        }
    }

    newRelatives.add(parent);

    for (RelationshipVo relative : newRelatives) {
        if (!existingRelatives.contains(relative)) {
            existingRelatives.add(relative);
        } else {
            for (RelationshipVo existingRelative : existingRelatives) {
                if (relative.getIndividualId().equals(existingRelative.getIndividualId())) {
                    if (existingRelative.getFatherId() == null) {
                        existingRelative.setFatherId(relative.getFatherId());
                    }
                    if (existingRelative.getMotherId() == null) {
                        existingRelative.setMotherId(relative.getMotherId());
                    }
                }
            }
        }
    }

    for (RelationshipVo relative : existingRelatives) {
        String dummyParent = "D-";
        String father = relative.getFatherId();
        String mother = relative.getMotherId();
        String individual = relative.getIndividualId();

        if (father != null) {
            dummyParent = dummyParent + father;
        }

        if (mother != null) {
            dummyParent = dummyParent + mother;
        }

        if (!"D-".equals(dummyParent) && !dummyParents.contains(dummyParent)) {
            dummyParents.add(dummyParent);
            if (father != null) {
                if (firstLine) {
                    pedigree.append(father + " " + dummyParent);
                    firstLine = false;
                } else {
                    pedigree.append("\n" + father + " " + dummyParent);
                }
            }
            if (mother != null) {
                if (firstLine) {
                    pedigree.append(mother + " " + dummyParent);
                    firstLine = false;
                } else {
                    pedigree.append("\n" + mother + " " + dummyParent);
                }
            }
            pedigree.append("\n" + dummyParent + " " + individual);
        } else if (!"D-".equals(dummyParent)) {
            if (firstLine) {
                pedigree.append(dummyParent + " " + individual);
                firstLine = false;
            } else {
                pedigree.append("\n" + dummyParent + " " + individual);
            }
        }
    }

    //TODO comment this block to disable circular validations for inbred relatives
    Set<String> circularUIDs = PedigreeUploadValidator.getCircularUIDs(pedigree);
    if (circularUIDs.size() > 0) {
        this.error("Performing this action will create a circular relationship in the pedigree.");
        StringBuffer sb = new StringBuffer(
                "The proposed action will cause a pedigree cycle involving subjects with UID:");
        boolean first = true;
        for (String uid : circularUIDs) {
            if (first) {
                sb.append(uid);
                first = false;
            } else {
                sb.append(", " + uid);
            }
        }
        sb.append(".");
        this.error(sb.toString());
        target.add(feedbackPanel);
        return;
    }

    // Assign new parent relationships

    SubjectVO criteriaSubjectVo = new SubjectVO();
    criteriaSubjectVo.getLinkSubjectStudy().setStudy(study);
    criteriaSubjectVo.getLinkSubjectStudy().setSubjectUID(subjectUID);
    Collection<SubjectVO> subjects = iArkCommonService.getSubject(criteriaSubjectVo);
    SubjectVO subjectVo = subjects.iterator().next();
    pedigreeRelationship.setSubject(subjectVo.getLinkSubjectStudy());

    criteriaSubjectVo.getLinkSubjectStudy().setSubjectUID(parentUID);
    subjects = iArkCommonService.getSubject(criteriaSubjectVo);
    subjectVo = subjects.iterator().next();
    pedigreeRelationship.setRelative(subjectVo.getLinkSubjectStudy());

    String gender = subject.getLinkSubjectStudy().getPerson().getGenderType().getName();

    List<Relationship> relationships = iArkCommonService.getFamilyRelationships();
    for (Relationship relationship : relationships) {
        if ("Male".equalsIgnoreCase(gender) && "Father".equalsIgnoreCase(relationship.getName())) {
            pedigreeRelationship.setRelationship(relationship);
            break;
        }

        if ("Female".equalsIgnoreCase(gender) && "Mother".equalsIgnoreCase(relationship.getName())) {
            pedigreeRelationship.setRelationship(relationship);
            break;
        }
    }

    iStudyService.create(pedigreeRelationship);
    modalWindow.close(target);
}

From source file:au.org.theark.study.web.component.global.subject.SubjectContainerPanel.java

License:Open Source License

/**
 * @param id/*from w ww.j a v a 2 s .c  om*/
 * @param studyLogoMarkup 
 * @param studyNameMarkup 
 * @param mainTabs 
 */
public SubjectContainerPanel(String id, WebMarkupContainer arkContextMarkup, WebMarkupContainer studyNameMarkup,
        WebMarkupContainer studyLogoMarkup, TabbedPanel mainTabs) {
    super(id);
    this.arkContextMarkup = arkContextMarkup;
    this.studyNameMarkup = studyNameMarkup;
    this.studyLogoMarkup = studyLogoMarkup;
    this.mainTabs = mainTabs;

    /* Initialise the CPM */
    cpModel = new CompoundPropertyModel<SubjectVO>(new SubjectVO());

    // Restrict to subjects in current study in session
    sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    if (sessionStudyId != null) {
        study = iArkCommonService.getStudy(sessionStudyId);
    }

    containerForm = new ContainerForm("containerForm", cpModel);
    containerForm.add(initialiseFeedBackPanel());
    containerForm.add(initialiseSearchResults());
    containerForm.add(initialiseSearchPanel());

    prerenderContextCheck();

    add(containerForm);
}

From source file:au.org.theark.study.web.component.global.subject.SubjectContainerPanel.java

License:Open Source License

/**
 * Re-use in pedigree panel- commented due to looks like un used in here.
 * //from  ww  w .j  av a 2 s  .  c o m
 * @param id
 * @param studyLogoMarkup 
 * @param studyNameMarkup 
 * @param modalWindow
 */
/*public SubjectContainerPanel(String id, WebMarkupContainer arkContextMarkup, WebMarkupContainer studyNameMarkup, WebMarkupContainer studyLogoMarkup,AbstractDetailModalWindow modalWindow,String gender,List<RelationshipVo> relatives) {
   super(id);
   this.arkContextMarkup = arkContextMarkup;
   this.studyNameMarkup = studyNameMarkup;
   this.studyLogoMarkup = studyLogoMarkup;
           
    Initialise the CPM 
           
   SubjectVO subjectVO = new SubjectVO();
   subjectVO.setEnableNewButton(false);
   cpModel = new CompoundPropertyModel<SubjectVO>(subjectVO);
           
           
// Restrict to subjects in current study in session
   sessionStudyId = (Long) SecurityUtils.getSubject().getSession().getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
   if (sessionStudyId != null) {
 study = iArkCommonService.getStudy(sessionStudyId);
 List<Study> studyListForUser = iArkCommonService.getParentAndChildStudies(sessionStudyId);
 cpModel.getObject().setStudyList(studyListForUser);
   }
        
   containerForm = new ContainerForm("containerForm", cpModel);
   containerForm.add(initialiseFeedBackPanel());
   containerForm.add(initialiseSearchResults(modalWindow,gender,relatives));
   containerForm.add(initialiseSearchPanel());
           
   arkCrudContainerVO.getSearchPanelContainer().get("searchComponentPanel").get("searchForm").get("genderType").setEnabled(false);
   arkCrudContainerVO.getSearchPanelContainer().get("searchComponentPanel").get("searchForm").get("study").setEnabled(false);
           
   add(containerForm);
}*/

@SuppressWarnings("unchecked")
protected void prerenderContextCheck() {

    SecurityUtils.getSubject().getSession().setAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID, null);

    // Get the Person in Context and determine the Person Type
    Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID);

    if ((sessionStudyId != null) && (sessionPersonId != null)) {
        String sessionPersonType = (String) SecurityUtils.getSubject().getSession()
                .getAttribute(au.org.theark.core.Constants.PERSON_TYPE);
        if (sessionPersonType.equals(au.org.theark.core.Constants.PERSON_CONTEXT_TYPE_SUBJECT)) {
            Person person;
            boolean contextLoaded = false;
            try {
                person = studyService.getPerson(sessionPersonId);
                SubjectVO subjectVO = new SubjectVO();
                subjectVO.getLinkSubjectStudy().setPerson(person); // must have Person
                subjectVO.getLinkSubjectStudy().setStudy(study); // must have Study
                List<SubjectVO> subjectList = (List<SubjectVO>) iArkCommonService.getSubject(subjectVO);
                subjectList.get(0).setStudyList(cpModel.getObject().getStudyList());
                containerForm.setModelObject(subjectList.get(0));
                contextLoaded = true;
            } catch (EntityNotFoundException e) {
                log.error(e.getMessage());
            } catch (ArkSystemException e) {
                log.error(e.getMessage());
            }

            if (contextLoaded) {
                // Available/assigned child studies
                List<Study> availableChildStudies = new ArrayList<Study>(0);
                List<Study> selectedChildStudies = new ArrayList<Study>(0);

                if (containerForm.getModelObject().getLinkSubjectStudy().getStudy().getParentStudy() != null) {
                    availableChildStudies = iStudyService.getChildStudyListOfParent(
                            containerForm.getModelObject().getLinkSubjectStudy().getStudy());
                    selectedChildStudies = iArkCommonService.getAssignedChildStudyListForPerson(
                            containerForm.getModelObject().getLinkSubjectStudy().getStudy(),
                            containerForm.getModelObject().getLinkSubjectStudy().getPerson());
                }

                containerForm.getModelObject().setAvailableChildStudies(availableChildStudies);
                containerForm.getModelObject().setSelectedChildStudies(selectedChildStudies);

                // Put into Detail View mode
                arkCrudContainerVO.getSearchPanelContainer().setVisible(false);
                arkCrudContainerVO.getSearchResultPanelContainer().setVisible(false);
                arkCrudContainerVO.getEditButtonContainer().setVisible(false);
            }
        }
    }
}