Skip to content

Commit

Permalink
PP-11205 Set archived_date (#2238)
Browse files Browse the repository at this point in the history
- Sets `archived_date` when a service is archived
- Returns the field in the API.
  • Loading branch information
kbottla authored Nov 9, 2023
1 parent 031475f commit 86dfc67
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 8 deletions.
4 changes: 4 additions & 0 deletions openapi/adminusers_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,10 @@ components:
archived:
type: boolean
example: false
archived_date:
type: string
format: date-time
example: 2023-04-09T18:07:46.568Z
collect_billing_address:
type: boolean
example: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ private int archiveServices() {
if (canArchiveService(serviceEntity)) {
numberOfServicesArchived.getAndIncrement();
serviceEntity.setArchived(true);
serviceEntity.setArchivedDate(clock.instant().atZone(UTC));

serviceDao.merge(serviceEntity);
detachUsers(serviceEntity);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/uk/gov/pay/adminusers/model/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public class Service {
@Schema(example = "2022-04-09T18:07:46.568Z")
private ZonedDateTime wentLiveDate;

@JsonSerialize(using = ApiResponseDateTimeSerializer.class)
@Schema(example = "2023-04-09T18:07:46.568Z")
private ZonedDateTime archivedDate;

@JsonIgnore
private ServiceName serviceName;

Expand Down Expand Up @@ -94,6 +98,7 @@ public static Service from(Integer id, String externalId, ServiceName serviceNam
false,
null,
null,
null,
null);
}

Expand All @@ -112,6 +117,7 @@ public static Service from(Integer id,
boolean archived,
ZonedDateTime createdDate,
ZonedDateTime wentLiveDate,
ZonedDateTime archivedDate,
PspTestAccountStage pspTestAccountStage) {
return new Service(id,
externalId,
Expand All @@ -128,6 +134,7 @@ public static Service from(Integer id,
archived,
createdDate,
wentLiveDate,
archivedDate,
pspTestAccountStage);
}

Expand All @@ -146,6 +153,7 @@ private Service(@JsonProperty("id") Integer id,
boolean archived,
ZonedDateTime createdDate,
ZonedDateTime wentLiveDate,
ZonedDateTime archivedDate,
PspTestAccountStage currentPspTestAccountStage) {
this.id = id;
this.externalId = externalId;
Expand All @@ -162,6 +170,7 @@ private Service(@JsonProperty("id") Integer id,
this.archived = archived;
this.createdDate = createdDate;
this.wentLiveDate = wentLiveDate;
this.archivedDate = archivedDate;
this.currentPspTestAccountStage = currentPspTestAccountStage;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ public class ServiceEntity {
@Convert(converter = UTCDateTimeConverter.class)
private ZonedDateTime wentLiveDate;

@Column(name = "archived_date")
@Convert(converter = UTCDateTimeConverter.class)
private ZonedDateTime archivedDate;

@Column(name = "current_psp_test_account_stage")
@Enumerated(STRING)
private PspTestAccountStage currentPspTestAccountStage = PspTestAccountStage.NOT_STARTED;
Expand Down Expand Up @@ -263,6 +267,14 @@ public void setWentLiveDate(ZonedDateTime wentLiveDate) {
this.wentLiveDate = wentLiveDate;
}

public ZonedDateTime getArchivedDate() {
return archivedDate;
}

public void setArchivedDate(ZonedDateTime archivedDate) {
this.archivedDate = archivedDate;
}

public PspTestAccountStage getCurrentPspTestAccountStage() {
return currentPspTestAccountStage;
}
Expand All @@ -288,6 +300,7 @@ public Service toService() {
this.archived,
this.createdDate,
this.wentLiveDate,
this.archivedDate,
this.currentPspTestAccountStage);
service.setGatewayAccountIds(gatewayAccountIds.stream()
.map(GatewayAccountIdEntity::getGatewayAccountId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static org.apache.commons.lang3.RandomUtils.nextInt;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static uk.gov.pay.adminusers.fixtures.ForgottenPasswordDbFixture.aForgottenPasswordDbFixture;
import static uk.gov.pay.adminusers.fixtures.InviteDbFixture.inviteDbFixture;
Expand Down Expand Up @@ -139,6 +140,7 @@ void shouldArchiveHistoricalServicesAndDetachUsers() throws JsonProcessingExcept

List<Map<String, Object>> services = databaseHelper.findServiceByExternalId(service.getExternalId());
assertThat(services.get(0).get("archived"), is(true));
assertThat(services.get(0).get("archived_date"), is(notNullValue()));

serviceRoles = databaseHelper.findServiceRoleForUser(user.getId());
assertTrue(serviceRoles.isEmpty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ void shouldArchiveService_WhenTheLastTransactionDateIsBeforeTheServicesEligibleF
expungeAndArchiveHistoricalDataService.expungeAndArchiveHistoricalData();

assertTrue(serviceEntity.isArchived());
assertThat(serviceEntity.getArchivedDate(), is(clock.instant().atZone(UTC)));
verify(mockServiceDao).merge(serviceEntity);
verify(mockServiceRoleDao).removeUsersFromService(serviceEntity.getId());
}
Expand All @@ -225,6 +226,7 @@ void shouldArchiveServiceWithoutTransactionsButCreatedBeforeTheServicesEligibleF
expungeAndArchiveHistoricalDataService.expungeAndArchiveHistoricalData();

assertTrue(serviceEntity.isArchived());
assertThat(serviceEntity.getArchivedDate(), is(clock.instant().atZone(UTC)));
verify(mockServiceDao).merge(serviceEntity);
verify(mockServiceRoleDao).removeUsersFromService(serviceEntity.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public final class ServiceEntityFixture {
private String sector;
private PspTestAccountStage pspTestAccountStage = PspTestAccountStage.NOT_STARTED;
private boolean archived = false;
private ZonedDateTime archivedDate;

private ServiceEntityFixture() {
}
Expand Down Expand Up @@ -133,6 +134,11 @@ public ServiceEntityFixture withArchived(boolean archived) {
return this;
}

public ServiceEntityFixture withArchivedDate(ZonedDateTime archivedDate) {
this.archivedDate = archivedDate;
return this;
}

public ServiceEntity build() {
ServiceEntity serviceEntity = new ServiceEntity();
serviceEntity.setId(id);
Expand All @@ -152,6 +158,7 @@ public ServiceEntity build() {
serviceEntity.setSector(sector);
serviceEntity.setCurrentPspTestAccountStage(pspTestAccountStage);
serviceEntity.setArchived(archived);
serviceEntity.setArchivedDate(archivedDate);
return serviceEntity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

@ExtendWith(MockitoExtension.class)
@ExtendWith(DropwizardExtensionsSupport.class)
public class ServiceResourceFindTest extends ServiceResourceBaseTest {
class ServiceResourceFindTest extends ServiceResourceBaseTest {

private static ServiceDao mockedServiceDao = mock(ServiceDao.class);
private static UserDao mockedUserDao = mock(UserDao.class);
Expand Down Expand Up @@ -74,7 +74,7 @@ public void setUp() {
}

@Test
public void shouldGet_existingServiceById_withDefaultEnNameVariant() {
void shouldGet_existingServiceById_withDefaultEnNameVariant() {
String serviceExternalId = randomUuid();
ServiceEntity serviceEntity = ServiceEntityFixture.aServiceEntity().withExternalId(serviceExternalId).build();
given(mockedServiceDao.findByExternalId(serviceExternalId)).willReturn(Optional.of(serviceEntity));
Expand All @@ -98,7 +98,7 @@ public void shouldGet_existingServiceById_withDefaultEnNameVariant() {
}

@Test
public void shouldGetServiceById_withServiceNameVariantForCy() {
void shouldGetServiceById_withServiceNameVariantForCy() {
String serviceExternalId = randomUuid();
ServiceEntity serviceEntity = ServiceEntityFixture.aServiceEntity()
.withExternalId(serviceExternalId)
Expand All @@ -119,7 +119,7 @@ public void shouldGetServiceById_withServiceNameVariantForCy() {
}

@Test
public void shouldGetServiceById_withServiceNameVariantsForEn_andCy() {
void shouldGetServiceById_withServiceNameVariantsForEn_andCy() {
String serviceExternalId = randomUuid();
ServiceEntity serviceEntity = ServiceEntityFixture.aServiceEntity()
.withExternalId(serviceExternalId)
Expand All @@ -142,7 +142,7 @@ public void shouldGetServiceById_withServiceNameVariantsForEn_andCy() {
}

@Test
public void shouldFind_existingServiceByGatewayAccountId() {
void shouldFind_existingServiceByGatewayAccountId() {
GatewayAccountIdEntity gatewayAccountIdEntity = new GatewayAccountIdEntity();
String gatewayAccountId = randomUuid();
gatewayAccountIdEntity.setGatewayAccountId(gatewayAccountId);
Expand All @@ -151,6 +151,7 @@ public void shouldFind_existingServiceByGatewayAccountId() {
.withRedirectToServiceImmediatelyOnTerminalState(true)
.withCreatedDate(ZonedDateTime.parse("2020-01-31T12:30:00Z"))
.withWentLiveDate(ZonedDateTime.parse("2020-02-01T09:00:00Z"))
.withArchivedDate(ZonedDateTime.parse("2021-02-01T09:00:00Z"))
.withSector("police")
.build();
gatewayAccountIdEntity.setService(serviceEntity);
Expand All @@ -175,13 +176,14 @@ public void shouldFind_existingServiceByGatewayAccountId() {
assertThat(json.get("current_go_live_stage"), is(String.valueOf(serviceEntity.getCurrentGoLiveStage())));
assertThat(json.get("created_date"), is("2020-01-31T12:30:00.000Z"));
assertThat(json.get("went_live_date"), is("2020-02-01T09:00:00.000Z"));
assertThat(json.get("archived_date"), is("2021-02-01T09:00:00.000Z"));
assertThat(json.get("sector"), is("police"));
assertThat(json.get("internal"), is(false));
assertThat(json.get("archived"), is(false));
}

@Test
public void shouldReturn404_whenFindByGatewayAccountId_ifNotFound() {
void shouldReturn404_whenFindByGatewayAccountId_ifNotFound() {
String gatewayAccountId = randomUuid();
given(mockedServiceDao.findByGatewayAccountId(gatewayAccountId)).willReturn(Optional.empty());

Expand All @@ -192,15 +194,15 @@ public void shouldReturn404_whenFindByGatewayAccountId_ifNotFound() {
}

@Test
public void shouldReturn404_whenGetServiceById_ifNotFound() {
void shouldReturn404_whenGetServiceById_ifNotFound() {
String externalId = randomUuid();
given(mockedServiceDao.findByExternalId(externalId)).willReturn(Optional.empty());
Response response = RESOURCES.target(format("/v1/api/services/%s", externalId)).request().get();
assertThat(response.getStatus(), is(404));
}

@Test
public void shouldReturnBadRequest_whenGetByGatewayAccountId_isMissingQueryParam() {
void shouldReturnBadRequest_whenGetByGatewayAccountId_isMissingQueryParam() {
Response response = RESOURCES.target("/v1/api/services")
.queryParam("gatewayAccountId", "")
.request().get();
Expand Down

0 comments on commit 86dfc67

Please sign in to comment.