fix broken build due to small logging error detected by SpotBugs
significant reformatting due to Eclipse auto-save action (someone really needs to finish the Checkstyle uniform formatting) see https://github.com/apache/fineract/pull/592
This commit is contained in:
committed by
Michael Vorburger ⛑️
parent
b9b265b915
commit
b1eb62f221
+87
-89
@@ -48,108 +48,106 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
@Service
|
@Service
|
||||||
public class RateWriteServiceImpl implements RateWriteService {
|
public class RateWriteServiceImpl implements RateWriteService {
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory
|
private final static Logger logger = LoggerFactory.getLogger(RateWriteServiceImpl.class);
|
||||||
.getLogger(RateWriteServiceImpl.class);
|
|
||||||
private final RateRepository rateRepository;
|
|
||||||
private final AppUserRepository appUserRepository;
|
|
||||||
private final PlatformSecurityContext context;
|
|
||||||
private final RateDefinitionCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
|
||||||
|
|
||||||
@Autowired
|
private final RateRepository rateRepository;
|
||||||
public RateWriteServiceImpl(RateRepository rateRepository, AppUserRepository appUserRepository,
|
private final AppUserRepository appUserRepository;
|
||||||
final RateDefinitionCommandFromApiJsonDeserializer fromApiJsonDeserializer,
|
private final PlatformSecurityContext context;
|
||||||
PlatformSecurityContext context) {
|
private final RateDefinitionCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
||||||
this.rateRepository = rateRepository;
|
|
||||||
this.appUserRepository = appUserRepository;
|
|
||||||
this.context = context;
|
|
||||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Autowired
|
||||||
public CommandProcessingResult createRate(JsonCommand command) {
|
public RateWriteServiceImpl(RateRepository rateRepository, AppUserRepository appUserRepository,
|
||||||
try {
|
final RateDefinitionCommandFromApiJsonDeserializer fromApiJsonDeserializer,
|
||||||
this.context.authenticatedUser();
|
PlatformSecurityContext context) {
|
||||||
this.fromApiJsonDeserializer.validateForCreate(command.json());
|
this.rateRepository = rateRepository;
|
||||||
|
this.appUserRepository = appUserRepository;
|
||||||
final Long approveUserId = command.longValueOfParameterNamed(approveUserIdParamName);
|
this.context = context;
|
||||||
AppUser approveUser = null;
|
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||||
if (approveUserId != null) {
|
|
||||||
approveUser = this.appUserRepository.findById(approveUserId).orElseThrow(() -> new UserNotFoundException(approveUserId));
|
|
||||||
}
|
|
||||||
final Rate rate = Rate.fromJson(command, approveUser);
|
|
||||||
|
|
||||||
this.rateRepository.save(rate);
|
|
||||||
|
|
||||||
return new CommandProcessingResultBuilder().withCommandId(command.commandId())
|
|
||||||
.withEntityId(rate.getId()).build();
|
|
||||||
|
|
||||||
} catch (final DataIntegrityViolationException dve) {
|
|
||||||
handleRateDataIntegrityIssues(command, dve.getMostSpecificCause(), dve);
|
|
||||||
return CommandProcessingResult.empty();
|
|
||||||
} catch (final PersistenceException dve) {
|
|
||||||
Throwable throwable = ExceptionUtils.getRootCause(dve.getCause());
|
|
||||||
handleRateDataIntegrityIssues(command, throwable, dve);
|
|
||||||
return CommandProcessingResult.empty();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
@Override
|
||||||
@Override
|
public CommandProcessingResult createRate(JsonCommand command) {
|
||||||
public CommandProcessingResult updateRate(final Long rateId, final JsonCommand command) {
|
try {
|
||||||
try {
|
this.context.authenticatedUser();
|
||||||
this.context.authenticatedUser();
|
this.fromApiJsonDeserializer.validateForCreate(command.json());
|
||||||
|
|
||||||
final Rate rateToUpdate = this.rateRepository.findById(rateId).orElseThrow(() -> new RateNotFoundException(rateId));
|
final Long approveUserId = command.longValueOfParameterNamed(approveUserIdParamName);
|
||||||
|
AppUser approveUser = null;
|
||||||
|
if (approveUserId != null) {
|
||||||
|
approveUser = this.appUserRepository.findById(approveUserId).orElseThrow(() -> new UserNotFoundException(approveUserId));
|
||||||
|
}
|
||||||
|
final Rate rate = Rate.fromJson(command, approveUser);
|
||||||
|
|
||||||
final Map<String, Object> changes = rateToUpdate.update(command);
|
this.rateRepository.save(rate);
|
||||||
|
|
||||||
this.fromApiJsonDeserializer.validateForUpdate(command.json());
|
return new CommandProcessingResultBuilder().withCommandId(command.commandId())
|
||||||
|
.withEntityId(rate.getId()).build();
|
||||||
|
|
||||||
if (changes.containsKey(approveUserIdParamName)) {
|
} catch (final DataIntegrityViolationException dve) {
|
||||||
final Long newApproveUserId = (Long) changes.get(approveUserIdParamName);
|
handleRateDataIntegrityIssues(command, dve.getMostSpecificCause(), dve);
|
||||||
AppUser newApproveUser = null;
|
return CommandProcessingResult.empty();
|
||||||
if (newApproveUserId != null) {
|
} catch (final PersistenceException dve) {
|
||||||
newApproveUser = this.appUserRepository.findById(newApproveUserId).orElseThrow(() -> new UserNotFoundException(newApproveUserId));
|
Throwable throwable = ExceptionUtils.getRootCause(dve.getCause());
|
||||||
|
handleRateDataIntegrityIssues(command, throwable, dve);
|
||||||
|
return CommandProcessingResult.empty();
|
||||||
}
|
}
|
||||||
rateToUpdate.setApproveUser(newApproveUser);
|
|
||||||
}
|
|
||||||
if (!changes.isEmpty()) {
|
|
||||||
this.rateRepository.saveAndFlush(rateToUpdate);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CommandProcessingResultBuilder() //
|
|
||||||
.withCommandId(command.commandId()) //
|
|
||||||
.withEntityId(rateId) //
|
|
||||||
.with(changes) //
|
|
||||||
.build();
|
|
||||||
|
|
||||||
} catch (final DataIntegrityViolationException dve) {
|
|
||||||
handleRateDataIntegrityIssues(command, dve.getMostSpecificCause(), dve);
|
|
||||||
return new CommandProcessingResult(Long.valueOf(-1));
|
|
||||||
} catch (final PersistenceException dve) {
|
|
||||||
Throwable throwable = ExceptionUtils.getRootCause(dve.getCause());
|
|
||||||
handleRateDataIntegrityIssues(command, throwable, dve);
|
|
||||||
return CommandProcessingResult.empty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public CommandProcessingResult updateRate(final Long rateId, final JsonCommand command) {
|
||||||
|
try {
|
||||||
|
this.context.authenticatedUser();
|
||||||
|
|
||||||
/*
|
final Rate rateToUpdate = this.rateRepository.findById(rateId).orElseThrow(() -> new RateNotFoundException(rateId));
|
||||||
* Guaranteed to throw an exception no matter what the data integrity issue
|
|
||||||
* is.
|
final Map<String, Object> changes = rateToUpdate.update(command);
|
||||||
*/
|
|
||||||
private void handleRateDataIntegrityIssues(final JsonCommand command, final Throwable realCause,
|
this.fromApiJsonDeserializer.validateForUpdate(command.json());
|
||||||
final Exception dve) {
|
|
||||||
if (realCause.getMessage().contains("rate_name_org")) {
|
if (changes.containsKey(approveUserIdParamName)) {
|
||||||
final String name = command.stringValueOfParameterNamed("name");
|
final Long newApproveUserId = (Long) changes.get(approveUserIdParamName);
|
||||||
throw new PlatformDataIntegrityException("error.msg.fund.duplicate.externalId",
|
AppUser newApproveUser = null;
|
||||||
"A rate with name '" + name
|
if (newApproveUserId != null) {
|
||||||
+ "' already exists", "name", name);
|
newApproveUser = this.appUserRepository.findById(newApproveUserId).orElseThrow(() -> new UserNotFoundException(newApproveUserId));
|
||||||
|
}
|
||||||
|
rateToUpdate.setApproveUser(newApproveUser);
|
||||||
|
}
|
||||||
|
if (!changes.isEmpty()) {
|
||||||
|
this.rateRepository.saveAndFlush(rateToUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withCommandId(command.commandId()) //
|
||||||
|
.withEntityId(rateId) //
|
||||||
|
.with(changes) //
|
||||||
|
.build();
|
||||||
|
|
||||||
|
} catch (final DataIntegrityViolationException dve) {
|
||||||
|
handleRateDataIntegrityIssues(command, dve.getMostSpecificCause(), dve);
|
||||||
|
return new CommandProcessingResult((long) -1);
|
||||||
|
} catch (final PersistenceException dve) {
|
||||||
|
Throwable throwable = ExceptionUtils.getRootCause(dve.getCause());
|
||||||
|
handleRateDataIntegrityIssues(command, throwable, dve);
|
||||||
|
return CommandProcessingResult.empty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.error(dve.getMessage(), dve);
|
/*
|
||||||
throw new PlatformDataIntegrityException("error.msg.fund.unknown.data.integrity.issue",
|
* Guaranteed to throw an exception no matter what the data integrity issue
|
||||||
"Unknown data integrity issue with resource: " + realCause.getMessage());
|
* is.
|
||||||
}
|
*/
|
||||||
|
private void handleRateDataIntegrityIssues(final JsonCommand command, final Throwable realCause,
|
||||||
|
final Exception dve) {
|
||||||
|
if (realCause.getMessage().contains("rate_name_org")) {
|
||||||
|
final String name = command.stringValueOfParameterNamed("name");
|
||||||
|
throw new PlatformDataIntegrityException("error.msg.fund.duplicate.externalId",
|
||||||
|
"A rate with name '" + name
|
||||||
|
+ "' already exists", "name", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.error("Error due to Exception", dve);
|
||||||
|
throw new PlatformDataIntegrityException("error.msg.fund.unknown.data.integrity.issue",
|
||||||
|
"Unknown data integrity issue with resource: " + realCause.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user