@Test void testValidateNegotiatorExportAllCollectionsAreDisabled() { NegotiatorRequest request = NegotiatorRequest.create( "http: "molgenis_id_1", "*=q=MOLGENIS", "a nice molgenis query", "Sjfg03Msmdp92Md82103FNskas9H735F"); Entity entityDisabled = mock(Entity.class); String entityDisabledLabel = "Entity Disabled"; when(entityDisabled.getLabelValue()).thenReturn(entityDisabledLabel); when(entityDisabled.get("enabled")).thenReturn(false); when(molgenisQuery.findAll()).thenReturn(Stream.of(entityDisabled)); when(jsMagmaScriptEvaluator.eval("$(enabled).value()", entityDisabled)).thenReturn(FALSE); ExportValidationResponse actual = negotiatorController.validateNegotiatorExport(request); List<String> disabledCollections = Collections.singletonList(entityDisabledLabel); ExportValidationResponse expected = ExportValidationResponse.create( false, "Please make sure your selection contains at least 1 row that supports the negotiator.", emptyList(), disabledCollections); assertEquals(expected, actual); }
@PostMapping("/validate") @ResponseBody public ExportValidationResponse validateNegotiatorExport(@RequestBody NegotiatorRequest request) { if (request.getBiobankRsql() != null || request.getBiobankId() != null) { throw new IllegalArgumentException("Cannot verify requests with biobank filters."); } boolean isValidRequest = true; String message = ""; List<String> enabledCollectionsLabels; List<String> disabledCollectionLabels; Optional<NegotiatorEntityConfig> entityConfigOptional = getNegotiatorEntityConfig(request.getEntityId()); if (entityConfigOptional.isPresent()) { NegotiatorEntityConfig entityConfig = entityConfigOptional.get(); LOG.info("Validating negotiator request\n\n{}", request); List<Entity> collectionEntities = getCollectionEntities(request); List<Entity> disabledCollections = getDisabledCollections(collectionEntities, entityConfig); Function<Entity, String> getLabel = entity -> entity.getLabelValue().toString(); disabledCollectionLabels = disabledCollections.stream().map(getLabel).collect(toList()); enabledCollectionsLabels = collectionEntities.stream() .filter(e -> !disabledCollections.contains(e)) .map(getLabel) .collect(toList()); if (!disabledCollections.isEmpty()) { message = messageSource.getMessage( "dataexplorer_directory_disabled", new Object[] {disabledCollections.size(), collectionEntities.size()}, getLocale()); } if (collectionEntities.isEmpty() || (collectionEntities.size() == disabledCollections.size())) { isValidRequest = false; message = messageSource.getMessage( "dataexplorer_directory_no_rows", new Object[] {}, getLocale()); } } else { throw new MolgenisDataException( messageSource.getMessage( "dataexplorer_directory_no_config", new Object[] {}, getLocale())); } return ExportValidationResponse.create( isValidRequest, message, enabledCollectionsLabels, disabledCollectionLabels); }
NegotiatorController extends PluginController { @PostMapping("/validate") @ResponseBody public ExportValidationResponse validateNegotiatorExport(@RequestBody NegotiatorRequest request) { if (request.getBiobankRsql() != null || request.getBiobankId() != null) { throw new IllegalArgumentException("Cannot verify requests with biobank filters."); } boolean isValidRequest = true; String message = ""; List<String> enabledCollectionsLabels; List<String> disabledCollectionLabels; Optional<NegotiatorEntityConfig> entityConfigOptional = getNegotiatorEntityConfig(request.getEntityId()); if (entityConfigOptional.isPresent()) { NegotiatorEntityConfig entityConfig = entityConfigOptional.get(); LOG.info("Validating negotiator request\n\n{}", request); List<Entity> collectionEntities = getCollectionEntities(request); List<Entity> disabledCollections = getDisabledCollections(collectionEntities, entityConfig); Function<Entity, String> getLabel = entity -> entity.getLabelValue().toString(); disabledCollectionLabels = disabledCollections.stream().map(getLabel).collect(toList()); enabledCollectionsLabels = collectionEntities.stream() .filter(e -> !disabledCollections.contains(e)) .map(getLabel) .collect(toList()); if (!disabledCollections.isEmpty()) { message = messageSource.getMessage( "dataexplorer_directory_disabled", new Object[] {disabledCollections.size(), collectionEntities.size()}, getLocale()); } if (collectionEntities.isEmpty() || (collectionEntities.size() == disabledCollections.size())) { isValidRequest = false; message = messageSource.getMessage( "dataexplorer_directory_no_rows", new Object[] {}, getLocale()); } } else { throw new MolgenisDataException( messageSource.getMessage( "dataexplorer_directory_no_config", new Object[] {}, getLocale())); } return ExportValidationResponse.create( isValidRequest, message, enabledCollectionsLabels, disabledCollectionLabels); } }
NegotiatorController extends PluginController { @PostMapping("/validate") @ResponseBody public ExportValidationResponse validateNegotiatorExport(@RequestBody NegotiatorRequest request) { if (request.getBiobankRsql() != null || request.getBiobankId() != null) { throw new IllegalArgumentException("Cannot verify requests with biobank filters."); } boolean isValidRequest = true; String message = ""; List<String> enabledCollectionsLabels; List<String> disabledCollectionLabels; Optional<NegotiatorEntityConfig> entityConfigOptional = getNegotiatorEntityConfig(request.getEntityId()); if (entityConfigOptional.isPresent()) { NegotiatorEntityConfig entityConfig = entityConfigOptional.get(); LOG.info("Validating negotiator request\n\n{}", request); List<Entity> collectionEntities = getCollectionEntities(request); List<Entity> disabledCollections = getDisabledCollections(collectionEntities, entityConfig); Function<Entity, String> getLabel = entity -> entity.getLabelValue().toString(); disabledCollectionLabels = disabledCollections.stream().map(getLabel).collect(toList()); enabledCollectionsLabels = collectionEntities.stream() .filter(e -> !disabledCollections.contains(e)) .map(getLabel) .collect(toList()); if (!disabledCollections.isEmpty()) { message = messageSource.getMessage( "dataexplorer_directory_disabled", new Object[] {disabledCollections.size(), collectionEntities.size()}, getLocale()); } if (collectionEntities.isEmpty() || (collectionEntities.size() == disabledCollections.size())) { isValidRequest = false; message = messageSource.getMessage( "dataexplorer_directory_no_rows", new Object[] {}, getLocale()); } } else { throw new MolgenisDataException( messageSource.getMessage( "dataexplorer_directory_no_config", new Object[] {}, getLocale())); } return ExportValidationResponse.create( isValidRequest, message, enabledCollectionsLabels, disabledCollectionLabels); } NegotiatorController(
      RestTemplate restTemplate,
      UserPermissionEvaluator permissions,
      DataService dataService,
      QueryRsqlConverter rsqlQueryConverter,
      JsMagmaScriptEvaluator jsMagmaScriptEvaluator,
      MessageSource messageSource); }
NegotiatorController extends PluginController { @PostMapping("/validate") @ResponseBody public ExportValidationResponse validateNegotiatorExport(@RequestBody NegotiatorRequest request) { if (request.getBiobankRsql() != null || request.getBiobankId() != null) { throw new IllegalArgumentException("Cannot verify requests with biobank filters."); } boolean isValidRequest = true; String message = ""; List<String> enabledCollectionsLabels; List<String> disabledCollectionLabels; Optional<NegotiatorEntityConfig> entityConfigOptional = getNegotiatorEntityConfig(request.getEntityId()); if (entityConfigOptional.isPresent()) { NegotiatorEntityConfig entityConfig = entityConfigOptional.get(); LOG.info("Validating negotiator request\n\n{}", request); List<Entity> collectionEntities = getCollectionEntities(request); List<Entity> disabledCollections = getDisabledCollections(collectionEntities, entityConfig); Function<Entity, String> getLabel = entity -> entity.getLabelValue().toString(); disabledCollectionLabels = disabledCollections.stream().map(getLabel).collect(toList()); enabledCollectionsLabels = collectionEntities.stream() .filter(e -> !disabledCollections.contains(e)) .map(getLabel) .collect(toList()); if (!disabledCollections.isEmpty()) { message = messageSource.getMessage( "dataexplorer_directory_disabled", new Object[] {disabledCollections.size(), collectionEntities.size()}, getLocale()); } if (collectionEntities.isEmpty() || (collectionEntities.size() == disabledCollections.size())) { isValidRequest = false; message = messageSource.getMessage( "dataexplorer_directory_no_rows", new Object[] {}, getLocale()); } } else { throw new MolgenisDataException( messageSource.getMessage( "dataexplorer_directory_no_config", new Object[] {}, getLocale())); } return ExportValidationResponse.create( isValidRequest, message, enabledCollectionsLabels, disabledCollectionLabels); } NegotiatorController(
      RestTemplate restTemplate,
      UserPermissionEvaluator permissions,
      DataService dataService,
      QueryRsqlConverter rsqlQueryConverter,
      JsMagmaScriptEvaluator jsMagmaScriptEvaluator,
      MessageSource messageSource); @RunAsSystem boolean showDirectoryButton(String entityTypeId); @PostMapping("/validate") @ResponseBody ExportValidationResponse validateNegotiatorExport(@RequestBody NegotiatorRequest request); @PostMapping("/export") @ResponseBody String exportToNegotiator(@RequestBody NegotiatorRequest request); @ExceptionHandler(RuntimeException.class) @ResponseBody @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) ErrorMessageResponse handleRuntimeException(RuntimeException e); }
NegotiatorController extends PluginController { @PostMapping("/validate") @ResponseBody public ExportValidationResponse validateNegotiatorExport(@RequestBody NegotiatorRequest request) { if (request.getBiobankRsql() != null || request.getBiobankId() != null) { throw new IllegalArgumentException("Cannot verify requests with biobank filters."); } boolean isValidRequest = true; String message = ""; List<String> enabledCollectionsLabels; List<String> disabledCollectionLabels; Optional<NegotiatorEntityConfig> entityConfigOptional = getNegotiatorEntityConfig(request.getEntityId()); if (entityConfigOptional.isPresent()) { NegotiatorEntityConfig entityConfig = entityConfigOptional.get(); LOG.info("Validating negotiator request\n\n{}", request); List<Entity> collectionEntities = getCollectionEntities(request); List<Entity> disabledCollections = getDisabledCollections(collectionEntities, entityConfig); Function<Entity, String> getLabel = entity -> entity.getLabelValue().toString(); disabledCollectionLabels = disabledCollections.stream().map(getLabel).collect(toList()); enabledCollectionsLabels = collectionEntities.stream() .filter(e -> !disabledCollections.contains(e)) .map(getLabel) .collect(toList()); if (!disabledCollections.isEmpty()) { message = messageSource.getMessage( "dataexplorer_directory_disabled", new Object[] {disabledCollections.size(), collectionEntities.size()}, getLocale()); } if (collectionEntities.isEmpty() || (collectionEntities.size() == disabledCollections.size())) { isValidRequest = false; message = messageSource.getMessage( "dataexplorer_directory_no_rows", new Object[] {}, getLocale()); } } else { throw new MolgenisDataException( messageSource.getMessage( "dataexplorer_directory_no_config", new Object[] {}, getLocale())); } return ExportValidationResponse.create( isValidRequest, message, enabledCollectionsLabels, disabledCollectionLabels); } NegotiatorController(
      RestTemplate restTemplate,
      UserPermissionEvaluator permissions,
      DataService dataService,
      QueryRsqlConverter rsqlQueryConverter,
      JsMagmaScriptEvaluator jsMagmaScriptEvaluator,
      MessageSource messageSource); @RunAsSystem boolean showDirectoryButton(String entityTypeId); @PostMapping("/validate") @ResponseBody ExportValidationResponse validateNegotiatorExport(@RequestBody NegotiatorRequest request); @PostMapping("/export") @ResponseBody String exportToNegotiator(@RequestBody NegotiatorRequest request); @ExceptionHandler(RuntimeException.class) @ResponseBody @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) ErrorMessageResponse handleRuntimeException(RuntimeException e); static final String ID; }