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($searchQuery);
229 $ruleArray = $this->compatibilityDao->getAllRules($limit, $offset, $searchQuery);
231 return new JsonResponse([
233 "recordsTotal" => $totalCount,
234 "recordsFiltered" => $totalCount,
235 "data" => $ruleArray,
236 ], JsonResponse::HTTP_OK);
245 $result = $this->compatibilityDao->insertEmptyRule();
247 return new JsonResponse([
"lr_pk" => $result], JsonResponse::HTTP_OK);
249 return new JsonResponse([
"error" =>
"Failed to add rule."], JsonResponse::HTTP_BAD_REQUEST);
264 $licFirstName = $request->get(self::FIRST_LIC_NAME_PARAM_NAME);
265 $insertFirstName = $request->get(self::INSERT_FIRST_LIC_NAME_PARAM_NAME);
267 $licSecondName = $request->get(self::SECOND_LIC_NAME_PARAM_NAME);
268 $insertSecondName = $request->get(self::INSERT_SECOND_LIC_NAME_PARAM_NAME);
270 $licFirstType = $request->get(self::FIRST_LIC_TYPE_PARAM_NAME);
271 $insertFirstType = $request->get(self::INSERT_FIRST_LIC_TYPE_PARAM_NAME);
273 $licSecondType = $request->get(self::SECOND_LIC_TYPE_PARAM_NAME);
274 $insertSecondType = $request->get(self::INSERT_SECOND_LIC_TYPE_PARAM_NAME);
276 $licText = $request->get(self::TEXT_PARAM_NAME);
277 $insertText = $request->get(self::INSERT_TEXT_PARAM_NAME);
279 $licResult = $request->get(self::RESULT_PARAM_NAME);
280 $insertResult = $request->get(self::INSERT_RESULT_PARAM_NAME);
282 if (!empty($licFirstName)) {
283 foreach ($licFirstName as $rulePk => $firstLic) {
284 if ($firstLic ==
"0") {
285 $rules[$rulePk][
'firstLic'] =
null;
287 $rules[$rulePk][
'firstLic'] = $firstLic;
291 if (!empty($licSecondName)) {
292 foreach ($licSecondName as $rulePk => $secondLic) {
293 if ($secondLic ==
"0") {
294 $rules[$rulePk][
'secondLic'] =
null;
296 $rules[$rulePk][
'secondLic'] = $secondLic;
300 if (!empty($licFirstType)) {
301 foreach ($licFirstType as $rulePk => $firstType) {
302 if ($firstType ==
"---") {
303 $rules[$rulePk][
'firstType'] =
null;
305 $rules[$rulePk][
'firstType'] = $firstType;
309 if (!empty($licSecondType)) {
310 foreach ($licSecondType as $rulePk => $secondType) {
311 if ($secondType ==
"---") {
312 $rules[$rulePk][
'secondType'] =
null;
314 $rules[$rulePk][
'secondType'] = $secondType;
318 if (!empty($licText)) {
319 foreach ($licText as $rulePk => $text) {
320 $rules[$rulePk][
'comment'] = $text;
323 if (!empty($licResult)) {
324 foreach ($licResult as $rulePk => $result) {
325 $rules[$rulePk][
'result'] = $result;
329 if (! empty($rules)) {
331 $update[
'updated'] = $this->compatibilityDao->updateRuleFromArray(
333 }
catch (\UnexpectedValueException $e) {
334 $update[
'updated'] = $e->getMessage();
338 $update[
"inserted"] = $this->
insertRules($insertFirstName,
339 $insertSecondName, $insertFirstType, $insertSecondType, $insertText,
355 $firstTypeArray, $secondTypeArray, $commentArray,
359 if ((!empty($firstNameArray) && !empty($secondNameArray)
360 && !empty($firstTypeArray) && !empty($secondTypeArray)
361 && !empty($commentArray))) {
362 for ($i = 0; $i < count($commentArray); $i++) {
363 if ($firstNameArray[$i] ==
"0") {
364 $firstNameArray[$i] =
null;
366 if ($secondNameArray[$i] ==
"0") {
367 $secondNameArray[$i] =
null;
369 if ($firstTypeArray[$i] ==
"---") {
370 $firstTypeArray[$i] =
null;
372 if ($secondTypeArray[$i] ==
"---") {
373 $secondTypeArray[$i] =
null;
375 $returnVal[] = $this->compatibilityDao->insertRule($firstNameArray[$i],
376 $secondNameArray[$i], $firstTypeArray[$i], $secondTypeArray[$i],
377 $commentArray[$i], $resultArray[$i]);
379 $returnVal[
'status'] = 0;
381 if (count(array_filter($returnVal,
function($val) {
384 $returnVal[
'status'] |= 1;
387 if (in_array(-1, $returnVal)) {
388 $returnVal[
'status'] |= 1 << 1;
391 if (in_array(-2, $returnVal)) {
392 $returnVal[
'status'] |= 1 << 2;
406 $rulePk = $request->get(
"rule");
407 $val = $this->compatibilityDao->deleteRule($rulePk);
408 $returnVal[
'status'] = $val ? 1 : -1;
413 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