Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.5.2 [TODO]
### Fixed
- Prevent missing contextual external or previous files from clearing existing contextual data.

## 2.5.0 [2026-04-16]
### Added
- New schedule endpoints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@ public ContextualExternalVariableJsonService(ContextualExternalVariablePersistan
public boolean readContextualExternalFile(String collectionInstrumentId, String filePath) throws GenesisException {
try(FileInputStream inputStream = new FileInputStream(filePath)){
JsonFactory jsonFactory = new JsonFactory();
moveCollectionToBackup(collectionInstrumentId);
try(JsonParser jsonParser = jsonFactory.createParser(inputStream)){
List<ContextualExternalVariableModel> toSave = new ArrayList<>();
goToContextualExternalToken(jsonParser);
long savedCount = 0;
Set<String> savedInterrogationIds = new HashSet<>();
if (!goToContextualExternalToken(jsonParser)) {
log.warn("No contextualExternal part found in file {}", filePath);
return false;
}
if(jsonParser.nextToken() == null){ //skip field name, stop if end of file
log.warn("Reached end of file, found no contextualExternal part.");
return false;
}
moveCollectionToBackup(collectionInstrumentId);
List<ContextualExternalVariableModel> toSave = new ArrayList<>();
long savedCount = 0;
Set<String> savedInterrogationIds = new HashSet<>();
jsonParser.nextToken(); //skip [
while (jsonParser.currentToken() != JsonToken.END_ARRAY) {
ContextualExternalVariableModel contextualExternalVariableModel = readNextContextualExternal(
Expand Down Expand Up @@ -84,19 +87,14 @@ public ContextualExternalVariableModel findByCollectionInstrumentIdAndInterrogat
return contextualExternalVariablePersistancePort.findByCollectionInstrumentIdAndInterrogationId(collectionInstrumentId, interrogationId);
}

private static void goToContextualExternalToken(JsonParser jsonParser) throws IOException{
boolean isTokenFound = false;
while (!isTokenFound){
jsonParser.nextToken();
if(jsonParser.currentToken() == null){
return;
}
if(jsonParser.currentToken().equals(JsonToken.FIELD_NAME)
&& jsonParser.currentName() != null
&& jsonParser.currentName().equals("editedExternal")) {
isTokenFound = true;
private static boolean goToContextualExternalToken(JsonParser jsonParser) throws IOException {
while (jsonParser.nextToken() != null) {
if (jsonParser.currentToken() == JsonToken.FIELD_NAME
&& "editedExternal".equals(jsonParser.currentName())) {
return true;
}
}
return false;
}

private void moveCollectionToBackup(String collectionInstrumentId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,22 @@ public boolean readContextualPreviousFile(String collectionInstrumentId,
String filePath) throws GenesisException {
try(FileInputStream inputStream = new FileInputStream(filePath)){
checkSourceStateLength(sourceState);
moveCollectionToBackup(collectionInstrumentId);

JsonFactory jsonFactory = new JsonFactory();
try (JsonParser jsonParser = jsonFactory.createParser(inputStream)) {
List<ContextualPreviousVariableModel> toSave = new ArrayList<>();
goToEditedPreviousToken(jsonParser);
long savedCount = 0;
Set<String> savedInterrogationIds = new HashSet<>();
if (!goToEditedPreviousToken(jsonParser)) {
log.warn("No EditedPrevious part found in file {}", filePath);
return false;
}
if (jsonParser.nextToken() == null) { //skip field name, stop if end of file
log.warn("Reached end of file, found no EditedPrevious part.");
return false;
}
moveCollectionToBackup(collectionInstrumentId);
List<ContextualPreviousVariableModel> toSave = new ArrayList<>();
long savedCount = 0;
Set<String> savedInterrogationIds = new HashSet<>();

jsonParser.nextToken(); //skip [
while (jsonParser.currentToken() != JsonToken.END_ARRAY) {
ContextualPreviousVariableModel contextualPreviousVariableModel = readNextContextualPrevious(
Expand Down Expand Up @@ -109,19 +113,14 @@ private static void checkSourceStateLength(String sourceState) throws GenesisExc
}
}

private static void goToEditedPreviousToken(JsonParser jsonParser) throws IOException{
boolean isTokenFound = false;
while (!isTokenFound){
jsonParser.nextToken();
if(jsonParser.currentToken() == null){
return;
}
if(jsonParser.currentToken().equals(JsonToken.FIELD_NAME)
&& jsonParser.currentName() != null
&& jsonParser.currentName().equals("editedPrevious")) {
isTokenFound = true;
private boolean goToEditedPreviousToken(JsonParser jsonParser) throws IOException {
while (jsonParser.nextToken() != null) {
if (jsonParser.currentToken() == JsonToken.FIELD_NAME
&& "editedPrevious".equals(jsonParser.getCurrentName())) {
return true;
}
}
return false;
}

private ContextualPreviousVariableModel readNextContextualPrevious(JsonParser jsonParser,
Expand Down
Loading