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

knowledgepixels / nanodash / 17302137193

28 Aug 2025 04:35PM UTC coverage: 11.965% (-0.4%) from 12.355%
17302137193

Pull #244

github

web-flow
Merge 4e969b0ee into 3323a35f1
Pull Request #244: Use vocabularies with latest version of `nanopub-java`

331 of 3840 branches covered (8.62%)

Branch coverage included in aggregate %.

943 of 6808 relevant lines covered (13.85%)

0.61 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/ProjectPage.java
1
package com.knowledgepixels.nanodash.page;
2

3
import com.knowledgepixels.nanodash.QueryApiAccess;
4
import com.knowledgepixels.nanodash.Utils;
5
import com.knowledgepixels.nanodash.component.QueryResultTable;
6
import com.knowledgepixels.nanodash.component.TemplateResults;
7
import com.knowledgepixels.nanodash.component.TitleBar;
8
import com.knowledgepixels.nanodash.component.UserList;
9
import com.knowledgepixels.nanodash.template.Template;
10
import com.knowledgepixels.nanodash.template.TemplateData;
11
import org.apache.commons.lang3.tuple.Pair;
12
import org.apache.wicket.markup.html.basic.Label;
13
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
14
import org.apache.wicket.markup.html.link.ExternalLink;
15
import org.apache.wicket.markup.repeater.Item;
16
import org.apache.wicket.markup.repeater.data.DataView;
17
import org.apache.wicket.markup.repeater.data.ListDataProvider;
18
import org.apache.wicket.request.mapper.parameter.PageParameters;
19
import org.eclipse.rdf4j.model.IRI;
20
import org.eclipse.rdf4j.model.Literal;
21
import org.eclipse.rdf4j.model.Statement;
22
import org.eclipse.rdf4j.model.vocabulary.DCTERMS;
23
import org.eclipse.rdf4j.model.vocabulary.RDFS;
24
import org.nanopub.Nanopub;
25
import org.nanopub.extra.services.ApiResponse;
26
import org.nanopub.extra.services.FailedApiCallException;
27
import org.nanopub.vocabulary.NTEMPLATE;
28

29
import java.util.*;
30

31
import static com.knowledgepixels.nanodash.Utils.vf;
32

33
/**
34
 * The ProjectPage class represents a project page in the Nanodash application.
35
 */
