Skip to content

Instantly share code, notes, and snippets.

@adilkurniaramdan
Created November 13, 2015 08:12
Show Gist options
  • Save adilkurniaramdan/00e2e4659c8c5baf5221 to your computer and use it in GitHub Desktop.
Save adilkurniaramdan/00e2e4659c8c5baf5221 to your computer and use it in GitHub Desktop.
package com.qinti.eptp.web.rest.report;
import com.qinti.eptp.domain.user.EPerusahaan;
import com.qinti.eptp.domain.user.User;
import com.qinti.eptp.exception.ResourceNotFoundException;
import com.qinti.eptp.repository.buktipotong.BPA1Repository;
import com.qinti.eptp.repository.user.UserRepository;
import com.qinti.eptp.security.SecurityUtils;
import com.qinti.eptp.service.DirectoryService;
import com.qinti.eptp.service.report.*;
import com.qinti.eptp.util.Constant;
import net.sf.dynamicreports.report.exception.DRException;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
/**
* Created by adildramdan on 6/12/15.
*/
@RestController
@RequestMapping("/report/api")
public class Report21Resource {
@Inject
R1721A1Service r1721A1Service;
@Inject
R1721A2Service r1721A2Service;
@Inject
R1721ISatuMasaService r1721ISatuMasaService;
@Inject
R1721ISatuTahunService r1721ISatuTahunService;
@Inject
R1721IIService r1721IIService;
@Inject
R1721IIIService r1721IIIService;
@Inject
R1721IVService r1721IVService;
@Inject
R1721VService r1721VService;
@Inject
R1721VIService r1721VIService;
@Inject
R1721VIIService r1721VIIService;
@Inject
R1721SPTIndukService r1721SPTIndukService;
@Inject
R1721SPTIndukP2Service r1721SPTIndukP2Service;
@Inject
DirectoryService directoryService;
@Inject
UserRepository userRepository;
@Inject
BPA1Repository bpa1Repository;
@RequestMapping(value = "/report21/1721A1/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<?> generate1721A1(@PathVariable("id") String id) throws IOException, DRException {
String perusahaanId = userRepository.findOneByLogin(SecurityUtils.getCurrentLogin())
.map(User::getePerusahaan)
.map(EPerusahaan::getId)
.orElseThrow(ResourceNotFoundException::new);
String fileName = directoryService.createFileName(Constant.REPORT_KODE.A1, DirectoryService.pdf);
String pdfFile = directoryService.createFile(Constant.DIR.REPORT, fileName, perusahaanId);
File pdf = r1721A1Service.generateReport(id, pdfFile);
FileSystemResource isr = new FileSystemResource(pdf);
HttpHeaders respHeaders = new HttpHeaders();
respHeaders.setContentType(MediaType.parseMediaType("application/pdf"));
respHeaders.setContentLength(isr.contentLength());
respHeaders.setContentDispositionFormData("attachment", fileName);
return new ResponseEntity<>(isr, respHeaders, HttpStatus.OK);
}
@RequestMapping(value = "/report21/1721A2/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<?> generate1721A2(@PathVariable("id") String id) throws IOException, DRException {
String perusahaanId = userRepository.findOneByLogin(SecurityUtils.getCurrentLogin())
.map(User::getePerusahaan)
.map(EPerusahaan::getId)
.orElseThrow(ResourceNotFoundException::new);
String fileName = directoryService.createFileName(Constant.REPORT_KODE.A2, DirectoryService.pdf);
String pdfFile = directoryService.createFile(Constant.DIR.REPORT, fileName, perusahaanId);
File pdf = r1721A2Service.generateReport(id, pdfFile);
FileSystemResource isr = new FileSystemResource(pdf);
HttpHeaders respHeaders = new HttpHeaders();
respHeaders.setContentType(MediaType.parseMediaType("application/pdf"));
respHeaders.setContentLength(isr.contentLength());
respHeaders.setContentDispositionFormData("attachment", fileName);
return new ResponseEntity<>(isr, respHeaders, HttpStatus.OK);
}
@RequestMapping(value = "/report21/1721ISatuMasa/{esptId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<?> generate1721ISatuMasa(@PathVariable("esptId") String esptId) throws IOException, DRException {
String perusahaanId = userRepository.findOneByLogin(SecurityUtils.getCurrentLogin())
.map(User::getePerusahaan)
.map(EPerusahaan::getId)
.orElseThrow(ResourceNotFoundException::new);
String fileName = directoryService.createFileName(Constant.REPORT_KODE.DPSM, DirectoryService.pdf);
String pdfFile = directoryService.createFile(Constant.DIR.REPORT, fileName, perusahaanId);
File pdf = r1721ISatuMasaService.generateReport(esptId, perusahaanId, pdfFile);
FileSystemResource isr = new FileSystemResource(pdf);
HttpHeaders respHeaders = new HttpHeaders();
respHeaders.setContentType(MediaType.parseMediaType("application/pdf"));
respHeaders.setContentLength(isr.contentLength());
respHeaders.setContentDispositionFormData("attachment", fileName);
return new ResponseEntity<>(isr, respHeaders, HttpStatus.OK);
}
@RequestMapping(value = "/report21/1721ISatuTahun/{esptId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<?> generate1721ISatuTahun(@PathVariable("esptId") String esptId) throws IOException, DRException {
String perusahaanId = userRepository.findOneByLogin(SecurityUtils.getCurrentLogin())
.map(User::getePerusahaan)
.map(EPerusahaan::getId)
.orElseThrow(ResourceNotFoundException::new);
String fileName = directoryService.createFileName(Constant.REPORT_KODE.DPST, DirectoryService.pdf);
String pdfFile = directoryService.createFile(Constant.DIR.REPORT, fileName, perusahaanId);
File pdf = r1721ISatuTahunService.generateReport(esptId, perusahaanId, pdfFile);
FileSystemResource isr = new FileSystemResource(pdf);
HttpHeaders respHeaders = new HttpHeaders();
respHeaders.setContentType(MediaType.parseMediaType("application/pdf"));
respHeaders.setContentLength(isr.contentLength());
respHeaders.setContentDispositionFormData("attachment", fileName);
return new ResponseEntity<>(isr, respHeaders, HttpStatus.OK);
}
@RequestMapping(value = "/report21/1721II/{esptId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<?> generate1721II(@PathVariable("esptId") String esptId) throws IOException, DRException {
String perusahaanId = userRepository.findOneByLogin(SecurityUtils.getCurrentLogin())
.map(User::getePerusahaan)
.map(EPerusahaan::getId)
.orElseThrow(ResourceNotFoundException::new);
String fileName = directoryService.createFileName(Constant.REPORT_KODE.TF, DirectoryService.pdf);
String pdfFile = directoryService.createFile(Constant.DIR.REPORT, fileName, perusahaanId);
File pdf = r1721IIService.generateReport(esptId, perusahaanId, pdfFile);
FileSystemResource isr = new FileSystemResource(pdf);
HttpHeaders respHeaders = new HttpHeaders();
respHeaders.setContentType(MediaType.parseMediaType("application/pdf"));
respHeaders.setContentLength(isr.contentLength());
respHeaders.setContentDispositionFormData("attachment", fileName);
return new ResponseEntity<>(isr, respHeaders, HttpStatus.OK);
}
@RequestMapping(value = "/report21/1721III/{esptId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<?> generate1721III(@PathVariable("esptId") String esptId) throws IOException, DRException {
String perusahaanId = userRepository.findOneByLogin(SecurityUtils.getCurrentLogin())
.map(User::getePerusahaan)
.map(EPerusahaan::getId)
.orElseThrow(ResourceNotFoundException::new);
String fileName = directoryService.createFileName(Constant.REPORT_KODE.F, DirectoryService.pdf);
String pdfFile = directoryService.createFile(Constant.DIR.REPORT, fileName, perusahaanId);
File pdf = r1721IIIService.generateReport(esptId, perusahaanId, pdfFile);
FileSystemResource isr = new FileSystemResource(pdf);
HttpHeaders respHeaders = new HttpHeaders();
respHeaders.setContentType(MediaType.parseMediaType("application/pdf"));
respHeaders.setContentLength(isr.contentLength());
respHeaders.setContentDispositionFormData("attachment", fileName);
return new ResponseEntity<>(isr, respHeaders, HttpStatus.OK);
}
@RequestMapping(value = "/report21/1721IV/{esptId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<?> generate1721IV(@PathVariable("esptId") String esptId) throws IOException, DRException {
String perusahaanId = userRepository.findOneByLogin(SecurityUtils.getCurrentLogin())
.map(User::getePerusahaan)
.map(EPerusahaan::getId)
.orElseThrow(ResourceNotFoundException::new);
String fileName = directoryService.createFileName(Constant.REPORT_KODE.SSP, DirectoryService.pdf);
String pdfFile = directoryService.createFile(Constant.DIR.REPORT, fileName, perusahaanId);
File pdf = r1721IVService.generateReport(esptId, perusahaanId, pdfFile);
FileSystemResource isr = new FileSystemResource(pdf);
HttpHeaders respHeaders = new HttpHeaders();
respHeaders.setContentType(MediaType.parseMediaType("application/pdf"));
respHeaders.setContentLength(isr.contentLength());
respHeaders.setContentDispositionFormData("attachment", fileName);
return new ResponseEntity<>(isr, respHeaders, HttpStatus.OK);
}
@RequestMapping(value = "/report21/1721V/{esptId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<?> generate1721V(@PathVariable("esptId") String esptId) throws IOException, DRException {
String perusahaanId = userRepository.findOneByLogin(SecurityUtils.getCurrentLogin())
.map(User::getePerusahaan)
.map(EPerusahaan::getId)
.orElseThrow(ResourceNotFoundException::new);
String fileName = directoryService.createFileName(Constant.REPORT_KODE.DB, DirectoryService.pdf);
String pdfFile = directoryService.createFile(Constant.DIR.REPORT, fileName, perusahaanId);
File pdf = r1721VService.generateReport(esptId, perusahaanId, pdfFile);
FileSystemResource isr = new FileSystemResource(pdf);
HttpHeaders respHeaders = new HttpHeaders();
respHeaders.setContentType(MediaType.parseMediaType("application/pdf"));
respHeaders.setContentLength(isr.contentLength());
respHeaders.setContentDispositionFormData("attachment", fileName);
return new ResponseEntity<>(isr, respHeaders, HttpStatus.OK);
}
@RequestMapping(value = "/report21/1721VI/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<?> generate1721VI(@PathVariable("id") String id) throws IOException, DRException {
String perusahaanId = userRepository.findOneByLogin(SecurityUtils.getCurrentLogin())
.map(User::getePerusahaan)
.map(EPerusahaan::getId)
.orElseThrow(ResourceNotFoundException::new);
String fileName = directoryService.createFileName(Constant.REPORT_KODE.TFD, DirectoryService.pdf);
String pdfFile = directoryService.createFile(Constant.DIR.REPORT, fileName, perusahaanId);
File pdf = r1721VIService.generateReport(id, pdfFile);
FileSystemResource isr = new FileSystemResource(pdf);
HttpHeaders respHeaders = new HttpHeaders();
respHeaders.setContentType(MediaType.parseMediaType("application/pdf"));
respHeaders.setContentLength(isr.contentLength());
respHeaders.setContentDispositionFormData("attachment", fileName);
return new ResponseEntity<>(isr, respHeaders, HttpStatus.OK);
}
@RequestMapping(value = "/report21/1721VII/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<?> generate1721VII(@PathVariable("id") String id) throws IOException, DRException {
String perusahaanId = userRepository.findOneByLogin(SecurityUtils.getCurrentLogin())
.map(User::getePerusahaan)
.map(EPerusahaan::getId)
.orElseThrow(ResourceNotFoundException::new);
String fileName = directoryService.createFileName(Constant.REPORT_KODE.FD, DirectoryService.pdf);
String pdfFile = directoryService.createFile(Constant.DIR.REPORT, fileName, perusahaanId);
File pdf = r1721VIIService.generateReport(id, pdfFile);
FileSystemResource isr = new FileSystemResource(pdf);
HttpHeaders respHeaders = new HttpHeaders();
respHeaders.setContentType(MediaType.parseMediaType("application/pdf"));
respHeaders.setContentLength(isr.contentLength());
respHeaders.setContentDispositionFormData("attachment", fileName);
return new ResponseEntity<>(isr, respHeaders, HttpStatus.OK);
}
@RequestMapping(value = "/report21/1721SPTIndukHal1/{esptId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<?> generate1721SPTIndukHal1(@PathVariable("esptId") String esptId) throws IOException, DRException {
String perusahaanId = userRepository.findOneByLogin(SecurityUtils.getCurrentLogin())
.map(User::getePerusahaan)
.map(EPerusahaan::getId)
.orElseThrow(ResourceNotFoundException::new);
String fileName = directoryService.createFileName(Constant.REPORT_KODE.INDUK_HAL1, DirectoryService.pdf);
String pdfFile = directoryService.createFile(Constant.DIR.REPORT, fileName, perusahaanId);
File pdf = r1721SPTIndukService.generateReport(esptId, perusahaanId, pdfFile);
FileSystemResource isr = new FileSystemResource(pdf);
HttpHeaders respHeaders = new HttpHeaders();
respHeaders.setContentType(MediaType.parseMediaType("application/pdf"));
respHeaders.setContentLength(isr.contentLength());
respHeaders.setContentDispositionFormData("attachment", fileName);
return new ResponseEntity<>(isr, respHeaders, HttpStatus.OK);
}
@RequestMapping(value = "/report21/1721SPTIndukHal2/{esptId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<?> generate1721SPTIndukHal2(@PathVariable("esptId") String esptId) throws IOException, DRException {
String perusahaanId = userRepository.findOneByLogin(SecurityUtils.getCurrentLogin())
.map(User::getePerusahaan)
.map(EPerusahaan::getId)
.orElseThrow(ResourceNotFoundException::new);
String fileName = directoryService.createFileName(Constant.REPORT_KODE.INDUK_HAL2, DirectoryService.pdf);
String pdfFile = directoryService.createFile(Constant.DIR.REPORT, fileName, perusahaanId);
File pdf = r1721SPTIndukP2Service.generateReport(esptId, perusahaanId, pdfFile);
FileSystemResource isr = new FileSystemResource(pdf);
HttpHeaders respHeaders = new HttpHeaders();
respHeaders.setContentType(MediaType.parseMediaType("application/pdf"));
respHeaders.setContentLength(isr.contentLength());
respHeaders.setContentDispositionFormData("attachment", fileName);
return new ResponseEntity<>(isr, respHeaders, HttpStatus.OK);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment