Search in sources :

Example 1 with StateEntity

use of org.mifos.application.master.business.StateEntity in project head by mifos.

the class AccountStateMachines method retrieveNextPossibleAccountStateObjectsForLoan.

private List<AccountStateEntity> retrieveNextPossibleAccountStateObjectsForLoan(StateEntity accountStateEntityObj) throws ApplicationException {
    logger.debug("In AccountStateMachines::retrieveNextPossibleAccountStateObjectsForLoan()");
    List<AccountStateEntity> stateEntityList = new ArrayList<AccountStateEntity>();
    try {
        List<StateEntity> stateList = statesMapForLoan.get(accountStateEntityObj);
        if (null != stateList) {
            for (StateEntity accountStateEntity : stateList) {
                for (AccountStateEntity accountStateEnty : accountStateEntityListForLoan) {
                    if (accountStateEntity.sameId(accountStateEnty)) {
                        stateEntityList.add(accountStateEnty);
                        break;
                    }
                }
            }
        }
        return stateEntityList;
    } catch (Exception e) {
        throw new StatesInitializationException(SavingsConstants.STATEINITIALIZATION_EXCEPTION, e);
    }
}
Also used : ArrayList(java.util.ArrayList) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) ServiceException(org.mifos.framework.exceptions.ServiceException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) StateEntity(org.mifos.application.master.business.StateEntity)

Example 2 with StateEntity

use of org.mifos.application.master.business.StateEntity in project head by mifos.

the class AccountStateMachines method retrieveNextPossibleCustomerStateForClient.

private List<CustomerStatusEntity> retrieveNextPossibleCustomerStateForClient(StateEntity customerStateEntityObj) throws ApplicationException {
    logger.debug("In AccountStateMachines::retrieveNextPossibleCustomerStateForClient()");
    List<CustomerStatusEntity> stateEntityList = new ArrayList<CustomerStatusEntity>();
    try {
        List<StateEntity> stateList = statesMapForClient.get(customerStateEntityObj);
        if (null != stateList) {
            for (StateEntity customerStateEntity : stateList) {
                for (CustomerStatusEntity customerStatusEntry : customerStatusListForClient) {
                    if (customerStatusEntry.sameId(customerStateEntity)) {
                        stateEntityList.add(customerStatusEntry);
                        break;
                    }
                }
            }
        }
        return stateEntityList;
    } catch (Exception e) {
        throw new StatesInitializationException(SavingsConstants.STATEINITIALIZATION_EXCEPTION, e);
    }
}
Also used : ArrayList(java.util.ArrayList) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) CustomerStatusEntity(org.mifos.customers.business.CustomerStatusEntity) ServiceException(org.mifos.framework.exceptions.ServiceException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) StateEntity(org.mifos.application.master.business.StateEntity)

Example 3 with StateEntity

use of org.mifos.application.master.business.StateEntity in project head by mifos.

the class AccountStateMachines method retrieveNextPossibleCustomerStateForGroup.

private List<CustomerStatusEntity> retrieveNextPossibleCustomerStateForGroup(StateEntity customerStateEntityObj) throws ApplicationException {
    logger.debug("In AccountStateMachines::retrieveNextPossibleCustomerStateForGroup()");
    List<CustomerStatusEntity> stateEntityList = new ArrayList<CustomerStatusEntity>();
    try {
        List<StateEntity> stateList = statesMapForGroup.get(customerStateEntityObj);
        if (null != stateList) {
            for (StateEntity customerStateEntity : stateList) {
                for (CustomerStatusEntity customerStatusEntry : customerStatusListForGroup) {
                    if (customerStatusEntry.sameId(customerStateEntity)) {
                        stateEntityList.add(customerStatusEntry);
                        break;
                    }
                }
            }
        }
        return stateEntityList;
    } catch (Exception e) {
        throw new StatesInitializationException(SavingsConstants.STATEINITIALIZATION_EXCEPTION, e);
    }
}
Also used : ArrayList(java.util.ArrayList) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) CustomerStatusEntity(org.mifos.customers.business.CustomerStatusEntity) ServiceException(org.mifos.framework.exceptions.ServiceException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) StateEntity(org.mifos.application.master.business.StateEntity)

Example 4 with StateEntity

use of org.mifos.application.master.business.StateEntity in project head by mifos.

the class StateXMLParser method loadMapFromXml.

public Map<StateEntity, List<StateEntity>> loadMapFromXml(String filename, String configurationName) {
    Map<StateEntity, List<StateEntity>> transitionMap = new HashMap<StateEntity, List<StateEntity>>();
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(true);
        factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
        // Specify our own schema - this overrides the schemaLocation in the
        // xml file
        factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", "StateMachine.xsd");
        DocumentBuilder builder = factory.newDocumentBuilder();
        builder.setErrorHandler(null);
        Document document = builder.parse(MifosResourceUtil.getClassPathResourceAsStream(filename));
        Node mapToprocess = null;
        /*
             * String configurationName = ""; if
             * (stateConfiguration=="configuration1") configurationName = "1";
             * else configurationName = "2";
             */
        NodeList configMaps = document.getElementsByTagName("stateConfiguration");
        for (int m = 0; m < configMaps.getLength(); m++) {
            Node stateConfiguration = configMaps.item(m);
            if (configurationName.equals(stateConfiguration.getAttributes().getNamedItem("configurationName").getNodeValue())) {
                mapToprocess = stateConfiguration;
            }
        }
        // NodeList stateList = firstChild.getChildNodes();
        NodeList stateList = mapToprocess.getChildNodes();
        for (int i = 0; i < stateList.getLength(); i++) {
            // each state has state id and possiblestates as childern
            Node state = stateList.item(i);
            // iterate for each child of state
            NodeList stateInfoList = state.getChildNodes();
            StateEntity currentState = null;
            List<StateEntity> currntPossibleStates = new ArrayList<StateEntity>();
            for (int j = 0; j < stateInfoList.getLength(); j++) {
                Node info = stateInfoList.item(j);
                if ("stateid".equals(info.getLocalName())) {
                    Element ele = (Element) info;
                    currentState = new StateEntity(Short.valueOf(((Text) ele.getFirstChild()).getData()));
                }
                if ("possiblestates".equals(info.getLocalName())) {
                    // get all the childern
                    NodeList allStates = info.getChildNodes();
                    currntPossibleStates = new ArrayList<StateEntity>();
                    for (int k = 0; k < allStates.getLength(); k++) {
                        Node infoState = allStates.item(k);
                        NodeList eachPossiblechild = infoState.getChildNodes();
                        for (int l = 0; l < eachPossiblechild.getLength(); l++) {
                            Node eachPossiblechildelement = eachPossiblechild.item(l);
                            if ("stateid".equals(eachPossiblechildelement.getLocalName())) {
                                Element element = (Element) eachPossiblechildelement;
                                Short possibleTrantionId = Short.valueOf(((Text) element.getFirstChild()).getData());
                                currntPossibleStates.add(new StateEntity(possibleTrantionId));
                            }
                        }
                    }
                }
            }
            if (currentState != null) {
                transitionMap.put(currentState, currntPossibleStates);
            }
        }
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (SAXParseException e) {
        throw new RuntimeException(e);
    } catch (SAXException e) {
        throw new RuntimeException(e);
    }
    return transitionMap;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) HashMap(java.util.HashMap) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.w3c.dom.Document) StateEntity(org.mifos.application.master.business.StateEntity) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 5 with StateEntity

use of org.mifos.application.master.business.StateEntity in project head by mifos.

the class AccountStateMachines method retrieveNextPossibleAccountStateObjectsForSavings.

private List<AccountStateEntity> retrieveNextPossibleAccountStateObjectsForSavings(StateEntity accountStateEntityObj) throws ApplicationException {
    logger.debug("In AccountStateMachines::retrieveNextPossibleAccountStateObjectsForSavings()");
    List<AccountStateEntity> stateEntityList = new ArrayList<AccountStateEntity>();
    try {
        List<StateEntity> stateList = statesMapForSavings.get(accountStateEntityObj);
        if (null != stateList) {
            for (StateEntity accountStateEntity : stateList) {
                for (AccountStateEntity accountStateEnty : accountStateEntityListForSavings) {
                    if (accountStateEntity.sameId(accountStateEnty)) {
                        stateEntityList.add(accountStateEnty);
                        break;
                    }
                }
            }
        }
        return stateEntityList;
    } catch (Exception e) {
        throw new StatesInitializationException(SavingsConstants.STATEINITIALIZATION_EXCEPTION, e);
    }
}
Also used : ArrayList(java.util.ArrayList) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) ServiceException(org.mifos.framework.exceptions.ServiceException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) StateEntity(org.mifos.application.master.business.StateEntity)

Aggregations

ArrayList (java.util.ArrayList)6 StateEntity (org.mifos.application.master.business.StateEntity)6 ApplicationException (org.mifos.framework.exceptions.ApplicationException)5 PersistenceException (org.mifos.framework.exceptions.PersistenceException)5 ServiceException (org.mifos.framework.exceptions.ServiceException)5 StatesInitializationException (org.mifos.framework.exceptions.StatesInitializationException)5 CustomerStatusEntity (org.mifos.customers.business.CustomerStatusEntity)3 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1 SAXException (org.xml.sax.SAXException)1 SAXParseException (org.xml.sax.SAXParseException)1