Exemplo n.º 1
0
  public List<StatisticReportRecordVO> getStatisticReportRecord(
      String reportDefinitionId, String objectId, AccountUserVO accountUser) throws Exception {
    if (reportDefinitionId == null || objectId == null) {
      throw new IllegalArgumentException("Arguments are null!");
    }

    /*
     * Properties repDefProps = new Properties(); URL url =
     * SimpleStatistics.class.getClassLoader().getResource(REPORTDEFINITION_PROPERTIES_FILE); if
     * (url == null) { throw new FileNotFoundException(REPORTDEFINITION_PROPERTIES_FILE); }
     * repDefProps.load(new FileInputStream(new File(url.toURI())));
     */

    // String repDefId = repDefProps.getProperty(reportDefinitionType);

    // EntityManager em = emf.createEntityManager();
    // String repDefId =
    // ReportDefinitionStorage.getInstance().getReportDefinitionMap().get(reportDefinitionType);

    if (reportDefinitionId == null)
      throw new Exception("Reportdefinition does not exist: " + reportDefinitionId);

    StatisticReportParamsVO repParams = new StatisticReportParamsVO();
    repParams.setReportDefinitionId(reportDefinitionId);

    StatisticReportRecordParamVO param =
        new StatisticReportRecordParamVO(
            "object_id", new StatisticReportRecordStringParamValueVO(objectId));
    repParams.getParamList().add(param);

    String xmlParams = xmlTransforming.transformToStatisticReportParameters(repParams);

    ReportHandler repHandler;
    if (accountUser == null || accountUser.getHandle() == null)
      repHandler = ServiceLocator.getReportHandler();
    else repHandler = ServiceLocator.getReportHandler(accountUser.getHandle());

    String xmlReport = repHandler.retrieve(xmlParams);

    List<StatisticReportRecordVO> reportRecordList =
        xmlTransforming.transformToStatisticReportRecordList(xmlReport);

    return reportRecordList;
  }
Exemplo n.º 2
0
 private List<StatisticReportDefinitionVO> retrieveReportDefinitionListFromFile()
     throws Exception {
   String repDefListXML =
       ResourceUtil.getResourceAsString(
           REPORTDEFINITION_FILE, SimpleStatistics.class.getClassLoader());
   String[] repDefs = repDefListXML.split("\n");
   List<StatisticReportDefinitionVO> repDefVOList = new ArrayList<StatisticReportDefinitionVO>();
   for (String repDefXml : repDefs) {
     repDefVOList.add(xmlTransforming.transformToStatisticReportDefinition(repDefXml));
   }
   return repDefVOList;
 }
