be.bittich.quote.controller.impl.AuthorController.java Source code

Java tutorial

Introduction

Here is the source code for be.bittich.quote.controller.impl.AuthorController.java

Source

/*
 * Copyright 2014 nateriver.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package be.bittich.quote.controller.impl;

import be.bittich.quote.model.Author;
import be.bittich.quote.model.Quote;
import be.bittich.quote.model.User;
import be.bittich.quote.service.AuthorService;
import be.bittich.quote.service.FactoryService;
import be.bittich.quote.service.SecurityService;
import be.bittich.quote.vo.LastnameFirstnameVO;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author nateriver
 */
@RestController("authorController")
@RequestMapping(value = "/author")
public class AuthorController extends AbstractController<Author, Long> {

    private static final long serialVersionUID = -5455702081118476099L;
    private final Logger LOG = LoggerFactory.getLogger(QuoteController.class);

    @Autowired
    private SecurityService securityService;

    public AuthorController() {
    }

    @Autowired
    private FactoryService factoryService;

    @Override
    public AuthorService getService() {
        return this.factoryService.authorService();
    }

    @RequestMapping(value = "/autocomplete", method = { RequestMethod.GET })
    @ResponseStatus(HttpStatus.OK)
    public List<LastnameFirstnameVO> autoCompletion() {
        return this.getService().autoCompleteLastNameFirstName();
    }

    @Override
    public Logger getLogger() {
        return LOG;
    }

    @Override
    public Boolean canUpdate(Author t) {
        return (securityService.isAdmin());
    }

    @Override
    public Boolean canDelete(Long id) {
        return (securityService.isAdmin());
    }
}