12 namespace Fossology\UI\Page;
18 use Symfony\Component\HttpFoundation\JsonResponse;
19 use Symfony\Component\HttpFoundation\Request;
20 use Symfony\Component\HttpFoundation\Response;
33 const NAME =
"admin_license_compatibility_rules";
131 function __construct()
133 parent::__construct(self::NAME,
135 self::TITLE =>
"License Compatibility Rules",
136 self::MENU_LIST =>
"Admin::License Admin::Compatibility Rules",
137 self::REQUIRES_LOGIN =>
true,
140 $this->compatibilityDao = $this->
getObject(
'dao.compatibility');
141 $this->licenseDao = $this->
getObject(
'dao.license');
148 protected function handle(Request $request)
150 if ($request->get(
'action') ===
'fetchLicenseData') {
153 if ($request->get(
"action",
"") ===
"fetchRules") {
157 if ($request->get(self::UPDATE_PARAM_NAME, 0) == 1) {
158 return new JsonResponse($this->
updateRules($request),
159 JsonResponse::HTTP_OK);
160 } elseif ($request->get(
"action", 0) ===
"deleterule") {
161 return new JsonResponse($this->
deleteRules($request),
162 JsonResponse::HTTP_OK);
163 } elseif ($request->get(
"action", 0) ===
"addrule") {
183 return $this->
render(
'admin_license_compatibility_rules.html.twig',
184 $this->mergeWithDefault($vars));
195 $licenseArray = $this->licenseDao->getLicenseArray(0);
196 $licenseArray = array_column($licenseArray,
'shortname',
'id');
197 $licenseList = [0 =>
"---"];
198 $licenseList += $licenseArray;
200 $licenseTypes = $SysConf[
'SYSCONFIG'][
'LicenseTypes'];
201 $licenseTypes = explode(
',', $licenseTypes);
202 $licenseTypes = array_map(
'trim', $licenseTypes);
203 $licenseTypes = [
"---", ...$licenseTypes];
204 $licenseTypeList = array_combine($licenseTypes, $licenseTypes);
206 return new JsonResponse([
207 'licenseArray' => $licenseList,
208 'licenseTypes' => $licenseTypeList,
209 ], JsonResponse::HTTP_OK);
219 $offset = intval($request->query->get(
'start', 0));
220 $limit = intval($request->query->get(
'length', 10));
221 $draw = intval($request->query->get(
'draw', 1));
222 $searchQuery = $_GET[
'search'][
'value'] ??
'';
224 if (!empty($searchQuery)) {
225 $searchQuery =
'%' . $searchQuery .
'%';
228 $totalCount = $this->compatibilityDao->getTotalRulesCount();
229 $filteredCount = empty($searchQuery) ? $totalCount : $this->compatibilityDao->getTotalRulesCount($searchQuery);
230 $ruleArray = $this->compatibilityDao->getAllRules($limit, $offset, $searchQuery);
232 return new JsonResponse([
234 "recordsTotal" => $totalCount,
235 "recordsFiltered" => $filteredCount,
236 "data" => $ruleArray,
237 ], JsonResponse::HTTP_OK);
246 $result = $this->compatibilityDao->insertEmptyRule();
248 return new JsonResponse([
"lr_pk" => $result], JsonResponse::HTTP_OK);
250 return new JsonResponse([
"error" =>
"Failed to add rule."], JsonResponse::HTTP_BAD_REQUEST);
265 $licFirstName = $request->get(self::FIRST_LIC_NAME_PARAM_NAME);
266 $insertFirstName = $request->get(self::INSERT_FIRST_LIC_NAME_PARAM_NAME);
268 $licSecondName = $request->get(self::SECOND_LIC_NAME_PARAM_NAME);
269 $insertSecondName = $request->get(self::INSERT_SECOND_LIC_NAME_PARAM_NAME);
271 $licFirstType = $request->get(self::FIRST_LIC_TYPE_PARAM_NAME);
272 $insertFirstType = $request->get(self::INSERT_FIRST_LIC_TYPE_PARAM_NAME);
274 $licSecondType = $request->get(self::SECOND_LIC_TYPE_PARAM_NAME);
275 $insertSecondType = $request->get(self::INSERT_SECOND_LIC_TYPE_PARAM_NAME);
277 $licText = $request->get(self::TEXT_PARAM_NAME);
278 $insertText = $request->get(self::INSERT_TEXT_PARAM_NAME);
280 $licResult = $request->get(self::RESULT_PARAM_NAME);
281 $insertResult = $request->get(self::INSERT_RESULT_PARAM_NAME);
283 if (!empty($licFirstName)) {
284 foreach ($licFirstName as $rulePk => $firstLic) {
285 if ($firstLic ==
"0") {
286 $rules[$rulePk][
'firstLic'] =
null;
288 $rules[$rulePk][
'firstLic'] = $firstLic;
292 if (!empty($licSecondName)) {
293 foreach ($licSecondName as $rulePk => $secondLic) {
294 if ($secondLic ==
"0") {
295 $rules[$rulePk][
'secondLic'] =
null;
297 $rules[$rulePk][
'secondLic'] = $secondLic;
301 if (!empty($licFirstType)) {
302 foreach ($licFirstType as $rulePk => $firstType) {
303 if ($firstType ==
"---") {
304 $rules[$rulePk][
'firstType'] =
null;
306 $rules[$rulePk][
'firstType'] = $firstType;
310 if (!empty($licSecondType)) {
311 foreach ($licSecondType as $rulePk => $secondType) {
312 if ($secondType ==
"---") {
313 $rules[$rulePk][
'secondType'] =
null;
315 $rules[$rulePk][
'secondType'] = $secondType;
319 if (!empty($licText)) {
320 foreach ($licText as $rulePk => $text) {
321 $rules[$rulePk][
'comment'] = $text;
324 if (!empty($licResult)) {
325 foreach ($licResult as $rulePk => $result) {
326 $rules[$rulePk][
'result'] = $result;
330 if (! empty($rules)) {
332 $update[
'updated'] = $this->compatibilityDao->updateRuleFromArray(
334 }
catch (\UnexpectedValueException $e) {
335 $update[
'updated'] = $e->getMessage();
339 $update[
"inserted"] = $this->
insertRules($insertFirstName,
340 $insertSecondName, $insertFirstType, $insertSecondType, $insertText,
356 $firstTypeArray, $secondTypeArray, $commentArray,
360 if ((!empty($firstNameArray) && !empty($secondNameArray)
361 && !empty($firstTypeArray) && !empty($secondTypeArray)
362 && !empty($commentArray))) {
363 for ($i = 0; $i < count($commentArray); $i++) {
364 if ($firstNameArray[$i] ==
"0") {
365 $firstNameArray[$i] =
null;
367 if ($secondNameArray[$i] ==
"0") {
368 $secondNameArray[$i] =
null;
370 if ($firstTypeArray[$i] ==
"---") {
371 $firstTypeArray[$i] =
null;
373 if ($secondTypeArray[$i] ==
"---") {
374 $secondTypeArray[$i] =
null;
376 $returnVal[] = $this->compatibilityDao->insertRule($firstNameArray[$i],
377 $secondNameArray[$i], $firstTypeArray[$i], $secondTypeArray[$i],
378 $commentArray[$i], $resultArray[$i]);
380 $returnVal[
'status'] = 0;
382 if (count(array_filter($returnVal,
function($val) {
385 $returnVal[
'status'] |= 1;
388 if (in_array(-1, $returnVal)) {
389 $returnVal[
'status'] |= 1 << 1;
392 if (in_array(-2, $returnVal)) {
393 $returnVal[
'status'] |= 1 << 2;
407 $rulePk = $request->get(
"rule");
408 $val = $this->compatibilityDao->deleteRule($rulePk);
409 $returnVal[
'status'] = $val ? 1 : -1;
414 register_plugin(
new AdminLicenseCompatibilityRules());
Contains the constants and helpers for authentication of user.
render($templateName, $vars=null, $headers=null)
deleteRules(Request $request)
Delete a rule from the UI.
const INSERT_FIRST_LIC_TYPE_PARAM_NAME
updateRules(Request $request)
Update the already existing rules.
const FIRST_LIC_TYPE_PARAM_NAME
const INSERT_RESULT_PARAM_NAME
addRule()
Add a new empty compatibility rule.
const INSERT_SECOND_LIC_TYPE_PARAM_NAME
const INSERT_SECOND_LIC_NAME_PARAM_NAME
const INSERT_TEXT_PARAM_NAME
fetchRules(Request $request)
Fetch the compatibility rules based on search query and pagination.
const INSERT_FIRST_LIC_NAME_PARAM_NAME
const SECOND_LIC_TYPE_PARAM_NAME
insertRules($firstNameArray, $secondNameArray, $firstTypeArray, $secondTypeArray, $commentArray, $resultArray)
Insert new rules from the UI.
fetchLicenseData()
Fetch the available license data.
const FIRST_LIC_NAME_PARAM_NAME
const SECOND_LIC_NAME_PARAM_NAME