Search in sources :

Example 16 with RunAsSystem

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);
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) FileMeta(org.molgenis.data.file.model.FileMeta) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Example 17 with RunAsSystem

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();
        }
    };
}
Also used : Entity(org.molgenis.data.Entity) Iterator(java.util.Iterator) AnnotationException(org.molgenis.data.annotation.core.exception.AnnotationException) List(java.util.List) AnnotationException(org.molgenis.data.annotation.core.exception.AnnotationException) IOException(java.io.IOException) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with RunAsSystem

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;
    }
}
Also used : JobExecution(org.molgenis.jobs.model.JobExecution) ScheduledJob(org.molgenis.jobs.model.ScheduledJob) ScheduledJob(org.molgenis.jobs.model.ScheduledJob) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Example 19 with RunAsSystem

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!");
    }
}
Also used : Entity(org.molgenis.data.Entity) QueryImpl(org.molgenis.data.support.QueryImpl) InputStreamReader(java.io.InputStreamReader) UnknownEntityException(org.molgenis.data.UnknownEntityException) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ClassPathResource(org.springframework.core.io.ClassPathResource) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Example 20 with RunAsSystem

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);
}
Also used : ProgressImpl(org.molgenis.jobs.ProgressImpl) RunAsUserToken(org.springframework.security.access.intercept.RunAsUserToken) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Aggregations

RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)29 Entity (org.molgenis.data.Entity)12 Transactional (org.springframework.transaction.annotation.Transactional)7 User (org.molgenis.data.security.auth.User)5 QueryImpl (org.molgenis.data.support.QueryImpl)4 UnknownEntityException (org.molgenis.data.UnknownEntityException)3 MolgenisUserException (org.molgenis.security.user.MolgenisUserException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 Stream (java.util.stream.Stream)2 DataService (org.molgenis.data.DataService)2 Fetch (org.molgenis.data.Fetch)2 IndexActionGroup (org.molgenis.data.index.meta.IndexActionGroup)2 INDEX_ACTION_GROUP (org.molgenis.data.index.meta.IndexActionGroupMetaData.INDEX_ACTION_GROUP)2 Token (org.molgenis.data.security.auth.Token)2 ProgressImpl (org.molgenis.jobs.ProgressImpl)2 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)2 RunAsUserToken (org.springframework.security.access.intercept.RunAsUserToken)2