-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
549 send metadata from sample data to eq for routing piping and linki…
…ng (#19)
- Loading branch information
Showing
22 changed files
with
737 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/uk/gov/ons/ssdc/rhservice/messaging/CollectionExerciseUpdateReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package uk.gov.ons.ssdc.rhservice.messaging; | ||
|
||
import static uk.gov.ons.ssdc.rhservice.utils.JsonHelper.convertJsonBytesToEvent; | ||
|
||
import org.springframework.integration.annotation.MessageEndpoint; | ||
import org.springframework.integration.annotation.ServiceActivator; | ||
import org.springframework.messaging.Message; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import uk.gov.ons.ssdc.rhservice.model.dto.CollectionExerciseUpdateDTO; | ||
import uk.gov.ons.ssdc.rhservice.model.dto.EventDTO; | ||
import uk.gov.ons.ssdc.rhservice.model.repository.CollectionExerciseRepository; | ||
|
||
@MessageEndpoint | ||
public class CollectionExerciseUpdateReceiver { | ||
|
||
private final CollectionExerciseRepository collectionExerciseRepository; | ||
|
||
public CollectionExerciseUpdateReceiver( | ||
CollectionExerciseRepository collectionExerciseRepository) { | ||
this.collectionExerciseRepository = collectionExerciseRepository; | ||
} | ||
|
||
@Transactional | ||
@ServiceActivator(inputChannel = "collectionExerciseUpdateChannel", adviceChain = "retryAdvice") | ||
public void receiveMessage(Message<byte[]> message) { | ||
EventDTO event = convertJsonBytesToEvent(message.getPayload()); | ||
CollectionExerciseUpdateDTO collectionExerciseUpdateDTO = | ||
event.getPayload().getCollectionExerciseUpdate(); | ||
collectionExerciseRepository.writeCollectionExerciseUpdate(collectionExerciseUpdateDTO); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 4 additions & 6 deletions
10
src/main/java/uk/gov/ons/ssdc/rhservice/model/dto/CaseUpdateDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
package uk.gov.ons.ssdc.rhservice.model.dto; | ||
|
||
import java.util.Date; | ||
import java.util.Map; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CaseUpdateDTO { | ||
private String caseId; | ||
private String surveyId; | ||
private String collectionExerciseId; | ||
private boolean invalid; | ||
private String refusalReceived; | ||
private Map<String, String> sample; | ||
private Map<String, String> sampleSensitive; | ||
private String caseRef; | ||
private Date createdAt; | ||
private Date lastUpdatedAt; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/uk/gov/ons/ssdc/rhservice/model/dto/CollectionExerciseUpdateDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package uk.gov.ons.ssdc.rhservice.model.dto; | ||
|
||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CollectionExerciseUpdateDTO { | ||
private String collectionExerciseId; | ||
private List<CollectionInstrumentSelectionRule> collectionInstrumentRules; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/uk/gov/ons/ssdc/rhservice/model/dto/CollectionInstrumentSelectionRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package uk.gov.ons.ssdc.rhservice.model.dto; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CollectionInstrumentSelectionRule implements Serializable { | ||
private String collectionInstrumentUrl; | ||
private List<EqLaunchSettings> eqLaunchSettings; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/uk/gov/ons/ssdc/rhservice/model/dto/EqLaunchSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package uk.gov.ons.ssdc.rhservice.model.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class EqLaunchSettings { | ||
private String sampleField; | ||
private String launchDataFieldName; | ||
private boolean mandatory; | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/uk/gov/ons/ssdc/rhservice/model/dto/EventDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/uk/gov/ons/ssdc/rhservice/model/repository/CollectionExerciseRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package uk.gov.ons.ssdc.rhservice.model.repository; | ||
|
||
import java.util.Optional; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import uk.gov.ons.ssdc.rhservice.model.dto.CollectionExerciseUpdateDTO; | ||
import uk.gov.ons.ssdc.rhservice.service.RHFirestoreClient; | ||
|
||
@Service | ||
public class CollectionExerciseRepository { | ||
private final RHFirestoreClient rhFirestoreClient; | ||
|
||
@Value("${cloud-storage.collection-exercise-schema-name}") | ||
private String collectionExerciseSchemaName; | ||
|
||
public CollectionExerciseRepository(RHFirestoreClient rhFirestoreClient) { | ||
this.rhFirestoreClient = rhFirestoreClient; | ||
} | ||
|
||
public void writeCollectionExerciseUpdate( | ||
final CollectionExerciseUpdateDTO collectionExerciseUpdateDTO) { | ||
String id = collectionExerciseUpdateDTO.getCollectionExerciseId(); | ||
rhFirestoreClient.storeObject(collectionExerciseSchemaName, id, collectionExerciseUpdateDTO); | ||
} | ||
|
||
public Optional<CollectionExerciseUpdateDTO> readCollectionExerciseUpdate( | ||
String collectionExerciseId) { | ||
return rhFirestoreClient.retrieveObject( | ||
CollectionExerciseUpdateDTO.class, collectionExerciseSchemaName, collectionExerciseId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/uk/gov/ons/ssdc/rhservice/service/LaunchDataFieldSetter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package uk.gov.ons.ssdc.rhservice.service; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.springframework.stereotype.Component; | ||
import uk.gov.ons.ssdc.rhservice.model.dto.CaseUpdateDTO; | ||
import uk.gov.ons.ssdc.rhservice.model.dto.EqLaunchSettings; | ||
import uk.gov.ons.ssdc.rhservice.model.dto.UacUpdateDTO; | ||
import uk.gov.ons.ssdc.rhservice.model.repository.CaseRepository; | ||
import uk.gov.ons.ssdc.rhservice.model.repository.CollectionExerciseRepository; | ||
|
||
@Component | ||
public class LaunchDataFieldSetter { | ||
private final CaseRepository caseRepository; | ||
private final CollectionExerciseRepository collectionExerciseRepository; | ||
|
||
public LaunchDataFieldSetter( | ||
CaseRepository caseRepository, CollectionExerciseRepository collectionExerciseRepository) { | ||
this.caseRepository = caseRepository; | ||
this.collectionExerciseRepository = collectionExerciseRepository; | ||
} | ||
|
||
public void stampLaunchDataFieldsOnUAC(UacUpdateDTO uacUpdateDTO) { | ||
List<EqLaunchSettings> eqLaunchDataSettings = | ||
getEqLaunchSettingsFromCollectionExercise( | ||
uacUpdateDTO.getCollectionExerciseId(), uacUpdateDTO.getCollectionInstrumentUrl()); | ||
|
||
if (eqLaunchDataSettings == null || eqLaunchDataSettings.isEmpty()) { | ||
return; | ||
} | ||
|
||
CaseUpdateDTO caze = getCase(uacUpdateDTO.getCaseId()); | ||
|
||
Map<String, String> launchData = new HashMap<>(); | ||
for (EqLaunchSettings eqLaunchSettings : eqLaunchDataSettings) { | ||
|
||
if (caze.getSample().containsKey(eqLaunchSettings.getSampleField())) { | ||
launchData.put( | ||
eqLaunchSettings.getLaunchDataFieldName(), | ||
caze.getSample().get(eqLaunchSettings.getSampleField())); | ||
} else if (eqLaunchSettings.isMandatory()) { | ||
throw new RuntimeException( | ||
"Expected field: " | ||
+ eqLaunchSettings.getSampleField() | ||
+ " missing on case id: " | ||
+ caze.getCaseId()); | ||
} | ||
} | ||
|
||
uacUpdateDTO.setLaunchData(launchData); | ||
} | ||
|
||
private List<EqLaunchSettings> getEqLaunchSettingsFromCollectionExercise( | ||
String collectionExerciseId, String collectionInstrumentUrl) { | ||
return collectionExerciseRepository.readCollectionExerciseUpdate(collectionExerciseId) | ||
.orElseThrow( | ||
() -> new RuntimeException("Collection Exercise not found: " + collectionExerciseId)) | ||
.getCollectionInstrumentRules().stream() | ||
.filter( | ||
collexInstrumentRule -> | ||
collexInstrumentRule.getCollectionInstrumentUrl().equals(collectionInstrumentUrl)) | ||
.findFirst() | ||
.orElseThrow( | ||
() -> | ||
new RuntimeException( | ||
"Collection Instrument Url not matched: " + collectionInstrumentUrl)) | ||
.getEqLaunchSettings(); | ||
} | ||
|
||
private CaseUpdateDTO getCase(String caseId) { | ||
return caseRepository | ||
.readCaseUpdate(caseId) | ||
.orElseThrow(() -> new RuntimeException("Not Found case ID: " + caseId)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/test/java/uk/gov/ons/ssdc/rhservice/exceptions/CollectionExerciseNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package uk.gov.ons.ssdc.rhservice.exceptions; | ||
|
||
public class CollectionExerciseNotFoundException extends Exception { | ||
public CollectionExerciseNotFoundException(String message) { | ||
super(message); | ||
} | ||
} |
Oops, something went wrong.