36
public class ProjectPage extends NanodashPage {
37

38
    private static final long serialVersionUID = 1L;
39

40
    /**
41
     * The mount path for this page.
42
     */
43
    public static final String MOUNT_PATH = "/project";
44

45
    /**
46
     * {@inheritDoc}
47
     */
48
    @Override
49
    public String getMountPath() {
50
        return MOUNT_PATH;
×
51
    }
52

53
    /**
54
     * The predicate for the owner of the project.
55
     */
56
    public static final IRI HAS_OWNER = vf.createIRI("https://w3id.org/kpxl/gen/terms/hasOwner");
×
57

58
    /**
59
     * The predicate for pinned templates in the project.
60
     */
61
    public static final IRI HAS_PINNED_TEMPLATE = vf.createIRI("https://w3id.org/kpxl/gen/terms/hasPinnedTemplate");
×
62

63
    /**
64
     * The predicate for pinned queries in the project.
65
     */
66
    public static final IRI HAS_PINNED_QUERY = vf.createIRI("https://w3id.org/kpxl/gen/terms/hasPinnedQuery");
×
67

68
    /**
69
     * Constructor for the ProjectPage.
70
     *
71
     * @param parameters the page parameters
72
     * @throws org.nanopub.extra.services.FailedApiCallException if the API call fails
73
     */
74
    public ProjectPage(final PageParameters parameters) throws FailedApiCallException {
75
        super(parameters);
×
76

77
        String id = parameters.get("id").toString();
×
78
        ApiResponse resp = QueryApiAccess.get("get-introducing-np", "thing", id);
×
79
        String npId = resp.getData().get(0).get("np");
×
80
        Nanopub np = Utils.getAsNanopub(npId);
×
81

82
        add(new TitleBar("titlebar", this, null));
×
83
        String label = id.replaceFirst("^.*/", "");
×
84

85
        String description = null;
×
86
        List<IRI> owners = new ArrayList<>();
×
87
        List<Template> templates = new ArrayList<>();
×
88
        Set<String> templateTags = new HashSet<>();
×
89
        Map<String, List<Template>> templatesPerTag = new HashMap<>();
×
90
        List<IRI> queryIds = new ArrayList<>();
×
91
        IRI defaultProvenance = null;
×
92

93
        for (Statement st : np.getAssertion()) {
×
94
            if (st.getSubject().stringValue().equals(id)) {
×
95
                if (st.getPredicate().equals(DCTERMS.DESCRIPTION)) {
×
96
                    description = st.getObject().stringValue();
×
97
                } else if (st.getPredicate().equals(RDFS.LABEL)) {
×
98
                    label = st.getObject().stringValue();
×
99
                } else if (st.getPredicate().equals(HAS_OWNER) && st.getObject() instanceof IRI obj) {
×
100
                    owners.add(obj);
×
101
                } else if (st.getPredicate().equals(HAS_PINNED_TEMPLATE) && st.getObject() instanceof IRI obj) {
×
102
                    templates.add(TemplateData.get().getTemplate(obj.stringValue()));
×
103
                } else if (st.getPredicate().equals(HAS_PINNED_QUERY) && st.getObject() instanceof IRI obj) {
×
104
                    queryIds.add(obj);
×
105
                } else if (st.getPredicate().equals(NTEMPLATE.HAS_DEFAULT_PROVENANCE) && st.getObject() instanceof IRI obj) {
×
106
                    defaultProvenance = obj;
×
107
                }
108
            } else if (st.getPredicate().equals(NTEMPLATE.HAS_TAG) && st.getObject() instanceof Literal l) {
×
109
                templateTags.add(l.stringValue());
×
110
                List<Template> list = templatesPerTag.get(l.stringValue());
×
111
                if (list == null) {
×
112
                    list = new ArrayList<>();
×
113
                    templatesPerTag.put(l.stringValue(), list);
×
114
                }
115
                list.add(TemplateData.get().getTemplate(st.getSubject().stringValue()));
×
116
            }
117
        }
×
118

119
        add(new Label("pagetitle", label + " (project) | nanodash"));
×
120
        add(new Label("projectname", label));
×
121
        add(new ExternalLink("id", id, id));
×
122
        add(new BookmarkablePageLink<Void>("np", ExplorePage.class, new PageParameters().add("id", np.getUri())));
×
123
        add(new Label("description", "<span class=\"internal\">" + Utils.sanitizeHtml(description) + "</span>").setEscapeModelStrings(false));
×
124

125
        final PageParameters params = new PageParameters();
×
126
        if (defaultProvenance != null) {
×
127
            params.add("prtemplate", defaultProvenance.stringValue());
×
128
        }
129
        List<Pair<String, List<Template>>> templateLists = new ArrayList<>();
×
130
        List<String> templateTagList = new ArrayList<>(templateTags);
×
131
        Collections.sort(templateTagList);
×
132
        for (String tag : templateTagList) {
×
133
            for (Template t : templatesPerTag.get(tag)) {
×
134
                if (templates.contains(t)) templates.remove(t);
×
135
            }
×
136
            templateLists.add(Pair.of(tag, templatesPerTag.get(tag)));
×
137
        }
×
138
        if (!templates.isEmpty()) {
×
139
            String l = templateLists.isEmpty() ? "Templates" : "Other Templates";
×
140
            templateLists.add(Pair.of(l, templates));
×
141
        }
142
        add(new DataView<Pair<String, List<Template>>>("template-lists", new ListDataProvider<Pair<String, List<Template>>>(templateLists)) {
×
143

144
            private static final long serialVersionUID = 1L;
145

146
            @Override
147
            protected void populateItem(Item<Pair<String, List<Template>>> item) {
148
                item.add(new Label("label", item.getModelObject().getLeft()));
×
149
                item.add(TemplateResults.fromList("templates", item.getModelObject().getRight(), params));
×
150
            }
×
151

152
        });
153
        add(TemplateResults.fromList("templates", templates, params));
×
154
        add(new UserList("owners", owners));
×
155

156
        add(new DataView<IRI>("queries", new ListDataProvider<IRI>(queryIds)) {
×
157

158
            private static final long serialVersionUID = 1L;
159

160
            @Override
161
            protected void populateItem(Item<IRI> item) {
162
                String queryId = QueryApiAccess.getQueryId(item.getModelObject());
×
163
                item.add(QueryResultTable.createComponent("query", queryId, false));
×
164
            }
×
165

166
        });
167
    }
×
168

169
    /**
170
     * Checks if auto-refresh is enabled for this page.
171
     *
172
     * @return true if auto-refresh is enabled, false otherwise
173
     */
174
    protected boolean hasAutoRefreshEnabled() {
175
        return true;
×
176
    }
177

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