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

knowledgepixels / nanodash / 22677265677

04 Mar 2026 03:53PM UTC coverage: 15.903% (-0.05%) from 15.951%
22677265677

Pull #372

github

web-flow
Merge ca0bc354b into a74c65742
Pull Request #372: Add component for showing full URIs as plain links + ExploreDisplayMenu

701 of 5343 branches covered (13.12%)

Branch coverage included in aggregate %.

1727 of 9925 relevant lines covered (17.4%)

2.38 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.Utils;
7
import com.knowledgepixels.nanodash.component.*;
8
import com.knowledgepixels.nanodash.domain.AbstractResourceWithProfile;
9
import com.knowledgepixels.nanodash.domain.IndividualAgent;
10
import com.knowledgepixels.nanodash.domain.MaintainedResource;
11
import com.knowledgepixels.nanodash.domain.User;
12
import com.knowledgepixels.nanodash.repository.MaintainedResourceRepository;
13
import com.knowledgepixels.nanodash.repository.SpaceRepository;
14
import org.apache.wicket.Component;
15
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;
16
import org.apache.wicket.markup.html.basic.Label;
17
import org.apache.wicket.markup.html.link.AbstractLink;
18
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
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 = id.replaceFirst("^.*[#/]([^#/]+)$", "$1");
×
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 Label("pagetitle", label + " (resource part) | nanodash"));
×
145
        add(new Label("name", label));
×
146
        add(new ExternalLinkWithActionsPanel("id", Model.of(id), Model.of(label), nanopubId == null ? Values.iri(id) : Values.iri(nanopubId)));
×
147

148
        // TODO Improve this code, e.g. make Space a subclass of MaintainedResource or otherwise refactor:
149
        // we now use the ProfileResource abstraction, but the code still has to be imprved
150
        if (resourceWithProfile != null) {
×
151
            final List<AbstractLink> viewButtons = new ArrayList<>();
×
152
            viewButtons.add(new AddViewDisplayButton("button",
×
153
                            "https://w3id.org/np/RAZg-r7oQjVZ3Ewy7pUzd9eINl6fCa3HGclTsDeRag5to",
154
                            "latest",
155
                            resourceWithProfile.getId(),
×
156
                            resourceWithProfile.getId(),
×
157
                            new PageParameters()
158
                                    .set("part", id)
×
159
                    )
160
            );
161

162
            final String nanopubRef = nanopubId == null ? "x:" : nanopubId;
×
163
            final AbstractResourceWithProfile footerResource = resourceWithProfile.getSpace() != null ? resourceWithProfile.getSpace() : resourceWithProfile;
×
164
            if (resourceWithProfile.isDataInitialized()) {
×
165
                add(new ViewList("views", resourceWithProfile, id, nanopubRef, classes, footerResource, viewButtons));
×
166
            } else {
167
                add(new AjaxLazyLoadPanel<Component>("views") {
×
168

169
                    @Override
170
                    public Component getLazyLoadComponent(String markupId) {
171
                        return new ViewList(markupId, resourceWithProfile, id, nanopubRef, classes, footerResource, viewButtons);
×
172
                    }
173

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

179
                    @Override
180
                    public Component getLoadingComponent(String id) {
181
                        return new Label(id, "<div class=\"row-section\"><div class=\"col-12\">" + ResultComponent.getWaitIconHtml() + "</div></div>").setEscapeModelStrings(false);
×
182
                    }
183

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

189
            final List<AbstractLink> viewButtons = new ArrayList<>();
×
190
            viewButtons.add(new AddViewDisplayButton("button",
×
191
                            "https://w3id.org/np/RAZg-r7oQjVZ3Ewy7pUzd9eINl6fCa3HGclTsDeRag5to",
192
                            "latest",
193
                            resourceWithProfile.getSpace().getId(),
×
194
                            resourceWithProfile.getSpace().getId(),
×
195
                            new PageParameters()
196
                                    .set("part", id)
×
197
                    )
198
            );
199

200
            if (resourceWithProfile.getSpace().isDataInitialized()) {
×
201
                add(new ViewList("views", resourceWithProfile.getSpace(), id, nanopubId, classes, resourceWithProfile.getSpace(), viewButtons));
×
202
            } else {
203
                add(new AjaxLazyLoadPanel<Component>("views") {
×
204

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

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

215
                    @Override
216
                    public Component getLoadingComponent(String id) {
217
                        return new Label(id, "<div class=\"row-section\"><div class=\"col-12\">" + ResultComponent.getWaitIconHtml() + "</div></div>").setEscapeModelStrings(false);
×
218
                    }
219

220
                });
221
            }
222
        }
223
    }
×
224

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

234
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc