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

knowledgepixels / nanodash / 19170532844

07 Nov 2025 01:56PM UTC coverage: 14.148% (-0.8%) from 14.95%
19170532844

push

github

tkuhn
feat(Space): Part-level elements for Spaces, also namespace-declared

518 of 4596 branches covered (11.27%)

Branch coverage included in aggregate %.

1335 of 8501 relevant lines covered (15.7%)

0.7 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/ResourcePartPage.java
1
package com.knowledgepixels.nanodash.page;
2

3
import java.util.ArrayList;
4
import java.util.HashSet;
5
import java.util.List;
6
import java.util.Set;
7

8
import org.apache.wicket.Component;
9
import org.apache.wicket.RestartResponseException;
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.eclipse.rdf4j.model.Statement;
18
import org.eclipse.rdf4j.model.vocabulary.DCTERMS;
19
import org.eclipse.rdf4j.model.vocabulary.RDF;
20
import org.eclipse.rdf4j.model.vocabulary.RDFS;
21
import org.eclipse.rdf4j.model.vocabulary.SKOS;
22
import org.nanopub.Nanopub;
23
import org.nanopub.extra.services.ApiResponse;
24
import org.nanopub.extra.services.FailedApiCallException;
25
import org.nanopub.extra.services.QueryRef;
26

27
import com.knowledgepixels.nanodash.ApiCache;
28
import com.knowledgepixels.nanodash.MaintainedResource;
29
import com.knowledgepixels.nanodash.QueryApiAccess;
30
import com.knowledgepixels.nanodash.ResourceView;
31
import com.knowledgepixels.nanodash.Space;
32
import com.knowledgepixels.nanodash.User;
33
import com.knowledgepixels.nanodash.Utils;
34
import com.knowledgepixels.nanodash.component.ButtonList;
35
import com.knowledgepixels.nanodash.component.TitleBar;
36
import com.knowledgepixels.nanodash.component.ViewList;
37

38
/**
39
 * This class represents a page for a maintained resource.
40
 */
