private void logPubItemAction( PubItemVO pubItem, String ip, String userAgent, ItemAction action, String sessionId, boolean loggedIn, String referer, List<StatisticReportRecordParamVO> additionalParams) throws Exception { List<StatisticReportRecordParamVO> paramList = new ArrayList<StatisticReportRecordParamVO>(); /* * List<CreatorVO> creatorList = pubItem.getMetadata().getCreators(); String persAffIds = ""; * for(CreatorVO creator : creatorList) { if (creator.getPerson()!=null && * creator.getPerson().getIdentifier()!=null && * creator.getPerson().getIdentifier().getId()!=null && * !creator.getPerson().getIdentifier().getId().equals("")) { persAffIds += * creator.getPerson().getIdentifier().getId() + ","; } } StatisticReportRecordParamVO * persAffParam = new StatisticReportRecordParamVO(); persAffParam.setName("persAffId"); * persAffParam.setParamValue(new StatisticReportRecordStringParamValueVO(persAffIds)); * paramList.add(persAffParam); */ StatisticReportRecordParamVO oaParam = new StatisticReportRecordParamVO(); oaParam.setName("hasOAComponent"); oaParam.setParamValue( new StatisticReportRecordStringParamValueVO(String.valueOf(getHasOAComponent(pubItem)))); paramList.add(oaParam); String authorIds = "{"; String orgIds = "{"; List<CreatorVO> creatorList = pubItem.getMetadata().getCreators(); for (CreatorVO creator : creatorList) { if (creator.getPerson() != null && creator.getPerson().getIdentifier() != null && creator.getPerson().getIdentifier().getId() != null && !creator.getPerson().getIdentifier().getId().equals("")) { // sl.logAuthorAction(sessionId, ip, creator.getPerson().getIdentifier().getId(), loggedIn, // referer, "pubman", null, AdminHelper.getAdminUserHandle()); authorIds += creator.getPerson().getIdentifier().getId() + ","; /* * StatisticReportRecordParamVO authorIdsParam = new StatisticReportRecordParamVO(); * authorIdsParam.setName("authorId"); authorIdsParam.setParamValue(new * StatisticReportRecordStringParamValueVO(creator.getPerson().getIdentifier().getId())); * paramList.add(authorIdsParam); */ } /* * if(creator.getPerson()!=null && creator.getPerson().getOrganizationsSize()>0) { * for(OrganizationVO org : creator.getPerson().getOrganizations()) { if(org.getIdentifier()!= * null && !org.getIdentifier().equals("")) { //sl.logOrgAction(sessionId, ip, * org.getIdentifier(), loggedIn, referer, "pubman", null, AdminHelper.getAdminUserHandle()); * orgIds += org.getIdentifier() + ","; * * // StatisticReportRecordParamVO orgIdsParam = new StatisticReportRecordParamVO(); // * orgIdsParam.setName("orgId"); // orgIdsParam.setParamValue(new * StatisticReportRecordStringParamValueVO(org.getIdentifier())); // * paramList.add(orgIdsParam); * * } } } */ if (creator.getOrganization() != null && creator.getOrganization().getIdentifier() != null && !creator.getOrganization().getIdentifier().equals("")) { // sl.logOrgAction(sessionId, ip, creator.getOrganization().getIdentifier(), loggedIn, // referer, "pubman", null, AdminHelper.getAdminUserHandle()); orgIds += creator.getOrganization().getIdentifier() + ","; /* * StatisticReportRecordParamVO orgIdsParam = new StatisticReportRecordParamVO(); * orgIdsParam.setName("orgId"); orgIdsParam.setParamValue(new * StatisticReportRecordStringParamValueVO(creator.getOrganization().getIdentifier())); * paramList.add(orgIdsParam); */ } } for (OrganizationVO org : getAffiliatedOrganizations(pubItem)) { if (org.getIdentifier() != null && !org.getIdentifier().equals("")) { orgIds += org.getIdentifier() + ","; } } authorIds += "}"; orgIds += "}"; StatisticReportRecordParamVO authorIdsParam = new StatisticReportRecordParamVO(); authorIdsParam.setName("authorIds"); authorIdsParam.setParamValue(new StatisticReportRecordStringParamValueVO(authorIds)); paramList.add(authorIdsParam); StatisticReportRecordParamVO orgIdsParam = new StatisticReportRecordParamVO(); orgIdsParam.setName("orgIds"); orgIdsParam.setParamValue(new StatisticReportRecordStringParamValueVO(orgIds)); paramList.add(orgIdsParam); if (additionalParams != null) { paramList.addAll(additionalParams); } // InitialContext ic = new InitialContext(); // StatisticLogger sl = (StatisticLogger) ic.lookup(StatisticLogger.SERVICE_NAME); statisticLogger.logItemAction( sessionId, ip, userAgent, new PubItemVO(pubItem), action, loggedIn, referer, "pubman", paramList, AdminHelper.getAdminUserHandle()); }
/** {@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); } }