Merge remote branch 'upstream/master'

This commit is contained in:
Marco Antonio Nina
2014-03-12 09:00:52 -04:00
7 changed files with 327 additions and 24 deletions

View File

@@ -98,15 +98,15 @@ class Department
*/
public function saveDepartment($dep_data, $create = true)
{
$dep_data = array_change_key_case($dep_data, CASE_UPPER);
Validator::isArray($dep_data, '$dep_data');
Validator::isNotEmpty($dep_data, '$dep_data');
Validator::isBoolean($create, '$create');
$dep_data = array_change_key_case($dep_data, CASE_UPPER);
$oDepartment = new \Department();
if (isset($dep_data['DEP_UID']) && $dep_data['DEP_UID'] != '') {
Validator::depUid($dep_data['DEP_UID']);
}
if (isset($dep_data['DEP_TITLE'])) {
Validator::depTitle($dep_data['DEP_TITLE']);
}
if (isset($dep_data['DEP_PARENT']) && $dep_data['DEP_PARENT'] != '') {
Validator::depUid($dep_data['DEP_PARENT'], 'dep_parent');
}
@@ -119,9 +119,17 @@ class Department
if (!$create) {
$dep_data['DEPO_TITLE'] = $dep_data['DEP_TITLE'];
if (isset($dep_data['DEP_TITLE'])) {
Validator::depTitle($dep_data['DEP_TITLE'], $dep_data['DEP_UID']);
}
$oDepartment->update($dep_data);
$oDepartment->updateDepartmentManager($dep_data['DEP_UID']);
} else {
if (isset($dep_data['DEP_TITLE'])) {
Validator::depTitle($dep_data['DEP_TITLE']);
} else {
throw (new \Exception("The field dep_title is required."));
}
$dep_uid = $oDepartment->create($dep_data);
$response = $this->getDepartment($dep_uid);
return $response;
@@ -141,6 +149,10 @@ class Department
public function deleteDepartment($dep_uid)
{
$dep_uid = Validator::depUid($dep_uid);
$dep_data = $this->getDepartment($dep_uid);
if ($dep_data['has_children'] != 0) {
throw (new \Exception("Can not delete the department. The department has children"));
}
$oDepartment = new \Department();
$oDepartment->remove($dep_uid);
}

View File

@@ -480,11 +480,9 @@ class FilesManager
$sSubDirectory = substr(str_replace($sMainDirectory,'',$sSubDirectory),1);
switch ($sMainDirectory) {
case 'templates':
$sMainDirectory = 'mailTemplates';
$sDirectory = PATH_DATA_MAILTEMPLATES . $sProcessUID . PATH_SEP . ($sSubDirectory != '' ? $sSubDirectory . PATH_SEP : '');
break;
case 'public':
$sMainDirectory = 'public';
$sDirectory = PATH_DATA_PUBLIC . $sProcessUID . PATH_SEP . ($sSubDirectory != '' ? $sSubDirectory . PATH_SEP : '');
break;
default:
@@ -505,5 +503,44 @@ class FilesManager
throw $e;
}
}
/**
*
* @param string $sProcessUID {@min 32} {@max 32}
* @param string $prfUid {@min 32} {@max 32}
*
*
* @access public
*/
public function getProcessFileManager($sProcessUID, $prfUid)
{
try {
$oProcessFiles = \ProcessFilesPeer::retrieveByPK($prfUid);
$fcontent = file_get_contents($oProcessFiles->getPrfPath());
$sFile = end(explode("/",$oProcessFiles->getPrfPath()));
$path = $oProcessFiles->getPrfPath();
$sPath = str_replace($sFile,'',$path);
$sSubDirectory = substr(str_replace($sProcessUID,'',substr($sPath,(strpos($sPath, $sProcessUID)))),0,-1);
$sMainDirectory = str_replace(substr($sPath, strpos($sPath, $sProcessUID)),'', $sPath);
if ($sMainDirectory == PATH_DATA_MAILTEMPLATES) {
$sMainDirectory = 'templates';
} else {
$sMainDirectory = 'public';
}
$oProcessFile = array('prf_uid' => $oProcessFiles->getPrfUid(),
'prf_filename' => $sFile,
'usr_uid' => $oProcessFiles->getUsrUid(),
'prf_update_usr_uid' => $oProcessFiles->getPrfUpdateUsrUid(),
'prf_path' => $sMainDirectory.$sSubDirectory,
'prf_type' => $oProcessFiles->getPrfType(),
'prf_editable' => $oProcessFiles->getPrfEditable(),
'prf_create_date' => $oProcessFiles->getPrfCreateDate(),
'prf_update_date' => $oProcessFiles->getPrfUpdateDate(),
'prf_content' => $fcontent);
return $oProcessFile;
} catch (Exception $e) {
throw $e;
}
}
}

