use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.
the class GroupLogic method bulkMembersAction.
@PreAuthorize("hasRole('" + StandardEntitlement.TASK_CREATE + "') " + "and hasRole('" + StandardEntitlement.TASK_EXECUTE + "')")
@Transactional
public ExecTO bulkMembersAction(final String key, final BulkMembersActionType actionType) {
Group group = groupDAO.find(key);
if (group == null) {
throw new NotFoundException("Group " + key);
}
Implementation jobDelegate = implementationDAO.find(ImplementationType.TASKJOB_DELEGATE).stream().filter(impl -> GroupMemberProvisionTaskJobDelegate.class.getName().equals(impl.getBody())).findFirst().orElse(null);
if (jobDelegate == null) {
jobDelegate = entityFactory.newEntity(Implementation.class);
jobDelegate.setKey(GroupMemberProvisionTaskJobDelegate.class.getSimpleName());
jobDelegate.setEngine(ImplementationEngine.JAVA);
jobDelegate.setType(ImplementationType.TASKJOB_DELEGATE);
jobDelegate.setBody(GroupMemberProvisionTaskJobDelegate.class.getName());
jobDelegate = implementationDAO.save(jobDelegate);
}
SchedTask task = entityFactory.newEntity(SchedTask.class);
task.setName("Bulk member provision for group " + group.getName());
task.setActive(true);
task.setJobDelegate(jobDelegate);
task = taskDAO.save(task);
try {
Map<String, Object> jobDataMap = jobManager.register(task, null, confDAO.find("tasks.interruptMaxRetries", 1L));
jobDataMap.put(TaskJob.DRY_RUN_JOBDETAIL_KEY, false);
jobDataMap.put(GroupMemberProvisionTaskJobDelegate.GROUP_KEY_JOBDETAIL_KEY, key);
jobDataMap.put(GroupMemberProvisionTaskJobDelegate.ACTION_TYPE_JOBDETAIL_KEY, actionType);
scheduler.getScheduler().triggerJob(JobNamer.getJobKey(task), new JobDataMap(jobDataMap));
} catch (Exception e) {
LOG.error("While executing task {}", task, e);
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling);
sce.getElements().add(e.getMessage());
throw sce;
}
ExecTO result = new ExecTO();
result.setJobType(JobType.TASK);
result.setRefKey(task.getKey());
result.setRefDesc(taskDataBinder.buildRefDesc(task));
result.setStart(new Date());
result.setStatus("JOB_FIRED");
result.setMessage("Job fired; waiting for results...");
return result;
}
use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.
the class ImplementationLogic method read.
@PreAuthorize("hasRole('" + StandardEntitlement.IMPLEMENTATION_READ + "')")
@Transactional(readOnly = true)
public ImplementationTO read(final ImplementationType type, final String key) {
Implementation implementation = implementationDAO.find(key);
if (implementation == null) {
LOG.error("Could not find implementation '" + key + "'");
throw new NotFoundException(key);
}
if (implementation.getType() != type) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest);
sce.getElements().add("Found " + type + ", expected " + implementation.getType());
throw sce;
}
return binder.getImplementationTO(implementation);
}
use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.
the class ImplementationLogic method delete.
@PreAuthorize("hasRole('" + StandardEntitlement.IMPLEMENTATION_DELETE + "')")
public void delete(final ImplementationType type, final String key) {
Implementation implementation = implementationDAO.find(key);
if (implementation == null) {
LOG.error("Could not find implementation '" + key + "'");
throw new NotFoundException(key);
}
if (implementation.getType() != type) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest);
sce.getElements().add("Found " + type + ", expected " + implementation.getType());
throw sce;
}
boolean inUse = false;
switch(implementation.getType()) {
case REPORTLET:
inUse = !reportDAO.findByReportlet(implementation).isEmpty();
break;
case ACCOUNT_RULE:
inUse = !policyDAO.findByAccountRule(implementation).isEmpty();
break;
case PASSWORD_RULE:
inUse = !policyDAO.findByPasswordRule(implementation).isEmpty();
break;
case ITEM_TRANSFORMER:
inUse = !resourceDAO.findByTransformer(implementation).isEmpty();
break;
case TASKJOB_DELEGATE:
inUse = !taskDAO.findByDelegate(implementation).isEmpty();
break;
case RECON_FILTER_BUILDER:
inUse = !taskDAO.findByReconFilterBuilder(implementation).isEmpty();
break;
case LOGIC_ACTIONS:
inUse = !realmDAO.findByLogicActions(implementation).isEmpty();
break;
case PROPAGATION_ACTIONS:
inUse = !resourceDAO.findByPropagationActions(implementation).isEmpty();
break;
case PULL_ACTIONS:
inUse = !taskDAO.findByPullActions(implementation).isEmpty();
break;
case PUSH_ACTIONS:
inUse = !taskDAO.findByPushActions(implementation).isEmpty();
break;
case PULL_CORRELATION_RULE:
inUse = !policyDAO.findByCorrelationRule(implementation).isEmpty();
break;
case VALIDATOR:
inUse = !plainSchemaDAO.findByValidator(implementation).isEmpty();
break;
case RECIPIENTS_PROVIDER:
inUse = !notificationDAO.findByRecipientsProvider(implementation).isEmpty();
break;
default:
}
if (inUse) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InUse);
sce.getElements().add("This implementation is in use");
throw sce;
}
implementationDAO.delete(key);
}
use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.
the class MailTemplateLogic method setFormat.
@PreAuthorize("hasRole('" + StandardEntitlement.MAIL_TEMPLATE_UPDATE + "')")
public void setFormat(final String key, final MailTemplateFormat format, final String template) {
MailTemplate mailTemplate = mailTemplateDAO.find(key);
if (mailTemplate == null) {
LOG.error("Could not find mail template '" + key + "'");
throw new NotFoundException(key);
}
if (format == MailTemplateFormat.HTML) {
mailTemplate.setHTMLTemplate(template);
} else {
mailTemplate.setTextTemplate(template);
}
mailTemplateDAO.save(mailTemplate);
}
use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.
the class MailTemplateLogic method getFormat.
@PreAuthorize("hasRole('" + StandardEntitlement.MAIL_TEMPLATE_READ + "')")
public String getFormat(final String key, final MailTemplateFormat format) {
MailTemplate mailTemplate = mailTemplateDAO.find(key);
if (mailTemplate == null) {
LOG.error("Could not find mail template '" + key + "'");
throw new NotFoundException(key);
}
String template = format == MailTemplateFormat.HTML ? mailTemplate.getHTMLTemplate() : mailTemplate.getTextTemplate();
if (StringUtils.isBlank(template)) {
LOG.error("Could not find mail template '" + key + "' in " + format + " format");
throw new NotFoundException(key + " in " + format);
}
return template;
}
Aggregations