### Eclipse Workspace Patch 1.0 #P OMRS-logic Index: web/module/deleteSuccessToken.jsp =================================================================== --- web/module/deleteSuccessToken.jsp (revision 0) +++ web/module/deleteSuccessToken.jsp (revision 0) @@ -0,0 +1,3 @@ +<%@ include file="/WEB-INF/template/include.jsp" %> + + \ No newline at end of file Index: web/module/editSuccessToken.jsp =================================================================== --- web/module/editSuccessToken.jsp (revision 0) +++ web/module/editSuccessToken.jsp (revision 0) @@ -0,0 +1,3 @@ +<%@ include file="/WEB-INF/template/include.jsp" %> + + \ No newline at end of file Index: metadata/messages.properties =================================================================== --- metadata/messages.properties (revision 12751) +++ metadata/messages.properties (working copy) @@ -20,3 +20,25 @@ logic.init.status.running = Default Logic Rule Registration running logic.init.status.complete = Default Logic Rule Registration complete. logic.init.submit.button = Run now... + +logic.logicTokenForm.empty = All The Fields Have To Be Filled +logic.tokens.list.title = Available Tokens +logic.tokens.individual.Detail = Token Info +logic.token.string = Token Name +logic.token.className = Token Class Name +logic.token.error.class.name = Class Name cannot be empty +logic.token.manage.title = Individual Token Management +logic.token.state = Token State +logic.token.error.token = Token value cannot be empty +logic.token.error.state = State value cannot be empty +logic.token.tag.values = Tagged Values +logic.token.save = Save Changes +logic.token.saved = Token Saved +logic.token.delete = Delete +logic.view.token = Registered Tokens +logic.token.error.general = Error while submitting form +logic.token.error = Token value cannot be empty +logic.field.blank = Fields Cannot be left blank +logic.parameter.blank = Parameters cannot be left blank +logic.delete.success = Successfully Deleted +logic.delete.notsuccess = Not deleted \ No newline at end of file Index: web/module/tokenInit.jsp =================================================================== --- web/module/tokenInit.jsp (revision 0) +++ web/module/tokenInit.jsp (revision 0) @@ -0,0 +1,46 @@ +<%@ include file="/WEB-INF/template/include.jsp" %> +<%@ include file="/WEB-INF/template/header.jsp"%> + + + + + + + + + + + + + +"/> +
+ + + +<%@ include file="/WEB-INF/template/footer.jsp" %> + \ No newline at end of file Index: src/api/org/openmrs/logic/extension/html/AdminList.java =================================================================== --- src/api/org/openmrs/logic/extension/html/AdminList.java (revision 12751) +++ src/api/org/openmrs/logic/extension/html/AdminList.java (working copy) @@ -20,6 +20,7 @@ Map localHashMap = new LinkedHashMap(); localHashMap.put("/module/logic/init.form", "logic.init.title"); localHashMap.put("/module/logic/logic.form", "logic.start.title"); + localHashMap.put("/module/logic/tokenInit.list", "logic.view.token"); return localHashMap; } } Index: web/module/token.jsp =================================================================== --- web/module/token.jsp (revision 0) +++ web/module/token.jsp (revision 0) @@ -0,0 +1,32 @@ +<%@ include file="/WEB-INF/template/include.jsp" %> +<%@ include file="/WEB-INF/template/header.jsp"%> + + + + + +
+ + + + + + + + + + + + + +
+ "> + + "> + + +
+ "> +
+ +<%@ include file="/WEB-INF/template/footer.jsp" %> \ No newline at end of file Index: web/src/org/openmrs/logic/web/controller/TokenController.java =================================================================== --- web/src/org/openmrs/logic/web/controller/TokenController.java (revision 0) +++ web/src/org/openmrs/logic/web/controller/TokenController.java (revision 0) @@ -0,0 +1,313 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ + +package org.openmrs.logic.web.controller; + + +import java.util.Collections; + +import java.util.List; +import java.util.ArrayList; +import java.util.Vector; + + + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openmrs.Patient; +import org.openmrs.api.APIException; +import org.openmrs.api.context.Context; +import org.openmrs.logic.LogicService; +import org.openmrs.messagesource.MessageSourceService; + +import org.springframework.beans.propertyeditors.CustomNumberEditor; +import org.springframework.context.support.MessageSourceAccessor; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.web.bind.ServletRequestDataBinder; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.openmrs.web.WebConstants; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.validation.BindException; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.mvc.SimpleFormController; +import org.springframework.web.servlet.view.RedirectView; + + + +import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable; +@Controller +public class TokenController { + + /** Logger for this class and subclasses */ + protected final Log log = LogFactory.getLog(getClass()); + + /** + * Initializes the entire process of viewing, editing and updating the Default Registered Tokens + * Responsible for performing ajax calls for corresponding pages + * + * + */ + + @RequestMapping(value = "/module/logic/tokenInit", method = RequestMethod.GET) + public void init(HttpServletRequest request, ModelMap model) + { + HttpSession session=request.getSession(); + int initPageValue=1; + log.debug("Entered in to the initialization stage of TokenController"); + + if((Integer)(session.getAttribute("requestPageNumberSession"))!=null) + { + model.addAttribute("reqPageNum", (Integer)(session.getAttribute("requestPageNumberSession"))); + } + + else + { + model.addAttribute("reqPageNum", initPageValue); + } + } + + /** + * Performing the Delete operation of entire tokens + * + * + */ + @RequestMapping(value = "/module/logic/deleteSuccessToken", method = RequestMethod.POST) + protected void onSubmit(HttpServletRequest request, ModelMap map) throws Exception { + HttpSession httpSession = request.getSession(); + + + + log.debug("Entered in to onSubmit of tokeListController"); + MessageSourceService msa = Context.getMessageSourceService(); + + if (Context.hasPrivilege("View Administration Functions")) + { + + + log.debug("user has the privileges ro go further in to onSubmit of tokeListController"); + String success = ""; + String error = ""; + + + + String[] ruleTokenList = request.getParameterValues("tokenName"); + + + + + String deleted = msa.getMessage("logic.delete.success"); + String notDeleted = msa.getMessage("logic.delete.notsuccess"); + + LogicService logicService = Context.getLogicService(); + if(ruleTokenList!=null) + { + for (String p : ruleTokenList) + { + + try{ + + logicService.removeRule(p); + if (!success.equals("")) + success += "
"; + success += p + " " + deleted; + } + + catch (DataIntegrityViolationException e) + { + error = handleTokensIntegrityException(e, error, notDeleted); + } + catch (APIException e) + { + error = handleTokensIntegrityException(e, error, notDeleted); + httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, error); + } + + + log.debug("The success message in onsubmit is "+success); + } + + } + + else + error = notDeleted; + + + + + if (!success.equals("")) + httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, success); + if (!error.equals("")) + httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, error); + } + + + } + + + + /** + * Logs a Token/Rule delete data integrity violation exception and returns a user friedly message + * of the problem that occured. ++ * ++ * @param e the exception. ++ * @param error the error message. ++ * @param notDeleted the not deleted error message. ++ * @return the formatted error message. ++ */ + private String handleTokensIntegrityException(Exception e, String error, String notDeleted) { + log.warn("Error deleting Token", e); + if (!error.equals("")) + error += "
"; + error += notDeleted; + return error; + } + +/** + * Place holder for the token list. Performs the functionality of fetching necessary tokens + * + * @param model The ModelMap to be used by view to render page + */ + +@RequestMapping(value = "/module/logic/tokenTable") +public void showTokensListPage(HttpServletRequest request, ModelMap map) +{ + + HttpSession session=request.getSession(); + log.debug("Entered in to the showTokenListPage of TokenController"); + log.debug("Entered in to formBackingObjectMethod of tokeList.list"); + + int requestPageNumber=0; + + + requestPageNumber=Integer.parseInt((String)request.getParameter("page")); + List ruleTokenList=null; + Vector ruleFragmentedTokenList=new Vector(); + int pageNumbers=0; + ArrayList pageList = new ArrayList(); + + + + + log.debug("The value of the requested page is : "+requestPageNumber); + + if (Context.hasPrivilege("View Administration Functions")) + { + + log.debug("This user has the privileges : "); + LogicService logicService = Context.getLogicService(); + ruleTokenList = logicService.getAllTokens(); + log.debug("The ruleTokenList size is : "+ruleTokenList.size()); + Collections.sort(ruleTokenList); + + int size=ruleTokenList.size(); + + if(size%20!=0) + { + pageNumbers=(size/20)+1; + + } + + else + { + pageNumbers=(size/20); + + + } + + log.debug("The value od the page numbers : "+pageNumbers); + for(int i=1;i<=pageNumbers;i++) + { + pageList.add(i); + } + + log.debug("The object value of the page numbers : "+pageList.size()); + + int startingCountValue=((requestPageNumber-1)*20); + log.debug("The startign count value is : "+startingCountValue); + int finishingCountValue=(requestPageNumber*20); + if(finishingCountValue>ruleTokenList.size()) + { + finishingCountValue=ruleTokenList.size(); + } + log.debug("The finishing count value is : "+finishingCountValue); + + + String tempToeknValue=ruleTokenList.get(229); + + log.debug("229 th temporary token value is : "+tempToeknValue); + + + + int a=0; + + for(int i=startingCountValue; i0.4 org.openmrs.@MODULE_ID@ OpenMRS Core Developer - - - + @MODULE_PACKAGE@.LogicModuleActivator https://dev.openmrs.org/modules/download/@MODULE_ID@/update.rdf Index: web/src/org/openmrs/logic/web/controller/LogicInitController.java =================================================================== --- web/src/org/openmrs/logic/web/controller/LogicInitController.java (revision 12751) +++ web/src/org/openmrs/logic/web/controller/LogicInitController.java (working copy) @@ -41,7 +41,8 @@ */ @RequestMapping("/module/logic/load") public void runInit() { - if (Context.hasPrivilege("View Administration Functions")) { + if (Context.hasPrivilege("View Administration Functions")) + { isInitRunning = ProcessStatus.STATUS_ON; LogicUtil.registerDefaultRules(); isInitRunning = ProcessStatus.STATUS_OFF; Index: web/module/tokens.jsp =================================================================== --- web/module/tokens.jsp (revision 12751) +++ web/module/tokens.jsp (working copy) @@ -1,2 +1,3 @@ -<%@ include file="/WEB-INF/template/include.jsp"%>${keyword} +<%@ include file="/WEB-INF/template/include.jsp"%> +${keyword} \ No newline at end of file Index: src/api/org/openmrs/logic/db/hibernate/HibernateLogicRuleTokenDAO.java =================================================================== --- src/api/org/openmrs/logic/db/hibernate/HibernateLogicRuleTokenDAO.java (revision 12751) +++ src/api/org/openmrs/logic/db/hibernate/HibernateLogicRuleTokenDAO.java (working copy) @@ -65,7 +65,8 @@ /** * @see org.openmrs.logic.db.LogicRuleTokenDAO#saveLogicRuleToken(org.openmrs.logic.LogicRuleToken) */ - public LogicRuleToken saveLogicRuleToken(LogicRuleToken logicToken) throws DAOException { + public LogicRuleToken saveLogicRuleToken(LogicRuleToken logicToken) throws DAOException + { sessionFactory.getCurrentSession().saveOrUpdate(logicToken); return logicToken; } @@ -74,6 +75,8 @@ * @see org.openmrs.logic.db.LogicRuleTokenDAO#getLogicRuleToken(java.lang.String) */ public LogicRuleToken getLogicRuleToken(String token) { + System.out.println("Entered in to dangerous area"); + System.out.println("The value of the session at hibernate level"+sessionFactory.getCurrentSession()); return (LogicRuleToken) sessionFactory.getCurrentSession().createQuery( "from LogicRuleToken logicRuleToken where logicRuleToken.token = :token").setString("token", token) .uniqueResult(); Index: web/src/org/openmrs/logic/web/controller/LogicTokenController.java =================================================================== --- web/src/org/openmrs/logic/web/controller/LogicTokenController.java (revision 0) +++ web/src/org/openmrs/logic/web/controller/LogicTokenController.java (revision 0) @@ -0,0 +1,155 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ + +package org.openmrs.logic.web.controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openmrs.api.context.Context; +import org.openmrs.logic.LogicRuleToken; +import org.openmrs.logic.LogicService; +import org.openmrs.logic.Rule; +import org.openmrs.logic.StatefulRule; +import org.openmrs.web.WebConstants; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller +public class LogicTokenController { + + /** Logger for this class and subclasses */ + protected final Log log = LogFactory.getLog(getClass()); + + + + /** ++ * The onSubmit function receives the form/command object that was modified by the token editing input form ++ * and saves it to the db ++ * ++ * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest, ++ * javax.servlet.http.HttpServletResponse, java.lang.Object, ++ * org.springframework.validation.BindException) ++ */ + @RequestMapping(value = "/module/logic/editSuccessToken", method = RequestMethod.POST) + public void onSubmit(HttpServletRequest request,ModelMap model,Object obj) throws Exception { + + HttpSession httpSession = request.getSession(); + String requestTokenState =null; + + + String requestTokenName = request.getParameter("newTokenName").trim().toString().toUpperCase(); + + //If the Rule is of Reference class then it will be having states. If not no states will be there. + if((request.getParameter("newClassName").trim().toString()).equalsIgnoreCase("org.openmrs.logic.rule.ReferenceRule")) + { + + requestTokenState = request.getParameter("newTokenState").trim().toString(); + } + + + String requestTokenClass = request.getParameter("newClassName").trim().toString(); + + + + String tempToken = request.getParameter("previousTokenName").trim().toString(); + + + if (Context.hasPrivilege("View Administration Functions")) + { + + log.debug("onSubmit of LogicTokenFormController has admin privileges"); + + LogicService logicService = Context.getLogicService(); + Class c = Context.loadClass(requestTokenClass); + Object obj1 = c.newInstance(); + Rule rule = (Rule) obj1; + + if(requestTokenClass.equalsIgnoreCase("org.openmrs.logic.rule.ReferenceRule")) + { + + ((StatefulRule)rule).restoreFromString(requestTokenState); + } + + + + + logicService.removeRule(tempToken); + logicService.updateRule(requestTokenName, rule); + + + + + httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "logic.token.saved"); + + + } + + + + } + + + + + /** + * This is called prior to displaying the token info for the first time. It tells Spring the + * form/command object to load into the request + * + * @see org.springframework.web.servlet.mvc.AbstractFormController#formBackingObject(javax.servlet.http.HttpServletRequest) + */ + + + + + + @RequestMapping(value = "/module/logic/logicToken", method = RequestMethod.GET) + public @ModelAttribute("logicToken") Object showTokenDescriptionPage(@RequestParam(required = false, value = "ruleToken") String requestToken, ModelMap model) + { + log.debug("Entered in to formBackingObjectMethod of LogicToken.form"); + LogicRuleToken logicToken=null; + + + + + + + log.debug("Entered in to formBackingObjectMethod of LogicToken.form"); + if (requestToken != null) + { + LogicService logicService = Context.getLogicService(); + + Rule rule=logicService.getRule(requestToken); + logicToken=new LogicRuleToken(requestToken,rule); + + + } + if(logicToken == null) + new LogicRuleToken(); + + + log.debug("Completed Token Info fetching Operation"); + + return logicToken; + + + } + + +} \ No newline at end of file Index: web/module/tokenTable.jsp =================================================================== --- web/module/tokenTable.jsp (revision 0) +++ web/module/tokenTable.jsp (revision 0) @@ -0,0 +1,44 @@ +<%@ include file="/WEB-INF/template/include.jsp"%> + + + + + + + + + + + +
+ + + ${pList} + ${pList} + + +
+ +
+ + + + + + + + + + + + + +
+ "> + + "> + + +
+ "> +
\ No newline at end of file Index: metadata/moduleApplicationContext.xml =================================================================== --- metadata/moduleApplicationContext.xml (revision 12751) +++ metadata/moduleApplicationContext.xml (working copy) @@ -19,6 +19,7 @@ + Index: web/module/logicToken.jsp =================================================================== --- web/module/logicToken.jsp (revision 0) +++ web/module/logicToken.jsp (revision 0) @@ -0,0 +1,119 @@ +<%@ include file="/WEB-INF/template/include.jsp" %> +<%@ include file="/WEB-INF/template/header.jsp"%> + + + + + + + + + + + + +

+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + +
+ "> + "> +
+ "> + +
+ "> + +
+ "> +
+ + + +
+ + + \ No newline at end of file Index: dist/logic-0.4.omod =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream