
nl.tno.bim.mapping.controller.CommonWordController Maven / Gradle / Ivy
package nl.tno.bim.mapping.controller;
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.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
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 io.swagger.annotations.ApiOperation;
import nl.tno.bim.mapping.domain.CommonWord;
import nl.tno.bim.mapping.services.CommonWordService;
@CrossOrigin()
@RestController()
@RequestMapping(value = "/api")
public class CommonWordController {
private static final Logger logger = LoggerFactory.getLogger(CommonWordController.class);
private CommonWordService commonWordService;
@Autowired
public void setCommonWordService(CommonWordService commonWordService) {
this.commonWordService = commonWordService;
}
@ApiOperation(value = "Persist new Common word")
@RequestMapping(method = RequestMethod.POST, value = "/commonword")
public ResponseEntity> addCommonWords(@RequestBody List commonWords) {
if (logger.isDebugEnabled()) {
logger.debug("CommonWord: triggering method addCommonWords ");
}
List cwds = commonWordService.persistCommonWords(commonWords);
if (cwds == null) {
if (logger.isDebugEnabled()) {
logger.debug("CommonWord: returning internal server error due to backend service problem ");
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
if (logger.isDebugEnabled()) {
logger.debug("returning persisted data ");
}
return ResponseEntity.status(HttpStatus.OK).body(cwds);
}
@ApiOperation(value = "Get common word by Id")
@RequestMapping(method = RequestMethod.GET, value = "/commonword/{id}")
public ResponseEntity getCommonWordById(@PathVariable Long id) {
if (logger.isDebugEnabled()) {
logger.debug("CommonWord: triggering method getCommonWordById ");
}
CommonWord ms = commonWordService.retrieveCommonWordById(id);
if (ms == null) {
if (logger.isDebugEnabled()) {
logger.debug("getCommonWordById: returning 404 no data found ");
}
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
if (logger.isDebugEnabled()) {
logger.debug("returning CommonWord 200 object");
}
return ResponseEntity.status(HttpStatus.OK).body(ms);
}
@ApiOperation(value = "Get All common words or use Request paramter word to filter")
@RequestMapping(method = RequestMethod.GET, value = "/commonword")
public ResponseEntity> searchCommonWord(@RequestParam(required = false) String word) {
if (logger.isDebugEnabled()) {
logger.debug("CommonWord: triggering method searchCommonWord");
}
List ms = commonWordService.findCommonWord(word);
if (ms == null) {
if (logger.isDebugEnabled()) {
logger.debug("searchCommonWord: returning 404 no data found ");
}
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
if (logger.isDebugEnabled()) {
logger.debug("returning CommonWord List 200 object");
}
return ResponseEntity.status(HttpStatus.OK).body(ms);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy