Using different OpenAPI features for redback and archiva
diff --git a/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/Util.java b/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/Util.java
deleted file mode 100644
index db4d4f9..0000000
--- a/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/Util.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package org.apache.archiva.redback.rest.api;/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import org.apache.commons.lang3.StringUtils;
-
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.UriInfo;
-
-/**
- * Central utility class that may be used by service implementations.
- *
- * @author Martin Stockhammer <martin_s@apache.org>
- */
-public class Util
-{
- /**
- * Returns <code>false</code>, if the given parameter is not present in the given uriInfo, or is present and set to 'false' or '0'.
- * In all other cases it returns <code>true</code>.
- *
- * This means you can activate a flag by setting '?param', '?param=true', '?param=1', ...
- * It is deactivated, if the parameter is absent, or '?param=false', or '?param=0'
- *
- * @param uriInfo the uriInfo context instance, that is used to check for the parameter
- * @param queryParameterName the query parameter name
- * @return
- */
- public static boolean isFlagSet( final UriInfo uriInfo, final String queryParameterName) {
- MultivaluedMap<String, String> params = uriInfo.getQueryParameters( );
- if (!params.containsKey( queryParameterName )) {
- return false;
- }
- // parameter is available
- String value = params.getFirst( queryParameterName );
- // if its available but without a value it is flagged as present
- if (StringUtils.isEmpty( value )) {
- return true;
- }
- // if it has a value, we check for false values:
- if ("false".equalsIgnoreCase( value ) || "0".equalsIgnoreCase( value )) {
- return false;
- }
- return true;
- }
-}
diff --git a/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/model/PaginationInfo.java b/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/model/PaginationInfo.java
deleted file mode 100644
index 4cd0fd8..0000000
--- a/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/model/PaginationInfo.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package org.apache.archiva.redback.rest.api.model;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import io.swagger.v3.oas.annotations.media.Schema;
-
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-
-/**
- *
- * Informational attributes for pagination.
- *
- * @author Martin Stockhammer <martin_s@apache.org>
- */
-@XmlRootElement(name="pagination")
-@Schema(name="PaginationInfo", description = "Contains paging information (limit, offset, totalCount)")
-public class PaginationInfo
-{
- long totalCount;
- long offset;
- long limit;
-
- public PaginationInfo() {
-
- }
-
- public PaginationInfo( long totalCount, long offset, long limit )
- {
- this.totalCount = totalCount;
- this.offset = offset;
- this.limit = limit;
- }
-
- @Schema(description = "The total number of data available.")
- public long getTotalCount( )
- {
- return totalCount;
- }
-
- public void setTotalCount( long totalCount )
- {
- this.totalCount = totalCount;
- }
-
- @Schema(description = "The offset of the first element of the returned dataset.")
- public long getOffset( )
- {
- return offset;
- }
-
- public void setOffset( long offset )
- {
- this.offset = offset;
- }
-
- @Schema(description = "The maximum number of elements returned per page.")
- public long getLimit( )
- {
- return limit;
- }
-
- public void setLimit( long limit )
- {
- this.limit = limit;
- }
-}
diff --git a/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/model/v2/PagedResult.java b/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/model/v2/PagedResult.java
deleted file mode 100644
index 1aa998f..0000000
--- a/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/model/v2/PagedResult.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package org.apache.archiva.redback.rest.api.model.v2;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import io.swagger.v3.oas.annotations.media.Schema;
-import org.apache.archiva.redback.rest.api.model.PaginationInfo;
-
-import javax.xml.bind.annotation.XmlRootElement;
-import java.util.List;
-
-/**
- * A Paged result puts the data into an envelope
- * @author Martin Stockhammer <martin_s@apache.org>
- */
-@XmlRootElement(name="pagedResult")
-@Schema(name = "PagedResult", description = "Contains paged data. Pages are defined by limit and offset.")
-public class PagedResult<T>
-{
- PaginationInfo pagination;
- List<T> data;
-
- public PagedResult() {
-
- }
-
- public PagedResult( int totalCount, int offset, int limit, List<T> data ) {
- this.data = data;
- this.pagination = new PaginationInfo( totalCount, offset, limit );
- }
-
- public static final <T> PagedResult<T> of(int totalSize, int offset, int limit, List<T> element) {
- return new PagedResult( totalSize, offset, limit, element);
- }
-
- @Schema(description = "This is the payload of the paged data. The type of data depends on the REST method. ")
- public List<T> getData( )
- {
- return data;
- }
-
- public void setData( List<T> data )
- {
- this.data = data;
- }
-
- @Schema(description = "The pagination information")
- public PaginationInfo getPagination( )
- {
- return pagination;
- }
-
- public void setPagination( PaginationInfo pagination )
- {
- this.pagination = pagination;
- }
-}
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/v2/PagingHelper.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/v2/PagingHelper.java
deleted file mode 100644
index 1fa2756..0000000
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/v2/PagingHelper.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package org.apache.archiva.redback.rest.services.v2;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import org.apache.archiva.redback.rest.api.model.v2.PagedResult;
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Helper class for creating paged results.
- *
- * @author Martin Stockhammer <martin_s@apache.org>
- */
-public class PagingHelper
-{
- public static <T> PagedResult<T> getResultFromList( int offset, int limit, List<T> data) {
- if (offset>=data.size()) {
- return new PagedResult<>( data.size( ), offset, limit, Collections.emptyList( ) );
- }
- int lastIndex = getLastIndex( offset, limit, data.size( ) );
- return new PagedResult<>( data.size(), offset, limit, data.subList( offset, lastIndex ) );
- }
-
- public static int getLastIndex(int offset, int limit, int listSize) {
- return Math.min( Math.max( 0, offset + limit ), listSize );
- }
-
-
-}
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/v2/QueryHelper.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/v2/QueryHelper.java
deleted file mode 100644
index ba417aa..0000000
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/v2/QueryHelper.java
+++ /dev/null
@@ -1,168 +0,0 @@
-package org.apache.archiva.redback.rest.services.v2;/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import org.apache.commons.lang3.StringUtils;
-
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.function.BiPredicate;
-import java.util.function.Function;
-import java.util.function.Predicate;
-
-/**
- *
- * Helper class that returns combined filter and comparison objects for ordering.
- *
- * The query term may be consist of simple query terms separated by whitespace or attribute queries
- * in the form <code>attribute:query</code>, which means only the attribute is searched for the query string.
- * <br />
- * Example:
- * <dl>
- * <dt>`user1 test`</dt>
- * <dd>
- * searches for the tokens user1 and test in the default attributes.
- * </dd>
- * <dt>`user1 name:test`</dt>
- * <dd>searches for the token user1 in the default attributes and for the token test in the attribute name.</dd>
- * </dl>
- *
- *
- * @since 3.0
- * @author Martin Stockhammer <martin_s@apache.org>
- */
-public class QueryHelper<T>
-{
-
- private final Map<String, BiPredicate<String, T>> FILTER_MAP;
- private final Map<String, Comparator<T>> ORDER_MAP;
- private final String[] DEFAULT_SEARCH_FIELDS;
- private final Predicate<T> DEFAULT_FILTER = ( T att ) -> false;
-
-
- /**
- * Creates a new query helper with the given filters and comparators.
- *
- * @param filterMap a map of filters, where the key is the attribute name and the value is a predicate that matches
- * the filter value and the object instance.
- * @param orderMap a map of comparators, where key is the attribute name and the value is a comparator for the given
- * object instance
- * @param defaultSearchFields A array of attribute names, that are used as default search fields.
- */
- public QueryHelper(Map<String, BiPredicate<String, T>> filterMap, Map<String, Comparator<T>> orderMap,
- String[] defaultSearchFields)
- {
- this.FILTER_MAP = filterMap;
- this.DEFAULT_SEARCH_FIELDS = defaultSearchFields;
- this.ORDER_MAP = new HashMap<>( orderMap );
- }
-
- public <U extends Comparable<? super U>> void addNullsafeFieldComparator( String fieldName, Function<? super T, U> keyExtractor) {
- ORDER_MAP.put( fieldName, Comparator.comparing( keyExtractor, Comparator.nullsLast( Comparator.naturalOrder( ) ) ) );
- }
-
- public void addStringFilter(String attribute, Function<? super T, String> keyExtractor) {
- this.FILTER_MAP.put( attribute, ( String q, T r ) -> StringUtils.containsIgnoreCase( keyExtractor.apply( r ), q ) );
- }
-
- public void addBooleanFilter(String attribute, Function<? super T, Boolean> keyExtractor) {
- this.FILTER_MAP.put( attribute, ( String q, T r ) -> Boolean.valueOf( q ) == keyExtractor.apply( r ) );
- }
-
- /**
- * Get the comparator for a specific attribute.
- * @param attributeName the name of the attribute.
- * @return
- */
- Comparator<T> getAttributeComparator( String attributeName )
- {
- return ORDER_MAP.get( attributeName );
- }
-
- /**
- * Get the combined order for the given attributes in the given order.
- *
- * @param orderBy the attributes to compare. The first attribute in the list will be used first for comparing.
- * @param ascending
- * @return
- */
- Comparator<T> getComparator( List<String> orderBy, boolean ascending )
- {
- if ( ascending )
- {
- return orderBy.stream( ).map( ( String name ) -> getAttributeComparator( name ) ).filter( Objects::nonNull )
- .reduce( Comparator::thenComparing )
- .orElseThrow( () -> new IllegalArgumentException( "No attribute ordering found" ) );
- }
-
- else
- {
- return orderBy.stream( ).map( ( String name ) -> getAttributeComparator( name ) == null ? null : getAttributeComparator( name )
- .reversed( ) ).filter( Objects::nonNull ).reduce( Comparator::thenComparing )
- .orElseThrow( () -> new IllegalArgumentException( "No attribute ordering found" ) );
- }
- }
-
- /**
- * Returns a query filter for a specific attribute and query token.
- * @param attribute the attribute name to filter for.
- * @param queryToken the search token.
- * @return The predicate used to filter the token
- */
- Predicate<T> getAttributeQueryFilter( final String attribute, final String queryToken )
- {
- if ( FILTER_MAP.containsKey( attribute ) )
- {
- return ( T u ) -> FILTER_MAP.get( attribute ).test( queryToken, u );
- }
- else
- {
- return DEFAULT_FILTER;
- }
- }
-
- /**
- * Returns the combined query filter for the given query terms.
- * The query terms may be either simple strings separated by whitespace or use the
- * <code>attribute:query</code> syntax, that searches only the attribute for the query term.
- * @param queryTerms the query string
- * @return the combined query filter
- */
- Predicate<T> getQueryFilter( String queryTerms )
- {
- return Arrays.stream( queryTerms.split( "\\s+" ) )
- .map( s -> {
- if ( s.contains( ":" ) )
- {
- String attr = StringUtils.substringBefore( s, ":" );
- String term = StringUtils.substringAfter( s, ":" );
- return getAttributeQueryFilter( attr, term );
- }
- else
- {
- return Arrays.stream( DEFAULT_SEARCH_FIELDS )
- .map( att -> getAttributeQueryFilter( att, s ) ).reduce( Predicate::or ).get( );
- }
- }
- ).reduce( Predicate::or ).get( );
- }
-
-}
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/resources/META-INF/spring-context.xml b/redback-integrations/redback-rest/redback-rest-services/src/main/resources/META-INF/spring-context.xml
index ff90b95..104d858 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/resources/META-INF/spring-context.xml
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/resources/META-INF/spring-context.xml
@@ -61,9 +61,12 @@
<!-- CXF OpenApiFeature -->
- <bean id="openApiFeature" class="org.apache.cxf.jaxrs.openapi.OpenApiFeature">
- <property name="scanKnownConfigLocations" value="true"/>
- <!-- customize some of the properties -->
+ <bean id="redbackOpenApiFeature" class="org.apache.cxf.jaxrs.openapi.OpenApiFeature">
+ <property name="scanKnownConfigLocations" value="false"/>
+ <property name="configLocation" value="redback/openapi-configuration.yaml"/>
+ <property name="scan" value="false"/>
+ <property name="useContextBasedConfig" value="true"/>
+ <!-- <property name="scannerClass" value="io.swagger.v3.jaxrs2.integration.JaxrsApplicationScanner"/> -->
</bean>
<jaxrs:server name="redbackServices" address="/redbackServices">
@@ -89,7 +92,7 @@
</jaxrs:providers>
</jaxrs:server>
- <jaxrs:server address="/v2/redback">
+ <jaxrs:server name="v2.redback" address="/v2/redback">
<jaxrs:serviceBeans>
<ref bean="v2.userService#rest"/>
<ref bean="v2.authenticationService#rest"/>
@@ -109,7 +112,7 @@
<ref bean="threadLocalUserCleaner#rest"/>
</jaxrs:providers>
<jaxrs:features>
- <ref bean="openApiFeature" />
+ <ref bean="redbackOpenApiFeature" />
</jaxrs:features>
</jaxrs:server>
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/test/resources/spring-context.xml b/redback-integrations/redback-rest/redback-rest-services/src/test/resources/spring-context.xml
index a9f90c8..1da544b 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/test/resources/spring-context.xml
+++ b/redback-integrations/redback-rest/redback-rest-services/src/test/resources/spring-context.xml
@@ -48,11 +48,7 @@
</bean>
<alias name="authenticator#jwt" alias="jwtAuthenticator#default" />
-
-
-
<alias name="authorizer#rbac" alias="authorizer#default"/>
-
<alias name="userManager#configurable" alias="userManager#default"/>
<!--