use of org.molgenis.data.Entity 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.data.Entity in project molgenis by molgenis.
the class EntityReferenceTest method testSetEntityIdAttribute.
@Test
public void testSetEntityIdAttribute() {
Entity entity = mock(Entity.class);
when(entity.getAttributeNames()).thenReturn(singletonList(ID_ATTR_NAME)).getMock();
when(entity.get(ID_ATTR_NAME)).thenReturn("newEntityId");
entityReference.set(entity);
assertEquals(entityReference.getIdValue(), "newEntityId");
}
use of org.molgenis.data.Entity in project molgenis by molgenis.
the class AbstractRepositoryTest method testUpsertBatch.
// // Note: streamFetch cannot be tested because mocking default methods is not supported by Mockito
@Test
public void testUpsertBatch() {
Object id0 = "id0";
Object id1 = "id1";
Entity entity0 = when(mock(Entity.class).getIdValue()).thenReturn(id0).getMock();
Entity entity1 = when(mock(Entity.class).getIdValue()).thenReturn(id1).getMock();
List<Entity> batch = Arrays.asList(entity0, entity1);
doReturn(Stream.of(entity0)).when(abstractRepository).findAll(objectStreamCaptor.capture(), any(Fetch.class));
doReturn(1).when(abstractRepository).add(addStreamCaptor.capture());
doNothing().when(abstractRepository).update(updateStreamCaptor.capture());
abstractRepository.upsertBatch(batch);
assertEquals(addStreamCaptor.getValue().collect(Collectors.toList()), Collections.singletonList(entity1), "New entity should get added.");
assertEquals(updateStreamCaptor.getValue().collect(Collectors.toList()), Collections.singletonList(entity0), "Existing entity should get updated.");
}
use of org.molgenis.data.Entity in project molgenis by molgenis.
the class AbstractRepositoryTest method beforeTest.
@BeforeTest
public void beforeTest() {
MockitoAnnotations.initMocks(this);
Attribute idAttr = when(mock(Attribute.class).getName()).thenReturn("id").getMock();
entityType = when(mock(EntityType.class).getId()).thenReturn("entity").getMock();
when(entityType.getIdAttribute()).thenReturn(idAttr);
abstractRepository = Mockito.spy(new AbstractRepository() {
@Override
public Iterator<Entity> iterator() {
return null;
}
public EntityType getEntityType() {
return entityType;
}
@Override
public Set<RepositoryCapability> getCapabilities() {
return Collections.emptySet();
}
});
}
use of org.molgenis.data.Entity in project molgenis by molgenis.
the class DocumentContentBuilderTest method createDocumentReferenceAttribute.
@Test(dataProvider = "createDocumentReference")
public void createDocumentReferenceAttribute(AttributeType attributeType, Entity value, String expectedContent) {
String attrIdentifier = "attr";
Entity entity = createEntity(attrIdentifier, attributeType);
when(entity.getEntity(attrIdentifier)).thenReturn(value);
Document document = documentContentBuilder.createDocument(entity);
assertDocumentEquals(document, expectedContent);
}
Aggregations