Java tutorial
/*Copyright (c) 2016-2017 trustedcare.us.com All Rights Reserved. This software is the confidential and proprietary information of trustedcare.us.com You shall not disclose such Confidential Information and shall use it only in accordance with the terms of the source code license agreement you entered into with trustedcare.us.com*/ package com.tcitest2.poctest.controller; /*This is a Studio Managed File. DO NOT EDIT THIS FILE. Your changes may be reverted by Studio.*/ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.hibernate.TypeMismatchException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartHttpServletRequest; import com.wavemaker.runtime.data.exception.EntityNotFoundException; import com.wavemaker.runtime.data.export.ExportType; import com.wavemaker.runtime.data.expression.QueryFilter; import com.wavemaker.runtime.file.model.DownloadResponse; import com.wavemaker.runtime.file.model.Downloadable; import com.wavemaker.runtime.util.WMMultipartUtils; import com.wavemaker.runtime.util.WMRuntimeUtils; import com.wavemaker.tools.api.core.annotations.WMAccessVisibility; import com.wavemaker.tools.api.core.models.AccessSpecifier; import com.wordnik.swagger.annotations.Api; import com.wordnik.swagger.annotations.ApiOperation; import com.wordnik.swagger.annotations.ApiParam; import com.tcitest2.poctest.MedicationPhotos; import com.tcitest2.poctest.service.MedicationPhotosService; /** * Controller object for domain model class MedicationPhotos. * @see MedicationPhotos */ @RestController("poctest.MedicationPhotosController") @Api(value = "MedicationPhotosController", description = "Exposes APIs to work with MedicationPhotos resource.") @RequestMapping("/poctest/MedicationPhotos") public class MedicationPhotosController { private static final Logger LOGGER = LoggerFactory.getLogger(MedicationPhotosController.class); @Autowired @Qualifier("poctest.MedicationPhotosService") private MedicationPhotosService medicationPhotosService; @ApiOperation(value = "Creates a new MedicationPhotos instance.") @RequestMapping(method = RequestMethod.POST) @WMAccessVisibility(value = AccessSpecifier.APP_ONLY) public MedicationPhotos createMedicationPhotos(@RequestBody MedicationPhotos medicationPhotos) { LOGGER.debug("Create MedicationPhotos with information: {}", medicationPhotos); medicationPhotos = medicationPhotosService.create(medicationPhotos); LOGGER.debug("Created MedicationPhotos with information: {}", medicationPhotos); return medicationPhotos; } @ApiOperation(value = "Creates a new MedicationPhotos instance.This API should be used when the MedicationPhotos instance has fields that requires multipart data.") @RequestMapping(method = RequestMethod.POST, consumes = { "multipart/form-data" }) @WMAccessVisibility(value = AccessSpecifier.APP_ONLY) public MedicationPhotos createMedicationPhotos(MultipartHttpServletRequest multipartHttpServletRequest) { MedicationPhotos medicationPhotos = WMMultipartUtils.toObject(multipartHttpServletRequest, MedicationPhotos.class, "poctest"); LOGGER.debug("Creating a new MedicationPhotos with information: {}", medicationPhotos); return medicationPhotosService.create(medicationPhotos); } @ApiOperation(value = "Returns the MedicationPhotos instance associated with the given id.") @RequestMapping(value = "/{id:.+}", method = RequestMethod.GET) @WMAccessVisibility(value = AccessSpecifier.APP_ONLY) public MedicationPhotos getMedicationPhotos(@PathVariable("id") Integer id) throws EntityNotFoundException { LOGGER.debug("Getting MedicationPhotos with id: {}", id); MedicationPhotos foundMedicationPhotos = medicationPhotosService.getById(id); LOGGER.debug("MedicationPhotos details with id: {}", foundMedicationPhotos); return foundMedicationPhotos; } @ApiOperation(value = "Retrieves content for the given BLOB field in MedicationPhotos instance") @RequestMapping(value = "/{id}/content/{fieldName}", method = RequestMethod.GET, produces = "application/octet-stream") @WMAccessVisibility(value = AccessSpecifier.APP_ONLY) public DownloadResponse getMedicationPhotosBLOBContent(@PathVariable("id") Integer id, @PathVariable("fieldName") String fieldName, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, @RequestParam(value = "download", defaultValue = "false") boolean download) { LOGGER.debug("Retrieves content for the given BLOB field {} in MedicationPhotos instance", fieldName); if (!WMRuntimeUtils.isLob(MedicationPhotos.class, fieldName)) { throw new TypeMismatchException("Given field " + fieldName + " is not a valid BLOB type"); } MedicationPhotos medicationPhotos = medicationPhotosService.getById(id); return WMMultipartUtils.buildDownloadResponseForBlob(medicationPhotos, fieldName, httpServletRequest, download); } @ApiOperation(value = "Updates the MedicationPhotos instance associated with the given id.") @RequestMapping(value = "/{id:.+}", method = RequestMethod.PUT) @WMAccessVisibility(value = AccessSpecifier.APP_ONLY) public MedicationPhotos editMedicationPhotos(@PathVariable("id") Integer id, @RequestBody MedicationPhotos medicationPhotos) throws EntityNotFoundException { LOGGER.debug("Editing MedicationPhotos with id: {}", medicationPhotos.getId()); medicationPhotos.setId(id); medicationPhotos = medicationPhotosService.update(medicationPhotos); LOGGER.debug("MedicationPhotos details with id: {}", medicationPhotos); return medicationPhotos; } @ApiOperation(value = "Updates the MedicationPhotos instance associated with the given id.This API should be used when MedicationPhotos instance fields that require multipart data.") @RequestMapping(value = "/{id:.+}", method = RequestMethod.POST, consumes = { "multipart/form-data" }) @WMAccessVisibility(value = AccessSpecifier.APP_ONLY) public MedicationPhotos editMedicationPhotos(@PathVariable("id") Integer id, MultipartHttpServletRequest multipartHttpServletRequest) throws EntityNotFoundException { MedicationPhotos newMedicationPhotos = WMMultipartUtils.toObject(multipartHttpServletRequest, MedicationPhotos.class, "poctest"); newMedicationPhotos.setId(id); MedicationPhotos oldMedicationPhotos = medicationPhotosService.getById(id); WMMultipartUtils.updateLobsContent(oldMedicationPhotos, newMedicationPhotos); LOGGER.debug("Updating MedicationPhotos with information: {}", newMedicationPhotos); return medicationPhotosService.update(newMedicationPhotos); } @ApiOperation(value = "Deletes the MedicationPhotos instance associated with the given id.") @RequestMapping(value = "/{id:.+}", method = RequestMethod.DELETE) @WMAccessVisibility(value = AccessSpecifier.APP_ONLY) public boolean deleteMedicationPhotos(@PathVariable("id") Integer id) throws EntityNotFoundException { LOGGER.debug("Deleting MedicationPhotos with id: {}", id); MedicationPhotos deletedMedicationPhotos = medicationPhotosService.delete(id); return deletedMedicationPhotos != null; } /** * @deprecated Use {@link #findMedicationPhotos(String, Pageable)} instead. */ @Deprecated @ApiOperation(value = "Returns the list of MedicationPhotos instances matching the search criteria.") @RequestMapping(value = "/search", method = RequestMethod.POST) @WMAccessVisibility(value = AccessSpecifier.APP_ONLY) public Page<MedicationPhotos> searchMedicationPhotosByQueryFilters(Pageable pageable, @RequestBody QueryFilter[] queryFilters) { LOGGER.debug("Rendering MedicationPhotos list"); return medicationPhotosService.findAll(queryFilters, pageable); } @ApiOperation(value = "Returns the list of MedicationPhotos instances matching the search criteria.") @RequestMapping(method = RequestMethod.GET) @WMAccessVisibility(value = AccessSpecifier.APP_ONLY) public Page<MedicationPhotos> findMedicationPhotos( @ApiParam("conditions to filter the results") @RequestParam(value = "q", required = false) String query, Pageable pageable) { LOGGER.debug("Rendering MedicationPhotos list"); return medicationPhotosService.findAll(query, pageable); } @ApiOperation(value = "Returns downloadable file for the data.") @RequestMapping(value = "/export/{exportType}", method = RequestMethod.GET, produces = "application/octet-stream") @WMAccessVisibility(value = AccessSpecifier.APP_ONLY) public Downloadable exportMedicationPhotos(@PathVariable("exportType") ExportType exportType, @ApiParam("conditions to filter the results") @RequestParam(value = "q", required = false) String query, Pageable pageable) { return medicationPhotosService.export(exportType, query, pageable); } @ApiOperation(value = "Returns the total count of MedicationPhotos instances.") @RequestMapping(value = "/count", method = RequestMethod.GET) @WMAccessVisibility(value = AccessSpecifier.APP_ONLY) public Long countMedicationPhotos( @ApiParam("conditions to filter the results") @RequestParam(value = "q", required = false) String query) { LOGGER.debug("counting MedicationPhotos"); return medicationPhotosService.count(query); } /** * This setter method should only be used by unit tests * * @param service MedicationPhotosService instance */ protected void setMedicationPhotosService(MedicationPhotosService service) { this.medicationPhotosService = service; } }