-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNotesSpecificationBuilder.java
More file actions
50 lines (46 loc) · 1.84 KB
/
NotesSpecificationBuilder.java
File metadata and controls
50 lines (46 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.example.notes.builder;
import com.example.notes.criteria.BaseSpecificationBuilder;
import com.example.notes.criteria.Criteria;
import com.example.notes.entity.Notes;
import com.example.notes.repository.NotesRepository;
import com.example.notes.service.NotesService;
import com.example.notes.specifications.NotesSpecification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class NotesSpecificationBuilder extends BaseSpecificationBuilder {
@Autowired
NotesSpecification notesSpecification;
@Autowired
NotesRepository notesRepository;
public Specification builder(List<Criteria> criteriaList) {
Specification<Notes> specForId = null;
Specification<Notes> specForQuery = null;
Boolean first = true;
for (Criteria x : criteriaList) {
if (x.getKey().equalsIgnoreCase("id")) {
specForId = notesSpecification.builder("hasId",(Long.parseLong(x.getValue())));
} else if(x.getKey().equalsIgnoreCase("title")) {
if (first) {
first = false;
specForQuery = notesSpecification.builder("hasNoteHeadingLike",(x.getValue()));
} else {
specForQuery = specForQuery.or(notesSpecification.builder("hasNoteHeadingLike",(x.getValue())));
}
}
}
if(!first)
{
specForId = specForId.and(specForQuery);
}
Specification spec = Specification.where(specForId);
return spec;
}
public List<Notes> build(String data) {
super.builder(data);
Specification spec= builder(super.criteriaList);
return notesRepository.findAll(spec);
}
}