Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
Responding to review from @jamiesnape on #115.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpatrick committed Aug 4, 2015
1 parent 54b5425 commit 695e0fc
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 51 deletions.
2 changes: 1 addition & 1 deletion modules/tracker/controllers/components/ApiComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public function scalarAdd($args)
*/
public function resultsUploadJson($args)
{
/** Change this to add a submission Id or UUID */
/** Change this to add a submission id or uuid. */

$submissionId = -1;
/** @var CommunityModel $communityModel */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Tracker_ApiscalarComponent extends AppComponent
*
* @path /tracker/scalar/{id}
* @http DELETE
* @param id
* @param int id the id of the scalar to delete
*
* @param array $args parameters
* @throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function get($args)
}

/**
* TODO.
* @todo
*
* @path /tracker/submission
* @http GET
Expand Down Expand Up @@ -155,15 +155,17 @@ public function post($args)
$this->moduleName);

if (!isset($args['uuid'])) {
$args['uuid'] = uniqid();
/** @var UuidComponent $uuidComponent */
$uuidComponent = MidasLoader::loadComponent('UuidComponent');
$args['uuid'] = $uuidComponent->generate();
}

/** @var Tracker_SubmissionDao $submissionDao */
$submissionDao = $submissionModel->initDao('Submission',
$args,
$this->moduleName);

