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

knowledgepixels / nanodash / 18741366223

23 Oct 2025 07:48AM UTC coverage: 12.895% (-0.8%) from 13.69%
18741366223

push

github

tkuhn
feat: Apply new view display method also for Space pages

452 of 4396 branches covered (10.28%)

Branch coverage included in aggregate %.

1174 of 8214 relevant lines covered (14.29%)

0.64 hits per line

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

0.0
src/main/java/com/knowledgepixels/nanodash/page/SpacePage.java
1
package com.knowledgepixels.nanodash.page;
2

3
import java.time.LocalDateTime;
4
import java.time.ZoneId;
5
import java.time.format.DateTimeFormatter;
6
import java.util.ArrayList;
7
import java.util.List;
8

9
import org.apache.wicket.Component;
10
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;
11
import org.apache.wicket.markup.html.basic.Label;
12
import org.apache.wicket.markup.html.link.AbstractLink;
13
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
14
import org.apache.wicket.model.Model;
15
import org.apache.wicket.request.mapper.parameter.PageParameters;
16
import org.eclipse.rdf4j.model.IRI;
17
import org.nanopub.Nanopub;
18
import org.nanopub.extra.services.FailedApiCallException;
19

20
import com.knowledgepixels.nanodash.Space;
21
import com.knowledgepixels.nanodash.SpaceMemberRole;
22
import com.knowledgepixels.nanodash.User;
23
import com.knowledgepixels.nanodash.Utils;
24
import com.knowledgepixels.nanodash.component.ButtonList;
25
import com.knowledgepixels.nanodash.component.ItemListElement;
26
import com.knowledgepixels.nanodash.component.ItemListPanel;
27
import com.knowledgepixels.nanodash.component.PinGroupList;
28
import com.knowledgepixels.nanodash.component.SpaceUserList;
29
import com.knowledgepixels.nanodash.component.TitleBar;
30
import com.knowledgepixels.nanodash.component.ViewList;
31
import com.knowledgepixels.nanodash.connector.ConnectorConfig;
32
import com.knowledgepixels.nanodash.connector.GenOverviewPage;
33

34
/**
35
 * The ProjectPage class represents a space page in the Nanodash application.
36
 */
37
public class SpacePage extends NanodashPage {
38

39
    /**
40
     * The mount path for this page.
41
     */
42
    public static final String MOUNT_PATH = "/space";
43

44
    /**
45
     * {@inheritDoc}
46
     */
47
    @Override
48
    public String getMountPath() {
49
        return MOUNT_PATH;
×
50
    }
51

52
    /**
53
     * Space object with the data shown on this page.
54
     */
55
    private Space space;
56

57
    private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
×
58

59
    /**
60
     * Constructor for the SpacePage.
61
     *
62
     * @param parameters the page parameters
63
     * @throws org.nanopub.extra.services.FailedApiCallException if the API call fails
64
     */
65
    public SpacePage(final PageParameters parameters) throws FailedApiCallException {
66
        super(parameters);
×
67

68
        space = Space.get(parameters.get("id").toString());
×
69
        Nanopub np = space.getRootNanopub();
×
70

71
        add(new TitleBar("titlebar", this, "connectors"));
×
72

73
        add(new Label("pagetitle", space.getLabel() + " (space) | nanodash"));
×
74
        add(new Label("spacename", space.getLabel()));
×
75
        add(new Label("spacetype", space.getTypeLabel()));
×
76
        add(new BookmarkablePageLink<Void>("id", ExplorePage.class, parameters.set("label", space.getLabel())).setBody(Model.of(space.getId())));
×
77
        add(new BookmarkablePageLink<Void>("np", ExplorePage.class, new PageParameters().add("id", np.getUri())));
×
78

79
        add(new ItemListPanel<String>(
×
80
                "altids",
81
                "Alternative IDs:",
82
                space.getAltIDs(),
×
83
                id -> new ItemListElement("item", ExplorePage.class, new PageParameters().add("id", id), id)
×
84
            ));
85

86
        if (space.getStartDate() != null) {
×
87
            String dateString;
88
            LocalDateTime dt = LocalDateTime.ofInstant(space.getStartDate().toInstant(), ZoneId.systemDefault());
×
89
            dateString = dateTimeFormatter.format(dt);
×
90
            if (space.getEndDate() != null) {
×
91
                dt = LocalDateTime.ofInstant(space.getEndDate().toInstant(), ZoneId.systemDefault());
×
92
                String endDate = dateTimeFormatter.format(dt);
×
93
                if (!dateString.equals(endDate)) {
×
94
                    dateString += " - " + endDate;
×
95
                }
96
            }
97
            add(new Label("date", dateString));
×
98
        } else {
×
99
            add(new Label("date").setVisible(false));
×
100
        }
101

102
        add(new Label("description", "<span>" + Utils.sanitizeHtml(space.getDescription()) + "</span>").setEscapeModelStrings(false));
×
103

104
        final List<AbstractLink> pinButtons = new ArrayList<>();
×
105

106
        AbstractLink addPinnedTemplateButton = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, new PageParameters()
×
107
                .add("template", "https://w3id.org/np/RA2YwreWrGW9HkzWls8jgwaIINKUB5ZTli1aFKQt13dUk")
×
108
                .add("param_space", space.getId())
×
109
                .add("context", space.getId())
×
110
            );
111
        addPinnedTemplateButton.setBody(Model.of("+ template"));
×
112
        pinButtons.add(addPinnedTemplateButton);
×
113

114
        AbstractLink addPinnedQueryButton = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, new PageParameters()
×
115
                .add("template", "https://w3id.org/np/RAuLESdeRUlk1GcTwvzVXShiBMI0ntJs2DL2Bm5DzW_ZQ")
×
116
                .add("param_space", space.getId())
×
117
            );
118
        addPinnedQueryButton.setBody(Model.of("+ query"));
×
119
        pinButtons.add(addPinnedQueryButton);
×
120

121
        if (space.isDataInitialized()) {
×
122
            add(new PinGroupList("pin-groups", space));
×
123
            add(new ButtonList("pin-buttons", space, null, null, pinButtons));
×
124
        } else {
125
            add(new AjaxLazyLoadPanel<Component>("pin-groups") {
×
126
    
127
                @Override
128
                public Component getLazyLoadComponent(String markupId) {
129
                    return new PinGroupList(markupId, space);
×
130
                }
131
    
132
                @Override
133
                protected boolean isContentReady() {
134
                    return space.isDataInitialized();
×
135
                }
136
    
137
            });
138
            add(new AjaxLazyLoadPanel<Component>("pin-buttons") {
×
139
    
140
                @Override
141
                public Component getLazyLoadComponent(String markupId) {
142
                    return new ButtonList(markupId, space, null, null, pinButtons);
×
143
                }
144
    
145
                @Override
146
                protected boolean isContentReady() {
147
                    return space.isDataInitialized();
×
148
                }
149

150
                public Component getLoadingComponent(String id) {
151
                    return new Label(id).setVisible(false);
×
152
                };
153
    
154
            });
155
        }
156

157
        final List<AbstractLink> viewButtons = new ArrayList<>();
×
158
        AbstractLink addViewButton = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, new PageParameters()
×
159
                .add("template", "https://w3id.org/np/RA7vjbk3kz4FCu2eTX5oekZshPeOGNGTw8b2WLk8ZS7VI")
×
160
                .add("param_resource", space.getId())
×
161
                .add("context", space.getId())
×
162
            );
163
        addViewButton.setBody(Model.of("+"));
×
164
        viewButtons.add(addViewButton);
×
165

166
        if (space.isDataInitialized()) {
×
167
            add(new ViewList("views", space));
×
168
            add(new ButtonList("view-buttons", space, null, null, viewButtons));
×
169
        } else {
170
            add(new AjaxLazyLoadPanel<Component>("views") {
×
171
    
172
                @Override
173
                public Component getLazyLoadComponent(String markupId) {
174
                    return new ViewList(markupId, space);
×
175
                }
176
    
177
                @Override
178
                protected boolean isContentReady() {
179
                    return space.isDataInitialized();
×
180
                }
181
    
182
            });
183
            add(new AjaxLazyLoadPanel<Component>("view-buttons") {
×
184
    
185
                @Override
186
                public Component getLazyLoadComponent(String markupId) {
187
                    return new ButtonList(markupId, space, null, null, viewButtons);
×
188
                }
189
    
190
                @Override
191
                protected boolean isContentReady() {
192
                    return space.isDataInitialized();
×
193
                }
194

195
                public Component getLoadingComponent(String id) {
196
                    return new Label(id).setVisible(false);
×
197
                };
198
    
199
            });
200
        }
201

202
        add(new ItemListPanel<>(
×
203
                "roles",
204
                "Roles:",
205
                () -> space.isDataInitialized(),
×
206
                () -> space.getRoles(),
×
207
                r -> new ItemListElement("item", ExplorePage.class, new PageParameters().add("id", r.getId()), r.getName())
×
208
            )
209
            .makeInline()
×
210
            .setSpace(space)
×
211
            .addAdminButton("+", PublishPage.class, new PageParameters()
×
212
                    .add("template", "https://w3id.org/np/RARBzGkEqiQzeiHk0EXFcv9Ol1d-17iOh9MoFJzgfVQDc")
×
213
                    .add("param_space", space.getId())
×
214
                    .add("template-version", "latest")
×
215
                )
216
            );
