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

knowledgepixels / nanodash / 19963316244

05 Dec 2025 12:43PM UTC coverage: 15.37% (+0.2%) from 15.197%
19963316244

push

github

tkuhn
Merge branch 'master' of github.com:knowledgepixels/nanodash

593 of 4972 branches covered (11.93%)

Branch coverage included in aggregate %.

1567 of 9081 relevant lines covered (17.26%)

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 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.MaintainedResource;
27
import com.knowledgepixels.nanodash.NanodashPageRef;
28
import com.knowledgepixels.nanodash.ProfiledResource;
29
import com.knowledgepixels.nanodash.QueryApiAccess;
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 maintained resource.
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
                throw new IllegalArgumentException("Not a resource or space: " + contextId);
×
74
            }
75
            profiledResource = Space.get(contextId);
×
76
        }
77

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

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

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

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

120
        List<ProfiledResource> superSpaces = profiledResource.getSpace().getAllSuperSpacesUntilRoot();
×
121
        if (profiledResource instanceof MaintainedResource) {
×
122
            superSpaces.add(profiledResource.getSpace());
×
123
        }
124
        superSpaces.add(profiledResource);
×
125
        List<NanodashPageRef> breadCrumb = new ArrayList<>(superSpaces.stream().map(ss -> new NanodashPageRef(SpacePage.class, new PageParameters().add("id", ss.getId()), ss.getLabel())).toList());
×
126
        breadCrumb.add(new NanodashPageRef(ResourcePartPage.class, new PageParameters().add("id", id).add("context", contextId).add("label", label), label));
×
127
        NanodashPageRef[] breadCrumbArray = breadCrumb.toArray(new NanodashPageRef[0]);
×
128
        add(new TitleBar("titlebar", this, null,
×
129
                breadCrumbArray
130
        ));
131

132
        add(new Label("pagetitle", label + " (resource part) | nanodash"));
×
133
        add(new Label("name", label));
×
134
        add(new BookmarkablePageLink<Void>("id", ExplorePage.class, parameters.set("label", label)).setBody(Model.of(id)));
×
135
        add(new BookmarkablePageLink<Void>("np", ExplorePage.class, new PageParameters().set("id", nanopubId == null ? id : nanopubId)));
×
136

137
        // TODO Improve this code, e.g. make Space a subclass of MaintainedResource or otherwise refactor:
138
        // we now use the ProfileResource abstraction, but the code still has to be imprved
139
        if (profiledResource != null) {
×
140
            final List<AbstractLink> viewButtons = new ArrayList<>();
×
141
            AbstractLink addViewButton = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, new PageParameters()
×
142
                    .set("template", "https://w3id.org/np/RAPxKWDTDP4neVtRckQcTqKHqCC_GHWWPrs7DESb2BJjo")
×
143
                    .set("template-version", "latest")
×
144
                    .set("param_resource", profiledResource.getId())
×
145
                    .set("context", profiledResource.getId())
×
146
            );
147
            addViewButton.setBody(Model.of("+ view"));
×
148
            viewButtons.add(addViewButton);
×
149

150
            final String nanopubRef = nanopubId == null ? "x:" : nanopubId;
×
151
            if (profiledResource.isDataInitialized()) {
×
152
                add(new ViewList("views", profiledResource, id, nanopubRef, classes));
×
153
                add(new ButtonList("view-buttons", profiledResource.getSpace(), null, null, viewButtons));
×
154
            } else {
155
                add(new AjaxLazyLoadPanel<Component>("views") {
×
156

157
                    @Override
158
                    public Component getLazyLoadComponent(String markupId) {
159
                        return new ViewList(markupId, profiledResource, id, nanopubRef, classes);
×
160
                    }
161

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

167
                });
168
                add(new AjaxLazyLoadPanel<Component>("view-buttons") {
×
169

170
                    @Override
171
                    public Component getLazyLoadComponent(String markupId) {
172
                        return new ButtonList(markupId, profiledResource.getSpace(), null, null, viewButtons);
×
173
                    }
174

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

180
                    public Component getLoadingComponent(String id) {
181
                        return new Label(id).setVisible(false);
×
182
                    }
183

184
                });
185
            }
186
        } else {
×
187
            // TODO Ugly code duplication (see above):
188

189
            final List<AbstractLink> viewButtons = new ArrayList<>();
×
190
            AbstractLink addViewButton = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, new PageParameters()
×
191
                    .set("template", "https://w3id.org/np/RAPxKWDTDP4neVtRckQcTqKHqCC_GHWWPrs7DESb2BJjo")
×
192
                    .set("template-version", "latest")
×
193
                    .set("param_resource", profiledResource.getSpace().getId())
×
194
                    .set("context", profiledResource.getSpace().getId())
×
195
            );
196
            addViewButton.setBody(Model.of("+ view"));
×
197
            viewButtons.add(addViewButton);
×
198

199
            if (profiledResource.getSpace().isDataInitialized()) {
×
200
                add(new ViewList("views", profiledResource.getSpace(), id, nanopubId, classes));
×
201
                add(new ButtonList("view-buttons", profiledResource.getSpace(), null, null, viewButtons));
×
202
            } else {
203
                add(new AjaxLazyLoadPanel<Component>("views") {
×
204

205
                    @Override
206
                    public Component getLazyLoadComponent(String markupId) {
207
                        return new ViewList(markupId, profiledResource.getSpace(), id, nanopubId, classes);
×
208
                    }
209

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

215
                });
216
                add(new AjaxLazyLoadPanel<Component>("view-buttons") {
×
217

218
                    @Override
219
                    public Component getLazyLoadComponent(String markupId) {
220
                        return new ButtonList(markupId, profiledResource.getSpace(), null, null, viewButtons);
×
221
                    }
222

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

228
                    public Component getLoadingComponent(String id) {
229
                        return new Label(id).setVisible(false);
×
230
                    }
231

232
                });
233
            }
234
        }
235
    }
×
236

237
    /**
238
     * Checks if auto-refresh is enabled for this page.
239
     *
240
     * @return true if auto-refresh is enabled, false otherwise
241
     */
242
    protected boolean hasAutoRefreshEnabled() {
243
        return true;
×
244
    }
245

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