Search in sources :

Example 1 with OneClickImportJobExecution

use of org.molgenis.oneclickimporter.job.OneClickImportJobExecution in project molgenis by molgenis.

the class OneClickImporterControllerTest method before.

@BeforeMethod
public void before() {
    OneClickImporterController oneClickImporterController = new OneClickImporterController(menuReaderService, appSettings, userAccountService, fileStore, oneClickImportJobExecutionFactory, jobExecutor);
    Menu menu = mock(Menu.class);
    when(menu.findMenuItemPath(OneClickImporterController.ONE_CLICK_IMPORTER)).thenReturn("/test-path");
    when(menuReaderService.getMenu()).thenReturn(menu);
    when(localeResolver.resolveLocale(any())).thenReturn(new Locale("nl"));
    when(appSettings.getLanguageCode()).thenReturn("en");
    User user = mock(User.class);
    when(user.isSuperuser()).thenReturn(false);
    when(userAccountService.getCurrentUser()).thenReturn(user);
    OneClickImportJobExecution jobExecution = mock(OneClickImportJobExecution.class);
    when(oneClickImportJobExecutionFactory.create()).thenReturn(jobExecution);
    EntityType oneClickImportJobExecutionEntityType = mock(EntityType.class);
    when(jobExecution.getEntityType()).thenReturn(oneClickImportJobExecutionEntityType);
    when(jobExecution.getIdValue()).thenReturn("id_1");
    when(oneClickImportJobExecutionEntityType.getId()).thenReturn("jobExecutionId");
    StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
    stringConverter.setWriteAcceptCharset(false);
    mockMvc = MockMvcBuilders.standaloneSetup(oneClickImporterController).setLocaleResolver(localeResolver).setMessageConverters(gsonHttpMessageConverter, stringConverter).build();
}
Also used : Locale(java.util.Locale) EntityType(org.molgenis.data.meta.model.EntityType) User(org.molgenis.data.security.auth.User) Menu(org.molgenis.core.ui.menu.Menu) OneClickImportJobExecution(org.molgenis.oneclickimporter.job.OneClickImportJobExecution) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with OneClickImportJobExecution

use of org.molgenis.oneclickimporter.job.OneClickImportJobExecution in project molgenis by molgenis.

the class OneClickImporterController method importFile.

@ResponseBody
@PostMapping(value = "/upload", produces = MediaType.TEXT_HTML_VALUE)
public String importFile(@RequestParam(value = "file") MultipartFile multipartFile) throws IOException {
    String filename = multipartFile.getOriginalFilename();
    fileStore.store(multipartFile.getInputStream(), filename);
    OneClickImportJobExecution jobExecution = oneClickImportJobExecutionFactory.create();
    jobExecution.setUser(getCurrentUsername());
    jobExecution.setFile(filename);
    jobExecutor.submit(jobExecution);
    return concatEntityHref(jobExecution);
}
Also used : OneClickImportJobExecution(org.molgenis.oneclickimporter.job.OneClickImportJobExecution)

Aggregations

OneClickImportJobExecution (org.molgenis.oneclickimporter.job.OneClickImportJobExecution)2 Locale (java.util.Locale)1 Menu (org.molgenis.core.ui.menu.Menu)1 EntityType (org.molgenis.data.meta.model.EntityType)1 User (org.molgenis.data.security.auth.User)1 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)1 BeforeMethod (org.testng.annotations.BeforeMethod)1