Adicion de end point para REPORT TABLES

This commit is contained in:
Brayan Osmar Pereyra Suxo
2014-02-07 11:18:02 -04:00
parent 68c1d98b96
commit a078044fb5
4 changed files with 163 additions and 29 deletions

View File

@@ -108,12 +108,12 @@ class AdditionalTables extends BaseAdditionalTables
$oDataset = FieldsPeer::doSelectRS($oCriteria); $oDataset = FieldsPeer::doSelectRS($oCriteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
while ($oDataset->next()) { while ($oDataset->next()) {
$auxField = $oDataset->getRow(); $auxField = $oDataset->getRow();
if ($auxField['FLD_TYPE'] == 'TIMESTAMP') { if ($auxField['FLD_TYPE'] == 'TIMESTAMP') {
$auxField['FLD_TYPE'] = 'DATETIME'; $auxField['FLD_TYPE'] = 'DATETIME';
} }
$this->fields[] = $auxField; $this->fields[] = $auxField;
} }
return $this->fields; return $this->fields;
@@ -263,6 +263,27 @@ class AdditionalTables extends BaseAdditionalTables
} }
} }
/**
* verify if Additional Table row specified in [sUID] exists.
*
* @param string $sUID the uid of the additional table
*/
public function exists ($sUID)
{
$con = Propel::getConnection(AdditionalTablesPeer::DATABASE_NAME);
try {
$oPro = AdditionalTablesPeer::retrieveByPk($sUID);
if (is_object($oPro) && get_class($oPro) == 'AdditionalTables') {
return true;
} else {
return false;
}
} catch (Exception $oError) {
throw ($oError);
}
}
public function deleteAll($id) public function deleteAll($id)
{ {
//deleting pm table //deleting pm table
@@ -390,34 +411,34 @@ class AdditionalTables extends BaseAdditionalTables
$cont = 0; $cont = 0;
$fieldAppUid = ''; $fieldAppUid = '';
foreach ($fieldsTable as $value) { foreach ($fieldsTable as $value) {
if ($value != 'APP_UID') { if ($value != 'APP_UID') {
if (($cont+1) == $countField) { if (($cont+1) == $countField) {
if ($aData['FIELDS'][$cont]['FLD_TYPE'] == 'VARCHAR') { if ($aData['FIELDS'][$cont]['FLD_TYPE'] == 'VARCHAR') {
$stringOr .= '$oCriteria->getNewCriterion(' . $sClassPeerName . '::' . strtoupper($value) . ', "%' . $filter . '%", Criteria::LIKE)'; $stringOr .= '$oCriteria->getNewCriterion(' . $sClassPeerName . '::' . strtoupper($value) . ', "%' . $filter . '%", Criteria::LIKE)';
} else { } else {
$stringOr .= '$oCriteria->getNewCriterion(' . $sClassPeerName . '::' . strtoupper($value) . ', "' . $filter . '", Criteria::LIKE)'; $stringOr .= '$oCriteria->getNewCriterion(' . $sClassPeerName . '::' . strtoupper($value) . ', "' . $filter . '", Criteria::LIKE)';
} }
} else { } else {
if ($aData['FIELDS'][$cont]['FLD_TYPE'] == 'VARCHAR') { if ($aData['FIELDS'][$cont]['FLD_TYPE'] == 'VARCHAR') {
$stringOr .= '$oCriteria->getNewCriterion(' . $sClassPeerName . '::' . strtoupper($value) . ', "%' . $filter . '%", Criteria::LIKE)->addOr('; $stringOr .= '$oCriteria->getNewCriterion(' . $sClassPeerName . '::' . strtoupper($value) . ', "%' . $filter . '%", Criteria::LIKE)->addOr(';
} else { } else {
$stringOr .= '$oCriteria->getNewCriterion(' . $sClassPeerName . '::' . strtoupper($value) . ', "' . $filter . '", Criteria::LIKE)->addOr('; $stringOr .= '$oCriteria->getNewCriterion(' . $sClassPeerName . '::' . strtoupper($value) . ', "' . $filter . '", Criteria::LIKE)->addOr(';
} }
} }
} else { } else {
$fieldAppUid = $cont; $fieldAppUid = $cont;
} }
$cont++; $cont++;
} }
for ($c = 0; $c < $countField-1; $c++) { for ($c = 0; $c < $countField-1; $c++) {
if ($fieldAppUid !== $c) { if ($fieldAppUid !== $c) {
$stringOr .= ')'; $stringOr .= ')';
} }
} }
$stringOr .= ');'; $stringOr .= ');';
eval($stringOr); eval($stringOr);
$oCriteriaCount = clone $oCriteria; $oCriteriaCount = clone $oCriteria;
eval('$count = ' . $sClassPeerName . '::doCount($oCriteria);'); eval('$count = ' . $sClassPeerName . '::doCount($oCriteria);');
} }

