use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.
the class JobScheduler method runNow.
/**
* Executes a {@link ScheduledJob} immediately.
*
* @param scheduledJobId ID of the {@link ScheduledJob} to run
*/
public synchronized void runNow(String scheduledJobId) {
ScheduledJob scheduledJob = getJob(scheduledJobId);
try {
JobKey jobKey = new JobKey(scheduledJobId, SCHEDULED_JOB_GROUP);
if (quartzScheduler.checkExists(jobKey)) {
// Run job now
quartzScheduler.triggerJob(jobKey);
} else {
// Schedule with 'now' trigger
Trigger trigger = newTrigger().withIdentity(scheduledJobId, SCHEDULED_JOB_GROUP).startNow().build();
schedule(scheduledJob, trigger);
}
} catch (SchedulerException e) {
LOG.error("Error runNow ScheduledJob", e);
throw new MolgenisDataException("Error job runNow", e);
}
}
use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.
the class PostgreSqlUtils method getPostgreSqlQueryValue.
/**
* Returns the PostgreSQL query value for the given entity attribute. For query operators requiring a list of
* values (e.g. IN or RANGE) this method must be called for each individual query value.
*
* @param queryValue value of the type that matches the attribute type
* @param attr attribute
* @return PostgreSQL value
*/
static Object getPostgreSqlQueryValue(Object queryValue, Attribute attr) {
while (true) {
String attrName = attr.getName();
AttributeType attrType = attr.getDataType();
switch(attrType) {
case BOOL:
if (queryValue != null && !(queryValue instanceof Boolean)) {
throw new MolgenisDataException(format("Attribute [%s] query value is of type [%s] instead of [%s]", attrName, queryValue.getClass().getSimpleName(), Boolean.class.getSimpleName()));
}
return queryValue;
case CATEGORICAL:
// one query value
case CATEGORICAL_MREF:
case FILE:
// one query value
case MREF:
case XREF:
case ONE_TO_MANY:
// queries values referencing an entity can either be the entity itself or the entity id
if (queryValue != null) {
if (queryValue instanceof Entity) {
queryValue = ((Entity) queryValue).getIdValue();
}
attr = attr.getRefEntity().getIdAttribute();
continue;
} else {
return null;
}
case DATE:
if (queryValue != null && !(queryValue instanceof LocalDate)) {
throw new MolgenisDataException(format("Attribute [%s] query value is of type [%s] instead of [%s]", attrName, queryValue.getClass().getSimpleName(), LocalDate.class.getSimpleName()));
}
return queryValue;
case DATE_TIME:
if (queryValue == null) {
return null;
}
if (!(queryValue instanceof Instant)) {
throw new MolgenisDataException(format("Attribute [%s] query value is of type [%s] instead of [%s]", attrName, queryValue.getClass().getSimpleName(), Instant.class.getSimpleName()));
}
return ((Instant) queryValue).atOffset(UTC);
case DECIMAL:
if (queryValue != null && !(queryValue instanceof Double)) {
throw new MolgenisDataException(format("Attribute [%s] query value is of type [%s] instead of [%s]", attrName, queryValue.getClass().getSimpleName(), Double.class.getSimpleName()));
}
return queryValue;
case ENUM:
// enum query values can be an enum or enum string
if (queryValue != null) {
if (queryValue instanceof String) {
return queryValue;
} else if (queryValue instanceof Enum<?>) {
return queryValue.toString();
} else {
throw new MolgenisDataException(format("Attribute [%s] query value is of type [%s] instead of [%s] or [%s]", attrName, queryValue.getClass().getSimpleName(), String.class.getSimpleName(), Enum.class.getSimpleName()));
}
} else {
return null;
}
case EMAIL:
case HTML:
case HYPERLINK:
case SCRIPT:
case STRING:
case TEXT:
if (queryValue != null && !(queryValue instanceof String)) {
throw new MolgenisDataException(format("Attribute [%s] query value is of type [%s] instead of [%s]", attrName, queryValue.getClass().getSimpleName(), String.class.getSimpleName()));
}
return queryValue;
case INT:
if (queryValue != null && !(queryValue instanceof Integer)) {
throw new MolgenisDataException(format("Attribute [%s] query value is of type [%s] instead of [%s]", attrName, queryValue.getClass().getSimpleName(), Integer.class.getSimpleName()));
}
return queryValue;
case LONG:
if (queryValue != null && !(queryValue instanceof Long)) {
throw new MolgenisDataException(format("Attribute [%s] query value is of type [%s] instead of [%s]", attrName, queryValue.getClass().getSimpleName(), Long.class.getSimpleName()));
}
return queryValue;
case COMPOUND:
throw new RuntimeException(format("Illegal attribute type [%s]", attrType.toString()));
default:
throw new UnexpectedEnumException(attrType);
}
}
}
use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.
the class MappingProjectRepositoryImpl method update.
@Override
@Transactional
public void update(MappingProject mappingProject) {
MappingProject existing = getMappingProject(mappingProject.getIdentifier());
if (existing == null) {
throw new MolgenisDataException("MappingProject does not exist");
}
Entity mappingProjectEntity = toEntity(mappingProject);
dataService.update(MAPPING_PROJECT, mappingProjectEntity);
}
use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.
the class FileRepositoryCollectionFactory method createFileRepositoryCollection.
/**
* Factory method for creating a new FileRepositorySource
* <p>
* For example an excel file
*/
public FileRepositoryCollection createFileRepositoryCollection(File file) {
Class<? extends FileRepositoryCollection> clazz;
String extension = FileExtensionUtils.findExtensionFromPossibilities(file.getName(), fileRepositoryCollection.keySet());
clazz = fileRepositoryCollection.get(extension);
if (clazz == null) {
throw new MolgenisDataException("Unknown extension for file '" + file.getName() + "'");
}
Constructor<? extends FileRepositoryCollection> ctor;
try {
ctor = clazz.getConstructor(File.class);
} catch (Exception e) {
throw new MolgenisDataException("Exception creating [" + clazz + "] missing constructor FileRepositorySource(File file)");
}
FileRepositoryCollection fileRepositoryCollection = BeanUtils.instantiateClass(ctor, file);
autowireCapableBeanFactory.autowireBeanProperties(fileRepositoryCollection, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
try {
fileRepositoryCollection.init();
} catch (IOException e) {
throw new RuntimeException(e);
}
return fileRepositoryCollection;
}
use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.
the class ImportRunService method createAndSendStatusMail.
private void createAndSendStatusMail(ImportRun importRun) {
try {
SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setTo(userService.getUser(importRun.getUsername()).getEmail());
mailMessage.setSubject(createMailTitle(importRun));
mailMessage.setText(createEnglishMailText(importRun, ZoneId.systemDefault()));
mailSender.send(mailMessage);
} catch (MailException mce) {
LOG.error("Could not send import status mail", mce);
throw new MolgenisDataException("An error occurred. Please contact the administrator.");
}
}
Aggregations