generated from creek-service/multi-module-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Adds support for one resource descriptor to expose dependencies on other resources. - Removes unnecessary methods on `ResourceDescriptor`. - Ensure all resource interfaces derive from `ResourceDescriptor`.
- Loading branch information
1 parent
0c445c9
commit 3858f81
Showing
19 changed files
with
491 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
metadata/src/main/java/org/creekservice/api/platform/metadata/ResourceCollection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2023 Creek Contributors (https://github.com/creek-service) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.creekservice.api.platform.metadata; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
/** A collection of resources. */ | ||
public interface ResourceCollection { | ||
|
||
/** | ||
* The stream of the resources in the collection. | ||
* | ||
* <p>In general, callers should call {@link #collectResources(ResourceCollection)}, rather than | ||
* directly calling this method. | ||
* | ||
* @return the resources in the collection. | ||
*/ | ||
Stream<? extends ResourceDescriptor> resources(); | ||
|
||
/** | ||
* Utility method to collect all resources from a collection, including any resources referenced | ||
* by any resources encountered. | ||
* | ||
* <p>Child resources are returned earlier in the stream than parents. | ||
* | ||
* @param collection the resource collection to retrieve all resources from. | ||
* @return complete stream of resources. | ||
*/ | ||
static Stream<ResourceDescriptor> collectResources(final ResourceCollection collection) { | ||
final Set<ResourceCollection> visited = new HashSet<>(); | ||
visited.add(collection); | ||
return collection.resources().flatMap(child -> collectResources(child, visited)); | ||
} | ||
|
||
/** | ||
* Utility method to collect all resources referenced by a {@code ResourceDescriptor}, including | ||
* any resources referenced by any resources encountered. | ||
* | ||
* <p>Child resources are returned earlier in the stream than parents. | ||
* | ||
* <p>In general, callers should call {@link #collectResources(ResourceCollection)}, rather than | ||
* directly calling this method. | ||
* | ||
* @param resource the resource descriptor to retrieve all resources from. | ||
* @param visited the set of resource containers already visited. | ||
* @return complete stream of resources. | ||
*/ | ||
static Stream<ResourceDescriptor> collectResources( | ||
final ResourceDescriptor resource, final Set<ResourceCollection> visited) { | ||
if (!visited.add(resource)) { | ||
// Already processed: | ||
return Stream.empty(); | ||
} | ||
|
||
return Stream.concat( | ||
resource.resources().flatMap(child -> collectResources(child, visited)), | ||
Stream.of(resource)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.