com.testing26thjuly_.db123testing.controller.SelfRelationTableController.java Source code

Java tutorial

Introduction

Here is the source code for com.testing26thjuly_.db123testing.controller.SelfRelationTableController.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.testing26thjuly_.db123testing.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.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.testing26thjuly_.db123testing.SelfRelationTable;
import com.testing26thjuly_.db123testing.service.SelfRelationTableService;
import com.wordnik.swagger.annotations.*;
import com.wavemaker.tools.api.core.annotations.WMAccessVisibility;
import com.wavemaker.tools.api.core.models.AccessSpecifier;

/**
 * Controller object for domain model class SelfRelationTable.
 * @see SelfRelationTable
 */
@RestController("DB123Testing.SelfRelationTableController")
@RequestMapping("/DB123Testing/SelfRelationTable")
@Api(description = "Exposes APIs to work with SelfRelationTable resource.", value = "SelfRelationTableController")
public class SelfRelationTableController {

    private static final Logger LOGGER = LoggerFactory.getLogger(SelfRelationTableController.class);

    @Autowired
    @Qualifier("DB123Testing.SelfRelationTableService")
    private SelfRelationTableService selfRelationTableService;

    @RequestMapping(value = "/{id}/content/{fieldName}", method = RequestMethod.GET, produces = "application/octet-stream")
    @ApiOperation(value = "Retrieves content for the given BLOB field in SelfRelationTable instance")
    public DownloadResponse getSelfRelationTableBLOBContent(@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 SelfRelationTable instance", fieldName);
        if (!WMRuntimeUtils.isLob(SelfRelationTable.class, fieldName)) {
            throw new TypeMismatchException("Given field " + fieldName + " is not a valid BLOB type");
        }
        SelfRelationTable selfrelationtable = selfRelationTableService.getById(id);
        return WMMultipartUtils.buildDownloadResponseForBlob(selfrelationtable, fieldName, httpServletRequest,
                download);
    }

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

    @RequestMapping(method = RequestMethod.GET)
    @ApiOperation(value = "Returns the list of SelfRelationTable instances matching the search criteria.")
    public Page<SelfRelationTable> findSelfRelationTables(@RequestParam(value = "q", required = false) String query,
            Pageable pageable) {
        LOGGER.debug("Rendering SelfRelationTables list");
        return selfRelationTableService.findAll(query, pageable);
    }

    @RequestMapping(value = "/export/{exportType}", method = RequestMethod.GET, produces = "application/octet-stream")
    @ApiOperation(value = "Returns downloadable file for the data.")
    public Downloadable exportSelfRelationTables(@PathVariable("exportType") ExportType exportType,
            @RequestParam(value = "q", required = false) String query, Pageable pageable) {
        return selfRelationTableService.export(exportType, query, pageable);
    }

    @RequestMapping(value = "/{id:.+}/selfRelationTablesForIntCol", method = RequestMethod.GET)
    @ApiOperation(value = "Gets the selfRelationTablesForIntCol instance associated with the given id.")
    public Page<SelfRelationTable> findAssociatedSelfRelationTablesForIntCol(Pageable pageable,
            @PathVariable("id") Integer id) {
        LOGGER.debug("Fetching all associated selfRelationTablesForIntCol");
        return selfRelationTableService.findAssociatedValues(id, "selfRelationTableByIntCol", "id", pageable);
    }

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

    @RequestMapping(method = RequestMethod.POST)
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    @ApiOperation(value = "Creates a new SelfRelationTable instance.")
    public SelfRelationTable createSelfRelationTable(@RequestBody SelfRelationTable selfrelationtable) {
        LOGGER.debug("Create SelfRelationTable with information: {}", selfrelationtable);
        selfrelationtable = selfRelationTableService.create(selfrelationtable);
        LOGGER.debug("Created SelfRelationTable with information: {}", selfrelationtable);
        return selfrelationtable;
    }

    @RequestMapping(method = RequestMethod.POST, consumes = { "multipart/form-data" })
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    @ApiOperation(value = "Creates a new SelfRelationTable instance.")
    public SelfRelationTable createSelfRelationTable(MultipartHttpServletRequest multipartHttpServletRequest) {
        SelfRelationTable selfrelationtable = WMMultipartUtils.toObject(multipartHttpServletRequest,
                SelfRelationTable.class, "DB123Testing");
        LOGGER.debug("Creating a new SelfRelationTable with information: {}", selfrelationtable);
        return selfRelationTableService.create(selfrelationtable);
    }

    @RequestMapping(value = "/count", method = RequestMethod.GET)
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    @ApiOperation(value = "Returns the total count of SelfRelationTable instances.")
    public Long countSelfRelationTables(@RequestParam(value = "q", required = false) String query) {
        LOGGER.debug("counting SelfRelationTables");
        return selfRelationTableService.count(query);
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    @ApiOperation(value = "Returns the SelfRelationTable instance associated with the given id.")
    public SelfRelationTable getSelfRelationTable(@PathVariable(value = "id") Integer id)
            throws EntityNotFoundException {
        LOGGER.debug("Getting SelfRelationTable with id: {}", id);
        SelfRelationTable foundSelfRelationTable = selfRelationTableService.getById(id);
        LOGGER.debug("SelfRelationTable details with id: {}", foundSelfRelationTable);
        return foundSelfRelationTable;
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    @ApiOperation(value = "Updates the SelfRelationTable instance associated with the given id.")
    public SelfRelationTable editSelfRelationTable(@PathVariable(value = "id") Integer id,
            @RequestBody SelfRelationTable selfrelationtable) throws EntityNotFoundException {
        LOGGER.debug("Editing SelfRelationTable with id: {}", selfrelationtable.getId());
        selfrelationtable.setId(id);
        selfrelationtable = selfRelationTableService.update(selfrelationtable);
        LOGGER.debug("SelfRelationTable details with id: {}", selfrelationtable);
        return selfrelationtable;
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.POST, consumes = { "multipart/form-data" })
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    @ApiOperation(value = "Updates the SelfRelationTable instance associated with the given id.This API should be used when SelfRelationTable instance fields that require multipart data.")
    public SelfRelationTable editSelfRelationTable(@PathVariable(value = "id") Integer id,
            MultipartHttpServletRequest multipartHttpServletRequest) throws EntityNotFoundException {
        SelfRelationTable newSelfRelationTable = WMMultipartUtils.toObject(multipartHttpServletRequest,
                SelfRelationTable.class, "DB123Testing");
        newSelfRelationTable.setId(id);
        SelfRelationTable oldSelfRelationTable = selfRelationTableService.getById(id);
        WMMultipartUtils.updateLobsContent(oldSelfRelationTable, newSelfRelationTable);
        LOGGER.debug("Updating SelfRelationTable with information: {}", newSelfRelationTable);
        return selfRelationTableService.update(newSelfRelationTable);
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    @ApiOperation(value = "Deletes the SelfRelationTable instance associated with the given id.")
    public boolean deleteSelfRelationTable(@PathVariable(value = "id") Integer id) throws EntityNotFoundException {
        LOGGER.debug("Deleting SelfRelationTable with id: {}", id);
        SelfRelationTable deletedSelfRelationTable = selfRelationTableService.delete(id);
        return deletedSelfRelationTable != null;
    }
}