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

knowledgepixels / nanodash / 19473636483

18 Nov 2025 04:35PM UTC coverage: 14.513% (+0.2%) from 14.288%
19473636483

push

github

ashleycaselli
ci(deps): update action actions/setup-java to v5.0.0

542 of 4792 branches covered (11.31%)

Branch coverage included in aggregate %.

1437 of 8844 relevant lines covered (16.25%)

0.72 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.FailedApiCallException;
24
import org.nanopub.extra.services.QueryRef;
25

26
import java.util.ArrayList;
27
import java.util.HashSet;
28
import java.util.List;
29
import java.util.Set;
30

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

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

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

49
    /**
50
     * Maintained resource object with the data shown on this page.
51
     */
52
    private MaintainedResource resource;
53
    private Space space;
54

55
    public ResourcePartPage(final PageParameters parameters) throws FailedApiCallException {
56
        super(parameters);
×
57

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

68
        add(new TitleBar("titlebar", this, "connectors"));
×
69

70
        QueryRef getDefQuery = new QueryRef("get-term-definitions", "term", id);
×
71
        for (IRI userIri : space.getUsers()) {
×
72
            for (String pubkey : User.getUserData().getPubkeyhashes(userIri, true)) {
×
73
                getDefQuery.getParams().put("pubkey", pubkey);
×
74
            }
×
75
        }
×
76

77
        final String nanopubId;
78
        String label = id.replaceFirst("^.*[#/]([^#/]+)$", "$1");
×
79
        String description = null;
×
80
        Set<IRI> classes = new HashSet<>();
×
81

82
        ApiResponse getDefResp = ApiCache.retrieveResponse(getDefQuery);
×
83
        if (getDefResp == null) {
×
84
            getDefResp = QueryApiAccess.forcedGet(getDefQuery);
×
85
        }
86
        if (getDefResp != null && !getDefResp.getData().isEmpty()) {
×
87
            nanopubId = getDefResp.getData().iterator().next().get("np");
×
88

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

107

108
        if (description != null) {
×
109
            add(new Label("description", description));
×
110
        } else {
111
            add(new Label("description").setVisible(false));
×
112
        }
113

114
        add(new Label("pagetitle", label + " (resource part) | nanodash"));
×
115
        add(new Label("name", label));
×
116
        add(new BookmarkablePageLink<Void>("id", ExplorePage.class, parameters.set("label", label)).setBody(Model.of(id)));
×
117
        add(new BookmarkablePageLink<Void>("np", ExplorePage.class, new PageParameters().set("id", nanopubId == null ? id : nanopubId)));
×
118

119
        // TODO Improve this code, e.g. make Space a subclass of MaintainedResource or otherwise refactor:
120
        if (resource != null) {
×
121
            add(new BookmarkablePageLink<Void>("resource", MaintainedResourcePage.class, new PageParameters().set("id", resource.getId())).setBody(Model.of(resource.getLabel())));
×
122

123
            final List<AbstractLink> viewButtons = new ArrayList<>();
×
124
            AbstractLink addViewButton = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, new PageParameters()
×
125
                    .set("template", "https://w3id.org/np/RAxERE0cQ9jLQZ5VjeA-1v3XnE9ugxLpFG8vpkAd5FqHE")
×
126
                    .set("param_displayType", KPXL_TERMS.PART_LEVEL_VIEW_DISPLAY)
×
127
                    .set("param_resource", resource.getId())
×
128
                    .set("context", resource.getId())
×
129
            );
130
            addViewButton.setBody(Model.of("+ view"));
×
131
            viewButtons.add(addViewButton);
×
132

133
            final String nanopubRef = nanopubId == null ? "x:" : nanopubId;
×
134
            if (resource.isDataInitialized()) {
×
135
                add(new ViewList("views", resource, id, nanopubRef, classes));
×
136
                add(new ButtonList("view-buttons", space, null, null, viewButtons));
×
137
            } else {
138
                add(new AjaxLazyLoadPanel<Component>("views") {
×
139

140
                    @Override
141
                    public Component getLazyLoadComponent(String markupId) {
142
                        return new ViewList(markupId, resource, id, nanopubRef, classes);
×
143
                    }
144

145
                    @Override
146
                    protected boolean isContentReady() {
147
                        return resource.isDataInitialized();
×
148
                    }
149

150
                });
151
                add(new AjaxLazyLoadPanel<Component>("view-buttons") {
×
152

153
                    @Override
154
                    public Component getLazyLoadComponent(String markupId) {
155
                        return new ButtonList(markupId, space, null, null, viewButtons);
×
156
                    }
157

158
                    @Override
159
                    protected boolean isContentReady() {
160
                        return resource.isDataInitialized();
×
161
                    }
162

163
                    public Component getLoadingComponent(String id) {
164
                        return new Label(id).setVisible(false);
×
165
                    }
166

167
                    ;
168

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

174
            add(new BookmarkablePageLink<Void>("resource", SpacePage.class, new PageParameters().set("id", space.getId())).setBody(Model.of(space.getLabel())));
×
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", space.getId())
×
181
                    .set("context", space.getId())
×
182
            );
183
            addViewButton.setBody(Model.of("+ view"));
×
184
            viewButtons.add(addViewButton);
×
185

186
            if (space.isDataInitialized()) {
×
187
                add(new ViewList("views", space, id, nanopubId, classes));
×
188
                add(new ButtonList("view-buttons", space, 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, space, id, nanopubId, classes);
×
195
                    }
196

197
                    @Override
198
                    protected boolean isContentReady() {
199
                        return space.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, space, null, null, viewButtons);
×
208
                    }
209

210
                    @Override
211
                    protected boolean isContentReady() {
212
                        return space.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

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

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