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

Commit 4c964cf

Browse files
author
Charles Ma
committed
ENH: refs #301 XML results format
1 parent 3974ef3 commit 4c964cf

File tree

19 files changed

+668
-142
lines changed

19 files changed

+668
-142
lines changed

core/controllers/components/DateComponent.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,49 @@ static public function ago($timestamp, $only_time = false)
8484
}
8585
return $text;
8686
}
87+
88+
/** format the date (ex: 5 days ago) */
89+
static public function duration($timestamp)
90+
{
91+
if(!is_numeric($timestamp))
92+
{
93+
$timestamp = strtotime($timestamp);
94+
if($timestamp == false)
95+
{
96+
return "";
97+
}
98+
}
99+
$difference = $timestamp;
100+
$periods = array("second", "minute", "hour", "day", "week", "month", "years", "decade");
101+
$periodsFr = array("seconde", "minute", "heure", "jour", "semaine", "mois", "annee", "decades");
102+
$lengths = array("60", "60", "24", "7", "4.35", "12", "10");
103+
for($j = 0; $difference >= $lengths[$j]; $j++)
104+
{
105+
$difference /= $lengths[$j];
106+
}
107+
$difference = round($difference);
108+
if($difference != 1)
109+
{
110+
$periods[$j] .= "s";
111+
if($periodsFr[$j] != 'mois')
112+
{
113+
$periodsFr[$j] .= "s";
114+
}
115+
}
116+
117+
if($periods[$j] == 'second' || $periods[$j] == 'seconds')
118+
{
119+
$difference = $timestamp;
120+
}
121+
122+
if(Zend_Registry::get('configGlobal')->application->lang == 'fr')
123+
{
124+
$text = $difference." ".$periodsFr[$j];
125+
}
126+
else
127+
{
128+
$text = $difference." ".$periods[$j];
129+
}
130+
return $text;
131+
}
87132
} // end class

