Skip to content

Commit 2079c7e

Browse files
Story(CCLS-2206) Enable Update OPA Assessment endpoint
1 parent 368ec83 commit 2079c7e

File tree

11 files changed

+616
-37
lines changed

11 files changed

+616
-37
lines changed

assessment-api/open-api-specification.yml

+41-10
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,28 @@ paths:
4141
description: 'Not found'
4242
'500':
4343
description: 'Internal server error'
44+
put:
45+
tags:
46+
- assessments
47+
summary: 'update an existing assessment'
48+
operationId: 'updateAssessment'
49+
parameters:
50+
- $ref: '#/components/parameters/requiredUserLoginId'
51+
requestBody:
52+
description: update an existing assessment
53+
content:
54+
application/json:
55+
schema:
56+
$ref: '#/components/schemas/assessmentDetail'
57+
responses:
58+
'204':
59+
description: 'Successful update'
60+
'400':
61+
description: 'Bad request'
62+
'401':
63+
description: 'Unauthorized'
64+
'500':
65+
description: 'Internal server error'
4466
delete:
4567
tags:
4668
- assessments
@@ -109,10 +131,10 @@ paths:
109131
patch:
110132
tags:
111133
- assessments
112-
summary: 'update assessment'
113-
operationId: 'updateAssessment'
134+
summary: 'patch assessment'
135+
operationId: 'patchAssessment'
114136
requestBody:
115-
description: update an assessment
137+
description: patch an assessment
116138
content:
117139
application/json:
118140
schema:
@@ -204,7 +226,8 @@ components:
204226
type: 'object'
205227
properties:
206228
id:
207-
type: 'string'
229+
type: 'integer'
230+
format: 'int64'
208231
provider_id:
209232
type: 'string'
210233
case_reference_number:
@@ -257,7 +280,8 @@ components:
257280
type: object
258281
properties:
259282
id:
260-
type: string
283+
type: 'integer'
284+
format: 'int64'
261285
name:
262286
type: string
263287
entities:
@@ -272,7 +296,8 @@ components:
272296
type: object
273297
properties:
274298
id:
275-
type: string
299+
type: 'integer'
300+
format: 'int64'
276301
name:
277302
type: string
278303
attributes:
@@ -295,22 +320,27 @@ components:
295320
type: object
296321
properties:
297322
id:
298-
type: string
323+
type: 'integer'
324+
format: 'int64'
299325
name:
300326
type: string
301327
type:
302328
type: string
303329
value:
304330
type: string
331+
prepopulated:
332+
type: boolean
333+
asked:
334+
type: boolean
305335
required:
306336
- id
307337
- attributeId
308-
- value
309338
assessmentRelationshipDetail:
310339
type: object
311340
properties:
312341
id:
313-
type: string
342+
type: 'integer'
343+
format: 'int64'
314344
name:
315345
type: string
316346
prepopulated:
@@ -324,7 +354,8 @@ components:
324354
type: object
325355
properties:
326356
id:
327-
type: string
357+
type: 'integer'
358+
format: 'int64'
328359
target_entity_id:
329360
type: string
330361

assessment-service/src/integrationTest/java/uk/gov/laa/ccms/caab/assessment/controller/BaseAssessmentControllerIntegrationTest.java

+153-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
import static org.junit.jupiter.api.Assertions.assertNotNull;
66
import static org.junit.jupiter.api.Assertions.assertNull;
77
import static org.junit.jupiter.api.Assertions.assertTrue;
8-
import static org.junit.jupiter.api.Assertions.assertFalse;
98

9+
import jakarta.transaction.Transactional;
1010
import java.util.List;
1111
import java.util.stream.Stream;
12+
import javax.management.relation.Relation;
1213
import org.junit.jupiter.api.Test;
1314
import org.junit.jupiter.params.ParameterizedTest;
1415
import org.junit.jupiter.params.provider.Arguments;
@@ -17,9 +18,13 @@
1718
import org.springframework.http.HttpStatus;
1819
import org.springframework.http.ResponseEntity;
1920
import org.springframework.test.context.jdbc.Sql;
21+
import uk.gov.laa.ccms.caab.assessment.model.AssessmentAttributeDetail;
2022
import uk.gov.laa.ccms.caab.assessment.model.AssessmentDetail;
2123
import uk.gov.laa.ccms.caab.assessment.model.AssessmentDetails;
24+
import uk.gov.laa.ccms.caab.assessment.model.AssessmentEntityDetail;
2225
import uk.gov.laa.ccms.caab.assessment.model.AssessmentEntityTypeDetail;
26+
import uk.gov.laa.ccms.caab.assessment.model.AssessmentRelationshipDetail;
27+
import uk.gov.laa.ccms.caab.assessment.model.AssessmentRelationshipTargetDetail;
2328
import uk.gov.laa.ccms.caab.assessment.model.PatchAssessmentDetail;
2429

2530
public abstract class BaseAssessmentControllerIntegrationTest {
@@ -118,6 +123,7 @@ public void testGetAssessments_expect200_empty() {
118123

119124
@Test
120125
@Sql(scripts = "/sql/assessments_insert.sql")
126+
@Transactional
121127
public void testPatchAssessments_expect200_empty() {
122128

123129
final Long id = 26L;
@@ -129,7 +135,7 @@ public void testPatchAssessments_expect200_empty() {
129135
.status("status2");
130136

131137
ResponseEntity<Void> response =
132-
assessmentController.updateAssessment(26L, "testUser", patch);
138+
assessmentController.patchAssessment(26L, "testUser", patch);
133139

134140
ResponseEntity<AssessmentDetail> afterPatchResponse = assessmentController.getAssessment(id);
135141

@@ -167,6 +173,151 @@ public void testDeleteCheckpoint_returns204() {
167173
assertNull(assessmentResponse.getBody().getCheckpoint());
168174
}
169175

176+
private static Stream<Arguments> updateAssessmentArguments_base() {
177+
return Stream.of(
178+
Arguments.of(
179+
new AssessmentDetail().id(26L)
180+
.name("new_assessment1")
181+
.status("new_status1")
182+
.providerId("new_owner1")
183+
.caseReferenceNumber("987654321")
184+
)
185+
);
186+
}
187+
188+
@Test
189+
@Sql(scripts = "/sql/assessments_insert.sql")
190+
@Transactional
191+
public void testUpdateAssessment() {
192+
final String loginId = "testUser";
193+
194+
AssessmentDetail expected = buildAssessmentDetail();
195+
196+
ResponseEntity<Void> response = assessmentController.updateAssessment(loginId, expected);
197+
assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
198+
199+
ResponseEntity<AssessmentDetail> updatedResponse = assessmentController.getAssessment(expected.getId());
200+
assertEquals(HttpStatus.OK, updatedResponse.getStatusCode());
201+
202+
AssessmentDetail actual = updatedResponse.getBody();
203+
assertEquals(expected.getName(), actual.getName());
204+
assertEquals(expected.getStatus(), actual.getStatus());
205+
assertEquals(expected.getProviderId(), actual.getProviderId());
206+
assertEquals(expected.getCaseReferenceNumber(), actual.getCaseReferenceNumber());
207+
208+
assertEquals(expected.getEntityTypes().size(), actual.getEntityTypes().size());
209+
for (AssessmentEntityTypeDetail expectedEntityType : expected.getEntityTypes()) {
210+
AssessmentEntityTypeDetail actualEntityType = actual.getEntityTypes().stream()
211+
.filter(a -> a.getId().equals(expectedEntityType.getId()))
212+
.findFirst()
213+
.orElseThrow(() -> new AssertionError("EntityType not found"));
214+
215+
assertEquals(expectedEntityType.getName(), actualEntityType.getName());
216+
assertEquals(expectedEntityType.getId(), actualEntityType.getId());
217+
assertEquals(expectedEntityType.getEntities().size(), actualEntityType.getEntities().size());
218+
219+
for (AssessmentEntityDetail expectedEntity : expectedEntityType.getEntities()) {
220+
AssessmentEntityDetail actualEntity = actualEntityType.getEntities().stream()
221+
.filter(a -> a.getId().equals(expectedEntity.getId()))
222+
.findFirst()
223+
.orElseThrow(() -> new AssertionError("Entity not found"));
224+
225+
assertEquals(expectedEntity.getName(), actualEntity.getName());
226+
assertEquals(expectedEntity.getId(), actualEntity.getId());
227+
assertEquals(expectedEntity.getAttributes().size(), actualEntity.getAttributes().size());
228+
229+
for (AssessmentAttributeDetail expectedAttribute : expectedEntity.getAttributes()) {
230+
AssessmentAttributeDetail actualAttribute = actualEntity.getAttributes().stream()
231+
.filter(a -> a.getId().equals(expectedAttribute.getId()))
232+
.findFirst()
233+
.orElseThrow(() -> new AssertionError("Attribute not found"));
234+
235+
assertEquals(expectedAttribute.getName(), actualAttribute.getName());
236+
assertEquals(expectedAttribute.getId(), actualAttribute.getId());
237+
assertEquals(expectedAttribute.getType(), actualAttribute.getType());
238+
assertEquals(expectedAttribute.getValue(), actualAttribute.getValue());
239+
assertEquals(expectedAttribute.getPrepopulated(), actualAttribute.getPrepopulated());
240+
assertEquals(expectedAttribute.getAsked(), actualAttribute.getAsked());
241+
}
242+
243+
assertEquals(expectedEntity.getRelations().size(), actualEntity.getRelations().size());
244+
245+
for (AssessmentRelationshipDetail expectedRelation : expectedEntity.getRelations()) {
246+
AssessmentRelationshipDetail actualRelation = actualEntity.getRelations().stream()
247+
.filter(a -> a.getId().equals(expectedRelation.getId()))
248+
.findFirst()
249+
.orElseThrow(() -> new AssertionError("Relation not found"));
250+
251+
assertEquals(expectedRelation.getName(), actualRelation.getName());
252+
assertEquals(expectedRelation.getId(), actualRelation.getId());
253+
assertEquals(expectedRelation.getRelationshipTargets().size(), actualRelation.getRelationshipTargets().size());
254+
255+
for (AssessmentRelationshipTargetDetail expectedTarget : expectedRelation.getRelationshipTargets()) {
256+
AssessmentRelationshipTargetDetail actualTarget = actualRelation.getRelationshipTargets().stream()
257+
.filter(a -> a.getId().equals(expectedTarget.getId()))
258+
.findFirst()
259+
.orElseThrow(() -> new AssertionError("RelationshipTarget not found"));
260+
261+
assertEquals(expectedTarget.getId(), actualTarget.getId());
262+
assertEquals(expectedTarget.getTargetEntityId(), actualTarget.getTargetEntityId());
263+
}
264+
}
265+
}
266+
}
267+
268+
269+
}
270+
271+
public static AssessmentDetail buildAssessmentDetail() {
272+
return new AssessmentDetail()
273+
.id(26L)
274+
.name("new_assessment1")
275+
.status("new_status1")
276+
.providerId("new_owner1")
277+
.caseReferenceNumber("987654321")
278+
.addEntityTypesItem(buildEntityType());
279+
}
280+
281+
public static AssessmentEntityTypeDetail buildEntityType() {
282+
return new AssessmentEntityTypeDetail()
283+
.id(27L)
284+
.name("new_entity_type1")
285+
.addEntitiesItem(buildEntity());
286+
}
287+
288+
public static AssessmentEntityDetail buildEntity() {
289+
return new AssessmentEntityDetail()
290+
.id(28L)
291+
.name("new_entity1")
292+
.prepopulated(true)
293+
.addAttributesItem(buildAttribute())
294+
.addRelationsItem(buildRelation());
295+
}
296+
297+
public static AssessmentAttributeDetail buildAttribute() {
298+
return new AssessmentAttributeDetail()
299+
.id(29L)
300+
.name("new_attribute1")
301+
.type("new_type1")
302+
.value("new_value1")
303+
.prepopulated(true)
304+
.asked(true);
305+
}
306+
307+
public static AssessmentRelationshipDetail buildRelation() {
308+
return new AssessmentRelationshipDetail()
309+
.id(30L)
310+
.name("new_relation1")
311+
.prepopulated(true)
312+
.addRelationshipTargetsItem(buildRelationTarget());
313+
}
314+
315+
public static AssessmentRelationshipTargetDetail buildRelationTarget() {
316+
return new AssessmentRelationshipTargetDetail()
317+
.id(31L)
318+
.targetEntityId("new_entity1");
319+
}
320+
170321

171322

172323

assessment-service/src/integrationTest/resources/sql/assessments_insert.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
INSERT INTO XXCCMS_OPA_SESSION (ID, OWNER_ID, TARGET_ID, ASSESSMENT, STATUS, CREATED_BY, MODIFIED_BY)
2-
VALUES (26, 'owner1', '1234567890', 'assessment1', 'status1', 'creator1', 'modifier1');
1+
INSERT INTO XXCCMS_OPA_SESSION (ID, OWNER_ID, TARGET_ID, ASSESSMENT, STATUS, CREATED, CREATED_BY, MODIFIED, MODIFIED_BY)
2+
VALUES(26, 'owner1', '1234567890', 'assessment1', 'status1', TIMESTAMP '2024-05-13 13:17:06.218000', 'creator1', TIMESTAMP '2024-05-13 13:17:06.218000', 'modifier1');
33

44
-- Insert into XXCCMS_OPA_LISTENTITY
55
INSERT INTO XXCCMS_OPA_LISTENTITY (ID, FK_OPA_SESSION, ENTITY_TYPE)

assessment-service/src/main/java/uk/gov/laa/ccms/caab/assessment/audit/AuditorAwareImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class AuditorAwareImpl implements AuditorAware<String> {
1313
public static final ThreadLocal<String> currentUserHolder = new ThreadLocal<String>();
1414

1515
@Override
16-
public Optional<String> getCurrentAuditor() {
16+
public Optional getCurrentAuditor() {
1717
return Optional.of(currentUserHolder.get());
1818
}
1919

assessment-service/src/main/java/uk/gov/laa/ccms/caab/assessment/controller/AssessmentController.java

+21-4
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,37 @@ public ResponseEntity<Void> deleteAssessments(
9797
}
9898

9999
/**
100-
* Updates an assessment with the provided details.
100+
* Patches an assessment with the provided details.
101101
*
102102
* @param assessmentId The ID of the assessment to update.
103103
* @param caabUserLoginId The CAAB user login ID performing the update.
104-
* @param patch The details to update the assessment with.
104+
* @param patch The patch to update the assessment with.
105105
* @return ResponseEntity with the status of the update operation.
106106
*/
107107
@Override
108-
public ResponseEntity<Void> updateAssessment(
108+
public ResponseEntity<Void> patchAssessment(
109109
final Long assessmentId,
110110
final String caabUserLoginId,
111111
final PatchAssessmentDetail patch) {
112112

113-
assessmentService.updateAssessment(assessmentId, patch);
113+
assessmentService.patchAssessment(assessmentId, patch);
114+
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
115+
}
116+
117+
/**
118+
* updates an assessment.
119+
*
120+
* @param caabUserLoginId The CAAB user login ID performing the update.
121+
* @param assessment The details to update the assessment with.
122+
* @return ResponseEntity with the status of the update operation.
123+
*/
124+
@Override
125+
public ResponseEntity<Void> updateAssessment(
126+
final String caabUserLoginId,
127+
final AssessmentDetail assessment) {
128+
129+
assessmentService.updateAssessment(assessment);
114130
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
115131
}
132+
116133
}

assessment-service/src/main/java/uk/gov/laa/ccms/caab/assessment/entity/OpaSession.java

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import jakarta.persistence.Column;
55
import jakarta.persistence.Embedded;
66
import jakarta.persistence.Entity;
7+
import jakarta.persistence.EntityListeners;
78
import jakarta.persistence.FetchType;
89
import jakarta.persistence.GeneratedValue;
910
import jakarta.persistence.Id;
@@ -13,17 +14,20 @@
1314
import jakarta.persistence.Table;
1415
import java.util.List;
1516
import lombok.Data;
17+
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
1618

1719
/**
1820
* Represents an Oracle Intelligence Advisor session.
1921
*/
2022
@Entity
2123
@Table(name = "XXCCMS_OPA_SESSION")
24+
2225
@SequenceGenerator(
2326
allocationSize = 1,
2427
name = "XXCCMS_OPASESSION_GENERATED_ID_S",
2528
sequenceName = "XXCCMS_OPA_GENERATED_ID_S")
2629
@Data
30+
@EntityListeners(AuditingEntityListener.class)
2731
public class OpaSession {
2832

2933
/**

0 commit comments

Comments
 (0)