View File

@@ -164,7 +164,7 @@ class DataBaseConnection
} else { } else {
// TEST CONNECTION // TEST CONNECTION
$allData = $this->getDataBaseConnection($pro_uid, $dataDBConnection['DBS_UID']); $allData = $this->getDataBaseConnection($pro_uid, $dataDBConnection['DBS_UID']);
$dataTest = array_merge($allData, $dataDBConnection); $dataTest = array_merge($allData, $dataDBConnection, array('DBS_PASSWORD' => $passOrigin));
$resTest = $this->testConnection($dataTest); $resTest = $this->testConnection($dataTest);
if (!$resTest['resp']) { if (!$resTest['resp']) {
throw (new \Exception($resTest['message'])); throw (new \Exception($resTest['message']));

View File

@@ -45,14 +45,14 @@ class ReportTable
*/ */
public function getReportTable($pro_uid, $rep_uid, $validate = true) public function getReportTable($pro_uid, $rep_uid, $validate = true)
{ {
$repData = array();
//VALIDATION //VALIDATION
if ($validate) { if ($validate) {
$pro_uid = $this->validateProUid($pro_uid); $pro_uid = $this->validateProUid($pro_uid);
$rep_uid = $this->validateRepUid($rep_uid);
$repData['PRO_UID'] = $pro_uid; $repData['PRO_UID'] = $pro_uid;
} }
$repData = array();
$additionalTables = new AdditionalTables(); $additionalTables = new AdditionalTables();
// REPORT TABLE PROPERTIES // REPORT TABLE PROPERTIES
@@ -81,6 +81,46 @@ class ReportTable
return $repData; return $repData;
} }
/**
* Get data for ReportTable
* @var string $pro_uid. Uid for Process
* @var string $rep_uid. Uid for Report Table
* @var string $validate. Flag for validate
*
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return array
*/
public function getDataReportTableData($pro_uid, $rep_uid)
{
//VALIDATION
if ($validate) {
$pro_uid = $this->validateProUid($pro_uid);
$rep_uid = $this->validateRepUid($rep_uid);
$repData['PRO_UID'] = $pro_uid;
}
$additionalTables = new AdditionalTables();
$table = $additionalTables->load($rep_uid, true);
$result = $additionalTables->getAllData($rep_uid);
$primaryKeys = $additionalTables->getPrimaryKeys();
if (is_array($result['rows'])) {
foreach ($result['rows'] as $i => $row) {
$result['rows'][$i] = array_change_key_case($result['rows'][$i], CASE_LOWER);
$primaryKeysValues = array ();
foreach ($primaryKeys as $key) {
$primaryKeysValues[] = isset( $row[$key['FLD_NAME']] ) ? $row[$key['FLD_NAME']] : '';
}
$result['rows'][$i]['__index__'] = G::encrypt( implode( ',', $primaryKeysValues ), 'pmtable' );
}
} else {
$result['rows'] = array();
}
return $result;
}
/** /**
* Save Data for Report Table * Save Data for Report Table
* @var string $pro_uid. Uid for Process * @var string $pro_uid. Uid for Process
@@ -269,7 +309,7 @@ class ReportTable
); );
$oFields->create( $field ); $oFields->create( $field );
} }
$this->generateDataReport($pro_uid, $rep_uid); $this->generateDataReport($pro_uid, $rep_uid, false);
if ($createRep) { if ($createRep) {
return $this->getReportTable($pro_uid, $rep_uid, false); return $this->getReportTable($pro_uid, $rep_uid, false);
} }
@@ -287,6 +327,9 @@ class ReportTable
*/ */
public function updateReportTable($pro_uid, $rep_data) public function updateReportTable($pro_uid, $rep_data)
{ {
$pro_uid = $this->validateProUid($pro_uid);
$rep_uid = $this->validateRepUid($rep_uid);
$rep_uid = trim($rep_data['rep_uid']); $rep_uid = trim($rep_data['rep_uid']);
$dataValidate = array(); $dataValidate = array();
@@ -322,6 +365,9 @@ class ReportTable
*/ */
public function deleteReportTable($pro_uid, $rep_uid) public function deleteReportTable($pro_uid, $rep_uid)
{ {
$pro_uid = $this->validateProUid($pro_uid);
$rep_uid = $this->validateRepUid($rep_uid);
$at = new AdditionalTables(); $at = new AdditionalTables();
$table = $at->load( $rep_uid ); $table = $at->load( $rep_uid );
@@ -346,7 +392,13 @@ class ReportTable
* *
* @return void * @return void
*/ */
public function generateDataReport($pro_uid, $rep_uid) { public function generateDataReport($pro_uid, $rep_uid, $validate = true) {
if ($validate) {
$pro_uid = $this->validateProUid($pro_uid);
$rep_uid = $this->validateRepUid($rep_uid);
G::loadClass('pmTable');
}
$additionalTables = new AdditionalTables(); $additionalTables = new AdditionalTables();
$table = $additionalTables->load($rep_uid); $table = $additionalTables->load($rep_uid);
$additionalTables->populateReportTable( $additionalTables->populateReportTable(
@@ -582,6 +634,27 @@ class ReportTable
return $pro_uid; return $pro_uid;
} }
/**
* Validate Report Table Uid
* @var string $rep_uid. Uid for report table
*
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return string
*/
public function validateRepUid ($rep_uid) {
$rep_uid = trim($rep_uid);
if ($rep_uid == '') {
throw (new \Exception("The report table with rep_uid: '', does not exist."));
}
$oAdditionalTables = new \AdditionalTables();
if (!($oAdditionalTables->exists($rep_uid))) {
throw (new \Exception("The report table with rep_uid: '$rep_uid', does not exist."));
}
return $rep_uid;
}
/** /**
* Validate Report Table Name * Validate Report Table Name
* @var string $rep_tab_name. Name for report table * @var string $rep_tab_name. Name for report table
@@ -713,7 +786,7 @@ class ReportTable
break; break;
} }
G::loadClass( 'pmTable' ); G::loadClass('pmTable');
$columnsTypes = \PmTable::getPropelSupportedColumnTypes(); $columnsTypes = \PmTable::getPropelSupportedColumnTypes();
$res = array_search($fld_type, $columnsTypes); $res = array_search($fld_type, $columnsTypes);

View File

@@ -54,6 +54,46 @@ class ReportTable extends Api
} }
} }
/**
* @param string $prj_uid {@min 1} {@max 32}
* @param string $rep_uid {@min 1} {@max 32}
* @return array
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @url GET /:prj_uid/report-table/:rep_uid/populate
*/
public function doGetPopulateReportTable($prj_uid, $rep_uid)
{
try {
$oReportTable = new \BusinessModel\ReportTable();
$response = $oReportTable->generateDataReport($prj_uid, $rep_uid);
return $response;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @param string $prj_uid {@min 1} {@max 32}
* @param string $rep_uid {@min 1} {@max 32}
* @return array
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @url GET /:prj_uid/report-table/:rep_uid/data
*/
public function doGetReportTableData($prj_uid, $rep_uid)
{
try {
$oReportTable = new \BusinessModel\ReportTable();
$response = $oReportTable->getDataReportTableData($prj_uid, $rep_uid);
return $response;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/** /**
* @param string $prj_uid {@min 1} {@max 32} * @param string $prj_uid {@min 1} {@max 32}
* @param array $request_data * @param array $request_data