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

kit-data-manager / ro-crate-java / #576

10 Nov 2025 11:54AM UTC coverage: 91.45% (+0.6%) from 90.804%
#576

Pull #279

github

Pfeil
fix: error in local file path detection
Pull Request #279: Next Version (2.1.0-rc4)

238 of 253 new or added lines in 8 files covered. (94.07%)

1 existing line in 1 file now uncovered.

2246 of 2456 relevant lines covered (91.45%)

0.91 hits per line

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

95.0
/src/main/java/edu/kit/datamanager/ro_crate/entities/data/DataSetEntity.java
1
package edu.kit.datamanager.ro_crate.entities.data;
2

3
import com.fasterxml.jackson.annotation.JsonInclude;
4
import com.fasterxml.jackson.databind.JsonNode;
5
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
6

7
import com.fasterxml.jackson.databind.node.ObjectNode;
8
import edu.kit.datamanager.ro_crate.entities.serializers.HasPartSerializer;
9

10
import java.util.HashSet;
11
import java.util.Set;
12
import java.util.stream.Collectors;
13

14
/**
15
 * A helping class for the creating of Data entities of type Dataset.
16
 *
17
 * @author Nikola Tzotchev on 5.2.2022 г.
18
 * @version 1
19
 */
20
public class DataSetEntity extends DataEntity {
21

22
    public static final String TYPE = "Dataset";
23

24
    /**
25
     * Points to the parts of this dataset.
26
     * <p>
27
     * This will be serialized to and deserialized from the "hasPart" property
28
     * and exists for convenience to represent the additional capabilities of
29
     * a DataSetEntity over a normal DataEntity.
30
     */
31
    @JsonSerialize(using = HasPartSerializer.class)
32
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
33
    public Set<String> hasPart;
34

35
    /**
36
     * Constructor for instantiating a Dataset entity from the builder.
37
     *
38
     * @param entityBuilder the builder passed as argument.
39
     */
40
    public DataSetEntity(AbstractDataSetBuilder<?> entityBuilder) {
41
        super(entityBuilder);
1✔
42
        this.hasPart = entityBuilder.hasPart.stream()
1✔
43
                .filter(s -> !s.isBlank())
1✔
44
                .collect(Collectors.toSet());
1✔
45
        this.addType(TYPE);
1✔
46
    }
1✔
47

48
    public void removeFromHasPart(String str) {
49
        this.hasPart.remove(str);
1✔
50
    }
1✔
51

52
    public void addToHasPart(String id) {
53
        if (id != null && !id.isEmpty()) {
1✔
54
            this.hasPart.add(id);
1✔
55
        }
56
    }
1✔
57

58
    /**
59
     * Check if the hasPart property contains a specific id.
60
     *
61
     * @deprecated use {@link #hasPart(String)} instead.
62
     *
63
     * @param id the id to check for
64
     * @return true if the id is present, false otherwise
65
     */
66
    @Deprecated(forRemoval = true)
67
    public boolean hasInHasPart(String id) {
UNCOV
68
        return this.hasPart.contains(id);
×
69
    }
70

71
    /**
72
     * Check if the hasPart property contains a specific id.
73
     * @param id the id to check for
74
     * @return true if the id is present, false otherwise
75
     */
76
    public boolean hasPart(String id) {
77
        return this.hasPart.contains(id);
1✔
78
    }
79

80
    abstract static class AbstractDataSetBuilder<T extends AbstractDataEntityBuilder<T>> extends
81
            AbstractDataEntityBuilder<T> {
82

83
        Set<String> hasPart;
84

85
        public AbstractDataSetBuilder() {
1✔
86
            this.hasPart = new HashSet<>();
1✔
87
        }
1✔
88

89
        public T setHasPart(Set<String> hasPart) {
90
            this.hasPart = hasPart;
1✔
91
            return self();
1✔
92
        }
93

94
        public T addToHasPart(DataEntity dataEntity) {
95
            if (dataEntity != null) {
1✔
96
                this.hasPart.add(dataEntity.getId());
1✔
97
                this.relatedItems.add(dataEntity.getId());
1✔
98
            }
99
            return self();
1✔
100
        }
101

102
        public T addToHasPart(String dataEntity) {
103
            if (dataEntity != null) {
1✔
104
                this.hasPart.add(dataEntity);
1✔
105
                this.relatedItems.add(dataEntity);
1✔
106
            }
107
            return self();
1✔
108
        }
109

110
        @Override
111
        public T setAllUnsafe(ObjectNode properties) {
112
            super.setAllUnsafe(properties);
1✔
113
            JsonNode hasPart = properties.path("hasPart");
1✔
114
            String txt = hasPart.asText();
1✔
115
            if (!txt.isBlank()) {
1✔
NEW
116
                this.hasPart.add(txt);
×
117
            }
118
            hasPart.valueStream()
1✔
119
                    .map(JsonNode::asText)
1✔
120
                    .filter(value -> !value.isBlank())
1✔
121
                    .forEach(
1✔
122
                            value -> this.hasPart.add(value)
1✔
123
                    );
124
            return self();
1✔
125
        }
126

127
        @Override
128
        public abstract DataSetEntity build();
129
    }
130

131
    /**
132
     * Builder for the helping class DataSetEntity.
133
     */
134
    public static final class DataSetBuilder extends AbstractDataSetBuilder<DataSetBuilder> {
1✔
135

136
        @Override
137
        public DataSetBuilder self() {
138
            return this;
1✔
139
        }
140

141
        @Override
142
        public DataSetEntity build() {
143
            return new DataSetEntity(this);
1✔
144
        }
145
    }
146
}
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

© 2025 Coveralls, Inc