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

knowledgepixels / nanodash / 23429117751

23 Mar 2026 08:56AM UTC coverage: 16.395% (-0.001%) from 16.396%
23429117751

push

github

tkuhn
fix: show space and maintained resource labels instead of URI suffixes when linked

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

746 of 5613 branches covered (13.29%)

Branch coverage included in aggregate %.

1895 of 10496 relevant lines covered (18.05%)

2.47 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/IriItem.java
1
package com.knowledgepixels.nanodash.component;
2

3
import com.knowledgepixels.nanodash.LocalUri;
4
import com.knowledgepixels.nanodash.Utils;
5
import com.knowledgepixels.nanodash.component.StatementItem.RepetitionGroup;
6
import com.knowledgepixels.nanodash.domain.MaintainedResource;
7
import com.knowledgepixels.nanodash.domain.Space;
8
import com.knowledgepixels.nanodash.repository.MaintainedResourceRepository;
9
import com.knowledgepixels.nanodash.repository.SpaceRepository;
10
import com.knowledgepixels.nanodash.template.ContextType;
11
import com.knowledgepixels.nanodash.template.Template;
12
import com.knowledgepixels.nanodash.template.UnificationException;
13
import org.apache.wicket.behavior.AttributeAppender;
14
import org.apache.wicket.markup.html.basic.Label;
15
import org.apache.wicket.markup.html.link.ExternalLink;
16
import org.eclipse.rdf4j.model.IRI;
17
import org.eclipse.rdf4j.model.Value;
18
import org.eclipse.rdf4j.model.ValueFactory;
19
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
20
import org.eclipse.rdf4j.model.vocabulary.PROV;
21
import org.nanopub.vocabulary.NTEMPLATE;
22

23

24
/**
25
 * A panel that displays an IRI with a label and a link to explore it.
26
 */
