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.classicmodels.controller; /*This is a Studio Managed File. DO NOT EDIT THIS FILE. Your changes may be reverted by Studio.*/ import com.dbscenarios_30mar.classicmodels.service.ProductlinesService; import com.dbscenarios_30mar.classicmodels.service.ProductsService; 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.classicmodels.*; import com.dbscenarios_30mar.classicmodels.service.*; /** * Controller object for domain model class Productlines. * @see com.dbscenarios_30mar.classicmodels.Productlines */ @RestController(value = "Classicmodels.ProductlinesController") @Api(value = "/classicmodels/Productlines", description = "Exposes APIs to work with Productlines resource.") @RequestMapping("/classicmodels/Productlines") public class ProductlinesController { private static final Logger LOGGER = LoggerFactory.getLogger(ProductlinesController.class); @Autowired @Qualifier("classicmodels.ProductlinesService") private ProductlinesService productlinesService; @Autowired @Qualifier("classicmodels.ProductsService") private ProductsService productsService; @RequestMapping(value = "/search", method = RequestMethod.POST) @ApiOperation(value = "Returns the list of Productlines instances matching the search criteria.") public Page<Productlines> findProductliness(Pageable pageable, @RequestBody QueryFilter[] queryFilters) { LOGGER.debug("Rendering Productliness list"); return productlinesService.findAll(queryFilters, pageable); } @RequestMapping(value = "/", method = RequestMethod.GET) @ApiOperation(value = "Returns the list of Productlines instances.") public Page<Productlines> getProductliness(Pageable pageable) { LOGGER.debug("Rendering Productliness list"); return productlinesService.findAll(pageable); } @RequestMapping(value = "/count", method = RequestMethod.GET) @ApiOperation(value = "Returns the total count of Productlines instances.") public Long countAllProductliness() { LOGGER.debug("counting Productliness"); Long count = productlinesService.countAll(); return count; } @RequestMapping(value = "/{id:.+}", method = RequestMethod.GET) @ApiOperation(value = "Returns the Productlines instance associated with the given id.") public Productlines getProductlines(@PathVariable("id") String id) throws EntityNotFoundException { LOGGER.debug("Getting Productlines with id: {}", id); Productlines instance = productlinesService.findById(id); LOGGER.debug("Productlines details with id: {}", instance); return instance; } @RequestMapping(value = "/{id:.+}", method = RequestMethod.DELETE) @ApiOperation(value = "Deletes the Productlines instance associated with the given id.") public boolean deleteProductlines(@PathVariable("id") String id) throws EntityNotFoundException { LOGGER.debug("Deleting Productlines with id: {}", id); Productlines deleted = productlinesService.delete(id); return deleted != null; } @RequestMapping(value = "/{id:.+}", method = RequestMethod.PUT) @ApiOperation(value = "Updates the Productlines instance associated with the given id.") public Productlines editProductlines(@PathVariable("id") String id, @RequestBody Productlines instance) throws EntityNotFoundException { LOGGER.debug("Editing Productlines with id: {}", instance.getProductLine()); instance.setProductLine(id); instance = productlinesService.update(instance); LOGGER.debug("Productlines details with id: {}", instance); return instance; } @RequestMapping(value = "/{id:.+}", method = RequestMethod.POST, consumes = { "multipart/form-data" }) @ApiOperation(value = "Updates the Productlines instance associated with the given id.This API should be used when Productlines instance fields that require multipart data.") public Productlines editProductlines(@PathVariable("id") String id, MultipartHttpServletRequest multipartHttpServletRequest) throws EntityNotFoundException { Productlines newproductlines = WMMultipartUtils.toObject(multipartHttpServletRequest, Productlines.class, "classicmodels"); newproductlines.setProductLine(id); Productlines oldproductlines = productlinesService.findById(id); WMMultipartUtils.updateLobsContent(oldproductlines, newproductlines); LOGGER.debug("Updating productlines with information: {}", newproductlines); return productlinesService.update(newproductlines); } @RequestMapping(value = "/{id}/content/{fieldName}", method = RequestMethod.GET, produces = "application/octet-stream") @ApiOperation(value = "Retrieves content for the given BLOB field in Productlines instance") public DownloadResponse getProductlinesBLOBContent(@PathVariable("id") String 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 Productlines instance", fieldName); if (!WMRuntimeUtils.isLob(Productlines.class, fieldName)) { throw new TypeMismatchException("Given field " + fieldName + " is not a valid BLOB type"); } Productlines instance = productlinesService.findById(id); return WMMultipartUtils.buildDownloadResponseForBlob(instance, fieldName, httpServletRequest, download); } @RequestMapping(value = "/{id:.+}/productses", method = RequestMethod.GET) @ApiOperation(value = "Gets the productses instance associated with the given id.") public Page<Products> findAssociatedproductses(Pageable pageable, @PathVariable("id") String id) { LOGGER.debug("Fetching all associated productses"); return productsService.findAssociatedValues(id, "productlines", "productLine", pageable); } @RequestMapping(value = "/", method = RequestMethod.POST) @ApiOperation(value = "Creates a new Productlines instance.") public Productlines createProductlines(@RequestBody Productlines instance) { LOGGER.debug("Create Productlines with information: {}", instance); instance = productlinesService.create(instance); LOGGER.debug("Created Productlines with information: {}", instance); return instance; } @RequestMapping(value = "/", method = RequestMethod.POST, consumes = { "multipart/form-data" }) @ApiOperation(value = "Creates a new Productlines instance.This API should be used when the Productlines instance has fields that requires multipart data.") public Productlines createProductlines(MultipartHttpServletRequest multipartHttpServletRequest) { Productlines productlines = WMMultipartUtils.toObject(multipartHttpServletRequest, Productlines.class, "classicmodels"); LOGGER.debug("Creating a new productlines with information: {}", productlines); return productlinesService.create(productlines); } /** * This setter method should only be used by unit tests * * @param service */ protected void setProductlinesService(ProductlinesService service) { this.productlinesService = service; } }