Facebook
From Sexy Plover, 5 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 240
  1. #set($EntityCommonName2 = $EntityCommonName)
  2. #set($EntityCommonNamePlural2 = $EntityCommonNamePlural.substring(0,1).toUpperCase() + $EntityCommonNamePlural.substring(1))
  3.  
  4. #set( $array = $BasePath.split('/') )
  5. #set($idArray=[])
  6.  
  7. #foreach( $arrElement in $array )
  8.     #if( $arrElement.contains("{"))
  9.             #set($trail = $arrElement.indexOf('}') - 1)
  10.             $idArray.add($arrElement.substring(1,$trail))
  11.     #end
  12. #end
  13.  
  14.  
  15. #if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
  16.  
  17. import com.asseco.cb.foundation.application.BaseController;
  18. import com.asseco.cb.foundation.application.Patch;
  19. import com.asseco.cb.foundation.application.PatchRequestBody;
  20. import io.swagger.annotations.Api;
  21. import io.swagger.annotations.ApiOperation;
  22. import org.springframework.data.domain.Page;
  23. import org.springframework.data.domain.Pageable;
  24. import org.springframework.data.rest.webmvc.BasePathAwareController;
  25. import org.springframework.http.HttpStatus;
  26. import org.springframework.http.ResponseEntity;
  27. import org.springframework.web.bind.annotation.DeleteMapping;
  28. import org.springframework.web.bind.annotation.GetMapping;
  29. import org.springframework.web.bind.annotation.PatchMapping;
  30. import org.springframework.web.bind.annotation.PathVariable;
  31. import org.springframework.web.bind.annotation.PostMapping;
  32. import org.springframework.web.bind.annotation.RequestBody;
  33. import org.springframework.web.bind.annotation.ResponseBody;
  34. import org.springframework.web.bind.annotation.ResponseStatus;
  35. import org.springframework.web.bind.annotation.RestController;
  36.  
  37. #parse("File Header.java")
  38. @RestController
  39. @Api(tags = "$EntityCommonNamePlural2", description = "$EntityCommonNamePlural2")
  40. public class ${NAME}Controller extends BaseController<${NAME}> {
  41.  
  42.   private final static String basePath = "/$BasePath";
  43.  
  44.   public ${NAME}Controller(${NAME}Repository repository) {
  45.     super(repository);
  46.   }
  47.  
  48.   @PostMapping(path = basePath)
  49.   @ApiOperation("Add new $EntityCommonName")
  50.   public ResponseEntity<${NAME}> addNew(@RequestBody ${NAME} entity) {
  51.     return super.addNew(entity);
  52.   }
  53.  
  54.   @GetMapping(path = basePath + _id)
  55.   @ApiOperation("Get $EntityCommonName")
  56.   public ResponseEntity<${NAME}> getOne(@PathVariable("id") Long id) {
  57.     return super.getOne(id);
  58.   }
  59.  
  60.   @PostMapping(path = basePath + _id_editable)
  61.   @ApiOperation("Provide editable version of $EntityCommonName")
  62.   public ResponseEntity<${NAME}> provideEditable(@PathVariable("id") Long id) {
  63.     return super.provideEditable(id);
  64.   }
  65.  
  66.   @PatchMapping(path = basePath + _id_editable_version)
  67.   @Patch(service = ${NAME}Repository.class)
  68.   @ResponseStatus(HttpStatus.OK)
  69.   @ApiOperation("Update editable version of $EntityCommonName")
  70.   public void updateEditable(@PathVariable("id") Long id, @PathVariable("version") Integer version, @RequestBody @PatchRequestBody ${NAME} edited) {
  71.     super.updateEditable(id, version, edited);
  72.   }
  73.  
  74.   @DeleteMapping(path = basePath + _id_version)
  75.   @ResponseStatus(HttpStatus.OK)
  76.   @ApiOperation("Remove $EntityCommonName")
  77.   public void remove(@PathVariable("id") Long id, @PathVariable("version") Integer version) {
  78.     super.remove(id, version);
  79.   }
  80.  
  81.   @PostMapping(path = basePath + _id_editable_version_acceptance)
  82.   @ResponseStatus(HttpStatus.OK)
  83.   @ApiOperation("Accept new or edited $EntityCommonName")
  84.   public void acceptEdited(@PathVariable("id") Long id, @PathVariable("version") Integer version) {
  85.     super.acceptEdited(id, version);
  86.   }
  87.  
  88.   @PostMapping(path = basePath + _id_editable_version_rejection)
  89.   @ResponseStatus(HttpStatus.OK)
  90.   @ApiOperation("Reject new or edited $EntityCommonName")
  91.   public void rejectEdited(@PathVariable("id") Long id, @PathVariable("version") Integer version) {
  92.     super.rejectEdited(id, version);
  93.   }
  94.  
  95.   @GetMapping(path = basePath)
  96.   @ResponseStatus(HttpStatus.OK)
  97.   @ApiOperation("Get $EntityCommonNamePlural")
  98.   public @ResponseBody Page<${NAME}> getAll(Pageable pageable
  99.     #if( $idArray[0] != "" )
  100.         #foreach($id in $idArray)
  101.             , Long $id
  102.         #end
  103.     #end) {
  104.     return super.getAll(
  105.      pageable);
  106.   }
  107. }