27
public class IriItem extends AbstractContextComponent {
28

29
    private IRI iri;
30

31
    /**
32
     * Constructor for creating an IRI item with a given IRI and repetition group.
33
     *
34
     * @param id              the component ID
35
     * @param parentId        the parent ID (e.g., "subj", "obj")
36
     * @param iriP            the IRI to display
37
     * @param objectPosition  whether this is in the object position of a statement
38
     * @param statementPartId the ID of the statement part this IRI belongs to
39
     * @param rg              the repetition group context
40
     */
41
    public IriItem(String id, String parentId, IRI iriP, boolean objectPosition, IRI statementPartId, RepetitionGroup rg) {
42
        super(id, rg.getContext());
×
43
        this.iri = iriP;
×
44
        final Template template = context.getTemplate();
×
45
        String labelString = null;
×
46
        if (iri.equals(NTEMPLATE.ASSERTION_PLACEHOLDER)) {
×
47
            if (context.getType() == ContextType.ASSERTION) {
×
48
                labelString = "this assertion";
×
49
            } else {
50
                labelString = "the assertion above";
×
51
            }
52
        } else if (iri.equals(NTEMPLATE.NANOPUB_PLACEHOLDER)) {
×
53
            labelString = "this nanopublication";
×
54
        }
55
        if (template.getLabel(iri) != null) {
×
56
            labelString = template.getLabel(iri);
×
57
        } else if (iri.equals(PROV.WAS_ATTRIBUTED_TO)) {
×
58
            // temporary solution until we have full provenance graph support
59
            labelString = "is attributed to";
×
60
        } else if (labelString == null) {
×
61
            String iriString = iri.stringValue();
×
62
            Space space = SpaceRepository.get().findById(iriString);
×
63
            if (space != null) {
×
64
                labelString = space.getLabel();
×
65
            } else if (SpaceRepository.get().findByAltId(iriString) != null) {
×
66
                labelString = SpaceRepository.get().findByAltId(iriString).getLabel();
×
67
            } else if (MaintainedResourceRepository.get().findById(iriString) != null) {
×
68
                labelString = MaintainedResourceRepository.get().findById(iriString).getLabel();
×
69
            } else {
70
                labelString = Utils.getShortNameFromURI(iriString);
×
71
            }
72
        }
73
        if (!statementPartId.equals(template.getFirstOccurrence(iri))) {
×
74
            labelString = labelString.replaceFirst("^[aA]n? ", "the ");
×
75
        }
76
        if (!labelString.isEmpty() && parentId.equals("subj") && !labelString.matches("https?://.*")) {
×
77
            // Capitalize first letter of label if at subject position:
78
            labelString = labelString.substring(0, 1).toUpperCase() + labelString.substring(1);
×
79
        }
80
        labelString = labelString.replaceAll("%I%", "" + rg.getRepeatIndex());
×
81

82
        String iriString = iri.stringValue();
×
83
        String description = "";
×
84
        if (iri.equals(NTEMPLATE.ASSERTION_PLACEHOLDER)) {
×
85
            if (this.context.getExistingNanopub() != null) {
×
86
                iriString = this.context.getExistingNanopub().getAssertionUri().stringValue();
×
87
            } else {
88
                iriString = LocalUri.of("assertion").stringValue();
×
89
            }
90
            description = "This is the identifier for the assertion of this nanopublication.";
×
91
        } else if (iri.equals(NTEMPLATE.NANOPUB_PLACEHOLDER)) {
×
92
            if (this.context.getExistingNanopub() != null) {
×
93
                iriString = this.context.getExistingNanopub().getUri().stringValue();
×
94
            } else {
95
                iriString = LocalUri.of("nanopub").stringValue();
×
96
            }
97
            description = "This is the identifier for this whole nanopublication.";
×
98
        } else if (template.isLocalResource(iri)) {
×
99
            if (this.context.getExistingNanopub() == null) {
×
100
                iriString = iriString.replace(Utils.getUriPrefix(iriString), LocalUri.PREFIX);
×
101
            }
102
        }
103
        if (iriString.startsWith(context.getTemplateId())) {
×
104
            iriString = iriString.replace(context.getTemplateId(), "");
×
105
            if (this.context.getExistingNanopub() != null) {
×
106
                iriString = this.context.getExistingNanopub().getUri().stringValue() + iriString;
×
107
            }
108
            description = "This is a local identifier minted within the nanopublication.";
×
109
        }
110
        if (labelString.contains(" - ")) description = labelString.replaceFirst("^.* - ", "");
×
111
        add(new Label("description", description));
×
112
        add(Utils.getUriLink("uri", iriString));
×
113

114
        String href = null;
×
115
        if (Utils.isLocalURI(iriString)) {
×
116
            href = "";
×
117
        } else {
118
            href = NanodashLink.getPageUrl(iriString);
×
119
        }
120
        ExternalLink linkComp = new ExternalLink("link", href, labelString.replaceFirst(" - .*$", ""));
×
121
        if (iri.equals(NTEMPLATE.ASSERTION_PLACEHOLDER)) {
×
122
            linkComp.add(new AttributeAppender("class", " this-assertion "));
×
123
            iri = LocalUri.of("assertion");
×
124
        } else if (iri.equals(NTEMPLATE.NANOPUB_PLACEHOLDER)) {
×
125
            linkComp.add(new AttributeAppender("class", " this-nanopub "));
×
126
            iri = LocalUri.of("nanopub");
×
127
        }
128
        add(linkComp);
×
129
        if (template.isIntroducedResource(iri) || template.isEmbeddedResource(iri)) {
×
130
            linkComp.add(AttributeAppender.append("class", "introduced"));
×
131
        }
132
    }
×
133

134
    private static ValueFactory vf = SimpleValueFactory.getInstance();
×
135

136
    /**
137
     * {@inheritDoc}
138
     */
139
    @Override
140
    public void removeFromContext() {
141
        // Nothing to be done here.
142
    }
×
143

144
    /**
145
     * {@inheritDoc}
146
     */
147
    @Override
148
    public boolean isUnifiableWith(Value v) {
149
        if (!(v instanceof IRI)) return false;
×
150
        // TODO: Check that template URIs don't have regex characters:
151
        String iriS = iri.stringValue().replaceFirst("^" + context.getTemplateId() + "[#/]?", LocalUri.PREFIX);
×
152
        if (context.isReadOnly()) {
×
153
            return iriS.equals(v.stringValue().replaceFirst("^" + context.getExistingNanopub().getUri() + "[#/]?", LocalUri.PREFIX));
×
154
        } else {
155
            return iriS.equals(v.stringValue());
×
156
        }
157
    }
158

159
    /**
160
     * {@inheritDoc}
161
     */
162
    @Override
163
    public void unifyWith(Value v) throws UnificationException {
164
        if (!isUnifiableWith(v)) throw new UnificationException(v.stringValue());
×
165
        // Nothing left to be done here.
166
    }
×
167

168
    /**
169
     * {@inheritDoc}
170
     */
171
    @Override
172
    public void fillFinished() {
173
    }
×
174

175
    /**
176
     * {@inheritDoc}
177
     */
178
    @Override
179
    public void finalizeValues() {
180
    }
×
181

182
    /**
183
     * {@inheritDoc}
184
     */
185
    @Override
186
    public String toString() {
187
        return "[IRI item: " + iri + "]";
×
188
    }
189

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