public static void update() { try { final String msg = "DatabaseSchemaUpdater: Begin"; log(msg); final String applicationName = CommonServiceLocator.getInstance().getAppName(); DAO dao = DAOConfigFactory.getInstance().getDAOFactory(applicationName).getDAO(); Method getConnectionManagerMethod = ReflectionUtils.findMethod(dao.getClass(), "getConnectionManager"); ReflectionUtils.makeAccessible(getConnectionManagerMethod); IConnectionManager connectionManager = (IConnectionManager) ReflectionUtils.invokeMethod(getConnectionManagerMethod, dao); Connection c = null; try { c = connectionManager.getConnection(); update(c); } finally { try { connectionManager.commit(); } catch (Exception e) { } connectionManager.closeConnection(); } } catch (Exception e) { final String msg = "DatabaseSchemaUpdater: Failed with " + e.getMessage(); log(msg); } }
/** * This method would return the Clinical Diagnosis List * * @return List which contains the Clinical Diagnosis Data * @throws BizLogicException * @throws BizLogicException */ public List getClinicalDiagnosisList(String query, boolean showSubset) throws BizLogicException { // populating clinical Diagnosis field final List<NameValueBean> clinicalDiagnosisList = new ArrayList(); final String sourceObjectName = PermissibleValueImpl.class.getName(); final String[] selectColumnName = {"value"}; DAO dao = null; try { new DefaultBizLogic(); dao = this.openDAOSession(null); String hql = "Select PermissibleValueImpl.value from edu.wustl.common.cde.PermissibleValueImpl " + "PermissibleValueImpl WHERE LOWER(PermissibleValueImpl.value) like LOWER('%" + query + "%') AND PermissibleValueImpl.cde.publicId = 'Clinical_Diagnosis_PID' " + "order by PermissibleValueImpl.value desc"; List dataList = dao.executeQuery(hql); clinicalDiagnosisList.add( new NameValueBean(Constants.SELECT_OPTION, "" + Constants.SELECT_OPTION_VALUE)); if (showSubset) { clinicalDiagnosisList.add( new NameValueBean(Constants.SHOW_SUBSET + "start", Constants.SHOW_SUBSET)); } int cnt = 1; final Iterator<String> iterator = dataList.iterator(); while (iterator.hasNext()) { final String clinicaDiagnosisvalue = iterator.next(); if (clinicaDiagnosisvalue.toString().toLowerCase().startsWith(query.toLowerCase())) { clinicalDiagnosisList.add( 1, new NameValueBean(clinicaDiagnosisvalue, clinicaDiagnosisvalue)); cnt++; } else { clinicalDiagnosisList.add( cnt, new NameValueBean(clinicaDiagnosisvalue, clinicaDiagnosisvalue)); } } if (showSubset) { clinicalDiagnosisList.add( new NameValueBean(Constants.SHOW_SUBSET + "end", Constants.SHOW_SUBSET)); } this.closeDAOSession(dao); } catch (final DAOException exp) { this.logger.error(exp.getMessage(), exp); exp.printStackTrace(); throw this.getBizLogicException(exp, exp.getErrorKeyName(), exp.getMsgValues()); } finally { this.closeDAOSession(dao); } return clinicalDiagnosisList; }
/** * Called from DefaultBizLogic to get ObjectId for authorization check (non-Javadoc) * * @param dao : dao * @param domainObject : domainObject * @return String * @see edu.wustl.common.bizlogic.DefaultBizLogic#getObjectId(edu.wustl.common.dao.DAO, * java.lang.Object) */ @Override public String getObjectId(DAO dao, Object domainObject) { final StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(Site.class.getName()); try { if (domainObject instanceof StorageContainer) { final StorageContainer storageContainer = (StorageContainer) domainObject; final Map similarContainerMap = storageContainer.getSimilarContainerMap(); final Object keys[] = similarContainerMap.keySet().toArray(); final Set<Long> scIds = new HashSet<Long>(); final Set<Long> siteIds = new HashSet<Long>(); for (final Object key : keys) { if (key.toString().contains("parentContainerId")) { scIds.add(Long.valueOf(similarContainerMap.get(key).toString())); } if (key.toString().contains("siteId")) { siteIds.add(Long.valueOf(similarContainerMap.get(key).toString())); } } for (final Long scId : scIds) { Site site = null; Object object = null; object = dao.retrieveById(StorageContainer.class.getName(), scId); if (object != null) { final StorageContainer parentContainer = (StorageContainer) object; site = parentContainer.getSite(); } if (site != null) { if (!siteIds.contains(site.getId())) { stringBuffer.append("_" + site.getId().toString()); } siteIds.add(site.getId()); } } for (final Long siteId : siteIds) { stringBuffer.append("_" + siteId.toString()); } } } catch (final DAOException daoExp) { this.logger.error(daoExp.getMessage(), daoExp); daoExp.printStackTrace(); } return stringBuffer.toString(); }
/** * Overrides the executeSecureAction method of SecureAction class. * * @param mapping object of ActionMapping * @param form : actionForm * @param request object of HttpServletRequest * @param response object of HttpServletResponse * @throws Exception generic exception * @return ActionForward : ActionForward */ @Override public ActionForward executeSecureAction( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { DAO dao = null; String pageOf = null; try { final SessionDataBean sessionDataBean = (SessionDataBean) request.getSession().getAttribute(Constants.SESSION_DATA); dao = AppUtility.openDAOSession(sessionDataBean); final SpecimenArrayAliquotForm specimenArrayAliquotForm = (SpecimenArrayAliquotForm) form; pageOf = request.getParameter(Constants.PAGE_OF); final StorageContainerForSpArrayBizLogic bizLogic = new StorageContainerForSpArrayBizLogic(); final SessionDataBean sessionData = (SessionDataBean) request.getSession().getAttribute(Constants.SESSION_DATA); final List<NameValueBean> storagePositionListForSpecimenArrayAliquot = AppUtility.getStoragePositionTypeListForTransferEvent(); request.setAttribute( "storagePositionListForSpecimenArrayAliquot", storagePositionListForSpecimenArrayAliquot); final String exceedingMaxLimit = "false"; if (specimenArrayAliquotForm.getButtonClicked().equalsIgnoreCase("submit")) { final Map tempAliquotMap = new HashMap(); if (specimenArrayAliquotForm.getCheckedButton().equals("1")) { tempAliquotMap.put("label", specimenArrayAliquotForm.getParentSpecimenArrayLabel()); } else { tempAliquotMap.put("barcode", specimenArrayAliquotForm.getBarcode()); } tempAliquotMap.put("aliquotcount", specimenArrayAliquotForm.getAliquotCount()); request.getSession().setAttribute("tempAliquotMap", tempAliquotMap); } else if (specimenArrayAliquotForm.getButtonClicked().equalsIgnoreCase("create")) { boolean arePropertiesChanged = false; final Map tempAliquotMap = (HashMap) request.getSession().getAttribute("tempAliquotMap"); final String label = (String) tempAliquotMap.get("label"); final String barcode = (String) tempAliquotMap.get("barcode"); if (specimenArrayAliquotForm.getCheckedButton().equals("1")) { if (label == null || !label .trim() .equalsIgnoreCase( specimenArrayAliquotForm.getParentSpecimenArrayLabel().trim())) { arePropertiesChanged = true; } } else { if (barcode == null || !barcode.trim().equalsIgnoreCase(specimenArrayAliquotForm.getBarcode().trim())) { arePropertiesChanged = true; } } final String aliquotcount = (String) tempAliquotMap.get("aliquotcount"); if (!aliquotcount .trim() .equalsIgnoreCase(specimenArrayAliquotForm.getAliquotCount().trim())) { arePropertiesChanged = true; } /** * Repopulate the form with storage container locations in case user has changed any of * label/barcode, aliquot count, quantity per aliquot. */ if (arePropertiesChanged == true) { specimenArrayAliquotForm.setParentSpecimenArrayLabel(label); specimenArrayAliquotForm.setAliquotCount(aliquotcount); specimenArrayAliquotForm.setBarcode(barcode); ActionErrors errors = this.getActionErrors(request); if (errors == null) { errors = new ActionErrors(); } if (arePropertiesChanged == true) { errors.add( ActionErrors.GLOBAL_ERROR, new ActionError("errors.specimenArrayAliquots.reSubmit")); } TreeMap containerMap = new TreeMap(); this.checkForSpecimenArray(request, specimenArrayAliquotForm, dao); // int aliquotCount = // Integer.parseInt(specimenArrayAliquotForm.getAliquotCount()); final Long id = (Long) request.getAttribute(Constants.STORAGE_TYPE_ID); containerMap = bizLogic.getAllocatedContainerMapForSpecimenArray(id.longValue(), sessionData, dao); this.populateAliquotsStorageLocations(specimenArrayAliquotForm, containerMap); request.setAttribute(Constants.AVAILABLE_CONTAINER_MAP, containerMap); request.setAttribute(Constants.PAGE_OF, Constants.PAGE_OF_SPECIMEN_ARRAY_CREATE_ALIQUOT); this.saveErrors(request, errors); return mapping.findForward(Constants.PAGE_OF_SPECIMEN_ARRAY_CREATE_ALIQUOT); } else { // TODO specimenArrayAliquotForm.setButtonClicked("none"); return mapping.findForward(Constants.COMMON_ADD_EDIT); } } if (Constants.PAGE_OF_SPECIMEN_ARRAY_ALIQUOT_SUMMARY.equals(pageOf)) { final Map map = (Map) request.getAttribute("forwardToHashMap"); if (map != null) { // TODO specimenArrayAliquotForm.setSpecimenClass( CommonUtilities.toString(map.get(Constants.ALIQUOT_SPECIMEN_CLASS))); specimenArrayAliquotForm.setSpecimenArrayType( CommonUtilities.toString(map.get(Constants.ALIQUOT_SPECIMEN_ARRAY_TYPE))); specimenArrayAliquotForm.setAliquotCount( CommonUtilities.toString(map.get(Constants.ALIQUOT_ALIQUOT_COUNTS))); final Collection specimenTypesCollection = (Collection) map.get(Constants.ALIQUOT_SPECIMEN_TYPES); final List specimenTypeList = this.setSpecimenTypes(specimenTypesCollection, specimenArrayAliquotForm); request.setAttribute(Constants.SPECIMEN_TYPE_LIST, specimenTypeList); String containerNameKey = ""; String posDim1Key = ""; String posDim2Key = ""; /** This code is added to set storage positions in case of manual mode. bug 15085 */ for (int iCount = 1; iCount <= Integer.parseInt(specimenArrayAliquotForm.getAliquotCount()); iCount++) { if (map.get("radio_" + iCount) != null && map.get("radio_" + iCount).equals("2")) { containerNameKey = "SpecimenArray:" + iCount + "_StorageContainer_name"; posDim1Key = "SpecimenArray:" + iCount + "_positionDimensionOne"; posDim2Key = "SpecimenArray:" + iCount + "_positionDimensionTwo"; map.put(containerNameKey, map.get(containerNameKey + "_fromMap")); if (!map.get(posDim1Key + "_fromMap").equals("")) { map.put(posDim1Key, map.get(posDim1Key + "_fromMap")); } if (!map.get(posDim2Key + "_fromMap").equals("")) { map.put(posDim2Key, map.get(posDim2Key + "_fromMap")); } } } specimenArrayAliquotForm.setSpecimenArrayAliquotMap(map); } final ActionErrors errors = this.getActionErrors(request); if (errors == null || errors.size() == 0) { final ActionMessages messages = new ActionMessages(); messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("aliquots.success")); this.saveMessages(request, messages); } return mapping.findForward(pageOf); } Map containerMap = new HashMap(); if (Constants.PAGE_OF_SPECIMEN_ARRAY_CREATE_ALIQUOT.equals( request.getParameter(Constants.PAGE_OF))) { pageOf = this.validate(request, specimenArrayAliquotForm); if (Constants.PAGE_OF_SPECIMEN_ARRAY_CREATE_ALIQUOT.equals(pageOf)) { pageOf = this.checkForSpecimenArray(request, specimenArrayAliquotForm, dao); if (Constants.PAGE_OF_SPECIMEN_ARRAY_CREATE_ALIQUOT.equals(pageOf)) { final int aliquotCount = Integer.parseInt(specimenArrayAliquotForm.getAliquotCount()); final Long id = (Long) request.getAttribute(Constants.STORAGE_TYPE_ID); containerMap = bizLogic.getAllocatedContainerMapForSpecimenArray(id.longValue(), sessionData, dao); pageOf = this.checkForSufficientAvailablePositions(request, containerMap, aliquotCount); if (Constants.PAGE_OF_SPECIMEN_ARRAY_CREATE_ALIQUOT.equals(pageOf)) { final ActionErrors errors = (ActionErrors) request.getAttribute(Globals.ERROR_KEY); if (errors == null || errors.size() == 0) { this.populateAliquotsStorageLocations(specimenArrayAliquotForm, containerMap); } } } } } request.setAttribute(Constants.EXCEEDS_MAX_LIMIT, exceedingMaxLimit); request.setAttribute(Constants.AVAILABLE_CONTAINER_MAP, containerMap); request.setAttribute(Constants.PAGE_OF, pageOf); } finally { dao.closeSession(); } return mapping.findForward(pageOf); }
/** * @param request HttpServletRequest * @param form SpecimenArrayAliquotForm * @return String : String * @throws BizLogicException : BizLogicException * @throws Exception : Exception */ private String checkForSpecimenArray( HttpServletRequest request, SpecimenArrayAliquotForm form, DAO dao) throws BizLogicException, Exception { List specimenArrayList = new ArrayList(); String errorString = ""; final String specimenArrayLabel = form.getParentSpecimenArrayLabel(); final int aliquotCount = Integer.parseInt(form.getAliquotCount()); if (form.getCheckedButton().equals("1")) { specimenArrayList = dao.retrieve(SpecimenArray.class.getName(), Constants.SYSTEM_NAME, specimenArrayLabel); errorString = Constants.SYSTEM_LABEL; } else { final String barcode = form.getBarcode().trim(); specimenArrayList = dao.retrieve(SpecimenArray.class.getName(), Constants.SYSTEM_BARCODE, barcode); errorString = Constants.SYSTEM_BARCODE; } if (specimenArrayList.isEmpty()) { final ActionErrors errors = this.getActionErrors(request); errors.add( ActionErrors.GLOBAL_ERROR, new ActionError("errors.specimenArrayAliquots.notExists", errorString)); this.saveErrors(request, errors); return Constants.PAGE_OF_SPECIMEN_ARRAY_ALIQUOT; } else { final SpecimenArray specimenArray = (SpecimenArray) specimenArrayList.get(0); /** * Name : Virender Reviewer: Prafull Retriving specimenArrayTypeObject replaced * SpecimenArrayType arrayType = specimenArray.getSpecimenArrayType(); */ if (Status.ACTIVITY_STATUS_DISABLED.toString().equals(specimenArray.getActivityStatus())) { final ActionErrors errors = this.getActionErrors(request); errors.add( ActionErrors.GLOBAL_ERROR, new ActionError("errors.specimenArrayAliquots.disabled", "Parent Specimen Array")); this.saveErrors(request, errors); return Constants.PAGE_OF_SPECIMEN_ARRAY_ALIQUOT; // throw BizLogicException( // "Fail to create Aliquots, Parent SpecimenArray" + " " + // ApplicationProperties.getValue("error.object.disabled")); } final List arrayTypeList = dao.retrieveAttribute( SpecimenArray.class, "id", specimenArray.getId(), "specimenArrayType"); if ((arrayTypeList != null) && (arrayTypeList.size() > 0)) { final SpecimenArrayType arrayType = (SpecimenArrayType) arrayTypeList.get(0); form.setSpecimenArrayType(arrayType.getName()); form.setSpecimenClass(arrayType.getSpecimenClass()); /** * Name: Virender Mehta Reviewer: Prafull Retrive Child Specimen Collection from parent * Specimen String[] specimenTypeArr = new * String[arrayType.getSpecimenTypeCollection().size()]; */ final Collection specimenTypeCollection = dao.retrieveAttribute( SpecimenArrayType.class, "id", arrayType.getId(), "elements(specimenTypeCollection)"); // String[] specimenTypeArr = new // String[specimenTypeCollection.size()]; final List specimenTypeList = this.setSpecimenTypes(specimenTypeCollection, form); request.setAttribute(Constants.SPECIMEN_TYPE_LIST, specimenTypeList); request.setAttribute(Constants.STORAGE_TYPE_ID, arrayType.getId()); final Map aliquotMap = form.getSpecimenArrayAliquotMap(); final SpecimenArrayAliquotsBizLogic aliquotBizLogic = (SpecimenArrayAliquotsBizLogic) AbstractFactoryConfig.getInstance() .getBizLogicFactory() .getBizLogic(Constants.SPECIMEN_ARRAY_ALIQUOT_FORM_ID); final long nextAvailablenumber = aliquotBizLogic.getNextAvailableNumber("CATISSUE_SPECIMEN_ARRAY"); /** Putting the default label values in the AliquotMap */ for (int i = 1; i <= aliquotCount; i++) { final String labelKey = "SpecimenArray:" + i + "_label"; final String aliquotLabel = specimenArrayLabel + "_" + (nextAvailablenumber + i - 1); aliquotMap.put(labelKey, aliquotLabel); } form.setSpecimenArrayAliquotMap(aliquotMap); form.setSpecimenArrayId("" + specimenArray.getId()); } } return Constants.PAGE_OF_SPECIMEN_ARRAY_CREATE_ALIQUOT; }
/** * Saves the storageContainer object in the database. * * @param dao : dao * @param obj The storageType object to be saved. * @param sessionDataBean The session in which the object is saved. * @throws BizLogicException : BizLogicException */ @Override protected void insert(Object obj, DAO dao, SessionDataBean sessionDataBean) throws BizLogicException { final StorageContainer container = (StorageContainer) obj; container.setActivityStatus(Status.ACTIVITY_STATUS_ACTIVE.toString()); final List contList = new ArrayList(); final int noOfContainers = container.getNoOfContainers().intValue(); final Map simMap = container.getSimilarContainerMap(); // --- common values for all similar containers --- new StorageTypeBizLogic().loadStorageType(dao, container); this.logger.debug(simMap); final int checkButton = Integer.parseInt((String) simMap.get("checkedButton")); // int checkButton = 1; try { for (int i = 1; i <= noOfContainers; i++) { final String simContPrefix = "simCont:" + i + "_"; final String IdKey = simContPrefix + "Id"; final String parentContNameKey = simContPrefix + "parentContName"; final String contName = (String) simMap.get(simContPrefix + "name"); String barcode = (String) simMap.get(simContPrefix + "barcode"); if (barcode != null && barcode.equals("")) // this is done // because barcode // is empty string // set by struts { // but barcode in DB is unique but can be null. barcode = null; } final StorageContainer cont = new StorageContainer(container); if (checkButton == 1) // site { final String siteId = (String) simMap.get(simContPrefix + "siteId"); final String siteName = (String) simMap.get(simContPrefix + "siteName"); final Site site = new Site(); /** * Start: Change for API Search --- Jitendra 06/10/2006 In Case of Api Search, previoulsy * it was failing since there was default class level initialization on domain object. For * example in User object, it was initialized as protected String lastName=""; So we * removed default class level initialization on domain object and are initializing in * method setAllValues() of domain object. But in case of Api Search, default values will * not get set since setAllValues() method of domainObject will not get called. To avoid * null pointer exception, we are setting the default values same as we were setting in * setAllValues() method of domainObject. */ ApiSearchUtil.setSiteDefault(site); site.setId(new Long(siteId)); site.setName(siteName); cont.setSite(site); new SiteBizLogic().loadSite(dao, cont); } else // parentContainer { StorageContainer parentContainer = null; final String parentId = (String) simMap.get(simContPrefix + "parentContainerId"); final String posOne = (String) simMap.get(simContPrefix + "positionDimensionOne"); final String posTwo = (String) simMap.get(simContPrefix + "positionDimensionTwo"); final Object object = dao.retrieveById(StorageContainer.class.getName(), new Long(parentId)); if (object != null) { parentContainer = (StorageContainer) object; cont.setSite(parentContainer.getSite()); } final IFactory factory = AbstractFactoryConfig.getInstance().getBizLogicFactory(); final StorageContainerBizLogic storageContainerBizLogic = (StorageContainerBizLogic) factory.getBizLogic(Constants.STORAGE_CONTAINER_FORM_ID); storageContainerBizLogic.checkContainer( dao, StorageContainerUtil.setparameterList( parentContainer.getId().toString(), posOne, posTwo, false), sessionDataBean, null); ContainerPosition cntPos = cont.getLocatedAtPosition(); if (cntPos == null) { cntPos = new ContainerPosition(); } cntPos.setPositionDimensionOne(new Integer(posOne)); cntPos.setPositionDimensionTwo(new Integer(posTwo)); cntPos.setOccupiedContainer(cont); cntPos.setParentContainer(parentContainer); cont.setLocatedAtPosition(cntPos); // Have to set Site object for parentContainer SiteBizLogic siteBiz = new SiteBizLogic(); siteBiz.loadSite(dao, parentContainer); siteBiz.loadSiteFromContainerId(dao, parentContainer); cntPos.setPositionDimensionOne(new Integer(posOne)); cntPos.setPositionDimensionTwo(new Integer(posTwo)); cntPos.setOccupiedContainer(cont); cont.setLocatedAtPosition(cntPos); cont.setSite(parentContainer.getSite()); this.logger.debug("^^>> " + parentContainer.getSite()); simMap.put(parentContNameKey, parentContainer.getName()); } // StorageContainer cont = new StorageContainer(); cont.setName(contName); // <<---- cont.setBarcode(barcode); // <<---- // by falguni // Storage container label generator // Call Storage container label generator if its specified to // use automatic label generator if (edu.wustl.catissuecore.util.global.Variables.isStorageContainerLabelGeneratorAvl) { LabelGenerator storagecontLblGenerator; storagecontLblGenerator = LabelGeneratorFactory.getInstance( Constants.STORAGECONTAINER_LABEL_GENERATOR_PROPERTY_NAME); try { storagecontLblGenerator.setLabel(cont); } catch (LabelGenException e) { this.logger.error(e.getMessage(), e); } } simMap.put(simContPrefix + "name", cont.getName()); this.logger.debug( "cont.getCollectionProtocol().size() " + cont.getCollectionProtocolCollection().size()); cont.setActivityStatus("Active"); dao.insert(cont.getCapacity()); dao.insert(cont); contList.add(cont); container.setId(cont.getId()); simMap.put(IdKey, cont.getId().toString()); } } catch (final DAOException daoExp) { this.logger.error(daoExp.getMessage(), daoExp); daoExp.printStackTrace(); throw this.getBizLogicException(daoExp, daoExp.getErrorKeyName(), daoExp.getMsgValues()); } catch (final NameGeneratorException e) { this.logger.error(e.getMessage(), e); e.printStackTrace(); throw this.getBizLogicException(e, "utility.error", ""); } }