@Test void testExportToNegotiator() { NegotiatorRequest request = NegotiatorRequest.create( "http: "molgenis_id_1", "*=q=MOLGENIS", "a nice molgenis query", "Sjfg03Msmdp92Md82103FNskas9H735F"); when(negotiatorConfig.getUsername()).thenReturn("username"); when(negotiatorConfig.getPassword()).thenReturn("password"); when(negotiatorConfig.getNegotiatorURL()).thenReturn("http: when(restTemplate.postForLocation(eq("http: .thenReturn(URI.create("http: String actual = negotiatorController.exportToNegotiator(request); String expected = "http: assertEquals(expected, actual); }
@PostMapping("/export") @ResponseBody public String exportToNegotiator(@RequestBody NegotiatorRequest request) { LOG.info("Sending Negotiator request"); NegotiatorEntityConfig entityConfig = getNegotiatorEntityConfig(request.getEntityId()) .orElseThrow( () -> new IllegalArgumentException("Negotiator entity config entity id is illegal")); NegotiatorConfig config = entityConfig.getNegotiatorConfig(); String expression = config.getString(ENABLED_EXPRESSION); List<Collection> collectionEntities = getCollectionEntities(request).stream() .filter(entity -> expression == null || evaluateExpressionOnEntity(expression, entity)) .map(entity -> getEntityCollection(entityConfig, entity)) .collect(toList()); if (request.getBiobankRsql() != null) { requireNonNull(request.getBiobankId(), "Must provide biobankId if biobankRsql is provided"); List<Object> biobankIds = getBiobankEntities(request).stream() .map(Entity::getIdValue) .map(Object::toString) .collect(toList()); collectionEntities = collectionEntities.stream() .filter(it -> biobankIds.contains(it.getBiobankId())) .collect(toList()); } else { requireNonNull( request.getRsql(), "Must provide at least one filter, either rsql or biobankRsql"); } HttpEntity<NegotiatorQuery> queryHttpEntity = getNegotiatorQueryHttpEntity(request, config, collectionEntities); return postQueryToNegotiator(config, queryHttpEntity); }
NegotiatorController extends PluginController { @PostMapping("/export") @ResponseBody public String exportToNegotiator(@RequestBody NegotiatorRequest request) { LOG.info("Sending Negotiator request"); NegotiatorEntityConfig entityConfig = getNegotiatorEntityConfig(request.getEntityId()) .orElseThrow( () -> new IllegalArgumentException("Negotiator entity config entity id is illegal")); NegotiatorConfig config = entityConfig.getNegotiatorConfig(); String expression = config.getString(ENABLED_EXPRESSION); List<Collection> collectionEntities = getCollectionEntities(request).stream() .filter(entity -> expression == null || evaluateExpressionOnEntity(expression, entity)) .map(entity -> getEntityCollection(entityConfig, entity)) .collect(toList()); if (request.getBiobankRsql() != null) { requireNonNull(request.getBiobankId(), "Must provide biobankId if biobankRsql is provided"); List<Object> biobankIds = getBiobankEntities(request).stream() .map(Entity::getIdValue) .map(Object::toString) .collect(toList()); collectionEntities = collectionEntities.stream() .filter(it -> biobankIds.contains(it.getBiobankId())) .collect(toList()); } else { requireNonNull( request.getRsql(), "Must provide at least one filter, either rsql or biobankRsql"); } HttpEntity<NegotiatorQuery> queryHttpEntity = getNegotiatorQueryHttpEntity(request, config, collectionEntities); return postQueryToNegotiator(config, queryHttpEntity); } }
NegotiatorController extends PluginController { @PostMapping("/export") @ResponseBody public String exportToNegotiator(@RequestBody NegotiatorRequest request) { LOG.info("Sending Negotiator request"); NegotiatorEntityConfig entityConfig = getNegotiatorEntityConfig(request.getEntityId()) .orElseThrow( () -> new IllegalArgumentException("Negotiator entity config entity id is illegal")); NegotiatorConfig config = entityConfig.getNegotiatorConfig(); String expression = config.getString(ENABLED_EXPRESSION); List<Collection> collectionEntities = getCollectionEntities(request).stream() .filter(entity -> expression == null || evaluateExpressionOnEntity(expression, entity)) .map(entity -> getEntityCollection(entityConfig, entity)) .collect(toList()); if (request.getBiobankRsql() != null) { requireNonNull(request.getBiobankId(), "Must provide biobankId if biobankRsql is provided"); List<Object> biobankIds = getBiobankEntities(request).stream() .map(Entity::getIdValue) .map(Object::toString) .collect(toList()); collectionEntities = collectionEntities.stream() .filter(it -> biobankIds.contains(it.getBiobankId())) .collect(toList()); } else { requireNonNull( request.getRsql(), "Must provide at least one filter, either rsql or biobankRsql"); } HttpEntity<NegotiatorQuery> queryHttpEntity = getNegotiatorQueryHttpEntity(request, config, collectionEntities); return postQueryToNegotiator(config, queryHttpEntity); } NegotiatorController(
      RestTemplate restTemplate,
      UserPermissionEvaluator permissions,
      DataService dataService,
      QueryRsqlConverter rsqlQueryConverter,
      JsMagmaScriptEvaluator jsMagmaScriptEvaluator,
      MessageSource messageSource); }
NegotiatorController extends PluginController { @PostMapping("/export") @ResponseBody public String exportToNegotiator(@RequestBody NegotiatorRequest request) { LOG.info("Sending Negotiator request"); NegotiatorEntityConfig entityConfig = getNegotiatorEntityConfig(request.getEntityId()) .orElseThrow( () -> new IllegalArgumentException("Negotiator entity config entity id is illegal")); NegotiatorConfig config = entityConfig.getNegotiatorConfig(); String expression = config.getString(ENABLED_EXPRESSION); List<Collection> collectionEntities = getCollectionEntities(request).stream() .filter(entity -> expression == null || evaluateExpressionOnEntity(expression, entity)) .map(entity -> getEntityCollection(entityConfig, entity)) .collect(toList()); if (request.getBiobankRsql() != null) { requireNonNull(request.getBiobankId(), "Must provide biobankId if biobankRsql is provided"); List<Object> biobankIds = getBiobankEntities(request).stream() .map(Entity::getIdValue) .map(Object::toString) .collect(toList()); collectionEntities = collectionEntities.stream() .filter(it -> biobankIds.contains(it.getBiobankId())) .collect(toList()); } else { requireNonNull( request.getRsql(), "Must provide at least one filter, either rsql or biobankRsql"); } HttpEntity<NegotiatorQuery> queryHttpEntity = getNegotiatorQueryHttpEntity(request, config, collectionEntities); return postQueryToNegotiator(config, queryHttpEntity); } 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("/export") @ResponseBody public String exportToNegotiator(@RequestBody NegotiatorRequest request) { LOG.info("Sending Negotiator request"); NegotiatorEntityConfig entityConfig = getNegotiatorEntityConfig(request.getEntityId()) .orElseThrow( () -> new IllegalArgumentException("Negotiator entity config entity id is illegal")); NegotiatorConfig config = entityConfig.getNegotiatorConfig(); String expression = config.getString(ENABLED_EXPRESSION); List<Collection> collectionEntities = getCollectionEntities(request).stream() .filter(entity -> expression == null || evaluateExpressionOnEntity(expression, entity)) .map(entity -> getEntityCollection(entityConfig, entity)) .collect(toList()); if (request.getBiobankRsql() != null) { requireNonNull(request.getBiobankId(), "Must provide biobankId if biobankRsql is provided"); List<Object> biobankIds = getBiobankEntities(request).stream() .map(Entity::getIdValue) .map(Object::toString) .collect(toList()); collectionEntities = collectionEntities.stream() .filter(it -> biobankIds.contains(it.getBiobankId())) .collect(toList()); } else { requireNonNull( request.getRsql(), "Must provide at least one filter, either rsql or biobankRsql"); } HttpEntity<NegotiatorQuery> queryHttpEntity = getNegotiatorQueryHttpEntity(request, config, collectionEntities); return postQueryToNegotiator(config, queryHttpEntity); } 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; }