Commit dfa19306 authored by Jyrgen Hannus's avatar Jyrgen Hannus
Browse files

TEIS-1268: added input validation for create official user service

parent 0efd5e36
theGroup=ee.sm.ti.teis
theVersion=1.4.0
theVersion=1.5.0-SNAPSHOT
commonsVersion=1.6.0
officeApiGatewayVersion=1.6.0
pluginVersion=1.0.1
......
......@@ -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