use of org.molgenis.security.core.runas.RunAsSystem in project molgenis by molgenis.
the class StyleServiceImpl method getThemeData.
@Override
@RunAsSystem
public FileSystemResource getThemeData(String styleName, BootstrapVersion bootstrapVersion) throws MolgenisStyleException {
StyleSheet styleSheet = findThemeByName(styleName);
if (styleSheet == null) {
throw new MolgenisStyleException("No theme found for with name: " + styleName);
}
// Fetch the theme file from the store.
FileMeta fileMeta;
if (bootstrapVersion.equals(BOOTSTRAP_VERSION_3)) {
fileMeta = styleSheet.getBootstrap3Theme();
} else {
fileMeta = styleSheet.getBootstrap4Theme();
// If no bootstrap 4 theme was set fetch the default theme from the resources folder
if (fileMeta == null) {
StyleSheet fallBackTheme = findThemeByName(BOOTSTRAP_FALL_BACK_THEME);
fileMeta = fallBackTheme.getBootstrap4Theme();
}
}
File file = fileStore.getFile(fileMeta.getId());
return new FileSystemResource(file);
}
use of org.molgenis.security.core.runas.RunAsSystem in project molgenis by molgenis.
the class AbstractRepositoryEntityAnnotator method annotate.
@Override
@Transactional
@RunAsSystem
public Iterator<Entity> annotate(final Iterable<Entity> sourceIterable, boolean updateMode) {
Iterator<Entity> source = sourceIterable.iterator();
return new Iterator<Entity>() {
int current = 0;
int size = 0;
List<Entity> results;
Entity result;
@Override
public boolean hasNext() {
return current < size || source.hasNext();
}
@Override
public Entity next() {
Entity sourceEntity = null;
if (current >= size) {
if (source.hasNext()) {
try {
sourceEntity = source.next();
results = annotateEntity(sourceEntity, updateMode);
} catch (Exception e) {
throw new AnnotationException(sourceEntity, current + 1, getRequiredAttributes(), getSimpleName(), e);
}
size = results.size();
}
current = 0;
}
if (!results.isEmpty()) {
result = results.get(current);
} else {
result = sourceEntity;
}
++current;
return result;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
use of org.molgenis.security.core.runas.RunAsSystem in project molgenis by molgenis.
the class JobExecutor method executeScheduledJob.
/**
* Executes a {@link ScheduledJob} in the current thread.
*
* @param scheduledJobId ID of the {@link ScheduledJob} to run
*/
@RunAsSystem
public void executeScheduledJob(String scheduledJobId) {
ScheduledJob scheduledJob = dataService.findOneById(SCHEDULED_JOB, scheduledJobId, ScheduledJob.class);
JobExecution jobExecution = createJobExecution(scheduledJob);
Job molgenisJob = saveExecutionAndCreateJob(jobExecution);
try {
runJob(jobExecution, molgenisJob);
} catch (Exception ex) {
LOG.error("Error creating job for JobExecution.", ex);
jobExecution.setStatus(JobExecution.Status.FAILED);
jobExecution.setProgressMessage(ex.getMessage());
dataService.update(jobExecution.getEntityType().getId(), jobExecution);
throw ex;
}
}
use of org.molgenis.security.core.runas.RunAsSystem in project molgenis by molgenis.
the class OntologyScriptInitializerImpl method initialize.
@Override
@RunAsSystem
public void initialize() {
Resource resource = new ClassPathResource("roc-curve.R");
if (resource.exists()) {
long count = dataService.count(SCRIPT, new QueryImpl<>().eq(ScriptMetaData.NAME, ROC_CURVE_SCRIPT_NAME));
if (count == 0) {
Entity scriptType = dataService.findOne(ScriptTypeMetaData.SCRIPT_TYPE, new QueryImpl<>().eq(ScriptTypeMetaData.NAME, "R"));
if (scriptType == null)
throw new UnknownEntityException("ScriptType R does not exist!");
String scriptContent;
try {
scriptContent = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream(), "UTF-8"));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
if (dataService.count(SCRIPT_PARAMETER, new QueryImpl<>().eq(ScriptParameterMetaData.NAME, ROC_CURVE_SCRIPT_PARAMETER)) == 0) {
dataService.add(SCRIPT_PARAMETER, scriptParameterFactory.create().setName(ROC_CURVE_SCRIPT_PARAMETER));
}
Entity scriptParameterEntity = dataService.findOne(SCRIPT_PARAMETER, new QueryImpl<>().eq(ScriptParameterMetaData.NAME, ROC_CURVE_SCRIPT_PARAMETER));
Script script = scriptFactory.create();
script.setName(ROC_CURVE_SCRIPT_NAME);
script.setGenerateToken(true);
script.set(ScriptMetaData.TYPE, scriptType);
script.setResultFileExtension("png");
script.setContent(scriptContent);
script.set(ScriptMetaData.PARAMETERS, Arrays.asList(scriptParameterEntity));
dataService.add(SCRIPT, script);
LOG.info("Script entity \"roc\" has been added to the database!");
} else {
LOG.info("Script entity \"roc\" already exists in the database!");
}
} else {
LOG.info("R script \"roc-curve.R\" does not exist on classpath!");
}
}
use of org.molgenis.security.core.runas.RunAsSystem in project molgenis by molgenis.
the class SortaJobFactory method create.
@RunAsSystem
public SortaJobImpl create(SortaJobExecution jobExecution) {
TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
ProgressImpl progress = new ProgressImpl(jobExecution, jobExecutionUpdater, mailSender);
String username = jobExecution.getUser();
RunAsUserToken runAsAuthentication = new RunAsUserToken("Job Execution", username, null, userDetailsService.loadUserByUsername(username).getAuthorities(), null);
SortaJobProcessor matchInputTermBatchService = new SortaJobProcessor(jobExecution.getOntologyIri(), jobExecution.getSourceEntityName(), jobExecution.getResultEntityName(), progress, dataService, sortaService, idGenerator, menuReaderService);
return new SortaJobImpl(matchInputTermBatchService, runAsAuthentication, progress, transactionTemplate);
}
Aggregations