Skip to content

Commit

Permalink
Fixing (or partially fixing) issues with sending grants to open search
Browse files Browse the repository at this point in the history
  • Loading branch information
GavCookCO committed Apr 19, 2024
1 parent 93883fc commit f2f9c39
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.contentful.java.cda.CDAClient;
import com.contentful.java.cda.CDAEntry;
import com.contentful.java.cda.QueryOperation;
import com.contentful.java.cma.CMACallback;
import com.contentful.java.cma.CMAClient;
import com.contentful.java.cma.model.CMAEntry;
import com.contentful.java.cma.model.rich.CMARichDocument;
Expand Down Expand Up @@ -32,6 +31,7 @@
import gov.cabinetoffice.gap.adminbackend.repositories.SchemeRepository;
import gov.cabinetoffice.gap.adminbackend.utils.CurrencyFormatter;
import gov.cabinetoffice.gap.adminbackend.utils.HelperUtils;
import static gov.cabinetoffice.gap.adminbackend.validation.validators.AdvertPageResponseValidator.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONArray;
Expand All @@ -47,8 +47,6 @@
import java.time.format.DateTimeFormatter;
import java.util.*;

import static gov.cabinetoffice.gap.adminbackend.validation.validators.AdvertPageResponseValidator.*;

@Service
@RequiredArgsConstructor
@Slf4j
Expand Down Expand Up @@ -300,7 +298,6 @@ public void deleteGrantAdvert(UUID grantAdvertId) {
}

public GrantAdvert publishAdvert(UUID advertId) {
final Instant now = Instant.now();
final GrantAdvert advert = getAdvertById(advertId);

CMAEntry contentfulAdvert;
Expand All @@ -320,13 +317,8 @@ public GrantAdvert publishAdvert(UUID advertId) {
advert.setContentfulEntryId(contentfulAdvert.getId());

if (Boolean.FALSE.equals(contentfulAdvert.isPublished())) {
contentfulManagementClient.entries().async().publish(contentfulAdvert, new CMACallback<>() {
@Override
protected void onSuccess(CMAEntry result) {
openSearchService.indexEntry(result);
log.debug("Took {} seconds to publish advert", Duration.between(now, Instant.now()).getSeconds());
}
});
final CMAEntry publishedAdvert = contentfulManagementClient.entries().publish(contentfulAdvert);
openSearchService.indexEntry(publishedAdvert);
}

updateGrantAdvertApplicationDates(advert);
Expand Down Expand Up @@ -460,6 +452,7 @@ private void createRichTextQuestionsInContentful(final GrantAdvert advert, final
log.info("Took {} seconds to try and update rich text questions in Contentful", Duration.between(now, Instant.now()).getSeconds());
})
.block();

log.info("Took {} seconds to update rich text questions in Contentful", Duration.between(now, Instant.now()).getSeconds());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ void publishAdvert_successfullyPublishedAdvert() {

when(contentfulEntries.fetchOne(contentfulAdvertId)).thenReturn(publishedContentfulAdvert);

when(contentfulEntries.async()).thenReturn(async);
//when(contentfulEntries.async()).thenReturn(async);

doReturn(mockGrantAdvert).when(grantAdvertService).save(any());

Expand Down Expand Up @@ -899,7 +899,7 @@ void publishAdvert_successfullyPublishedAdvert() {
verify(contentfulEntries).fetchOne(contentfulAdvertId);

// verify that we've published
verify(async).publish(eq(publishedContentfulAdvert), any());
verify(contentfulEntries).publish(publishedContentfulAdvert);
}

@Test
Expand All @@ -924,7 +924,7 @@ void publishAdvert_updatesExistingAdvert_IfFirstPublishedDateHasBeenSet() {
when(contentfulEntries.update(Mockito.any())).thenReturn(publishedContentfulAdvert);
when(contentfulEntries.fetchOne(contentfulAdvertId)).thenReturn(publishedContentfulAdvert,
publishedContentfulAdvert);
when(contentfulEntries.async()).thenReturn(async);
//when(contentfulEntries.async()).thenReturn(async);
doReturn(grantAvertInDatabase).when(grantAdvertService).save(any());

final WebClient webClient = mock(WebClient.class);
Expand Down Expand Up @@ -965,7 +965,7 @@ void publishAdvert_updatesExistingAdvert_IfFirstPublishedDateHasBeenSet() {
verify(contentfulEntries, atLeastOnce()).fetchOne(contentfulAdvertId);

// verify that we've published
verify(async).publish(eq(publishedContentfulAdvert), any());
verify(contentfulEntries).publish(publishedContentfulAdvert);
}

@Test
Expand Down Expand Up @@ -1010,7 +1010,7 @@ void publishAdvertThroughLambda_successfullyPublishedAdvert() {

when(contentfulEntries.fetchOne(contentfulAdvertId)).thenReturn(publishedContentfulAdvert);

when(contentfulEntries.async()).thenReturn(async);
//when(contentfulEntries.async()).thenReturn(async);

final ArgumentCaptor<CMAEntry> entryCaptor = ArgumentCaptor.forClass(CMAEntry.class);

Expand Down Expand Up @@ -1047,7 +1047,7 @@ void publishAdvertThroughLambda_successfullyPublishedAdvert() {
verify(contentfulEntries).fetchOne(contentfulAdvertId);

// verify that we've published
verify(async).publish(eq(publishedContentfulAdvert), any());
verify(contentfulEntries).publish(publishedContentfulAdvert);
}

}
Expand Down

0 comments on commit f2f9c39

Please sign in to comment.