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

nl.tno.bim.mapping.controller.MaterialMappingController 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.MaterialMapping;
import nl.tno.bim.mapping.services.MaterialMappingService;

@CrossOrigin()
@RestController()
@RequestMapping(value = "/api")
public class MaterialMappingController {

	private final static Logger logger = LoggerFactory.getLogger(MaterialMappingController.class);

    private MaterialMappingService materialMappingService;

    @Autowired
    public void setMaterialMappingService(MaterialMappingService materialMappingService) {
        this.materialMappingService = materialMappingService;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/materialmapping")
    public ResponseEntity addNewMaterialMapping(@RequestBody MaterialMapping materialMapping) {
        if (logger.isDebugEnabled()) {
            logger.debug("triggering method addNewMaterialMapping ");
        }
        MaterialMapping mm = materialMappingService.persistMaterialMapping(materialMapping);
        if (mm == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("MaterialMapping: 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(mm);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/materialmapping/{id}")
    public ResponseEntity getMaterialMappingById(@PathVariable Long id) {
        if (logger.isDebugEnabled()) {
            logger.debug("triggering method getMaterialMappingById ");
        }
        MaterialMapping mm = materialMappingService.retrieveMaterialMappingById(id);
        if (mm == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("retrieveMaterialMappingById: returning 404 no data found ");
            }
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("returning MaterialMapping 200 object");
        }
        return ResponseEntity.status(HttpStatus.OK).body(mm);

    }

    @RequestMapping(method = RequestMethod.GET, value = "/materialmapping")
    public ResponseEntity> searchMaterialMapping(@RequestParam(required = false) Long nmdProductId, @RequestParam(required = false) String materialName) {
        if (logger.isDebugEnabled()) {
            logger.debug("MaterialMapping: triggering method searchMaterialMapping ");
        }
        List mm = materialMappingService.searchMaterialMapping(nmdProductId,materialName);
        if (mm == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("MaterialMapping: returning 404 no data found ");
            }
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("returning MaterialMapping List 200 object");
        }
        return ResponseEntity.status(HttpStatus.OK).body(mm);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy