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

knowledgepixels / nanodash / 21519787438

30 Jan 2026 02:47PM UTC coverage: 14.273% (-0.7%) from 15.008%
21519787438

push

github

tkuhn
feat: Support part-pages for user profiles

553 of 5132 branches covered (10.78%)

Branch coverage included in aggregate %.

1515 of 9357 relevant lines covered (16.19%)

2.81 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.extensions.ajax.markup.html.AjaxLazyLoadPanel;
10
import org.apache.wicket.markup.html.basic.Label;
11
import org.apache.wicket.markup.html.link.AbstractLink;
12
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
13
import org.apache.wicket.model.Model;
14
import org.apache.wicket.request.mapper.parameter.PageParameters;
15
import org.eclipse.rdf4j.model.IRI;
16
import org.eclipse.rdf4j.model.Statement;
17
import org.eclipse.rdf4j.model.vocabulary.DCTERMS;
18
import org.eclipse.rdf4j.model.vocabulary.RDF;
19
import org.eclipse.rdf4j.model.vocabulary.RDFS;
20
import org.eclipse.rdf4j.model.vocabulary.SKOS;
21
import org.nanopub.Nanopub;
22
import org.nanopub.extra.services.ApiResponse;
23
import org.nanopub.extra.services.QueryRef;
24

25
import com.knowledgepixels.nanodash.ApiCache;
26
import com.knowledgepixels.nanodash.IndividualAgent;
27
import com.knowledgepixels.nanodash.MaintainedResource;
28
import com.knowledgepixels.nanodash.NanodashPageRef;
29
import com.knowledgepixels.nanodash.ProfiledResource;
30
import com.knowledgepixels.nanodash.Space;
31
import com.knowledgepixels.nanodash.User;
32
import com.knowledgepixels.nanodash.Utils;
33
import com.knowledgepixels.nanodash.component.ButtonList;
34
import com.knowledgepixels.nanodash.component.TitleBar;
35
import com.knowledgepixels.nanodash.component.ViewList;
36

37
/**
38
 * This class represents a page for a resource part in the context of a maintained resource, space, or user.
39
 */
