Skip to content

Commit

Permalink
fixes for assets
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelmathot committed May 31, 2021
1 parent 820f5e0 commit c9fe721
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ internal static IStacSummaryItem CreateSummaryValueSetFromArrays(IEnumerable<obj
/// </summary>
protected void DeclareStacExtension()
{
if (StacPropertiesContainer.StacObjectContainer == null) return;
if (!StacPropertiesContainer.StacObjectContainer.StacExtensions.Contains(Identifier))
StacPropertiesContainer.StacObjectContainer.StacExtensions.Add(Identifier);
}
Expand Down
13 changes: 7 additions & 6 deletions src/DotNetStac/StacAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public static StacAsset CreateMetadataAsset(IStacObject stacObject, Uri uri, Con

ContentType type;

Collection<string> roles;
private Dictionary<string, object> properties;
private IStacObject parentStacObject;

Expand All @@ -97,7 +96,7 @@ internal StacAsset()
/// <param name="uri">uri to the asset</param>
public StacAsset(IStacObject stacObject, Uri uri) : this()
{
if (!(stacObject is StacItem || stacObject is StacCollection))
if (!(stacObject == null || stacObject is StacItem || stacObject is StacCollection))
throw new InvalidOperationException("An asset cannot be defined in " + stacObject.GetType().Name);
parentStacObject = stacObject;
Uri = uri;
Expand All @@ -114,7 +113,7 @@ public StacAsset(IStacObject stacObject, Uri uri) : this()
/// <param name="mediaType">media-type of the asset</param>
public StacAsset(IStacObject stacObject, Uri uri, IEnumerable<string> roles, string title, ContentType mediaType) : this(stacObject, uri)
{
Roles = roles == null ? new Collection<string>() : new Collection<string>(roles.ToList());
Roles = roles == null ? new SortedSet<string>() : new SortedSet<string>(roles.ToList());
Title = title;
MediaType = mediaType;
}
Expand All @@ -126,14 +125,16 @@ public StacAsset(IStacObject stacObject, Uri uri, IEnumerable<string> roles, str
/// <param name="stacObject">new parent stac object</param>
public StacAsset(StacAsset source, IStacObject stacObject)
{
if (!(stacObject is StacItem || stacObject is StacCollection))
if (!(stacObject == null || stacObject is StacItem || stacObject is StacCollection))
throw new InvalidOperationException("An asset cannot be defined in " + stacObject.GetType().Name);
if (source == null)
throw new ArgumentNullException("source");
base_uri = source.base_uri;
href = source.href;
if (source.roles != null)
roles = new Collection<string>(source.roles);
if (source.Roles != null)
Roles = new SortedSet<string>(source.Roles);
else
Roles = new SortedSet<string>();
title = source.title;
type = source.type;
description = source.description;
Expand Down

0 comments on commit c9fe721

Please sign in to comment.