Search in sources :

Example 1 with NegotiatorEntityConfig

use of org.molgenis.dataexplorer.negotiator.config.NegotiatorEntityConfig in project molgenis by molgenis.

the class NegotiatorController method validateNegotiatorExport.

@PostMapping("/validate")
@ResponseBody
public ExportValidationResponse validateNegotiatorExport(@RequestBody NegotiatorRequest request) {
    boolean isValidRequest = true;
    String message = "";
    List<String> enabledCollectionsLabels;
    List<String> disabledCollectionLabels;
    NegotiatorEntityConfig entityConfig = getNegotiatorEntityConfig(request.getEntityId());
    if (null != entityConfig) {
        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);
}
Also used : PluginController(org.molgenis.web.PluginController) NegotiatorConfig(org.molgenis.dataexplorer.negotiator.config.NegotiatorConfig) ErrorMessageResponse(org.molgenis.web.ErrorMessageResponse) LoggerFactory(org.slf4j.LoggerFactory) QueryImpl(org.molgenis.data.support.QueryImpl) Controller(org.springframework.stereotype.Controller) Attribute(org.molgenis.data.meta.model.Attribute) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem) Function(java.util.function.Function) PluginPermission(org.molgenis.data.plugin.model.PluginPermission) Objects.requireNonNull(java.util.Objects.requireNonNull) PluginIdentity(org.molgenis.data.plugin.model.PluginIdentity) JsMagmaScriptEvaluator(org.molgenis.js.magma.JsMagmaScriptEvaluator) APPLICATION_JSON(org.springframework.http.MediaType.APPLICATION_JSON) RestTemplate(org.springframework.web.client.RestTemplate) MessageSource(org.springframework.context.MessageSource) RestClientException(org.springframework.web.client.RestClientException) QueryRsqlConverter(org.molgenis.data.rest.convert.QueryRsqlConverter) Logger(org.slf4j.Logger) URI(org.molgenis.dataexplorer.negotiator.NegotiatorController.URI) LocaleContextHolder.getLocale(org.springframework.context.i18n.LocaleContextHolder.getLocale) HttpHeaders(org.springframework.http.HttpHeaders) UTF_8(java.nio.charset.StandardCharsets.UTF_8) NegotiatorEntityConfigMeta(org.molgenis.dataexplorer.negotiator.config.NegotiatorEntityConfigMeta) EntityTypeUtils(org.molgenis.data.support.EntityTypeUtils) EntityType(org.molgenis.data.meta.model.EntityType) Collectors(java.util.stream.Collectors) HttpStatus(org.springframework.http.HttpStatus) HttpEntity(org.springframework.http.HttpEntity) Base64(java.util.Base64) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ENABLED_EXPRESSION(org.molgenis.dataexplorer.negotiator.config.NegotiatorEntityConfigMeta.ENABLED_EXPRESSION) UserPermissionEvaluator(org.molgenis.security.core.UserPermissionEvaluator) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) DataService(org.molgenis.data.DataService) Query(org.molgenis.data.Query) NegotiatorEntityConfig(org.molgenis.dataexplorer.negotiator.config.NegotiatorEntityConfig) MolgenisDataException(org.molgenis.data.MolgenisDataException) Entity(org.molgenis.data.Entity) NegotiatorEntityConfig(org.molgenis.dataexplorer.negotiator.config.NegotiatorEntityConfig) HttpEntity(org.springframework.http.HttpEntity) Entity(org.molgenis.data.Entity) MolgenisDataException(org.molgenis.data.MolgenisDataException)

Example 2 with NegotiatorEntityConfig

use of org.molgenis.dataexplorer.negotiator.config.NegotiatorEntityConfig in project molgenis by molgenis.

the class NegotiatorControllerTest method beforeMethod.

@BeforeMethod
public void beforeMethod() {
    initMocks(this);
    /* Negotiator config mock */
    Query<NegotiatorEntityConfig> query = new QueryImpl<NegotiatorEntityConfig>().eq(NegotiatorEntityConfigMeta.ENTITY, "molgenis_id_1");
    when(dataService.findOne(NegotiatorEntityConfigMeta.NEGOTIATORENTITYCONFIG, query, NegotiatorEntityConfig.class)).thenReturn(negotiatorEntityConfig);
    when(collectionAttr.getName()).thenReturn("collectionAttr");
    when(collectionAttr.getDataType()).thenReturn(AttributeType.STRING);
    doReturn(collectionAttr).when(negotiatorEntityConfig).getEntity(COLLECTION_ID, Attribute.class);
    when(biobackAttr.getName()).thenReturn("biobackAttr");
    when(biobackAttr.getDataType()).thenReturn(AttributeType.STRING);
    doReturn(biobackAttr).when(negotiatorEntityConfig).getEntity(BIOBANK_ID, Attribute.class);
    when(negotiatorEntityConfig.getString(ENABLED_EXPRESSION)).thenReturn("$(enabled).value()");
    when(negotiatorEntityConfig.getNegotiatorConfig()).thenReturn(negotiatorConfig);
    /* get EntityCollection mock */
    when(entityType.getId()).thenReturn("molgenis_id_1");
    when(dataService.getEntityType("molgenis_id_1")).thenReturn(entityType);
    when(queryRsql.createQuery(entityType)).thenReturn(molgenisQuery);
    when(rsqlQueryConverter.convert("*=q=MOLGENIS")).thenReturn(queryRsql);
    LocaleContextHolder.setLocale(Locale.ENGLISH);
    AllPropertiesMessageSource messageSource = new AllPropertiesMessageSource();
    messageSource.addMolgenisNamespaces("dataexplorer");
    negotiatorController = new NegotiatorController(restTemplate, permissionService, dataService, rsqlQueryConverter, jsMagmaScriptEvaluator, messageSource);
}
Also used : NegotiatorEntityConfig(org.molgenis.dataexplorer.negotiator.config.NegotiatorEntityConfig) AllPropertiesMessageSource(org.molgenis.i18n.properties.AllPropertiesMessageSource) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with NegotiatorEntityConfig

