Merge branch 'master' of bitbucket.org:colosa/processmaker

This commit is contained in:
Brayan Osmar Pereyra Suxo
2014-04-02 16:06:27 -04:00
6 changed files with 419 additions and 29 deletions

View File

@@ -273,7 +273,7 @@ class Calendar
$this->throwExceptionIfExistsName($arrayData["CAL_NAME"], $this->arrayFieldNameForException["calendarName"]);
if (!(count($arrayData["CAL_WORK_DAYS"]) >= 3)) {
if (isset($arrayData["CAL_WORK_DAYS"]) && count($arrayData["CAL_WORK_DAYS"]) < 3) {
throw (new \Exception(\G::LoadTranslation("ID_MOST_AT_LEAST_3_DAY")));
}
@@ -294,6 +294,10 @@ class Calendar
if (isset($arrayData["CAL_WORK_HOUR"])) {
foreach ($arrayData["CAL_WORK_HOUR"] as $value) {
if ($value["DAY"] != "ALL" && !in_array($value["DAY"], $arrayData["CAL_WORK_DAYS"])) {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($this->arrayWorkHourFieldNameForException["day"], $this->arrayFieldNameForException["calendarWorkDays"]), "Value specified for \"{0}\" does not exists in \"{1}\"")));
}
$arrayCalendarWorkHour[] = array(
"CALENDAR_BUSINESS_DAY" => $this->workDaysReplaceData($value["DAY"]),
"CALENDAR_BUSINESS_START" => $value["HOUR_START"],
@@ -346,6 +350,136 @@ class Calendar
}
}
/**
* Update Calendar
*
* @param string $calendarUid Unique id of Calendar
* @param array $arrayData Data
*
* return array Return data of the Calendar updated
*/
public function update($calendarUid, $arrayData)
{
try {
$arrayData = \G::array_change_key_case2($arrayData, CASE_UPPER);
//Verify data
$process = new \BusinessModel\Process();
$this->throwExceptionIfNotExistsCalendar($calendarUid, $this->arrayFieldNameForException["calendarUid"]);
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, false);
if (isset($arrayData["CAL_NAME"])) {
$this->throwExceptionIfExistsName($arrayData["CAL_NAME"], $this->arrayFieldNameForException["calendarName"], $calendarUid);
}
if (isset($arrayData["CAL_WORK_DAYS"]) && count($arrayData["CAL_WORK_DAYS"]) < 3) {
throw (new \Exception(\G::LoadTranslation("ID_MOST_AT_LEAST_3_DAY")));
}
if (isset($arrayData["CAL_WORK_HOUR"])) {
foreach ($arrayData["CAL_WORK_HOUR"] as $value) {
$process->throwExceptionIfDataNotMetFieldDefinition($value, $this->arrayWorkHourFieldDefinition, $this->arrayWorkHourFieldNameForException, true);
}
}
if (isset($arrayData["CAL_HOLIDAY"])) {
foreach ($arrayData["CAL_HOLIDAY"] as $value) {
$process->throwExceptionIfDataNotMetFieldDefinition($value, $this->arrayHolidayFieldDefinition, $this->arrayHolidayFieldNameForException, true);
}
}
//Set variables
$arrayCalendarData = \G::array_change_key_case2($this->getCalendar($calendarUid), CASE_UPPER);
$calendarWorkDays = (isset($arrayData["CAL_WORK_DAYS"]))? $arrayData["CAL_WORK_DAYS"] : $arrayCalendarData["CAL_WORK_DAYS"];
$arrayCalendarWorkHour = array();
$arrayAux = (isset($arrayData["CAL_WORK_HOUR"]))? $arrayData["CAL_WORK_HOUR"] : $arrayCalendarData["CAL_WORK_HOUR"];
foreach ($arrayAux as $value) {
if (isset($arrayData["CAL_WORK_HOUR"]) && $value["DAY"] != "ALL" && !in_array($value["DAY"], $calendarWorkDays)) {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($this->arrayWorkHourFieldNameForException["day"], $this->arrayFieldNameForException["calendarWorkDays"]), "Value specified for \"{0}\" does not exists in \"{1}\"")));
}
$arrayCalendarWorkHour[] = array(
"CALENDAR_BUSINESS_DAY" => $this->workDaysReplaceData($value["DAY"]),
"CALENDAR_BUSINESS_START" => $value["HOUR_START"],
"CALENDAR_BUSINESS_END" => $value["HOUR_END"]
);
}
$arrayCalendarHoliday = array();
$arrayAux = (isset($arrayData["CAL_HOLIDAY"]))? $arrayData["CAL_HOLIDAY"] : $arrayCalendarData["CAL_HOLIDAY"];
foreach ($arrayAux as $value) {
$arrayCalendarHoliday[] = array(
"CALENDAR_HOLIDAY_NAME" => $value["NAME"],
"CALENDAR_HOLIDAY_START" => $value["DATE_START"],
"CALENDAR_HOLIDAY_END" => $value["DATE_END"]
);
}
$arrayDataAux = array();
$arrayDataAux["CALENDAR_UID"] = $calendarUid;
$arrayDataAux["CALENDAR_NAME"] = (isset($arrayData["CAL_NAME"]))? $arrayData["CAL_NAME"] : $arrayCalendarData["CAL_NAME"];
$arrayDataAux["CALENDAR_DESCRIPTION"] = (isset($arrayData["CAL_DESCRIPTION"]))? $arrayData["CAL_DESCRIPTION"] : $arrayCalendarData["CAL_DESCRIPTION"];
$arrayDataAux["CALENDAR_WORK_DAYS"] = explode("|", $this->workDaysReplaceData(implode("|", $calendarWorkDays)));
$arrayDataAux["CALENDAR_STATUS"] = (isset($arrayData["CAL_STATUS"]))? $arrayData["CAL_STATUS"] : $arrayCalendarData["CAL_STATUS"];
$arrayDataAux["BUSINESS_DAY"] = $arrayCalendarWorkHour;
$arrayDataAux["HOLIDAY"] = $arrayCalendarHoliday;
//Update
$calendarDefinition = new \CalendarDefinition();
$calendarDefinition->saveCalendarInfo($arrayDataAux);
//Return
if (!$this->formatFieldNameInUppercase) {
$arrayData = \G::array_change_key_case2($arrayData, CASE_LOWER);
}
return $arrayData;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Delete Calendar
*
* @param string $calendarUid Unique id of Calendar
*
* return void
*/
public function delete($calendarUid)
{
try {
//Verify data
$calendarDefinition = new \CalendarDefinition();
$this->throwExceptionIfNotExistsCalendar($calendarUid, $this->arrayFieldNameForException["calendarUid"]);
$arrayAux = $calendarDefinition->getAllCounterByCalendar("USER");
$nU = (isset($arrayAux[$calendarUid]))? $arrayAux[$calendarUid] : 0;
$arrayAux = $calendarDefinition->getAllCounterByCalendar("TASK");
$nT = (isset($arrayAux[$calendarUid]))? $arrayAux[$calendarUid] : 0;
$arrayAux = $calendarDefinition->getAllCounterByCalendar("PROCESS");
$nP = (isset($arrayAux[$calendarUid]))? $arrayAux[$calendarUid] : 0;
if ($nU + $nT + $nP > 0) {
throw (new \Exception(\G::LoadTranslation("ID_MSG_CANNOT_DELETE_CALENDAR")));
}
//Delete
$calendarDefinition->deleteCalendar($calendarUid);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get criteria for Calendar
*

View File

@@ -96,7 +96,6 @@ class ProcessCategory
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\ProcessCategoryPeer::CATEGORY_UID);
$criteria->addSelectColumn(\ProcessCategoryPeer::CATEGORY_PARENT);
$criteria->addSelectColumn(\ProcessCategoryPeer::CATEGORY_NAME);
@@ -232,5 +231,172 @@ class ProcessCategory
throw $e;
}
}
}
/**
* Get a Process Category
*
* @param string $cat_uid Category Id
*
* return array Return an object with the Process Category
*/
public function getCategory($cat_uid)
{
try {
$oProcessCategory = '';
$process = new \Process();
$oTotalProcessesByCategory = $process->getAllProcessesByCategory();
$criteria = $this->getAProcessCategoryCriteria($cat_uid);
$criteriaCount = clone $criteria;
$criteriaCount->clearSelectColumns();
$criteriaCount->addSelectColumn("COUNT(" . \ProcessCategoryPeer::CATEGORY_UID . ") AS NUM_REC");
$rsCriteriaCount = \ProcessCategoryPeer::doSelectRS($criteriaCount);
$rsCriteriaCount->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteriaCount->next();
$rsCriteria = \ProcessCategoryPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
$row["CATEGORY_TOTAL_PROCESSES"] = (isset($oTotalProcessesByCategory[$row["CATEGORY_UID"]]))? $oTotalProcessesByCategory[$row["CATEGORY_UID"]] : 0;
$oProcessCategory = $this->getProcessCategoryDataFromRecord($row);
}
//Return
if ($oProcessCategory != '') {
return $oProcessCategory;
} else {
throw (new \Exception( 'The Category with cat_uid: '.$cat_uid.' doesn\'t exist!'));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Post Process Category
*
* @param string $cat_name Name of Category
*
* return array
*/
public function addCategory($cat_name)
{
try {
require_once 'classes/model/ProcessCategory.php';
$catName = trim( $cat_name );
if ($this->existsName( $cat_name )) {
throw (new \Exception( 'cat_name. Duplicate Process Category name'));
}
$catUid = \G::GenerateUniqueID();
$pcat = new \ProcessCategory();
$pcat->setNew( true );
$pcat->setCategoryUid( $catUid );
$pcat->setCategoryName( $catName );
$pcat->save();
$oProcessCategory = array_change_key_case($this->getCategory( $catUid ), CASE_LOWER);
//Return
return $oProcessCategory;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Put Process Category
*
* @param string $cat_uid Category id
* @param string $cat_name Category Name
*
* return array
*/
public function updateCategory($cat_uid, $cat_name)
{
try {
require_once 'classes/model/ProcessCategory.php';
$catUID = $cat_uid;
$catName = trim( $cat_name );
if ($this->existsName( $cat_name )) {
throw (new \Exception( 'cat_name. Duplicate Process Category name'));
}
$pcat = new \ProcessCategory();
$pcat->setNew( false );
$pcat->setCategoryUid( $catUID );
$pcat->setCategoryName( $catName );
$pcat->save();
$oProcessCategory = array_change_key_case($this->getCategory( $cat_uid ), CASE_LOWER);
//Return
return $oProcessCategory;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Delete Process Category
*
* @param string $cat_uid Category id
*
* return array
*/
public function deleteCategory($cat_uid)
{
try {
require_once 'classes/model/ProcessCategory.php';
$criteria = $this->getAProcessCategoryCriteria($cat_uid);
$rsCriteria = \ProcessCategoryPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteria->next();
$row = $rsCriteria->getRow();
if ($row) {
$cat = new \ProcessCategory();
$cat->setCategoryUid( $cat_uid );
$cat->delete();
} else {
throw (new \Exception( 'The Category with cat_uid: '.$cat_uid.' doesn\'t exist!'));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get criteria for Process Category
*
* return object
*/
public function getAProcessCategoryCriteria($cat_uid)
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\ProcessCategoryPeer::CATEGORY_UID);
$criteria->addSelectColumn(\ProcessCategoryPeer::CATEGORY_PARENT);
$criteria->addSelectColumn(\ProcessCategoryPeer::CATEGORY_NAME);
$criteria->addSelectColumn(\ProcessCategoryPeer::CATEGORY_ICON);
$criteria->add(\ProcessCategoryPeer::CATEGORY_UID, $cat_uid);
return $criteria;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Checks if the name exists
*
* @param string $name Name
*
* return bool Return true if the name exists, false otherwise
*/
public function existsName($name)
{
try {
$criteria = new \Criteria("workflow");
$criteria->add(\ProcessCategoryPeer::CATEGORY_NAME, $name, \Criteria::EQUAL);
$rsCriteria = \ProcessCategoryPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteria->next();
return $rsCriteria->getRow();
} catch (\Exception $e) {
throw $e;
}
}
}

View File

@@ -71,5 +71,40 @@ class Calendar extends Api
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @url PUT /:cal_uid
*
* @param string $cal_uid {@min 32}{@max 32}
* @param array $request_data
*/
public function doPut($cal_uid, $request_data)
{
try {
$calendar = new \BusinessModel\Calendar();
$calendar->setFormatFieldNameInUppercase($this->formatFieldNameInUppercase);
$arrayData = $calendar->update($cal_uid, $request_data);
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @url DELETE /:cal_uid
*
* @param string $cal_uid {@min 32}{@max 32}
*/
public function doDelete($cal_uid)
{
try {
$calendar = new \BusinessModel\Calendar();
$calendar->setFormatFieldNameInUppercase($this->formatFieldNameInUppercase);
$calendar->delete($cal_uid);
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
}

View File

@@ -14,7 +14,7 @@ class ProcessCategory extends Api
private $formatFieldNameInUppercase = false;
/**
* @url GET /categories
* @url GET
*/
public function doGetCategories($filter = null, $start = null, $limit = null)
{
@@ -29,5 +29,77 @@ class ProcessCategory extends Api
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
}
/**
* @url GET /:cat_uid
*
* @param string $cat_uid {@min 32}{@max 32}
*/
public function doGetCategory($cat_uid)
{
try {
$processCategory = new \BusinessModel\ProcessCategory();
$processCategory->setFormatFieldNameInUppercase($this->formatFieldNameInUppercase);
$response = $processCategory->getCategory($cat_uid);
return $response;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @url POST
*
* @param string $cat_name
*
*/
public function doPostCategory($cat_name)
{
try {
$processCategory = new \BusinessModel\ProcessCategory();
$response = $processCategory->addCategory($cat_name);
return $response;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @url PUT /:cat_uid
*
* @param string $cat_uid {@min 32}{@max 32}
* @param string $cat_name
*
*/
public function doPutCategory($cat_uid, $cat_name)
{
try {
$processCategory = new \BusinessModel\ProcessCategory();
$response = $processCategory->updateCategory($cat_uid, $cat_name);
return $response;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @url DELETE /:cat_uid
*
* @param string $cat_uid {@min 32}{@max 32}
*
*/
public function doDeleteCategory($cat_uid)
{
try {
$processCategory = new \BusinessModel\ProcessCategory();
$processCategory->deleteCategory($cat_uid);
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
}

View File

@@ -65,4 +65,10 @@ debug = 1
[alias: cases]
case = "Services\Api\ProcessMaker\Case"
input-document = "Services\Api\ProcessMaker\Cases\InputDocument"
output-document = "Services\Api\ProcessMaker\Cases\OutputDocument"
output-document = "Services\Api\ProcessMaker\Cases\OutputDocument"
[alias: category]
category = "Services\Api\ProcessMaker\ProcessCategory"
[alias: categories]
category = "Services\Api\ProcessMaker\ProcessCategory"

View File

@@ -1,23 +0,0 @@
<?php
$accesstoken = "e79057f4276661bedb6154eed3834f6cbd738853";
$headr = array();
$inp_doc_uid = '68671480353319e5e1dee74089764900';
$tas_uid = '19582733053319e304cfa76025663570';
$app_doc_comment = 'desde script php';
$headr[] = 'Authorization: Bearer '.$accesstoken;
$file = "/home/wendy/uploadfiles/test1.html";
$url = "http://wendy.pmos.colosa.net/api/1.0/wendy/cases/64654381053382b8bb4c415067063003/input-document";
$ch = curl_init();
$a = array('form'=>'@'.$file, 'inp_doc_uid'=>$inp_doc_uid, 'tas_uid' =>$tas_uid, 'app_doc_comment' =>$app_doc_comment);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headr);
curl_setopt($ch, CURLOPT_POSTFIELDS, $a);
print "<h3>post</h3>";
print_r($a);
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);
curl_close($ch);
print "<h3>response var_dump</h3>";
var_dump($postResult);
print "<textarea cols='50' rows='10'>".$postResult."</textarea>";