|
28 | 28 | import java.util.List; |
29 | 29 | import java.util.Map; |
30 | 30 | import java.util.Optional; |
31 | | -import org.acme.auth.AuthUtils; |
32 | | -import org.acme.model.domain.*; |
33 | | -import org.acme.model.dto.PublishScreenerRequest; |
34 | | -import org.acme.model.dto.SaveSchemaRequest; |
35 | 31 | import org.acme.model.dto.Screener.CreateScreenerRequest; |
36 | 32 | import org.acme.model.dto.Screener.EditScreenerRequest; |
37 | | -import org.acme.persistence.EligibilityCheckRepository; |
38 | | -import org.acme.persistence.PublishedScreenerRepository; |
39 | | -import org.acme.persistence.ScreenerRepository; |
40 | | -import org.acme.persistence.StorageService; |
41 | | -import org.acme.service.DmnService; |
42 | 33 |
|
43 | 34 | @Path("/api") |
44 | 35 | public class ScreenerResource { |
@@ -270,6 +261,40 @@ public Response deleteScreener( |
270 | 261 | } |
271 | 262 | } |
272 | 263 |
|
| 264 | + /** |
| 265 | + * Returns the list of unique input paths required by all checks in a screener. |
| 266 | + * This endpoint transforms inputDefinition schemas and extracts paths, |
| 267 | + * replacing the frontend's transformInputDefinitionSchema and extractJsonSchemaPaths logic. |
| 268 | + */ |
| 269 | + @GET |
| 270 | + @Path("/screener/{screenerId}/form-paths") |
| 271 | + public Response getScreenerFormPaths(@Context SecurityIdentity identity, |
| 272 | + @PathParam("screenerId") String screenerId) { |
| 273 | + String userId = AuthUtils.getUserId(identity); |
| 274 | + |
| 275 | + Optional<Screener> screenerOpt = screenerRepository.getWorkingScreener(screenerId); |
| 276 | + if (screenerOpt.isEmpty()) { |
| 277 | + throw new NotFoundException(); |
| 278 | + } |
| 279 | + Screener screener = screenerOpt.get(); |
| 280 | + |
| 281 | + if (!isUserAuthorizedToAccessScreenerByScreener(userId, screener)) { |
| 282 | + return Response.status(Response.Status.UNAUTHORIZED).build(); |
| 283 | + } |
| 284 | + |
| 285 | + try { |
| 286 | + List<Benefit> benefits = screenerRepository.getBenefitsInScreener(screener); |
| 287 | + List<String> paths = new ArrayList<>(inputSchemaService.extractAllInputPaths(benefits)); |
| 288 | + Collections.sort(paths); |
| 289 | + return Response.ok().entity(new FormPathsResponse(paths)).build(); |
| 290 | + } catch (Exception e) { |
| 291 | + Log.error(e); |
| 292 | + return Response.status(Response.Status.INTERNAL_SERVER_ERROR) |
| 293 | + .entity(Map.of("error", "Could not extract form paths")) |
| 294 | + .build(); |
| 295 | + } |
| 296 | + } |
| 297 | + |
273 | 298 | private boolean isUserAuthorizedToAccessScreener(String userId, String screenerId) { |
274 | 299 | Optional<Screener> screenerOptional = |
275 | 300 | screenerRepository.getWorkingScreenerMetaDataOnly(screenerId); |
|
0 commit comments