Skip to content

Commit

Permalink
*8253* Introduced SciELO plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
beghelli committed Mar 10, 2014
1 parent bf6f7d3 commit cee9f77
Show file tree
Hide file tree
Showing 6 changed files with 312 additions and 0 deletions.
60 changes: 60 additions & 0 deletions plugins/generic/scielo/SciELOPlugin.inc.php
@@ -0,0 +1,60 @@
<?php

/**
* @file plugins/generic/scielo/SciELOPlugin.inc.php
*
* Copyright (c) 2003-2013 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class SciELOPlugin
* @ingroup plugins_generic_scielo
*
* @brief SciELO usage statistics.
*/


import('lib.pkp.classes.plugins.GenericPlugin');

class SciELOPlugin extends GenericPlugin {

//
// Implement methods from PKPPlugin.
//
/**
* @see LazyLoadPlugin::register()
*/
function register($category, $path) {
$success = parent::register($category, $path);
return $success;
}

/**
* @see PKPPlugin::getDisplayName()
*/
function getDisplayName() {
return __('plugins.generic.scielo.displayName');
}

/**
* @see PKPPlugin::getDescription()
*/
function getDescription() {
return __('plugins.generic.scielo.description');
}

/**
* @see PKPPlugin::isSitePlugin()
*/
function isSitePlugin() {
return true;
}

/**
* @see PKPPlugin::getInstallSitePluginSettingsFile()
*/
function getInstallSitePluginSettingsFile() {
return $this->getPluginPath() . '/settings.xml';
}
}

?>
166 changes: 166 additions & 0 deletions plugins/generic/scielo/SciELOStatsSender.inc.php
@@ -0,0 +1,166 @@
<?php

/**
* @file plugins/generic/scielo/SciELOStatsSender.php
*
* Copyright (c) 2003-2012 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class SciELOStatsSender
* @ingroup plugins_generic_scielo
*
* @brief Scheduled task to send statistics to SciELO ratchet tool.
* @see http://docs.scielo.org/projects/ratchet/en/latest/api.html
*/

import('lib.pkp.classes.scheduledTask.ScheduledTask');
import('lib.pkp.classes.webservice.JSONWebService');

class SciELOStatsSender extends ScheduledTask {

/**
* Constructor.
* @param $argv array task arguments
*/
function SciELOStatsSender($args) {
parent::ScheduledTask($args);

}

/**
* @see FileLoader::execute()
*/
function execute() {
$plugin = PluginRegistry::getPlugin('generic', 'SciELOPlugin');
$unregisteredSettingName = 'scieloUnregisteredStats';

// Get journals with stats to be sent.
$journalDao = DAORegistry::getDAO('JournalDAO'); /* @var $journalDao JournalDAO */
$journalSettingsDao = DAORegistry::getDAO('JournalSettingsDAO'); /* @var $journalSettingsDao JournalSettingsDAO */
$journalFactory = $journalDao->getBySetting($unregisteredSettingName, true);

// Send journal stats.
while ($journal = $journalFactory->next()) {
if (!$this->_claimObject($journalSettingsDao, $journalId)) continue;
$lastStatsSendingDate = $journalSettingsDao->getSetting($journalId, 'scieloLastStatsSendingDate');

if (!$this->_isMigratedStatsSent($journalSettingsDao, $journalId)) {
$this->_sendMigratedStats($journalSettingsDao, ASSOC_TYPE_JOURNAL, $journal, $lastStatsSendingDate);
}

$metrics = $journal->getMetrics(OJS_METRIC_TYPE_COUNTER);
}


$serverUrl = '200.136.72.14:8860/';
$jsonMessage = json_encode(array(
'code' => '123456',
'journal' => '0034-8910',
'issue' => '0034-891020090004',
'article.y2011.m10.d01' => 100,
'article.y2011.m10.d02' => 100,
'article.y2011.m10.d03' => 100,
'article.y2012.m11.d01' => 10,
'article.y2012.m11.a02' => 10,
'article.y2012.m11.a03' => 10,
'article.y2012.m10.total' => 300,
'article.y2012.m11.total' => 30,
'article.y2012.total' => 330,
'total' => 330,
'bra' => 200,
'mex' => 100,
'arg' => 10,
'col' => 20
));

$serverUrl = $serverUrl . 'api/v1/article/bulk?data=' . $jsonMessage ;
$webServiceRequest = new WebServiceRequest($serverUrl);
$webServiceRequest->setMethod('POST');
$webServiceRequest->setAccept('application/json');
$webServiceRequest->setHeader('Content-Type', 'application/json');

$webService = new WebService();
$webService->call($webServiceRequest);

// Check the reponse status.
if ($webService->getLastResponseStatus() == '200') {
return true;
} else {
return false;
}
}


//
// Private helper methdos.
//
/**
* Tries to claim the passed object id to start the statistics
* send process.
* @param $settingsDao SettingsDAO
* @param $objectId int
* @return boolean Whether or not the claim was successful.
*/
private function _claimObject($settingsDao, $objectId) {
if (!is_a($settingsDao, 'SettingsDAO')) assert(false);

$claimedSettingName = 'scieloObjectClaimed';
if (!$settingsDao->getSetting($objectId, $claimedSettingName)) {
// Claim the object.
$settingsDao->updateSetting($objectId, $claimedSettingName, true);
return true;
} else {
// Already claimed by another instance of this script.
return false;
}
}

/**
* Check if the statistics collected by previous versions of
* OJS and migrated when upgrading were already sent to SciELO.
* @param $settingsDao SettingsDAO
* @param $objectId int
* @return boolean
*/
private function _isMigratedStatsSent($settingsDao, $objectId) {
if (!is_a($settingsDao, 'SettingsDAO')) assert(false);
return $settingsDao->getSetting($objectId, 'scieloMigratedStatsSent');
}

/**
* Send the statistics collected by previous versions of OJS
* and migrated when upgrading to SciELO.
* @param $settingsDao SettingsDAO
* @param $assocType int
* @param $assocObject DataObject
* @param $lastStatsSendingDate timestamp
*/
private function _sendMigratedStats($settingsDao, $assocType, $assocObject, $lastStatsSendingDate) {
if (!is_a($settingsDao, 'SettingsDAO')) assert(false);
switch ($assocType) {
case ASSOC_TYPE_JOURNAL:
// Get the statistics.
$metrics = $assocObject->getMetrics(OJS_METRIC_TYPE_LEGACY_COUNTER, array(STATISTICS_DIMENSION_MONTH));
if($metrics) {
$message = array(
'code' => $assocObject->getId(),
'journal.y2011.m10.d01' => 100,
'article.y2011.m10.d02' => 100,
'article.y2011.m10.d03' => 100,
'article.y2012.m11.d01' => 10,
'article.y2012.m11.a02' => 10,
'article.y2012.m11.a03' => 10,
'article.y2012.m10.total' => 300,
'article.y2012.m11.total' => 30,
'article.y2012.total' => 330,
'total' => 330,
'bra' => 200,
'mex' => 100,
'arg' => 10,
'col' => 20
);
}
}
}
}
?>
21 changes: 21 additions & 0 deletions plugins/generic/scielo/index.php
@@ -0,0 +1,21 @@
<?php

