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

knowledgepixels / nanodash / 18836452063

27 Oct 2025 09:39AM UTC coverage: 13.1% (-0.6%) from 13.674%
18836452063

push

github

tkuhn
feat: Get term definition nanopubs for resource part pages

457 of 4440 branches covered (10.29%)

Branch coverage included in aggregate %.

1212 of 8300 relevant lines covered (14.6%)

0.65 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 org.apache.wicket.RestartResponseException;
4
import org.apache.wicket.markup.html.basic.Label;
5
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
6
import org.apache.wicket.model.Model;
7
import org.apache.wicket.request.mapper.parameter.PageParameters;
8
import org.eclipse.rdf4j.model.IRI;
9
import org.eclipse.rdf4j.model.Statement;
10
import org.eclipse.rdf4j.model.vocabulary.DCTERMS;
11
import org.eclipse.rdf4j.model.vocabulary.RDFS;
12
import org.eclipse.rdf4j.model.vocabulary.SKOS;
13
import org.nanopub.Nanopub;
14
import org.nanopub.extra.services.ApiResponse;
15
import org.nanopub.extra.services.FailedApiCallException;
16
import org.nanopub.extra.services.QueryRef;
17

18
import com.knowledgepixels.nanodash.MaintainedResource;
19
import com.knowledgepixels.nanodash.QueryApiAccess;
20
import com.knowledgepixels.nanodash.User;
21
import com.knowledgepixels.nanodash.Utils;
22
import com.knowledgepixels.nanodash.component.TitleBar;
23

24
/**
25
 * This class represents a page for a maintained resource.
26
 */
27
public class ResourcePartPage extends NanodashPage {
28

29
    /**
30
     * The mount path for this page.
31
     */
32
    public static final String MOUNT_PATH = "/part";
33

34
    /**
35
     * {@inheritDoc}
36
     */
37
    @Override
38
    public String getMountPath() {
39
        return MOUNT_PATH;
×
40
    }
41

42
    /**
43
     * Maintained resource object with the data shown on this page.
44
     */
45
    private MaintainedResource resource;
46

47
    public ResourcePartPage(final PageParameters parameters) throws FailedApiCallException {
48
        super(parameters);
×
49

50
        final String id = parameters.get("id").toString();
×
51
        final String contextId = parameters.get("context").toString();
×
52
        resource = MaintainedResource.get(contextId);
×
53

54
        add(new TitleBar("titlebar", this, "connectors"));
×
55

56
        QueryRef getDefQuery = new QueryRef("get-term-definitions", "term", id);
×
57
        for (IRI userIri : resource.getSpace().getUsers()) {
×
58
            for (String pubkey : User.getUserData().getPubkeyhashes(userIri, true)) {
×
59
                getDefQuery.getParams().put("pubkey", pubkey);
×
60
            }
×
61
        }
×
62
        ApiResponse getDefResp = QueryApiAccess.forcedGet(getDefQuery);
×
63
        if (getDefResp == null || getDefResp.getData().isEmpty()) {
×
64
            throw new RestartResponseException(ExplorePage.class, parameters);
×
65
        }
66
        String nanopubId = getDefResp.getData().iterator().next().get("np");
×
67
        Nanopub nanopub = Utils.getAsNanopub(nanopubId);
×
68

69
        String label = id.replaceFirst("^.*[#/]([^#/]+)$", "$1");
×
70
        String description = null;
×
71
        for (Statement st : nanopub.getAssertion()) {
×
72
            if (!st.getSubject().stringValue().equals(id)) continue;
×
73
            if (st.getPredicate().equals(RDFS.LABEL)) label = st.getObject().stringValue();
×
74
            if (st.getPredicate().equals(SKOS.DEFINITION) || st.getPredicate().equals(DCTERMS.DESCRIPTION) || st.getPredicate().equals(RDFS.COMMENT)) {
×
75
                description = st.getObject().stringValue();
×
76
            }
77
        }
×
78

79
        if (description != null) {
×
80
            add(new Label("description", description));
×
81
        } else {
82
            add(new Label("description").setVisible(false));
×
83
        }
84

85
        add(new Label("pagetitle", label + " (resource part) | nanodash"));
×
86
        add(new Label("name", label));
×
87
        add(new BookmarkablePageLink<Void>("id", ExplorePage.class, parameters.set("label", label)).setBody(Model.of(id)));
×
88
        add(new BookmarkablePageLink<Void>("np", ExplorePage.class, new PageParameters().add("id", nanopubId)));
×
89

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

92

93
//        final List<AbstractLink> viewButtons = new ArrayList<>();
94
//        AbstractLink addViewButton = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, new PageParameters()
95
//                .add("template", "https://w3id.org/np/RA7vjbk3kz4FCu2eTX5oekZshPeOGNGTw8b2WLk8ZS7VI")
96
//                .add("param_resource", resource.getId())
97
//                .add("context", resource.getId())
98
//            );
99
//        addViewButton.setBody(Model.of("+"));
100
//        viewButtons.add(addViewButton);
101
//
102
//        if (resource.isDataInitialized()) {
103
//            add(new ViewList("views", resource));
104
//            add(new ButtonList("view-buttons", space, null, null, viewButtons));
105
//        } else {
106
//            add(new AjaxLazyLoadPanel<Component>("views") {
107
//    
108
//                @Override
109
//                public Component getLazyLoadComponent(String markupId) {
110
//                    return new ViewList(markupId, resource);
111
//                }
112
//    
113
//                @Override
114
//                protected boolean isContentReady() {
115
//                    return resource.isDataInitialized();
116
//                }
117
//    
118
//            });
119
//            add(new AjaxLazyLoadPanel<Component>("view-buttons") {
120
//    
121
//                @Override
122
//                public Component getLazyLoadComponent(String markupId) {
123
//                    return new ButtonList(markupId, space, null, null, viewButtons);
124
//                }
125
//    
126
//                @Override
127
//                protected boolean isContentReady() {
128
//                    return resource.isDataInitialized();
129
//                }
130
//
131
//                public Component getLoadingComponent(String id) {
132
//                    return new Label(id).setVisible(false);
133
//                };
134
//    
135
//            });
136
//        }
137
    }
×
138

139
    /**
140
     * Checks if auto-refresh is enabled for this page.
141
     *
142
     * @return true if auto-refresh is enabled, false otherwise
143
     */
144
    protected boolean hasAutoRefreshEnabled() {
145
        return true;
×
146
    }
147

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