List of usage examples for org.apache.shiro SecurityUtils getSubject
public static Subject getSubject()
From source file:au.org.theark.lims.web.component.biospecimenupload.form.SearchForm.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from w w w . j ava 2 s . c o m protected void onSearch(AjaxRequestTarget target) { target.add(feedbackPanel); // Set study in context Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); // Get a list of all Fields for the Study in context Study study = iArkCommonService.getStudy(studyId); Upload searchUpload = getModelObject().getUpload(); searchUpload.setStudy(study); java.util.Collection<Upload> uploadCollection = iArkCommonService.searchUploads(searchUpload); if (uploadCollection != null && uploadCollection.size() == 0) { this.info("Uploads with the specified criteria do not exist in the system."); target.add(feedbackPanel); } getModelObject().setUploadCollection(uploadCollection); listView.removeAll(); arkCrudContainerVO.getSearchResultPanelContainer().setVisible(true);// Make the WebMarkupContainer that houses the search results visible target.add(arkCrudContainerVO.getSearchResultPanelContainer()); }
From source file:au.org.theark.lims.web.component.biotransaction.BioTransactionListPanel.java
License:Open Source License
@Override protected void onBeforeRender() { Long sessionBiospecimenId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.lims.web.Constants.BIOSPECIMEN); if (sessionBiospecimenId != null) { Biospecimen biospecimen = null;/* w w w .ja v a 2s. c o m*/ boolean contextLoaded = false; try { biospecimen = iLimsService.getBiospecimen(sessionBiospecimenId); if (biospecimen != null) { contextLoaded = true; } } catch (EntityNotFoundException e) { log.error(e.getMessage()); } if (contextLoaded) { cpModel.getObject().setBiospecimen(biospecimen); cpModel.getObject().getBioTransaction().setBiospecimen(biospecimen); } } super.onBeforeRender(); }
From source file:au.org.theark.lims.web.component.biotransaction.form.BioTransactionListForm.java
License:Open Source License
public void initialiseForm() { feedbackPanel = new FeedbackPanel("feedback"); feedbackPanel.setOutputMarkupPlaceholderTag(true); add(feedbackPanel);//from w ww .j a va 2 s . c o m //transactionDateLbl = new Label("bioTransaction.transactionDate", simpleDateFormat.format(new Date())); transactionDate = new DateTextField("bioTransaction.transactionDate", new PatternDateConverter(au.org.theark.core.Constants.DD_MM_YYYY, false)); ArkDatePicker dobDatePicker = new ArkDatePicker(); dobDatePicker.bind(transactionDate); transactionDate.add(dobDatePicker); quantity = new TextField<Number>("bioTransaction.quantity"); unitsLbl = new Label("bioTransaction.biospecimen.unit.name", cpModel.getObject().getBiospecimen().getUnit().getName()); reasonLbl = new TextField<String>("bioTransaction.reason"); recorderLbl = new Label("bioTransaction.recorder", SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal().toString()); initStatus(); initAccessRequest(); initSaveButton(); addFormComponents(); }
From source file:au.org.theark.lims.web.component.biotransaction.form.BioTransactionListForm.java
License:Open Source License
private void initSaveButton() { saveButton = new ArkBusyAjaxButton("saveButton") { private static final long serialVersionUID = 1L; @Override//w w w . j a v a 2 s.co m public boolean isVisible() { return true; } @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { // Set defaults //cpModel.getObject().getBioTransaction().setTransactionDate(new Date()); cpModel.getObject().getBioTransaction() .setRecorder(SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal().toString()); Double qtyAvail = iLimsService.getQuantityAvailable(cpModel.getObject().getBiospecimen()); Double txnQuantity = cpModel.getObject().getBioTransaction().getQuantity(); if (txnQuantity == null) { error("Field 'Quantity' is required"); target.add(feedbackPanel); } else if (cpModel.getObject().getBioTransaction().getStatus() == null) { error("Field 'Status' is required"); target.add(feedbackPanel); } else { // Make quantity minus if positive and Aliquoted, Processed or Delivered String status = cpModel.getObject().getBioTransaction().getStatus().getName(); if (status != null && (status.equalsIgnoreCase("Aliquoted") || status.equalsIgnoreCase("Processed") || status.equalsIgnoreCase("Delivered")) && txnQuantity != null && txnQuantity > 0) { txnQuantity = (-1 * txnQuantity); cpModel.getObject().getBioTransaction().setQuantity(txnQuantity); } // Check that quantity specified not greater than available if (txnQuantity < 0 && (Math.abs(txnQuantity) > (qtyAvail == null ? 0 : qtyAvail))) { error("When aliquoting, processing or delivering, transaction quantity may not exceed total quantity available."); target.add(feedbackPanel); } else { cpModel.getObject().getBioTransaction() .setUnit(cpModel.getObject().getBiospecimen().getUnit()); //TODO: Unit iLimsService.createBioTransaction(cpModel.getObject()); info("Transaction saved successfully"); // update biospecimen (qty avail) qtyAvail = iLimsService.getQuantityAvailable(cpModel.getObject().getBiospecimen()); cpModel.getObject().getBiospecimen().setQuantity(qtyAvail); try { iLimsService.updateBiospecimen(cpModel.getObject()); } catch (ArkSystemException e) { this.error(e.getMessage()); } // refresh transaction form BioTransaction bioTransaction = new BioTransaction(); bioTransaction.setBiospecimen(cpModel.getObject().getBiospecimen()); bioTransaction.setUnit(cpModel.getObject().getBiospecimen().getUnit()); //TODO: Unit cpModel.getObject().setBioTransaction(bioTransaction); target.add(form.getParent().getParent()); target.add(feedbackPanel); } } } // @Override // public boolean isEnabled() { // Biospecimen b = cpModel.getObject().getBiospecimen(); // if(b==null){ // return false; // } // Double qa = iLimsService.getQuantityAvailable(b); // return (qa != null && qa > 0); // } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(feedbackPanel); } }; }
From source file:au.org.theark.lims.web.component.bioupload.BioUploadContainerPanel.java
License:Open Source License
protected WebMarkupContainer initialiseSearchResults() { searchResultPanel = new SearchResultListPanel("searchResults", feedBackPanel, containerForm, arkCrudContainerVO);//from ww w .java 2 s. c o m iModel = new LoadableDetachableModel<Object>() { private static final long serialVersionUID = 1L; @Override protected Object load() { // Return all Uploads for the Study in context java.util.Collection<Upload> studyUploads = new ArrayList<Upload>(); Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); //if (isActionPermitted() && sessionStudyId != null) { TODO we need so make sure permission logic only occurs at the highest possible level if (sessionStudyId != null) { Upload studyUpload = new Upload(); studyUpload.setStudy(iArkCommonService.getStudy(sessionStudyId)); //explicitly search all bio uploads not based on ark function //studyUpload.setArkFunction(arkFunction); studyUploads = iArkCommonService.searchUploadsForBio(studyUpload); } listView.removeAll(); return studyUploads; } }; listView = searchResultPanel.buildPageableListView(iModel); listView.setReuseItems(true); PagingNavigator pageNavigator = new PagingNavigator("navigator", listView); searchResultPanel.add(pageNavigator); searchResultPanel.add(listView); arkCrudContainerVO.getSearchResultPanelContainer().add(searchResultPanel); searchResultPanel.setVisible(true); return arkCrudContainerVO.getSearchResultPanelContainer(); }
From source file:au.org.theark.lims.web.component.bioupload.BioUploadStep1.java
License:Open Source License
private void saveFileInMemory(AjaxRequestTarget target) { Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); FileUpload fileUpload = fileUploadField.getFileUpload(); containerForm.getModelObject().setFileUpload(fileUpload); Payload payload = iArkCommonService.createPayload(fileUpload.getBytes()); containerForm.getModelObject().getUpload().setPayload(payload); String filename = containerForm.getModelObject().getFileUpload().getClientFileName(); String fileFormatName = filename.substring(filename.lastIndexOf('.') + 1).toUpperCase(); au.org.theark.core.model.study.entity.FileFormat fileFormat = new au.org.theark.core.model.study.entity.FileFormat(); fileFormat = iArkCommonService.getFileFormatByName(fileFormatName); byte[] byteArray = fileUpload.getMD5(); String checksum = getHex(byteArray); containerForm.getModelObject().getUpload().setStudy(study); containerForm.getModelObject().getUpload().setFileFormat(fileFormat); containerForm.getModelObject().getUpload().setChecksum(checksum); containerForm.getModelObject().getUpload().setFilename(filename); containerForm.getModelObject().getUpload().setStartTime(new Date(System.currentTimeMillis())); if (containerForm.getModelObject().getUpload().getUploadType() != null) { if (containerForm.getModelObject().getUpload().getUploadType().getName() .equalsIgnoreCase("Biospecimen Custom Data")) { containerForm.getModelObject().getUpload().setArkFunction( iArkCommonService.getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_BIOSPECIMEN)); } else if (containerForm.getModelObject().getUpload().getUploadType().getName() .equalsIgnoreCase("Biocollection Custom Data")) { //containerForm.getModelObject().getUpload().setArkFunction(iArkCommonService.getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_LIMS_COLLECTION)); containerForm.getModelObject().getUpload().setArkFunction( iArkCommonService.getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_LIMS_CUSTOM_FIELD)); } else {/*from w ww.j av a 2 s . c o m*/ log.error("\n\n\n\n\n\n\n\n\n\n\n uploadType unrecognized"); } //containerForm.getModelObject().getUpload().setArkFunction(iArkCommonService.getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_SUBJECT_UPLOAD)); log.info("\n\n\n\n\n\n\n\n\n\n\n\n upload type = " + containerForm.getModelObject().getUpload().getUploadType().getName()); } else { log.error("\n\n\n\n\n\n\n\n\n\n\n uploadType is null"); } wizardForm.setFileName(filename); containerForm.getModelObject().getUpload() .setUploadStatus(iArkCommonService.getUploadStatusFor(Constants.UPLOAD_STATUS_AWAITING_VALIDATION)); try { iArkCommonService.createUpload(containerForm.getModelObject().getUpload()); } catch (Exception e) { error("There was a problem during the upload process."); getWizardForm().onError(target, null); } }
From source file:au.org.theark.lims.web.component.bioupload.BioUploadStep4.java
License:Open Source License
@Override public void onStepOutNext(AbstractWizardForm<?> form, AjaxRequestTarget target) { form.getNextButton().setEnabled(false); target.add(form.getNextButton());/*from www. j a v a2s.c om*/ // Filename seems to be lost from model when moving between steps in wizard? is this a symptom of something greater? containerForm.getModelObject().getUpload().setFilename(wizardForm.getFileName()); String fileFormat = containerForm.getModelObject().getUpload().getFileFormat().getName(); char delimiterChar = containerForm.getModelObject().getUpload().getDelimiterType().getDelimiterCharacter(); try { List<String> uidsToUpload = containerForm.getModelObject().getUidsToUpload(); //log.info("________________________________________________________" + "about to try passing list of uids is of size " + uidsToUpload.size() ); InputStream inputStream = containerForm.getModelObject().getFileUpload().getInputStream(); long size = containerForm.getModelObject().getFileUpload().getSize(); Long uploadId = containerForm.getModelObject().getUpload().getId(); String report = generateInitialUploadReport(); Subject currentUser = SecurityUtils.getSubject(); Long studyId = (Long) currentUser.getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); if (containerForm.getModelObject().getUpload().getUploadType().getName() .equalsIgnoreCase("Subject Demographic Data")) { StudyDataUploadExecutor task = new StudyDataUploadExecutor(iArkCommonService, iLimsService, inputStream, uploadId, //null user studyId, fileFormat, delimiterChar, size, report, uidsToUpload); task.run(); } else if (containerForm.getModelObject().getUpload().getUploadType().getName() .equalsIgnoreCase("Study-specific (custom) Data")) { BioSpecimenCustomDataUploadExecutor task = new BioSpecimenCustomDataUploadExecutor( iArkCommonService, iLimsService, inputStream, uploadId, //null user studyId, fileFormat, delimiterChar, size, report, uidsToUpload); task.run(); } } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
From source file:au.org.theark.lims.web.component.bioupload.form.SearchForm.java
License:Open Source License
@Override protected void onSearch(AjaxRequestTarget target) { target.add(feedbackPanel);/*from w ww . j a va 2s . c o m*/ Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); // Get a list of all Fields for the Study in context Study study = iArkCommonService.getStudy(studyId); Upload searchUpload = getModelObject().getUpload(); searchUpload.setStudy(study); java.util.Collection<Upload> uploadCollection = iArkCommonService.searchUploads(searchUpload); if (uploadCollection != null && uploadCollection.size() == 0) { this.info("Uploads with the specified criteria does not exist in the system."); target.add(feedbackPanel); } getModelObject().setUploadCollection(uploadCollection); listView.removeAll(); arkCrudContainerVO.getSearchResultPanelContainer().setVisible(true);// Make the WebMarkupContainer that houses the search results visible target.add(arkCrudContainerVO.getSearchResultPanelContainer()); }
From source file:au.org.theark.lims.web.component.button.zebra.biocollection.PrintBioCollectionLabelButton.java
License:Open Source License
/** * Construct an ajax button to send the specified barcodeString to a ZebraTLP2844 printer<br> * <b>NOTE:</b> Assumes there is an applet on the page with the name "jZebra" * // w w w.j a v a2 s .c om * @param id the markup identifier * @param bioCollection the bioCollection in context * @param numberModel the number of labels to print */ public PrintBioCollectionLabelButton(String id, final BioCollection bioCollection, IModel<Number> numberModel) { super(id); setOutputMarkupPlaceholderTag(true); this.bioCollection = bioCollection; this.numberModel = numberModel; this.barcodesToPrint = (Number) numberModel.getObject(); try { this.bioCollection = iLimsService.getBioCollection(bioCollection.getId()); String sessionSubjectUID = (String) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.SUBJECTUID); LinkSubjectStudy linkSubjectStudy = null; Study study = bioCollection.getStudy(); linkSubjectStudy = iArkCommonService.getSubjectByUID(sessionSubjectUID, study); this.bioCollection.setLinkSubjectStudy(linkSubjectStudy); } catch (EntityNotFoundException e) { log.error(e.getMessage()); } barcodeLabel = new BarcodeLabel(); barcodeLabel.setStudy(bioCollection.getStudy()); barcodeLabel.setName("zebra biocollection"); barcodeLabel = iLimsAdminService.searchBarcodeLabel(barcodeLabel); }
From source file:au.org.theark.lims.web.component.button.zebra.biocollection.PrintBiospecimensForBioCollectionButton.java
License:Open Source License
/** * Construct an ajax button to send the specified barcodeString for a particular BioCollection to a ZebraTLP2844 printer<br> * <b>NOTE:</b> Assumes there is an applet on the page with the name "jZebra" * //from w ww . jav a 2 s. c o m * @param id * @param bioCollection */ public PrintBiospecimensForBioCollectionButton(String id, final BioCollection bioCollection, String printerName, IModel<Number> numberModel) { super(id); this.printerName = printerName; this.numberModel = numberModel; if (numberModel != null) { this.barcodesToPrint = (Number) numberModel.getObject(); } else { this.barcodesToPrint = 1; } setOutputMarkupPlaceholderTag(true); this.bioCollection = bioCollection; try { this.bioCollection = iLimsService.getBioCollection(bioCollection.getId()); String sessionSubjectUID = (String) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.SUBJECTUID); LinkSubjectStudy linkSubjectStudy = null; Study study = bioCollection.getStudy(); linkSubjectStudy = iArkCommonService.getSubjectByUID(sessionSubjectUID, study); this.bioCollection.setLinkSubjectStudy(linkSubjectStudy); } catch (EntityNotFoundException e) { log.error(e.getMessage()); } barcodeLabel = new BarcodeLabel(); barcodeLabel.setStudy(bioCollection.getStudy()); barcodeLabel.setName(printerName); barcodeLabel = iLimsAdminService.searchBarcodeLabel(barcodeLabel); }