Updating /project endpint, now is working GET /projects/{prj_uid} and /projects methods (only is loading diagram's activities)

This commit is contained in:
Erik Amaru Ortiz
2014-02-06 11:00:15 -04:00
parent e714847d79
commit 6b8ca3c9ee
6 changed files with 204 additions and 33 deletions

View File

@@ -34,9 +34,24 @@ class Project extends Api
public function get($prjUid)
{
try {
$projects = new \StdClass(); //TODO
$bwp = \ProcessMaker\Project\Adapter\BpmnWorkflow::load($prjUid);
return $projects;
$project = array_change_key_case($bwp->getProject(), CASE_LOWER);
$diagram = $bwp->getDiagram();
if (! is_null($diagram)) {
$diagram = array_change_key_case($diagram, CASE_LOWER);
$diagram["activities"] = $bwp->getActivities(array("changeCaseTo" => CASE_LOWER));
$diagram["events"] = $bwp->getEvents();
$diagram["flows"] = $bwp->getFlows();
$diagram["artifacts"] = $bwp->getArtifacts();
$diagram["laneset"] = $bwp->getLanesets();
$diagram["lanes"] = $bwp->getLanes();
$project["diagrams"][] = $diagram;
}
return $project;
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
@@ -48,27 +63,28 @@ class Project extends Api
public function post($request_data)
{
try {
$config = array();
$config['project'] = array('replace_uids' => true);
// NEED REFACTOR
// $config = array();
// $config['project'] = array('replace_uids' => true);
//
// $bpmnModel = new BpmnModel();
// $result = $bpmnModel->createProject($request_data, $config['project']['replace_uids']);
//
// if (array_key_exists('prj_uid', $result)) {
// $prjUid = $result['prj_uid'];
// } else {
// $prjUid = $result[0]['new_uid'];
// }
//
// $wfProcess = Workflow::loadFromBpmnProject($prjUid);
//
// $process = new \BusinessModel\Process();
// $userUid = $this->getUserId();
// $data = array('process' => $wfProcess);
//
// $process->createProcess($userUid, $data);
$bpmnModel = new BpmnModel();
$result = $bpmnModel->createProject($request_data, $config['project']['replace_uids']);
if (array_key_exists('prj_uid', $result)) {
$prjUid = $result['prj_uid'];
} else {
$prjUid = $result[0]['new_uid'];
}
$wfProcess = Workflow::loadFromBpmnProject($prjUid);
$process = new \BusinessModel\Process();
$userUid = $this->getUserId();
$data = array('process' => $wfProcess);
$process->createProcess($userUid, $data);
return $result;
// return $result;
} catch (\Exception $e) {
// TODO in case that $process->createProcess($userUid, $data); fails maybe the BPMN project was created successfully
// so, we need remove it or change the creation order.
@@ -81,7 +97,8 @@ class Project extends Api
{
try {
$result = BpmnModel::updateProject($prjUid, $request_data);
//$result = BpmnModel::updateProject($prjUid, $request_data);
return $result;
} catch (\Exception $e) {