use of org.molgenis.data.file.model.FileMeta in project molgenis by molgenis.
the class AppRepositoryDecoratorTest method getMockApp.
private App getMockApp(String id, boolean isActive, String resourceFilename) {
App app = mock(App.class);
when(app.getId()).thenReturn(id);
when(app.getName()).thenReturn(APP_NAME);
when(app.isActive()).thenReturn(isActive);
when(app.getUseFreemarkerTemplate()).thenReturn(true);
if (resourceFilename != null) {
FileMeta fileMeta = mock(FileMeta.class);
when(fileMeta.getId()).thenReturn(resourceFilename);
when(fileMeta.getFilename()).thenReturn(resourceFilename);
when(app.getSourceFiles()).thenReturn(fileMeta);
when(fileStore.getFile(resourceFilename)).thenReturn(getFile(getClass(), '/' + resourceFilename));
when(fileStore.getStorageDir()).thenReturn("target/generated-test-resources");
}
return app;
}
use of org.molgenis.data.file.model.FileMeta in project molgenis by molgenis.
the class AmazonBucketIngester method createFileMeta.
private FileMeta createFileMeta(String jobExecutionID, File file) {
FileMeta fileMeta = fileMetaFactory.create(jobExecutionID);
fileMeta.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
fileMeta.setSize(file.length());
fileMeta.setFilename(jobExecutionID + '/' + file.getName());
fileMeta.setUrl("/files/" + jobExecutionID);
return fileMeta;
}
use of org.molgenis.data.file.model.FileMeta in project molgenis by molgenis.
the class PostgreSqlUtils method getPostgreSqlValue.
/**
* Returns the PostgreSQL value for the given entity attribute
*
* @param entity entity
* @param attr attribute
* @return PostgreSQL value
*/
static Object getPostgreSqlValue(Entity entity, Attribute attr) {
String attrName = attr.getName();
AttributeType attrType = attr.getDataType();
switch(attrType) {
case BOOL:
return entity.getBoolean(attrName);
case CATEGORICAL:
case XREF:
Entity xrefEntity = entity.getEntity(attrName);
return xrefEntity != null ? getPostgreSqlValue(xrefEntity, xrefEntity.getEntityType().getIdAttribute()) : null;
case CATEGORICAL_MREF:
case MREF:
case ONE_TO_MANY:
Iterable<Entity> entities = entity.getEntities(attrName);
return stream(entities.spliterator(), false).map(mrefEntity -> getPostgreSqlValue(mrefEntity, mrefEntity.getEntityType().getIdAttribute())).collect(toList());
case DATE:
return entity.getLocalDate(attrName);
case DATE_TIME:
// As a workaround for #5674, we don't store milliseconds
Instant instant = entity.getInstant(attrName);
return instant != null ? instant.truncatedTo(ChronoUnit.SECONDS).atOffset(UTC) : null;
case DECIMAL:
return entity.getDouble(attrName);
case EMAIL:
case ENUM:
case HTML:
case HYPERLINK:
case SCRIPT:
case STRING:
case TEXT:
return entity.getString(attrName);
case FILE:
FileMeta fileEntity = entity.getEntity(attrName, FileMeta.class);
return fileEntity != null ? getPostgreSqlValue(fileEntity, fileEntity.getEntityType().getIdAttribute()) : null;
case INT:
return entity.getInt(attrName);
case LONG:
return entity.getLong(attrName);
case COMPOUND:
throw new RuntimeException(format("Illegal attribute type [%s]", attrType.toString()));
default:
throw new UnexpectedEnumException(attrType);
}
}
use of org.molgenis.data.file.model.FileMeta 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.file.model.FileMeta 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