com.sample1.classicmodels.controller.ProductlinesController.java Source code

Java tutorial

Introduction

Here is the source code for com.sample1.classicmodels.controller.ProductlinesController.java

Source

/*Copyright (c) 2016-2017 wavemaker.com All Rights Reserved.
 This software is the confidential and proprietary information of wavemaker.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 wavemaker.com*/
package com.sample1.classicmodels.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.sample1.classicmodels.Productlines;
import com.sample1.classicmodels.service.ProductlinesService;

/**
 * Controller object for domain model class Productlines.
 * @see Productlines
 */
@RestController("classicmodels.ProductlinesController")
@Api(value = "ProductlinesController", 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;

    @ApiOperation(value = "Creates a new Productlines instance.")
    @RequestMapping(method = RequestMethod.POST)
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    public Productlines createProductlines(@RequestBody Productlines productlines) {
        LOGGER.debug("Create Productlines with information: {}", productlines);

        productlines = productlinesService.create(productlines);
        LOGGER.debug("Created Productlines with information: {}", productlines);

        return productlines;
    }

    @ApiOperation(value = "Creates a new Productlines instance.This API should be used when the Productlines instance has fields that requires multipart data.")
    @RequestMapping(method = RequestMethod.POST, consumes = { "multipart/form-data" })
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    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);
    }

    @ApiOperation(value = "Returns the Productlines instance associated with the given id.")
    @RequestMapping(value = "/{id:.+}", method = RequestMethod.GET)
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    public Productlines getProductlines(@PathVariable("id") String id) throws EntityNotFoundException {
        LOGGER.debug("Getting Productlines with id: {}", id);

        Productlines foundProductlines = productlinesService.getById(id);
        LOGGER.debug("Productlines details with id: {}", foundProductlines);

        return foundProductlines;
    }

    @ApiOperation(value = "Retrieves content for the given BLOB field in Productlines instance")
    @RequestMapping(value = "/{id}/content/{fieldName}", method = RequestMethod.GET, produces = "application/octet-stream")
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    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 productlines = productlinesService.getById(id);

        return WMMultipartUtils.buildDownloadResponseForBlob(productlines, fieldName, httpServletRequest, download);
    }

    @ApiOperation(value = "Updates the Productlines instance associated with the given id.")
    @RequestMapping(value = "/{id:.+}", method = RequestMethod.PUT)
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    public Productlines editProductlines(@PathVariable("id") String id, @RequestBody Productlines productlines)
            throws EntityNotFoundException {
        LOGGER.debug("Editing Productlines with id: {}", productlines.getProductLine());

        productlines.setProductLine(id);
        productlines = productlinesService.update(productlines);
        LOGGER.debug("Productlines details with id: {}", productlines);

        return productlines;
    }

    @ApiOperation(value = "Updates the Productlines instance associated with the given id.This API should be used when Productlines instance fields that require multipart data.")
    @RequestMapping(value = "/{id:.+}", method = RequestMethod.POST, consumes = { "multipart/form-data" })
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    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.getById(id);
        WMMultipartUtils.updateLobsContent(oldProductlines, newProductlines);
        LOGGER.debug("Updating Productlines with information: {}", newProductlines);

        return productlinesService.update(newProductlines);
    }

    @ApiOperation(value = "Deletes the Productlines instance associated with the given id.")
    @RequestMapping(value = "/{id:.+}", method = RequestMethod.DELETE)
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    public boolean deleteProductlines(@PathVariable("id") String id) throws EntityNotFoundException {
        LOGGER.debug("Deleting Productlines with id: {}", id);

        Productlines deletedProductlines = productlinesService.delete(id);

        return deletedProductlines != null;
    }

    /**
     * @deprecated Use {@link #findProductlines(String, Pageable)} instead.
     */
    @Deprecated
    @ApiOperation(value = "Returns the list of Productlines instances matching the search criteria.")
    @RequestMapping(value = "/search", method = RequestMethod.POST)
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    public Page<Productlines> searchProductlinesByQueryFilters(Pageable pageable,
            @RequestBody QueryFilter[] queryFilters) {
        LOGGER.debug("Rendering Productlines list");
        return productlinesService.findAll(queryFilters, pageable);
    }

    @ApiOperation(value = "Returns the paginated list of Productlines instances matching the optional query (q) request param. If there is no query provided, it returns all the instances. Pagination & Sorting parameters such as page& size, sort can be sent as request parameters. The sort value should be a comma separated list of field names & optional sort order to sort the data on. eg: field1 asc, field2 desc etc ")
    @RequestMapping(method = RequestMethod.GET)
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    public Page<Productlines> findProductlines(
            @ApiParam("conditions to filter the results") @RequestParam(value = "q", required = false) String query,
            Pageable pageable) {
        LOGGER.debug("Rendering Productlines list");
        return productlinesService.findAll(query, pageable);
    }

    @ApiOperation(value = "Returns the paginated list of Productlines instances matching the optional query (q) request param. This API should be used only if the query string is too big to fit in GET request with request param. The request has to made in application/x-www-form-urlencoded format.")
    @RequestMapping(value = "/filter", method = RequestMethod.POST, consumes = "application/x-www-form-urlencoded")
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    public Page<Productlines> filterProductlines(
            @ApiParam("conditions to filter the results") @RequestParam(value = "q", required = false) String query,
            Pageable pageable) {
        LOGGER.debug("Rendering Productlines list");
        return productlinesService.findAll(query, pageable);
    }

    @ApiOperation(value = "Returns downloadable file for the data matching the optional query (q) request param.")
    @RequestMapping(value = "/export/{exportType}", method = { RequestMethod.GET,
            RequestMethod.POST }, produces = "application/octet-stream")
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    public Downloadable exportProductlines(@PathVariable("exportType") ExportType exportType,
            @ApiParam("conditions to filter the results") @RequestParam(value = "q", required = false) String query,
            Pageable pageable) {
        return productlinesService.export(exportType, query, pageable);
    }

    @ApiOperation(value = "Returns the total count of Productlines instances matching the optional query (q) request param.")
    @RequestMapping(value = "/count", method = { RequestMethod.GET, RequestMethod.POST })
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    public Long countProductlines(
            @ApiParam("conditions to filter the results") @RequestParam(value = "q", required = false) String query) {
        LOGGER.debug("counting Productlines");
        return productlinesService.count(query);
    }

    /**
    * This setter method should only be used by unit tests
    *
    * @param service ProductlinesService instance
    */
    protected void setProductlinesService(ProductlinesService service) {
        this.productlinesService = service;
    }

}