Search in sources :

Example 1 with Propagation

use of org.springframework.transaction.annotation.Propagation in project syncope by apache.

the class JPAUserDAO method findDynRoles.

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true)
@Override
@SuppressWarnings("unchecked")
public List<Role> findDynRoles(final String key) {
    Query query = entityManager().createNativeQuery("SELECT role_id FROM " + JPARoleDAO.DYNMEMB_TABLE + " WHERE any_id=?");
    query.setParameter(1, key);
    List<Role> result = new ArrayList<>();
    query.getResultList().stream().map(resultKey -> resultKey instanceof Object[] ? (String) ((Object[]) resultKey)[0] : ((String) resultKey)).forEachOrdered(actualKey -> {
        Role role = roleDAO.find(actualKey.toString());
        if (role == null) {
            LOG.error("Could not find role with id {}, even though returned by the native query", actualKey);
        } else if (!result.contains(role)) {
            result.add(role);
        }
    });
    return result;
}
Also used : Role(org.apache.syncope.core.persistence.api.entity.Role) AccountRule(org.apache.syncope.core.persistence.api.dao.AccountRule) Date(java.util.Date) Realm(org.apache.syncope.core.persistence.api.entity.Realm) NoResultException(javax.persistence.NoResultException) Autowired(org.springframework.beans.factory.annotation.Autowired) Entity(org.apache.syncope.core.persistence.api.entity.Entity) AnyDeletedEvent(org.apache.syncope.core.provisioning.api.event.AnyDeletedEvent) RoleDAO(org.apache.syncope.core.persistence.api.dao.RoleDAO) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) AnyCreatedUpdatedEvent(org.apache.syncope.core.provisioning.api.event.AnyCreatedUpdatedEvent) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) JPAUser(org.apache.syncope.core.persistence.jpa.entity.user.JPAUser) Repository(org.springframework.stereotype.Repository) EntityViolationType(org.apache.syncope.common.lib.types.EntityViolationType) Role(org.apache.syncope.core.persistence.api.entity.Role) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) Collection(java.util.Collection) Resource(javax.annotation.Resource) Set(java.util.Set) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) AccountPolicyException(org.apache.syncope.core.provisioning.api.utils.policy.AccountPolicyException) Collectors(java.util.stream.Collectors) ImplementationManager(org.apache.syncope.core.spring.ImplementationManager) List(java.util.List) Query(javax.persistence.Query) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) PasswordPolicyException(org.apache.syncope.core.provisioning.api.utils.policy.PasswordPolicyException) Group(org.apache.syncope.core.persistence.api.entity.group.Group) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) StandardEntitlement(org.apache.syncope.common.lib.types.StandardEntitlement) AccessToken(org.apache.syncope.core.persistence.api.entity.AccessToken) TypedQuery(javax.persistence.TypedQuery) JPAAnyUtilsFactory(org.apache.syncope.core.persistence.jpa.entity.JPAAnyUtilsFactory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) Propagation(org.springframework.transaction.annotation.Propagation) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) User(org.apache.syncope.core.persistence.api.entity.user.User) AccessTokenDAO(org.apache.syncope.core.persistence.api.dao.AccessTokenDAO) PasswordRule(org.apache.syncope.core.persistence.api.dao.PasswordRule) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) ApplicationContextProvider(org.apache.syncope.core.spring.ApplicationContextProvider) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) Collections(java.util.Collections) SecurityQuestion(org.apache.syncope.core.persistence.api.entity.user.SecurityQuestion) Transactional(org.springframework.transaction.annotation.Transactional) Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Propagation

use of org.springframework.transaction.annotation.Propagation in project CzechIdMng by bcvsolutions.

the class DefaultSysProvisioningAttributeService method saveAttributes.

/**
 * Provisioning operation is saved in new transaction, attributes has to be saved too.
 */
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void saveAttributes(ProvisioningOperation operation) {
    Assert.notNull(operation, "Operation is required.");
    Assert.notNull(operation.getId(), "Operation identifier is required.");
    // 
    if (operation.getProvisioningContext().getConnectorObject() != null) {
        List<IcAttribute> connectorAttributes = operation.getProvisioningContext().getConnectorObject().getAttributes();
        if (!CollectionUtils.isEmpty(connectorAttributes)) {
            for (IcAttribute connectorAttribute : connectorAttributes) {
                SysProvisioningAttribute provisioningAttribute = new SysProvisioningAttribute(operation.getId(), connectorAttribute.getName());
                if (CollectionUtils.isEmpty(connectorAttribute.getValues())) {
                    provisioningAttribute.setRemoved(true);
                } else {
                    provisioningAttribute.setRemoved(connectorAttribute.getValues().stream().allMatch(v -> {
                        return v == null || StringUtils.isEmpty(v.toString());
                    }));
                }
                repository.save(provisioningAttribute);
            }
        }
    }
}
Also used : SysProvisioningAttribute(eu.bcvsolutions.idm.acc.entity.SysProvisioningAttribute) List(java.util.List) Propagation(org.springframework.transaction.annotation.Propagation) ProvisioningOperation(eu.bcvsolutions.idm.acc.domain.ProvisioningOperation) SysProvisioningAttributeRepository(eu.bcvsolutions.idm.acc.repository.SysProvisioningAttributeRepository) CollectionUtils(org.springframework.util.CollectionUtils) SysProvisioningAttribute(eu.bcvsolutions.idm.acc.entity.SysProvisioningAttribute) Autowired(org.springframework.beans.factory.annotation.Autowired) SysProvisioningAttributeService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningAttributeService) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) StringUtils(org.apache.commons.lang3.StringUtils) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Propagation

