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);
}
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);
}
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);
}
Aggregations