/**
* @defgroup plugins_generic_scielo
*/

/**
* @file plugins/generic/scielo/index.php
*
* Copyright (c) 2003-2013 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @ingroup plugins_generic_scielo
* @brief Wrapper for scielo statistics plugin.
*
*/
require_once('SciELOPlugin.inc.php');

return new SciELOPlugin();

?>
16 changes: 16 additions & 0 deletions plugins/generic/scielo/locale/en_US/locale.xml
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE locale SYSTEM "../../../../../lib/pkp/dtd/locale.dtd">

<!--
* plugins/generic/scielo/locale/en_US/locale.xml
*
* Copyright (c) 2003-2013 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* Localization strings
-->

<locale name="en_US" full_name="U.S. English">
<message key="plugins.generic.scielo.displayName">SciELO statistics</message>
<message key="plugins.generic.scielo.description">Communicate with SciELO server to post and get data objects usage statistics.</message>
</locale>
25 changes: 25 additions & 0 deletions plugins/generic/scielo/scheduledTasks.xml
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
* plugins/generic/usageStats/scheduledTasks.xml
*
* Copyright (c) 2003-2012 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* Usage statistics plugin scheduled tasks registry file.
*
* This file lists all usage statistics plugin scheduled tasks to be executed by the system.
*
* Note that this functionality requires scheduled task support to be enabled.
* The degree of granularity supported for the task frequency depends on the
* frequency the scheduled task script itself is scheduled to run (as
* configured in cron, for example).
-->

<!DOCTYPE scheduled_tasks SYSTEM "../../../lib/pkp/dtd/scheduledTasks.dtd">

<scheduled_tasks>
<task class="plugins.generic.scielo.SciELOStatsSender">
<descr>Send usage statistics data to SciELO database.</descr>
</task>
</scheduled_tasks>
24 changes: 24 additions & 0 deletions plugins/generic/scielo/settings.xml
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plugin_settings SYSTEM "../../../lib/pkp/dtd/pluginSettings.dtd">

<!--
* plugins/generic/scielo/settings.xml
*
* Copyright (c) 2003-2013 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* Default plugin settings.
*
-->

<plugin_settings>
<setting type="bool">
<name>enabled</name>
<value>false</value>
</setting>
<setting type="string">
<name>serverUrl</name>
<value>"http://200.136.72.14:8860/"</value>
</setting>
</plugin_settings>

0 comments on commit cee9f77

Please sign in to comment.