View File

@@ -848,7 +848,6 @@ class ProcessSupervisor
*/
public function removeInputDocumentSupervisor($sProcessUID, $sPuiUID)
{
$oConnection = \Propel::getConnection(\StepSupervisorPeer::DATABASE_NAME);
try {
$oInputDocumentSupervidor = \StepSupervisorPeer::retrieveByPK($sPuiUID);
if (!is_null($oInputDocumentSupervidor)) {
@@ -858,7 +857,6 @@ class ProcessSupervisor
throw (new \Exception('This row does not exist!'));
}
} catch (Exception $oError) {
$oConnection->rollback();
throw ($oError);
}
}

View File

@@ -9,8 +9,7 @@ namespace BusinessModel;
*
* @protected
*/
class Validator
{
class Validator{
/**
* Validate dep_uid
* @var string $dep_uid. Uid for Departament
@@ -120,6 +119,57 @@ class Validator
}
return $usr_uid;
}
/**
* Validate is array
* @var array $field. Field type array
*
* @access public
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return void
*/
static public function isArray($field, $nameField)
{
if (!is_array($field)) {
throw (new \Exception("The field '$nameField' is not an array."));
}
}
/**
* Validate is boolean
* @var boolean $field. Field type boolean
*
* @access public
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return void
*/
static public function isBoolean($field, $nameField)
{
if (!is_bool($field)) {
throw (new \Exception("The field '$nameField' is not a boolean."));
}
}
/**
* Validate is boolean
* @var boolean $field. Field type boolean
*
* @access public
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return void
*/
static public function isNotEmpty($field, $nameField)
{
if (empty($field)) {
throw (new \Exception("The field '$nameField' is empty."));
}
}
}

View File

@@ -151,6 +151,26 @@ class FilesManager extends Api
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @param string $prj_uid {@min 32} {@max 32}
* @param string $prf_uid {@min 32} {@max 32}
*
* @url GET /:prj_uid/file-manager/:prf_uid
*
*/
public function doGetProcessFileManager($prj_uid, $prf_uid)
{
try {
$filesManager = new \BusinessModel\FilesManager();
$response = $filesManager->getProcessFileManager($prj_uid, $prf_uid);
//response
return $response;
} catch (\Exception $e) {
//response
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
}
class ProcessFilesManagerStructurePost

View File

@@ -286,6 +286,7 @@ class ProcessSupervisors extends Api
try {
$supervisor = new \BusinessModel\ProcessSupervisor();
$supervisor->removeDynaformSupervisor($prjUid, $pudUid);
ob_end_clean();
} catch (\Exception $e) {
//response
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
@@ -304,6 +305,7 @@ class ProcessSupervisors extends Api
try {
$supervisor = new \BusinessModel\ProcessSupervisor();
$supervisor->removeInputDocumentSupervisor($prjUid, $puiUid);
ob_end_clean();
} catch (\Exception $e) {
//response
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());

View File

@@ -16,7 +16,172 @@ if (!class_exists("Propel")) {
*/
class DepartmentTest extends \PHPUnit_Framework_TestCase
{
public function testSaveDepartment()
public function testCreateDepartmentErrorArray()
{
try {
$oDepartment = new \BusinessModel\Department();
$oDepartment->saveDepartment(true);
} catch (\Exception $e) {
$res = $e->getMessage();
$this->assertEquals($res, "The field '". '$dep_data' . "' is not an array.");
}
}
public function testCreateDepartmentErrorBoolean()
{
try {
$oDepartment = new \BusinessModel\Department();
$oDepartment->saveDepartment(array('1'),array());
} catch (\Exception $e) {
$res = $e->getMessage();
$this->assertEquals($res, "The field '". '$create' . "' is not a boolean.");
}
}
public function testCreateDepartmentErrorArrayEmpty()
{
try {
$oDepartment = new \BusinessModel\Department();
$oDepartment->saveDepartment(array());
} catch (\Exception $e) {
$res = $e->getMessage();
$this->assertEquals($res, "The field '". '$dep_data' . "' is empty.");
}
}
public function testCreateDepartmentErrorArrayDepUidExist()
{
try {
$data = array('dep_uid' => 'testUidDepartment');
$oDepartment = new \BusinessModel\Department();
$oDepartment->saveDepartment($data);
} catch (\Exception $e) {
$res = $e->getMessage();
$this->assertEquals($res, "The departament with dep_uid: 'testUidDepartment' does not exist.");
}
}
public function testCreateDepartmentErrorArrayDepParentExist()
{
try {
$data = array('dep_parent' => 'testUidDepartment');
$oDepartment = new \BusinessModel\Department();
$oDepartment->saveDepartment($data);
} catch (\Exception $e) {
$res = $e->getMessage();
$this->assertEquals($res, "The departament with dep_parent: 'testUidDepartment' does not exist.");
}
}
public function testCreateDepartmentErrorArrayDepManagerExist()
{
try {
$data = array('dep_manager' => 'testUidUser');
$oDepartment = new \BusinessModel\Department();
$oDepartment->saveDepartment($data);
} catch (\Exception $e) {
$res = $e->getMessage();
$this->assertEquals($res, "The user with dep_manager: 'testUidUser' does not exist.");
}
}
public function testCreateDepartmentErrorArrayDepStatus()
{
try {
$data = array('dep_status' => 'SUPER ACTIVO');
$oDepartment = new \BusinessModel\Department();
$oDepartment->saveDepartment($data);
} catch (\Exception $e) {
$res = $e->getMessage();
$this->assertEquals($res, "The departament with dep_status: 'SUPER ACTIVO' is incorrect.");
}
}
public function testCreateDepartmentErrorArrayDepTitleEmpty()
{
try {
$data = array('dep_status' => 'ACTIVE');
$oDepartment = new \BusinessModel\Department();
$oDepartment->saveDepartment($data);
} catch (\Exception $e) {
$res = $e->getMessage();
$this->assertEquals($res, "The field dep_title is required.");
}
}
public function testCreateDepartmentErrorArrayDepTitleRepeated()
{
$oDepartment = new \BusinessModel\Department();
////////// Create department parent
$dep1 = array (
'dep_title' => 'departamento padre'
);
$arrayDepartments = $oDepartment->saveDepartment($dep1);
$this->assertTrue(isset($arrayDepartments['dep_uid']));
try {
$arrayDepartments = $oDepartment->saveDepartment($dep1);
} catch (\Exception $e) {
$res = $e->getMessage();
$this->assertEquals($res, "The departament with dep_title: 'departamento padre' exist.");
}
$oDepartment->deleteDepartment($arrayDepartments['dep_uid']);
}
public function testCreateDepartmentNormal()
{
$oDepartment = new \BusinessModel\Department();
////////// Create department parent
$dep1 = array (
'dep_title' => 'departamento padre'
);
$arrayDepartments = $oDepartment->saveDepartment($dep1);
$this->assertTrue(isset($arrayDepartments['dep_uid']));
$this->assertEquals($arrayDepartments['dep_parent'], '');
$this->assertEquals($arrayDepartments['dep_title'], 'departamento padre');
$this->assertEquals($arrayDepartments['dep_status'], 'ACTIVE');
$this->assertEquals($arrayDepartments['dep_manager'], '');
$this->assertEquals($arrayDepartments['has_children'], 0);
$oDepartment->deleteDepartment($arrayDepartments['dep_uid']);
}
public function testUpdateDepartmentErrorArrayDepTitleRepeated()
{
$oDepartment = new \BusinessModel\Department();
////////// Create department parent
$dep1 = array (
'dep_title' => 'dep1'
);
$dep2 = array (
'dep_title' => 'dep2'
);
$dataDep1 = $oDepartment->saveDepartment($dep1);
$this->assertTrue(isset($dataDep1['dep_uid']));
$dataDep2 = $oDepartment->saveDepartment($dep2);
$this->assertTrue(isset($dataDep2['dep_uid']));
$dep2Update = array (
'dep_uid' => $dataDep2['dep_uid'],
'dep_title' => 'dep1'
);
try {
$oDepartment->saveDepartment($dep2Update, false);
} catch (\Exception $e) {
$res = $e->getMessage();
$this->assertEquals($res, "The departament with dep_title: 'dep1' exist.");
}
$oDepartment->deleteDepartment($dataDep1['dep_uid']);
$oDepartment->deleteDepartment($dataDep2['dep_uid']);
}
public function testGetDepartments()
{
$oDepartment = new \BusinessModel\Department();
@@ -63,20 +228,15 @@ class DepartmentTest extends \PHPUnit_Framework_TestCase
'dep_manager' => '',
);
$oDepartment->saveDepartment($depUp2, false);
}
public function testGetDepartments()
{
$oDepartment = new \BusinessModel\Department();
$arrayDepartments = $oDepartment->getDepartments();
$this->assertTrue(is_array($arrayDepartments));
$this->assertEquals(count($arrayDepartments), 1);
$this->assertTrue(is_array($arrayDepartments[0]['dep_children']));
$this->assertEquals(count($arrayDepartments[0]['dep_children']), 1);
}
public function testGetDepartment()
{
$oDepartment = new \BusinessModel\Department();
$arrayDepartments = $oDepartment->getDepartments();
$depIdPadre = $arrayDepartments[0]['dep_uid'];
@@ -91,19 +251,43 @@ class DepartmentTest extends \PHPUnit_Framework_TestCase
$this->assertTrue(is_array($dataChild));
$this->assertEquals($dataChild['dep_title'], 'DepHijo');
$this->assertEquals($dataChild['dep_manager'], '');
$oDepartment->deleteDepartment($depIdChild);
$oDepartment->deleteDepartment($depIdPadre);
}
public function testDeleteDepartment()
// TODO: Assigned Users to department
public function testDeleteDepartmentErrorUsersSelections()
{
}
public function testDeleteDepartmentErrorDepartmentParent()
{
$oDepartment = new \BusinessModel\Department();
$arrayDepartments = $oDepartment->getDepartments();
$dataDepChild = $arrayDepartments[0]['dep_children'];
$oDepartment->deleteDepartment($dataDepChild[0]['dep_uid']);
$oDepartment->deleteDepartment($arrayDepartments[0]['dep_uid']);
////////// Create department parent
$dep1 = array (
'dep_title' => 'dep1'
);
$dataDep1 = $oDepartment->saveDepartment($dep1);
$this->assertTrue(isset($dataDep1['dep_uid']));
$dep2 = array (
'dep_title' => 'dep2',
'dep_parent' => $dataDep1['dep_uid']
);
$dataDep2 = $oDepartment->saveDepartment($dep2);
$this->assertTrue(isset($dataDep2['dep_uid']));
$arrayDepartments = $oDepartment->getDepartments();
$this->assertEquals(count($arrayDepartments), 0);
try {
$oDepartment->deleteDepartment($dataDep1['dep_uid']);
} catch (\Exception $e) {
$res = $e->getMessage();
$this->assertEquals($res, "Can not delete the department. The department has children");
}
$oDepartment->deleteDepartment($dataDep2['dep_uid']);
$oDepartment->deleteDepartment($dataDep1['dep_uid']);
}
}