Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,52 @@ public FeatureArtifactBuilder addMetadata(String key, Object value) {
if (key == null)
throw new IllegalArgumentException("Metadata key cannot be null");

if (value == null)
throw new IllegalArgumentException("Metadata value cannot be null");
if (key.length() == 0)
throw new IllegalArgumentException("Key must not be empty");

if ("id".equalsIgnoreCase(key))
throw new IllegalArgumentException("Key cannot be 'id'");

checkMetadataValue(value);

this.metadata.put(key, value);
return this;
}

@Override
@Override
public FeatureArtifactBuilder addMetadata(Map<String,Object> md) {
if (md.keySet().contains(null))
throw new IllegalArgumentException("Metadata key cannot be null");

if (md.values().contains(null))
throw new IllegalArgumentException("Metadata value cannot be null");
if (md.keySet().contains(""))
throw new IllegalArgumentException("Key must not be empty");

if (md.keySet().stream()
.map(String::toLowerCase)
.anyMatch(s -> "id".equals(s))) {
throw new IllegalArgumentException("Key cannot be 'id'");
}

md.values().stream()
.forEach(this::checkMetadataValue);

this.metadata.putAll(md);
return this;
}

private void checkMetadataValue(Object value) {
if (value instanceof String)
return;

if (value instanceof Boolean)
return;

if (value instanceof Number)
return;

throw new IllegalArgumentException("Illegal metadata value: " + value);
}

@Override
public FeatureArtifact build() {
return new ArtifactImpl(id, metadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public FeatureBundleBuilder addMetadata(String key, Object value) {
if ("id".equalsIgnoreCase(key))
throw new IllegalArgumentException("Key cannot be 'id'");

this.metadata.put(key, value);
checkMetadataValue(value);

this.metadata.put(key, value);
return this;
}

Expand All @@ -63,10 +65,26 @@ public FeatureBundleBuilder addMetadata(Map<String,Object> md) {
throw new IllegalArgumentException("Key cannot be 'id'");
}

md.values().stream()
.forEach(this::checkMetadataValue);

this.metadata.putAll(md);
return this;
}

private void checkMetadataValue(Object value) {
if (value instanceof String)
return;

if (value instanceof Boolean)
return;

if (value instanceof Number)
return;

throw new IllegalArgumentException("Illegal metadata value: " + value);
}

@Override
public FeatureBundle build() {
return new BundleImpl(id, metadata);
Expand Down