Spring Boot : Kotlin & MongoRepository : Performing a full text search - spring-boot

Hi there I am really new to Spring Boot and using Kotlin to learn it (I do Android/iOS professionally etc)
I have a basic API setup (Spring Boot, Web, MongoDB etc) and my interface uses MongoRepository
I have set up my MongoDB with a full-text index (text1) and sort by score. I am trying to call it in Kotlin now
override fun searchResult(search : String): List<Result> {
val criteria = TextCriteria.forDefaultLanguage()
.matchingAny(search)
val query = TextQuery.queryText(criteria)
.sortByScore()
.with(PageRequest(0, 5))
var r : List<Result> = searchRepository.findAll(query, Result.class)
}
How do I actually execute the query? FindAll is not right?

You need to create a query method in the repository interface. Please refer to repository spring documentation for details

Related

Custom Query REST Data with Panache

I am using REST Data with Panache for JAX RESTful Web Service generation by extending PanacheEntityResource. In Spring land there is query builder mechanism that allows the Spring Data repository to generate an SQL query based on the name and return type of the custom method signature.
I'm trying to achieve the same thing using Panache, so far unsuccessfully.
#ResourceProperties(path = "tasks", paged = false)
public interface TaskResource extends PanacheEntityResource<Task, UUID> {
List<Task> findByOrganizationId(#QueryParam("organizationId") UUID organizationId);
}
I want to pass the organazation ID as a query parameter, such that my request will be http://localhost:8080/tasks?organizationId=1e7e669d-2935-4d6f-8b23-7a2497b0f5b0, and my response will return a list of Tasks whose organization ID matches the one provided. Is there support for this functionality?
That functionality is currently not supported.
See https://quarkus.io/guides/rest-data-panache and https://quarkus.io/guides/spring-data-rest for more details

filter dynamodb from list in springboot

I have a Spring boot application using an AWS DynamoDb table which contains a list of items as such:
#DynamoDBTable(tableName = MemberDbo.TABLENAME)
public class MemberDbo {
public static final String TABLENAME = "Member";
#NonNull
#DynamoDBHashKey
#DynamoDBAutoGeneratedKey
protected String id;
// some more parameters
#DynamoDBAttribute
private List<String> membergroupIds;
}
I would like to find all members belonging to one specific groupId. In best case I would like to use CrudRepository like this:
#EnableScan
public interface MemberRepository extends CrudRepository<MemberDbo, String> {
List<MemberDbo> findByMembergroupIdsContaining(String membergroupIds); // actually I want to filter by ONE groupId
}
Unfortunately the query above is not working (java.lang.String cannot be cast to java.util.List)
Any suggestions how to build a correct query with CrudRepository?
Any suggestions how to create a query with Amazon SDK or some other Springboot-compliant methods?
Alternatively can I create a dynamoDb index somehow and filter by that index?
Or do I need to create and maintain a new table programmatically containing the mapping between membergroupIds and members (which results in a lot of overhead in code and costs)?
A solution for CrudRepository is preferred since I may use Paging in future versions and CrudRepository easily supports paging.
If I have understood correctly this looks very easy. You using DynamoDBMapper for model persistence.
You have a member object, which contains a list of membergroupids, and all you want to do is retrieve this from the database. If so, using DynamoDBMapper you would do something like this:
AmazonDynamoDB dynamoDBClient = new AmazonDynamoDBClient();
DynamoDBMapper mapper = new DynamoDBMapper(dynamoDBClient);
MemberDbo member = mapper.load(MemberDbo.class, hashKey, rangeKey);
member.getMembergroupIds();
Where you need to replace hashKey and rangeKey. You can omit rangeKey if you don't have one.
DynamoDBMapper also supports paging out of the box.
DynamoDBMapper is an excellent model persistence tool, it has strong features, its simple to use and because its written by AWS, it has seamless integration with DynamoDB. Its creators have also clearly been influenced by spring. In short, I would use DynamoDBMapper for model persistence and Spring Boot for model-controller stuff.

How to generate dynamic query in #Query annotation from spring boot

My json which stored mongodb,
{
"deviceId": "testdevice",
"deviceData": {
"device_owner": "Anand",
"device_type": "xxxx"
"device_desc": "xxxx"
...
}
}
Here deviceData is device specific.It may vary based on devices. I want to generate dynamic way to filter data based on device data , i.e, deviceData.OBJECT=VALUE. I am trying to retrieve the value from spring boot app.
My spring boot DAO class
#Query({'device':?0, 'deviceData.filterString'})
Page findByDeviceData(String deviceId, String filterString,Pageable pageable);
Can any one help how to achieve this
Thanks in advance.

spring batch with spring data JPA using RepositoryItemReader and Repository Item writer

spring batch with spring data JPA using RepositoryItemReader and Repository Item writer.
I dont see any example implementation online , please throw some light or examples ..code links
RepositoryItemReader<MemberDemographics> repositoryReport = new
RepositoryItemReader<MemberDemographics>();
repositoryReport.setRepository(memberDemoGraphicsRepository); //Repository class refferance
repositoryReport.setMethodName("getMemberDemoGraphicByGroupID");//repository method
List<Long> groupIDs = groupDemogrRepository.getValidGroups();
for (Long id : groupIDs) {
List<Long> parameters = new ArrayList<>() ;
parameters.add(id);
setAgrguments(parameters);
}
repositoryReport.setArguments(getAgrguments());// Mehtod Arguments

Spring OAuth 2 + Spring Data Neo4j multi-tenancy

I'm going to implement multi-tenancy support in my Spring OAuth 2 + Spring Data Neo4j project.
I have configure my OAuth2 Authorization Server with a few different clients with a different clientId.
Also, I have added a base TenantEntity to my Spring Data Neo4j models:
#NodeEntity
public abstract class TenantEntity extends BaseEntity {
private String tenantId;
public String getTenantId() {
return tenantId;
}
public void setTenantId(String tenantId) {
this.tenantId = tenantId;
}
}
All of my existing Spring Data Neo4j entities must now extend this TenantEntity.
Right now I'm going to rewrite all of my Neo4j queries in order to support this tenantId parameter.
For example current query:
MATCH (d:Decision)<-[:DEFINED_BY]-(c:Criterion) WHERE id(d) = {decisionId} AND NOT (c)<-[:CONTAINS]-(:CriterionGroup) RETURN c
I going to rewrite to following:
MATCH (d:Decision)<-[:DEFINED_BY]-(c:Criterion) WHERE id(d) = {decisionId} AND d.tenantId = {tenantId} AND c.tenantId = {tenantId} AND NOT (c)<-[:CONTAINS]-(:CriterionGroup) RETURN c
In turn for tenantId I'm going to use OAuth2 clientId and store it together with every Neo4j entity.
Is it a correct approach in order to implement multi-tenancy or Spring OAuth2/Data Neo4j can propose something more standard for this purpose out of the box ?
Since Neo4j currently has no feature to support multi-tenancy, if you particularly need this, it must be worked-around as you have done. You solution looks reasonable.
Alternatively, licensing is by machine, so it is possible to use, for example, Docker and spin up multiple Neo4j instances each on a different port.

Resources