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.lims.web.component.subjectlims.lims.biocollection.form.BioCollectionListForm.java

License:Open Source License

private void initialiseNewButton() {
    newButton = new ArkBusyAjaxButton(Constants.NEW) {

        private static final long serialVersionUID = 1L;

        @Override/*  w w w  .  j  av a2  s  .c o  m*/
        public boolean isVisible() {
            boolean isVisible = true;

            String sessionSubjectUID = (String) SecurityUtils.getSubject().getSession()
                    .getAttribute(au.org.theark.core.Constants.SUBJECTUID);
            isVisible = (ArkPermissionHelper.isActionPermitted(au.org.theark.core.Constants.NEW)
                    && sessionSubjectUID != null);

            return isVisible;
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            onNew(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            this.error("An unexpected error occurred. Unable to proceed with New BioCollection.");
        }
    };
    newButton.setDefaultFormProcessing(false);

    add(newButton);
}

From source file:au.org.theark.lims.web.component.subjectlims.lims.biospecimen.form.BiospecimenDataEntryModalDetailForm.java

License:Open Source License

@Override
protected void onSave(AjaxRequestTarget target) {
    boolean saveOk = true;
    org.apache.shiro.subject.Subject currentUser = SecurityUtils.getSubject();
    try {/* w  w  w  .jav a 2s . c o  m*/
        if (cpModel.getObject().getBiospecimen().getId() == null) {
            // Save/Process/Aliquot
            if (cpModel.getObject().getBiospecimenProcessing().isEmpty()) { //empty
                // Normal Save functionality
                // Initial transaction detail
                currentUser = SecurityUtils.getSubject();
                cpModel.getObject().getBioTransaction().setRecorder(currentUser.getPrincipal().toString());
                cpModel.getObject().getBioTransaction().setUnit(cpModel.getObject().getBiospecimen().getUnit()); //TODO: soon in web form

                iLimsService.createBiospecimen(cpModel.getObject());

                // Update location
                if (cpModel.getObject().getBiospecimenLocationVO().getIsAllocated()) {
                    if (cpModel.getObject().getInvCell() != null
                            && cpModel.getObject().getInvCell().getBiospecimen() != null) {
                        iInventoryService.updateInvCell(cpModel.getObject().getInvCell());
                    }
                }
                this.info("Biospecimen " + cpModel.getObject().getBiospecimen().getBiospecimenUid()
                        + " was created successfully");
                setQuantityLabel();
            } else if (cpModel.getObject().getBiospecimenProcessing()
                    .equalsIgnoreCase(au.org.theark.lims.web.Constants.BIOSPECIMEN_PROCESSING_PROCESSING)) {
                // Process the biospecimen
                try {
                    LimsVO limsVo = cpModel.getObject();
                    Biospecimen biospecimen = limsVo.getBiospecimen();
                    Biospecimen parentBiospecimen = iLimsService
                            .getBiospecimen(biospecimen.getParent().getId());
                    double qtyUsedFromParent = limsVo.getParentBiospecimen().getQuantity();

                    if (qtyUsedFromParent > parentBiospecimen.getQuantity()) {
                        StringBuffer errorMessage = new StringBuffer();

                        errorMessage.append("Cannot process more than ");
                        errorMessage.append(parentBiospecimen.getQuantity());
                        errorMessage.append(parentBiospecimen.getUnit().getName());
                        errorMessage.append(" of the parent biospecimen");

                        this.error(errorMessage);
                        saveOk = false;
                    } else {
                        // Process the biospecimen and it's parent
                        iLimsService.createBiospecimen(limsVo);

                        // Add parent transaction
                        LimsVO parentLimsVo = new LimsVO();
                        parentLimsVo.setBiospecimen(parentBiospecimen);
                        parentLimsVo.getBioTransaction().setId(null);
                        parentLimsVo.getBioTransaction().setUnit(biospecimen.getUnit()); //TODO: soon in web form
                        parentLimsVo.getBioTransaction().setBiospecimen(parentBiospecimen);
                        parentLimsVo.getBioTransaction().setTransactionDate(Calendar.getInstance().getTime());
                        parentLimsVo.getBioTransaction()
                                .setReason("Processed for: " + biospecimen.getBiospecimenUid());
                        parentLimsVo.getBioTransaction().setRecorder(currentUser.getPrincipal().toString());

                        // NOTE: Removing from parent is negative-value transaction
                        parentLimsVo.getBioTransaction().setQuantity(qtyUsedFromParent * -1);
                        BioTransactionStatus bioTransactionStatus = iLimsService
                                .getBioTransactionStatusByName("Processed");
                        parentLimsVo.getBioTransaction().setStatus(bioTransactionStatus);
                        iLimsService.createBioTransaction(parentLimsVo);

                        this.info("Biospecimen " + cpModel.getObject().getBiospecimen().getBiospecimenUid()
                                + " was created successfully");
                        setQuantityLabel();
                    }
                } catch (EntityNotFoundException e) {
                    log.error(e.getMessage());
                }
            } else if (cpModel.getObject().getBiospecimenProcessing()
                    .equalsIgnoreCase(au.org.theark.lims.web.Constants.BIOSPECIMEN_PROCESSING_ALIQUOTING)) {
                // Aliquot the biospecimen
                try {
                    LimsVO limsVo = cpModel.getObject();
                    Biospecimen biospecimen = limsVo.getBiospecimen();
                    BioTransaction bioTransaction = limsVo.getBioTransaction();
                    Biospecimen parentBiospecimen = iLimsService
                            .getBiospecimen(biospecimen.getParent().getId());

                    if (parentBiospecimen.getQuantity() != null
                            && bioTransaction.getQuantity() > parentBiospecimen.getQuantity()) {
                        StringBuffer errorMessage = new StringBuffer();

                        errorMessage.append("Cannot aliquot more than ");
                        errorMessage.append(parentBiospecimen.getQuantity());
                        errorMessage.append(parentBiospecimen.getUnit().getName());
                        errorMessage.append(" of the parent biospecimen");

                        this.error(errorMessage);
                        saveOk = false;
                    } else {
                        // Aliquot the biospecimen and it's parent
                        iLimsService.createBiospecimen(limsVo);

                        // Add parent transaction
                        LimsVO parentLimsVo = new LimsVO();
                        //parentLimsVo.setBiospecimen(parentBiospecimen);
                        parentLimsVo.getBioTransaction().setId(null);
                        parentLimsVo.getBioTransaction().setBiospecimen(parentBiospecimen);
                        parentLimsVo.getBioTransaction().setUnit(biospecimen.getUnit()); //TODO: soon in web form
                        parentLimsVo.getBioTransaction().setTransactionDate(Calendar.getInstance().getTime());
                        parentLimsVo.getBioTransaction()
                                .setReason("Sub-Aliquot for: " + biospecimen.getBiospecimenUid());
                        parentLimsVo.getBioTransaction().setRecorder(currentUser.getPrincipal().toString());

                        // NOTE: Removing from parent is negative-value transaction
                        parentLimsVo.getBioTransaction().setQuantity(bioTransaction.getQuantity() * -1);
                        BioTransactionStatus bioTransactionStatus = iLimsService
                                .getBioTransactionStatusByName("Aliquoted");
                        parentLimsVo.getBioTransaction().setStatus(bioTransactionStatus);
                        iLimsService.createBioTransaction(parentLimsVo);

                        this.info("Biospecimen " + cpModel.getObject().getBiospecimen().getBiospecimenUid()
                                + " was created successfully");
                        setQuantityLabel();
                    }
                } catch (EntityNotFoundException e) {
                    log.error(e.getMessage());
                }
            }
        } else {
            // Update location
            if (cpModel.getObject().getBiospecimenLocationVO().getIsAllocated()) {
                if (cpModel.getObject().getInvCell() != null
                        && cpModel.getObject().getInvCell().getBiospecimen() != null) {
                    iInventoryService.updateInvCell(cpModel.getObject().getInvCell());
                }
            }

            // Update qty avail
            cpModel.getObject().getBiospecimen()
                    .setQuantity(iLimsService.getQuantityAvailable(cpModel.getObject().getBiospecimen()));

            // Update biospecimen
            iLimsService.updateBiospecimen(cpModel.getObject());

            this.info("Biospecimen " + cpModel.getObject().getBiospecimen().getBiospecimenUid()
                    + " was updated successfully");

            // Hide/show barcode image
            barcodeImage.setVisible(cpModel.getObject().getBiospecimen().getBarcoded());
            target.add(barcodeImage);
            setQuantityLabel();
        }

        if (saveOk) {
            // Allow the Biospecimen custom data to be saved any time save is performed
            if (biospecimenCFDataEntryPanel instanceof BiospecimenCustomDataDataViewPanel) {
                ((BiospecimenCustomDataDataViewPanel) biospecimenCFDataEntryPanel).saveCustomData();
            }

            // refresh the custom field data entry panel (if necessary)
            //if (initialiseBiospecimenCFDataEntry(cpModel.getObject().getCustomFieldCategory())) {
            //arkCrudContainerVo.getDetailPanelFormContainer().addOrReplace(biospecimenCFDataEntryPanel);
            arkCrudContainerVo.getDetailPanelFormContainer().addOrReplace(dataEntryWMC);
            //}

            // refresh the bio transactions (if necessary)
            if (initialiseBioTransactionListPanel()) {
                arkCrudContainerVo.getDetailPanelFormContainer().addOrReplace(bioTransactionListPanel);
            }

            // refresh the location panel
            if (initialiseBiospecimenLocationPanel()) {
                arkCrudContainerVo.getDetailPanelFormContainer().addOrReplace(biospecimenLocationPanel);
            }

            // Disable initial transaction details, and hide inital quantity text box
            bioTransactionDetailWmc.setEnabled(true);
            bioTransactionQuantityTxtFld.setVisible(false);
            quantityTxtFld.setVisible(true);
            // quantityTxtFld.setModelObject(bioTransactionQuantityTxtFld.getModelObject());
            target.add(bioTransactionDetailWmc);

            barcodeImage.setVisible(cpModel.getObject().getBiospecimen().getBarcoded());
            target.add(barcodeImage);

            // Enable/re-enable buttons panel
            initialiseBiospecimenButtonsPanel();

            target.add(biospecimenbuttonsPanel);

            cpModel.getObject().setBiospecimenProcessing("");
            parentQuantityTxtFld.setVisible(false);
            target.add(parentQuantityTxtFld);
            onSavePostProcess(target);
            //Replace the new button to 
            replaceDeleteButton();

        }
    } catch (ArkSystemException e) {
        this.error(e.getMessage());
    }
    processErrors(target);
}

From source file:au.org.theark.lims.web.component.subjectlims.lims.biospecimen.form.BiospecimenDataEntryModalDetailForm.java

License:Open Source License

/**
 * Takes all details of a biospecimen, copies to a new Biospecimen, then allows editing of details before save
 * /*from www. ja  va 2s . c om*/
 * @param target
 */
protected void onCloneBiospecimen(AjaxRequestTarget target) {
    final Biospecimen clonedBiospecimen = cpModel.getObject().getBiospecimen();
    final String clonedBiospecimenUid = clonedBiospecimen.getBiospecimenUid();
    final Biospecimen biospecimen = new Biospecimen();

    try {
        // Copy parent biospecimen details to new biospecimen
        PropertyUtils.copyProperties(biospecimen, clonedBiospecimen);

        // Amend specific fields/detail
        biospecimen.setId(null);

        if (biospecimen.getStudy().getAutoGenerateBiospecimenUid()) {
            biospecimen.setBiospecimenUid(Constants.AUTO_GENERATED);
        } else {
            biospecimen.setBiospecimenUid(null);
        }

        // Cloning not a child biospecimen
        // biospecimen.setParent(clonedBiospecimen);
        // biospecimen.setParentUid(clonedBiospecimen.getBiospecimenUid());

        biospecimen.setSampleType(clonedBiospecimen.getSampleType());
        biospecimen.setBioCollection(clonedBiospecimen.getBioCollection());
        biospecimen.setQuantity(null);
        biospecimen.setUnit(clonedBiospecimen.getUnit());
        biospecimen.setComments("Clone of " + clonedBiospecimenUid);
        biospecimen.setBarcoded(false);
        biospecimen.setQuantity(clonedBiospecimen.getQuantity());
        biospecimen.setUnit(clonedBiospecimen.getUnit());
        biospecimen.setTreatmentType(clonedBiospecimen.getTreatmentType());
        biospecimen.setChildren(new ArrayList<Biospecimen>(0));

        Study studyFromClone = clonedBiospecimen.getStudy();
        // There should be a study and only then do the rest of the code here
        if (studyFromClone != null) {
            Study study = iArkCommonService.getStudy(studyFromClone.getId());
            biospecimen.setStudy(study);
            // Reset the biospecimen detail
            cpModel.getObject().setBiospecimen(biospecimen);

            // Set the bioTransaction detail
            org.apache.shiro.subject.Subject currentUser = SecurityUtils.getSubject();
            cpModel.getObject().getBioTransaction().setRecorder(currentUser.getPrincipal().toString());
            cpModel.getObject().getBioTransaction().setQuantity(null);
            cpModel.getObject().getBioTransaction().setUnit(biospecimen.getUnit());

            enableQuantityTreatment(target);
            //Refer the solution for the ARK-1764
            CompoundPropertyModel<BiospecimenCustomDataVO> bioCFDataCpModel = new CompoundPropertyModel<BiospecimenCustomDataVO>(
                    new BiospecimenCustomDataVO());
            bioCFDataCpModel.getObject().setBiospecimen(biospecimen);
            bioCFDataCpModel.getObject().setArkFunction(iArkCommonService
                    .getArkFunctionByName(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_LIMS_CUSTOM_FIELD));
            biospecimenCFDataEntryPanel = new BiospecimenCustomDataDataViewPanel("biospecimenCFDataEntryPanel",
                    bioCFDataCpModel).initialisePanel(iArkCommonService.getCustomFieldsPerPage(), null);
            dataEntryWMC.addOrReplace(biospecimenCFDataEntryPanel);
            arkCrudContainerVo.getDetailPanelFormContainer().addOrReplace(dataEntryWMC);
            target.add(biospecimenCFDataEntryPanel);
            target.add(dataEntryWMC);
            target.add(arkCrudContainerVo.getDetailPanelFormContainer());
            // refresh the bioTransaction panel
            initialiseBioTransactionListPanel();
            arkCrudContainerVo.getDetailPanelFormContainer().addOrReplace(bioTransactionListPanel);

            // refresh the location panel
            cpModel.getObject().setBiospecimenLocationVO(new BiospecimenLocationVO());
            initialiseBiospecimenLocationPanel();
            arkCrudContainerVo.getDetailPanelFormContainer().addOrReplace(biospecimenLocationPanel);
            target.add(biospecimenLocationPanel);

            // Notify in progress
            this.info("Cloning biospecimen " + clonedBiospecimenUid + ", please save to confirm");
            target.add(feedbackPanel);

            // hide button panel
            biospecimenbuttonsPanel.setVisible(false);
            target.add(biospecimenbuttonsPanel);
        } else {
            log.error("Cannot find a study for the cloned biospecimen.");
        }
    } catch (IllegalAccessException e) {
        log.error(e.getMessage());
    } catch (InvocationTargetException e) {
        log.error(e.getMessage());
    } catch (NoSuchMethodException e) {
        log.error(e.getMessage());
    }

}

From source file:au.org.theark.lims.web.component.subjectlims.lims.biospecimen.form.BiospecimenDataEntryModalDetailForm.java

License:Open Source License

/**
 * Handle processing or aliquoting of a parent biospecimen. Process essentially changing the type of a parent biospecimen. Aliquot essentially
 * taking an amount from a parent biospecimen.
 * /*from w  ww  . ja v  a 2  s. c  o m*/
 * @param target
 *           AjxaxRequestTarget
 * @param processOrAliquot
 *           indication to whether a process or an aliquot
 * @param comment
 *           comment to add to biospecimen comments
 */
protected void processOrAliquot(AjaxRequestTarget target, String processOrAliquot, String comment) {
    final Biospecimen parentBiospecimen = cpModel.getObject().getBiospecimen();
    final String parentBiospecimenUid = parentBiospecimen.getBiospecimenUid();
    final Biospecimen biospecimen = new Biospecimen();

    cpModel.getObject().setParentBiospecimen(parentBiospecimen);

    try {
        // Copy parent biospecimen details to new biospecimen
        PropertyUtils.copyProperties(biospecimen, parentBiospecimen);

        // Amend specific fields/detail
        biospecimen.setId(null);

        if (biospecimen.getStudy().getAutoGenerateBiospecimenUid()) {
            biospecimen.setBiospecimenUid(Constants.AUTO_GENERATED);
        } else {
            biospecimen.setBiospecimenUid(null);
        }
        /***
         * TRAV TO INVESTIGATE ASAP
        // Cloning not a child biospecimen
        // biospecimen.setParent(clonedBiospecimen);
        // biospecimen.setParentUid(clonedBiospecimen.getBiospecimenUid());
        **/

        biospecimen.setParent(parentBiospecimen);
        biospecimen.setParentUid(parentBiospecimen.getBiospecimenUid());
        biospecimen.setSampleType(parentBiospecimen.getSampleType());
        biospecimen.setBioCollection(parentBiospecimen.getBioCollection());
        biospecimen.setQuantity(null);
        biospecimen.setUnit(parentBiospecimen.getUnit());
        biospecimen.setComments(comment + parentBiospecimenUid);
        biospecimen.setBarcoded(false);
        biospecimen.setTreatmentType(parentBiospecimen.getTreatmentType());
        biospecimen.setChildren(new ArrayList<Biospecimen>(0));

        Study studyFromParent = parentBiospecimen.getStudy();
        // There should be a study and only then do the rest of the code here
        if (studyFromParent != null) {
            Study study = iArkCommonService.getStudy(studyFromParent.getId());
            biospecimen.setStudy(study);
            // Reset the biospecimen detail
            cpModel.getObject().setBiospecimen(biospecimen);
            cpModel.getObject().setBiospecimenProcessing(processOrAliquot);
            // Set the bioTransaction detail
            org.apache.shiro.subject.Subject currentUser = SecurityUtils.getSubject();
            cpModel.getObject().getBioTransaction().setRecorder(currentUser.getPrincipal().toString());
            cpModel.getObject().getBioTransaction().setQuantity(null);
            cpModel.getObject().getBioTransaction().setUnit(biospecimen.getUnit()); //TODO: unit
            enableQuantityTreatment(target);
            // Refer the solution for the ARK-1764
            CompoundPropertyModel<BiospecimenCustomDataVO> bioCFDataCpModel = new CompoundPropertyModel<BiospecimenCustomDataVO>(
                    new BiospecimenCustomDataVO());
            bioCFDataCpModel.getObject().setBiospecimen(biospecimen);
            bioCFDataCpModel.getObject().setArkFunction(iArkCommonService
                    .getArkFunctionByName(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_LIMS_CUSTOM_FIELD));
            biospecimenCFDataEntryPanel = new BiospecimenCustomDataDataViewPanel("biospecimenCFDataEntryPanel",
                    bioCFDataCpModel).initialisePanel(iArkCommonService.getCustomFieldsPerPage(), null);
            dataEntryWMC.addOrReplace(biospecimenCFDataEntryPanel);
            arkCrudContainerVo.getDetailPanelFormContainer().addOrReplace(dataEntryWMC);
            target.add(biospecimenCFDataEntryPanel);
            target.add(dataEntryWMC);
            target.add(arkCrudContainerVo.getDetailPanelFormContainer());
            // refresh the bioTransaction panel
            initialiseBioTransactionListPanel();
            arkCrudContainerVo.getDetailPanelFormContainer().addOrReplace(bioTransactionListPanel);
            // refresh the location panel
            cpModel.getObject().setBiospecimenLocationVO(new BiospecimenLocationVO());
            initialiseBiospecimenLocationPanel();
            arkCrudContainerVo.getDetailPanelFormContainer().addOrReplace(biospecimenLocationPanel);
            target.add(biospecimenLocationPanel);
            // Notify in progress
            this.info(processOrAliquot + " biospecimen " + cpModel.getObject().getBiospecimen().getParentUid()
                    + ", please save to confirm");
            target.add(feedbackPanel);

            // hide button panel
            biospecimenbuttonsPanel.setVisible(false);
            target.add(biospecimenbuttonsPanel);
        } else {
            log.error("Cannot find a study for the parent biospecimen.");
        }
    } catch (IllegalAccessException e) {
        log.error(e.getMessage());
    } catch (InvocationTargetException e) {
        log.error(e.getMessage());
    } catch (NoSuchMethodException e) {
        log.error(e.getMessage());
    }
}

From source file:au.org.theark.lims.web.component.subjectlims.lims.biospecimen.form.BiospecimenListForm.java

License:Open Source License

@Override
public void onBeforeRender() {
    // Get session data (used for subject search)
    Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    String sessionSubjectUID = (String) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.SUBJECTUID);

    if ((sessionStudyId != null) && (sessionSubjectUID != null)) {
        LinkSubjectStudy linkSubjectStudy = null;
        Study study = null;/*from   ww  w . j  a  v  a  2 s  .  c  om*/
        boolean contextLoaded = false;
        try {
            study = iArkCommonService.getStudy(sessionStudyId);
            linkSubjectStudy = iArkCommonService.getSubjectByUID(sessionSubjectUID, study);
            if (study != null && linkSubjectStudy != null) {
                contextLoaded = true;
            }
        } catch (EntityNotFoundException e) {
            log.error(e.getMessage());
        }

        if (contextLoaded) {
            // Successfully loaded from backend
            cpModel.getObject().setLinkSubjectStudy(linkSubjectStudy);
            cpModel.getObject().getBiospecimen().setLinkSubjectStudy(linkSubjectStudy);
            cpModel.getObject().getBiospecimen().setStudy(study);
        }
    }

    super.onBeforeRender();
}

From source file:au.org.theark.lims.web.component.subjectlims.lims.biospecimen.form.BiospecimenListForm.java

License:Open Source License

private void initialiseNewButton() {
    newButton = new ArkBusyAjaxButton(Constants.NEW) {

        private static final long serialVersionUID = 1L;

        @Override//  w  w w  . j  a  v a 2  s . c o m
        public boolean isVisible() {
            boolean isVisible = true;

            String sessionSubjectUID = (String) SecurityUtils.getSubject().getSession()
                    .getAttribute(au.org.theark.core.Constants.SUBJECTUID);
            isVisible = (ArkPermissionHelper.isActionPermitted(au.org.theark.core.Constants.NEW)
                    && sessionSubjectUID != null);

            return isVisible;
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            onNew(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            this.error("An unexpected error occurred. Unable to proceed with New Biospecimen.");
        }
    };
    newButton.setDefaultFormProcessing(false);

    add(newButton);
}

From source file:au.org.theark.lims.web.component.subjectlims.lims.biospecimen.form.BiospecimenListForm.java

License:Open Source License

private void initialiseBatchCreateButton() {
    batchCreateButton = new ArkBusyAjaxButton("batchCreate") {

        private static final long serialVersionUID = 1L;

        @Override/*from   w  w  w  . j  a  va2  s .c om*/
        public boolean isVisible() {
            boolean isVisible = true;

            String sessionSubjectUID = (String) SecurityUtils.getSubject().getSession()
                    .getAttribute(au.org.theark.core.Constants.SUBJECTUID);
            isVisible = (ArkPermissionHelper.isActionPermitted(au.org.theark.core.Constants.NEW)
                    && sessionSubjectUID != null);

            return isVisible;
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            onBatchCreate(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            this.error("An unexpected error occurred. Unable to proceed with Batch Crreate Biospecimen.");
        }
    };
    batchCreateButton.setDefaultFormProcessing(false);

    add(batchCreateButton);
}

From source file:au.org.theark.lims.web.component.subjectlims.lims.biospecimen.form.BiospecimenListForm.java

License:Open Source License

private void onBatchCreate(AjaxRequestTarget target) {
    // Needs CREATE permission AND a BioCollection to select from
    boolean hasBioCollections = false;

    // Get session data (used for subject search)
    Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    String sessionSubjectUID = (String) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.SUBJECTUID);

    if ((sessionStudyId != null) && (sessionSubjectUID != null)) {
        LinkSubjectStudy linkSubjectStudy = null;
        Study study = null;/*from   ww w  .ja v a 2s .com*/
        boolean contextLoaded = false;
        try {
            study = iArkCommonService.getStudy(sessionStudyId);
            linkSubjectStudy = iArkCommonService.getSubjectByUID(sessionSubjectUID, study);
            if (study != null && linkSubjectStudy != null) {
                contextLoaded = true;
            }
        } catch (EntityNotFoundException e) {
            log.error(e.getMessage());
        }

        if (contextLoaded) {
            // Successfully loaded from backend
            cpModel.getObject().setLinkSubjectStudy(linkSubjectStudy);
            cpModel.getObject().getBiospecimen().setLinkSubjectStudy(linkSubjectStudy);
            cpModel.getObject().getBiospecimen().setStudy(study);
        }
    }

    hasBioCollections = iLimsService.hasBioCollections(cpModel.getObject().getLinkSubjectStudy());

    if (hasBioCollections) {
        // Set new Biospecimen into model, then show modalWindow to save
        CompoundPropertyModel<LimsVO> newModel = new CompoundPropertyModel<LimsVO>(new LimsVO());
        newModel.getObject().setLinkSubjectStudy(cpModel.getObject().getLinkSubjectStudy());
        newModel.getObject().setStudy(cpModel.getObject().getStudy());
        newModel.getObject().getBiospecimen().setLinkSubjectStudy(getModelObject().getLinkSubjectStudy());
        newModel.getObject().getBiospecimen().setStudy(getModelObject().getLinkSubjectStudy().getStudy());

        // Allow for autogen or manual biospecimenUid entry
        boolean isAutoBiospecimen = getModelObject().getLinkSubjectStudy().getStudy()
                .getAutoGenerateBiospecimenUid();
        if (isAutoBiospecimen) {
            modalContentPanel = new AutoGenBatchCreateBiospecimenPanel("content", feedbackPanel, newModel,
                    modalWindow);
        } else {
            modalContentPanel = new ManualBatchCreateBiospecimenPanel("content", feedbackPanel, newModel,
                    modalWindow);
        }

        // Set the modalWindow title and content
        modalWindow.setTitle("Batch Create Biospecimens");
        modalWindow.setContent(modalContentPanel);
        modalWindow.show(target);
    } else {
        this.error("No Biospecimen Collections exist. Please create at least one Collection.");
    }
    // refresh the feedback messages
    target.add(feedbackPanel);
}

From source file:au.org.theark.lims.web.component.subjectlims.lims.biospecimen.form.BiospecimenListForm.java

License:Open Source License

/**
 * /*w  w w.j  ava  2s .c  om*/
 * @param iModel
 * @return the pageableListView of BioCollection
 */
public DataView<Biospecimen> buildDataView(ArkDataProvider2<LimsVO, Biospecimen> biospecimenProvider) {

    DataView<Biospecimen> biospecimenDataView = new DataView<Biospecimen>("biospecimenList",
            biospecimenProvider) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final Item<Biospecimen> item) {
            item.setOutputMarkupId(true);
            // DO NOT store the item.getModelObject! Checking it is ok...
            final Biospecimen biospecimen = item.getModelObject();

            WebMarkupContainer rowDetailsWMC = new WebMarkupContainer("rowDetailsWMC", item.getModel());
            ArkBusyAjaxLink listDetailsLink = new ArkBusyAjaxLink("listDetailsLink") {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    CompoundPropertyModel<LimsVO> newModel = new CompoundPropertyModel<LimsVO>(new LimsVO());
                    try {
                        Biospecimen biospecimenFromDB = iLimsService.getBiospecimen(biospecimen.getId());
                        newModel.getObject().setBiospecimen(biospecimenFromDB);
                        newModel.getObject().setBioCollection(biospecimenFromDB.getBioCollection());
                        newModel.getObject().setTreeModel(cpModel.getObject().getTreeModel());
                        showModalWindow(target, newModel);
                    } catch (EntityNotFoundException e) {
                        log.error(e.getMessage());
                    }
                }
            };

            idLblFld = new Label("biospecimen.id", String.valueOf(biospecimen.getId()));

            nameLblFld = new Label("biospecimen.biospecimenUid", biospecimen.getBiospecimenUid());
            listDetailsLink.add(nameLblFld);
            rowDetailsWMC.add(listDetailsLink);

            studyLblFld = new Label("biospecimen.study.name", biospecimen.getStudy().getName());
            sampleTypeLblFld = new Label("biospecimen.sampleType.name", biospecimen.getSampleType().getName());
            collectionLblFld = new Label("biospecimen.bioCollection.biocollectionUid",
                    biospecimen.getBioCollection().getBiocollectionUid());
            commentsLblFld = new Label("biospecimen.comments", biospecimen.getComments());

            biospecimen.setQuantity(iLimsService.getQuantityAvailable(biospecimen));
            if (biospecimen.getQuantity() == null) {
                quantityLblFld = new Label("biospecimen.quantity", "0");
            } else {
                quantityLblFld = new Label("biospecimen.quantity", biospecimen.getQuantity().toString());
            }
            if (biospecimen.getUnit() == null) {
                unitsLblFld = new Label("biospecimen.unit", "");
            } else {
                unitsLblFld = new Label("biospecimen.unit", biospecimen.getUnit().getName());
            }

            try {
                locationLbl = new Label("biospecimen.location", "view");
                locationLink = new ArkBusyAjaxLink("biospecimen.location.link") {

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

                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        CompoundPropertyModel<LimsVO> newModel = new CompoundPropertyModel<LimsVO>(
                                new LimsVO());
                        newModel.getObject().getBiospecimen().setId(biospecimen.getId());
                        BiospecimenLocationVO biospecimenLocationVo;
                        try {
                            biospecimenLocationVo = iInventoryService.getBiospecimenLocation(biospecimen);
                            newModel.getObject().setBiospecimenLocationVO(biospecimenLocationVo);
                            newModel.getObject().setTreeModel(cpModel.getObject().getTreeModel());
                            BioLocationPanel bioLocationPanel = new BioLocationPanel("content", newModel) {
                                /**
                                 * 
                                 */
                                private static final long serialVersionUID = 1L;

                                @Override
                                public void refreshParentPanel(AjaxRequestTarget target) {
                                }
                            };
                            bioLocationPanel.getUnallocateButton().setVisible(false);
                            bioLocationPanel.add(new AttributeModifier("class", "detailsPanelBorder"));
                            // Set the modalWindow title and content
                            modalWindow.setTitle("Biospecimen Location Detail");
                            modalWindow.setContent(bioLocationPanel);
                            modalWindow.show(target);
                        } catch (ArkSystemException e) {
                            log.error(e.getMessage());
                        }
                    }
                };

                locationLink.add(locationLbl);

                BiospecimenLocationVO biospecimenLocationVo = iInventoryService
                        .getBiospecimenLocation(biospecimen);
                if (!biospecimenLocationVo.getIsAllocated()) {
                    locationLink.setVisible(false);
                }
            } catch (ArkSystemException e) {
                log.error(e.getMessage());
            }

            item.add(idLblFld);
            item.add(rowDetailsWMC);
            item.add(studyLblFld);
            item.add(sampleTypeLblFld);
            item.add(collectionLblFld);
            //item.add(commentsLblFld);
            item.add(quantityLblFld);
            item.add(unitsLblFld);
            item.add(locationLink);

            if (biospecimen.getBarcoded()) {
                item.addOrReplace(
                        new ContextImage("biospecimen.barcoded", new Model<String>("images/icons/tick.png")));
            } else {
                item.addOrReplace(
                        new ContextImage("biospecimen.barcoded", new Model<String>("images/icons/cross.png")));
            }

            item.add(new AjaxButton("batchAliquot") {

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

                @Override
                public boolean isEnabled() {
                    return ArkPermissionHelper.isActionPermitted(au.org.theark.core.Constants.NEW);
                }

                protected void onSubmit(AjaxRequestTarget target,
                        org.apache.wicket.markup.html.form.Form<?> form) {
                    onBatchAliquot(target, item.getModel());
                    target.add(feedbackPanel);
                };

                protected void onError(AjaxRequestTarget target,
                        org.apache.wicket.markup.html.form.Form<?> form) {
                    target.add(feedbackPanel);
                };

                public boolean isVisible() {
                    SecurityManager securityManager = ThreadContext.getSecurityManager();
                    Subject currentUser = SecurityUtils.getSubject();
                    boolean canCreate = ArkPermissionHelper.hasNewPermission(securityManager, currentUser);
                    boolean validQuantity = (item.getModelObject().getQuantity() != null
                            && item.getModelObject().getQuantity() > 0);
                    return (canCreate && validQuantity);
                };

            }.setDefaultFormProcessing(false));

            item.add(new AjaxButton("allocateUnallocate") {
                private static final long serialVersionUID = 1L;

                @Override
                public boolean isEnabled() {
                    return ArkPermissionHelper.isActionPermitted(au.org.theark.core.Constants.EDIT);
                }

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

                    BiospecimenLocationVO biospecimenLocationVo = null;
                    try {
                        biospecimenLocationVo = iInventoryService.getBiospecimenLocation(biospecimen);
                    } catch (ArkSystemException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    if (biospecimenLocationVo.getIsAllocated()) {
                        //unallocate
                        InvCell invCell = iInventoryService.getInvCellByBiospecimen(biospecimen);
                        invCell.setBiospecimen(null);
                        invCell.setStatus("Empty");
                        iInventoryService.updateInvCell(invCell);

                        try {
                            cpModel.getObject()
                                    .setBiospecimenLocationVO(iInventoryService.getInvCellLocation(invCell));
                            cpModel.getObject().getBiospecimenLocationVO().setIsAllocated(false);
                            cpModel.getObject().setInvCell(invCell);
                        } catch (ArkSystemException e) {
                        }
                    } else {
                        //cpModel.getObject().setBiospecimen(biospecimen);
                        CompoundPropertyModel<LimsVO> cpm = new CompoundPropertyModel<LimsVO>(new LimsVO());
                        cpm.getObject().setBiospecimen(biospecimen);
                        modalContentPanel = new BioModalAllocateDetailPanel("content", modalWindow, cpm);

                        // Set the modalWindow title and content
                        modalWindow.setTitle("Biospecimen Allocation");
                        modalWindow.setContent(modalContentPanel);
                        modalWindow.setWidthUnit("%");
                        modalWindow.setInitialWidth(70);
                        modalWindow.show(target);
                        //cpModel.getObject().setBiospecimen(new Biospecimen());
                        modalWindow.repaintComponent(BiospecimenListForm.this);

                    }
                    target.add(BiospecimenListForm.this);
                }

                @Override
                protected void onError(AjaxRequestTarget target, Form<?> form) {
                }

            }.setDefaultFormProcessing(false).setOutputMarkupPlaceholderTag(true));

            item.add(new AttributeModifier(Constants.CLASS, new AbstractReadOnlyModel() {

                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    return (item.getIndex() % 2 == 1) ? Constants.EVEN : Constants.ODD;
                }
            }));
        }

    };

    return biospecimenDataView;
}

