All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.tno.bim.mapping.controller.MappingSetMapController 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 nl.tno.bim.mapping.domain.MappingSetMap;
import nl.tno.bim.mapping.exception.NoMappingIdException;
import nl.tno.bim.mapping.exception.NoMappingSetException;
import nl.tno.bim.mapping.exception.NoMappingSetIdException;
import nl.tno.bim.mapping.exception.NoMappingSetMapException;
import nl.tno.bim.mapping.services.MappingSetMapService;

@CrossOrigin()
@RestController()
@RequestMapping(value = "/api")
public class MappingSetMapController {
    private final static Logger logger = LoggerFactory.getLogger(MappingSetMapController.class);


    private MappingSetMapService mappingSetMapService;

    @Autowired
    public void setBimMappingService(MappingSetMapService mappingSetMapService) {
        this.mappingSetMapService = mappingSetMapService;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/mappingsetmap")
    public ResponseEntity addMappingSetMap(@RequestBody MappingSetMap mappingSetMap) {
        if (logger.isDebugEnabled()) {
            logger.debug("triggering method addMappingSetMap ");
        }
        try {
            MappingSetMap ms = mappingSetMapService.persistMappingSetMapService(mappingSetMap);
            if (ms == null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("addMappingSetMap: returning internal server error due to backend service problem ");
                }
                return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
            }
            if (logger.isDebugEnabled()) {
                logger.debug("addMappingSetMap: returning persisted data ");
            }
            return ResponseEntity.status(HttpStatus.OK).body(ms);
        } catch (NoMappingIdException | NoMappingSetIdException | NoMappingSetException | NoMappingSetMapException nmie) {
            logger.error(nmie.getMessage());
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
        }

    }
    @RequestMapping(method = RequestMethod.PUT, value = "/mappingsetmap")
    public ResponseEntity updateMappingSetMap(@RequestBody MappingSetMap mappingSetMap) {
        if (logger.isDebugEnabled()) {
            logger.debug("triggering method addMappingSetMap ");
        }
            MappingSetMap ms = mappingSetMapService.updateMappingSetMapService(mappingSetMap);
            if (ms == null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("updateMappingSetMap: returning internal server error due to backend service problem ");
                }
                return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
            }
            if (logger.isDebugEnabled()) {
                logger.debug("addMappingSetMap: returning persisted data ");
            }
            return ResponseEntity.status(HttpStatus.OK).body(ms);
   }

    @RequestMapping(method = RequestMethod.GET, value = "/mappingsetmap/{id}")
    public ResponseEntity getMappingSetMapById(@PathVariable Long id) {
        if (logger.isDebugEnabled()) {
            logger.debug("triggering method getMappingSetMapById ");
        }
        MappingSetMap ms = mappingSetMapService.retrieveMappingSetMapById(id);
        if (ms == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("returning 404 no data found ");
            }
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("returning MappingSetMap 200 object");
        }
        return ResponseEntity.status(HttpStatus.OK).body(ms);

    }

    @RequestMapping(method = RequestMethod.GET, value = "/mappingsetmap")
    public ResponseEntity> searchMappingSetMap(@RequestParam(required = false) String q) {
        if (logger.isDebugEnabled()) {
            logger.debug("triggering method searchMappingSetMap ");
        }
        List ms = mappingSetMapService.searchMappingSetMap(q);
        if (ms == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("returning 404 no data found ");
            }
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("returning MappingSetMap List 200 object");
        }
        return ResponseEntity.status(HttpStatus.OK).body(ms);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy