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

knowledgepixels / nanodash / 23847171852

01 Apr 2026 11:51AM UTC coverage: 15.884% (-0.4%) from 16.286%
23847171852

push

github

web-flow
Merge pull request #428 from knowledgepixels/feature/422-download-rdf

Add raw page content RDF download

769 of 6002 branches covered (12.81%)

Branch coverage included in aggregate %.

1938 of 11040 relevant lines covered (17.55%)

2.4 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.ApiCache;
4
import com.knowledgepixels.nanodash.NanodashPageRef;
5
import com.knowledgepixels.nanodash.QueryApiAccess;
6
import com.knowledgepixels.nanodash.SpaceMemberRole;
7
import com.knowledgepixels.nanodash.Utils;
8
import com.knowledgepixels.nanodash.component.*;
9
import com.knowledgepixels.nanodash.domain.AbstractResourceWithProfile;
10
import com.knowledgepixels.nanodash.domain.IndividualAgent;
11
import com.knowledgepixels.nanodash.domain.MaintainedResource;
12
import com.knowledgepixels.nanodash.domain.Space;
13
import com.knowledgepixels.nanodash.domain.User;
14
import com.knowledgepixels.nanodash.repository.MaintainedResourceRepository;
15
import com.knowledgepixels.nanodash.repository.SpaceRepository;
16
import org.apache.wicket.Component;
17
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;
18
import org.apache.wicket.markup.html.basic.Label;
19
import org.apache.wicket.model.Model;
20
import org.apache.wicket.request.mapper.parameter.PageParameters;
21
import org.eclipse.rdf4j.model.IRI;
22
import org.eclipse.rdf4j.model.Statement;
23
import org.eclipse.rdf4j.model.util.Values;
24
import org.eclipse.rdf4j.model.vocabulary.DCTERMS;
25
import org.eclipse.rdf4j.model.vocabulary.RDF;
26
import org.eclipse.rdf4j.model.vocabulary.RDFS;
27
import org.eclipse.rdf4j.model.vocabulary.SKOS;
28
import org.nanopub.Nanopub;
29
import org.nanopub.extra.services.ApiResponse;
30
import org.nanopub.extra.services.QueryRef;
31

32
import java.util.ArrayList;
33
import java.util.HashSet;
34
import java.util.List;
35
import java.util.Set;
36

37
/**
38
 * This class represents a page for a resource part in the context of a maintained resource, space, or user.
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
     * Resource with profile (Space or MaintainedResource) object with the data shown on this page.
57
     */
58
    private AbstractResourceWithProfile resourceWithProfile;
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 = parameters.get("label").isEmpty() ? id.replaceFirst("^.*[#/]([^#/]+)$", "$1") : parameters.get("label").toString();
×
67
        String description = null;
×
68
        Set<IRI> classes = new HashSet<>();
×
69

70
        resourceWithProfile = MaintainedResourceRepository.get().findById(contextId);
×
71
        if (resourceWithProfile == null) {
×
72
            if (SpaceRepository.get().findById(contextId) != null) {
×
73
                resourceWithProfile = SpaceRepository.get().findById(contextId);
×
74
            } else if (IndividualAgent.isUser(contextId)) {
×
75
                resourceWithProfile = IndividualAgent.get(contextId);
×
76
            } else {
77
                throw new IllegalArgumentException("Not a resource, space, or user: " + contextId);
×
78
            }
79
        }
80

81
        QueryRef getDefQuery = new QueryRef(QueryApiAccess.GET_TERM_DEFINITIONS, "term", id);
×
82
        if (resourceWithProfile.getSpace() != null) {
×
83
            for (IRI userIri : resourceWithProfile.getSpace().getUsers()) {
×
84
                for (String pubkey : User.getUserData().getPubkeyHashes(userIri, true)) {
×
85
                    getDefQuery.getParams().put("pubkey", pubkey);
×
86
                }
×
87
            }
×
88
        } else {
89
            for (String pubkey : User.getUserData().getPubkeyHashes(Utils.vf.createIRI(contextId), true)) {
×
90
                getDefQuery.getParams().put("pubkey", pubkey);
×
91
            }
×
92
        }
93

94
        ApiResponse getDefResp = ApiCache.retrieveResponseSync(getDefQuery, false);