From source file:au.org.theark.lims.web.component.subjectlims.lims.biospecimen.form.BiospecimenListForm.java

License:Open Source License

protected void onNew(AjaxRequestTarget target) {
    // Needs CREATE permission AND a BioCollection to select from
    boolean hasBioCollections = false;

    // Get session data (used for subject search)
    Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    String sessionSubjectUID = (String) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.SUBJECTUID);

    if ((sessionStudyId != null) && (sessionSubjectUID != null)) {
        LinkSubjectStudy linkSubjectStudy = null;
        Study study = null;//from   www .  j  a  v  a 2 s .c  o m
        boolean contextLoaded = false;
        try {
            study = iArkCommonService.getStudy(sessionStudyId);
            linkSubjectStudy = iArkCommonService.getSubjectByUID(sessionSubjectUID, study);
            if (study != null && linkSubjectStudy != null) {
                contextLoaded = true;
            }
        } catch (EntityNotFoundException e) {
            log.error(e.getMessage());
        }

        if (contextLoaded) {
            // Successfully loaded from backend
            cpModel.getObject().setLinkSubjectStudy(linkSubjectStudy);
            cpModel.getObject().getBiospecimen().setLinkSubjectStudy(linkSubjectStudy);
            cpModel.getObject().getBiospecimen().setStudy(study);
        }
    }

    hasBioCollections = iLimsService.hasBioCollections(cpModel.getObject().getLinkSubjectStudy());

    if (hasBioCollections) {
        // Set new Biospecimen into model, then show modalWindow to save
        CompoundPropertyModel<LimsVO> newModel = new CompoundPropertyModel<LimsVO>(new LimsVO());
        newModel.getObject().setLinkSubjectStudy(cpModel.getObject().getLinkSubjectStudy());
        newModel.getObject().setStudy(cpModel.getObject().getStudy());
        newModel.getObject().getBiospecimen().setLinkSubjectStudy(getModelObject().getLinkSubjectStudy());
        newModel.getObject().getBiospecimen().setStudy(getModelObject().getLinkSubjectStudy().getStudy());
        newModel.getObject().setTreeModel(cpModel.getObject().getTreeModel());
        //TODO ASAP handle this newModel.getObject().getBiospecimen().setBiospecimenUid(Constants.AUTO_GENERATED);
        if (getModelObject().getLinkSubjectStudy().getStudy().getAutoGenerateBiospecimenUid()) {
            newModel.getObject().getBiospecimen().setBiospecimenUid(Constants.AUTO_GENERATED);
        } else {
            newModel.getObject().getBiospecimen().setBiospecimenUid("");
        }
        showModalWindow(target, newModel); // listDetailsForm);
    } else {
        this.error("No Biospecimen Collections exist. Please create at least one Collection.");
    }
    // refresh the feedback messages
    target.add(feedbackPanel);
}