Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Dec 20, 2022. It is now read-only.
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
1 change: 1 addition & 0 deletions bundles/org.aposin.gem.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Export-Package: org.aposin.gem.core;uses:="org.osgi.framework,org.slf4j",
org.aposin.gem.core.impl.internal.workflow.command;x-internal:=true,
org.aposin.gem.core.impl.internal.workflow.command.base;x-internal:=true,
org.aposin.gem.core.impl.model.repo,
org.aposin.gem.core.impl.service,
org.aposin.gem.core.impl.service.launcher,
org.aposin.gem.core.utils
Bundle-ClassPath: .,
Expand Down
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();
Copy link
Contributor

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?

Copy link
Member Author

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).

}

/**
* {@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();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a Collection and not a List (or Set)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API for getGemServices is already returning a collection; this change is not refactoring that API but just using it. I believe that it is because the implementation of the IServiceContainer is using Map::values to return the services. In any case, as the services are used mostly internally to provide hooks on GEM, it shouldn't be a problem and we can always change between collection implementations as required.

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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public List<IProject> getProjects() {
private void loadProjects() {
projects = config.projects.stream() //
.map(project -> new ProjectImpl(this, project)) //
.sorted() //
.sorted(getServiceContainer().getGemSorter().getProjectComparator()) //
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -129,7 +128,7 @@ private void loadObsoleteEnvironments() {
// maybeObsoleteBranches only contain obsoleteBranches
obsoleteEnvironments = maybeObsoleteBranches.stream() //
.map(branch -> new ObsoleteKnownEnvironment(config, this, projectInternalBranch, branch, branchToRepos.get(branch))) //
.sorted(Comparator.reverseOrder()) //
.sorted(config.getServiceContainer().getGemSorter().getEnvironmentComparator()) //
.collect(Collectors.toList());
}

Expand All @@ -148,10 +147,8 @@ private void loadEnvironments() {
}
environments.add(new EnvironmentImpl(config, this, env));
}
// finally, sort environments (reverse order, as it is usually the version number)
// TODO - maybe it is worth to provide a configuration to short the environments
// TODO - or do it at the UI level instead of here...
environments.sort(Comparator.reverseOrder());
// sort environments using the sorter extension
environments.sort(config.getServiceContainer().getGemSorter().getEnvironmentComparator());
}

/**
Expand Down
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();
}
}