core/controllers/components/UtilityComponent.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,59 @@
1313
/** Utility componenet */
1414
class UtilityComponent extends AppComponent
1515
{
16+
17+
/**
18+
* The main function for converting to an XML document.
19+
* Pass in a multi dimensional array and this recrusively loops through and builds up an XML document.
20+
*
21+
* @param array $data
22+
* @param string $rootNodeName - what you want the root node to be - defaultsto data.
23+
* @param SimpleXMLElement $xml - should only be used recursively
24+
* @return string XML
25+
*/
26+
public function toXml($data, $rootNodeName = 'data', $xml=null)
27+
{
28+
// turn off compatibility mode as simple xml throws a wobbly if you don't.
29+
if(ini_get('zend.ze1_compatibility_mode') == 1)
30+
{
31+
ini_set ('zend.ze1_compatibility_mode', 0);
32+
}
33+
34+
if ($xml == null)
35+
{
36+
$xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><$rootNodeName />");
37+
}
38+
39+
// loop through the data passed in.
40+
foreach($data as $key => $value)
41+
{
42+
// no numeric keys in our xml please!
43+
if(is_numeric($key))
44+
{
45+
// make string key...
46+
$key = "unknownNode_". (string) $key;
47+
}
48+
49+
// replace anything not alpha numeric
50+
$key = preg_replace('/[^a-z]/i', '', $key);
51+
52+
// if there is another array found recrusively call this function
53+
if(is_array($value))
54+
{
55+
$node = $xml->addChild($key);
56+
// recrusive call.
57+
$this->toXml($value, $rootNodeName, $node);
58+
}
59+
else
60+
{
61+
// add single node.
62+
$value = htmlentities($value);
63+
$xml->addChild($key,$value);
64+
}
65+
}
66+
// pass back as string. or simple xml object if you want!
67+
return $xml->asXML();
68+
}
1669
/** Get all the modules */
1770
public function getAllModules()
1871
{

core/public/js/admin/admin.showlog.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function initLogs()
88
$('.logsLoading').show();
99
$('table#listLogs tr.logSum').remove();
1010
$('table#listLogs tr.logDetail').remove();
11-
$.each(jsonLogs, function(index, value) {
11+
$.each(jsonLogs, function(index, value) {
1212
var html='';
1313
html+='<tr class="logSum">';
1414
html+=' <td>'+value.datetime+'</td>';
@@ -32,10 +32,10 @@ function initLogs()
3232
html+='</tr>';
3333
$('table#listLogs').append(html);
3434
});
35-
35+
3636
$('table#listLogs').show();
3737
$('.logsLoading').hide();
38-
38+
3939
$('table#listLogs tr.logSum').click(function()
4040
{
4141
showBigDialogWithContent('Log', $(this).next().html(),true);
@@ -55,19 +55,19 @@ var dates = $( "#startlog, #endlog" ).datepicker({
5555
selectedDate, instance.settings );
5656
dates.not( this ).datepicker( "option", option, date );
5757
}
58-
});
58+
});
5959

6060
$('#logSelector').ajaxForm( {beforeSubmit: validateShowlog, success: successShowlog} );
6161

62-
function validateShowlog(formData, jqForm, options) {
62+
function validateShowlog(formData, jqForm, options) {
6363
$('table#listLogs').hide();
6464
$('.logsLoading').show();
6565
}
6666

67-
function successShowlog(responseText, statusText, xhr, form)
67+
function successShowlog(responseText, statusText, xhr, form)
6868
{
6969
$('div#jsonLogs').html(responseText);
70-
70+
7171
try {
7272
jsonLogs = jQuery.parseJSON($('div#jsonLogs').html());
7373
} catch (e) {

core/views/helpers/Duration.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5+
69328 Lyon, FRANCE.
6+
7+
See Copyright.txt for details.
8+
This software is distributed WITHOUT ANY WARRANTY; without even
9+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
PURPOSE. See the above copyright notices for more information.
11+
=========================================================================*/
12+
13+
class Zend_View_Helper_Duration
14+
{
15+
/** translation helper */
16+
function duration($timestamp)
17+
{
18+
Zend_Loader::loadClass('DateComponent', BASE_PATH . '/core/controllers/components');
19+
$component=new DateComponent();
20+
return $component->duration($timestamp);
21+
}
22+
23+
24+
/** Set view*/
25+
public function setView(Zend_View_Interface $view)
26+
{
27+
$this->view = $view;
28+
}
29+
}// end class

modules/GlobalModule.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,18 @@ public function loadModuleElements()
114114
{
115115
foreach($this->_moduleDaos as $dao)
116116
{
117-
include_once (BASE_PATH . "/modules/".$this->moduleName."/models/dao/".$dao."Dao.php");
117+
if(file_exists(BASE_PATH . "/modules/".$this->moduleName."/models/dao/".$dao."Dao.php"))
118+
{
119+
include_once (BASE_PATH . "/modules/".$this->moduleName."/models/dao/".$dao."Dao.php");
120+
}
121+
elseif(file_exists(BASE_PATH . "/privateModules/".$this->moduleName."/models/dao/".$dao."Dao.php"))
122+
{
123+
include_once (BASE_PATH . "/privateModules/".$this->moduleName."/models/dao/".$dao."Dao.php");
124+
}
125+
else
126+
{
127+
throw new Zend_Exception('Unable to find dao '.$dao);
128+
}
118129
}
119130
}
120131

@@ -123,7 +134,18 @@ public function loadModuleElements()
123134
foreach($this->_moduleComponents as $component)
124135
{
125136
$nameComponent = ucfirst($this->moduleName).'_'.$component . "Component";
126-
include_once (BASE_PATH . "/modules/".$this->moduleName."/controllers/components/".$component."Component.php");
137+
if(file_exists(BASE_PATH . "/modules/".$this->moduleName."/controllers/components/".$component."Component.php"))
138+
{
139+
include_once (BASE_PATH . "/modules/".$this->moduleName."/controllers/components/".$component."Component.php");
140+
}
141+
elseif(file_exists(BASE_PATH . "/privateModules/".$this->moduleName."/controllers/components/".$component."Component.php"))
142+
{
143+
include_once (BASE_PATH . "/privateModules/".$this->moduleName."/controllers/components/".$component."Component.php");
144+
}
145+
else
146+
{
147+
throw new Zend_Exception('Unable to find components '.$component);
148+
}
127149
if(!class_exists($nameComponent))
128150
{
129151
throw new Zend_Exception('Unable to find '.$nameComponent);
@@ -138,6 +160,18 @@ public function loadModuleElements()
138160
{
139161
$nameForm = ucfirst($this->moduleName).'_'.$forms . "Form";
140162
include_once (BASE_PATH . "/modules/".$this->moduleName."/controllers/forms/".$forms."Form.php");
163+
if(file_exists(BASE_PATH . "/modules/".$this->moduleName."/controllers/forms/".$forms."Form.php"))
164+
{
165+
include_once (BASE_PATH . "/modules/".$this->moduleName."/controllers/forms/".$forms."Form.php");
166+
}
167+
elseif(file_exists(BASE_PATH . "/privateModules/".$this->moduleName."/controllers/forms/".$forms."Form.php"))
168+
{
169+
include_once (BASE_PATH . "/privateModules/".$this->moduleName."/controllers/forms/".$forms."Form.php");
170+
}
171+
else
172+
{
173+
throw new Zend_Exception('Unable to find form '.$forms);
174+
}
141175
if(!class_exists($nameForm))
142176
{
143177
throw new Zend_Exception('Unable to find '.$nameForm);

modules/remoteprocessing/Notification.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ public function processProcessingResults($params)
172172
$modulesConfig=Zend_Registry::get('configsModules');
173173

174174
$modelLoad = new MIDAS_ModelLoader();
175+
$itempolicyuserModel = $modelLoad->loadModel('Itempolicyuser');
175176
$userModel = $modelLoad->loadModel('User');
176177
$folderModel = $modelLoad->loadModel('Folder');
177178
$itemModel = $modelLoad->loadModel('Item');
@@ -180,11 +181,20 @@ public function processProcessingResults($params)
180181
$job = $jobModel->load($params['job_id']);
181182

182183
$userDao = $userModel->load($params['userKey']);
184+
$creatorDao = $userModel->load($params['creator_id']);
183185

184-
$folder = $folderModel->load($params['ouputFolders'][0]);
186+
if(isset($params['ouputFolders'][0]))
187+
{
188+
$folder = $folderModel->load($params['ouputFolders'][0]);
189+
}
190+
else
191+
{
192+
$folder = $userDao->getPrivateFolder();
193+
}
185194

186195
$componentLoader = new MIDAS_ComponentLoader();
187196
$uploadComponent = $componentLoader->loadComponent('Upload');
197+
$params['outputKeys'] = array();
188198

189199
foreach($params['output'] as $file)
190200
{
@@ -196,6 +206,7 @@ public function processProcessingResults($params)
196206
$filepath = str_replace(".".$tmpArray[1].".", ".", $filepath);
197207
rename($oldfilepath, $filepath);
198208
$item = $uploadComponent->createUploadedItem($userDao, basename($filepath), $filepath, $folder);
209+
$params['outputKeys'][$tmpArray[1]][] = $item->getKey();
199210
$jobModel->addItemRelation($job, $item, MIDAS_REMOTEPROCESSING_RELATION_TYPE_OUPUT);
200211
// add parameter metadata
201212
if(is_numeric($tmpArray[1]) && isset($params['parametersList']) && isset($params['optionMatrix']))
@@ -219,10 +230,13 @@ public function processProcessingResults($params)
219230
}
220231
if(isset($params['log']) && !empty($params['log']))
221232
{
233+
$jobComponenet = $componentLoader->loadComponent('Job', 'remoteprocessing');
234+
$xmlResults = $jobComponenet->computeLogs($job, $params['log'], $params);
222235
$logFile = BASE_PATH.'/tmp/misc/'.uniqid();
223-
file_put_contents($logFile, $params['log']);
224-
$item = $uploadComponent->createUploadedItem($userDao, 'log.txt', $logFile, $folder);
225-
$jobModel->addItemRelation($job, $item, MIDAS_REMOTEPROCESSING_RELATION_TYPE_OUPUT);
236+
file_put_contents($logFile, $xmlResults);
237+
$item = $uploadComponent->createUploadedItem($userDao, 'job-'.$params['job_id'].'_results.xml', $logFile, $folder);
238+
$itempolicyuserModel->createPolicy($creatorDao, $item, MIDAS_POLICY_READ);
239+
$jobModel->addItemRelation($job, $item, MIDAS_REMOTEPROCESSING_RELATION_TYPE_RESULTS);
226240
unlink($logFile);
227241
}
228242
}

modules/remoteprocessing/constant/module.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919
define("MIDAS_REMOTEPROCESSING_RELATION_TYPE_EXECUTABLE", 0);
2020
define("MIDAS_REMOTEPROCESSING_RELATION_TYPE_INPUT", 1);
2121
define("MIDAS_REMOTEPROCESSING_RELATION_TYPE_OUPUT", 2);
22+
define("MIDAS_REMOTEPROCESSING_RELATION_TYPE_RESULTS", 3);
2223
?>

modules/remoteprocessing/controllers/ConfigController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class Remoteprocessing_ConfigController extends Remoteprocessing_AppController
1919
/** download remote script */
2020
function downloadAction()
2121
{
22+
while(ob_get_level() > 0)
23+
{
24+
ob_end_clean();
25+
}
2226
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
2327
{
2428
throw new Zend_Exception("You should be an administrator");
@@ -27,6 +31,7 @@ function downloadAction()
2731
$this->disableLayout();
2832
$this->disableView();
2933
Zend_Loader::loadClass('ZipStream', BASE_PATH.'/library/ZipStream/');
34+
ob_start();
3035
$zip = new ZipStream('RemoteScript.zip');
3136

3237
$file = BASE_PATH.'/modules/remoteprocessing/remotescript/main.py';
@@ -45,6 +50,7 @@ function downloadAction()
4550
}
4651

4752
$zip->finish();
53+
exit();
4854
}
4955

5056
/** index action*/

0 commit comments

Comments
 (0)