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

knowledgepixels / nanodash / 19851922971

02 Dec 2025 08:23AM UTC coverage: 15.356% (+0.06%) from 15.298%
19851922971

push

github

web-flow
Merge pull request #316 from knowledgepixels/292-breadcrumb-for-space-resource-hierarchy

Add breadcrumb path element to show space/resource hierarchy

596 of 4982 branches covered (11.96%)

Branch coverage included in aggregate %.

1569 of 9117 relevant lines covered (17.21%)

0.77 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 com.knowledgepixels.nanodash.*;
4
import com.knowledgepixels.nanodash.component.ButtonList;
5
import com.knowledgepixels.nanodash.component.TitleBar;
6
import com.knowledgepixels.nanodash.component.ViewList;
7
import com.knowledgepixels.nanodash.vocabulary.KPXL_TERMS;
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 java.util.ArrayList;
26
import java.util.HashSet;
27
import java.util.List;
28
import java.util.Set;
29

30
/**
31
 * This class represents a page for a maintained resource.
32
 */
33
public class ResourcePartPage extends NanodashPage {
34

35
    /**
36
     * The mount path for this page.
37
     */
38
    public static final String MOUNT_PATH = "/part";
39

40
    /**
41
     * {@inheritDoc}
42
     */
43
    @Override
44
    public String getMountPath() {
45
        return MOUNT_PATH;
×
46
    }
47

48
    /**
49
     * Profiled resource (Space or MaintainedResource) object with the data shown on this page.
50
     */
51
    private ProfiledResource profiledResource;
52

53
    public ResourcePartPage(final PageParameters parameters) {
54
        super(parameters);
×
55

56
        final String id = parameters.get("id").toString();
×
57
        final String contextId = parameters.get("context").toString();
×
58
        profiledResource = MaintainedResource.get(contextId);
×
59
        if (profiledResource == null) {
×
60
            if (Space.get(contextId) == null) {
×
61
                throw new IllegalArgumentException("Not a resource or space: " + contextId);
×
62
            }
63
            profiledResource = Space.get(contextId);
×
64
        }
65

66
        List<ProfiledResource> superSpaces = profiledResource.getSpace().getAllSuperSpacesUntilRoot();
×
67
        if (profiledResource instanceof MaintainedResource) {
×
68
            superSpaces.add(profiledResource.getSpace());
×
69
        }
70
        superSpaces.add(profiledResource);
×
71
        add(new TitleBar("titlebar", this, null,
×
72
                superSpaces.stream().map(ss -> new NanodashPageRef(SpacePage.class, new PageParameters().add("id", ss.getId()), ss.getLabel())).toArray(NanodashPageRef[]::new)
×
73
        ));
74

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

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

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

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

112

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

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

124
        // TODO Improve this code, e.g. make Space a subclass of MaintainedResource or otherwise refactor:
125
        // we now use the ProfileResource abstraction, but the code still has to be imprved
126
        if (profiledResource != null) {
×
127
            final List<AbstractLink> viewButtons = new ArrayList<>();
×
128
            AbstractLink addViewButton = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, new PageParameters()
×
129
                    .set("template", "https://w3id.org/np/RAxERE0cQ9jLQZ5VjeA-1v3XnE9ugxLpFG8vpkAd5FqHE")
×
130
                    .set("param_displayType", KPXL_TERMS.PART_LEVEL_VIEW_DISPLAY)
×
131
                    .set("param_resource", profiledResource.getId())
×
132
                    .set("context", profiledResource.getId())
×
133
            );
134
            addViewButton.setBody(Model.of("+ view"));
×
135
            viewButtons.add(addViewButton);
×
136

137
            final String nanopubRef = nanopubId == null ? "x:" : nanopubId;
×
138
            if (profiledResource.isDataInitialized()) {
×
139
                add(new ViewList("views", profiledResource, id, nanopubRef, classes));
×
140
                add(new ButtonList("view-buttons", profiledResource.getSpace(), null, null, viewButtons));
×
141
            } else {
142
                add(new AjaxLazyLoadPanel<Component>("views") {
×
143

144
                    @Override
145
                    public Component getLazyLoadComponent(String markupId) {
146
                        return new ViewList(markupId, profiledResource, id, nanopubRef, classes);
×
147
                    }
148

149
                    @Override
150
                    protected boolean isContentReady() {
151
                        return profiledResource.isDataInitialized();
×
152
                    }
153

154
                });
155
                add(new AjaxLazyLoadPanel<Component>("view-buttons") {
×
156

157
                    @Override
158
                    public Component getLazyLoadComponent(String markupId) {
159
                        return new ButtonList(markupId, profiledResource.getSpace(), null, null, viewButtons);
×
160
                    }
161

162
                    @Override
163
                    protected boolean isContentReady() {
164
                        return profiledResource.isDataInitialized();
×
165
                    }
166

167
                    public Component getLoadingComponent(String id) {
168
                        return new Label(id).setVisible(false);
×
169
                    }
170

171
                });
172
            }
173
        } else {
×
174
            // TODO Ugly code duplication (see above):
175

176
            final List<AbstractLink> viewButtons = new ArrayList<>();
×
177
            AbstractLink addViewButton = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, new PageParameters()
×
178
                    .set("template", "https://w3id.org/np/RAxERE0cQ9jLQZ5VjeA-1v3XnE9ugxLpFG8vpkAd5FqHE")
×
179
                    .set("param_displayType", KPXL_TERMS.PART_LEVEL_VIEW_DISPLAY)
×
180
                    .set("param_resource", profiledResource.getSpace().getId())
×
181
                    .set("context", profiledResource.getSpace().getId())
×
182
            );
183
            addViewButton.setBody(Model.of("+ view"));
×
184
            viewButtons.add(addViewButton);
×
185

186
            if (profiledResource.getSpace().isDataInitialized()) {
×
187
                add(new ViewList("views", profiledResource.getSpace(), id, nanopubId, classes));
×
188
                add(new ButtonList("view-buttons", profiledResource.getSpace(), null, null, viewButtons));
×
189
            } else {
190
                add(new AjaxLazyLoadPanel<Component>("views") {
×
191

192
                    @Override
193
                    public Component getLazyLoadComponent(String markupId) {
194
                        return new ViewList(markupId, profiledResource.getSpace(), id, nanopubId, classes);
×
195
                    }
196

197
                    @Override
198
                    protected boolean isContentReady() {
199
                        return profiledResource.getSpace().isDataInitialized();
×
200
                    }
201

202
                });
203
                add(new AjaxLazyLoadPanel<Component>("view-buttons") {
×
204

205
                    @Override
206
                    public Component getLazyLoadComponent(String markupId) {
207
                        return new ButtonList(markupId, profiledResource.getSpace(), null, null, viewButtons);
×
208
                    }
209

210
                    @Override
211
                    protected boolean isContentReady() {
212
                        return profiledResource.getSpace().isDataInitialized();
×
213
                    }
214

215
                    public Component getLoadingComponent(String id) {
216
                        return new Label(id).setVisible(false);
×
217
                    }
218

219
                });
220
            }
221
        }
222
    }
×
223

224
    /**
225
     * Checks if auto-refresh is enabled for this page.
226
     *
227
     * @return true if auto-refresh is enabled, false otherwise
228
     */
229
    protected boolean hasAutoRefreshEnabled() {
230
        return true;
×
231
    }
232

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