Unverified Commit 692db820 authored by youcefxelians's avatar youcefxelians Committed by GitHub
Browse files

[FIX] Fix write conflict (#563)



Co-authored-by: default avatarJulien CORNILLE <julien.cornille@xelians.fr>
parent 4d1ec7f6
......@@ -56,6 +56,7 @@ import fr.gouv.vitamui.commons.api.logger.VitamUILogger;
import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import fr.gouv.vitamui.commons.api.utils.CriteriaUtils;
import fr.gouv.vitamui.commons.mongo.dao.CustomSequenceRepository;
import fr.gouv.vitamui.commons.mongo.service.SequenceGeneratorService;
import fr.gouv.vitamui.commons.mongo.service.VitamUICrudService;
import fr.gouv.vitamui.commons.security.client.dto.AuthUserDto;
import fr.gouv.vitamui.iam.internal.server.application.converter.ApplicationConverter;
......@@ -80,9 +81,9 @@ public class ApplicationInternalService extends VitamUICrudService<ApplicationDt
private final InternalSecurityService internalSecurityService;
@Autowired
public ApplicationInternalService(final CustomSequenceRepository sequenceRepository, final ApplicationRepository applicationRepository,
public ApplicationInternalService(final SequenceGeneratorService sequenceGeneratorService, final ApplicationRepository applicationRepository,
final ApplicationConverter applicationConverter, final InternalSecurityService internalSecurityService) {
super(sequenceRepository);
super(sequenceGeneratorService);
this.applicationRepository = applicationRepository;
this.applicationConverter = applicationConverter;
this.internalSecurityService = internalSecurityService;
......
......@@ -40,6 +40,7 @@ import fr.gouv.vitamui.commons.api.application.AbstractContextConfiguration;
import fr.gouv.vitamui.commons.api.identity.ServerIdentityConfiguration;
import fr.gouv.vitamui.commons.mongo.config.MongoConfig;
import fr.gouv.vitamui.commons.mongo.dao.CustomSequenceRepository;
import fr.gouv.vitamui.commons.mongo.service.SequenceGeneratorService;
import fr.gouv.vitamui.commons.rest.RestExceptionHandler;
import fr.gouv.vitamui.commons.rest.client.BaseRestClientFactory;
import fr.gouv.vitamui.commons.rest.client.configuration.RestClientConfiguration;
......@@ -209,27 +210,27 @@ public class ApiIamServerConfig extends AbstractContextConfiguration {
}
@Bean
public IdentityProviderInternalService identityProviderCrudService(
final CustomSequenceRepository sequenceRepository,
final IdentityProviderRepository identityProviderRepository, final SpMetadataGenerator spMetadataGenerator,
public SequenceGeneratorService sequenceGeneratorService(
final CustomSequenceRepository sequenceRepository) {
return new SequenceGeneratorService(sequenceRepository);
}
@Bean
public IdentityProviderInternalService identityProviderCrudService(final SequenceGeneratorService sequenceGeneratorService,final IdentityProviderRepository identityProviderRepository, final SpMetadataGenerator spMetadataGenerator,
final CustomerRepository customerRepository, final IamLogbookService iamLogbookService,
final IdentityProviderConverter idpConverter) {
return new IdentityProviderInternalService(sequenceRepository, identityProviderRepository, spMetadataGenerator,
return new IdentityProviderInternalService(sequenceGeneratorService, identityProviderRepository, spMetadataGenerator,
customerRepository, iamLogbookService,
idpConverter);
}
@Bean
public CustomerInternalService customerCrudService(final CustomSequenceRepository sequenceRepository,
final CustomerRepository customerRepository,
final OwnerInternalService internalOwnerService, final UserInternalService userInternalService,
final InternalSecurityService internalSecurityService, final AddressService addressService,
final InitCustomerService initCustomerService,
final IamLogbookService iamLogbookService, final CustomerConverter customerConverter,
final LogbookService logbookService) {
return new CustomerInternalService(sequenceRepository, customerRepository, internalOwnerService,
userInternalService, internalSecurityService,
addressService, initCustomerService, iamLogbookService, customerConverter, logbookService);
public CustomerInternalService customerCrudService(final SequenceGeneratorService sequenceGeneratorService, final CustomerRepository customerRepository,
final OwnerInternalService internalOwnerService, final UserInternalService userInternalService,
final InternalSecurityService internalSecurityService, final AddressService addressService, final InitCustomerService initCustomerService,
final IamLogbookService iamLogbookService, final CustomerConverter customerConverter, final LogbookService logbookService) {
return new CustomerInternalService(sequenceGeneratorService, customerRepository, internalOwnerService, userInternalService, internalSecurityService,
addressService, initCustomerService, iamLogbookService, customerConverter, logbookService);
}
@Bean
......@@ -238,14 +239,14 @@ public class ApiIamServerConfig extends AbstractContextConfiguration {
}
@Bean
public OwnerInternalService ownerCrudService(final CustomSequenceRepository sequenceRepository,
public OwnerInternalService ownerCrudService(final SequenceGeneratorService sequenceGeneratorService,
final OwnerRepository ownerRepository,
final CustomerRepository customerRepository, final AddressService addressService,
final IamLogbookService iamLogbookService,
final InternalSecurityService internalSecurityService, final OwnerConverter ownerConverter,
final LogbookService logbookService,
final TenantRepository tenantRepository) {
return new OwnerInternalService(sequenceRepository, ownerRepository, customerRepository, addressService,
return new OwnerInternalService(sequenceGeneratorService, ownerRepository, customerRepository, addressService,
iamLogbookService, internalSecurityService,
ownerConverter, logbookService, tenantRepository);
}
......@@ -259,7 +260,7 @@ public class ApiIamServerConfig extends AbstractContextConfiguration {
}
@Bean
public TenantInternalService tenantCrudService(final CustomSequenceRepository sequenceRepository,
public TenantInternalService tenantCrudService(final SequenceGeneratorService sequenceGeneratorService,
final TenantRepository tenantRepository,
final CustomerRepository customerRepository, final OwnerRepository ownerRepository,
final GroupRepository groupRepository,
......@@ -273,7 +274,7 @@ public class ApiIamServerConfig extends AbstractContextConfiguration {
final LogbookService logbookService,
final CustomerInitConfig customerInitConfig, final ExternalParametersRepository externalParametersRepository,
final ExternalParametersInternalService externalParametersInternalService) {
return new TenantInternalService(sequenceRepository, tenantRepository, customerRepository, ownerRepository,
return new TenantInternalService(sequenceGeneratorService, tenantRepository, customerRepository, ownerRepository,
groupRepository, profileRepository,
userRepository, internalGroupService, internalUserService, internalOwnerService, internalProfileService,
internalSecurityService,
......@@ -288,7 +289,7 @@ public class ApiIamServerConfig extends AbstractContextConfiguration {
}
@Bean
public UserInternalService userService(final CustomSequenceRepository sequenceRepository,
public UserInternalService userService(final SequenceGeneratorService sequenceGeneratorService,
final UserRepository userRepository,
final ProfileInternalService profileInternalService, final UserEmailInternalService userEmailInternalService,
final TenantRepository tenantRepository, final InternalSecurityService internalSecurityService,
......@@ -300,7 +301,7 @@ public class ApiIamServerConfig extends AbstractContextConfiguration {
final LogbookService logbookService, final AddressService addressService,
final ApplicationInternalService applicationInternalService,
final PasswordConfiguration passwordConfiguration) {
return new UserInternalService(sequenceRepository, userRepository, groupInternalService, profileInternalService,
return new UserInternalService(sequenceGeneratorService, userRepository, groupInternalService, profileInternalService,
userEmailInternalService,
tenantRepository, internalSecurityService, customerRepository, profilRepository, groupRepository,
iamLogbookService, userConverter,
......@@ -316,36 +317,36 @@ public class ApiIamServerConfig extends AbstractContextConfiguration {
}
@Bean
public GroupInternalService groupInternalService(final CustomSequenceRepository sequenceRepository,
public GroupInternalService groupInternalService(final SequenceGeneratorService sequenceGeneratorService,
final GroupRepository groupRepository,
final CustomerRepository customerRepository, final ProfileInternalService internalProfileService,
final UserRepository userRepository,
final InternalSecurityService internalSecurityService, final TenantRepository tenantRepository,
final IamLogbookService iamLogbookService,
final GroupConverter groupConverter, final LogbookService logbookService) {
return new GroupInternalService(sequenceRepository, groupRepository, customerRepository, internalProfileService,
return new GroupInternalService(sequenceGeneratorService, groupRepository, customerRepository, internalProfileService,
userRepository,
internalSecurityService, tenantRepository, iamLogbookService, groupConverter, logbookService);
}
@Bean
public ProfileInternalService profileCrudService(final CustomSequenceRepository sequenceRepository,
public ProfileInternalService profileCrudService(final SequenceGeneratorService sequenceGeneratorService,
final ProfileRepository profileRepository,
final CustomerRepository customerRepository, final GroupRepository groupRepository,
final TenantRepository tenantRepository,
final UserRepository userRepository, final InternalSecurityService internalSecurityService,
final IamLogbookService iamLogbookService,
final ProfileConverter profileConverter, final LogbookService logbookService) {
return new ProfileInternalService(sequenceRepository, profileRepository, customerRepository, groupRepository,
return new ProfileInternalService(sequenceGeneratorService, profileRepository, customerRepository, groupRepository,
tenantRepository, userRepository,
internalSecurityService, iamLogbookService, profileConverter, logbookService);
}
@Bean
public ApplicationInternalService applicationInternalService(final CustomSequenceRepository sequenceRepository,
public ApplicationInternalService applicationInternalService(final SequenceGeneratorService sequenceGeneratorService,
final ApplicationRepository applicationRepository, final ApplicationConverter applicationConverter,
final InternalSecurityService internalSecurityService) {
return new ApplicationInternalService(sequenceRepository, applicationRepository, applicationConverter,
return new ApplicationInternalService(sequenceGeneratorService, applicationRepository, applicationConverter,
internalSecurityService);
}
......@@ -372,7 +373,7 @@ public class ApiIamServerConfig extends AbstractContextConfiguration {
}
@Bean
public SubrogationInternalService subrogationCrudService(final CustomSequenceRepository sequenceRepository,
public SubrogationInternalService subrogationCrudService(final SequenceGeneratorService sequenceGeneratorService,
final SubrogationRepository subrogationRepository, final UserRepository userRepository,
final UserInternalService userInternalService,
final GroupInternalService groupInternalService, final GroupRepository groupRepository,
......@@ -380,7 +381,7 @@ public class ApiIamServerConfig extends AbstractContextConfiguration {
final InternalSecurityService internalSecurityService, final CustomerRepository customerRepository,
final SubrogationConverter subrogationConverter,
final IamLogbookService iamLogbookService) {
return new SubrogationInternalService(sequenceRepository, subrogationRepository, userRepository,
return new SubrogationInternalService(sequenceGeneratorService, subrogationRepository, userRepository,
userInternalService, groupInternalService,
groupRepository, profilRepository, internalSecurityService, customerRepository, subrogationConverter,
iamLogbookService);
......
......@@ -50,6 +50,7 @@ import fr.gouv.vitamui.commons.api.utils.CastUtils;
import fr.gouv.vitamui.commons.api.utils.EnumUtils;
import fr.gouv.vitamui.commons.logbook.dto.EventDiffDto;
import fr.gouv.vitamui.commons.mongo.dao.CustomSequenceRepository;
import fr.gouv.vitamui.commons.mongo.service.SequenceGeneratorService;
import fr.gouv.vitamui.commons.mongo.service.VitamUICrudService;
import fr.gouv.vitamui.commons.utils.VitamUIUtils;
import fr.gouv.vitamui.commons.vitam.api.access.LogbookService;
......@@ -124,13 +125,13 @@ public class CustomerInternalService extends VitamUICrudService<CustomerDto, Cus
private LogbookService logbookService;
@Autowired
public CustomerInternalService(final CustomSequenceRepository sequenceRepository,
public CustomerInternalService(final SequenceGeneratorService sequenceGeneratorService,
final CustomerRepository customerRepository, final OwnerInternalService internalOwnerService,
final UserInternalService userInternalService, final InternalSecurityService internalSecurityService,
final AddressService addressService, final InitCustomerService initCustomerService,
final IamLogbookService iamLogbookService, final CustomerConverter customerConverter,
final LogbookService logbookService) {
super(sequenceRepository);
super(sequenceGeneratorService);
this.customerRepository = customerRepository;
this.internalOwnerService = internalOwnerService;
this.userInternalService = userInternalService;
......
......@@ -50,6 +50,7 @@ import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import fr.gouv.vitamui.commons.mongo.CustomSequencesConstants;
import fr.gouv.vitamui.commons.mongo.dao.CustomSequenceRepository;
import fr.gouv.vitamui.commons.mongo.domain.CustomSequence;
import fr.gouv.vitamui.commons.mongo.service.SequenceGeneratorService;
import fr.gouv.vitamui.iam.common.dto.CustomerDto;
import fr.gouv.vitamui.iam.common.enums.Application;
import fr.gouv.vitamui.iam.internal.server.common.ApiIamInternalConstants;
......@@ -100,7 +101,6 @@ import java.util.stream.Collectors;
@Setter
public class InitCustomerService {
@Autowired
private CustomerRepository customerRepository;
......@@ -141,7 +141,7 @@ public class InitCustomerService {
private GroupInternalService internalGroupService;
@Autowired
private CustomSequenceRepository sequenceRepository;
private SequenceGeneratorService sequenceGeneratorService;
@Autowired
private IamLogbookService iamLogbookService;
......@@ -279,7 +279,7 @@ public class InitCustomerService {
tenant.setOwnerId(ownerId);
tenant.setEnabled(true);
tenant.setReadonly(false);
tenant.setIdentifier(internalTenantService.getNextSequenceId(SequencesConstants.TENANT_IDENTIFIER, 100));
tenant.setIdentifier(internalTenantService.getNextSequenceId(SequencesConstants.TENANT_IDENTIFIER, CustomSequencesConstants.DEFAULT_SEQUENCE_INCREMENT_VALUE));
Tenant createdTenant = initVitamTenantService.init(tenant, fullAccessContractDto);
externalParametersInternalService.create(fullAccessContractDto);
return saveTenant(createdTenant);
......@@ -474,11 +474,7 @@ public class InitCustomerService {
}
protected String generateIdentifier(final String sequenceName) {
final Optional<CustomSequence> customSequence =
sequenceRepository.incrementSequence(sequenceName, CustomSequencesConstants.SEQUENCE_INCREMENT_VALUE);
customSequence
.orElseThrow(() -> new InternalServerException("Sequence with name : " + sequenceName + " didn't exist"));
return String.valueOf(customSequence.get().getSequence());
return String.valueOf(sequenceGeneratorService.getNextSequenceId(sequenceName, CustomSequencesConstants.DEFAULT_SEQUENCE_INCREMENT_VALUE));
}
}
......@@ -51,7 +51,6 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -77,7 +76,7 @@ import fr.gouv.vitamui.commons.api.logger.VitamUILogger;
import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import fr.gouv.vitamui.commons.api.utils.CastUtils;
import fr.gouv.vitamui.commons.logbook.dto.EventDiffDto;
import fr.gouv.vitamui.commons.mongo.dao.CustomSequenceRepository;
import fr.gouv.vitamui.commons.mongo.service.SequenceGeneratorService;
import fr.gouv.vitamui.commons.mongo.service.VitamUICrudService;
import fr.gouv.vitamui.commons.mongo.utils.MongoUtils;
import fr.gouv.vitamui.commons.vitam.api.access.LogbookService;
......@@ -125,11 +124,11 @@ public class GroupInternalService extends VitamUICrudService<GroupDto, Group> {
private LogbookService logbookService;
@Autowired
public GroupInternalService(final CustomSequenceRepository sequenceRepository, final GroupRepository groupRepository,
public GroupInternalService(final SequenceGeneratorService sequenceGeneratorService, final GroupRepository groupRepository,
final CustomerRepository customerRepository, final ProfileInternalService internalProfileService, final UserRepository userRepository,
final InternalSecurityService internalSecurityService, final TenantRepository tenantRepository, final IamLogbookService iamLogbookService,
final GroupConverter groupConverter, final LogbookService logbookService) {
super(sequenceRepository);
super(sequenceGeneratorService);
this.groupRepository = groupRepository;
this.customerRepository = customerRepository;
this.internalProfileService = internalProfileService;
......
......@@ -41,6 +41,8 @@ import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import fr.gouv.vitamui.commons.mongo.service.SequenceGeneratorService;
import fr.gouv.vitamui.iam.common.enums.AuthnRequestBindingEnum;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -54,7 +56,6 @@ import fr.gouv.vitamui.commons.api.converter.Converter;
import fr.gouv.vitamui.commons.api.utils.CastUtils;
import fr.gouv.vitamui.commons.api.utils.EnumUtils;
import fr.gouv.vitamui.commons.logbook.dto.EventDiffDto;
import fr.gouv.vitamui.commons.mongo.dao.CustomSequenceRepository;
import fr.gouv.vitamui.commons.mongo.service.VitamUICrudService;
import fr.gouv.vitamui.iam.common.dto.IdentityProviderDto;
import fr.gouv.vitamui.iam.common.dto.common.ProviderEmbeddedOptions;
......@@ -88,10 +89,10 @@ public class IdentityProviderInternalService extends VitamUICrudService<Identity
private final IdentityProviderConverter idpConverter;
@Autowired
public IdentityProviderInternalService(final CustomSequenceRepository sequenceRepository, final IdentityProviderRepository identityProviderRepository,
public IdentityProviderInternalService(final SequenceGeneratorService sequenceGeneratorService, final IdentityProviderRepository identityProviderRepository,
final SpMetadataGenerator spMetadataGenerator, final CustomerRepository customerRepository, final IamLogbookService iamLogbookService,
final IdentityProviderConverter idpConverter) {
super(sequenceRepository);
super(sequenceGeneratorService);
this.identityProviderRepository = identityProviderRepository;
this.spMetadataGenerator = spMetadataGenerator;
this.customerRepository = customerRepository;
......
......@@ -59,7 +59,7 @@ import fr.gouv.vitamui.commons.api.logger.VitamUILogger;
import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import fr.gouv.vitamui.commons.api.utils.CastUtils;
import fr.gouv.vitamui.commons.logbook.dto.EventDiffDto;
import fr.gouv.vitamui.commons.mongo.dao.CustomSequenceRepository;
import fr.gouv.vitamui.commons.mongo.service.SequenceGeneratorService;
import fr.gouv.vitamui.commons.mongo.service.VitamUICrudService;
import fr.gouv.vitamui.commons.vitam.api.access.LogbookService;
import fr.gouv.vitamui.iam.internal.server.common.domain.Address;
......@@ -109,11 +109,11 @@ public class OwnerInternalService extends VitamUICrudService<OwnerDto, Owner> {
private static final VitamUILogger LOGGER = VitamUILoggerFactory.getInstance(OwnerInternalService.class);
@Autowired
public OwnerInternalService(final CustomSequenceRepository sequenceRepository, final OwnerRepository ownerRepository,
public OwnerInternalService(final SequenceGeneratorService sequenceGeneratorService, final OwnerRepository ownerRepository,
final CustomerRepository customerRepository, final AddressService addressService, final IamLogbookService iamLogbookService,
final InternalSecurityService internalSecurityService, final OwnerConverter ownerConverter, final LogbookService logbookService,
final TenantRepository tenantRepository) {
super(sequenceRepository);
super(sequenceGeneratorService);
this.ownerRepository = ownerRepository;
this.customerRepository = customerRepository;
this.addressService = addressService;
......
......@@ -46,6 +46,7 @@ import java.util.Optional;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import fr.gouv.vitamui.commons.mongo.service.SequenceGeneratorService;
import fr.gouv.vitamui.iam.internal.server.customer.config.CustomerInitConfig;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -72,7 +73,6 @@ import fr.gouv.vitamui.commons.api.logger.VitamUILogger;
import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import fr.gouv.vitamui.commons.api.utils.CastUtils;
import fr.gouv.vitamui.commons.logbook.dto.EventDiffDto;
import fr.gouv.vitamui.commons.mongo.dao.CustomSequenceRepository;
import fr.gouv.vitamui.commons.mongo.service.VitamUICrudService;
import fr.gouv.vitamui.commons.mongo.utils.MongoUtils;
import fr.gouv.vitamui.commons.vitam.api.access.LogbookService;
......@@ -125,11 +125,11 @@ public class ProfileInternalService extends VitamUICrudService<ProfileDto, Profi
private LogbookService logbookService;
@Autowired
public ProfileInternalService(final CustomSequenceRepository sequenceRepository, final ProfileRepository profileRepository,
public ProfileInternalService(final SequenceGeneratorService sequenceGeneratorService, final ProfileRepository profileRepository,
final CustomerRepository customerRepository, final GroupRepository groupRepository, final TenantRepository tenantRepository,
final UserRepository userRepository, final InternalSecurityService internalSecurityService, final IamLogbookService iamLogbookService,
final ProfileConverter profileConverter, final LogbookService logbookService) {
super(sequenceRepository);
super(sequenceGeneratorService);
this.profileRepository = profileRepository;
this.customerRepository = customerRepository;
this.groupRepository = groupRepository;
......
......@@ -42,10 +42,8 @@ import java.util.Optional;
import javax.validation.constraints.NotNull;
import fr.gouv.vitam.common.client.VitamContext;
import fr.gouv.vitamui.commons.api.logger.VitamUILogger;
import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import fr.gouv.vitamui.commons.logbook.service.EventService;
import org.apache.commons.lang.time.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -62,8 +60,8 @@ import fr.gouv.vitamui.commons.api.enums.UserStatusEnum;
import fr.gouv.vitamui.commons.api.enums.UserTypeEnum;
import fr.gouv.vitamui.commons.api.exception.ApplicationServerException;
import fr.gouv.vitamui.commons.logbook.common.EventType;
import fr.gouv.vitamui.commons.mongo.dao.CustomSequenceRepository;
import fr.gouv.vitamui.commons.mongo.repository.VitamUIRepository;
import fr.gouv.vitamui.commons.mongo.service.SequenceGeneratorService;
import fr.gouv.vitamui.commons.mongo.service.VitamUICrudService;
import fr.gouv.vitamui.iam.common.dto.SubrogationDto;
import fr.gouv.vitamui.iam.common.enums.SubrogationStatusEnum;
......@@ -125,11 +123,11 @@ public class SubrogationInternalService extends VitamUICrudService<SubrogationDt
private Integer genericUsersSubrogationTtl;
@Autowired
public SubrogationInternalService(final CustomSequenceRepository sequenceRepository, final SubrogationRepository subrogationRepository,
public SubrogationInternalService(final SequenceGeneratorService sequenceGeneratorService, final SubrogationRepository subrogationRepository,
final UserRepository userRepository, final UserInternalService userInternalService, final GroupInternalService groupInternalService,
final GroupRepository groupRepository, final ProfileRepository profilRepository, final InternalSecurityService internalSecurityService,
final CustomerRepository customerRepository, final SubrogationConverter subrogationConverter, final IamLogbookService iamLogbookService) {
super(sequenceRepository);
super(sequenceGeneratorService);
this.subrogationRepository = subrogationRepository;
this.userRepository = userRepository;
this.userInternalService = userInternalService;
......
......@@ -41,12 +41,7 @@ import fr.gouv.vitam.common.client.VitamContext;
import fr.gouv.vitam.common.exception.VitamClientException;
import fr.gouv.vitamui.commons.api.CommonConstants;
import fr.gouv.vitamui.commons.api.converter.Converter;
import fr.gouv.vitamui.commons.api.domain.ExternalParametersDto;
import fr.gouv.vitamui.commons.api.domain.GroupDto;
import fr.gouv.vitamui.commons.api.domain.OwnerDto;
import fr.gouv.vitamui.commons.api.domain.ServicesData;
import fr.gouv.vitamui.commons.api.domain.TenantDto;
import fr.gouv.vitamui.commons.api.domain.UserDto;
import fr.gouv.vitamui.commons.api.domain.*;
import fr.gouv.vitamui.commons.api.exception.ApplicationServerException;
import fr.gouv.vitamui.commons.api.exception.NotFoundException;
import fr.gouv.vitamui.commons.api.logger.VitamUILogger;
......@@ -54,7 +49,7 @@ import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import fr.gouv.vitamui.commons.api.utils.CastUtils;
import fr.gouv.vitamui.commons.logbook.dto.EventDiffDto;
import fr.gouv.vitamui.commons.mongo.CustomSequencesConstants;
import fr.gouv.vitamui.commons.mongo.dao.CustomSequenceRepository;
import fr.gouv.vitamui.commons.mongo.service.SequenceGeneratorService;
import fr.gouv.vitamui.commons.mongo.service.VitamUICrudService;
import fr.gouv.vitamui.commons.vitam.api.access.LogbookService;
import fr.gouv.vitamui.iam.common.enums.Application;
......@@ -147,7 +142,7 @@ public class TenantInternalService extends VitamUICrudService<TenantDto, Tenant>
private static final VitamUILogger LOGGER = VitamUILoggerFactory.getInstance(TenantInternalService.class);
@Autowired
public TenantInternalService(final CustomSequenceRepository sequenceRepository,
public TenantInternalService(final SequenceGeneratorService sequenceGeneratorService,
final TenantRepository tenantRepository,
final CustomerRepository customerRepository, final OwnerRepository ownerRepository,
final GroupRepository groupRepository,
......@@ -161,7 +156,7 @@ public class TenantInternalService extends VitamUICrudService<TenantDto, Tenant>
final CustomerInitConfig customerInitConfig, final ExternalParametersRepository externalParametersRepository,
final ExternalParametersInternalService externalParametersInternalService
) {
super(sequenceRepository);
super(sequenceGeneratorService);
this.tenantRepository = tenantRepository;
this.customerRepository = customerRepository;
this.ownerRepository = ownerRepository;
......@@ -540,8 +535,8 @@ public class TenantInternalService extends VitamUICrudService<TenantDto, Tenant>
.toJsonNode();
}
private synchronized int generateTenantIdentifier() {
return getNextSequenceId(SequencesConstants.TENANT_IDENTIFIER, 100);
private int generateTenantIdentifier() {
return getNextSequenceId(SequencesConstants.TENANT_IDENTIFIER, CustomSequencesConstants.DEFAULT_SEQUENCE_INCREMENT_VALUE);
}
@Override
......@@ -586,7 +581,7 @@ public class TenantInternalService extends VitamUICrudService<TenantDto, Tenant>
.buildProfile(ExternalParametersInternalService.EXTERNAL_PARAMS_PROFILE_FOR_DEFAULT_ACCESS_CONTRACT + " " +
tenantIdentifier,
String.valueOf(sequenceGeneratorService.getNextSequenceId(SequencesConstants.PROFILE_IDENTIFIER,
CustomSequencesConstants.SEQUENCE_INCREMENT_VALUE.intValue())),
CustomSequencesConstants.DEFAULT_SEQUENCE_INCREMENT_VALUE)),
ExternalParametersInternalService.EXTERNAL_PARAMS_PROFILE_FOR_DEFAULT_ACCESS_CONTRACT + " " +
tenantIdentifier,
true,
......
......@@ -56,7 +56,7 @@ import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import fr.gouv.vitamui.commons.api.utils.CastUtils;
import fr.gouv.vitamui.commons.api.utils.EnumUtils;
import fr.gouv.vitamui.commons.logbook.dto.EventDiffDto;
import fr.gouv.vitamui.commons.mongo.dao.CustomSequenceRepository;
import fr.gouv.vitamui.commons.mongo.service.SequenceGeneratorService;
import fr.gouv.vitamui.commons.mongo.service.VitamUICrudService;
import fr.gouv.vitamui.commons.security.client.config.password.PasswordConfiguration;
import fr.gouv.vitamui.commons.security.client.dto.AuthUserDto;
......@@ -171,14 +171,14 @@ public class UserInternalService extends VitamUICrudService<UserDto, User> {
private static final VitamUILogger LOGGER = VitamUILoggerFactory.getInstance(UserInternalService.class);
@Autowired
public UserInternalService(final CustomSequenceRepository sequenceRepository, final UserRepository userRepository,
public UserInternalService(final SequenceGeneratorService sequenceGeneratorService, final UserRepository userRepository,
final GroupInternalService groupInternalService, final ProfileInternalService profileInternalService,
final UserEmailInternalService userEmailInternalService, final TenantRepository tenantRepository,
final InternalSecurityService internalSecurityService, final CustomerRepository customerRepository, final ProfileRepository profilRepository,
final GroupRepository groupRepository, final IamLogbookService iamLogbookService, final UserConverter userConverter,
final MongoTransactionManager mongoTransactionManager, final LogbookService logbookService, final AddressService addressService,
ApplicationInternalService applicationInternalService, final PasswordConfiguration passwordConfiguration) {
super(sequenceRepository);
super(sequenceGeneratorService);
this.userRepository = userRepository;
this.groupInternalService = groupInternalService;
this.profileInternalService = profileInternalService;
......
......@@ -2,6 +2,7 @@ package fr.gouv.vitamui.iam.internal.server.application.service;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
......@@ -25,8 +26,7 @@ import fr.gouv.vitamui.commons.api.domain.TenantInformationDto;
import fr.gouv.vitamui.commons.api.exception.UnAuthorizedException;
import fr.gouv.vitamui.commons.api.logger.VitamUILogger;
import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import fr.gouv.vitamui.commons.mongo.dao.CustomSequenceRepository;
import fr.gouv.vitamui.commons.mongo.domain.CustomSequence;
import fr.gouv.vitamui.commons.mongo.service.SequenceGeneratorService;
import fr.gouv.vitamui.commons.security.client.dto.AuthUserDto;
import fr.gouv.vitamui.commons.test.utils.ServerIdentityConfigurationBuilder;
import fr.gouv.vitamui.iam.internal.server.application.converter.ApplicationConverter;
......@@ -46,20 +46,17 @@ public class ApplicationInternalServiceTest {
private final ApplicationRepository applicationRepository = mock(ApplicationRepository.class);
private final CustomSequenceRepository sequenceRepository = mock(CustomSequenceRepository.class);
private final SequenceGeneratorService sequenceGeneratorService = mock(SequenceGeneratorService.class);
private final InternalSecurityService internalSecurityService = mock(InternalSecurityService.class);
@Before
public void setup() {
applicationService = new ApplicationInternalService(sequenceRepository, applicationRepository, applicationConverter, internalSecurityService);
applicationService = new ApplicationInternalService(sequenceGeneratorService, applicationRepository, applicationConverter, internalSecurityService);
ServerIdentityConfigurationBuilder.setup("identityName", "identityRole", 1, 0);
final CustomSequence customSequence = new CustomSequence();
customSequence.setSequence(1);
when(sequenceRepository.incrementSequence(any(), any())).thenReturn(Optional.of(customSequence));
when(sequenceGeneratorService.getNextSequenceId(any(), anyInt())).thenReturn(1);
}
@Test
......
package fr.gouv.vitamui.iam.internal.server.customer.service;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;