Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [REST API] Batch of askTotalCount & matchTerm queryParameters for some APIs #4080

Merged
merged 8 commits into from
Jul 11, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
@PathParam("scopeId") ScopeId scopeId,
@QueryParam("usage") String usage,
@QueryParam("endpointType") @DefaultValue(EndpointInfo.ENDPOINT_TYPE_RESOURCE) String endpointType,
@QueryParam("matchTerm") String matchTerm,
@QueryParam("askTotalCount") boolean askTotalCount,
@QueryParam("offset") @DefaultValue("0") int offset,
@QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException {
EndpointInfoQuery query = endpointInfoFactory.newQuery(scopeId);
Expand All @@ -76,10 +78,14 @@
if (!Strings.isNullOrEmpty(usage)) {
andPredicate.and(query.attributePredicate(EndpointInfoAttributes.USAGES, endpointInfoFactory.newEndpointUsage(usage)));
}
if (matchTerm != null && !matchTerm.isEmpty()) {
andPredicate.and(query.matchPredicate(matchTerm));

Check warning on line 82 in rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/EndpointInfos.java

View check run for this annotation

Codecov / codecov/patch

rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/EndpointInfos.java#L82

Added line #L82 was not covered by tests
}
query.setPredicate(andPredicate);

query.setOffset(offset);
query.setLimit(limit);
query.setAskTotalCount(askTotalCount);

Check warning on line 88 in rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/EndpointInfos.java

View check run for this annotation

Codecov / codecov/patch

rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/EndpointInfos.java#L88

Added line #L88 was not covered by tests

return query(scopeId, endpointType, query);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
public GroupListResult simpleQuery(
@PathParam("scopeId") ScopeId scopeId,
@QueryParam("name") String name,
@QueryParam("askTotalCount") boolean askTotalCount,
@QueryParam("matchTerm") String matchTerm,
@QueryParam("offset") @DefaultValue("0") int offset,
@QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException {
GroupQuery query = groupFactory.newQuery(scopeId);
Expand All @@ -74,10 +76,14 @@
if (!Strings.isNullOrEmpty(name)) {
andPredicate.and(query.attributePredicate(KapuaNamedEntityAttributes.NAME, name));
}
if (matchTerm != null && !matchTerm.isEmpty()) {
andPredicate.and(query.matchPredicate(matchTerm));

Check warning on line 80 in rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Groups.java

View check run for this annotation

Codecov / codecov/patch

rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Groups.java#L80

Added line #L80 was not covered by tests
}
query.setPredicate(andPredicate);

query.setOffset(offset);
query.setLimit(limit);
query.setAskTotalCount(askTotalCount);

Check warning on line 86 in rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Groups.java

View check run for this annotation

Codecov / codecov/patch

rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Groups.java#L86

Added line #L86 was not covered by tests

return query(scopeId, query);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
public RoleListResult simpleQuery(
@PathParam("scopeId") ScopeId scopeId,
@QueryParam("name") String name,
@QueryParam("matchTerm") String matchTerm,
@QueryParam("askTotalCount") boolean askTotalCount,
@QueryParam("offset") @DefaultValue("0") int offset,
@QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException {
Expand All @@ -88,6 +89,9 @@
if (!Strings.isNullOrEmpty(name)) {
andPredicate.and(query.attributePredicate(KapuaNamedEntityAttributes.NAME, name));
}
if (matchTerm != null && !matchTerm.isEmpty()) {
andPredicate.and(query.matchPredicate(matchTerm));

Check warning on line 93 in rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Roles.java

View check run for this annotation

Codecov / codecov/patch

rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Roles.java#L93

Added line #L93 was not covered by tests
}
query.setPredicate(andPredicate);

query.setAskTotalCount(askTotalCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
@PathParam("scopeId") ScopeId scopeId,
@QueryParam("name") String name,
@QueryParam("askTotalCount") boolean askTotalCount,
@QueryParam("matchTerm") String matchTerm,
@QueryParam("offset") @DefaultValue("0") int offset,
@QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException {
TagQuery query = tagFactory.newQuery(scopeId);
Expand All @@ -76,6 +77,9 @@
if (!Strings.isNullOrEmpty(name)) {
andPredicate.and(query.attributePredicate(KapuaNamedEntityAttributes.NAME, name));
}
if (matchTerm != null && !matchTerm.isEmpty()) {
andPredicate.and(query.matchPredicate(matchTerm));

Check warning on line 81 in rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Tags.java

View check run for this annotation

Codecov / codecov/patch

rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Tags.java#L81

Added line #L81 was not covered by tests
}
query.setPredicate(andPredicate);

query.setOffset(offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ paths:
schema:
type: string
- $ref: './endpointInfo.yaml#/components/parameters/endpointType'
- $ref: '../openapi.yaml#/components/parameters/askTotalCount'
- name: matchTerm
in: query
description: |
A term to match on different fields. Every entity whose at least one of the specified fields starts with this value will be matched.
Matches on the following fields:

- SCHEMA
- DNS
schema:
type: string
- $ref: '../openapi.yaml#/components/parameters/limit'
- $ref: '../openapi.yaml#/components/parameters/offset'
responses:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ paths:
description: The group name to filter results
schema:
type: string
- $ref: '../openapi.yaml#/components/parameters/askTotalCount'
- name: matchTerm
in: query
description: |
A term to match on different fields. Every entity whose at least one of the specified fields starts with this value will be matched.
Matches on the following fields:

- DESCRIPTION
- NAME
schema:
type: string
- $ref: '../openapi.yaml#/components/parameters/limit'
- $ref: '../openapi.yaml#/components/parameters/offset'
responses:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ paths:
description: The role name to filter results
schema:
type: string
- name: matchTerm
in: query
description: |
A term to match on different fields. Every entity whose at least one of the specified fields starts with this value will be matched.
Matches on the following fields:

- DESCRIPTION
- NAME
schema:
type: string
- $ref: '../openapi.yaml#/components/parameters/askTotalCount'
- $ref: '../openapi.yaml#/components/parameters/limit'
- $ref: '../openapi.yaml#/components/parameters/offset'
Expand Down
10 changes: 10 additions & 0 deletions rest-api/resources/src/main/resources/openapi/tag/tag-scopeId.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ paths:
description: The tag name to filter results
schema:
type: string
- name: matchTerm
in: query
description: |
A term to match on different fields. Every entity whose at least one of the specified fields starts with this value will be matched.
Matches on the following fields:

- DESCRIPTION
- NAME
schema:
type: string
- $ref: '../openapi.yaml#/components/parameters/askTotalCount'
- $ref: '../openapi.yaml#/components/parameters/limit'
- $ref: '../openapi.yaml#/components/parameters/offset'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*******************************************************************************
* Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.service.endpoint;

import org.eclipse.kapua.model.query.predicate.MatchPredicate;

public interface EndpointInfoMatchPredicate<T> extends MatchPredicate<T> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,13 @@
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(factoryClass = EndpointInfoXmlRegistry.class, factoryMethod = "newQuery")
public interface EndpointInfoQuery extends KapuaQuery {

/**
* Instantiates a new {@link EndpointInfoMatchPredicate}.
*
* @param matchTerm The term to use to match.
* @param <T> The type of the term
* @return The newly instantiated {@link EndpointInfoMatchPredicate}.
* @since 2.1.0
*/
<T> EndpointInfoMatchPredicate<T> matchPredicate(T matchTerm);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.service.endpoint.internal;

import org.eclipse.kapua.commons.model.query.predicate.AbstractMatchPredicate;
import org.eclipse.kapua.service.endpoint.EndpointInfoAttributes;
import org.eclipse.kapua.service.endpoint.EndpointInfoMatchPredicate;

import java.util.Arrays;

public class EndpointInfoMatchPredicateImpl<T> extends AbstractMatchPredicate<T> implements EndpointInfoMatchPredicate<T> {

/**
* Constructor.
*
* @param matchTerm
* @since 2.1.0
*/
public EndpointInfoMatchPredicateImpl(T matchTerm) {
this.attributeNames = Arrays.asList(

Check warning on line 30 in service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoMatchPredicateImpl.java

View check run for this annotation

Codecov / codecov/patch

service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoMatchPredicateImpl.java#L29-L30

Added lines #L29 - L30 were not covered by tests
EndpointInfoAttributes.SCHEMA,
EndpointInfoAttributes.DNS
);
this.matchTerm = matchTerm;
}

Check warning on line 35 in service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoMatchPredicateImpl.java

View check run for this annotation

Codecov / codecov/patch

service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoMatchPredicateImpl.java#L34-L35

Added lines #L34 - L35 were not covered by tests

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery;
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.service.endpoint.EndpointInfoMatchPredicate;
import org.eclipse.kapua.service.endpoint.EndpointInfoQuery;

/**
Expand All @@ -32,4 +33,9 @@
public EndpointInfoQueryImpl(KapuaId scopeId) {
super(scopeId);
}

@Override
public <T> EndpointInfoMatchPredicate<T> matchPredicate(T matchTerm) {
return new EndpointInfoMatchPredicateImpl<>(matchTerm);

Check warning on line 39 in service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoQueryImpl.java

View check run for this annotation

Codecov / codecov/patch

service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoQueryImpl.java#L39

Added line #L39 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*******************************************************************************
* Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.service.authorization.group;

import org.eclipse.kapua.model.query.predicate.MatchPredicate;

public interface GroupMatchPredicate<T> extends MatchPredicate<T> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(factoryClass = GroupXmlRegistry.class, factoryMethod = "newQuery")
public interface GroupQuery extends KapuaQuery {
/**
* Instantiates a new {@link GroupMatchPredicate}.
*
* @param matchTerm The term to use to match.
* @param <T> The type of the term
* @return The newly instantiated {@link GroupMatchPredicate}.
* @since 2.1.0
*/
<T> GroupMatchPredicate<T> matchPredicate(T matchTerm);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
* @since 1.0.0
*/
public class RoleAttributes extends KapuaNamedEntityAttributes {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*******************************************************************************
* Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.service.authorization.role;

import org.eclipse.kapua.model.query.predicate.MatchPredicate;

public interface RoleMatchPredicate<T> extends MatchPredicate<T> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,14 @@
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(factoryClass = RoleXmlRegistry.class, factoryMethod = "newQuery")
public interface RoleQuery extends KapuaQuery {
/**
* Instantiates a new {@link RoleMatchPredicate}.
*
* @param matchTerm The term to use to match.
* @param <T> The type of the term
* @return The newly instantiated {@link RoleMatchPredicate}.
* @since 2.1.0
*/
<T> RoleMatchPredicate<T> matchPredicate(T matchTerm);

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* @since 1.1.0
*/
public class CertificateInfoAttributes extends KapuaNamedEntityAttributes {

public static final String CA_ID = "caId";

public static final String FORWARDABLE = "forwardable";
Expand All @@ -34,4 +33,12 @@ public class CertificateInfoAttributes extends KapuaNamedEntityAttributes {

public static final String USAGE_NAME = USAGE + ".name";

public static final String SERIAL = "serial";

public static final String ALGORITHM = "algorithm";

public static final String SUBJECT = "subject";



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*******************************************************************************
* Copyright (c) 2018, 2022 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.service.certificate.info;

import org.eclipse.kapua.model.query.predicate.MatchPredicate;

public interface CertificateInfoMatchPredicate<T> extends MatchPredicate<T> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,14 @@ public interface CertificateInfoQuery extends KapuaForwardableEntityQuery {
* @since 1.1.0
*/
void setIncludeInherited(Boolean includeInherited);

/**
* Instantiates a new {@link CertificateInfoMatchPredicate}.
*
* @param matchTerm The term to use to match.
* @param <T> The type of the term
* @return The newly instantiated {@link CertificateInfoMatchPredicate}.
* @since 2.1.0
*/
<T> CertificateInfoMatchPredicate<T> matchPredicate(T matchTerm);
}
Loading
Loading