Java tutorial
/*Copyright (c) 2016-2017 gmail.com All Rights Reserved. This software is the confidential and proprietary information of gmail.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 gmail.com*/ package com.dbscenarios_30mar.dbtest_allscenarios.controller; /*This is a Studio Managed File. DO NOT EDIT THIS FILE. Your changes may be reverted by Studio.*/ import com.dbscenarios_30mar.dbtest_allscenarios.service.AddressM1SpService; import java.io.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.hibernate.TypeMismatchException; 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.RestController; 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.multipart.MultipartHttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import com.wavemaker.runtime.data.exception.EntityNotFoundException; import com.wavemaker.runtime.data.expression.QueryFilter; import com.wavemaker.runtime.util.WMMultipartUtils; import com.wavemaker.runtime.util.WMRuntimeUtils; import com.wavemaker.runtime.file.model.DownloadResponse; import com.wordnik.swagger.annotations.*; import com.dbscenarios_30mar.dbtest_allscenarios.*; import com.dbscenarios_30mar.dbtest_allscenarios.service.*; /** * Controller object for domain model class AddressM1Sp. * @see com.dbscenarios_30mar.dbtest_allscenarios.AddressM1Sp */ @RestController(value = "Dbtest_allscenarios.AddressM1SpController") @Api(value = "/dbtest_allscenarios/AddressM1Sp", description = "Exposes APIs to work with AddressM1Sp resource.") @RequestMapping("/dbtest_allscenarios/AddressM1Sp") public class AddressM1SpController { private static final Logger LOGGER = LoggerFactory.getLogger(AddressM1SpController.class); @Autowired @Qualifier("dbtest_allscenarios.AddressM1SpService") private AddressM1SpService addressM1SpService; @RequestMapping(value = "/search", method = RequestMethod.POST) @ApiOperation(value = "Returns the list of AddressM1Sp instances matching the search criteria.") public Page<AddressM1Sp> findAddressM1Sps(Pageable pageable, @RequestBody QueryFilter[] queryFilters) { LOGGER.debug("Rendering AddressM1Sps list"); return addressM1SpService.findAll(queryFilters, pageable); } @RequestMapping(value = "/", method = RequestMethod.GET) @ApiOperation(value = "Returns the list of AddressM1Sp instances.") public Page<AddressM1Sp> getAddressM1Sps(Pageable pageable) { LOGGER.debug("Rendering AddressM1Sps list"); return addressM1SpService.findAll(pageable); } @RequestMapping(value = "/count", method = RequestMethod.GET) @ApiOperation(value = "Returns the total count of AddressM1Sp instances.") public Long countAllAddressM1Sps() { LOGGER.debug("counting AddressM1Sps"); Long count = addressM1SpService.countAll(); return count; } @RequestMapping(value = "/{id:.+}", method = RequestMethod.GET) @ApiOperation(value = "Returns the AddressM1Sp instance associated with the given id.") public AddressM1Sp getAddressM1Sp(@PathVariable("id") Integer id) throws EntityNotFoundException { LOGGER.debug("Getting AddressM1Sp with id: {}", id); AddressM1Sp instance = addressM1SpService.findById(id); LOGGER.debug("AddressM1Sp details with id: {}", instance); return instance; } @RequestMapping(value = "/{id:.+}", method = RequestMethod.DELETE) @ApiOperation(value = "Deletes the AddressM1Sp instance associated with the given id.") public boolean deleteAddressM1Sp(@PathVariable("id") Integer id) throws EntityNotFoundException { LOGGER.debug("Deleting AddressM1Sp with id: {}", id); AddressM1Sp deleted = addressM1SpService.delete(id); return deleted != null; } @RequestMapping(value = "/{id:.+}", method = RequestMethod.PUT) @ApiOperation(value = "Updates the AddressM1Sp instance associated with the given id.") public AddressM1Sp editAddressM1Sp(@PathVariable("id") Integer id, @RequestBody AddressM1Sp instance) throws EntityNotFoundException { LOGGER.debug("Editing AddressM1Sp with id: {}", instance.getAddressId()); instance.setAddressId(id); instance = addressM1SpService.update(instance); LOGGER.debug("AddressM1Sp details with id: {}", instance); return instance; } @RequestMapping(value = "/{id:.+}", method = RequestMethod.POST, consumes = { "multipart/form-data" }) @ApiOperation(value = "Updates the AddressM1Sp instance associated with the given id.This API should be used when AddressM1Sp instance fields that require multipart data.") public AddressM1Sp editAddressM1Sp(@PathVariable("id") Integer id, MultipartHttpServletRequest multipartHttpServletRequest) throws EntityNotFoundException { AddressM1Sp newaddressm1sp = WMMultipartUtils.toObject(multipartHttpServletRequest, AddressM1Sp.class, "dbtest_allscenarios"); newaddressm1sp.setAddressId(id); AddressM1Sp oldaddressm1sp = addressM1SpService.findById(id); WMMultipartUtils.updateLobsContent(oldaddressm1sp, newaddressm1sp); LOGGER.debug("Updating addressm1sp with information: {}", newaddressm1sp); return addressM1SpService.update(newaddressm1sp); } @RequestMapping(value = "/{id}/content/{fieldName}", method = RequestMethod.GET, produces = "application/octet-stream") @ApiOperation(value = "Retrieves content for the given BLOB field in AddressM1Sp instance") public DownloadResponse getAddressM1SpBLOBContent(@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 AddressM1Sp instance", fieldName); if (!WMRuntimeUtils.isLob(AddressM1Sp.class, fieldName)) { throw new TypeMismatchException("Given field " + fieldName + " is not a valid BLOB type"); } AddressM1Sp instance = addressM1SpService.findById(id); return WMMultipartUtils.buildDownloadResponseForBlob(instance, fieldName, httpServletRequest, download); } @RequestMapping(value = "/", method = RequestMethod.POST) @ApiOperation(value = "Creates a new AddressM1Sp instance.") public AddressM1Sp createAddressM1Sp(@RequestBody AddressM1Sp instance) { LOGGER.debug("Create AddressM1Sp with information: {}", instance); instance = addressM1SpService.create(instance); LOGGER.debug("Created AddressM1Sp with information: {}", instance); return instance; } @RequestMapping(value = "/", method = RequestMethod.POST, consumes = { "multipart/form-data" }) @ApiOperation(value = "Creates a new AddressM1Sp instance.This API should be used when the AddressM1Sp instance has fields that requires multipart data.") public AddressM1Sp createAddressM1Sp(MultipartHttpServletRequest multipartHttpServletRequest) { AddressM1Sp addressm1sp = WMMultipartUtils.toObject(multipartHttpServletRequest, AddressM1Sp.class, "dbtest_allscenarios"); LOGGER.debug("Creating a new addressm1sp with information: {}", addressm1sp); return addressM1SpService.create(addressm1sp); } /** * This setter method should only be used by unit tests * * @param service */ protected void setAddressM1SpService(AddressM1SpService service) { this.addressM1SpService = service; } }