Commit 6ed16f1d authored by Enriko Käsper's avatar Enriko Käsper

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Enriko Käsper

See merge request teis/officials-service!40
parents 5c827208 6f9ab64a
theGroup=ee.sm.ti.teis
theVersion=1.4.0
commonsVersion=1.6.0
officeApiGatewayVersion=1.6.0
theVersion=1.5.0
commonsVersion=1.7.0
officeApiGatewayVersion=1.7.0
pluginVersion=1.0.1
mapstructVersion=1.3.0.Final
querydslVersion=4.1.3
......@@ -221,7 +221,11 @@ class OfficialsListenerPrivilegesTest extends OfficialsAppTestBase {
private void verifyCreateOfficialUserIsAllowed(RequestMetaDTO requestMetaDTO) {
CreateOfficialUserRequest request = new CreateOfficialUserRequest();
request.setPayload(new CreateOfficialUserRequest.Parameters(new OfficialUserDto()), requestMetaDTO);
OfficialUserDto officialUser = new OfficialUserDto();
officialUser.setFirstName("tom");
officialUser.setLastName("crank");
officialUser.setIdCode("38912035472");
request.setPayload(new CreateOfficialUserRequest.Parameters(officialUser), requestMetaDTO);
CreateOfficialUserResponse response = listener.create(request);
verify(composeService, times(1)).composeEntity(any(OfficialUserDto.class));
verify(composeService, times(1)).composeDtoWithGroupManager(any());
......
......@@ -7,6 +7,7 @@ import ee.sm.ti.teis.officials.group.service.OfficialsGroupDataService;
import ee.sm.ti.teis.officials.group.service.OfficialsGroupManagerService;
import ee.sm.ti.teis.officials.official.OfficialUserEntity;
import ee.sm.ti.teis.officials.official.OfficialUserRepository;
import ee.sm.ti.teis.officials.official.validator.ValidCreateOfficialUser;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
......@@ -23,6 +24,7 @@ import static ee.sm.ti.teis.types.enums.ObjectStatus.DELETED;
@Service
@Validated
@RequiredArgsConstructor
@Transactional
public class OfficialBusinessService {
private final OfficialUserRepository repository;
......@@ -32,7 +34,7 @@ public class OfficialBusinessService {
private final OfficialDataService dataService;
private final OfficialComposeService composeService;
public OfficialUserDto create(OfficialUserDto dto, RequestMetaDTO requestMetaDTO) {
public OfficialUserDto create(@ValidCreateOfficialUser OfficialUserDto dto, RequestMetaDTO requestMetaDTO) {
OfficialUserEntity entity = composeService.composeEntity(dto);
OfficialUserEntity existingUser = dataService.getByIdCode(entity.getIdCode());
......@@ -54,7 +56,6 @@ public class OfficialBusinessService {
return composeService.composeDtoWithGroupManager(savedEntity);
}
@Transactional
public void delete(UUID id, RequestMetaDTO requestMetaDTO) {
OfficialUserEntity entity = dataService.getOfficialById(id);
......@@ -70,7 +71,6 @@ public class OfficialBusinessService {
notifyService.notifyAuditLogUserDeleted(entity, requestMetaDTO);
}
@Transactional
public OfficialUser updateOfficialUser(OfficialUser domain, RequestMetaDTO requestMetaDTO) {
OfficialUserEntity entity = dataService.getCurrentById(domain.getId());
String initialFirstName = entity.getFirstName();
......@@ -88,7 +88,6 @@ public class OfficialBusinessService {
return updatedDomain;
}
@Transactional
public OfficialUserDto update(UUID userId, UUID groupId, RequestMetaDTO requestMetaDTO) {
OfficialUserEntity entity = dataService.getCurrentById(userId);
if (entity.getOfficialsGroup() != null && entity.getOfficialsGroup().getId().equals(groupId)) {
......
package ee.sm.ti.teis.officials.official.validator;
import ee.sm.ti.teis.officegateway.official.dto.OfficialUserDto;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import static org.springframework.util.StringUtils.isEmpty;
public class CreateOfficialUserValidator implements ConstraintValidator<ValidCreateOfficialUser, OfficialUserDto> {
@Override
public boolean isValid(OfficialUserDto dto, ConstraintValidatorContext context) {
return !isEmpty(dto.getFirstName()) && !isEmpty(dto.getLastName()) && !isEmpty(dto.getIdCode());
}
}
package ee.sm.ti.teis.officials.official.validator;
import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Constraint(validatedBy = CreateOfficialUserValidator.class)
@Target({PARAMETER})
@Retention(RUNTIME)
@Documented
public @interface ValidCreateOfficialUser {
String message() default "Field validation error";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment