ManagerAdminPage.java

1
/*******************************************************************************
2
 * Copyhacked (H) 2012-2025.
3
 * This program and the accompanying materials
4
 * are made available under no term at all, use it like
5
 * you want, but share and discuss it
6
 * every time possible with every body.
7
 * 
8
 * Contributors:
9
 *      ron190 at ymail dot com - initial implementation
10
 ******************************************************************************/
11
package com.jsql.view.swing.manager;
12
13
import com.jsql.util.I18nUtil;
14
import com.jsql.util.LogLevelUtil;
15
import com.jsql.view.swing.list.ItemList;
16
import com.jsql.view.swing.manager.util.StateButton;
17
import com.jsql.view.swing.util.I18nViewUtil;
18
import com.jsql.view.swing.util.MediatorHelper;
19
import org.apache.commons.lang3.StringUtils;
20
import org.apache.logging.log4j.LogManager;
21
import org.apache.logging.log4j.Logger;
22
23
import java.awt.*;
24
import java.util.stream.Collectors;
25
26
/**
27
 * Manager to display webpages frequently used as backoffice administration.
28
 */
29
public class ManagerAdminPage extends AbstractManagerList {
30
    
31
    /**
32
     * Log4j logger sent to view.
33
     */
34
    private static final Logger LOGGER = LogManager.getRootLogger();
35
36
    /**
37
     * Create admin page finder.
38
     */
39
    public ManagerAdminPage() {
40
        super("swing/list/admin-page.txt");
41
42 1 1. <init> : removed call to com/jsql/view/swing/manager/ManagerAdminPage::buildRunButton → NO_COVERAGE
        this.buildRunButton("ADMIN_PAGE_RUN_BUTTON_LABEL", "ADMIN_PAGE_RUN_BUTTON_TOOLTIP");
43 1 1. <init> : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setName → NO_COVERAGE
        this.run.setName("runManagerAdminPage");
44 2 1. <init> : removed call to com/jsql/view/swing/manager/util/JButtonStateful::addActionListener → NO_COVERAGE
2. lambda$new$0 : removed call to com/jsql/view/swing/manager/ManagerAdminPage::runSearch → NO_COVERAGE
        this.run.addActionListener(actionEvent -> this.runSearch());
45 1 1. <init> : removed call to com/jsql/view/swing/list/DnDList::setName → NO_COVERAGE
        this.listPaths.setName("listManagerAdminPage");  // no tooltip, too annoying
46
47
        this.lastLine.add(this.horizontalGlue);
48
        this.lastLine.add(this.progressBar);
49
        this.lastLine.add(this.run);
50 1 1. <init> : removed call to com/jsql/view/swing/manager/ManagerAdminPage::add → NO_COVERAGE
        this.add(this.lastLine, BorderLayout.SOUTH);
51
    }
52
53
    private void runSearch() {
54 1 1. runSearch : negated conditional → NO_COVERAGE
        if (this.listPaths.getSelectedValuesList().isEmpty()) {
55
            LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Select at least one admin page in the list");
56
            return;
57
        }
58
        
59
        String urlAddressBar = MediatorHelper.panelAddressBar().getTextFieldAddress().getText();
60 2 1. runSearch : negated conditional → NO_COVERAGE
2. runSearch : negated conditional → NO_COVERAGE
        if (!urlAddressBar.isEmpty() && !urlAddressBar.matches("(?i)^https?://.*")) {
61 1 1. runSearch : negated conditional → NO_COVERAGE
            if (!urlAddressBar.matches("(?i)^\\w+://.*")) {
62
                LOGGER.log(LogLevelUtil.CONSOLE_INFORM, () -> I18nUtil.valueByKey("LOG_ADMIN_NO_PROTOCOL"));
63
                urlAddressBar = "http://"+ urlAddressBar;
64
            } else {
65
                LOGGER.log(LogLevelUtil.CONSOLE_INFORM, () -> I18nUtil.valueByKey("LOG_ADMIN_UNKNOWN_PROTOCOL"));
66
                return;
67
            }
68
        }
69
        
70
        String urlFinal = urlAddressBar;
71 2 1. lambda$runSearch$3 : removed call to com/jsql/view/swing/manager/ManagerAdminPage::searchAdminPages → NO_COVERAGE
2. runSearch : removed call to java/lang/Thread::start → NO_COVERAGE
        new Thread(() -> this.searchAdminPages(urlFinal), "ThreadAdminPage").start();
72
    }
73
74
    private void searchAdminPages(String urlAddressBar) {
75 1 1. searchAdminPages : negated conditional → NO_COVERAGE
        if (this.run.getState() == StateButton.STARTABLE) {
76 1 1. searchAdminPages : negated conditional → NO_COVERAGE
            if (StringUtils.isEmpty(urlAddressBar)) {
77
                LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Missing URL in address bar");
78
            } else {
79
                LOGGER.log(LogLevelUtil.CONSOLE_DEFAULT, "{} admin pages...", () -> I18nUtil.valueByKey("LOG_CHECKING"));
80 1 1. searchAdminPages : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setText → NO_COVERAGE
                this.run.setText(I18nViewUtil.valueByKey("ADMIN_PAGE_RUN_BUTTON_STOP"));
81 1 1. searchAdminPages : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setState → NO_COVERAGE
                this.run.setState(StateButton.STOPPABLE);
82 1 1. searchAdminPages : removed call to javax/swing/JProgressBar::setVisible → NO_COVERAGE
                this.progressBar.setVisible(true);
83 1 1. searchAdminPages : removed call to java/awt/Component::setVisible → NO_COVERAGE
                this.horizontalGlue.setVisible(false);
84
                MediatorHelper.model().getResourceAccess().createAdminPages(
85
                    urlAddressBar,
86
                    this.listPaths.getSelectedValuesList().stream().map(ItemList::toString).collect(Collectors.toList())
87
                );
88 1 1. searchAdminPages : removed call to com/jsql/view/swing/manager/ManagerAdminPage::endProcess → NO_COVERAGE
                this.endProcess();
89
            }
90 1 1. searchAdminPages : negated conditional → NO_COVERAGE
        } else if (this.run.getState() == StateButton.STOPPABLE) {
91 1 1. searchAdminPages : removed call to com/jsql/model/accessible/ResourceAccess::stopSearchAdmin → NO_COVERAGE
            MediatorHelper.model().getResourceAccess().stopSearchAdmin();
92 1 1. searchAdminPages : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setEnabled → NO_COVERAGE
            this.run.setEnabled(false);
93 1 1. searchAdminPages : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setState → NO_COVERAGE
            this.run.setState(StateButton.STOPPING);
94
        }
95
    }
96
}

