
nl.tno.bim.mapping.controller.MappingController 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.Mapping;
import nl.tno.bim.mapping.domain.MappingSet;
import nl.tno.bim.mapping.domain.MappingSetMap;
import nl.tno.bim.mapping.services.MappingService;
import nl.tno.bim.mapping.services.MappingSetMapService;
import nl.tno.bim.mapping.services.MappingSetService;
@CrossOrigin()
@RestController()
@RequestMapping(value = "/api")
public class MappingController {
private final static Logger logger = LoggerFactory.getLogger(MappingController.class);
private MappingService mappingService;
private MappingSetMapService mappingSetMapService;
private MappingSetService mappingSetService;
@Autowired
public void setMappingService(MappingService mappingService, MappingSetMapService mappingSetMapService, MappingSetService mappingSetService) {
this.mappingService = mappingService;
this.mappingSetMapService = mappingSetMapService;
this.mappingSetService = mappingSetService;
}
@ApiOperation(value = "Persist new Mapping")
@RequestMapping(method = RequestMethod.POST, value = "/mapping")
public ResponseEntity addNewMapping(@RequestBody Mapping mapping) {
if (logger.isDebugEnabled()) {
logger.debug("triggering method addNewMapping ");
}
Mapping map = mappingService.persistMapping(mapping);
if (map == null) {
if (logger.isDebugEnabled()) {
logger.debug("Mapping: 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(map);
}
@ApiOperation(value = "Add NMD mappings to an element\'s materials")
@RequestMapping(method = RequestMethod.PUT, value = "/addmapping/{mappingSetId}/{elementGuid}")
public ResponseEntity addMappingToElement(
@PathVariable("mappingSetId") Long mappingSetId,
@PathVariable("elementGuid") String elementGuid,
@RequestBody Mapping mapping
) {
if (logger.isDebugEnabled()) {
logger.debug("triggering method addMappingToElement");
}
MappingSet ms = this.mappingSetService.retrieveMappingSetById(mappingSetId);
if (ms == null) {
if (logger.isDebugEnabled()) {
logger.debug("addMappingToElement: returning 404, no MappingSet with ID " + mappingSetId + " found");
}
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
MappingSetMap msm = new MappingSetMap();
msm.setMappingSet(ms);
msm.setElementGuid(elementGuid);
msm.setMapping(mapping);
MappingSetMap savedMappingSetMap = mappingSetMapService.updateMappingSetMapService(msm);
if (savedMappingSetMap == null) {
if (logger.isDebugEnabled()) {
logger.debug("addMappingToMaterial: returning 500, new mapping could not be saved");
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
return ResponseEntity.status(HttpStatus.OK).body(savedMappingSetMap);
}
@ApiOperation(value = "Get Mapping by Id")
@RequestMapping(method = RequestMethod.GET, value = "/mapping/{id}")
public ResponseEntity getMappingById(@PathVariable Long id) {
if (logger.isDebugEnabled()) {
logger.debug("triggering method getMappingById ");
}
Mapping ms = mappingService.retrieveMappingById(id);
if (ms == null) {
if (logger.isDebugEnabled()) {
logger.debug("getMappingById: returning 404 no data found ");
}
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
if (logger.isDebugEnabled()) {
logger.debug("returning Mapping 200 object");
}
return ResponseEntity.status(HttpStatus.OK).body(ms);
}
@ApiOperation(value = "Get all mapping or filter by query parameter 'q'")
@RequestMapping(method = RequestMethod.GET, value = "/mapping")
public ResponseEntity> searchMapping(@RequestParam(required = false) String q) {
if (logger.isDebugEnabled()) {
logger.debug("searchMapping: triggering method searchMapping ");
}
List ms = mappingService.searchMapping(q);
if (ms == null) {
if (logger.isDebugEnabled()) {
logger.debug("searchMapping: returning 404 no data found ");
}
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
if (logger.isDebugEnabled()) {
logger.debug("returning Mapping List 200 object");
}
return ResponseEntity.status(HttpStatus.OK).body(ms);
}
@ApiOperation(value = "Get mapping by id and filter by MappingSetMap id")
@RequestMapping(method = RequestMethod.GET, value = "/mapping/{id}/mappingsetmap/{mappingsetmapid}")
public ResponseEntity> getMappingByIdAndMappingSetMapId(@PathVariable Long id,@RequestParam(required = false) Long mappingsetmapid) {
if (logger.isDebugEnabled()) {
logger.debug("triggering method getMappingByIdAndMappingSetMapId ");
}
List ms = mappingService.retrieveMappingByIdAndMappingSetMapId(id,mappingsetmapid);
if (ms == null) {
if (logger.isDebugEnabled()) {
logger.debug("getMappingByIdAndMappingSetMapId: returning 404 no data found ");
}
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
if (logger.isDebugEnabled()) {
logger.debug("returning Mapping List 200 object");
}
return ResponseEntity.status(HttpStatus.OK).body(ms);
}
@ApiOperation(value = "Get mapping by id and filter by query parameter 'q' for MappingSetMap")
@RequestMapping(method = RequestMethod.GET, value = "/mapping/{id}/mappingsetmap")
public ResponseEntity> getMappingByIdAndMappingSetMap(@PathVariable Long id,@RequestParam(required = false) String q) {
if (logger.isDebugEnabled()) {
logger.debug("triggering method getMappingById ");
}
List ms = mappingService.retrieveMappingByIdAndMappingSetMap(id,q);
if (ms == null) {
if (logger.isDebugEnabled()) {
logger.debug("getMappingByIdAndMappingSetMap: returning 404 no data found ");
}
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
if (logger.isDebugEnabled()) {
logger.debug("returning Mapping 200 object");
}
return ResponseEntity.status(HttpStatus.OK).body(ms);
}
//##########################################################
@ApiOperation(value = "Get mapping by id and filter by MaterialMapping ")
@RequestMapping(method = RequestMethod.GET, value = "/mapping/{id}/materialmapping")
public ResponseEntity> getMappingByIdAndMaterialMapping(@PathVariable Long id,@RequestParam(required = false) String q) {
if (logger.isDebugEnabled()) {
logger.debug("triggering method getMappingById ");
}
List ms = mappingService.retrieveMappingByIdAndMaterialMapping(id,q);
if (ms == null) {
if (logger.isDebugEnabled()) {
logger.debug("retrieveMappingByIdAndMaterialMapping: returning 404 no data found ");
}
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
if (logger.isDebugEnabled()) {
logger.debug("returning Mapping 200 object");
}
return ResponseEntity.status(HttpStatus.OK).body(ms);
}
@ApiOperation(value = "Get mapping by id and Materialmapping id")
@RequestMapping(method = RequestMethod.GET, value = "/mapping/{id}/materialmapping/{materialmappingid}")
public ResponseEntity> getMappingByIdAndMaterialMappingId(@PathVariable Long id,@RequestParam(required = false) Long materialmappingid) {
if (logger.isDebugEnabled()) {
logger.debug("triggering method getMappingById ");
}
List ms = mappingService.retrieveMappingByIdAndMaterialMappingId(id,materialmappingid);
if (ms == null) {
if (logger.isDebugEnabled()) {
logger.debug("getMappingByIdAndMaterialMappingMapId: returning 404 no data found ");
}
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
if (logger.isDebugEnabled()) {
logger.debug("returning Mapping 200 object");
}
return ResponseEntity.status(HttpStatus.OK).body(ms);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy