This repository was archived by the owner on Dec 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Extension for sorting projects/environments #19
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
60 changes: 60 additions & 0 deletions
60
bundles/org.aposin.gem.core/src/org/aposin/gem/core/api/service/IGemSorter.java
This file contains hidden or 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,60 @@ | ||
| /** | ||
| * Copyright 2020 Association for the promotion of open-source insurance software and for the establishment of open interface standards in the insurance industry (Verein zur Foerderung quelloffener Versicherungssoftware und Etablierung offener Schnittstellenstandards in der Versicherungsbranche) | ||
| * | ||
| * 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.aposin.gem.core.api.service; | ||
|
|
||
| import java.util.Comparator; | ||
|
|
||
| import org.aposin.gem.core.api.model.IEnvironment; | ||
| import org.aposin.gem.core.api.model.IProject; | ||
|
|
||
| /** | ||
| * Service to provide a sorting algorithm for several GEM objects. | ||
| * </br> | ||
| * IMPORTANT: should be provided only once. | ||
| */ | ||
| public interface IGemSorter extends IGemService { | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public default String getName() { | ||
| return getId(); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public default String getDisplayName() { | ||
| return getId(); | ||
| } | ||
|
|
||
| /** | ||
| * Get the comparator for the projects. | ||
| * | ||
| * @return project comparator. | ||
| */ | ||
| public Comparator<IProject> getProjectComparator(); | ||
|
|
||
| /** | ||
| * Get the comparator for the environments. | ||
| * | ||
| * @return environment comparator. | ||
| */ | ||
| public Comparator<IEnvironment> getEnvironmentComparator(); | ||
|
|
||
| } | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -18,17 +18,40 @@ | |
| import java.util.Collection; | ||
| import java.util.Map; | ||
|
|
||
| import org.aposin.gem.core.GemException; | ||
| import org.aposin.gem.core.api.IRefreshable; | ||
| import org.aposin.gem.core.api.config.GemConfigurationException; | ||
| import org.aposin.gem.core.api.config.IConfigurable; | ||
| import org.aposin.gem.core.api.service.launcher.IEnvironmentLauncherProvider; | ||
| import org.aposin.gem.core.api.service.launcher.IFeatureBranchLauncherProvider; | ||
| import org.aposin.gem.core.impl.service.DefaultGemSorter; | ||
|
|
||
| /** | ||
| * Container class for the services implemented by core and/or extensions. | ||
| */ | ||
| public interface IServiceContainer extends IRefreshable, IConfigurable { | ||
|
|
||
| /** | ||
| * Gets the configured {@link IGemSorter}. | ||
| * </br> | ||
| * Default implementation checks for an optional unique gem-sorter. | ||
| * | ||
| * @return sorter. | ||
| * | ||
| * @throws GemException if more than one sorter is provided. | ||
| */ | ||
| public default IGemSorter getGemSorter() { | ||
| final Collection<IGemSorter> sorters = getGemServices(IGemSorter.class); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why a Collection and not a List (or Set)?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The API for |
||
| switch (sorters.size()) { | ||
| case 0: | ||
| return new DefaultGemSorter(); | ||
| case 1: | ||
| return sorters.iterator().next(); | ||
| default: | ||
| throw new GemException("Several gem-sorters provided"); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Gets the configured default feature branch provider. | ||
| * | ||
|
|
||
This file contains hidden or 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 hidden or 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
56 changes: 56 additions & 0 deletions
56
bundles/org.aposin.gem.core/src/org/aposin/gem/core/impl/service/DefaultGemSorter.java
This file contains hidden or 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,56 @@ | ||
| /** | ||
| * Copyright 2020 Association for the promotion of open-source insurance software and for the establishment of open interface standards in the insurance industry (Verein zur Foerderung quelloffener Versicherungssoftware und Etablierung offener Schnittstellenstandards in der Versicherungsbranche) | ||
| * | ||
| * 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.aposin.gem.core.impl.service; | ||
|
|
||
| import java.util.Comparator; | ||
|
|
||
| import org.aposin.gem.core.api.config.GemConfigurationException; | ||
| import org.aposin.gem.core.api.config.IConfiguration; | ||
| import org.aposin.gem.core.api.model.IEnvironment; | ||
| import org.aposin.gem.core.api.model.IProject; | ||
| import org.aposin.gem.core.api.service.IGemSorter; | ||
|
|
||
| /** | ||
| * Default {@link IGemSorter}. | ||
| * </br> | ||
| * This sorter can be extended by plug-ins and be registered as a service (only one is allowed). | ||
| */ | ||
| public class DefaultGemSorter implements IGemSorter { | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public void setConfig(final IConfiguration config) throws GemConfigurationException { | ||
| // NO-OP | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public Comparator<IEnvironment> getEnvironmentComparator() { | ||
| return Comparator.reverseOrder(); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public Comparator<IProject> getProjectComparator() { | ||
| return Comparator.naturalOrder(); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it correct that both method call getId?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the gem-sorter, the name and display name are irrelevant by now cause only one should be provided and it is not used out of the core plug-in. In case that we allow in the future several sorters and a way to switch between them this should be reverted and each of the sorters should provide its own implementation of this methods (thus, removing the default one on the interface).