Package org.infoglue.deliver.applications.databeans

Examples of org.infoglue.deliver.applications.databeans.FormStatisticsBean


    getController().getDeliveryContext().setDisablePageCache(true);
   
    if(formContentId == null || formContentId.equals("-1"))
       throw new JspException("Wrong input");
   
    FormStatisticsBean formStatisticsBean = new FormStatisticsBean();
    try
    {
      ContentVO formContentVO = getController().getContent(formContentId);
      if(formContentVO != null)
      {
        LanguageVO masterLanguageVO = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForRepository(getController().getDatabase(), formContentVO.getRepositoryId());
        Collection formEntryValueVOList = FormEntryController.getController().getFormEntryValueVOList(formContentId, fieldName);
 
        String componentStructure = getController().getContentAttribute(formContentId, masterLanguageVO.getId(), "ComponentStructure", true);
        DOMBuilder domBuilder = new DOMBuilder();
        Document document = domBuilder.getDocument(componentStructure);
       
        String path = "";
       
        Map defaultOptionBeans = new HashMap();
        //document.selectSingleNode("/components//component/properties[property[@name = 'Field name'][@path_sv='food']]/property[@name='Options']/@path_sv");
        Element optionsParameter = (Element)document.selectSingleNode("/components//component/properties[property[@name = 'Field name'][@path_sv='" + fieldName + "']]/property[@name='" + optionsPropertyName + "']");
        if(optionsParameter != null)
        {
          path = optionsParameter.attributeValue("path_" + getController().getLanguage(getController().getLanguageId()).getLanguageCode());
          if(path == null || path.equals(""))
            path = optionsParameter.attributeValue("path_" + masterLanguageVO.getLanguageCode());
          if(path == null || path.equals(""))
            path = optionsParameter.attributeValue("path");
         
          String[] optionPairs = path.split("igbr");
          for(int i=0; i<optionPairs.length; i++)
          {
            String optionPair = optionPairs[i];
            String[] nameValuePair = optionPair.split("=");
            if(nameValuePair.length == 2)
            {
              String name = nameValuePair[0];
              String value = nameValuePair[1];
              FormStatisticsOptionBean formStatisticsOptionBean = new FormStatisticsOptionBean(name, value, 0, 0F);
              defaultOptionBeans.put(name, formStatisticsOptionBean);
            }
          }
        }
 
        formStatisticsBean.getFormEntryValueVOList().addAll(formEntryValueVOList);
 
        Integer totalEntries = formEntryValueVOList.size();
       
        Float totalValue = 0F;
       
        Map<String,Object> statisticsMap = new HashMap<String,Object>();
        statisticsMap.put("totalEntries", totalEntries);
       
        Iterator formEntryValueVOListIterator = formEntryValueVOList.iterator();
        while(formEntryValueVOListIterator.hasNext())
        {
          FormEntryValueVO formEntryValueVO = (FormEntryValueVO)formEntryValueVOListIterator.next();
         
          if(type.equals("percentage") || type.equals("numeric"))
          {
            Integer count = (Integer)statisticsMap.get("" + formEntryValueVO.getValue());
            if(count == null)
              statisticsMap.put("" + formEntryValueVO.getValue(), 1);
            else
              statisticsMap.put("" + formEntryValueVO.getValue(), count + 1);
          }
          else if(type.equals("average"))
          {
            try
            {
              totalValue = totalValue + Integer.getInteger(formEntryValueVO.getValue());
            }
            catch (Exception e)
            {
              logger.warn("Not a valid number:" + e.getMessage());
            }
          }
        }
       
        Map<String,Object> statisticsResultMap = new HashMap<String,Object>();
        statisticsResultMap.putAll(statisticsMap);
        if(type.equals("percentage") || type.equals("numeric"))
        {
          Iterator statisticsMapIterator = statisticsMap.keySet().iterator();
          while(statisticsMapIterator.hasNext())
          {
            String key = (String)statisticsMapIterator.next();
            Integer totalCount = (Integer)statisticsMap.get(key);
            statisticsResultMap.put(key + "_totalCount", totalCount);
            statisticsResultMap.put(key + "_percentage", (totalCount / totalEntries) * 100);
           
            String[] optionPairs = path.split("igbr");
            for(int i=0; i<optionPairs.length; i++)
            {
              String optionPair = optionPairs[i];
              String[] nameValuePair = optionPair.split("=");
              if(nameValuePair.length == 2)
              {
                String name = nameValuePair[0];
                String value = nameValuePair[1];
                if(name.equalsIgnoreCase(key))
                {
                  FormStatisticsOptionBean formStatisticsOptionBean = new FormStatisticsOptionBean(name, value, totalCount, ((float)totalCount / totalEntries) * 100);
                  formStatisticsBean.getFormStatisticsOptionBeanList().add(formStatisticsOptionBean);
                  defaultOptionBeans.remove(name);
                }
              }
            }
          }
         
          formStatisticsBean.getFormStatisticsOptionBeanList().addAll(defaultOptionBeans.values());
         
          produceResult(formStatisticsBean);
        }
        else if(type.equals("average"))
        {
View Full Code Here

TOP

Related Classes of org.infoglue.deliver.applications.databeans.FormStatisticsBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.