Exemplo n.º 3
0
  /** {@inheritDoc} */
  public void initReportDefinitionsInFramework() {

    try {

      logger.info("Initializing statistic aggregation definitions in framework database");
      AggregationDefinitionHandler adh =
          ServiceLocator.getAggregationDefinitionHandler(AdminHelper.getAdminUserHandle());
      String srwResponseXml = adh.retrieveAggregationDefinitions(new HashMap<String, String[]>());
      List<AggregationDefinitionVO> aggList =
          xmlTransforming.transformToStatisticAggregationDefinitionList(srwResponseXml);

      String aggregationTableName = null;

      for (AggregationDefinitionVO aggDef : aggList) {
        if (aggDef.getName().equals("pubman item statistics without version")) {
          logger.info(
              "Pubman statistic aggregation definition already exists with id "
                  + aggDef.getObjectId());

          aggregationTableName = aggDef.getAggregationTables().get(0).getName();
          logger.info("Pubman aggregated table name:" + aggregationTableName);
          break;
        }
      }

      // No aggregation found, create one
      if (aggregationTableName == null) {
        logger.info("No pubman aggregation definition found, creating one");

        String aggregationDefinitionXml =
            ResourceUtil.getResourceAsString(
                "pubman_object_stats_aggregation.xml", SimpleStatistics.class.getClassLoader());
        String createdAggDefXml = adh.create(aggregationDefinitionXml);
        AggregationDefinitionVO aggCreated =
            xmlTransforming.transformToStatisticAggregationDefinition(createdAggDefXml);
        logger.info("Pubman aggregation definition created with id " + aggCreated.getObjectId());
        aggregationTableName = aggCreated.getAggregationTables().get(0).getName();
        logger.info("Pubman aggregated table name:" + aggregationTableName);
      }

      logger.info("Initializing statistical report definitions in framework database");

      ReportDefinitionHandler repDefHandler =
          ServiceLocator.getReportDefinitionHandler(AdminHelper.getAdminUserHandle());
      // EntityManager em = emf.createEntityManager();
      String repDefFrameworkListXML =
          repDefHandler.retrieveReportDefinitions(new HashMap<String, String[]>());
      List<StatisticReportDefinitionVO> repDefFrameworkList =
          xmlTransforming.transformToStatisticReportDefinitionList(repDefFrameworkListXML);

      List<StatisticReportDefinitionVO> repDefFileList = retrieveReportDefinitionListFromFile();

      // Creating a Hash Map with ReportDefinitions from Framework and sql as key
      HashMap<String, StatisticReportDefinitionVO> repDefFrameworkMap =
          new HashMap<String, StatisticReportDefinitionVO>();

      for (StatisticReportDefinitionVO repDef : repDefFrameworkList) {
        repDefFrameworkMap.put(repDef.getSql(), repDef);
      }

      for (StatisticReportDefinitionVO repDefFile : repDefFileList) {
        String sql = repDefFile.getSql().replaceAll("pubman_object_stats", aggregationTableName);
        StatisticReportDefinitionVO repDefFW = repDefFrameworkMap.get(sql);
        String repDefObjectId;

        // Report Definition already existing
        if (repDefFW != null) {
          // set Property
          // Map<String, String> reportDefMap =
          // ReportDefinitionStorage.getInstance().getReportDefinitionMap();
          // reportDefMap.put(repDefFW.getSql(), repDefFW.getObjectId());
          repDefObjectId = repDefFW.getObjectId();
          logger.info(
              "Report Definition already  existing: "
                  + repDefFW.getObjectId()
                  + " --- "
                  + repDefFW.getSql());

        }
        // Report Definition does not exist yet
        else {
          // create and set
          String repDefFileXML =
              xmlTransforming
                  .transformToStatisticReportDefinition(repDefFile)
                  .replaceAll("pubman_object_stats", aggregationTableName);
          ;
          String repDefFWXMLNew = repDefHandler.create(repDefFileXML);
          StatisticReportDefinitionVO repDefFWNew =
              xmlTransforming.transformToStatisticReportDefinition(repDefFWXMLNew);
          // ReportDefinitionStorage.getInstance().getReportDefinitionMap().put(repDefFWNew.getSql(),
          // repDefFWNew.getObjectId());
          repDefObjectId = repDefFWNew.getObjectId();
          logger.info(
              "Created new report definition and added to Map: "
                  + repDefFWNew.getObjectId()
                  + " --- "
                  + repDefFWNew.getSql());
        }

        if (repDefFile.getName().equals("Item retrievals, all users")) {
          REPORTDEFINITION_NUMBER_OF_ITEM_RETRIEVALS_ALL_USERS = repDefObjectId;
        } else if (repDefFile.getName().equals("File downloads per Item, all users")) {
          REPORTDEFINITION_FILE_DOWNLOADS_PER_ITEM_ALL_USERS = repDefObjectId;
        } else if (repDefFile.getName().equals("File downloads, all users")) {
          REPORTDEFINITION_FILE_DOWNLOADS_PER_FILE_ALL_USERS = repDefObjectId;
        } else if (repDefFile.getName().equals("Item retrievals, anonymous users")) {
          REPORTDEFINITION_NUMBER_OF_ITEM_RETRIEVALS_ANONYMOUS = repDefObjectId;
        } else if (repDefFile.getName().equals("File downloads per Item, anonymous users")) {
          REPORTDEFINITION_FILE_DOWNLOADS_PER_ITEM_ANONYMOUS = repDefObjectId;
        } else if (repDefFile.getName().equals("File downloads, anonymous users")) {
          REPORTDEFINITION_FILE_DOWNLOADS_PER_FILE_ANONYMOUS = repDefObjectId;
        }
      }

      /*
       * logger.info( ReportDefinitionStorage.getInstance().getReportDefinitionMap().size()
       * +" Statistic report definitions are initialized! ");
       */

    } catch (Exception e) {
      logger.error(
          "Statistic report definitions could not be initialized! Statistic system may not work properly. ",
          e);
    }
  }