Search in sources :

Example 16 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class EntityUtilsTest method getIsNullValueMockEntity.

private Entity getIsNullValueMockEntity() {
    Entity entity = mock(Entity.class);
    when(entity.toString()).thenReturn("entity");
    return entity;
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity)

Example 17 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class AnnotationJobFactory method createJob.

@RunAsSystem
public AnnotationJob createJob(AnnotationJobExecution metaData) {
    dataService.add(ANNOTATION_JOB_EXECUTION, metaData);
    String annotatorNames = metaData.getAnnotators();
    String targetName = metaData.getTargetName();
    String username = metaData.getUser();
    // create an authentication to run as the user that is listed as the owner of the job
    RunAsUserToken runAsAuthentication = new RunAsUserToken("Job Execution", username, null, userDetailsService.loadUserByUsername(username).getAuthorities(), null);
    Repository<Entity> repository = dataService.getRepository(targetName);
    List<RepositoryAnnotator> availableAnnotators = annotationService.getAllAnnotators().stream().filter(RepositoryAnnotator::annotationDataExists).collect(toList());
    List<RepositoryAnnotator> requestedAnnotators = Arrays.stream(annotatorNames.split(",")).map(annotationService::getAnnotatorByName).collect(toList());
    AnnotatorDependencyOrderResolver resolver = new AnnotatorDependencyOrderResolver();
    List<RepositoryAnnotator> annotators = Lists.newArrayList(resolver.getAnnotatorSelectionDependencyList(availableAnnotators, requestedAnnotators, repository, entityTypeFactory));
    return new AnnotationJob(crudRepositoryAnnotator, username, annotators, repository, new ProgressImpl(metaData, jobExecutionUpdater, mailSender), runAsAuthentication, new TransactionTemplate(transactionManager));
}
Also used : Entity(org.molgenis.data.Entity) ProgressImpl(org.molgenis.jobs.ProgressImpl) RunAsUserToken(org.springframework.security.access.intercept.RunAsUserToken) RepositoryAnnotator(org.molgenis.data.annotation.core.RepositoryAnnotator) CrudRepositoryAnnotator(org.molgenis.data.annotation.web.CrudRepositoryAnnotator) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) AnnotatorDependencyOrderResolver(org.molgenis.data.annotation.core.utils.AnnotatorDependencyOrderResolver) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Example 18 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class NegotiatorControllerTest method testValidateNegotiatorExport.

@Test
public void testValidateNegotiatorExport() {
    NegotiatorRequest request = NegotiatorRequest.create("http://molgenis.org", "molgenis_id_1", "*=q=MOLGENIS", "a nice molgenis query", "Sjfg03Msmdp92Md82103FNskas9H735F");
    Entity entity = mock(Entity.class);
    String entityOneLabel = "Entity One";
    when(entity.getLabelValue()).thenReturn(entityOneLabel);
    when(entity.get("enabled")).thenReturn(true);
    when(dataService.findAll("molgenis_id_1", molgenisQuery)).thenReturn(Stream.of(entity));
    when(jsMagmaScriptEvaluator.eval("$(enabled).value()", entity)).thenReturn(TRUE);
    ExportValidationResponse actual = negotiatorController.validateNegotiatorExport(request);
    List<String> enabledCollections = Collections.singletonList(entityOneLabel);
    ExportValidationResponse expected = ExportValidationResponse.create(true, "", enabledCollections, emptyList());
    assertEquals(actual, expected);
}
Also used : HttpEntity(org.springframework.http.HttpEntity) Entity(org.molgenis.data.Entity) Test(org.testng.annotations.Test)

Example 19 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class NegotiatorControllerTest method testValidateNegotiatorExportEmptyCollections.

@Test
public void testValidateNegotiatorExportEmptyCollections() {
    NegotiatorRequest request = NegotiatorRequest.create("http://molgenis.org", "molgenis_id_1", "*=q=MOLGENIS", "a nice molgenis query", "Sjfg03Msmdp92Md82103FNskas9H735F");
    Entity entity = mock(Entity.class);
    when(entity.getLabelValue()).thenReturn("Entity One");
    when(entity.get("enabled")).thenReturn(true);
    when(dataService.findAll("molgenis_id_1", molgenisQuery)).thenReturn(Stream.empty());
    ExportValidationResponse actual = negotiatorController.validateNegotiatorExport(request);
    ExportValidationResponse expected = ExportValidationResponse.create(false, "Please make sure your selection contains at least 1 row that supports the negotiator.");
    assertEquals(actual, expected);
}
Also used : HttpEntity(org.springframework.http.HttpEntity) Entity(org.molgenis.data.Entity) Test(org.testng.annotations.Test)

Example 20 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class NegotiatorControllerTest method testValidateNegotiatorExportAllCollectionsAreDisabled.

@Test
public void testValidateNegotiatorExportAllCollectionsAreDisabled() {
    NegotiatorRequest request = NegotiatorRequest.create("http://molgenis.org", "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(dataService.findAll("molgenis_id_1", molgenisQuery)).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(actual, expected);
}
Also used : HttpEntity(org.springframework.http.HttpEntity) Entity(org.molgenis.data.Entity) Test(org.testng.annotations.Test)

Aggregations

Entity (org.molgenis.data.Entity)448 Test (org.testng.annotations.Test)295 DynamicEntity (org.molgenis.data.support.DynamicEntity)192 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)120 Attribute (org.molgenis.data.meta.model.Attribute)111 EntityType (org.molgenis.data.meta.model.EntityType)110 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)37 MolgenisDataException (org.molgenis.data.MolgenisDataException)20 QueryImpl (org.molgenis.data.support.QueryImpl)20 AttributeType (org.molgenis.data.meta.AttributeType)18 UnexpectedEnumException (org.molgenis.util.UnexpectedEnumException)18 Stream (java.util.stream.Stream)17 QueryRule (org.molgenis.data.QueryRule)16 MultiAllelicResultFilter (org.molgenis.data.annotation.core.filter.MultiAllelicResultFilter)16 RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)16 Objects.requireNonNull (java.util.Objects.requireNonNull)15 DataService (org.molgenis.data.DataService)15 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)15 WithMockUser (org.springframework.security.test.context.support.WithMockUser)14 Instant (java.time.Instant)13