217

218
        add(new ItemListPanel<IRI>(
×
219
                "users",
220
                "Users",
221
                () -> space.isDataInitialized(),
×
222
                () -> space.getUsers(),
×
223
                m -> {
224
                        String roleLabel = "(";
×
225
                        for (SpaceMemberRole r : space.getMemberRoles(m)) {
×
226
                            roleLabel += r.getName() + ", ";
×
227
                        }
×
228
                        roleLabel = roleLabel.replaceFirst(", $", ")");
×
229
                        return new ItemListElement("item", UserPage.class, new PageParameters().add("id", m), User.getShortDisplayName(m), roleLabel);
×
230
                    }
231
            ));
232

233

234
        if (space.isDataInitialized()) {
×
235
            add(new SpaceUserList("user-lists", space));
×
236
        } else {
237
            add(new AjaxLazyLoadPanel<Component>("user-lists") {
×
238
    
239
                @Override
240
                public Component getLazyLoadComponent(String markupId) {
241
                    return new SpaceUserList(markupId, space);
×
242
                }
243
    
244
                @Override
245
                protected boolean isContentReady() {
246
                    return space.isDataInitialized();
×
247
                }
248
    
249
            });
250
        }
251

252
        add(new ItemListPanel<Space>(
×
253
                "superspaces",
254
                "Part of",
255
                space.getSuperspaces(),
×
256
                (space) -> new ItemListElement("item", SpacePage.class, new PageParameters().add("id", space), space.getLabel(), "(" + space.getTypeLabel() + ")")
×
257
            ));
258

259
        addSubspacePanel("Alliance", true);
×
260
        addSubspacePanel("Consortium", false);
×
261
        addSubspacePanel("Organization", true);
×
262
        addSubspacePanel("Taskforce", false);
×
263
        addSubspacePanel("Division", true);
×
264
        addSubspacePanel("Taskunit", false);
×
265
        addSubspacePanel("Group", true);
×
266
        addSubspacePanel("Project", false);
×
267
        addSubspacePanel("Program", true);
×
268
        addSubspacePanel("Initiative", false);
×
269
        addSubspacePanel("Outlet", true);
×
270
        addSubspacePanel("Campaign", false);
×
271
        addSubspacePanel("Community", true);
×
272
        addSubspacePanel("Event", false);
×
273

274
        String shortId = space.getId().replace("https://w3id.org/spaces/", "");
×
275
        ConnectorConfig cc = ConnectorConfig.get(shortId);
×
276
        if (cc != null) {
×
277
            add(new BookmarkablePageLink<Void>("content-button", GenOverviewPage.class, new PageParameters().add("journal", shortId)).setBody(Model.of("Nanopublication Submissions")));
×
278
        } else {
279
            add(new Label("content-button").setVisible(false));
×
280
        }
281
    }
×
282

283
    private void addSubspacePanel(String type, boolean openEnded) {
284
        String typePl = type + "s";
×
285
        typePl = typePl.replaceFirst("ys$", "ies");
×
286

287
        add(new ItemListPanel<>(
×
288
                typePl.toLowerCase(),
×
289
                typePl,
290
                space.getSubspaces("https://w3id.org/kpxl/gen/terms/" + type),
×
291
                (space) -> new ItemListElement("item", SpacePage.class, new PageParameters().add("id", space), space.getLabel())
×
292
            )
293
            .setSpace(space)
×
294
            .setReadyFunction(space::isDataInitialized)
×
295
            .addMemberButton("+", PublishPage.class, new PageParameters()
×
296
                    .add("template", openEnded ? "https://w3id.org/np/RA7dQfmndqKmooQ4PlHyQsAql9i2tg_8GLHf_dqtxsGEQ" : "https://w3id.org/np/RAaE7NP9RNIx03AHZxanFMdtUuaTfe50ns5tHhpEVloQ4")
×
297
                    .add("param_type", "https://w3id.org/kpxl/gen/terms/" + type)
×
298
                    .add("param_space", space.getId().replaceFirst("https://w3id.org/spaces/", "") + "/<...>")
×
299
                    .add("template-version", "latest"))
×
300
            );
301
    }
×
302

303
    /**
304
     * Checks if auto-refresh is enabled for this page.
305
     *
306
     * @return true if auto-refresh is enabled, false otherwise
307
     */
308
    protected boolean hasAutoRefreshEnabled() {
309
        return true;
×
310
    }
311

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