[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [6774] bobimmodel and tests.
From: |
Petur Bjorn Thorsteinsson |
Subject: |
[Fmsystem-commits] [6774] bobimmodel and tests. |
Date: |
Fri, 14 Jan 2011 13:53:00 +0000 |
Revision: 6774
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=6774
Author: peturbjorn
Date: 2011-01-14 13:53:00 +0000 (Fri, 14 Jan 2011)
Log Message:
-----------
bobimmodel and tests.
Added Paths:
-----------
branches/dev-bim2/property/inc/class.bobimmodel.inc.php
branches/dev-bim2/property/tests/BIM/TestBObimmodel.php
Added: branches/dev-bim2/property/inc/class.bobimmodel.inc.php
===================================================================
--- branches/dev-bim2/property/inc/class.bobimmodel.inc.php
(rev 0)
+++ branches/dev-bim2/property/inc/class.bobimmodel.inc.php 2011-01-14
13:53:00 UTC (rev 6774)
@@ -0,0 +1,211 @@
+<?php
+/*
+ * Business logic class for creating new BIM models in Portico
+ * This class is designed with dependancy injection in mind
+ */
+/*phpgw::import_class('property.bimExceptions');
+phpgw::import_class('property.sobim');
+phpgw::import_class('property.sobimmodel');
+phpgw::import_class('property.sovfs');*/
+interface bobimmodel {
+ public function addUploadedIfcModel();
+ public function createBimModelList();
+ public function setVfsObject(sovfs $vfs);
+ public function setSobimmodel(sobimmodel $sobimmodel);
+ public function checkBimModelExists();
+ public function checkBimModelExistsByModelId();
+ public function removeIfcModel();
+ public function removeIfcModelByModelId();
+ public function setModelName($name);
+ public function getModelName();
+}
+
+class bobimmodel_impl implements bobimmodel {
+ private $sovfs;
+ private $sobimmodel;
+ private $modelName;
+ function __construct() {
+
+ }
+
+ public function setVfsObject(sovfs $vfs) {
+ $this->sovfs = $vfs;
+ }
+ public function setSobimmodel(sobimmodel $sobimmodel) {
+ $this->sobimmodel = $sobimmodel;
+ }
+ /*
+ * taken from calss.uitts.inc.php
+ * @return boolean true if success
+ * @throws FileExistsException if filename is already used
+ * @throws CopyFailureException if there is a failure copying
+ */
+
+ public function addUploadedIfcModel() {
+ if(!$this->sovfs) {
+ throw new Exception('Missing vfs object!');
+ }
+ try {
+ $filename = $this->saveUploadedBimData();
+ $this->applyModelName($filename);
+ $file_database_id = $this->sovfs->retrieveVfsFileId();
+ $this->sobimmodel->setVfsdatabaseid($file_database_id);
+ $this->sobimmodel->setModelName($this->modelName);
+ $this->sobimmodel->addBimModel();
+ return true;
+ } catch (FileExistsException $e) {
+ throw $e;
+ } catch (CopyFailureException $e) {
+ throw $e;
+ } catch ( ModelExistsException $e) {
+ throw $e;
+ }catch (Exception $e) {
+ throw $e;
+ }
+ }
+
+ private function applyModelName($filename) {
+ if(!($this->modelName && strlen($this->modelName)>0)) {
+ $this->modelName = $filename;
+ }
+ }
+ /*
+ * requires sobimmodel with db set
+ */
+ public function createBimModelList() {
+ if(!$this->sobimmodel) {
+ throw new Exception('Missing sobimodel object!');
+ }
+ $BimModelArray = $this->sobimmodel->retrieveBimModelList();
+ if(!$BimModelArray) {
+ return null;
+ } else {
+ $outputArray = array();
+
+ foreach($BimModelArray as $BimModel) {
+ //var_dump($BimModel);
+ array_push($outputArray,
$this->transformObjectToArray($BimModel));
+ }
+ return $outputArray;
+ }
+
+ }
+ /*
+ * Takes an object, gets the varibles from the public getter function
and returns
+ * an associative array
+ */
+ private function transformObjectToArray($object) {
+ $reflection = new ReflectionObject($object);
+ $publicMethods =
$reflection->getMethods(ReflectionProperty::IS_PUBLIC);
+ $result = array();
+ foreach($publicMethods as $method) {
+ /* @var $method ReflectionMethod */
+ if(preg_match("/^get(.+)/", $method->getName(),
$matches)) {
+ $memberVarible = lcfirst($matches[1]);
+ $value = $method->invoke($object);
+ $result[$memberVarible] = $value;
+ }
+ }
+ return $result;
+ }
+ /*
+ * This function requires:
+ * An SOvfs object with the filename and the submodule set
+ * An sobimmodel object with the modelname and the vfs_database_id
+ */
+ public function checkBimModelExists() {
+ if(!$this->sobimmodel || !$this->sovfs) {
+ throw new
InvalidArgumentException($this->displayArguments());
+ }
+ if($this->sovfs->checkIfFileExists()) {
+ $fileId = $this->sovfs->retrieveVfsFileId();
+ $this->sobimmodel->setVfsdatabaseid($fileId);
+ if($this->sobimmodel->checkIfModelExists() ) {
+ return true;
+ }
+
+ }
+ return false;
+
+ }
+ /*
+ * needs sobimmodel object with db and modelId set
+ * @return boolean
+ */
+ public function checkBimModelExistsByModelId() {
+ $this->checkIdArguments();
+ $bimModel =
$this->sobimmodel->retrieveBimModelInformationById();
+ return ($bimModel != null);
+ }
+
+ private function displayArguments() {
+ $string = "Argument list:\n".
+ "Model name:\t $this->modelName \n".
+ "Model id:\t $this->modelId \n".
+ "SOvfs:\t ".gettype($this->sovfs)."\n".
+ "SObimmodel:\t
".gettype($this->sobimmodel)."\n";
+ return $string;
+
+ }
+ /*
+ * This function needs:
+ * An SOvfs object with the filename and the submodule set
+ * An sobimmodel object with the modelname and the vfs_database_id
+ */
+ public function removeIfcModel() {
+ if(!$this->sobimmodel || !$this->sovfs) {
+ throw new
InvalidArgumentException($this->displayArguments());
+ }
+ $this->sobimmodel->removeBimModelFromDatabase();
+ $this->sovfs->removeFileFromVfs();
+ return true;
+ }
+ /*
+ * needs sobimmodel object with db and modelId set
+ * needs sovfs object, with submodule set
+ */
+ public function removeIfcModelByModelId() {
+ $this->checkIdArguments();
+ /* @var $bimModel BimModel */
+ $bimModel =
$this->sobimmodel->retrieveBimModelInformationById();
+ $this->sobimmodel->setModelName($bimModel->getName());
+ $this->sobimmodel->setVfsdatabaseid($bimModel->getVfsFileId());
+
+ $this->sovfs->setFilename($bimModel->getFileName());
+ $this->removeIfcModel();
+ }
+
+ private function checkIdArguments() {
+ if(!$this->sobimmodel || !$this->sovfs ||
!$this->sobimmodel->getModelId() || !$this->sovfs->getSubModule()) {
+ throw new
InvalidArgumentException($this->displayArguments());
+ }
+ }
+ /*
+ * expects item from the $_FILES object in the form:
+ * @param $uploadedFileArray Array ( [name] => <name>
+ * [type] => <mimeType>
+ * [tmp_name] => <filename with path>
+ * [error] => <error status>
+ * [size] => <file size> )
+ * @throws FileExistsException|Exception
+ * @return String|null filename of the uploaded file
+ */
+ private function saveUploadedBimData() {
+ try {
+ return $this->sovfs->addFileToVfs();
+ } catch (FileExistsException $e) {
+ throw $e;
+ } catch (CopyFailureException $e) {
+ throw $e;
+ } catch (Exception $e) {
+ throw $e;
+ }
+ }
+
+ public function setModelName($name) {
+ $this->modelName = $name;
+ }
+ public function getModelName() {
+ return $this->modelName;
+ }
+}
\ No newline at end of file
Added: branches/dev-bim2/property/tests/BIM/TestBObimmodel.php
===================================================================
--- branches/dev-bim2/property/tests/BIM/TestBObimmodel.php
(rev 0)
+++ branches/dev-bim2/property/tests/BIM/TestBObimmodel.php 2011-01-14
13:53:00 UTC (rev 6774)
@@ -0,0 +1,171 @@
+<?php
+/*
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+include_once './TestBimCommon.php';
+class TestBObimmodel extends TestBimCommon
+{
+
+ /**
+ * @var boolean $backupGlobals disable backup of GLOBALS which breaks
things
+ */
+ protected $backupGlobals = false;
+
+ /**
+ * @var integer $fieldID The attribute ID used for all the tests
+ */
+ protected $fieldID;
+
+ private $sovfs;
+ private $sobimmodel;
+ private $bobimmodel;
+
+ /**
+ * Setup the environment for the tests
+ *
+ * @return void
+ */
+ protected function setUp()
+ {
+ $this->initDatabase();
+
+ }
+ /**
+ * Clean up the environment after running a test
+ *
+ * @return void
+ */
+ protected function tearDown()
+ {
+
+
+ }
+
+ public function testDb(){
+ $this->assertNotNull($this->db);
+ }
+ /*
+ * @depends testDB
+ * @test
+ */
+ public function testAddUploadedIfcModel() {
+ $this->addIfcModel();
+ $this->assertTrue(true);
+ }
+
+ private function addIfcModel() {
+ $this->createDummyFile();
+
+ $filename = $this->vfsFileName;
+ $filenameWithPath = $this->vfsFileNameWithFullPath;
+ $this->bobimmodel = new bobimmodel_impl();
+ $this->sovfs = new sovfs_impl($filename, $filenameWithPath,
$this->vfsSubModule);
+ $this->bobimmodel->setVfsObject($this->sovfs);
+ $this->sobimmodel = new sobimmodel_impl($this->db);
+ $this->bobimmodel->setSobimmodel($this->sobimmodel);
+ $this->bobimmodel->setModelName($this->modelName);
+ $error = "";
+ try {
+ $this->bobimmodel->addUploadedIfcModel();
+ } catch (FileExistsException $e) {
+ $error = $e;
+ } catch (Exception $e) {
+ $error = $e;
+ }
+ if($error) {
+ echo "error in testAddUploadedIfcModel:".$error;
+ }
+ $this->removeDummyFile();
+ }
+ /*
+ * @depends testAddUploadedIfcModel
+ */
+ public function testCheckUploadedIfcModel() {
+ $bobimmodel = new bobimmodel_impl();
+ //init dependancies
+ $sovfs = new sovfs_impl($this->vfsFileName, null,
$this->vfsSubModule);
+ $vls_db_id = $sovfs->retrieveVfsFileId();
+ $sobimmodel = new sobimmodel_impl($this->db);
+ $sobimmodel->setModelName($this->modelName);
+ $sobimmodel->setVfsdatabaseid($vls_db_id);
+
+ $bobimmodel->setVfsObject($sovfs);
+ $bobimmodel->setSobimmodel($sobimmodel);
+
+ $this->assertTrue($bobimmodel->checkBimModelExists());
+ }
+ /*
+ * @depends testCheckUploadedIfcModel
+ */
+ public function testCreateBimModelList() {
+ $bobimmodel = new bobimmodel_impl();
+ $sobimmodel = new sobimmodel_impl($this->db);
+ $bobimmodel->setSobimmodel($sobimmodel);
+
+ $output = $bobimmodel->createBimModelList();
+
+ $modelFound = false;
+ /* @var $bimModel BimModel */
+ foreach($output as $bimModelArray ) {
+ if($bimModelArray['fileName'] == $this->vfsFileName &&
$bimModelArray['name'] == $this->modelName) {
+ $modelFound = true;
+ break;
+ }
+ }
+ $this->assertTrue($modelFound);
+
+
+ }
+ /*
+ * @depends testCreateBimModelList
+ */
+ public function testRemoveUploadedIfcModel() {
+ $bobimmodel = new bobimmodel_impl();
+ //init dependancies
+ $sovfs = new sovfs_impl($this->vfsFileName, null,
$this->vfsSubModule);
+ $vls_db_id = $sovfs->retrieveVfsFileId();
+ $sobimmodel = new sobimmodel_impl($this->db);
+ $sobimmodel->setModelName($this->modelName);
+ $sobimmodel->setVfsdatabaseid($vls_db_id);
+
+ $bobimmodel->setVfsObject($sovfs);
+ $bobimmodel->setSobimmodel($sobimmodel);
+
+ $this->assertTrue($bobimmodel->removeIfcModel());
+ }
+ /*
+ * @covers removeIfcModelByModelId
+ */
+ public function testRemoveIfcModelByModelId() {
+ $this->addIfcModel();
+ $bimModelArray = $this->sobimmodel->retrieveBimModelList();
+ $modelFound = false;
+ /* @var $bimModel BimModel */
+ foreach($bimModelArray as $bimModel ) {
+ if($bimModel->getFileName() == $this->vfsFileName &&
$bimModel->getVfsFileId() == $this->vfsFileId) {
+ $modelFound = true;
+ break;
+ }
+ }
+ if($modelFound) {
+
$this->sobimmodel->setModelId($bimModel->getDatabaseId());
+ $this->sovfs->setSubModule($this->vfsSubModule);
+ $this->bobimmodel->removeIfcModelByModelId();
+
$this->assertThat($this->bobimmodel->checkBimModelExistsByModelId());
+ }
+
+ }
+
+
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [6774] bobimmodel and tests.,
Petur Bjorn Thorsteinsson <=