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

Commit 3805989

Browse files
author
Charles Ma
committed
ENH: refs #301 Added some tests
Fixed Molder loader includes Added multi parameters processing
1 parent 85537c4 commit 3805989

File tree

29 files changed

+760
-114
lines changed

29 files changed

+760
-114
lines changed

core/models/ModelLoader.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,29 @@ public function loadModel($model, $module = '')
4343
{
4444
$databaseType = Zend_Registry::get('configDatabase')->database->type;
4545
$models = Zend_Registry::get('models');
46+
4647
if(!isset($models[$module.$model]))
4748
{
4849
if($module == '')
4950
{
51+
if(file_exists(BASE_PATH.'/core/models/base/'.$model.'ModelBase.php'))
52+
{
53+
include_once BASE_PATH.'/core/models/base/'.$model.'ModelBase.php';
54+
}
5055
include_once BASE_PATH.'/core/models/'.$databaseType.'/'.$model.'Model.php';
5156
$name = $model . 'Model';
5257
}
5358
else
5459
{
60+
if(file_exists(BASE_PATH.'/modules/'.$module.'/models/base/'.$model.'ModelBase.php'))
61+
{
62+
include_once BASE_PATH.'/modules/'.$module.'/models/base/'.$model.'ModelBase.php';
63+
}
64+
elseif(file_exists(BASE_PATH.'/privateModules/'.$module.'/models/base/'.$model.'ModelBase.php'))
65+
{
66+
include_once BASE_PATH.'/privateModules/'.$module.'/models/base/'.$model.'ModelBase.php';
67+
}
68+
5569
if(file_exists(BASE_PATH.'/modules/'.$module.'/models/'.$databaseType.'/'.$model.'Model.php'))
5670
{
5771
include_once BASE_PATH.'/modules/'.$module.'/models/'.$databaseType.'/'.$model.'Model.php';
@@ -67,6 +81,7 @@ public function loadModel($model, $module = '')
6781

6882
$name = ucfirst($module).'_'.$model.'Model';
6983
}
84+
7085
if(class_exists($name))
7186
{
7287
$models[$module.$model] = new $name;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<dataset>
3+
<user user_id="11111" firstname="FirstName11111" lastname="LastName11111"
4+
email="user11111@user11111.com" password="35fd8ba86ba403ffcc00feac5355ad20" creation="2011-01-27 12:09:02"
5+
folder_id="11110" publicfolder_id="11111" privatefolder_id="11112" admin="1"/>
6+
7+
<folder folder_id="11110" name="User 11111 name Folder 1" uuid='4e311fdf82007c245b07d8d6c4fcb4205f2621eb70'
8+
description="Description Folder 1" left_indice="1111" right_indice="11115"
9+
parent_id="-1" />
10+
11+
<folderpolicyuser folder_id="11110" user_id="1" policy='2' />
12+
<folder folder_id="11111" name="User 11111 name Folder 2" uuid='4e311fdf82007c245b07d8d6cb4205f2621eb72761'
13+
description="Description Folder 2" left_indice="11111" right_indice="11112"
14+
parent_id="11110" />
15+
<folderpolicyuser folder_id="11111" user_id="1" policy='2' />
16+
<folder folder_id="11112" name="User 11111 name Folder 3" uuid='4e311fdf8200745b07d8d6c4fcb4205f2621eb72762'
17+
description="Description Folder 3" left_indice="11113" right_indice="11114"
18+
parent_id="11110" />
19+
</dataset>

modules/remoteprocessing/Notification.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Remoteprocessing_Notification extends ApiEnabled_Notification
77
public $moduleName = 'remoteprocessing';
88
public $_moduleComponents=array('Api');
99
public $_moduleModels=array('Job');
10+
public $_models=array('Item');
1011
public $_moduleDaos=array('Job');
1112

1213
/** init notification process*/
@@ -16,7 +17,6 @@ public function init()
1617
$this->addTask("TASK_REMOTEPROCESSING_ADD_JOB", 'addJob', "");
1718
$this->addCallBack('CALLBACK_REMOTEPROCESSING_IS_EXECUTABLE', 'isExecutable');
1819
$this->addCallBack('CALLBACK_REMOTEPROCESSING_EXECUTABLE_RESULTS', 'processProcessingResults');
19-
2020
}//end init
2121

2222
/** check if item contains an executable */
@@ -41,15 +41,16 @@ public function isExecutable($params)
4141
public function processProcessingResults($params)
4242
{
4343
$modulesConfig=Zend_Registry::get('configsModules');
44-
$communityKey = $modulesConfig['zeiss']->community->results;
44+
4545
$modelLoad = new MIDAS_ModelLoader();
46-
$communityModel = $modelLoad->loadModel('Community');
4746
$userModel = $modelLoad->loadModel('User');
47+
$folderModel = $modelLoad->loadModel('Folder');
48+
$jobModel = $modelLoad->loadModel('Job', 'remoteprocessing');
49+
$job = $jobModel->load($params['job_id']);
4850

4951
$userDao = $userModel->load($params['userKey']);
5052

51-
$communityDao = $communityModel->load($communityKey);
52-
$folder = $communityDao->getPublicFolder();
53+
$folder = $folderModel->load($params['ouputFolders'][0]);
5354

5455
$componentLoader = new MIDAS_ComponentLoader();
5556
$uploadComponent = $componentLoader->loadComponent('Upload');
@@ -60,8 +61,17 @@ public function processProcessingResults($params)
6061
if(file_exists($filepath))
6162
{
6263
$item = $uploadComponent->createUploadedItem($userDao, basename($filepath), $filepath, $folder);
64+
$jobModel->addItemRelation($job, $item);
6365
}
6466
}
67+
if(isset($params['log']) && !empty($params['log']))
68+
{
69+
$logFile = BASE_PATH.'/tmp/misc/'.uniqid();
70+
file_put_contents($logFile, $params['log']);
71+
$item = $uploadComponent->createUploadedItem($userDao, 'log.txt', $logFile, $folder);
72+
$jobModel->addItemRelation($job, $item);
73+
unlink($logFile);
74+
}
6575
}
6676

6777
/** get Config Tabs */
@@ -100,6 +110,18 @@ public function addJob($params)
100110

101111
$job->setParams(JsonComponent::encode($params['params']));
102112
$this->Remoteprocessing_Job->save($job);
113+
114+
if(!empty($params['params']['input']))
115+
{
116+
foreach($params['params']['input'] as $itemId)
117+
{
118+
$item = $this->Item->load($itemId);
119+
if($item != false)
120+
{
121+
$this->Remoteprocessing_Job->addItemRelation($job, $item);
122+
}
123+
}
124+
}
103125
return;
104126
}
105127

modules/remoteprocessing/controllers/ConfigController.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
class Remoteprocessing_ConfigController extends Remoteprocessing_AppController
44
{
5-
public $_moduleComponents = array('Executable');
5+
public $_moduleForms=array('Config');
6+
public $_components=array('Utility', 'Date');
67

78
/** download remote script */
8-
function initAction()
9+
function downloadAction()
910
{
1011
if(!$this->logged||!$this->userSession->Dao->getAdmin()==1)
1112
{
@@ -65,8 +66,9 @@ function indexAction()
6566

6667
if($this->_request->isPost())
6768
{
68-
$this->_helper->layout->disableLayout();
69-
$this->_helper->viewRenderer->setNoRender();
69+
$this->disableLayout();
70+
$this->disableView();
71+
7072
$submitConfig = $this->_getParam('submitConfig');
7173
if(isset($submitConfig))
7274
{

modules/remoteprocessing/controllers/JobController.php

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ class Remoteprocessing_JobController extends Remoteprocessing_AppController
55
public $_models = array('Item', 'Bitstream', 'ItemRevision', 'Assetstore');
66
public $_components = array('Upload');
77
public $_moduleComponents = array('Executable');
8+
public $_moduleModels = array('Job');
89

910
/** manage jobs */
1011
function manageAction()
1112
{
12-
1313
$itemId = $this->_getParam("itemId");
1414
if(!isset($itemId) || !is_numeric($itemId))
1515
{
@@ -29,6 +29,14 @@ function manageAction()
2929
$metaFile = $this->ModuleComponent->Executable->getMetaIoFile($itemDao);
3030
$this->view->metaFile = $metaFile;
3131
$this->view->itemDao = $itemDao;
32+
33+
$this->view->relatedJobs = $this->Remoteprocessing_Job->getRelatedJob($itemDao);
34+
35+
if(isset($_GET['inprogress']))
36+
{
37+
$this->showNotificationMessage('The Job will appear in a next few minutes.');
38+
}
39+
3240
}
3341

3442
/** init a job */
@@ -69,50 +77,6 @@ function initAction()
6977
$this->disableView();
7078

7179
$this->ModuleComponent->Executable->initAndSchedule($itemDao, $metaContent, $_POST['results']);
72-
/*
73-
74-
$results = $_POST['results'];
75-
$xmlContent = $this->ModuleComponent->Executable->createDefinitionFile($results);
76-
$pathFile = BASE_PATH.'/tmp/misc/'.uniqid().time();
77-
file_put_contents($pathFile, $xmlContent);
78-
79-
$revision = $this->Item->getLastRevision($itemDao);
80-
$bitstreams = $revision->getBitstreams();
81-
82-
$itemRevisionDao = new ItemRevisionDao;
83-
$itemRevisionDao->setChanges('Modification Definition File');
84-
$itemRevisionDao->setUser_id($this->userSession->Dao->getKey());
85-
$itemRevisionDao->setDate(date('c'));
86-
$itemRevisionDao->setLicense(null);
87-
$this->Item->addRevision($itemDao, $itemRevisionDao);
88-
89-
foreach($bitstreams as $b)
90-
{
91-
if($b->getName() != 'MetaIO.vxml')
92-
{
93-
$b->saved = false;
94-
$b->setBitstreamId(null);
95-
$this->Bitstream->save($b);
96-
$this->ItemRevision->addBitstream($itemRevisionDao, $b);
97-
}
98-
}
99-
100-
$bitstreamDao = new BitstreamDao;
101-
$bitstreamDao->setName('MetaIO.vxml');
102-
$bitstreamDao->setPath($pathFile);
103-
$bitstreamDao->fillPropertiesFromPath();
104-
$defaultAssetStoreId = Zend_Registry::get('configGlobal')->defaultassetstore->id;
105-
$bitstreamDao->setAssetstoreId($defaultAssetStoreId);
106-
$assetstoreDao = $this->Assetstore->load($defaultAssetStoreId);
107-
108-
// Upload the bitstream if necessary (based on the assetstore type)
109-
$this->Component->Upload->uploadBitstream($bitstreamDao, $assetstoreDao);
110-
$this->ItemRevision->addBitstream($itemRevisionDao, $bitstreamDao);
111-
112-
if(file_exists($pathFile))
113-
{
114-
unlink($pathFile);
115-
}*/
11680
}
11781
}
11882

modules/remoteprocessing/controllers/components/ApiComponent.php

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ public function keepaliveserver($args)
103103
throw new Exception('Unable to authenticate as a server. Please check credentials.', MIDAS_INVALID_PARAMETER);
104104
}
105105

106+
if(!isset($args['os']))
107+
{
108+
throw new Exception('Please set the os', MIDAS_INVALID_PARAMETER);
109+
}
110+
106111
$groupModel = $modelLoad->loadModel('Group');
107112
$groupServer = $groupModel->load(MIDAS_GROUP_SERVER_KEY);
108113
$users = $groupServer->getUsers();
@@ -122,7 +127,7 @@ public function keepaliveserver($args)
122127
}
123128

124129
$jobModel = $modelLoad->loadModel('Job', 'remoteprocessing');
125-
$jobs = $jobModel->getBy(MIDAS_REMOTEPROCESSING_OS_WINDOWS, '');
130+
$jobs = $jobModel->getBy($args['os'], '');
126131

127132
if(empty($jobs))
128133
{
@@ -131,13 +136,43 @@ public function keepaliveserver($args)
131136
else
132137
{
133138
$paramsReturn['action'] = 'process';
134-
$params = $jobs[0]->getParams();
135139
$paramsReturn['params'] = JsonComponent::decode($jobs[0]->getParams());
136140
$paramsReturn['script'] = $jobs[0]->getScript();
137141
$paramsReturn['params']['job_id'] = $jobs[0]->getKey();
142+
143+
$paramsJob = $paramsReturn['params'];
138144
$paramsReturn['params'] = JsonComponent::encode($paramsReturn['params']);
139-
//$jobs[0]->setStatus(MIDAS_REMOTEPROCESSING_STATUS_STARTED);
145+
$jobs[0]->setStatus(MIDAS_REMOTEPROCESSING_STATUS_STARTED);
140146
$jobModel->save($jobs[0]);
147+
148+
$itempolicyuserModel = $modelLoad->loadModel('Itempolicyuser');
149+
$folderpolicyuserModel = $modelLoad->loadModel('Folderpolicyuser');
150+
$itemModel = $modelLoad->loadModel('Item');
151+
$folderModel = $modelLoad->loadModel('Folder');
152+
153+
// set policies
154+
if(isset($paramsJob['input']))
155+
{
156+
foreach($paramsJob['input'] as $itemId)
157+
{
158+
$item = $itemModel->load($itemId);
159+
if($item != false)
160+
{
161+
$itempolicyuserModel->createPolicy($userDao, $item, MIDAS_POLICY_READ);
162+
}
163+
}
164+
}
165+
if(isset($paramsJob['ouputFolders']))
166+
{
167+
foreach($paramsJob['ouputFolders'] as $folderId)
168+
{
169+
$folder = $folderModel->load($folderId);
170+
if($folder != false)
171+
{
172+
$folderpolicyuserModel->createPolicy($userDao, $folder, MIDAS_POLICY_WRITE);
173+
}
174+
}
175+
}
141176
}
142177

143178
return $paramsReturn;
@@ -180,7 +215,6 @@ public function resultsserver($args)
180215
}
181216

182217
$jobModel = $modelLoad->loadModel('Job', 'remoteprocessing');
183-
$jobs = $jobModel->getBy(MIDAS_REMOTEPROCESSING_OS_WINDOWS, '');
184218
if(!file_exists(BASE_PATH.'/tmp/remoteprocessing'))
185219
{
186220
mkdir(BASE_PATH.'/tmp/remoteprocessing');

0 commit comments

Comments
 (0)