use of org.molgenis.data.Repository in project molgenis by molgenis.
the class CrudRepositoryAnnotator method annotate.
private void annotate(RepositoryAnnotator annotator, Repository<Entity> repository, DatabaseAction action) {
if (!repository.getCapabilities().contains(WRITABLE)) {
throw new UnsupportedOperationException("Currently only writable repositories can be annotated");
}
try {
EntityType entityType = dataService.getMeta().getEntityType(repository.getName());
if (annotator instanceof EffectCreatingAnnotator) {
targetMetaData = ((EffectCreatingAnnotator) annotator).getTargetEntityType(entityType);
if (!dataService.hasRepository(targetMetaData.getId())) {
// add new entities to new repo
Repository externalRepository = dataService.getMeta().createRepository(targetMetaData);
permissionSystemService.giveUserWriteMetaPermissions(targetMetaData);
runAsSystem(() -> dataService.getMeta().updateEntityType(externalRepository.getEntityType()));
iterateOverEntitiesAndAnnotate(repository, annotator, DatabaseAction.ADD);
} else {
throw new UnsupportedOperationException("This entity has already been annotated with " + annotator.getSimpleName());
}
} else {
runAsSystem(() -> dataService.getMeta().updateEntityType(addAnnotatorMetaDataToRepositories(entityType, attributeFactory, annotator)));
iterateOverEntitiesAndAnnotate(dataService.getRepository(repository.getName()), annotator, action);
}
} catch (AnnotationException ae) {
deleteResultEntity(annotator, targetMetaData);
throw new UiAnnotationException(ae);
} catch (Exception e) {
deleteResultEntity(annotator, targetMetaData);
throw new RuntimeException(e);
}
}
use of org.molgenis.data.Repository in project molgenis by molgenis.
the class StyleServiceTest method addStylesWithExistingId.
@Test(expectedExceptions = MolgenisStyleException.class)
public void addStylesWithExistingId() throws IOException, MolgenisStyleException {
String styleId = "style";
String bs3FileName = "any";
String bs4FileName = "any";
InputStream bs3Data = IOUtils.toInputStream("any", "UTF-8");
InputStream bs4Data = IOUtils.toInputStream("any", "UTF-8");
StyleSheet styleSheet = mock(StyleSheet.class);
Repository styleSheetRepository = mock(Repository.class);
when(dataService.getRepository(STYLE_SHEET)).thenReturn(styleSheetRepository);
when(styleSheetRepository.findOneById(styleId)).thenReturn(styleSheet);
styleService.addStyle(styleId, bs3FileName, bs3Data, bs4FileName, bs4Data);
}
use of org.molgenis.data.Repository in project molgenis by molgenis.
the class IndexBootstrapperTest method testStartupNoIndex.
@Test
public void testStartupNoIndex() {
@SuppressWarnings("unchecked") Repository<Entity> repo1 = mock(Repository.class);
EntityType entityType1 = mock(EntityType.class);
when(repo1.getEntityType()).thenReturn(entityType1);
@SuppressWarnings("unchecked") Repository<Entity> repo2 = mock(Repository.class);
EntityType entityType2 = mock(EntityType.class);
when(repo2.getEntityType()).thenReturn(entityType2);
@SuppressWarnings("unchecked") Repository<Entity> repo3 = mock(Repository.class);
EntityType entityType3 = mock(EntityType.class);
when(repo3.getEntityType()).thenReturn(entityType3);
List<Repository<Entity>> repos = Arrays.asList(repo1, repo2, repo3);
when(indexService.hasIndex(attributeMetadata)).thenReturn(false);
when(metaDataService.getRepositories()).thenReturn(repos.stream());
indexBootstrapper.bootstrap();
// verify that new jobs are registered for all repos
verify(indexActionRegisterService).register(entityType1, null);
verify(indexActionRegisterService).register(entityType2, null);
verify(indexActionRegisterService).register(entityType3, null);
}
use of org.molgenis.data.Repository in project molgenis by molgenis.
the class StyleServiceTest method addBootstrap3StyleOnly.
@Test
public void addBootstrap3StyleOnly() throws IOException, MolgenisStyleException {
// setup
String styleId = "my-style.min.css";
String bs3FileName = "bs3FileName";
InputStream bs3Data = IOUtils.toInputStream("bs 3 data", "UTF-8");
Repository styleSheetRepository = mock(Repository.class);
when(dataService.getRepository(STYLE_SHEET)).thenReturn(styleSheetRepository);
when(styleSheetRepository.findOneById(styleId)).thenReturn(null);
String generatedId = "my-id";
when(idGenerator.generateId()).thenReturn(generatedId);
StyleSheet styleSheet = mock(StyleSheet.class);
when(styleSheet.getName()).thenReturn(styleId);
when(styleSheetFactory.create(styleId)).thenReturn(styleSheet);
FileMeta fileMeta = mock(FileMeta.class);
when(fileMetaFactory.create(generatedId)).thenReturn(fileMeta);
File storedFile = mock(File.class);
when(storedFile.length()).thenReturn(123L);
when(fileStore.getFile(generatedId)).thenReturn(storedFile);
// execute
styleService.addStyle(styleId, bs3FileName, bs3Data, null, null);
// verify
verify(styleSheet).setName(styleId);
verify(dataService, times(1)).add(STYLE_SHEET, styleSheet);
verify(fileStore, times(1)).store(bs3Data, generatedId);
verify(dataService, times(1)).add(FileMetaMetaData.FILE_META, fileMeta);
}
use of org.molgenis.data.Repository in project molgenis by molgenis.
the class StyleServiceTest method addBootstrap3And4Styles.
@Test
public void addBootstrap3And4Styles() throws IOException, MolgenisStyleException {
// setup
String styleId = "my-style.min.css";
String bs3FileName = "bs3FileName";
String bs4FileName = "bs4FileName";
InputStream bs3Data = IOUtils.toInputStream("bs 3 data", "UTF-8");
InputStream bs4Data = IOUtils.toInputStream("bs 4 data", "UTF-8");
Repository styleSheetRepository = mock(Repository.class);
when(dataService.getRepository(STYLE_SHEET)).thenReturn(styleSheetRepository);
when(styleSheetRepository.findOneById(styleId)).thenReturn(null);
String generatedId = "my-id";
when(idGenerator.generateId()).thenReturn(generatedId);
StyleSheet styleSheet = mock(StyleSheet.class);
when(styleSheet.getName()).thenReturn(styleId);
when(styleSheetFactory.create(styleId)).thenReturn(styleSheet);
FileMeta fileMeta = mock(FileMeta.class);
when(fileMetaFactory.create(generatedId)).thenReturn(fileMeta);
File storedFile = mock(File.class);
when(storedFile.length()).thenReturn(123L);
when(fileStore.getFile(generatedId)).thenReturn(storedFile);
// execute
styleService.addStyle(styleId, bs3FileName, bs3Data, bs4FileName, bs4Data);
// verify
verify(styleSheet).setName(styleId);
verify(dataService, times(1)).add(STYLE_SHEET, styleSheet);
verify(fileStore, times(1)).store(bs3Data, generatedId);
verify(fileStore, times(1)).store(bs4Data, generatedId);
// two times, once for each style file
verify(dataService, times(2)).add(FileMetaMetaData.FILE_META, fileMeta);
}
Aggregations