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

knowledgepixels / nanodash / 17837235071

18 Sep 2025 05:58PM UTC coverage: 13.87%. Remained the same
17837235071

push

github

tkuhn
chore: Remove serialVersionUIDs

443 of 4022 branches covered (11.01%)

Branch coverage included in aggregate %.

1133 of 7341 relevant lines covered (15.43%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
src/main/java/com/knowledgepixels/nanodash/component/ProfileIntroItem.java
1
package com.knowledgepixels.nanodash.component;
2

3
import com.knowledgepixels.nanodash.NanodashPreferences;
4
import com.knowledgepixels.nanodash.NanodashSession;
5
import com.knowledgepixels.nanodash.User;
6
import com.knowledgepixels.nanodash.Utils;
7
import com.knowledgepixels.nanodash.page.ExplorePage;
8
import com.knowledgepixels.nanodash.page.PublishPage;
9
import net.trustyuri.TrustyUriUtils;
10
import org.apache.commons.codec.Charsets;
11
import org.apache.wicket.markup.html.WebMarkupContainer;
12
import org.apache.wicket.markup.html.basic.Label;
13
import org.apache.wicket.markup.html.link.ExternalLink;
14
import org.apache.wicket.markup.html.panel.Panel;
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.eclipse.rdf4j.model.IRI;
19
import org.nanopub.SimpleTimestampPattern;
20
import org.nanopub.extra.security.KeyDeclaration;
21
import org.nanopub.extra.setting.IntroNanopub;
22

23
import java.net.URLEncoder;
24
import java.util.Calendar;
25
import java.util.HashMap;
26
import java.util.Map;
27

28
import static com.knowledgepixels.nanodash.Utils.urlEncode;
29

30
/**
31
 * A panel that shows the user's introduction nanopubs.
32
 */
33
public class ProfileIntroItem extends Panel {
34

35
    private NanodashSession session = NanodashSession.get();
×
36
    private NanodashPreferences prefs = NanodashPreferences.get();
×
37
    private int recommendedActionsCount = 0;
×
38
    private Map<IntroNanopub, String> includeKeysParamMap = new HashMap<>();
×
39
    private int approvedIntrosCount = 0;
×
40

41
    /**
42
     * Constructor.
43
     *
44
     * @param id the component id
45
     */
46
    public ProfileIntroItem(String id) {
47
        super(id);
×
48

49
        String publishIntroLinkString = PublishPage.MOUNT_PATH +
×
50
                                        "?template=http://purl.org/np/RAT8ayO62s4SFqDY1qjv24Iw0xarpbpc6zH68n7hRsAsA&" +
51
                                        "param_user=" + urlEncode(session.getUserIri()) + "&" +
×
52
//                                "param_name=" + urlEncode(session.getOrcidName()) + "&" +
53
                                        "param_public-key=" + urlEncode(session.getPubkeyString()) + "&" +
×
54
                                        "param_key-declaration=" + urlEncode(Utils.getShortPubkeyName(session.getPubkeyString())) + "&" +
×
55
                                        "param_key-declaration-ref=" + urlEncode(Utils.getShortPubkeyName(session.getPubkeyString())) + "&" +
×
56
                                        "param_key-location=" + urlEncode(prefs.getWebsiteUrl()) + "&" +
×
57
                                        "link-message=" + urlEncode("Check the checkbox at the end of this page and press 'Publish' to publish this " +
×
58
                                                                    "introduction linking your ORCID identifier to the local key used on this site.");
59

60
        // Do this here, so we know whether to show the recommended action before rendering stage:
61
        if (session.getLocalIntro() != null) {
×
62
            for (IntroNanopub inp : session.getUserIntroNanopubs()) {
×
63
                if (User.isApproved(inp)) approvedIntrosCount++;
×
64
                String params = "";
×
65
                int paramIndex = 0;
×
66
                for (KeyDeclaration kd : inp.getKeyDeclarations()) {
×
67
                    if (!hasKey(session.getLocalIntro(), kd)) {
×
68
                        paramIndex++;
×
69
                        params += "&" +
×
70
                                  "param_public-key__." + paramIndex + "=" + urlEncode(kd.getPublicKeyString()) + "&" +
×
71
                                  "param_key-declaration__." + paramIndex + "=" + urlEncode(Utils.getShortPubkeyName(kd.getPublicKeyString())) + "&" +
×
72
                                  "param_key-declaration-ref__." + paramIndex + "=" + urlEncode(Utils.getShortPubkeyName(kd.getPublicKeyString())) + "&" +
×
73
                                  "param_key-location__." + paramIndex + "=" + urlEncode(kd.getKeyLocation() == null ? "" : kd.getKeyLocation());
×
74
                    }
75
                }
×
76
                if (paramIndex > 0) {
×
77
                    includeKeysParamMap.put(inp, params);
×
78
                }
79
            }
×
80
        }
81

82
        WebMarkupContainer publishIntroItem = new WebMarkupContainer("publish-intro-item");
×
83
        publishIntroItem.add(new ExternalLink("publish-intro-link", publishIntroLinkString, "new introduction..."));
×
84
        add(publishIntroItem);
×
85
        publishIntroItem.setVisible(session.getLocalIntroCount() == 0);
×
86
        if (publishIntroItem.isVisible()) recommendedActionsCount++;
×
87

88
        WebMarkupContainer includeKeysItem = new WebMarkupContainer("include-keys-item");
×
89
        add(includeKeysItem);
×
90
        includeKeysItem.setVisible(!includeKeysParamMap.isEmpty());
×
91
        if (includeKeysItem.isVisible()) recommendedActionsCount++;
×
92

93
        WebMarkupContainer retractIntroItem = new WebMarkupContainer("retract-intro-item");
×
94
        add(retractIntroItem);
×
95
        retractIntroItem.setVisible(session.getLocalIntroCount() > 1);
×
96
        if (retractIntroItem.isVisible()) recommendedActionsCount++;
×
97

98
        WebMarkupContainer deriveIntroItem = new WebMarkupContainer("derive-intro-item");
×
99
        add(deriveIntroItem);
×
100
        deriveIntroItem.setVisible(session.getLocalIntroCount() == 0 && !session.getUserIntroNanopubs().isEmpty());
×
101
        if (deriveIntroItem.isVisible()) recommendedActionsCount++;
×
102

103
        WebMarkupContainer updateApprovedItem = new WebMarkupContainer("update-approved-item");
×
104
        add(updateApprovedItem);
×
105
        updateApprovedItem.setVisible(!session.isPubkeyApproved() && approvedIntrosCount > 0 && session.getLocalIntroCount() > 0);
×
106
        if (updateApprovedItem.isVisible()) recommendedActionsCount++;
×
107

108
        WebMarkupContainer getApprovalItem = new WebMarkupContainer("get-approval-item");
×
109
        String introUrl = (session.getLocalIntro() == null ? "" : session.getLocalIntro().getNanopub().getUri().stringValue());
×
110
        getApprovalItem.add(new ExternalLink("introduction-to-be-approved", introUrl, introUrl));
×
111
        add(getApprovalItem);
×
112
        getApprovalItem.setVisible(!session.isPubkeyApproved() && session.getLocalIntroCount() == 1);
×
113
        if (getApprovalItem.isVisible()) recommendedActionsCount++;
×
114

115
        WebMarkupContainer orcidLinkingItem = new WebMarkupContainer("orcid-linking-item");
×
116
        add(orcidLinkingItem);
×
117
        orcidLinkingItem.setVisible(false);
×
118
//                orcidLinkingItem.setVisible(!session.isOrcidLinked() && session.getLocalIntroCount() == 1);
119
        if (orcidLinkingItem.isVisible()) recommendedActionsCount++;
×
120

121
        if (session.getUserIntroNanopubs().isEmpty()) {
×
122
            add(new Label("intro-note", "<em>There are no introductions yet.</em>").setEscapeModelStrings(false));
×
123
        } else if (session.getLocalIntroCount() == 0) {
×
124
            // TODO: Check whether it's part of an introduction for a different ORCID, and show a warning if so
125
            add(new Label("intro-note", "The local key from this site is <strong class=\"negative\">not part of an introduction</strong> yet.").setEscapeModelStrings(false));
×
126
        } else if (session.getLocalIntroCount() == 1) {
×
127
            add(new Label("intro-note", ""));
×
128
        } else {
129
            add(new Label("intro-note", "You have <strong class=\"negative\">multiple introductions from this site</strong>.").setEscapeModelStrings(false));
×
130
        }
131
        if (recommendedActionsCount == 0) {
×
132
            add(new Label("action-note", "<em>There are no recommended actions.</em>").setEscapeModelStrings(false));
×
133
        } else if (recommendedActionsCount == 1) {
×
134
            add(new Label("action-note", "It is recommended that you <strong>execute this action</strong>:").setEscapeModelStrings(false));
×
135
        } else {
136
            add(new Label("action-note", "It is recommended that you <strong>execute one of these actions</strong>:").setEscapeModelStrings(false));
×
137
        }
138

139
        add(new DataView<IntroNanopub>("intro-nps", new ListDataProvider<IntroNanopub>(session.getUserIntroNanopubs())) {
×
140

141
            @Override
142
            protected void populateItem(Item<IntroNanopub> item) {
143
                final IntroNanopub inp = item.getModelObject();
×
144
                IRI location = Utils.getLocation(inp);
×
145
                String uri = inp.getNanopub().getUri().stringValue();
×
146
                ExternalLink link = new ExternalLink("intro-uri", ExplorePage.MOUNT_PATH + "?id=" + URLEncoder.encode(uri, Charsets.UTF_8));
×
147
                link.add(new Label("intro-uri-label", TrustyUriUtils.getArtifactCode(uri).substring(0, 10)));
×
148
                item.add(link);
×
149
                if (User.isApproved(inp)) {
×
150
                    item.add(new Label("intro-note", " <strong class=\"positive\">(approved)</strong>").setEscapeModelStrings(false));
×
151
                } else {
152
                    item.add(new Label("intro-note", ""));
×
153
                }
154
                if (session.isIntroWithLocalKey(inp)) {
×
155
                    item.add(new Label("location", "<strong>this site</strong>").setEscapeModelStrings(false));
×
156
                } else if (location == null) {
×
157
                    item.add(new Label("location", "unknown site"));
×
158
                } else {
159
                    item.add(new Label("location", "<a href=\"" + location + "\">" + location + "</a>").setEscapeModelStrings(false));
×
160
                }
161
                Calendar creationDate = SimpleTimestampPattern.getCreationTime(inp.getNanopub());
×
162
                item.add(new Label("date", (creationDate == null ? "unknown date" : NanopubItem.simpleDateFormat.format(creationDate.getTime()))));
×
163

164
                ExternalLink retractLink = new ExternalLink("retract-link", PublishPage.MOUNT_PATH + "?" +
×
165
                                                                            "template=http://purl.org/np/RA0QOsYNphQCityVcDIJEuldhhuJOX3GlBLw6QylRBhEI&" +
166
                                                                            "param_nanopubToBeRetracted=" + urlEncode(inp.getNanopub().getUri()) + "&" +
×
167
                                                                            "link-message=" + urlEncode("Check the checkbox at the end of this page and press 'Publish' to retract the " +
×
168
                                                                                                        "given introduction."),
169
                        "retract...");
170
                item.add(retractLink);
×
171
                retractLink.setVisible(session.getLocalIntroCount() > 1 && session.isIntroWithLocalKey(inp));
×
172

173
                ExternalLink deriveLink = new ExternalLink("derive-link", PublishPage.MOUNT_PATH + "?" +
×
174
                                                                          "template=http://purl.org/np/RAT8ayO62s4SFqDY1qjv24Iw0xarpbpc6zH68n7hRsAsA&" +
175
                                                                          "derive-a=" + urlEncode(inp.getNanopub().getUri()) + "&" +
×
176
                                                                          "param_public-key__.1=" + urlEncode(session.getPubkeyString()) + "&" +
×
177
                                                                          "param_key-declaration__.1=" + urlEncode(Utils.getShortPubkeyName(session.getPubkeyString())) + "&" +
×
178
                                                                          "param_key-declaration-ref__.1=" + urlEncode(Utils.getShortPubkeyName(session.getPubkeyString())) + "&" +
×
179
                                                                          "param_key-location__.1=" + urlEncode(prefs.getWebsiteUrl()) + "&" +
×
180
                                                                          "link-message=" + urlEncode("Enter you name below, check the checkbox at the end of the page, and press 'Publish' to publish this " +
×
181
                                                                                                      "introduction linking your ORCID identifier to the given keys."),
182
                        "derive new introduction...");
183
                item.add(deriveLink);
×
184
                deriveLink.setVisible(!session.isIntroWithLocalKey(inp) && session.getLocalIntroCount() == 0);
×
185

186
                if (includeKeysParamMap.containsKey(inp)) {
×
187
                    item.add(new ExternalLink("include-keys-link", PublishPage.MOUNT_PATH + "?" +
×
188
                                                                   "template=http://purl.org/np/RAT8ayO62s4SFqDY1qjv24Iw0xarpbpc6zH68n7hRsAsA&" +
189
                                                                   "supersede=" + urlEncode(session.getLocalIntro().getNanopub().getUri()) +
×
190
                                                                   includeKeysParamMap.get(inp) + "&" +
×
191
                                                                   "link-message=" + urlEncode("Check the checkbox at the end of this page and press 'Publish' to publish this " +
×
192
                                                                                               "introduction that includes the additional keys."),
193
                            "include keys..."));
194
                } else {
195
                    item.add(new ExternalLink("include-keys-link", ".", "").setVisible(false));
×
196
                }
197

198
                item.add(new DataView<>("intro-keys", new ListDataProvider<>(inp.getKeyDeclarations())) {
×
199

200
                    @Override
201
                    protected void populateItem(Item<KeyDeclaration> kdi) {
202
                        kdi.add(new Label("intro-key", Utils.getShortPubkeyName(Utils.createSha256HexHash(kdi.getModelObject().getPublicKeyString()))));
×
203
                    }
×
204

205
                });
206
            }
×
207

208
        });
209

210
    }
×
211

212
    private boolean hasKey(IntroNanopub inp, KeyDeclaration kd) {
213
        // TODO: Do this more efficiently:
214
        for (KeyDeclaration k : inp.getKeyDeclarations()) {
×
215
            if (k.getPublicKeyString().equals(kd.getPublicKeyString())) return true;
×
216
        }
×
217
        return false;
×
218
    }
219

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