×
95
        if (getDefResp != null && !getDefResp.getData().isEmpty()) {
×
96
            nanopubId = getDefResp.getData().iterator().next().get("np");
×
97

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

120
        if (description != null) {
×
121
            add(new Label("description", description));
×
122
        } else {
123
            add(new Label("description").setVisible(false));
×
124
        }
125

126
        List<NanodashPageRef> breadCrumb;
127
        if (resourceWithProfile.getSpace() != null) {
×
128
            List<AbstractResourceWithProfile> superSpaces = resourceWithProfile.getSpace().getAllSuperSpacesUntilRoot();
×
129
            if (resourceWithProfile instanceof MaintainedResource) {
×
130
                superSpaces.add(resourceWithProfile.getSpace());
×
131
            }
132
            superSpaces.add(resourceWithProfile);
×
133
            breadCrumb = new ArrayList<>(superSpaces.stream().map(ss -> new NanodashPageRef(SpacePage.class, new PageParameters().add("id", ss.getId()), ss.getLabel())).toList());
×
134
        } else {
×
135
            breadCrumb = new ArrayList<>();
×
136
            breadCrumb.add(new NanodashPageRef(UserPage.class, new PageParameters().add("id", contextId), resourceWithProfile.getLabel()));
×
137
        }
138
        breadCrumb.add(new NanodashPageRef(ResourcePartPage.class, new PageParameters().add("id", id).add("context", contextId).add("label", label), label));
×
139
        NanodashPageRef[] breadCrumbArray = breadCrumb.toArray(new NanodashPageRef[0]);
×
140
        add(new TitleBar("titlebar", this, null,
×
141
                breadCrumbArray
142
        ));
143

144
        add(new JustPublishedMessagePanel("justPublishedMessage", parameters));
×
145

146
        add(new Label("pagetitle", label + " (resource part) | nanodash"));
×
147
        add(new Label("name", label));
×
148
        add(new ExternalLinkWithActionsPanel("id", Model.of(id), Model.of(label), nanopubId == null ? Values.iri(id) : Values.iri(nanopubId)));
×
149

150
        boolean showButton = false;
×
151
        if (resourceWithProfile instanceof IndividualAgent ia) {
×
152
            showButton = ia.isCurrentUser();
×
153
        } else if (resourceWithProfile.getSpace() != null) {
×
154
            showButton = SpaceMemberRole.isCurrentUserAdmin(resourceWithProfile.getSpace());
×
155
        } else if (resourceWithProfile instanceof Space s) {
×
156
            showButton = SpaceMemberRole.isCurrentUserAdmin(s);
×
157
        }
158
        add(new AddViewDisplayButton("addviewdisplay",
×
159
                "https://w3id.org/np/RAZg-r7oQjVZ3Ewy7pUzd9eINl6fCa3HGclTsDeRag5to",
160
                "latest",
161
                resourceWithProfile.getId(),
×
162
                resourceWithProfile.getId(),
×
163
                new PageParameters()
164
                        .set("part", id)
×
165
                        .set("refresh-upon-publish", resourceWithProfile.getId())
×
166
        ).setVisible(showButton));
×
167

168
        add(new DownloadRdfLinks("download-rdf", "part", id, resourceWithProfile.getId()));
×
169

170
        final String nanopubRef = nanopubId == null ? "x:" : nanopubId;
×
171
        if (resourceWithProfile.isDataInitialized()) {
×
172
            add(new ViewList("views", resourceWithProfile, id, nanopubRef, classes));
×
173
        } else {
174
            add(new AjaxLazyLoadPanel<Component>("views") {
×
175

176
                @Override
177
                public Component getLazyLoadComponent(String markupId) {
178
                    return new ViewList(markupId, resourceWithProfile, id, nanopubRef, classes);
×
179
                }
180

181
                @Override
182
                protected boolean isContentReady() {
183
                    return resourceWithProfile.isDataInitialized();
×
184
                }
185

186
                @Override
187
                public Component getLoadingComponent(String id) {
188
                    return new Label(id, "<div class=\"row-section\"><div class=\"col-12\">" + ResultComponent.getWaitIconHtml() + "</div></div>").setEscapeModelStrings(false);
×
189
                }
190

191
            });
192
        }
193
    }
×
194

195
    /**
196
     * Checks if auto-refresh is enabled for this page.
197
     *
198
     * @return true if auto-refresh is enabled, false otherwise
199
     */
200
    protected boolean hasAutoRefreshEnabled() {
201
        return true;
×
202
    }
203

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