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

knowledgepixels / nanodash / 21569970831

01 Feb 2026 08:46PM UTC coverage: 14.11% (-0.2%) from 14.273%
21569970831

push

github

tkuhn
style: Remove "beta" from logo and "by Knowledge Pixels" link

549 of 5182 branches covered (10.59%)

Branch coverage included in aggregate %.

1506 of 9382 relevant lines covered (16.05%)

2.11 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
                    .set("part", id)
×
159
            );
160
            addViewButton.setBody(Model.of("+ view"));
×
161
            viewButtons.add(addViewButton);
×
162

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

246
                });
247
            }
248
        }
249
    }
×
250

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

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