use of org.springframework.transaction.annotation.Propagation in project hub-alert by blackducksoftware.

the class DefaultJiraServerJobDetailsAccessor method saveConcreteJobDetails.

@Override
@Transactional(propagation = Propagation.REQUIRED)
public JiraServerJobDetailsModel saveConcreteJobDetails(UUID jobId, JiraServerJobDetailsModel jobDetails) {
    JiraServerJobDetailsEntity jiraServerJobDetailsToSave = new JiraServerJobDetailsEntity(jobId, jobDetails.isAddComments(), jobDetails.getIssueCreatorUsername(), jobDetails.getProjectNameOrKey(), jobDetails.getIssueType(), jobDetails.getResolveTransition(), jobDetails.getReopenTransition(), jobDetails.getIssueSummary());
    JiraServerJobDetailsEntity savedJobDetails = jiraServerJobDetailsRepository.save(jiraServerJobDetailsToSave);
    jiraServerJobCustomFieldRepository.bulkDeleteByJobId(jobId);
    List<JiraServerJobCustomFieldEntity> customFieldsToSave = jobDetails.getCustomFields().stream().map(model -> new JiraServerJobCustomFieldEntity(savedJobDetails.getJobId(), model.getFieldName(), model.getFieldValue())).collect(Collectors.toList());
    List<JiraServerJobCustomFieldEntity> savedJobCustomFields = jiraServerJobCustomFieldRepository.saveAll(customFieldsToSave);
    savedJobDetails.setJobCustomFields(savedJobCustomFields);
    return convertToModel(savedJobDetails);
}
Also used : JiraServerJobCustomFieldRepository(com.synopsys.integration.alert.channel.jira.server.database.job.custom_field.JiraServerJobCustomFieldRepository) JiraServerChannelKey(com.synopsys.integration.alert.descriptor.api.JiraServerChannelKey) JiraServerJobDetailsRepository(com.synopsys.integration.alert.channel.jira.server.database.job.JiraServerJobDetailsRepository) Autowired(org.springframework.beans.factory.annotation.Autowired) UUID(java.util.UUID) DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) JiraJobCustomFieldModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraJobCustomFieldModel) Collectors(java.util.stream.Collectors) List(java.util.List) Component(org.springframework.stereotype.Component) JiraServerJobDetailsEntity(com.synopsys.integration.alert.channel.jira.server.database.job.JiraServerJobDetailsEntity) Propagation(org.springframework.transaction.annotation.Propagation) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Optional(java.util.Optional) JiraServerJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraServerJobDetailsModel) JiraServerJobCustomFieldEntity(com.synopsys.integration.alert.channel.jira.server.database.job.custom_field.JiraServerJobCustomFieldEntity) JiraServerJobDetailsAccessor(com.synopsys.integration.alert.common.persistence.accessor.JiraServerJobDetailsAccessor) Transactional(org.springframework.transaction.annotation.Transactional) JiraServerJobDetailsEntity(com.synopsys.integration.alert.channel.jira.server.database.job.JiraServerJobDetailsEntity) JiraServerJobCustomFieldEntity(com.synopsys.integration.alert.channel.jira.server.database.job.custom_field.JiraServerJobCustomFieldEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Propagation

use of org.springframework.transaction.annotation.Propagation in project hub-alert by blackducksoftware.

the class DefaultEmailJobDetailsAccessor method saveConcreteJobDetails.

@Override
@Transactional(propagation = Propagation.REQUIRED)
public EmailJobDetailsModel saveConcreteJobDetails(UUID jobId, EmailJobDetailsModel jobDetails) {
    EmailJobDetailsEntity jobDetailsToSave = new EmailJobDetailsEntity(jobId, jobDetails.getSubjectLine().orElse(null), jobDetails.isProjectOwnerOnly(), jobDetails.isAdditionalEmailAddressesOnly(), jobDetails.getAttachmentFileType());
    EmailJobDetailsEntity savedJobDetails = emailJobDetailsRepository.save(jobDetailsToSave);
    additionalEmailAddressRepository.bulkDeleteByJobId(jobId);
    List<EmailJobAdditionalEmailAddressEntity> additionalEmailAddressEntitiesToSave = jobDetails.getAdditionalEmailAddresses().stream().map(emailAddress -> new EmailJobAdditionalEmailAddressEntity(jobId, emailAddress)).collect(Collectors.toList());
    List<EmailJobAdditionalEmailAddressEntity> savedAdditionalEmailAddressEntities = additionalEmailAddressRepository.saveAll(additionalEmailAddressEntitiesToSave);
    savedJobDetails.setEmailJobAdditionalEmailAddresses(savedAdditionalEmailAddressEntities);
    return convertToModel(savedJobDetails);
}
Also used : EmailJobAdditionalEmailAddressRepository(com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressRepository) Autowired(org.springframework.beans.factory.annotation.Autowired) EmailChannelKey(com.synopsys.integration.alert.descriptor.api.EmailChannelKey) UUID(java.util.UUID) DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) Collectors(java.util.stream.Collectors) EmailJobDetailsAccessor(com.synopsys.integration.alert.common.persistence.accessor.EmailJobDetailsAccessor) List(java.util.List) Component(org.springframework.stereotype.Component) EmailJobDetailsEntity(com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsEntity) Propagation(org.springframework.transaction.annotation.Propagation) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Optional(java.util.Optional) EmailJobDetailsRepository(com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsRepository) EmailJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel) Transactional(org.springframework.transaction.annotation.Transactional) EmailJobAdditionalEmailAddressEntity(com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressEntity) EmailJobDetailsEntity(com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsEntity) EmailJobAdditionalEmailAddressEntity(com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Propagation

use of org.springframework.transaction.annotation.Propagation in project syncope by apache.

the class JPAAnyObjectDAO method findDynGroups.

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true)
@Override
@SuppressWarnings("unchecked")
public List<Group> findDynGroups(final String key) {
    Query query = entityManager().createNativeQuery("SELECT group_id FROM " + JPAGroupDAO.ADYNMEMB_TABLE + " WHERE any_id=?");
    query.setParameter(1, key);
    List<Group> result = new ArrayList<>();
    query.getResultList().stream().map(resultKey -> resultKey instanceof Object[] ? (String) ((Object[]) resultKey)[0] : ((String) resultKey)).forEachOrdered(actualKey -> {
        Group group = groupDAO().find(actualKey.toString());
        if (group == null) {
            LOG.error("Could not find group with id {}, even though returned by the native query", actualKey);
        } else if (!result.contains(group)) {
            result.add(group);
        }
    });
    return result;
}
Also used : Date(java.util.Date) Realm(org.apache.syncope.core.persistence.api.entity.Realm) NoResultException(javax.persistence.NoResultException) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) JPAAnyObject(org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAnyObject) URelationship(org.apache.syncope.core.persistence.api.entity.user.URelationship) TypedQuery(javax.persistence.TypedQuery) AnyDeletedEvent(org.apache.syncope.core.provisioning.api.event.AnyDeletedEvent) JPAAnyUtilsFactory(org.apache.syncope.core.persistence.jpa.entity.JPAAnyUtilsFactory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) AnyCreatedUpdatedEvent(org.apache.syncope.core.provisioning.api.event.AnyCreatedUpdatedEvent) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) Pair(org.apache.commons.lang3.tuple.Pair) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) Propagation(org.springframework.transaction.annotation.Propagation) Map(java.util.Map) AnyEntitlement(org.apache.syncope.common.lib.types.AnyEntitlement) JPAARelationship(org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAARelationship) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) Repository(org.springframework.stereotype.Repository) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) Collection(java.util.Collection) Set(java.util.Set) JPAURelationship(org.apache.syncope.core.persistence.jpa.entity.user.JPAURelationship) Collectors(java.util.stream.Collectors) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) List(java.util.List) Query(javax.persistence.Query) ARelationship(org.apache.syncope.core.persistence.api.entity.anyobject.ARelationship) Relationship(org.apache.syncope.core.persistence.api.entity.Relationship) Group(org.apache.syncope.core.persistence.api.entity.group.Group) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) ApplicationContextProvider(org.apache.syncope.core.spring.ApplicationContextProvider) Collections(java.util.Collections) Any(org.apache.syncope.core.persistence.api.entity.Any) Transactional(org.springframework.transaction.annotation.Transactional) Group(org.apache.syncope.core.persistence.api.entity.group.Group) TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) JPAAnyObject(org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAnyObject) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

List (java.util.List)7 Propagation (org.springframework.transaction.annotation.Propagation)7 Transactional (org.springframework.transaction.annotation.Transactional)7 Collectors (java.util.stream.Collectors)6 Map (java.util.Map)4 Set (java.util.Set)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 Date (java.util.Date)3 HashSet (java.util.HashSet)3 Optional (java.util.Optional)3 NoResultException (javax.persistence.NoResultException)3 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)2 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)2 UUID (java.util.UUID)2 Query (javax.persistence.Query)2 TypedQuery (javax.persistence.TypedQuery)2 Pair (org.apache.commons.lang3.tuple.Pair)2