List of usage examples for java.lang NullPointerException getMessage
public String getMessage()
From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.OntologyRetryController.java
public void doPost(HttpServletRequest req, HttpServletResponse response) { if (!isAuthorizedToDisplayPage(req, response, SimplePermission.EDIT_ONTOLOGY.ACTION)) { return;//from ww w . j a v a 2 s . co m } VitroRequest request = new VitroRequest(req); //create an EditProcessObject for this and put it in the session EditProcessObject epo = super.createEpo(request); /*for testing*/ Ontology testMask = new Ontology(); epo.setBeanClass(Ontology.class); epo.setBeanMask(testMask); String action = null; if (epo.getAction() == null) { action = "insert"; epo.setAction("insert"); } else { action = epo.getAction(); } OntologyDao oDao = request.getUnfilteredWebappDaoFactory().getOntologyDao(); epo.setDataAccessObject(oDao); Ontology ontologyForEditing = null; if (!epo.getUseRecycledBean()) { if (request.getParameter("uri") != null) { try { ontologyForEditing = oDao.getOntologyByURI(request.getParameter("uri")); action = "update"; } catch (NullPointerException e) { log.error("No ontology record found for the namespace " + request.getParameter("uri")); } } else { ontologyForEditing = new Ontology(); } epo.setOriginalBean(ontologyForEditing); } else { ontologyForEditing = (Ontology) epo.getNewBean(); } //validators List<Validator> validatorList = new ArrayList<Validator>(); validatorList.add(new RequiredFieldValidator()); validatorList.add(new UrlValidator()); epo.getValidatorMap().put("URI", validatorList); //make a simple mask for the class's id Object[] simpleMaskPair = new Object[2]; simpleMaskPair[0] = "Id"; simpleMaskPair[1] = Integer.valueOf(ontologyForEditing.getId()); epo.getSimpleMask().add(simpleMaskPair); //set up any listeners //make a postinsert pageforwarder that will send us to a new ontology's edit screen epo.setPostInsertPageForwarder(new OntologyInsertPageForwarder()); //make a postdelete pageforwarder that will send us to the list of ontologies epo.setPostDeletePageForwarder(new UrlForwarder("listOntologies")); //set the getMethod so we can retrieve a new bean after we've inserted it try { Class[] args = new Class[1]; args[0] = String.class; epo.setGetMethod(oDao.getClass().getDeclaredMethod("getOntologyByURI", args)); } catch (NoSuchMethodException e) { log.error("OntologyRetryController could not find the getOntologyByURI method in the DAO"); } FormObject foo = new FormObject(); foo.setErrorMap(epo.getErrMsgMap()); epo.setFormObject(foo); FormUtils.populateFormFromBean(ontologyForEditing, action, foo, epo.getBadValueMap()); RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP); request.setAttribute("bodyJsp", "/templates/edit/formBasic.jsp"); request.setAttribute("formJsp", "/templates/edit/specific/ontology_retry.jsp"); request.setAttribute("scripts", "/templates/edit/formBasic.js"); request.setAttribute("title", "Ontology Editing Form"); request.setAttribute("_action", action); request.setAttribute("unqualifiedClassName", "Ontology"); setRequestAttributes(request, epo); try { rd.forward(request, response); } catch (Exception e) { log.error("OntologyRetryContro" + "ller could not forward to view."); log.error(e.getMessage()); log.error(e.getStackTrace()); } }
From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.PropertyGroupRetryController.java
public void doPost(HttpServletRequest req, HttpServletResponse response) { if (!isAuthorizedToDisplayPage(req, response, SimplePermission.USE_MISCELLANEOUS_ADMIN_PAGES.ACTION)) { return;//ww w. j a va2s .c o m } VitroRequest request = new VitroRequest(req); //create an EditProcessObject for this and put it in the session EditProcessObject epo = super.createEpo(request); String action = null; if (epo.getAction() == null) { action = "insert"; epo.setAction("insert"); } else { action = epo.getAction(); } PropertyGroupDao pgDao = ModelAccess.on(getServletContext()).getWebappDaoFactory().getPropertyGroupDao(); epo.setDataAccessObject(pgDao); PropertyGroup propertyGroupForEditing = null; if (!epo.getUseRecycledBean()) { if (request.getParameter("uri") != null) { try { propertyGroupForEditing = (PropertyGroup) pgDao.getGroupByURI(request.getParameter("uri")); action = "update"; epo.setAction("update"); } catch (NullPointerException e) { log.error("Need to implement 'record not found' error message."); } if (propertyGroupForEditing == null) { // UTF-8 expected due to URIEncoding on Connector element in server.xml String uriToFind = new String(request.getParameter("uri")); propertyGroupForEditing = (PropertyGroup) pgDao.getGroupByURI(uriToFind); } } else { propertyGroupForEditing = new PropertyGroup(); } epo.setOriginalBean(propertyGroupForEditing); } else { propertyGroupForEditing = (PropertyGroup) epo.getNewBean(); } //validators List<Validator> validatorList = new ArrayList<Validator>(); validatorList.add(new RequiredFieldValidator()); epo.getValidatorMap().put("Name", validatorList); //make a postinsert pageforwarder that will send us to a new class's fetch screen epo.setPostInsertPageForwarder(new PropertyGroupInsertPageForwarder()); //make a postdelete pageforwarder that will send us to the list of classes epo.setPostDeletePageForwarder(new UrlForwarder("listPropertyGroups")); //set the getMethod so we can retrieve a new bean after we've inserted it try { Class[] args = new Class[1]; args[0] = String.class; epo.setGetMethod(pgDao.getClass().getDeclaredMethod("getGroupByURI", args)); } catch (NoSuchMethodException e) { log.error(this.getClass().getName() + " could not find the getGroupByURI method"); } FormObject foo = new FormObject(); foo.setErrorMap(epo.getErrMsgMap()); epo.setFormObject(foo); FormUtils.populateFormFromBean(propertyGroupForEditing, action, foo, epo.getBadValueMap()); RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP); request.setAttribute("bodyJsp", "/templates/edit/formBasic.jsp"); request.setAttribute("formJsp", "/templates/edit/specific/propertyGroup_retry.jsp"); request.setAttribute("scripts", "/templates/edit/formBasic.js"); request.setAttribute("title", "Property Group Editing Form"); request.setAttribute("_action", action); request.setAttribute("unqualifiedClassName", "PropertyGroup"); setRequestAttributes(request, epo); try { rd.forward(request, response); } catch (Exception e) { log.error("PropertyGroupRetryController could not forward to view."); log.error(e.getMessage()); log.error(e.getStackTrace()); } }
From source file:se.vgregion.service.innovationsslussen.idea.IdeaServiceImpl.java
protected int getCommentsCount(IdeaContent ideaContent) { int commentsCount = 0; try {// w ww . j av a 2 s .c o m MBMessageDisplay messageDisplay = null; try { messageDisplay = mbMessageLocalService.getDiscussionMessageDisplay(ideaContent.getUserId(), ideaContent.getGroupId(), IdeaContent.class.getName(), ideaContent.getId(), WorkflowConstants.STATUS_ANY); } catch (NullPointerException e) { return commentsCount; } MBThread thread = messageDisplay.getThread(); long threadId = thread.getThreadId(); long rootMessageId = thread.getRootMessageId(); messageComparator = new MessageCreateDateComparator(false); @SuppressWarnings("unchecked") List<MBMessage> mbMessages = mbMessageLocalService.getThreadMessages(threadId, WorkflowConstants.STATUS_ANY, messageComparator); for (MBMessage mbMessage : mbMessages) { long commentId = mbMessage.getMessageId(); if (commentId != rootMessageId) { commentsCount++; } } } catch (PortalException e) { LOGGER.error(e.getMessage(), e); } catch (SystemException e) { LOGGER.error(e.getMessage(), e); } return commentsCount; }
From source file:javadz.beanutils.PropertyUtilsBean.java
/** This just catches and wraps IllegalArgumentException. */ private Object invokeMethod(Method method, Object bean, Object[] values) throws IllegalAccessException, InvocationTargetException { if (bean == null) { throw new IllegalArgumentException( "No bean specified " + "- this should have been checked before reaching this method"); }//w ww . j a v a 2s .co m try { return method.invoke(bean, values); } catch (NullPointerException cause) { // JDK 1.3 and JDK 1.4 throw NullPointerException if an argument is // null for a primitive value (JDK 1.5+ throw IllegalArgumentException) String valueString = ""; if (values != null) { for (int i = 0; i < values.length; i++) { if (i > 0) { valueString += ", "; } if (values[i] == null) { valueString += "<null>"; } else { valueString += (values[i]).getClass().getName(); } } } String expectedString = ""; Class[] parTypes = method.getParameterTypes(); if (parTypes != null) { for (int i = 0; i < parTypes.length; i++) { if (i > 0) { expectedString += ", "; } expectedString += parTypes[i].getName(); } } IllegalArgumentException e = new IllegalArgumentException( "Cannot invoke " + method.getDeclaringClass().getName() + "." + method.getName() + " on bean class '" + bean.getClass() + "' - " + cause.getMessage() // as per https://issues.apache.org/jira/browse/BEANUTILS-224 + " - had objects of type \"" + valueString + "\" but expected signature \"" + expectedString + "\""); if (!BeanUtils.initCause(e, cause)) { log.error("Method invocation failed", cause); } throw e; } catch (IllegalArgumentException cause) { String valueString = ""; if (values != null) { for (int i = 0; i < values.length; i++) { if (i > 0) { valueString += ", "; } if (values[i] == null) { valueString += "<null>"; } else { valueString += (values[i]).getClass().getName(); } } } String expectedString = ""; Class[] parTypes = method.getParameterTypes(); if (parTypes != null) { for (int i = 0; i < parTypes.length; i++) { if (i > 0) { expectedString += ", "; } expectedString += parTypes[i].getName(); } } IllegalArgumentException e = new IllegalArgumentException( "Cannot invoke " + method.getDeclaringClass().getName() + "." + method.getName() + " on bean class '" + bean.getClass() + "' - " + cause.getMessage() // as per https://issues.apache.org/jira/browse/BEANUTILS-224 + " - had objects of type \"" + valueString + "\" but expected signature \"" + expectedString + "\""); if (!BeanUtils.initCause(e, cause)) { log.error("Method invocation failed", cause); } throw e; } }
From source file:org.evergreen.web.utils.beanutils.PropertyUtilsBean.java
/** This just catches and wraps IllegalArgumentException. */ protected Object invokeMethod(Method method, Object bean, Object[] values) throws IllegalAccessException, InvocationTargetException { if (bean == null) { throw new IllegalArgumentException( "No bean specified " + "- this should have been checked before reaching this method"); }/*from w w w. ja v a 2s .c om*/ try { return method.invoke(bean, values); } catch (NullPointerException cause) { // JDK 1.3 and JDK 1.4 throw NullPointerException if an argument is // null for a primitive value (JDK 1.5+ throw IllegalArgumentException) String valueString = ""; if (values != null) { for (int i = 0; i < values.length; i++) { if (i > 0) { valueString += ", "; } if (values[i] == null) { valueString += "<null>"; } else { valueString += (values[i]).getClass().getName(); } } } String expectedString = ""; Class[] parTypes = method.getParameterTypes(); if (parTypes != null) { for (int i = 0; i < parTypes.length; i++) { if (i > 0) { expectedString += ", "; } expectedString += parTypes[i].getName(); } } IllegalArgumentException e = new IllegalArgumentException( "Cannot invoke " + method.getDeclaringClass().getName() + "." + method.getName() + " on bean class '" + bean.getClass() + "' - " + cause.getMessage() // as per https://issues.apache.org/jira/browse/BEANUTILS-224 + " - had objects of type \"" + valueString + "\" but expected signature \"" + expectedString + "\""); if (!BeanUtils.initCause(e, cause)) { log.error("Method invocation failed", cause); } throw e; } catch (IllegalArgumentException cause) { String valueString = ""; if (values != null) { for (int i = 0; i < values.length; i++) { if (i > 0) { valueString += ", "; } if (values[i] == null) { valueString += "<null>"; } else { valueString += (values[i]).getClass().getName(); } } } String expectedString = ""; Class[] parTypes = method.getParameterTypes(); if (parTypes != null) { for (int i = 0; i < parTypes.length; i++) { if (i > 0) { expectedString += ", "; } expectedString += parTypes[i].getName(); } } IllegalArgumentException e = new IllegalArgumentException( "Cannot invoke " + method.getDeclaringClass().getName() + "." + method.getName() + " on bean class '" + bean.getClass() + "' - " + cause.getMessage() // as per https://issues.apache.org/jira/browse/BEANUTILS-224 + " - had objects of type \"" + valueString + "\" but expected signature \"" + expectedString + "\""); if (!BeanUtils.initCause(e, cause)) { log.error("Method invocation failed", cause); } //??,null,? //throw e; } return null; }
From source file:com.google.gsa.valve.modules.krb.KerberosAuthenticationProcess.java
/** * This is the main method that does the Kerberos authentication and * should be invoked by the classes that would like to open a new * authentication process against a Kerberized protected source. * <p>//from w w w . j ava2 s. co m * It behaves differently if the it's set up as a Negotiation process or * the Kerberos credentials are got from the username and password * credentials. It reads "isNegotiate" var and invokes the proper method * that manages Kerberos authentication specifically for each method. * <p> * If the Kerberos authentication result is OK, a cookie is created with an * encoded information that includes the username to be reused if this is * needed in any other Authn/AuthZ module. It also populates the credentials * vector with the user's Kerberos credential ("krb5") that the caller * process should reuse when authorizing. * * @param request HTTP request * @param response HTTP response * @param authCookies vector that contains the authentication cookies * @param url the document url * @param creds an array of credentials for all external sources * @param id the default credential id to be retrieved from creds * @return the HTTP error code * @throws HttpException * @throws IOException */ public int authenticate(HttpServletRequest request, HttpServletResponse response, Vector<Cookie> authCookies, String url, Credentials creds, String id) throws HttpException, IOException { //Vars int responseCode = HttpServletResponse.SC_UNAUTHORIZED; Cookie[] cookies = null; // Read cookies cookies = request.getCookies(); //Protection logger.debug("Checking if user already has Krb credentials. If so, return OK"); try { if (creds != null) { if (creds.getCredential(KRB5_ID) != null) { logger.debug("Credential found: " + KRB5_ID); if (creds.getCredential(KRB5_ID).getSubject() != null) { //user Kerberos subject already created, so user is authenticated logger.debug("Kerberos subject already exists. Returning..."); // Set status code responseCode = HttpServletResponse.SC_OK; // Return return responseCode; } } } } catch (NullPointerException e) { logger.debug("Krb subject does not exist. Continue with the process..."); } try { authMaxAge = Integer.parseInt(valveConf.getAuthMaxAge()); } catch (NumberFormatException nfe) { logger.error( "Configuration error: chack the configuration file as the number set for authMaxAge is not OK:"); } try { logger.debug("Getting credentials"); //Get Krb config files krbconfig = valveConf.getKrbConfig().getKrbconfig(); logger.debug("Krb config file: " + krbconfig); krbini = valveConf.getKrbConfig().getKrbini(); logger.debug("Krb ini file: " + krbini); if ((isNegotiate) && (serverSubject == null)) { try { initializeKerberos(); } catch (Exception ex) { logger.error("Exception during Server Kerberos config initialization: " + ex.getMessage(), ex); } finally { } } //Get user credentials //First read the u/p the credentails store, in this case using the same as the root login Credential userNamePwdCred = null; if (isNegotiate) { logger.debug("KerbAuth: IsNegotiate"); responseCode = authNegotiate(request, response); } else { logger.debug("KerbAuth: It's NOT IsNegotiate with id: " + id); try { logger.debug("HttpKrb: trying to get creds from repository id: " + id); userNamePwdCred = creds.getCredential(id); } catch (NullPointerException npe) { logger.error("NPE while reading credentials of ID: " + id); } if (userNamePwdCred == null) { logger.debug("HttpKrb: trying to get creds from repository \"root\""); userNamePwdCred = creds.getCredential("root"); } //Execute Authentication method with username and password responseCode = authUsernamePassword(userNamePwdCred); } if (responseCode == HttpServletResponse.SC_OK) { //create cookie createCookie(request, response); //add cookie to the cookie array authCookies.add(gsaKrbAuthCookie); //add Krb credentials Credential krb5Cred = new Credential(KRB5_ID); krb5Cred.setKrbSubject(getUserSubject()); krb5Cred.setUsername(getUsername()); creds.add(krb5Cred); } } catch (Exception e) { logger.debug("Error creating Credentials: " + e.getMessage()); e.printStackTrace(); responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } return responseCode; }
From source file:eu.qualityontime.commons.QPropertyUtilsBean.java
/** This just catches and wraps IllegalArgumentException. */ private Object invokeMethod(final Method method, final Object bean, final Object[] values) throws IllegalAccessException, InvocationTargetException { if (bean == null) { throw new IllegalArgumentException( "No bean specified " + "- this should have been checked before reaching this method"); }/*from ww w . j av a 2s .c o m*/ try { return method.invoke(bean, values); } catch (final NullPointerException cause) { // JDK 1.3 and JDK 1.4 throw NullPointerException if an argument is // null for a primitive value (JDK 1.5+ throw // IllegalArgumentException) String valueString = ""; if (values != null) { for (int i = 0; i < values.length; i++) { if (i > 0) { valueString += ", "; } if (values[i] == null) { valueString += "<null>"; } else { valueString += values[i].getClass().getName(); } } } String expectedString = ""; final Class<?>[] parTypes = method.getParameterTypes(); if (parTypes != null) { for (int i = 0; i < parTypes.length; i++) { if (i > 0) { expectedString += ", "; } expectedString += parTypes[i].getName(); } } final IllegalArgumentException e = new IllegalArgumentException( "Cannot invoke " + method.getDeclaringClass().getName() + "." + method.getName() + " on bean class '" + bean.getClass() + "' - " + cause.getMessage() // as per // https://issues.apache.org/jira/browse/BEANUTILS-224 + " - had objects of type \"" + valueString + "\" but expected signature \"" + expectedString + "\""); if (!initCause(e, cause)) { log.error("Method invocation failed", cause); } throw e; } catch (final IllegalArgumentException cause) { String valueString = ""; if (values != null) { for (int i = 0; i < values.length; i++) { if (i > 0) { valueString += ", "; } if (values[i] == null) { valueString += "<null>"; } else { valueString += values[i].getClass().getName(); } } } String expectedString = ""; final Class<?>[] parTypes = method.getParameterTypes(); if (parTypes != null) { for (int i = 0; i < parTypes.length; i++) { if (i > 0) { expectedString += ", "; } expectedString += parTypes[i].getName(); } } final IllegalArgumentException e = new IllegalArgumentException( "Cannot invoke " + method.getDeclaringClass().getName() + "." + method.getName() + " on bean class '" + bean.getClass() + "' - " + cause.getMessage() // as per // https://issues.apache.org/jira/browse/BEANUTILS-224 + " - had objects of type \"" + valueString + "\" but expected signature \"" + expectedString + "\""); if (!initCause(e, cause)) { log.error("Method invocation failed", cause); } throw e; } }
From source file:se.vgregion.service.innovationsslussen.idea.IdeaServiceImpl.java
protected List<CommentItemVO> getComments(IdeaContent ideaContent) { ArrayList<CommentItemVO> commentsList = new ArrayList<CommentItemVO>(); try {//from www. ja v a 2 s. com MBMessageDisplay messageDisplay = null; try { messageDisplay = mbMessageLocalService.getDiscussionMessageDisplay(ideaContent.getUserId(), ideaContent.getGroupId(), IdeaContent.class.getName(), ideaContent.getId(), WorkflowConstants.STATUS_ANY); } catch (NullPointerException e) { return commentsList; } Idea idea = ideaContent.getIdea(); MBThread thread = messageDisplay.getThread(); long threadId = thread.getThreadId(); long rootMessageId = thread.getRootMessageId(); messageComparator = new MessageCreateDateComparator(false); @SuppressWarnings("unchecked") List<MBMessage> mbMessages = mbMessageLocalService.getThreadMessages(threadId, WorkflowConstants.STATUS_ANY, messageComparator); for (MBMessage mbMessage : mbMessages) { String curCommentText = mbMessage.getBody(); Date createDate = mbMessage.getCreateDate(); long commentId = mbMessage.getMessageId(); if (commentId != rootMessageId) { long curCommentUserId = mbMessage.getUserId(); long scopeGroupId = mbMessage.getGroupId(); boolean isUserIdeaCreator = isUserIdeaCreator(curCommentUserId, idea); boolean isUserPrioCouncilMember = isUserPrioCouncilMember(curCommentUserId, scopeGroupId); boolean isUserInnovationsslussenEmployee = isUserInnovationsslussenEmployee(curCommentUserId, scopeGroupId); boolean isUserIdeaTransporter = isUserIdeaTransporter(curCommentUserId, scopeGroupId); CommentItemVO commentItem = new CommentItemVO(); commentItem.setCommentText(curCommentText); commentItem.setCreateDate(createDate); commentItem.setId(commentId); commentItem.setUserCreator(isUserIdeaCreator); commentItem.setUserIdeaTransporter(isUserIdeaTransporter); commentItem.setUserPrioCouncilMember(isUserPrioCouncilMember); commentItem.setUserInnovationsslussenEmployee(isUserInnovationsslussenEmployee); commentItem.setUserId(curCommentUserId); commentItem.setMessageId(mbMessage.getMessageId()); try { User curCommentUser = userLocalService.getUser(curCommentUserId); String curCommentUserFullName = curCommentUser.getFullName(); commentItem.setName(curCommentUserFullName); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } commentsList.add(commentItem); } } } catch (PortalException e) { LOGGER.error(e.getMessage(), e); } catch (SystemException e) { LOGGER.error(e.getMessage(), e); } return commentsList; }
From source file:it.cnr.icar.eric.client.ui.thin.RegistryObjectCollectionBean.java
/** * This method use to check the validity of Association Object by checking * its source/target object still exist.In case an exception occurs like * UnresolvedReferenceException it build user friendly message to display on * UI and server log. /*from ww w .j av a2 s . c o m*/ */ private boolean checkAssociationObjectValidity(String id, boolean isCurrentRegistryObject) { boolean status = true; RegistryObject ro = null; try { ro = RegistryBrowser.getBQM().getRegistryObject(id.trim()); if (ro instanceof Association) { if (((Association) ro).getSourceObject() != null && ((Association) ro).getTargetObject() != null) { status = true; if (RegistryBrowser.getBQM() .getRegistryObject(((Association) ro).getSourceObject().getKey().getId().trim()) == null || RegistryBrowser.getBQM().getRegistryObject( ((Association) ro).getTargetObject().getKey().getId().trim()) == null) { throw new NullPointerException(); } } } } catch (UnresolvedReferenceException ure) { try { if (isCurrentRegistryObject) { this.buildAssociationErrorMessage(ro); this.currentRegistryObject = null; log.warn(ure.getMessage()); } } catch (Exception ex) { } status = false; } catch (NullPointerException npe) { try { if (isCurrentRegistryObject) { this.buildAssociationErrorMessage(ro); this.currentRegistryObject = null; log.warn(npe.getMessage()); } } catch (Exception ex) { } status = false; } catch (Exception ex) { try { String msg = WebUIResourceBundle.getInstance().getString("message.AssociationNotValid1", new Object[] { ro.getKey().getId(), ro.getObjectType().toString(), WebUIResourceBundle.getInstance().getString("message.SourceTarget") }); OutputExceptions.warn(log, msg, msg, ex); } catch (Exception e) { } } return status; }
From source file:org.rti.zcore.dar.remote.StockEncounter.java
/** * This is only for editing patient dispensary items * @param inputType/*from w ww .j a va 2s . c om*/ * @param value * @param pageItemId * @param formId * @param encounterId * @param widgetType - "Form" or "Chart" * @param bridgeId - if the record is a patient bridge table * @return updated value */ public static String update(String inputType, String value, Long pageItemId, Long formId, Long encounterId, String widgetType, Long displayField, Long bridgeId, String currentFieldNameIdentifier) { String result = ""; WebContext exec = WebContextFactory.get(); String username = null; try { username = exec.getHttpServletRequest().getUserPrincipal().getName(); } catch (NullPointerException e) { // unit testing - it's ok... username = "demo"; } Connection conn = null; HttpSession session = null; try { conn = DatabaseUtils.getZEPRSConnection(username); SessionUtil zeprsSession = null; try { session = exec.getSession(); zeprsSession = (SessionUtil) session.getAttribute("zeprs_session"); } catch (Exception e) { // unit testing - it's ok... } Long patientId = null; Long eventId = null; Long siteId = null; String documentId = null; if (displayField == null) { displayField = encounterId; } PageItem pageItem = (PageItem) DynaSiteObjects.getPageItems().get(pageItemId); FormField formField = pageItem.getForm_field(); Long formFieldId = formField.getId(); if (widgetType.equals("Form")) { documentId = String.valueOf(formFieldId); } else if (widgetType.equals("Chart")) { documentId = String.valueOf(encounterId) + "." + String.valueOf(formFieldId); } if (pageItemId == 3861) { documentId = String.valueOf(encounterId) + "." + String.valueOf(displayField); } Form encounterForm = (Form) DynaSiteObjects.getForms().get(formId); if (encounterForm.getFormTypeId() == 6) { // patient bridge table form documentId = currentFieldNameIdentifier + String.valueOf(formFieldId); } SessionSubject sessionPatient = null; // sessionPatient used for rule processing in EncountersDAO.update if (zeprsSession != null) { try { sessionPatient = (SessionSubject) zeprsSession.getSessionPatient(); patientId = zeprsSession.getSessionPatient().getId(); eventId = zeprsSession.getSessionPatient().getCurrentEventId(); ClientSettings clientSettings = zeprsSession.getClientSettings(); siteId = clientSettings.getSiteId(); } catch (SessionUtil.AttributeNotFoundException e) { log.error("inputType: " + inputType + " value: " + value + " pageItemId: " + pageItemId + " formId: " + formId + " encounterId: " + encounterId); return documentId + "=" + "Error: your session may have expired. Please refresh this page or login again."; } catch (NullPointerException e) { // it's ok - testing patientId = new Long("44"); eventId = new Long("38"); siteId = new Long("1"); } } else { log.error("inputType: " + inputType + " value: " + value + " pageItemId: " + pageItemId + " formId: " + formId + " encounterId: " + encounterId); return documentId + "=" + "Error: your session may have expired. Please refresh this page or login again."; } Form form = (Form) DynaSiteObjects.getForms().get(formId); EncounterData encounter = null; String className = Constants.getDynasiteFormsPackage() + "." + StringManipulation.fixClassname(form.getName()); Class clazz = null; try { clazz = Class.forName(className); } catch (ClassNotFoundException e) { log.error(e); } try { encounter = (EncounterData) clazz.newInstance(); } catch (InstantiationException e) { log.error(e); } catch (IllegalAccessException e) { log.error(e); } try { encounter = (EncounterData) EncountersDAO.getOne(conn, encounterId, "SQL_RETRIEVEID" + formId, clazz); } catch (IOException e) { log.error(e); } catch (ServletException e) { log.error(e); } catch (SQLException e) { log.error(e); } catch (ObjectNotFoundException e) { log.error(e); } // extra validation for stock. Long itemId = null; String dataType = formField.getType(); Integer intValue = null; if (dataType.equals("Integer")) { try { intValue = Integer.valueOf(value); } catch (NumberFormatException e) { try { throw new PersistenceException( "This input field requires an integer value (e.g.: 55). You entered : " + value, e, false); } catch (PersistenceException e1) { result = documentId + "=" + "Error:" + e.getMessage(); } } } if (formField.getIdentifier().equals("dispensed")) { String itemIdStr = null; String dispensedStr = null; Long originallyDispensed = null; try { itemIdStr = BeanUtils.getProperty(encounter, "item_id"); dispensedStr = BeanUtils.getProperty(encounter, "dispensed"); } catch (IllegalAccessException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (InvocationTargetException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (NoSuchMethodException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (itemIdStr != null) { itemId = Long.valueOf(itemIdStr); originallyDispensed = Long.valueOf(dispensedStr); if (DynaSiteObjects.getStatusMap().get("balanceMap") != null) { HashMap<Long, StockReport> balanceMap = (HashMap<Long, StockReport>) DynaSiteObjects .getStatusMap().get("balanceMap"); StockReport stockReport = balanceMap.get(itemId); if (stockReport != null) { Integer balance = stockReport.getBalanceBF(); if (balance <= 0) { result = documentId + "=Error: This item is out of stock. Cannot proceed with this update. Current balance: " + balance; return result; } else if ((balance + originallyDispensed) - intValue < 0) { // add the originallyDispensed value back to the balanace, and then subtract the new dispensed value. result = documentId + "=Error: This update would create a negative stock balanace Please reduce the amount dispensed. Current balance: " + balance; return result; } } } } } else if (formField.getIdentifier().equals("item_id")) { result = documentId + "=Error: You may not change the stock item. Either delete this record or set the Quantity dispensed for this item to zero (0) and create a new record (Dispensing link -> \"Create New Dispensing record\" link)."; return result; } Timestamp lastModified = null; if (value != null) { try { EncountersDAO.update(conn, value, pageItemId, formId, encounterId, siteId, username, patientId, eventId, sessionPatient, lastModified, bridgeId, currentFieldNameIdentifier, null, session); if (formField.getIdentifier().equals("dispensed")) { if ((itemId != null) && (DynaSiteObjects.getStatusMap().get("balanceMap") != null)) { HashMap<Long, StockReport> balanceMap = (HashMap<Long, StockReport>) DynaSiteObjects .getStatusMap().get("balanceMap"); StockReport stockReport = balanceMap.get(itemId); if (stockReport != null) { if (intValue != null) { StockControl tempStockControl = InventoryDAO.getCurrentStockBalance(conn, itemId, null); Integer currentBalance = tempStockControl.getBalance(); //Integer currentBalance = balanceBF - intValue; stockReport.setBalanceBF(currentBalance); stockReport.setOnHand(currentBalance); balanceMap.put(itemId, stockReport); } } } } } catch (SQLException e) { log.error(e); } catch (ServletException e) { log.error(e); } catch (PersistenceException e) { result = documentId + "=" + "Error:" + e.getMessage(); } catch (ObjectNotFoundException e) { log.error(e); } catch (ClassNotFoundException e) { log.error(e); } catch (IOException e) { result = documentId + "=" + "Error:" + e.getMessage(); log.error(e); } if (result.equals("")) { if (value.equals("")) { result = documentId + "=" + value; } else { if (inputType.equals("select") || inputType.equals("select-dwr") || inputType.equals("multiselect_item")) { FieldEnumeration fieldEnum = (FieldEnumeration) DynaSiteObjects.getFieldEnumerations() .get(Long.valueOf(value)); switch (formFieldId.intValue()) { default: result = documentId + "=" + fieldEnum.getEnumeration(); break; } } else if (inputType.equals("lab_results")) { FieldEnumeration fieldEnum = (FieldEnumeration) DynaSiteObjects.getFieldEnumerations() .get(Long.valueOf(value)); result = documentId + "=" + fieldEnum.getEnumeration(); } else if (inputType.equals("currentMedicine")) { // Drugs drug = DrugsDAO.getOne(Long.valueOf(value)); Drugs drug = null; try { drug = (Drugs) DynaSiteObjects.getDrugMap().get(Long.valueOf(value)); result = documentId + "=" + drug.getName(); } catch (NumberFormatException e) { e.printStackTrace(); } if (drug == null) { result = documentId + "=" + value; } } else if (inputType.equals("Yes/No")) { if (value.equals("1")) { value = "Yes"; } else if (value.equals("0")) { value = "No"; } result = documentId + "=" + value; } else if (inputType.equals("checkbox")) { if (value.equals("true")) { value = "Yes"; } else if (value.equals("1")) { value = "Yes"; } else if (value.equals("on")) { value = "Yes"; } else if (value.equals("false")) { value = ""; } else if (value.equals("0")) { value = ""; } else if (value.equals("off")) { value = ""; } result = documentId + "=" + value; } else if (inputType.equals("checkbox_dwr")) { if (value.equals("true")) { value = "Yes"; } else if (value.equals("on")) { value = "Yes"; } else if (value.equals("false")) { value = ""; } else if (value.equals("off")) { value = ""; } result = documentId + "=" + value; } else if (inputType.equals("sex")) { if (value.equals("1")) { value = "Female"; } else if (value.equals("2")) { value = "Male"; } result = documentId + "=" + value; } else if (inputType.equals("ega")) { int valueInt = new Integer(value); int days = valueInt % 7; int weeks = valueInt / 7; value = weeks + ", " + days + "/7"; result = documentId + "=" + value; } else if (pageItem.getInputType().equals("sites") || pageItem.getInputType().equals("sites_not_selected")) { Long thisSite = new Long(value); Site site = (Site) DynaSiteObjects.getClinicMap().get(thisSite); value = site.getName(); result = documentId + "=" + value; } else if (inputType.equals("text") & displayField.intValue() != formFieldId.intValue()) { // used in Lab form chart to share two fields in one cell. /*if (displayField != 0) { documentId = String.valueOf(encounterId) + "." + String.valueOf(displayField); }*/ result = documentId + "=" + value; //} else if (inputType.equals("dropdown") & currentFieldNameIdentifier != null) { } else if (inputType.equals("dropdown") || inputType.equals("dropdown-add-one") || inputType.equals("dropdown_site")) { //Integer id = Integer.valueOf(value); String uuidValue = null; Integer id = null; if (pageItem.getFkIdentifier() != null && pageItem.getFkIdentifier().equals("uuid")) { uuidValue = value; } else { id = Integer.valueOf(value); } DropdownItem item = null; try { item = WidgetUtils.getDropdownItem(conn, pageItem.getDropdownTable(), pageItem.getDropdownColumn(), id, null, pageItem.getFkIdentifier(), uuidValue); } catch (ObjectNotFoundException e) { log.debug("value for Dropdown item not found:" + e); } catch (SQLException e) { log.debug("value for Dropdown item not found:" + e); } if (item != null) { value = item.getDropdownValue(); result = documentId + "=" + value; } else { value = "Unable to fetch updated value."; result = documentId + "=" + value; } } else { result = documentId + "=" + value; } } } } else { result = documentId + "=" + "Error: No value entered."; } } catch (ServletException e) { log.error(e); } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { if (conn != null && !conn.isClosed()) { conn.close(); conn = null; } } catch (SQLException e) { e.printStackTrace(); } } return result; }