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

knowledgepixels / nanodash / 26518296981

27 May 2026 02:41PM UTC coverage: 20.586% (+0.05%) from 20.537%
26518296981

push

github

web-flow
Merge pull request #471 from knowledgepixels/chore/bump-nanopub-1.90.0

Bump nanopub to 1.90.0 and drop placeholder/expansion code it now provides

1007 of 6204 branches covered (16.23%)

Branch coverage included in aggregate %.

2604 of 11337 relevant lines covered (22.97%)

3.29 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.FormComponent;
5
import org.apache.wicket.markup.html.form.TextArea;
6
import org.apache.wicket.markup.html.form.TextField;
7
import org.apache.wicket.markup.html.panel.Panel;
8
import org.apache.wicket.model.Model;
9
import org.apache.wicket.validation.INullAcceptingValidator;
10
import org.apache.wicket.validation.IValidatable;
11
import org.apache.wicket.validation.ValidationError;
12
import org.eclipse.rdf4j.common.net.ParsedIRI;
13
import org.nanopub.extra.services.QueryTemplate;
14

15
import java.net.URISyntaxException;
16

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

22
    private final FormComponent<String> formComponent;
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
        if (isMultiPlaceholder()) {
×
36
            add(new Label("textfield").setVisible(false));
×
37
            formComponent = new TextArea<>("textarea", Model.of(""));
×
38
        } else {
39
            formComponent = new TextField<>("textfield", Model.of(""));
×
40
            add(new Label("textarea").setVisible(false));
×
41
        }
42
        formComponent.add(new Validator());
×
43
        add(formComponent);
×
44
        add(new Label("marker", isOptional() ? "" : "*"));
×
45
    }
×
46

47
    /**
48
     * Returns the text field for entering the parameter value.
49
     *
50
     * @return the text field component
51
     */
52
    public FormComponent<String> getFormComponent() {
53
        return formComponent;
×
54
    }
55

56
    /**
57
     * Returns the values (multi) or single value (non-multi) entered in the text field.
58
     *
59
     * @return the value of the text field
60
     */
61
    public String[] getValues() {
62
        return expandValues(formComponent.getModelObject(), paramId);
×
63
    }
64

65
    /**
66
     * Returns the parameter ID.
67
     *
68
     * @return the parameter ID
69
     */
70
    public String getParamId() {
71
        return paramId;
×
72
    }
73

74
    /**
75
     * Returns the parameter name derived from the parameter ID.
76
     *
77
     * @return the parameter name
78
     */
79
    public String getParamName() {
80
        return QueryTemplate.getParamName(paramId);
×
81
    }
82

83
    /**
84
     * Sets the value of the field (non-multi) or adds the value to the list of values (multi).
85
     *
86
     * @param value the value to be set/added
87
     */
88
    public void putValue(String value) {
89
        if (value == null) {
×
90
            return;
×
91
        }
92
        if (isMultiPlaceholder()) {
×
93
            formComponent.getModel().setObject(formComponent.getModel().getObject() + value + "\n");
×
94
        } else {
95
            formComponent.getModel().setObject(value);
×
96
        }
97
    }
×
98

99
    /**
100
     * Clears the value of the field, setting it to an empty string.
101
     */
102
    public void clearValue() {
103
        formComponent.getModel().setObject("");
×
104
    }
×
105

106
    /**
107
     * Checks if the parameter is optional (starts with "__").
108
     *
109
     * @return true if the parameter is optional, false otherwise
110
     */
111
    public boolean isOptional() {
112
        return QueryTemplate.isOptionalPlaceholder(paramId);
×
113
    }
114

115
    /**
116
     * Checks if the parameter is an IRI parameter (ends with "_iri").
117
     *
118
     * @return true if the parameter is an IRI parameter, false otherwise
119
     */
120
    public boolean isIri() {
121
        return QueryTemplate.isIriPlaceholder(paramId);
×
122
    }
123

124
    /**
125
     * Checks if the parameter has been set (non-blank value).
126
     *
127
     * @return true if the parameter has been set, false otherwise
128
     */
129
    public boolean isSet() {
130
        return isSet(formComponent.getModelObject());
×
131
    }
132

133
    /**
134
     * Checks if the parameter is a multi parameter (ends with "_multi" or "_multi_iri").
135
     *
136
     * @return true if the parameter is a multi parameter, false otherwise
137
     */
138
    public boolean isMultiPlaceholder() {
139
        return QueryTemplate.isMultiPlaceholder(paramId);
×
140
    }
141

142
    private class Validator extends InvalidityHighlighting implements INullAcceptingValidator<String> {
×
143

144
        @Override
145
        public void validate(IValidatable<String> i) {
146
            if (isOptional() && !isSet(i.getValue())) {
×
147
                // all good
148
                return;
×
149
            }
150
            if (!isSet(i.getValue())) {
×
151
                i.error(new ValidationError("Missing value for " + paramId));
×
152
                return;
×
153
            }
154
            if (isIri()) {
×
155
                for (String value : expandValues(i.getValue(), paramId)) {
×
156
                    if (!value.matches("https?://.+")) {
×
157
                        i.error(new ValidationError("Invalid IRI protocol: " + value));
×
158
                        return;
×
159
                    }
160
                    try {
161
                        ParsedIRI piri = new ParsedIRI(value);
×
162
                        if (!piri.isAbsolute()) {
×
163
                            i.error(new ValidationError("IRI not well-formed: " + value));
×
164
                        }
165
                    } catch (URISyntaxException ex) {
×
166
                        i.error(new ValidationError("IRI not well-formed: " + value));
×
167
                    }
×
168
                }
169
            }
170
        }
×
171

172
    }
173

174
    /**
175
     * Checks if a string is set (non-null and non-blank).
176
     *
177
     * @param s the string to check
178
     * @return true if the string is set, false otherwise
179
     */
180
    public static boolean isSet(String s) {
181
        return s != null && !s.isBlank();
×
182
    }
183

184
    /**
185
     * Expands the value string into an array of values based on whether the parameter is multi or not.
186
     *
187
     * @param s       the value string
188
     * @param paramId the parameter ID
189
     * @return an array of values
190
     */
191
    public static String[] expandValues(String s, String paramId) {
192
        if (!isSet(s)) {
×
193
            return new String[]{};
×
194
        } else if (QueryTemplate.isMultiPlaceholder(paramId)) {
×
195
            return s.replaceFirst("\r?\n$", "").split("\r?\n");
×
196
        } else {
197
            return new String[]{s};
×
198
        }
199
    }
200

201
}
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