41
public class ResourcePartPage extends NanodashPage {
42

43
    /**
44
     * The mount path for this page.
45
     */
46
    public static final String MOUNT_PATH = "/part";
47

48
    /**
49
     * {@inheritDoc}
50
     */
51
    @Override
52
    public String getMountPath() {
53
        return MOUNT_PATH;
×
54
    }
55

56
    /**
57
     * Maintained resource object with the data shown on this page.
58
     */
59
    private MaintainedResource resource;
60
    private Space space;
61

62
    public ResourcePartPage(final PageParameters parameters) throws FailedApiCallException {
63
        super(parameters);
×
64

65
        final String id = parameters.get("id").toString();
×
66
        final String contextId = parameters.get("context").toString();
×
67
        resource = MaintainedResource.get(contextId);
×
68
        if (resource == null) {
×
69
            space = Space.get(contextId);
×
70
        } else {
71
            space = resource.getSpace();
×
72
        }
73
        if (space == null) throw new IllegalArgumentException("Not a resource or space: " + contextId);
×
74

75
        add(new TitleBar("titlebar", this, "connectors"));
×
76

77
        QueryRef getDefQuery = new QueryRef("get-term-definitions", "term", id);
×
78
        for (IRI userIri : space.getUsers()) {
×
79
            for (String pubkey : User.getUserData().getPubkeyhashes(userIri, true)) {
×
80
                getDefQuery.getParams().put("pubkey", pubkey);
×
81
            }
×
82
        }
×
83

84
        final String nanopubId;
85
        String label = id.replaceFirst("^.*[#/]([^#/]+)$", "$1");
×
86
        String description = null;
×
87
        Set<IRI> classes = new HashSet<>();
×
88

89
        ApiResponse getDefResp = ApiCache.retrieveResponse(getDefQuery);
×
90
        if (getDefResp == null) {
×
91
            getDefResp = QueryApiAccess.forcedGet(getDefQuery);
×
92
        }
93
        if (getDefResp != null && !getDefResp.getData().isEmpty()) {
×
94
            nanopubId = getDefResp.getData().iterator().next().get("np");
×
95

96
            Nanopub nanopub = Utils.getAsNanopub(nanopubId);
×
97
            for (Statement st : nanopub.getAssertion()) {
×
98
                if (!st.getSubject().stringValue().equals(id)) continue;
×
99
                if (st.getPredicate().equals(RDFS.LABEL)) label = st.getObject().stringValue();
×
100
                if (st.getPredicate().equals(SKOS.DEFINITION) || st.getPredicate().equals(DCTERMS.DESCRIPTION) || st.getPredicate().equals(RDFS.COMMENT)) {
×
101
                    description = st.getObject().stringValue();
×
102
                }
103
                if (st.getPredicate().equals(RDF.TYPE) && st.getObject() instanceof IRI objIri) {
×
104
                    classes.add(objIri);
×
105
                }
106
            }
×
107
        } else {
×
108
            nanopubId = null;
×
109
        }
110
//        if (getDefResp == null || getDefResp.getData().isEmpty()) {
111
//            throw new RestartResponseException(ExplorePage.class, parameters);
112
//        }
113

114

115
        if (description != null) {
×
116
            add(new Label("description", description));
×
117
        } else {
118
            add(new Label("description").setVisible(false));
×
119
        }
120

121
        add(new Label("pagetitle", label + " (resource part) | nanodash"));
×
122
        add(new Label("name", label));
×
123
        add(new BookmarkablePageLink<Void>("id", ExplorePage.class, parameters.set("label", label)).setBody(Model.of(id)));
×
124
        add(new BookmarkablePageLink<Void>("np", ExplorePage.class, new PageParameters().set("id", nanopubId == null ? id : nanopubId)));
×
125

126
        // TODO Improve this code, e.g. make Space a subclass of MaintainedResource or otherwise refactor:
127
        if (resource != null) {
×
128
            add(new BookmarkablePageLink<Void>("resource", MaintainedResourcePage.class, new PageParameters().set("id", resource.getId())).setBody(Model.of(resource.getLabel())));
×
129

130
            final List<AbstractLink> viewButtons = new ArrayList<>();
×
131
            AbstractLink addViewButton = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, new PageParameters()
×
132
                    .set("template", "https://w3id.org/np/RAxERE0cQ9jLQZ5VjeA-1v3XnE9ugxLpFG8vpkAd5FqHE")
×
133
                    .set("param_displayType", ResourceView.PART_LEVEL_VIEW_DISPLAY)
×
134
                    .set("param_resource", resource.getId())
×
135
                    .set("context", resource.getId())
×
136
                );
137
            addViewButton.setBody(Model.of("+ view"));
×
138
            viewButtons.add(addViewButton);
×
139
    
140
            final String nanopubRef = nanopubId == null ? "x:" : nanopubId;
×
141
            if (resource.isDataInitialized()) {
×
142
                add(new ViewList("views", resource, id, nanopubRef, classes));
×
143
                add(new ButtonList("view-buttons", space, null, null, viewButtons));
×
144
            } else {
145
                add(new AjaxLazyLoadPanel<Component>("views") {
×
146
        
147
                    @Override
148
                    public Component getLazyLoadComponent(String markupId) {
149
                        return new ViewList(markupId, resource, id, nanopubRef, classes);
×
150
                    }
151
        
152
                    @Override
153
                    protected boolean isContentReady() {
154
                        return resource.isDataInitialized();
×
155
                    }
156
        
157
                });
158
                add(new AjaxLazyLoadPanel<Component>("view-buttons") {
×
159
        
160
                    @Override
161
                    public Component getLazyLoadComponent(String markupId) {
162
                        return new ButtonList(markupId, space, null, null, viewButtons);
×
163
                    }
164
        
165
                    @Override
166
                    protected boolean isContentReady() {
167
                        return resource.isDataInitialized();
×
168
                    }
169
    
170
                    public Component getLoadingComponent(String id) {
171
                        return new Label(id).setVisible(false);
×
172
                    };
173
        
174
                });
175
            }
176
        } else {
×
177
            // TODO Ugly code duplication (see above):
178

179
            add(new BookmarkablePageLink<Void>("resource", SpacePage.class, new PageParameters().set("id", space.getId())).setBody(Model.of(space.getLabel())));
×
180

181
            final List<AbstractLink> viewButtons = new ArrayList<>();
×
182
            AbstractLink addViewButton = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, new PageParameters()
×
183
                    .set("template", "https://w3id.org/np/RAxERE0cQ9jLQZ5VjeA-1v3XnE9ugxLpFG8vpkAd5FqHE")
×
184
                    .set("param_displayType", ResourceView.PART_LEVEL_VIEW_DISPLAY)
×
185
                    .set("param_resource", space.getId())
×
186
                    .set("context", space.getId())
×
187
                );
188
            addViewButton.setBody(Model.of("+ view"));
×
189
            viewButtons.add(addViewButton);
×
190
    
191
            if (space.isDataInitialized()) {
×
192
                add(new ViewList("views", space, id, nanopubId, classes));
×
193
                add(new ButtonList("view-buttons", space, null, null, viewButtons));
×
194
            } else {
195
                add(new AjaxLazyLoadPanel<Component>("views") {
×
196
        
197
                    @Override
198
                    public Component getLazyLoadComponent(String markupId) {
199
                        return new ViewList(markupId, space, id, nanopubId, classes);
×
200
                    }
201
        
202
                    @Override
203
                    protected boolean isContentReady() {
204
                        return space.isDataInitialized();
×
205
                    }
206
        
207
                });
208
                add(new AjaxLazyLoadPanel<Component>("view-buttons") {
×
209
        
210
                    @Override
211
                    public Component getLazyLoadComponent(String markupId) {
212
                        return new ButtonList(markupId, space, null, null, viewButtons);
×
213
                    }
214
        
215
                    @Override
216
                    protected boolean isContentReady() {
217
                        return space.isDataInitialized();
×
218
                    }
219
    
220
                    public Component getLoadingComponent(String id) {
221
                        return new Label(id).setVisible(false);
×
222
                    };
223
        
224
                });
225
            }
226
        }
227
    }
×
228

229
    /**
230
     * Checks if auto-refresh is enabled for this page.
231
     *
232
     * @return true if auto-refresh is enabled, false otherwise
233
     */
234
    protected boolean hasAutoRefreshEnabled() {
235
        return true;
×
236
    }
237

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