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

Users Match Predicate #3051

Merged
merged 2 commits into from
Aug 27, 2020
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 @@ -51,11 +51,13 @@ public class Users extends AbstractKapuaResource {
/**
* Gets the {@link User} list in the scope.
*
* @param scopeId The {@link ScopeId} in which to search results.
* @param name The {@link User} name in which to search results.
* @param scopeId The {@link ScopeId} in which to search results.
* @param name The {@link User} name in which to search results.
* @param matchTerm A term to be matched in at least one of the configured fields of this entity
* @param askTotalCount Ask for the total count of the matched entities in the result
* @param offset The result set offset.
* @param limit The result set limit.
* @param offset The result set offset.
* @param limit The result set limit.
*
* @return The {@link UserListResult} of all the users associated to the current selected scope.
* @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @since 1.0.0
Expand All @@ -65,6 +67,7 @@ public class Users extends AbstractKapuaResource {
public UserListResult 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 @@ -74,6 +77,10 @@ public UserListResult simpleQuery(
if (!Strings.isNullOrEmpty(name)) {
andPredicate.and(query.attributePredicate(KapuaNamedEntityAttributes.NAME, name));
}
if (matchTerm != null && !matchTerm.isEmpty()) {
andPredicate.and(query.matchPredicate(matchTerm));
}

query.setPredicate(andPredicate);

query.setAskTotalCount(askTotalCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ paths:
description: The user 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:

- NAME
- EMAIL
- PHONE_NUMBER
- DISPLAY_NAME
- EXTERNAL_ID
- DESCRIPTION
- $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
Expand Up @@ -11,35 +11,8 @@
*******************************************************************************/
package org.eclipse.kapua.service.device.registry;

import java.util.Arrays;
import org.eclipse.kapua.model.query.predicate.MatchPredicate;

import org.eclipse.kapua.commons.model.query.predicate.AbstractMatchPredicate;

public class DeviceMatchPredicate<T> extends AbstractMatchPredicate<T> {

/**
* Constructor.
*
* @param matchTerm
* @since 1.3.0
*/
public DeviceMatchPredicate(T matchTerm) {
this.attributeNames = Arrays.asList(
DeviceAttributes.CLIENT_ID,
DeviceAttributes.DISPLAY_NAME,
DeviceAttributes.SERIAL_NUMBER,
DeviceAttributes.MODEL_ID,
DeviceAttributes.MODEL_NAME,
DeviceAttributes.BIOS_VERSION,
DeviceAttributes.FIRMWARE_VERSION,
DeviceAttributes.OS_VERSION,
DeviceAttributes.JVM_VERSION,
DeviceAttributes.OSGI_FRAMEWORK_VERSION,
DeviceAttributes.APPLICATION_FRAMEWORK_VERSION,
DeviceAttributes.CONNECTION_INTERFACE,
DeviceAttributes.CONNECTION_IP
);
this.matchTerm = matchTerm;
}
public interface DeviceMatchPredicate<T> extends MatchPredicate<T> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2020 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.service.device.registry.internal;

import java.util.Arrays;

import org.eclipse.kapua.commons.model.query.predicate.AbstractMatchPredicate;
import org.eclipse.kapua.service.device.registry.DeviceAttributes;
import org.eclipse.kapua.service.device.registry.DeviceMatchPredicate;

public class DeviceMatchPredicateImpl<T> extends AbstractMatchPredicate<T> implements DeviceMatchPredicate<T> {

/**
* Constructor.
*
* @param matchTerm
* @since 1.3.0
*/
public DeviceMatchPredicateImpl(T matchTerm) {
this.attributeNames = Arrays.asList(
DeviceAttributes.CLIENT_ID,
DeviceAttributes.DISPLAY_NAME,
DeviceAttributes.SERIAL_NUMBER,
DeviceAttributes.MODEL_ID,
DeviceAttributes.MODEL_NAME,
DeviceAttributes.BIOS_VERSION,
DeviceAttributes.FIRMWARE_VERSION,
DeviceAttributes.OS_VERSION,
DeviceAttributes.JVM_VERSION,
DeviceAttributes.OSGI_FRAMEWORK_VERSION,
DeviceAttributes.APPLICATION_FRAMEWORK_VERSION,
DeviceAttributes.CONNECTION_INTERFACE,
DeviceAttributes.CONNECTION_IP
);
this.matchTerm = matchTerm;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.service.device.registry.Device;
import org.eclipse.kapua.service.device.registry.DeviceAttributes;
import org.eclipse.kapua.service.device.registry.DeviceMatchPredicate;
import org.eclipse.kapua.service.device.registry.DeviceQuery;

/**
Expand Down Expand Up @@ -47,8 +46,8 @@ public DeviceQueryImpl(KapuaId scopeId) {
}

@Override
public <T> DeviceMatchPredicate<T> matchPredicate(T matchTerm) {
return new DeviceMatchPredicate<>(matchTerm);
public <T> DeviceMatchPredicateImpl<T> matchPredicate(T matchTerm) {
return new DeviceMatchPredicateImpl<>(matchTerm);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*******************************************************************************
* Copyright (c) 2020 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.service.user;

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

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@
@XmlType(factoryClass = UserXmlRegistry.class, factoryMethod = "newQuery")
public interface UserQuery extends KapuaQuery<User> {

<T> UserMatchPredicate<T> matchPredicate(T matchTerm);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*******************************************************************************
* Copyright (c) 2020 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.service.user.internal;

import java.util.Arrays;

import org.eclipse.kapua.commons.model.query.predicate.AbstractMatchPredicate;
import org.eclipse.kapua.model.KapuaNamedEntityAttributes;
import org.eclipse.kapua.service.user.UserAttributes;
import org.eclipse.kapua.service.user.UserMatchPredicate;

public class UserMatchPredicateImpl<T> extends AbstractMatchPredicate<T> implements UserMatchPredicate<T> {

/**
* Constructor.
*
* @param matchTerm
* @since 1.3.0
*/
public UserMatchPredicateImpl(T matchTerm) {
this.attributeNames = Arrays.asList(
KapuaNamedEntityAttributes.NAME,
UserAttributes.EMAIL,
UserAttributes.PHONE_NUMBER,
UserAttributes.DISPLAY_NAME,
UserAttributes.EXTERNAL_ID,
KapuaNamedEntityAttributes.DESCRIPTION
);
this.matchTerm = matchTerm;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ public UserQueryImpl(KapuaId scopeId) {
this();
setScopeId(scopeId);
}

@Override
public <T> UserMatchPredicateImpl<T> matchPredicate(T matchTerm) {
return new UserMatchPredicateImpl<>(matchTerm);
}

}