40
public class ResourcePartPage extends NanodashPage {
41

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

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

55
    /**
56
     * Profiled resource (Space or MaintainedResource) object with the data shown on this page.
57
     */
58
    private ProfiledResource profiledResource;
59

60
    public ResourcePartPage(final PageParameters parameters) {
61
        super(parameters);
×
62

63
        final String id = parameters.get("id").toString();
×
64
        final String contextId = parameters.get("context").toString();
×
65
        final String nanopubId;
66
        String label = id.replaceFirst("^.*[#/]([^#/]+)$", "$1");
×
67
        String description = null;
×
68
        Set<IRI> classes = new HashSet<>();
×
69

70
        profiledResource = MaintainedResource.get(contextId);
×
71
        if (profiledResource == null) {
×
72
            if (Space.get(contextId) != null) {
×
73
                profiledResource = Space.get(contextId);
×
74
            } else if (User.isUser(contextId)) {
×
75
                profiledResource = IndividualAgent.get(contextId);
×
76
            } else {
77
                throw new IllegalArgumentException("Not a resource, space, or user: " + contextId);
×
78
            }
79
        }
80

81
        QueryRef getDefQuery = new QueryRef("get-term-definitions", "term", id);
×
82
        if (profiledResource.getSpace() != null) {
×
83
            for (IRI userIri : profiledResource.getSpace().getUsers()) {
×
84
                for (String pubkey : User.getUserData().getPubkeyhashes(userIri, true)) {
×
85
                    getDefQuery.getParams().put("pubkey", pubkey);
×
86
                }
×
87
            }
×
88
        } else {
89
            for (String pubkey : User.getUserData().getPubkeyhashes(Utils.vf.createIRI(contextId), true)) {
×
90
                getDefQuery.getParams().put("pubkey", pubkey);
×
91
            }
×
92
        }
93

94
        ApiResponse getDefResp = ApiCache.retrieveResponseSync(getDefQuery, false);
×
95
        if (getDefResp != null && !getDefResp.getData().isEmpty()) {
×
96
            nanopubId = getDefResp.getData().iterator().next().get("np");
×
97

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

120
        if (description != null) {
×
121
            add(new Label("description", description));
×
122
        } else {
123
            add(new Label("description").setVisible(false));
×
124
        }
125

126
        List<NanodashPageRef> breadCrumb;
127
        if (profiledResource.getSpace() != null) {
×
128
            List<ProfiledResource> superSpaces = profiledResource.getSpace().getAllSuperSpacesUntilRoot();
×
129
            if (profiledResource instanceof MaintainedResource) {
×
130
                superSpaces.add(profiledResource.getSpace());
×
131
            }
132
            superSpaces.add(profiledResource);
×
133
            breadCrumb = new ArrayList<>(superSpaces.stream().map(ss -> new NanodashPageRef(SpacePage.class, new PageParameters().add("id", ss.getId()), ss.getLabel())).toList());
×
134
        } else {
×
135
            breadCrumb = new ArrayList<>();
×
136
            breadCrumb.add(new NanodashPageRef(UserPage.class, new PageParameters().add("id", contextId), profiledResource.getLabel()));
×
137
        }
138
        breadCrumb.add(new NanodashPageRef(ResourcePartPage.class, new PageParameters().add("id", id).add("context", contextId).add("label", label), label));
×
139
        NanodashPageRef[] breadCrumbArray = breadCrumb.toArray(new NanodashPageRef[0]);
×
140
        add(new TitleBar("titlebar", this, null,
×
141
                breadCrumbArray
142
        ));
143

144
        add(new Label("pagetitle", label + " (resource part) | nanodash"));
×
145
        add(new Label("name", label));
×
146
        add(new BookmarkablePageLink<Void>("id", ExplorePage.class, parameters.set("label", label)).setBody(Model.of(id)));
×
147
        add(new BookmarkablePageLink<Void>("np", ExplorePage.class, new PageParameters().set("id", nanopubId == null ? id : nanopubId)));
×
148

149
        // TODO Improve this code, e.g. make Space a subclass of MaintainedResource or otherwise refactor:
150
        // we now use the ProfileResource abstraction, but the code still has to be imprved
151
        if (profiledResource != null) {
×
152
            final List<AbstractLink> viewButtons = new ArrayList<>();
×
153
            AbstractLink addViewButton = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, new PageParameters()
×
154
                    .set("template", "https://w3id.org/np/RAPxKWDTDP4neVtRckQcTqKHqCC_GHWWPrs7DESb2BJjo")
×
155
                    .set("template-version", "latest")
×
156
                    .set("param_resource", profiledResource.getId())
×
157
                    .set("context", profiledResource.getId())
×
158
            );
159
            addViewButton.setBody(Model.of("+ view"));
×
160
            viewButtons.add(addViewButton);
×
161

162
            final String nanopubRef = nanopubId == null ? "x:" : nanopubId;
×
163
            if (profiledResource.isDataInitialized()) {
×
164
                add(new ViewList("views", profiledResource, id, nanopubRef, classes));
×
165
                add(new ButtonList("view-buttons", profiledResource.getSpace() != null ? profiledResource.getSpace() : profiledResource, null, null, viewButtons));
×
166
            } else {
167
                add(new AjaxLazyLoadPanel<Component>("views") {
×
168

169
                    @Override
170
                    public Component getLazyLoadComponent(String markupId) {
171
                        return new ViewList(markupId, profiledResource, id, nanopubRef, classes);
×
172
                    }
173

174
                    @Override
175
                    protected boolean isContentReady() {
176
                        return profiledResource.isDataInitialized();
×
177
                    }
178

179
                });
180
                add(new AjaxLazyLoadPanel<Component>("view-buttons") {
×
181

182
                    @Override
183
                    public Component getLazyLoadComponent(String markupId) {
184
                        return new ButtonList(markupId, profiledResource.getSpace() != null ? profiledResource.getSpace() : profiledResource, null, null, viewButtons);
×
185
                    }
186

187
                    @Override
188
                    protected boolean isContentReady() {
189
                        return profiledResource.isDataInitialized();
×
190
                    }
191

192
                    public Component getLoadingComponent(String id) {
193
                        return new Label(id).setVisible(false);
×
194
                    }
195

196
                });
197
            }
198
        } else {
×
199
            // TODO Ugly code duplication (see above):
200

201
            final List<AbstractLink> viewButtons = new ArrayList<>();
×
202
            AbstractLink addViewButton = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, new PageParameters()
×
203
                    .set("template", "https://w3id.org/np/RAPxKWDTDP4neVtRckQcTqKHqCC_GHWWPrs7DESb2BJjo")
×
204
                    .set("template-version", "latest")
×
205
                    .set("param_resource", profiledResource.getSpace().getId())
×
206
                    .set("context", profiledResource.getSpace().getId())
×
207
            );
208
            addViewButton.setBody(Model.of("+ view"));
×
209
            viewButtons.add(addViewButton);
×
210

211
            if (profiledResource.getSpace().isDataInitialized()) {
×
212
                add(new ViewList("views", profiledResource.getSpace(), id, nanopubId, classes));
×
213
                add(new ButtonList("view-buttons", profiledResource.getSpace(), null, null, viewButtons));
×
214
            } else {
215
                add(new AjaxLazyLoadPanel<Component>("views") {
×
216

217
                    @Override
218
                    public Component getLazyLoadComponent(String markupId) {
219
                        return new ViewList(markupId, profiledResource.getSpace(), id, nanopubId, classes);
×
220
                    }
221

222
                    @Override
223
                    protected boolean isContentReady() {
224
                        return profiledResource.getSpace().isDataInitialized();
×
225
                    }
226

227
                });
228
                add(new AjaxLazyLoadPanel<Component>("view-buttons") {
×
229

230
                    @Override
231
                    public Component getLazyLoadComponent(String markupId) {
232
                        return new ButtonList(markupId, profiledResource.getSpace(), null, null, viewButtons);
×
233
                    }
234

235
                    @Override
236
                    protected boolean isContentReady() {
237
                        return profiledResource.getSpace().isDataInitialized();
×
238
                    }
239

240
                    public Component getLoadingComponent(String id) {
241
                        return new Label(id).setVisible(false);
×
242
                    }
243

244
                });
245
            }
246
        }
247
    }
×
248

249
    /**
250
     * Checks if auto-refresh is enabled for this page.
251
     *
252
     * @return true if auto-refresh is enabled, false otherwise
253
     */
254
    protected boolean hasAutoRefreshEnabled() {
255
        return true;
×
256
    }
257

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