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

Commit 695e0fc

Browse files
committed
Responding to review from @jamiesnape on #115.
1 parent 54b5425 commit 695e0fc

File tree

8 files changed

+58
-51
lines changed

8 files changed

+58
-51
lines changed

modules/tracker/controllers/components/ApiComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ public function scalarAdd($args)
349349
*/
350350
public function resultsUploadJson($args)
351351
{
352-
/** Change this to add a submission Id or UUID */
352+
/** Change this to add a submission id or uuid. */
353353

354354
$submissionId = -1;
355355
/** @var CommunityModel $communityModel */

modules/tracker/controllers/components/ApiscalarComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Tracker_ApiscalarComponent extends AppComponent
2929
*
3030
* @path /tracker/scalar/{id}
3131
* @http DELETE
32-
* @param id
32+
* @param int id the id of the scalar to delete
3333
*
3434
* @param array $args parameters
3535
* @throws Exception

modules/tracker/controllers/components/ApisubmissionComponent.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function get($args)
104104
}
105105

106106
/**
107-
* TODO.
107+
* @todo
108108
*
109109
* @path /tracker/submission
110110
* @http GET
@@ -155,15 +155,17 @@ public function post($args)
155155
$this->moduleName);
156156

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

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

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

262-
if (!$apihelperComponent->getUser($args)) {
264+
if ($apihelperComponent->getUser($args) === false) {
263265
throw new Exception($msg, MIDAS_INVALID_POLICY);
264266
}
265267
}

modules/tracker/models/base/SubmissionModelBase.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,40 +52,43 @@ public function __construct()
5252

5353
/**
5454
* Create a submission.
55-
* @param $producerDao the producer to which the submission was submitted
56-
* @param $uuid the uuid of the submission
55+
*
56+
* @param Tracker_ProducerDao $producerDao the producer to which the submission was submitted
57+
* @param string $uuid the uuid of the submission
5758
* @param string $name the name of the submission (defaults to '')
5859
* @return Tracker_SubmissionDao
5960
*/
6061
public abstract function createSubmission($producerDao, $uuid, $name = '');
6162

6263
/**
6364
* Get a submission from its uuid.
64-
* @param $uuid the uuid of the submission
65-
* @return Tracker_SubmissionDao
65+
*
66+
* @param string $uuid the uuid of the submission
67+
* @return Tracker_SubmissionDao submission DAO
6668
*/
6769
public abstract function getSubmission($uuid);
6870

6971
/**
70-
* Return the submission with the given UUID (creating one if necessary).
72+
* Return the submission with the given uuid (creating one if necessary).
7173
*
72-
* @param Tracker_ProducerDao $producerDao the producer
74+
* @param Tracker_ProducerDao $producerDao producer DAO
7375
* @param string $uuid the uuid of the submission
74-
* @return Tracker_SubmissionDao
76+
* @return Tracker_SubmissionDao submission DAO
7577
*/
7678
public abstract function getOrCreateSubmission($producerDao, $uuid);
7779

7880
/**
7981
* Get submissions associated with a given producer.
80-
* @param Tracker_ProducerDao $producerDao the producer
81-
* @return array(Tracker_SubmissionDao)
82+
*
83+
* @param Tracker_ProducerDao $producerDao producer DAO
84+
* @return array submission DAOs
8285
*/
8386
public abstract function getSubmissionsByProducer($producerDao);
8487

8588
/**
8689
* Get the scalars associated with a submission.
87-
* @param $submissionDao the submission
88-
* @return array(Tracker_SubmissionDao)
90+
* @param Tracker_SubmissionDao $submissionDao submission DAO
91+
* @return array submission DAOs
8992
*/
9093
public abstract function getScalars($submissionDao);
9194
}

modules/tracker/models/dao/SubmissionDao.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
* @method string getName()
2929
* @method void setName(string $name)
3030
* @method string getUuid()
31-
* @method array getScalarss()
31+
* @method string setUuid(string $uuid)
32+
* @method array getScalars()
3233
* @method void setScalars(array $scalarDaos)
3334
* @package Modules\Tracker\DAO
3435
*/