use of org.molgenis.dataexplorer.negotiator.config.NegotiatorEntityConfig in project molgenis by molgenis.

the class NegotiatorController method exportToNegotiator.

@PostMapping("/export")
@ResponseBody
public String exportToNegotiator(@RequestBody NegotiatorRequest request) {
    LOG.info("Sending Negotiator request");
    NegotiatorEntityConfig entityConfig = getNegotiatorEntityConfig(request.getEntityId());
    NegotiatorConfig config = entityConfig.getNegotiatorConfig();
    String expression = config.getString(ENABLED_EXPRESSION);
    List<Collection> nonDisabledCollectionEntities = getCollectionEntities(request).stream().filter(entity -> expression == null || evaluateExpressionOnEntity(expression, entity)).map(entity -> getEntityCollection(entityConfig, entity)).collect(toList());
    HttpEntity<NegotiatorQuery> queryHttpEntity = getNegotiatorQueryHttpEntity(request, config, nonDisabledCollectionEntities);
    return postQueryToNegotiator(config, queryHttpEntity);
}
Also used : PluginController(org.molgenis.web.PluginController) NegotiatorConfig(org.molgenis.dataexplorer.negotiator.config.NegotiatorConfig) ErrorMessageResponse(org.molgenis.web.ErrorMessageResponse) LoggerFactory(org.slf4j.LoggerFactory) QueryImpl(org.molgenis.data.support.QueryImpl) Controller(org.springframework.stereotype.Controller) Attribute(org.molgenis.data.meta.model.Attribute) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem) Function(java.util.function.Function) PluginPermission(org.molgenis.data.plugin.model.PluginPermission) Objects.requireNonNull(java.util.Objects.requireNonNull) PluginIdentity(org.molgenis.data.plugin.model.PluginIdentity) JsMagmaScriptEvaluator(org.molgenis.js.magma.JsMagmaScriptEvaluator) APPLICATION_JSON(org.springframework.http.MediaType.APPLICATION_JSON) RestTemplate(org.springframework.web.client.RestTemplate) MessageSource(org.springframework.context.MessageSource) RestClientException(org.springframework.web.client.RestClientException) QueryRsqlConverter(org.molgenis.data.rest.convert.QueryRsqlConverter) Logger(org.slf4j.Logger) URI(org.molgenis.dataexplorer.negotiator.NegotiatorController.URI) LocaleContextHolder.getLocale(org.springframework.context.i18n.LocaleContextHolder.getLocale) HttpHeaders(org.springframework.http.HttpHeaders) UTF_8(java.nio.charset.StandardCharsets.UTF_8) NegotiatorEntityConfigMeta(org.molgenis.dataexplorer.negotiator.config.NegotiatorEntityConfigMeta) EntityTypeUtils(org.molgenis.data.support.EntityTypeUtils) EntityType(org.molgenis.data.meta.model.EntityType) Collectors(java.util.stream.Collectors) HttpStatus(org.springframework.http.HttpStatus) HttpEntity(org.springframework.http.HttpEntity) Base64(java.util.Base64) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ENABLED_EXPRESSION(org.molgenis.dataexplorer.negotiator.config.NegotiatorEntityConfigMeta.ENABLED_EXPRESSION) UserPermissionEvaluator(org.molgenis.security.core.UserPermissionEvaluator) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) DataService(org.molgenis.data.DataService) Query(org.molgenis.data.Query) NegotiatorEntityConfig(org.molgenis.dataexplorer.negotiator.config.NegotiatorEntityConfig) MolgenisDataException(org.molgenis.data.MolgenisDataException) Entity(org.molgenis.data.Entity) NegotiatorEntityConfig(org.molgenis.dataexplorer.negotiator.config.NegotiatorEntityConfig) NegotiatorConfig(org.molgenis.dataexplorer.negotiator.config.NegotiatorConfig)

Aggregations

NegotiatorEntityConfig (org.molgenis.dataexplorer.negotiator.config.NegotiatorEntityConfig)3 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)2 Base64 (java.util.Base64)2 List (java.util.List)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Collectors.toList (java.util.stream.Collectors.toList)2 DataService (org.molgenis.data.DataService)2 Entity (org.molgenis.data.Entity)2 MolgenisDataException (org.molgenis.data.MolgenisDataException)2 Query (org.molgenis.data.Query)2 Attribute (org.molgenis.data.meta.model.Attribute)2 EntityType (org.molgenis.data.meta.model.EntityType)2 PluginIdentity (org.molgenis.data.plugin.model.PluginIdentity)2 PluginPermission (org.molgenis.data.plugin.model.PluginPermission)2 QueryRsqlConverter (org.molgenis.data.rest.convert.QueryRsqlConverter)2 EntityTypeUtils (org.molgenis.data.support.EntityTypeUtils)2 QueryImpl (org.molgenis.data.support.QueryImpl)2 URI (org.molgenis.dataexplorer.negotiator.NegotiatorController.URI)2