Skip to content

Commit 21798d7

Browse files
committed
fix(api): use ObligationMap instead of Model class
Signed-off-by: Gaurav Mishra <[email protected]>
1 parent a5f29c3 commit 21798d7

File tree

4 files changed

+33
-69
lines changed

4 files changed

+33
-69
lines changed

src/www/ui/admin-obligation-file.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,6 @@ private function ObligationTopics()
4040
return ($topicarray);
4141
}
4242

43-
/** @brief get obligations list along with obligations id */
44-
public function getObligationsList()
45-
{
46-
$sql = "SELECT ob_pk, ob_topic from obligation_ref";
47-
$obligationsList = $this->dbManager->getRows($sql);
48-
return ($obligationsList);
49-
}
50-
51-
/** @brief get obligations Details along with obligations id */
52-
public function getObligationsDetails($id)
53-
{
54-
$sql = "SELECT * from obligation_ref WHERE ob_pk = $1";
55-
$obligationsDetails = $this->dbManager->getRows($sql, array($id));
56-
$obligationsArray=new Obligation($id);
57-
$finVal=$obligationsArray->getObligations($obligationsDetails);
58-
return ($finVal);
59-
}
60-
61-
/** @brief get obligations Details of all obligations */
62-
public function getAllObligationsDetails()
63-
{
64-
$sql = "SELECT * from obligation_ref";
65-
$obligationsDetails = $this->dbManager->getRows($sql);
66-
$obligationsArray=new Obligation(0);
67-
$finVal=$obligationsArray->getObligations($obligationsDetails);
68-
return ($finVal);
69-
}
70-
7143
/** @brief check if the text of this obligation is existing */
7244
private function isObligationTopicAndTextBlocked($obId,$topic,$text)
7345
{

src/www/ui/api/Controllers/ObligationController.php

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,7 @@ function obligationsDetails($request, $response, $args)
7474
return $response->withJson($returnVal->getArray(), $returnVal->getCode());
7575
}
7676

77-
$obligationInfo = $this->obligationMap->getObligationById($obligationId);
78-
$licenses = $this->obligationMap->getLicenseList($obligationId);
79-
$candidateLicenses = $this->obligationMap->getLicenseList($obligationId,
80-
true);
81-
$associatedLicenses = explode(";", $licenses);
82-
$associatedCandidateLicenses = explode(";", $candidateLicenses);
83-
84-
$obligation = Obligation::fromArray($obligationInfo, true,
85-
$associatedLicenses, $associatedCandidateLicenses);
77+
$obligation = $this->createExtendedObligationFromId($obligationId);
8678
return $response->withJson($obligation->getArray(), 200);
8779
}
8880

@@ -97,7 +89,32 @@ function obligationsDetails($request, $response, $args)
9789

9890
function obligationsAllDetails($request, $response, $args)
9991
{
100-
$listVal = $this->obligationFile->getAllObligationsDetails();
101-
return $response->withJson($listVal, 200);
92+
$obligationArray = [];
93+
$listVal = $this->obligationMap->getObligations();
94+
foreach ($listVal as $val) {
95+
$obligationId = intval($val['ob_pk']);
96+
$obligationArray[] = $this->createExtendedObligationFromId($obligationId)
97+
->getArray();
98+
}
99+
return $response->withJson($obligationArray, 200);
100+
}
101+
102+
/**
103+
* Create extended Obligation Model object for a given obligation ID.
104+
*
105+
* @param int $obligationId Obligation ID to get object for
106+
* @return Obligation Obligation model object for given id
107+
*/
108+
private function createExtendedObligationFromId($obligationId)
109+
{
110+
$obligationInfo = $this->obligationMap->getObligationById($obligationId);
111+
$licenses = $this->obligationMap->getLicenseList($obligationId);
112+
$candidateLicenses = $this->obligationMap->getLicenseList($obligationId,
113+
true);
114+
$associatedLicenses = explode(";", $licenses);
115+
$associatedCandidateLicenses = explode(";", $candidateLicenses);
116+
117+
return Obligation::fromArray($obligationInfo, true,
118+
$associatedLicenses, $associatedCandidateLicenses);
102119
}
103120
}

src/www/ui/api/Models/Obligation.php

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
* @brief Obligation
1111
*/
1212
namespace Fossology\UI\Api\Models;
13-
use Fossology\Lib\BusinessRules\ObligationMap;
1413

1514
/**
1615
* @class Obligation
@@ -94,6 +93,7 @@ class Obligation
9493
* @param string $text
9594
* @param string $classification
9695
* @param string $comment
96+
* @param boolean $extended
9797
*/
9898
public function __construct($id, $topic = "", $type = "", $text = "",
9999
$classification = "", $comment = "", $extended = false)
@@ -144,33 +144,6 @@ public function getArray()
144144
return $obligation;
145145
}
146146

147-
/**
148-
* Get Obligation elements as associative array
149-
* @return array
150-
*/
151-
public function getObligations($obligationsDetails)
152-
{
153-
$this->obligationMap = $GLOBALS['container']->get('businessrules.obligationmap');
154-
foreach ($obligationsDetails as $val) {
155-
$row['id'] = intval($val['ob_pk']);
156-
$row['type'] = $val['ob_type'];
157-
$row['topic'] = $val['ob_topic'];
158-
$row['text'] = $val['ob_text'];
159-
$row['classification'] = $val['ob_classification'];
160-
$row['modification'] = $val['ob_modifications'];
161-
$row['comment'] = $val['ob_comment'];
162-
$row['active'] = ($val['ob_active'] == "t" ? true : false);
163-
$row['textUpdatable'] = ($val['ob_text_updatable'] == "t" ? true : false);
164-
$row['hash'] = $val['ob_md5'];
165-
$associatedLicenses = explode(';', $this->obligationMap->getLicenseList($val['ob_pk']));
166-
$candidateLicenses = explode(';', $this->obligationMap->getLicenseList($val['ob_pk'], True));
167-
$row['associatedLicenses'] = ($associatedLicenses[0] != "" ? $associatedLicenses : []);
168-
$row['candidateLicenses'] = ($candidateLicenses[0] != "" ? $candidateLicenses : []);
169-
$finVal[] = $row;
170-
}
171-
return ($finVal);
172-
}
173-
174147
/**
175148
* Get the topic of the obligation
176149
* @return string

src/www/ui/api/documentation/openapi.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ paths:
282282
$ref: '#/components/schemas/ObligationExtended'
283283
default:
284284
$ref: '#/components/responses/defaultResponse'
285-
/obligations/:
285+
/obligations:
286286
get:
287287
operationId: getAllObligationsData
288288
tags:
@@ -296,7 +296,9 @@ paths:
296296
content:
297297
application/json:
298298
schema:
299-
$ref: '#/components/schemas/ObligationsDetails'
299+
type: array
300+
items:
301+
$ref: '#/components/schemas/ObligationExtended'
300302
default:
301303
$ref: '#/components/responses/defaultResponse'
302304

0 commit comments

Comments
 (0)