ManagerAdminPage.java

1
/*******************************************************************************
2
 * Copyhacked (H) 2012-2020.
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 about 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.JButtonStateful;
17
import com.jsql.view.swing.manager.util.StateButton;
18
import com.jsql.view.swing.ui.FlatButtonMouseAdapter;
19
import com.jsql.view.swing.util.I18nViewUtil;
20
import com.jsql.view.swing.util.MediatorHelper;
21
import com.jsql.view.swing.util.UiUtil;
22
import org.apache.commons.lang3.StringUtils;
23
import org.apache.logging.log4j.LogManager;
24
import org.apache.logging.log4j.Logger;
25
26
import javax.swing.*;
27
import java.awt.*;
28
import java.util.stream.Collectors;
29
30
/**
31
 * Manager to display webpages frequently used as backoffice administration.
32
 */
33
public class ManagerAdminPage extends AbstractManagerList {
34
    
35
    /**
36
     * Log4j logger sent to view.
37
     */
38
    private static final Logger LOGGER = LogManager.getRootLogger();
39
    
40
    /**
41
     * Create admin page finder.
42
     */
43
    public ManagerAdminPage() {
44
        
45
        super("swing/list/admin-page.txt");
46
47 1 1. <init> : removed call to com/jsql/view/swing/manager/ManagerAdminPage::initializeRunButton → NO_COVERAGE
        this.initializeRunButton();
48
        
49 1 1. <init> : removed call to com/jsql/view/swing/list/DnDList::setName → NO_COVERAGE
        this.listFile.setName("listManagerAdminPage");
50 1 1. <init> : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setName → NO_COVERAGE
        this.run.setName("runManagerAdminPage");
51
        
52 1 1. <init> : removed call to javax/swing/JPanel::setLayout → NO_COVERAGE
        this.lastLine.setLayout(new BorderLayout());
53 1 1. <init> : removed call to javax/swing/JPanel::setPreferredSize → NO_COVERAGE
        this.lastLine.setPreferredSize(new Dimension(0, 26));
54
        
55
        var panelRunButton = new JPanel();
56 1 1. <init> : removed call to javax/swing/JPanel::setLayout → NO_COVERAGE
        panelRunButton.setLayout(new BoxLayout(panelRunButton, BoxLayout.X_AXIS));
57
        
58
        panelRunButton.add(Box.createHorizontalGlue());
59
        panelRunButton.add(this.loader);
60
        panelRunButton.add(Box.createRigidArea(new Dimension(5, 0)));
61
        panelRunButton.add(this.run);
62
        
63 1 1. <init> : removed call to javax/swing/JPanel::add → NO_COVERAGE
        this.lastLine.add(panelRunButton, BorderLayout.LINE_END);
64
        
65 1 1. <init> : removed call to com/jsql/view/swing/manager/ManagerAdminPage::add → NO_COVERAGE
        this.add(this.lastLine, BorderLayout.SOUTH);
66
    }
67
68
    private void initializeRunButton() {
69
        
70
        this.defaultText = "ADMIN_PAGE_RUN_BUTTON_LABEL";
71
        this.run = new JButtonStateful(this.defaultText);
72 1 1. initializeRunButton : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE
        I18nViewUtil.addComponentForKey("ADMIN_PAGE_RUN_BUTTON_LABEL", this.run);
73 1 1. initializeRunButton : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setToolTipText → NO_COVERAGE
        this.run.setToolTipText(I18nUtil.valueByKey("ADMIN_PAGE_RUN_BUTTON_TOOLTIP"));
74
        
75 1 1. initializeRunButton : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setContentAreaFilled → NO_COVERAGE
        this.run.setContentAreaFilled(false);
76 1 1. initializeRunButton : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setBorder → NO_COVERAGE
        this.run.setBorder(BorderFactory.createEmptyBorder(4, 8, 4, 8));
77 1 1. initializeRunButton : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setBackground → NO_COVERAGE
        this.run.setBackground(UiUtil.COLOR_FOCUS_GAINED);
78
        
79 1 1. initializeRunButton : removed call to com/jsql/view/swing/manager/util/JButtonStateful::addMouseListener → NO_COVERAGE
        this.run.addMouseListener(new FlatButtonMouseAdapter(this.run));
80 2 1. initializeRunButton : removed call to com/jsql/view/swing/manager/util/JButtonStateful::addActionListener → NO_COVERAGE
2. lambda$initializeRunButton$0 : removed call to com/jsql/view/swing/manager/ManagerAdminPage::runSearch → NO_COVERAGE
        this.run.addActionListener(actionEvent -> this.runSearch());
81
82 1 1. initializeRunButton : removed call to javax/swing/JLabel::setVisible → NO_COVERAGE
        this.loader.setVisible(false);
83
    }
84
85
    private void runSearch() {
86
        
87 1 1. runSearch : negated conditional → NO_COVERAGE
        if (this.listFile.getSelectedValuesList().isEmpty()) {
88
            
89
            LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Select at least one admin page in the list");
90
            return;
91
        }
92
        
93
        String urlAddressBar = MediatorHelper.panelAddressBar().getTextFieldAddress().getText();
94
        
95 2 1. runSearch : negated conditional → NO_COVERAGE
2. runSearch : negated conditional → NO_COVERAGE
        if (!urlAddressBar.isEmpty() && !urlAddressBar.matches("(?i)^https?://.*")) {
96
            
97 1 1. runSearch : negated conditional → NO_COVERAGE
            if (!urlAddressBar.matches("(?i)^\\w+://.*")) {
98
                
99
                LOGGER.log(LogLevelUtil.CONSOLE_INFORM, () -> I18nUtil.valueByKey("LOG_ADMIN_NO_PROTOCOL"));
100
                urlAddressBar = "http://"+ urlAddressBar;
101
                
102
            } else {
103
                
104
                LOGGER.log(LogLevelUtil.CONSOLE_INFORM, () -> I18nUtil.valueByKey("LOG_ADMIN_UNKNOWN_PROTOCOL"));
105
                return;
106
            }
107
        }
108
        
109
        String urlFinal = urlAddressBar;
110
        
111 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();
112
    }
113
114
    private void searchAdminPages(String urlAddressBar) {
115
        
116 1 1. searchAdminPages : negated conditional → NO_COVERAGE
        if (ManagerAdminPage.this.run.getState() == StateButton.STARTABLE) {
117 1 1. searchAdminPages : negated conditional → NO_COVERAGE
            if (StringUtils.isEmpty(urlAddressBar)) {
118
                LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Missing URL in address bar");
119
            } else {
120
                
121
                LOGGER.log(LogLevelUtil.CONSOLE_DEFAULT, "Checking admin page(s)...");
122 1 1. searchAdminPages : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setText → NO_COVERAGE
                ManagerAdminPage.this.run.setText(I18nViewUtil.valueByKey("ADMIN_PAGE_RUN_BUTTON_STOP"));
123 1 1. searchAdminPages : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setState → NO_COVERAGE
                ManagerAdminPage.this.run.setState(StateButton.STOPPABLE);
124 1 1. searchAdminPages : removed call to javax/swing/JLabel::setVisible → NO_COVERAGE
                ManagerAdminPage.this.loader.setVisible(true);
125
                
126
                MediatorHelper.model().getResourceAccess().createAdminPages(
127
                    urlAddressBar,
128
                    this.listFile.getSelectedValuesList().stream().map(ItemList::toString).collect(Collectors.toList())
129
                );
130
            }
131 1 1. searchAdminPages : negated conditional → NO_COVERAGE
        } else if (this.run.getState() == StateButton.STOPPABLE) {
132
            
133 1 1. searchAdminPages : removed call to com/jsql/model/accessible/ResourceAccess::setSearchAdminStopped → NO_COVERAGE
            MediatorHelper.model().getResourceAccess().setSearchAdminStopped(true);
134 1 1. searchAdminPages : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setEnabled → NO_COVERAGE
            ManagerAdminPage.this.run.setEnabled(false);
135 1 1. searchAdminPages : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setState → NO_COVERAGE
            ManagerAdminPage.this.run.setState(StateButton.STOPPING);
136
        }
137
    }
138
}

Mutations

47

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

49

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/util/JButtonStateful::setName → NO_COVERAGE

52

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JPanel::setLayout → NO_COVERAGE

53

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JPanel::setPreferredSize → NO_COVERAGE

56

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JPanel::setLayout → NO_COVERAGE

63

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JPanel::add → NO_COVERAGE

65

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

72

1.1
Location : initializeRunButton
Killed by : none
removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE

73

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

75

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

76

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

77

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

79

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

80

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

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

82

1.1
Location : initializeRunButton
Killed by : none
removed call to javax/swing/JLabel::setVisible → NO_COVERAGE

87

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

95

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

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

97

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

111

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

116

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

117

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

122

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

123

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

124

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

131

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

133

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

134

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

135

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.16.1