Spring Bootを使用してRest APIを作成し、Hibernate Validationを使用してリクエスト入力を検証しています。
しかし、他の種類の検証も必要です。たとえば、更新データを確認する必要がある場合、会社IDが存在しない場合は、カスタム例外をスローする必要があります。
この検証は、サービス層またはコントローラー層に配置する必要がありますか?
サービス層:
 public Company update(Company entity) {
    if (entity.getId() == null || repository.findOne(entity.getId()) == null) {
        throw new ResourceNotFoundException("can not update un existence data with id : " 
            + entity.getId());
    }
    return repository.saveAndFlush(entity);
}
コントローラー層:
public HttpEntity<CompanyResource> update(@Valid @RequestBody Company companyRequest) {
    Company company = companyService.getById(companyRequest.getId());
    Precondition.checkDataFound(company, 
        "Can't not find data with id : " + companyRequest.getId());
    // TODO : extract ignore properties to constant
    BeanUtils.copyProperties(companyRequest, company, "createdBy", "createdDate",
            "updatedBy", "updatedDate", "version", "markForDelete");
    Company updatedCompany = companyService.update(company);
    CompanyResource companyResource = companyAssembler.toResource(updatedCompany);
    return new ResponseEntity<CompanyResource>(companyResource, HttpStatus.OK);
}