Mutations

42

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/manager/ManagerAdminPage::buildRunButton → NO_COVERAGE

43

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/manager/util/JButtonStateful::setName → NO_COVERAGE

44

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/manager/util/JButtonStateful::addActionListener → NO_COVERAGE

2.2
Location : lambda$new$0
Killed by : none
removed call to com/jsql/view/swing/manager/ManagerAdminPage::runSearch → NO_COVERAGE

45

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/list/DnDList::setName → NO_COVERAGE

50

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/manager/ManagerAdminPage::add → NO_COVERAGE

54

1.1
Location : runSearch
Killed by : none
negated conditional → NO_COVERAGE

60

1.1
Location : runSearch
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : runSearch
Killed by : none
negated conditional → NO_COVERAGE

61

1.1
Location : runSearch
Killed by : none
negated conditional → NO_COVERAGE

71

1.1
Location : lambda$runSearch$3
Killed by : none
removed call to com/jsql/view/swing/manager/ManagerAdminPage::searchAdminPages → NO_COVERAGE

2.2
Location : runSearch
Killed by : none
removed call to java/lang/Thread::start → NO_COVERAGE

75

1.1
Location : searchAdminPages
Killed by : none
negated conditional → NO_COVERAGE

76

1.1
Location : searchAdminPages
Killed by : none
negated conditional → NO_COVERAGE

80

1.1
Location : searchAdminPages
Killed by : none
removed call to com/jsql/view/swing/manager/util/JButtonStateful::setText → NO_COVERAGE

81

1.1
Location : searchAdminPages
Killed by : none
removed call to com/jsql/view/swing/manager/util/JButtonStateful::setState → NO_COVERAGE

82

1.1
Location : searchAdminPages
Killed by : none
removed call to javax/swing/JProgressBar::setVisible → NO_COVERAGE

83

1.1
Location : searchAdminPages
Killed by : none
removed call to java/awt/Component::setVisible → NO_COVERAGE

88

1.1
Location : searchAdminPages
Killed by : none
removed call to com/jsql/view/swing/manager/ManagerAdminPage::endProcess → NO_COVERAGE

90

1.1
Location : searchAdminPages
Killed by : none
negated conditional → NO_COVERAGE

91

1.1
Location : searchAdminPages
Killed by : none
removed call to com/jsql/model/accessible/ResourceAccess::stopSearchAdmin → NO_COVERAGE

92

1.1
Location : searchAdminPages
Killed by : none
removed call to com/jsql/view/swing/manager/util/JButtonStateful::setEnabled → NO_COVERAGE

93

1.1
Location : searchAdminPages
Killed by : none
removed call to com/jsql/view/swing/manager/util/JButtonStateful::setState → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.19.1