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

GRAD2-3315 : Changes to ignore school & district contact updates. #430

Open
wants to merge 3 commits into
base: grad-release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -78,8 +78,15 @@ public void initSpecifications() {
map.put(FilterOperation.IN, filterCriteria -> (root, criteriaQuery, criteriaBuilder) -> root
.get(filterCriteria.getFieldName()).in(filterCriteria.getConvertedValues()));

map.put(FilterOperation.NOT_IN, filterCriteria -> (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
.not(root.get(filterCriteria.getFieldName()).in(filterCriteria.getConvertedValues())));
map.put(FilterOperation.NOT_IN, filterCriteria -> (root, criteriaQuery, criteriaBuilder) -> {
if (filterCriteria.getFieldName().contains(".")) {
String[] splits = filterCriteria.getFieldName().split("\\.");
if (splits.length == 2) {
return criteriaBuilder.or(criteriaBuilder.not(root.join(splits[0]).get(splits[1]).in(filterCriteria.getConvertedValues())), criteriaBuilder.isNull(root.join(splits[0]).get(splits[1])));
}
}
return criteriaBuilder.or(criteriaBuilder.not(root.get(filterCriteria.getFieldName()).in(filterCriteria.getConvertedValues())), criteriaBuilder.isNull(root.get(filterCriteria.getFieldName())));
});

map.put(FilterOperation.BETWEEN,
filterCriteria -> (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.between(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
Expand Down Expand Up @@ -87,15 +88,16 @@ public Specification<EventHistoryEntity> setSpecificationAndSortCriteria(String
Specification<EventHistoryEntity> eventHistoryEntitySpecification = null;
try {
RequestUtil.getSortCriteria(sortCriteriaJson, objectMapper, sorts);
int i = 0;
if (StringUtils.isNotBlank(searchCriteriaListJson)) {
List<Search> searches = objectMapper.readValue(searchCriteriaListJson, new TypeReference<>() {
});
int i = 0;
for (var search : searches) {
eventHistoryEntitySpecification = getSpecifications(eventHistoryEntitySpecification, i, search);
i++;
}
}
eventHistoryEntitySpecification = getSpecifications(eventHistoryEntitySpecification, i, getDefaultSearchCriteria());
} catch (JsonProcessingException e) {
throw new TraxAPIRuntimeException(e.getMessage());
}
Expand Down Expand Up @@ -123,6 +125,17 @@ private Specification<EventHistoryEntity> getEventHistorySpecification(List<Sear
return eventHistoryEntitySpecification;
}

private Search getDefaultSearchCriteria() {
List<String> ignorableEvents = List.of("CREATE_SCHOOL_CONTACT", "UPDATE_SCHOOL_CONTACT", "DELETE_SCHOOL_CONTACT", "CREATE_DISTRICT_CONTACT", "UPDATE_DISTRICT_CONTACT", "DELETE_DISTRICT_CONTACT");
SearchCriteria searchCriteria = new SearchCriteria();
searchCriteria.setCondition(Condition.AND);
searchCriteria.setValueType(ValueType.STRING);
searchCriteria.setOperation(FilterOperation.NOT_IN);
searchCriteria.setValue(String.join(",", ignorableEvents));
searchCriteria.setKey("event.eventType");
return Search.builder().searchCriteriaList(new ArrayList<>(List.of(searchCriteria))).condition(Condition.AND).build();
}

private Specification<EventHistoryEntity> getSpecificationPerGroup(Specification<EventHistoryEntity> eventHistoryEntitySpecification, int i, SearchCriteria criteria, Specification<EventHistoryEntity> typeSpecification) {
if (i == 0) {
eventHistoryEntitySpecification = Specification.where(typeSpecification);
Expand Down Expand Up @@ -163,7 +176,6 @@ private Specification<EventHistoryEntity> getTypeSpecification(String key, Filte
return schoolEntitySpecification;
}


@Transactional(propagation = Propagation.SUPPORTS)
public CompletableFuture<Page<EventHistoryEntity>> findAll(Specification<EventHistoryEntity> eventHistorySpecs, final Integer pageNumber, final Integer pageSize, final List<Sort.Order> sorts) {
log.trace("In find all query: {}", eventHistorySpecs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void testUpdateEventHistory_givenInvalidId_shouldReturnStatusNotFound() throws E
}

private EventHistory createEventHistoryData() throws JsonProcessingException {
var event = TestUtils.createEvent("DELETE_DISTRICT_CONTACT", TestUtils.createDistrictContact(), LocalDateTime.now(), eventRepository);
var event = TestUtils.createEvent("UPDATE_AUTHORITY_CONTACT", TestUtils.createAuthorityContact(), LocalDateTime.now(), eventRepository);
var eventHistory = TestUtils.createEventHistory(event, LocalDateTime.now(), eventHistoryRepository);
return mapper.toStructure(eventHistory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ protected EventEntity createEventData() {
.eventId(UUID.randomUUID())
.eventPayload("""
{
"schoolContactId": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"schoolId": "d3b07384-d9a0-4c1e-8b0e-6e2b6b7b8b8b",
"schoolContactTypeCode": "string",
"authorityContactId": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"independentAuthorityId": "d3b07384-d9a0-4c1e-8b0e-6e2b6b7b8b8b",
"authorityContactTypeCode": "string",
"phoneNumber": "string",
"jobTitle": "string",
"phoneExtension": "string",
Expand All @@ -56,8 +56,8 @@ protected EventEntity createEventData() {
"expiryDate": "string"
}""")
.eventStatus("PROCESSED")
.eventType("CREATE_SCHOOL_CONTACT")
.eventOutcome("SCHOOL_CONTACT_CREATED")
.eventType("CREATE_AUTHORITY_CONTACT")
.eventOutcome("AUTHORITY_CONTACT_CREATED")
.createUser(USER)
.createDate(LocalDateTime.now())
.updateUser(USER)
Expand Down