formatting changes on file.
This commit is contained in:
+35
-36
@@ -28,7 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
@Service
|
@Service
|
||||||
public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatformService {
|
public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatformService {
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(RoleWritePlatformServiceJpaRepositoryImpl.class);
|
private final static Logger logger = LoggerFactory.getLogger(RoleWritePlatformServiceJpaRepositoryImpl.class);
|
||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
private final RoleRepository roleRepository;
|
private final RoleRepository roleRepository;
|
||||||
private final PermissionRepository permissionRepository;
|
private final PermissionRepository permissionRepository;
|
||||||
@@ -50,23 +50,22 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
|
|||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult createRole(final JsonCommand command) {
|
public CommandProcessingResult createRole(final JsonCommand command) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
context.authenticatedUser();
|
context.authenticatedUser();
|
||||||
|
|
||||||
this.roleCommandFromApiJsonDeserializer.validateForCreate(command
|
this.roleCommandFromApiJsonDeserializer.validateForCreate(command.json());
|
||||||
.json());
|
|
||||||
|
|
||||||
final Role entity = Role.fromJson(command);
|
final Role entity = Role.fromJson(command);
|
||||||
|
|
||||||
this.roleRepository.save(entity);
|
this.roleRepository.save(entity);
|
||||||
|
|
||||||
return new CommandProcessingResultBuilder()
|
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(entity.getId()).build();
|
||||||
.withCommandId(command.commandId())
|
} catch (DataIntegrityViolationException dve) {
|
||||||
.withEntityId(entity.getId()).build();
|
handleDataIntegrityIssues(command, dve);
|
||||||
} catch (DataIntegrityViolationException dve) {
|
return new CommandProcessingResultBuilder() //
|
||||||
handleDataIntegrityIssues(command, dve);
|
.withCommandId(command.commandId()) //
|
||||||
return CommandProcessingResult.empty();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -79,8 +78,8 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
|
|||||||
if (realCause.getMessage().contains("unq_name")) {
|
if (realCause.getMessage().contains("unq_name")) {
|
||||||
|
|
||||||
final String name = command.stringValueOfParameterNamed("name");
|
final String name = command.stringValueOfParameterNamed("name");
|
||||||
throw new PlatformDataIntegrityException("error.msg.role.duplicate.name", "Role with name `" + name
|
throw new PlatformDataIntegrityException("error.msg.role.duplicate.name", "Role with name `" + name + "` already exists",
|
||||||
+ "` already exists", "name", name);
|
"name", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
logAsErrorUnexpectedDataIntegrityException(dve);
|
logAsErrorUnexpectedDataIntegrityException(dve);
|
||||||
@@ -95,30 +94,30 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
|
|||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult updateRole(final Long roleId, final JsonCommand command) {
|
public CommandProcessingResult updateRole(final Long roleId, final JsonCommand command) {
|
||||||
try {
|
try {
|
||||||
context.authenticatedUser();
|
context.authenticatedUser();
|
||||||
|
|
||||||
this.roleCommandFromApiJsonDeserializer.validateForUpdate(command
|
this.roleCommandFromApiJsonDeserializer.validateForUpdate(command.json());
|
||||||
.json());
|
|
||||||
|
|
||||||
final Role role = this.roleRepository.findOne(roleId);
|
final Role role = this.roleRepository.findOne(roleId);
|
||||||
if (role == null) {
|
if (role == null) { throw new RoleNotFoundException(roleId); }
|
||||||
throw new RoleNotFoundException(roleId);
|
|
||||||
}
|
|
||||||
|
|
||||||
final Map<String, Object> changes = role.update(command);
|
final Map<String, Object> changes = role.update(command);
|
||||||
if (!changes.isEmpty()) {
|
if (!changes.isEmpty()) {
|
||||||
this.roleRepository.saveAndFlush(role);
|
this.roleRepository.saveAndFlush(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CommandProcessingResultBuilder() //
|
return new CommandProcessingResultBuilder() //
|
||||||
.withCommandId(command.commandId()) //
|
.withCommandId(command.commandId()) //
|
||||||
.withEntityId(roleId).with(changes) //
|
.withEntityId(roleId) //
|
||||||
.build();
|
.with(changes) //
|
||||||
} catch (DataIntegrityViolationException dve) {
|
.build();
|
||||||
handleDataIntegrityIssues(command, dve);
|
} catch (DataIntegrityViolationException dve) {
|
||||||
return new CommandProcessingResult(Long.valueOf(-1));
|
handleDataIntegrityIssues(command, dve);
|
||||||
}
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withCommandId(command.commandId()) //
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
|||||||
Reference in New Issue
Block a user