• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

knowledgepixels / nanodash / 17801984436

17 Sep 2025 03:03PM UTC coverage: 13.877% (-0.1%) from 14.007%
17801984436

push

github

tkuhn
Update ResearchGroupDemo mockup page

443 of 4020 branches covered (11.02%)

Branch coverage included in aggregate %.

1133 of 7337 relevant lines covered (15.44%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
src/main/java/com/knowledgepixels/nanodash/component/QueryParamField.java
1
package com.knowledgepixels.nanodash.component;
2

3
import org.apache.wicket.markup.html.basic.Label;
4
import org.apache.wicket.markup.html.form.TextField;
5
import org.apache.wicket.markup.html.panel.Panel;
6
import org.apache.wicket.model.IModel;
7
import org.apache.wicket.model.Model;
8
import org.apache.wicket.validation.INullAcceptingValidator;
9
import org.apache.wicket.validation.IValidatable;
10
import org.apache.wicket.validation.ValidationError;
11
import org.eclipse.rdf4j.common.net.ParsedIRI;
12

13
import java.net.URISyntaxException;
14

15
/**
16
 * A field for entering query parameters, with validation for required fields and IRIs.
17
 */
18
public class QueryParamField extends Panel {
19

20
    private static final long serialVersionUID = 1L;
21

22
    private final TextField<String> textfield;
23
    private final String paramId;
24

25
    /**
26
     * Constructs a QueryParamField with the given ID and parameter ID.
27
     *
28
     * @param id      the Wicket component ID
29
     * @param paramId the parameter ID, which may start with underscores and end with "_iri"
30
     */
31
    public QueryParamField(String id, String paramId) {
32
        super(id);
×
33
        this.paramId = paramId;
×
34
        add(new Label("paramname", getParamName()));
×
35
        textfield = new TextField<>("textfield", Model.of(""));
×
36
        textfield.add(new Validator());
×
37
        add(textfield);
×
38
        add(new Label("marker", isOptional() ? "" : "*"));
×
39
    }
×
40

41
    /**
42
     * Returns the text field for entering the parameter value.
43
     *
44
     * @return the text field component
45
     */
46
    public TextField<String> getTextField() {
47
        return textfield;
×
48
    }
49

50
    /**
51
     * Returns the value entered in the text field.
52
     *
53
     * @return the value of the text field
54
     */
55
    public String getValue() {
56
        return textfield.getModelObject();
×
57
    }
58

59
    /**
60
     * Returns the parameter ID.
61
     *
62
     * @return the parameter ID
63
     */
64
    public String getParamId() {
65
        return paramId;
×
66
    }
67

68
    /**
69
     * Returns the parameter name derived from the parameter ID.
70
     *
71
     * @return the parameter name
72
     */
73
    public String getParamName() {
74
        return getParamName(paramId);
×
75
    }
76

77
    /**
78
     * Returns the model of the text field.
79
     *
80
     * @return the model of the text field
81
     */
82
    public IModel<String> getModel() {
83
        return textfield.getModel();
×
84
    }
85

86
    /**
87
     * Checks if the parameter is optional (starts with "__").
88
     *
89
     * @return true if the parameter is optional, false otherwise
90
     */
91
    public boolean isOptional() {
92
        return paramId.startsWith("__");
×
93
    }
94

95
    /**
96
     * Checks if the parameter is an IRI parameter (ends with "_iri").
97
     *
98
     * @return true if the parameter is an IRI parameter, false otherwise
99
     */
100
    public boolean isIri() {
101
        return paramId.endsWith("_iri");
×
102
    }
103

104
    /**
105
     * Checks if the parameter is a multi parameter (ends with "_multi" or "_multi_iri").
106
     *
107
     * @return true if the parameter is a multi parameter, false otherwise
108
     */
109
    public static boolean isMultiPlaceholder(String placeholder) {
110
        return placeholder.endsWith("_multi") || placeholder.endsWith("_multi_iri");
×
111
    }
112

113
    private class Validator extends InvalidityHighlighting implements INullAcceptingValidator<String> {
×
114

115
        private static final long serialVersionUID = 1L;
116

117
        @Override
118
        public void validate(IValidatable<String> s) {
119
            String value = s.getValue();
×
120
            if (isOptional() && !isSet(value)) {
×
121
                // all good
122
                return;
×
123
            }
124
            if (!isSet(value)) {
×
125
                s.error(new ValidationError("Missing value for " + paramId));
×
126
                return;
×
127
            }
128
            if (isIri()) {
×
129
                if (!value.matches("https?://.+")) {
×
130
                    s.error(new ValidationError("Invalid IRI protocol: " + value));
×
131
                    return;
×
132
                }
133
                try {
134
                    ParsedIRI piri = new ParsedIRI(value);
×
135
                    if (!piri.isAbsolute()) {
×
136
                        s.error(new ValidationError("IRI not well-formed: " + value));
×
137
                    }
138
                } catch (URISyntaxException ex) {
×
139
                    s.error(new ValidationError("IRI not well-formed: " + value));
×
140
                }
×
141
            }
142
        }
×
143

144
        private static boolean isSet(String s) {
145
            return s != null && !s.isBlank();
×
146
        }
147

148
    }
149

150
    /**
151
     * Extracts the parameter name from the placeholder ID.
152
     *
153
     * @param placeholderId the placeholder ID, which may start with underscores and end with "_iri" and/or "_multi"
154
     * @return the parameter name, stripped of leading underscores and "_iri"/"_multi" suffixes
155
     */
156
    public static String getParamName(String placeholderId) {
157
        return placeholderId.replaceFirst("^_+", "").replaceFirst("_iri$", "").replaceFirst("_multi$", "");
×
158
    }
159

160
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc