Search in sources :

Example 16 with Entity

use of org.apache.syncope.core.persistence.api.entity.Entity in project syncope by apache.

the class MailTemplateLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.MAIL_TEMPLATE_DELETE + "')")
public MailTemplateTO delete(final String key) {
    MailTemplate mailTemplate = mailTemplateDAO.find(key);
    if (mailTemplate == null) {
        LOG.error("Could not find mail template '" + key + "'");
        throw new NotFoundException(key);
    }
    List<Notification> notifications = notificationDAO.findByTemplate(mailTemplate);
    if (!notifications.isEmpty()) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InUse);
        sce.getElements().addAll(notifications.stream().map(Entity::getKey).collect(Collectors.toList()));
        throw sce;
    }
    MailTemplateTO deleted = getMailTemplateTO(key);
    mailTemplateDAO.delete(key);
    return deleted;
}
Also used : Entity(org.apache.syncope.core.persistence.api.entity.Entity) MailTemplateTO(org.apache.syncope.common.lib.to.MailTemplateTO) MailTemplate(org.apache.syncope.core.persistence.api.entity.MailTemplate) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Notification(org.apache.syncope.core.persistence.api.entity.Notification) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 17 with Entity

use of org.apache.syncope.core.persistence.api.entity.Entity in project syncope by apache.

the class JPAConnInstanceDAO method delete.

@Override
public void delete(final String key) {
    ConnInstance connInstance = find(key);
    if (connInstance == null) {
        return;
    }
    connInstance.getResources().stream().map(Entity::getKey).collect(Collectors.toList()).forEach(resource -> resourceDAO.delete(resource));
    connInstanceHistoryConfDAO.deleteByEntity(connInstance);
    entityManager().remove(connInstance);
    connRegistry.unregisterConnector(key);
}
Also used : Entity(org.apache.syncope.core.persistence.api.entity.Entity) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) JPAConnInstance(org.apache.syncope.core.persistence.jpa.entity.JPAConnInstance)

Aggregations

Entity (org.apache.syncope.core.persistence.api.entity.Entity)17 Collectors (java.util.stream.Collectors)5 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)5 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 List (java.util.List)4 AnyTypeDAO (org.apache.syncope.core.persistence.api.dao.AnyTypeDAO)4 Realm (org.apache.syncope.core.persistence.api.entity.Realm)4 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 User (org.apache.syncope.core.persistence.api.entity.user.User)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 StringUtils (org.apache.commons.lang3.StringUtils)2 SyncopeClientCompositeException (org.apache.syncope.common.lib.SyncopeClientCompositeException)2 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)2 ClientExceptionType (org.apache.syncope.common.lib.types.ClientExceptionType)2