modules/tracker/models/pdo/SubmissionModel.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
*/
2828
class Tracker_SubmissionModel extends Tracker_SubmissionModelBase
2929
{
30-
3130
/**
3231
* Create a submission.
33-
* @param $producerDao the producer to which the submission was submitted
34-
* @param $uuid the uuid of the submission
32+
*
33+
* @param Tracker_ProducerDao $producerDao the producer to which the submission was submitted
34+
* @param string $uuid the uuid of the submission
3535
* @param string $name the name of the submission (defaults to '')
36-
* @return Tracker_SubmissionDao
36+
* @return void
3737
*/
3838
public function createSubmission($producerDao, $uuid, $name = '')
3939
{
@@ -46,7 +46,7 @@ public function createSubmission($producerDao, $uuid, $name = '')
4646
}
4747

4848
/**
49-
* Return the scalars for a given submission
49+
* Return the scalars for a given submission.
5050
*
5151
* @param Tracker_SubmissionDao $submissionDao submission DAO
5252
* @return array scalar DAOs
@@ -70,8 +70,9 @@ public function getScalars($submissionDao)
7070

7171
/**
7272
* Get submissions associated with a given producer.
73-
* @param Tracker_ProducerDao $producerDao the producer
74-
* @return array(Tracker_SubmissionDao)
73+
*
74+
* @param Tracker_ProducerDao $producerDao producer DAO
75+
* @return array submission DAOs
7576
*/
7677
public function getSubmissionsByProducer($producerDao)
7778
{
@@ -81,6 +82,7 @@ public function getSubmissionsByProducer($producerDao)
8182
$submissionDaos = array();
8283

8384
$rows = $this->database->fetchAll($sql);
85+
/** @var Zend_Db_Table_Row_Abstract $row */
8486
foreach ($rows as $row) {
8587
$submissionDaos[] = $this->initDao('Submission', $row, $this->moduleName);
8688
}
@@ -92,18 +94,19 @@ public function getSubmissionsByProducer($producerDao)
9294
* Return the submission with the given UUID.
9395
*
9496
* @param string $uuid the uuid of the submission
95-
* @return submission dao
97+
* @return false|Tracker_SubmissionDao submission Dao
9698
*/
9799
public function getSubmission($uuid)
98100
{
99101
$sql = $this->database->select()->setIntegrityCheck(false)
100102
->from('tracker_submission')
101103
->where('uuid = ?', $uuid);
102104
$res = $this->database->fetchAll($sql);
103-
if ($res->count() == 0) {
104-
return null;
105+
if ($res->count() === 0) {
106+
return false;
105107
} else {
106108
$submissionDao = $this->initDao('Submission', $res[0], $this->moduleName);
109+
107110
return $submissionDao;
108111
}
109112
}
@@ -122,19 +125,22 @@ public function getOrCreateSubmission($producerDao, $uuid)
122125
->where('uuid = ?', $uuid)
123126
->where('producer_id = ?', $producerDao->getKey());
124127
$res = $this->database->fetchAll($sql);
125-
if (count($res) == 1) {
128+
if (count($res) === 1) {
126129
$submissionDao = $this->initDao('Submission', $res[0],
127130
$this->moduleName);
128131
} else {
129132
$doc = array();
130133
$doc['uuid'] = $uuid;
131134
$doc['producer_id'] = $producerDao->getKey();
135+
136+
/** @var Tracker_SubmissionDao $submissionDao */
132137
$submissionDao = $this->initDao('Submission', $doc,
133138
$this->moduleName);
134139
$this->save($submissionDao);
135140
$submissionId = $submissionDao->getSubmissionId();
136141
$submissionDao = $this->load($submissionId);
137142
}
143+
138144
return $submissionDao;
139145
}
140146

modules/tracker/tests/controllers/ApiControllerTest.php

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

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

23-
/** Api Test for tracker module */
23+
/** API test for tracker module. */
2424
class Tracker_ApiControllerTest extends Api_CallMethodsTestCase
2525
{
2626
public $moduleName = 'tracker';
@@ -37,10 +37,15 @@ public function setUp()
3737
ControllerTestCase::setUp();
3838
}
3939

40-
/** Test the AJAX get free space call. */
40+
/**
41+
* Test uploading a scalar with a submission attached via uuid.
42+
*
43+
* @throws Zend_Exception
44+
*/
4145
public function testUploadScalarWithSubmission()
4246
{
43-
$uuid = uniqid();
47+
$uuidComponent = MidasLoader::loadComponent('Uuid');
48+
$uuid = $uuidComponent->generate();
4449

4550
$token = $this->_loginAsAdministrator();
4651

@@ -62,27 +67,16 @@ public function testUploadScalarWithSubmission()
6267
$this->assertEquals($curOutput->value, $scalarDao->getValue());
6368
$this->assertEquals($submissionDao->getKey(), $scalarDao->getSubmissionId());
6469
}
65-
66-
}
67-
68-
/**
69-
* Verify the scalar value is as expected
70-
* @param $testDao the dao returned from the submission uuid query
71-
* @param $truthDao the dao returned from the api call
72-
*/
73-
protected function _verifyScalar($testDao, $truthDao)
74-
{
75-
$this->assertEquals($testDao->getMetricName(), $truthDao->metric_name);
7670
}
7771

7872
/**
7973
* Helper function to submit scalars.
8074
*
81-
* @param $token the api token
82-
* @param $uuid the uuid of the submission
83-
* @param $metric the metric name of the trend
84-
* @param $value the scalar value
85-
* @return response object from the API
75+
* @param string $token the api token
76+
* @param string $uuid the uuid of the submission
77+
* @param string $metric the metric name of the trend
78+
* @param float $value the scalar value
79+
* @return mixed response object from the API
8680
*/
8781
protected function _submitScalar($token, $uuid, $metric, $value)
8882
{
@@ -96,6 +90,7 @@ protected function _submitScalar($token, $uuid, $metric, $value)
9690
$this->params['producerRevision'] = 'deadbeef';
9791
$this->params['submitTime'] = 'now';
9892
$this->params['submissionUuid'] = $uuid;
93+
9994
return $this->_callJsonApi()->data;
10095
}
10196
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<dataset>
3-
<tracker_producer producer_id="1" community_id="1" display_name="Test Producer" repository="http://test.com"
4-
executable_name="test.exe" description="" revision_url="http://github.com/test/test/" />
3+
<tracker_producer producer_id="1" community_id="1" display_name="Test Producer" repository="https://example.com"
4+
executable_name="test.exe" description="" revision_url="https:/example.net" />
55
<tracker_trend trend_id="1" producer_id="1" metric_name="metric_0" display_name="Metric #0" config_item_id="1000"
66
test_dataset_id="1001" truth_dataset_id="1002" unit="mm" />
77
<tracker_trend trend_id="2" producer_id="1" metric_name="metric_1" display_name="Metric #1" config_item_id="1000"
88
test_dataset_id="1001" truth_dataset_id="1002" unit="mm" />
99
<tracker_trend trend_id="3" producer_id="1" metric_name="metric_2" display_name="Metric #2" config_item_id="1000"
1010
test_dataset_id="1001" truth_dataset_id="1002" unit="mm" />
11-
</dataset>
11+
</dataset>

0 commit comments

Comments
 (0)