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

knowledgepixels / nanodash / 18883723711

28 Oct 2025 05:30PM UTC coverage: 13.555% (+0.07%) from 13.485%
18883723711

push

github

tkuhn
feat(MaintainedResource): Support for part-level views

483 of 4478 branches covered (10.79%)

Branch coverage included in aggregate %.

1259 of 8373 relevant lines covered (15.04%)

0.67 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.MaintainedResource;
28
import com.knowledgepixels.nanodash.QueryApiAccess;
29
import com.knowledgepixels.nanodash.ResourceView;
30
import com.knowledgepixels.nanodash.User;
31
import com.knowledgepixels.nanodash.Utils;
32
import com.knowledgepixels.nanodash.component.ButtonList;
33
import com.knowledgepixels.nanodash.component.TitleBar;
34
import com.knowledgepixels.nanodash.component.ViewList;
35

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

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

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

54
    /**
55
     * Maintained resource object with the data shown on this page.
56
     */
57
    private MaintainedResource resource;
58

59
    public ResourcePartPage(final PageParameters parameters) throws FailedApiCallException {
60
        super(parameters);
×
61

62
        final String id = parameters.get("id").toString();
×
63
        final String contextId = parameters.get("context").toString();
×
64
        resource = MaintainedResource.get(contextId);
×
65

66
        add(new TitleBar("titlebar", this, "connectors"));
×
67

68
        QueryRef getDefQuery = new QueryRef("get-term-definitions", "term", id);
×
69
        for (IRI userIri : resource.getSpace().getUsers()) {
×
70
            for (String pubkey : User.getUserData().getPubkeyhashes(userIri, true)) {
×
71
                getDefQuery.getParams().put("pubkey", pubkey);
×
72
            }
×
73
        }
×
74
        ApiResponse getDefResp = QueryApiAccess.forcedGet(getDefQuery);
×
75
        if (getDefResp == null || getDefResp.getData().isEmpty()) {
×
76
            throw new RestartResponseException(ExplorePage.class, parameters);
×
77
        }
78
        String nanopubId = getDefResp.getData().iterator().next().get("np");
×
79
        Nanopub nanopub = Utils.getAsNanopub(nanopubId);
×
80

81
        String label = id.replaceFirst("^.*[#/]([^#/]+)$", "$1");
×
82
        String description = null;
×
83
        Set<IRI> classes = new HashSet<>();
×
84
        for (Statement st : nanopub.getAssertion()) {
×
85
            if (!st.getSubject().stringValue().equals(id)) continue;
×
86
            if (st.getPredicate().equals(RDFS.LABEL)) label = st.getObject().stringValue();
×
87
            if (st.getPredicate().equals(SKOS.DEFINITION) || st.getPredicate().equals(DCTERMS.DESCRIPTION) || st.getPredicate().equals(RDFS.COMMENT)) {
×
88
                description = st.getObject().stringValue();
×
89
            }
90
            if (st.getPredicate().equals(RDF.TYPE) && st.getObject() instanceof IRI objIri) {
×
91
                classes.add(objIri);
×
92
            }
93
        }
×
94

95
        if (description != null) {
×
96
            add(new Label("description", description));
×
97
        } else {
98
            add(new Label("description").setVisible(false));
×
99
        }
100

101
        add(new Label("pagetitle", label + " (resource part) | nanodash"));
×
102
        add(new Label("name", label));
×
103
        add(new BookmarkablePageLink<Void>("id", ExplorePage.class, parameters.set("label", label)).setBody(Model.of(id)));
×
104
        add(new BookmarkablePageLink<Void>("np", ExplorePage.class, new PageParameters().add("id", nanopubId)));
×
105

106
        add(new BookmarkablePageLink<Void>("resource", MaintainedResourcePage.class, new PageParameters().set("id", resource.getId())).setBody(Model.of(resource.getLabel())));
×
107

108

109
        final List<AbstractLink> viewButtons = new ArrayList<>();
×
110
        AbstractLink addViewButton = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, new PageParameters()
×
111
                .add("template", "https://w3id.org/np/RAxERE0cQ9jLQZ5VjeA-1v3XnE9ugxLpFG8vpkAd5FqHE")
×
112
                .add("param_displayType", ResourceView.PART_LEVEL_VIEW_DISPLAY)
×
113
                .add("param_resource", resource.getId())
×
114
                .add("context", resource.getId())
×
115
            );
116
        addViewButton.setBody(Model.of("+"));
×
117
        viewButtons.add(addViewButton);
×
118

119
        if (resource.isDataInitialized()) {
×
120
            add(new ViewList("views", resource, id, nanopubId, classes));
×
121
            add(new ButtonList("view-buttons", resource.getSpace(), null, null, viewButtons));
×
122
        } else {
123
            add(new AjaxLazyLoadPanel<Component>("views") {
×
124
    
125
                @Override
126
                public Component getLazyLoadComponent(String markupId) {
127
                    return new ViewList(markupId, resource, id, nanopubId, classes);
×
128
                }
129
    
130
                @Override
131
                protected boolean isContentReady() {
132
                    return resource.isDataInitialized();
×
133
                }
134
    
135
            });
136
            add(new AjaxLazyLoadPanel<Component>("view-buttons") {
×
137
    
138
                @Override
139
                public Component getLazyLoadComponent(String markupId) {
140
                    return new ButtonList(markupId, resource.getSpace(), null, null, viewButtons);
×
141
                }
142
    
143
                @Override
144
                protected boolean isContentReady() {
145
                    return resource.isDataInitialized();
×
146
                }
147

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

156
    /**
157
     * Checks if auto-refresh is enabled for this page.
158
     *
159
     * @return true if auto-refresh is enabled, false otherwise
160
     */
161
    protected boolean hasAutoRefreshEnabled() {
162
        return true;
×
163
    }
164

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