// Catch violation of the unique constraint
// Catch violation of the unique constraint.
try {
$submissionModel->save($submissionDao);
} catch (Zend_Db_Statement_Exception $e) {
Expand Down Expand Up @@ -259,7 +261,7 @@ protected function _checkUser($args, $msg)
/** @var ApihelperComponent $apihelperComponent */
$apihelperComponent = MidasLoader::loadComponent('Apihelper');

if (!$apihelperComponent->getUser($args)) {
if ($apihelperComponent->getUser($args) === false) {
throw new Exception($msg, MIDAS_INVALID_POLICY);
}
}
Expand Down
25 changes: 14 additions & 11 deletions modules/tracker/models/base/SubmissionModelBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,40 +52,43 @@ public function __construct()

/**
* Create a submission.
* @param $producerDao the producer to which the submission was submitted
* @param $uuid the uuid of the submission
*
* @param Tracker_ProducerDao $producerDao the producer to which the submission was submitted
* @param string $uuid the uuid of the submission
* @param string $name the name of the submission (defaults to '')
* @return Tracker_SubmissionDao
*/
public abstract function createSubmission($producerDao, $uuid, $name = '');

/**
* Get a submission from its uuid.
* @param $uuid the uuid of the submission
* @return Tracker_SubmissionDao
*
* @param string $uuid the uuid of the submission
* @return Tracker_SubmissionDao submission DAO
*/
public abstract function getSubmission($uuid);

/**
* Return the submission with the given UUID (creating one if necessary).
* Return the submission with the given uuid (creating one if necessary).
*
* @param Tracker_ProducerDao $producerDao the producer
* @param Tracker_ProducerDao $producerDao producer DAO
* @param string $uuid the uuid of the submission
* @return Tracker_SubmissionDao
* @return Tracker_SubmissionDao submission DAO
*/
public abstract function getOrCreateSubmission($producerDao, $uuid);

/**
* Get submissions associated with a given producer.
* @param Tracker_ProducerDao $producerDao the producer
* @return array(Tracker_SubmissionDao)
*
* @param Tracker_ProducerDao $producerDao producer DAO
* @return array submission DAOs
*/
public abstract function getSubmissionsByProducer($producerDao);

/**
* Get the scalars associated with a submission.
* @param $submissionDao the submission
* @return array(Tracker_SubmissionDao)
* @param Tracker_SubmissionDao $submissionDao submission DAO
* @return array submission DAOs
*/
public abstract function getScalars($submissionDao);
}
3 changes: 2 additions & 1 deletion modules/tracker/models/dao/SubmissionDao.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
* @method string getName()
* @method void setName(string $name)
* @method string getUuid()
* @method array getScalarss()
* @method string setUuid(string $uuid)
* @method array getScalars()
* @method void setScalars(array $scalarDaos)
* @package Modules\Tracker\DAO
*/
Expand Down
28 changes: 17 additions & 11 deletions modules/tracker/models/pdo/SubmissionModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
*/
class Tracker_SubmissionModel extends Tracker_SubmissionModelBase
{

/**
* Create a submission.
* @param $producerDao the producer to which the submission was submitted
* @param $uuid the uuid of the submission
*
* @param Tracker_ProducerDao $producerDao the producer to which the submission was submitted
* @param string $uuid the uuid of the submission
* @param string $name the name of the submission (defaults to '')
* @return Tracker_SubmissionDao
* @return void
*/
public function createSubmission($producerDao, $uuid, $name = '')
{
Expand All @@ -46,7 +46,7 @@ public function createSubmission($producerDao, $uuid, $name = '')
}

/**
* Return the scalars for a given submission
* Return the scalars for a given submission.
*
* @param Tracker_SubmissionDao $submissionDao submission DAO
* @return array scalar DAOs
Expand All @@ -70,8 +70,9 @@ public function getScalars($submissionDao)

/**
* Get submissions associated with a given producer.
* @param Tracker_ProducerDao $producerDao the producer
* @return array(Tracker_SubmissionDao)
*
* @param Tracker_ProducerDao $producerDao producer DAO
* @return array submission DAOs
*/
public function getSubmissionsByProducer($producerDao)
{
Expand All @@ -81,6 +82,7 @@ public function getSubmissionsByProducer($producerDao)
$submissionDaos = array();

$rows = $this->database->fetchAll($sql);
/** @var Zend_Db_Table_Row_Abstract $row */
foreach ($rows as $row) {
$submissionDaos[] = $this->initDao('Submission', $row, $this->moduleName);
}
Expand All @@ -92,18 +94,19 @@ public function getSubmissionsByProducer($producerDao)
* Return the submission with the given UUID.
*
* @param string $uuid the uuid of the submission
* @return submission dao
* @return false|Tracker_SubmissionDao submission Dao
*/
public function getSubmission($uuid)
{
$sql = $this->database->select()->setIntegrityCheck(false)
->from('tracker_submission')
->where('uuid = ?', $uuid);
$res = $this->database->fetchAll($sql);
if ($res->count() == 0) {
return null;
if ($res->count() === 0) {
return false;
} else {
$submissionDao = $this->initDao('Submission', $res[0], $this->moduleName);

return $submissionDao;
}
}
Expand All @@ -122,19 +125,22 @@ public function getOrCreateSubmission($producerDao, $uuid)
->where('uuid = ?', $uuid)
->where('producer_id = ?', $producerDao->getKey());
$res = $this->database->fetchAll($sql);
if (count($res) == 1) {
if (count($res) === 1) {
$submissionDao = $this->initDao('Submission', $res[0],
$this->moduleName);
} else {
$doc = array();
$doc['uuid'] = $uuid;
$doc['producer_id'] = $producerDao->getKey();

/** @var Tracker_SubmissionDao $submissionDao */
$submissionDao = $this->initDao('Submission', $doc,
$this->moduleName);
$this->save($submissionDao);
$submissionId = $submissionDao->getSubmissionId();
$submissionDao = $this->load($submissionId);
}

return $submissionDao;
}

Expand Down
33 changes: 14 additions & 19 deletions modules/tracker/tests/controllers/ApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

require_once BASE_PATH.'/modules/api/tests/controllers/CallMethodsTestCase.php';

/** Api Test for tracker module */
/** API test for tracker module. */
class Tracker_ApiControllerTest extends Api_CallMethodsTestCase
{
public $moduleName = 'tracker';
Expand All @@ -37,10 +37,15 @@ public function setUp()
ControllerTestCase::setUp();
}

/** Test the AJAX get free space call. */
/**
* Test uploading a scalar with a submission attached via uuid.
*
* @throws Zend_Exception
*/
public function testUploadScalarWithSubmission()
{
$uuid = uniqid();
$uuidComponent = MidasLoader::loadComponent('Uuid');
$uuid = $uuidComponent->generate();

$token = $this->_loginAsAdministrator();

Expand All @@ -62,27 +67,16 @@ public function testUploadScalarWithSubmission()
$this->assertEquals($curOutput->value, $scalarDao->getValue());
$this->assertEquals($submissionDao->getKey(), $scalarDao->getSubmissionId());
}

}

/**
* Verify the scalar value is as expected
* @param $testDao the dao returned from the submission uuid query
* @param $truthDao the dao returned from the api call
*/
protected function _verifyScalar($testDao, $truthDao)
{
$this->assertEquals($testDao->getMetricName(), $truthDao->metric_name);
}

/**
* Helper function to submit scalars.
*
* @param $token the api token
* @param $uuid the uuid of the submission
* @param $metric the metric name of the trend
* @param $value the scalar value
* @return response object from the API
* @param string $token the api token
* @param string $uuid the uuid of the submission
* @param string $metric the metric name of the trend
* @param float $value the scalar value
* @return mixed response object from the API
*/
protected function _submitScalar($token, $uuid, $metric, $value)
{
Expand All @@ -96,6 +90,7 @@ protected function _submitScalar($token, $uuid, $metric, $value)
$this->params['producerRevision'] = 'deadbeef';
$this->params['submitTime'] = 'now';
$this->params['submissionUuid'] = $uuid;

return $this->_callJsonApi()->data;
}
}
6 changes: 3 additions & 3 deletions modules/tracker/tests/databaseDataset/default.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<tracker_producer producer_id="1" community_id="1" display_name="Test Producer" repository="http://test.com"
executable_name="test.exe" description="" revision_url="https://github.com/test/test/" />
<tracker_producer producer_id="1" community_id="1" display_name="Test Producer" repository="https://example.com"
executable_name="test.exe" description="" revision_url="https:/example.net" />
<tracker_trend trend_id="1" producer_id="1" metric_name="metric_0" display_name="Metric #0" config_item_id="1000"
test_dataset_id="1001" truth_dataset_id="1002" unit="mm" />
<tracker_trend trend_id="2" producer_id="1" metric_name="metric_1" display_name="Metric #1" config_item_id="1000"
test_dataset_id="1001" truth_dataset_id="1002" unit="mm" />
<tracker_trend trend_id="3" producer_id="1" metric_name="metric_2" display_name="Metric #2" config_item_id="1000"
test_dataset_id="1001" truth_dataset_id="1002" unit="mm" />
</dataset>
</dataset>

0 comments on commit 695e0fc

Please sign in to comment.