I'm using an optional ID here but I don't like having to declare TWO variables to receive the data. What is a more concise way to accomplish this without having to declare an extra OptionalOrg variable?
Optional<Organization> optionalOrg;
Organization org;
if (request.getOrgId() != null) {
optionalOrg = organizationRepository.findById(request.getOrgId());
} else {
optionalOrg = organizationRepository.findById(DEFAULT_ORG);
}
if (optionalOrg.isPresent()) {
org = optionalOrg.get();
} else {
throw new ClientException("Org not found);
}