|
18 | 18 |
|
19 | 19 | import java.time.LocalDateTime; |
20 | 20 | import java.util.ArrayList; |
21 | | -import java.util.Arrays; |
22 | 21 | import java.util.HashSet; |
23 | 22 | import java.util.List; |
24 | 23 | import java.util.Set; |
@@ -149,26 +148,38 @@ public DataProcessingContextModel getContext(String interrogationId) throws Gene |
149 | 148 | throw new GenesisException(404,"No interrogation in database with id %s".formatted(interrogationId)); |
150 | 149 | } |
151 | 150 | Set<String> partitionIds = new HashSet<>(); |
| 151 | + Set<String> campaignIds = new HashSet<>(); |
| 152 | + Set<String> collectionInstrumentIds = new HashSet<>(); |
| 153 | + |
152 | 154 | for (SurveyUnitModel su : surveyUnitModels){ |
153 | 155 | if (su.getCampaignId()!=null){ |
154 | | - partitionIds.add(su.getCampaignId()); |
155 | | - break; |
| 156 | + campaignIds.add(su.getCampaignId()); |
| 157 | + } |
| 158 | + if (su.getCollectionInstrumentId()!=null){ |
| 159 | + collectionInstrumentIds.add(su.getCampaignId()); |
156 | 160 | } |
157 | | - partitionIds.add(su.getCollectionInstrumentId()); |
158 | 161 | } |
159 | | - if(partitionIds.isEmpty()){ |
| 162 | + if(campaignIds.size() > 1 || collectionInstrumentIds.size()>1){ |
| 163 | + throw new GenesisException(500,"Multiple partitions for interrogation %s".formatted(interrogationId)); |
| 164 | + } |
| 165 | + |
| 166 | + if(campaignIds.isEmpty() && collectionInstrumentIds.isEmpty()){ |
160 | 167 | return null; |
161 | 168 | } |
162 | | - if(partitionIds.size() > 1){ |
163 | | - throw new GenesisException(500,"Multiple partitions for interrogation %s %n%s".formatted( |
164 | | - interrogationId, |
165 | | - Arrays.toString(partitionIds.toArray()) |
166 | | - )); |
| 169 | + |
| 170 | + DataProcessingContextModel contextModel = new DataProcessingContextModel(); |
| 171 | + if (!collectionInstrumentIds.isEmpty()){ |
| 172 | + contextModel = DataProcessingContextMapper.INSTANCE.documentToModel( |
| 173 | + dataProcessingContextPersistancePort.findByPartitionId(collectionInstrumentIds.stream().toList().getFirst()) |
| 174 | + ); |
167 | 175 | } |
168 | 176 |
|
169 | | - return DataProcessingContextMapper.INSTANCE.documentToModel( |
170 | | - dataProcessingContextPersistancePort.findByPartitionId(partitionIds.stream().toList().getFirst()) |
171 | | - ); |
| 177 | + if (contextModel.getId()==null && !campaignIds.isEmpty()) { |
| 178 | + contextModel = DataProcessingContextMapper.INSTANCE.documentToModel( |
| 179 | + dataProcessingContextPersistancePort.findByPartitionId(campaignIds.stream().toList().getFirst())); |
| 180 | + } |
| 181 | + |
| 182 | + return contextModel; |
172 | 183 | } |
173 | 184 |
|
174 | 185 | @Override |
|
0 commit comments