ProcessMaker-MA "Group (behat)"

- Se han implementado los siguientes features:
    GET    /api/1.0/{workspace}/groups?filter=abc&start=0&limit=25
    GET    /api/1.0/{workspace}/group/{grp_uid}
    POST   /api/1.0/{workspace}/group
    PUT    /api/1.0/{workspace}/group/{grp_uid}
    DELETE /api/1.0/{workspace}/group/{grp_uid}
This commit is contained in:
Victor Saisa Lopez
2014-01-30 14:30:18 -04:00
parent 25b48b40c7
commit cbc1913298
4 changed files with 235 additions and 35 deletions

View File

@@ -3,10 +3,31 @@ namespace BusinessModel;
class Group
{
private $formatFieldNameInUppercase = true;
private $arrayMsgExceptionParam = array();
/**
* Set the format of the fields name (uppercase, lowercase)
*
* @param bool $flag Value that set the format
*
* return void
*/
public function setFormatFieldNameInUppercase($flag)
{
try {
$this->formatFieldNameInUppercase = $flag;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Set exception messages for parameters
*
* @param array $arrayData Data with the params
*
* return void
*/
public function setArrayMsgExceptionParam($arrayData)
{
@@ -18,21 +39,18 @@ class Group
}
/**
* Verify if doesn't exist the Group in table GROUP
* Get the name of the field according to the format
*
* @param string $groupUid Unique id of Group
* @param string $fieldName Field name
*
* return void Throw exception if doesn't exist the Group in table GROUP
* return string Return the field name according the format
*/
public function throwExceptionIfNoExistsGroup($groupUid)
public function getFieldNameByFormatFieldName($fieldName)
{
$group = new \Groupwf();
if (!$group->GroupwfExists($groupUid)) {
$msg = (isset($this->arrayMsgExceptionParam["groupUid"]))? str_replace(array("{0}"), array($this->arrayMsgExceptionParam["groupUid"]), "Invalid value specified for \"{0}\"") . " / " : "";
$msg = $msg . str_replace(array("{0}", "{1}"), array($groupUid, "GROUPWF"), "The UID \"{0}\" doesn't exist in table {1}");
throw (new \Exception($msg));
try {
return ($this->formatFieldNameInUppercase)? strtoupper($fieldName) : strtolower($fieldName);
} catch (\Exception $e) {
throw $e;
}
}
@@ -44,7 +62,7 @@ class Group
*
* return bool Return true if exists the title of a Group, false otherwise
*/
public function existsTitle($title, $groupUidExclude = "")
public function existsTitle($groupTitle, $groupUidExclude = "")
{
try {
$delimiter = \DBAdapter::getStringDelimiter();
@@ -65,7 +83,7 @@ class Group
$criteria->add(\GroupwfPeer::GRP_UID, $groupUidExclude, \Criteria::NOT_EQUAL);
}
$criteria->add("CT.CON_VALUE", $title, \Criteria::EQUAL);
$criteria->add("CT.CON_VALUE", $groupTitle, \Criteria::EQUAL);
$rsCriteria = \GroupwfPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
@@ -80,6 +98,43 @@ class Group
}
}
/**
* Verify if status has invalid value
*
* @param string $groupStatus Status
*
* return void Throw exception if status has invalid value
*/
public function throwExceptionIfHaveInvalidValueInStatus($groupStatus)
{
if (!in_array($groupStatus, array("ACTIVE", "INACTIVE"))) {
$field = $this->getFieldNameByFormatFieldName("GRP_STATUS");
throw (new \Exception(str_replace(array("{0}"), array($field), "Invalid value specified for \"{0}\"")));
}
}
/**
* Verify if doesn't exist the Group in table GROUP
*
* @param string $groupUid Unique id of Group
*
* return void Throw exception if doesn't exist the Group in table GROUP
*/
public function throwExceptionIfNoExistsGroup($groupUid)
{
$group = new \Groupwf();
if (!$group->GroupwfExists($groupUid)) {
$field = $this->getFieldNameByFormatFieldName("GRP_UID");
$msg = str_replace(array("{0}"), array($field), "Invalid value specified for \"{0}\"") . " / ";
$msg = $msg . str_replace(array("{0}", "{1}"), array($groupUid, "GROUPWF"), "The UID \"{0}\" doesn't exist in table {1}");
throw (new \Exception($msg));
}
}
/**
* Verify if exists the title of a Group
*
@@ -88,10 +143,12 @@ class Group
*
* return void Throw exception if exists the title of a Group
*/
public function throwExceptionIfExistsTitle($title, $groupUidExclude = "")
public function throwExceptionIfExistsTitle($groupTitle, $groupUidExclude = "")
{
if ($this->existsTitle($title, $groupUidExclude)) {
$msg = (isset($this->arrayMsgExceptionParam["groupTitle"]))? str_replace(array("{0}"), array($this->arrayMsgExceptionParam["groupTitle"]), "Invalid value specified for \"{0}\"") . " / " : "";
if ($this->existsTitle($groupTitle, $groupUidExclude)) {
$field = $this->getFieldNameByFormatFieldName("GRP_TITLE");
$msg = str_replace(array("{0}"), array($field), "Invalid value specified for \"{0}\"") . " / ";
$msg = $msg . \G::LoadTranslation("ID_MSG_GROUP_NAME_EXISTS");
throw (new \Exception($msg));
@@ -114,25 +171,27 @@ class Group
//Verify data
if (!isset($arrayData["GRP_TITLE"])) {
throw (new \Exception(str_replace(array("{0}"), array(strtolower("GRP_TITLE")), "The \"{0}\" attribute is not defined")));
throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("GRP_TITLE")), "The \"{0}\" attribute is not defined")));
}
$arrayData["GRP_TITLE"] = trim($arrayData["GRP_TITLE"]);
if ($arrayData["GRP_TITLE"] == "") {
throw (new \Exception(str_replace(array("{0}"), array(strtolower("GRP_TITLE")), "The \"{0}\" attribute is empty")));
throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("GRP_TITLE")), "The \"{0}\" attribute is empty")));
}
if (!isset($arrayData["GRP_STATUS"])) {
throw (new \Exception(str_replace(array("{0}"), array(strtolower("GRP_STATUS")), "The \"{0}\" attribute is not defined")));
throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("GRP_STATUS")), "The \"{0}\" attribute is not defined")));
}
$arrayData["GRP_STATUS"] = trim($arrayData["GRP_STATUS"]);
if ($arrayData["GRP_STATUS"] == "") {
throw (new \Exception(str_replace(array("{0}"), array(strtolower("GRP_STATUS")), "The \"{0}\" attribute is empty")));
throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("GRP_STATUS")), "The \"{0}\" attribute is empty")));
}
$this->throwExceptionIfHaveInvalidValueInStatus($arrayData["GRP_STATUS"]);
$this->throwExceptionIfExistsTitle($arrayData["GRP_TITLE"]);
//Create
@@ -141,11 +200,13 @@ class Group
$groupUid = $group->create($arrayData);
//Return
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
$arrayData = array_merge(array("GRP_UID" => $groupUid), $arrayData);
unset($arrayData["grp_uid"]);
if (!$this->formatFieldNameInUppercase) {
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
}
return array_merge(array("grp_uid" => $groupUid), $arrayData);
return $arrayData;
} catch (\Exception $e) {
throw $e;
}
@@ -171,7 +232,7 @@ class Group
$arrayData["GRP_TITLE"] = trim($arrayData["GRP_TITLE"]);
if ($arrayData["GRP_TITLE"] == "") {
throw (new \Exception(str_replace(array("{0}"), array(strtolower("GRP_TITLE")), "The \"{0}\" attribute is empty")));
throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("GRP_TITLE")), "The \"{0}\" attribute is empty")));
}
}
@@ -179,10 +240,14 @@ class Group
$arrayData["GRP_STATUS"] = trim($arrayData["GRP_STATUS"]);
if ($arrayData["GRP_STATUS"] == "") {
throw (new \Exception(str_replace(array("{0}"), array(strtolower("GRP_STATUS")), "The \"{0}\" attribute is empty")));
throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("GRP_STATUS")), "The \"{0}\" attribute is empty")));
}
}
if (isset($arrayData["GRP_STATUS"])) {
$this->throwExceptionIfHaveInvalidValueInStatus($arrayData["GRP_STATUS"]);
}
if (isset($arrayData["GRP_TITLE"])) {
$this->throwExceptionIfExistsTitle($arrayData["GRP_TITLE"], $groupUid);
}
@@ -197,7 +262,11 @@ class Group
//Return
unset($arrayData["GRP_UID"]);
return array_change_key_case($arrayData, CASE_LOWER);
if (!$this->formatFieldNameInUppercase) {
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
}
return $arrayData;
} catch (\Exception $e) {
throw $e;
}
@@ -377,11 +446,11 @@ class Group
{
try {
return array(
"grp_uid" => $record["GRP_UID"],
"grp_title" => $record["GRP_TITLE"],
"grp_status" => $record["GRP_STATUS"],
"grp_users" => (int)($record["GRP_USERS"]),
"grp_tasks" => (int)($record["GRP_TASKS"])
$this->getFieldNameByFormatFieldName("GRP_UID") => $record["GRP_UID"],
$this->getFieldNameByFormatFieldName("GRP_TITLE") => $record["GRP_TITLE"],
$this->getFieldNameByFormatFieldName("GRP_STATUS") => $record["GRP_STATUS"],
$this->getFieldNameByFormatFieldName("GRP_USERS") => (int)($record["GRP_USERS"]),
$this->getFieldNameByFormatFieldName("GRP_TASKS") => (int)($record["GRP_TASKS"])
);
} catch (\Exception $e) {
throw $e;

View File

@@ -18,6 +18,7 @@ class Group extends Api
{
try {
$group = new \BusinessModel\Group();
$group->setFormatFieldNameInUppercase(false);
$response = $group->getGroups(array("filter" => $filter), null, null, $start, $limit);
@@ -36,7 +37,7 @@ class Group extends Api
{
try {
$group = new \BusinessModel\Group();
$group->setArrayMsgExceptionParam(array("groupUid" => "grp_uid"));
$group->setFormatFieldNameInUppercase(false);
$response = $group->getGroup($grp_uid);
@@ -62,7 +63,7 @@ class Group extends Api
) {
try {
$group = new \BusinessModel\Group();
$group->setArrayMsgExceptionParam(array("groupTitle" => "grp_title"));
$group->setFormatFieldNameInUppercase(false);
$arrayData = $group->create($request_data);
@@ -90,7 +91,7 @@ class Group extends Api
) {
try {
$group = new \BusinessModel\Group();
$group->setArrayMsgExceptionParam(array("groupUid" => "grp_uid", "groupTitle" => "grp_title"));
$group->setFormatFieldNameInUppercase(false);
$arrayData = $group->update($grp_uid, $request_data);
} catch (\Exception $e) {
@@ -107,7 +108,7 @@ class Group extends Api
{
try {
$group = new \BusinessModel\Group();
$group->setArrayMsgExceptionParam(array("groupUid" => "grp_uid"));
$group->setFormatFieldNameInUppercase(false);
$group->delete($grp_uid);
} catch (\Exception $e) {