com.osomapps.pt.reportphoto.ReportPhotoFileResource   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 21
dl 0
loc 26
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A ReportPhotoFileResource(ReportPhotoFileService) 0 3 1
A findOne(String,Long,String,HttpServletResponse) 0 15 1
1
package com.osomapps.pt.reportphoto;
2
3
import java.io.IOException;
4
import javax.servlet.http.HttpServletResponse;
5
import org.springframework.beans.factory.annotation.Autowired;
6
import org.springframework.util.FastByteArrayOutputStream;
7
import org.springframework.web.bind.annotation.GetMapping;
8
import org.springframework.web.bind.annotation.PathVariable;
9
import org.springframework.web.bind.annotation.RequestHeader;
10
import org.springframework.web.bind.annotation.RequestMapping;
11
import org.springframework.web.bind.annotation.ResponseBody;
12
import org.springframework.web.bind.annotation.RestController;
13
14
@RestController
15
@RequestMapping("api/v1/report-photo-file")
16
class ReportPhotoFileResource {
17
18
    private final ReportPhotoFileService reportPhotoFileService;
19
20
    @Autowired
21
    ReportPhotoFileResource(ReportPhotoFileService reportPhotoFileService) {
22
        this.reportPhotoFileService = reportPhotoFileService;
23
    }
24
25
    @GetMapping("{id}/{fileName}")
26
    @ResponseBody
27
    void findOne(
28
            @RequestHeader(value = "X-Token") String token,
29
            @PathVariable Long id,
30
            @PathVariable String fileName,
31
            HttpServletResponse response)
32
            throws IOException {
33
        try (FastByteArrayOutputStream outputStream = new FastByteArrayOutputStream()) {
34
            final ReportPhotoFileDTO reportPhotoFileDTO =
35
                    reportPhotoFileService.findOne(token, id, fileName, outputStream);
36
            response.setContentType(reportPhotoFileDTO.getFileType());
37
            outputStream.writeTo(response.getOutputStream());
38
            response.getOutputStream().close();
39
            outputStream.reset();
40
        }
41
    }
42
}
43