
nl.tno.bim.mapping.controller.MappingSetController 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.MappingSet;
import nl.tno.bim.mapping.services.MappingSetService;
@CrossOrigin()
@RestController()
@RequestMapping(value = "/api")
public class MappingSetController {
private final static Logger logger = LoggerFactory.getLogger(MappingSetController.class);
private MappingSetService mappingSetService;
@Autowired
public void setBimMappingService(MappingSetService mappingSetService) {
this.mappingSetService = mappingSetService;
}
private void sendToLog(String message) {
if (logger.isDebugEnabled()) {
logger.debug(message);
}
}
@ApiOperation(value = "Persist new MappingSet")
@RequestMapping(method = RequestMethod.POST, value = "/mappingset")
public ResponseEntity addNewMappingSet(@RequestBody MappingSet mappingSet) {
sendToLog("triggering method addNewMappingSet ");
try {
MappingSet ms = mappingSetService.persistNewMappingService(mappingSet);
if (ms == null) {
sendToLog("returning bad request due to error in persisting data.");
} else {
sendToLog("returning persisted data");
return ResponseEntity.status(HttpStatus.OK).body(ms);
}
} catch (Exception e) {
}
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
@ApiOperation(value = "Get MappingSet By Id ")
@RequestMapping(method = RequestMethod.GET, value = "/mappingset/{id}")
public ResponseEntity getMappingSetById(@PathVariable Long id) {
sendToLog("triggering method getMappingSetById ");
MappingSet ms = mappingSetService.retrieveMappingSetById(id);
if (ms == null) {
sendToLog("returning 404 no data found ");
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
sendToLog("returning MappingSet 200 object");
return ResponseEntity.status(HttpStatus.OK).body(ms);
}
@ApiOperation(value = "Get all Mapping set")
@RequestMapping(method = RequestMethod.GET, value = "/mappingset")
public ResponseEntity> searchMappingSet(@RequestParam(required = false) String projectId) {
sendToLog("triggering method searchMappingSet");
List ms = mappingSetService.searchMappingSet(projectId);
if (ms == null) {
sendToLog("returning 404 no data found ");
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
sendToLog("returning MappingSet List 200 object");
return ResponseEntity.status(HttpStatus.OK).body(ms);
}
@ApiOperation(value = "Get Latest revision for mapping set By projectId")
@RequestMapping(method = RequestMethod.GET, value = "/mappingset/{projectId}/mappingsetmap")
public ResponseEntity getMappingSetByMappingSetMapProjectId(@PathVariable String projectId) {
sendToLog("triggering method searchMappingSetByMappingSetMapProjectId ");
MappingSet ms = mappingSetService.loadMappingSetWithLatestByProjectId(projectId);
if (ms == null) {
sendToLog("returning 404 no data found ! ");
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
sendToLog("returning MappingSet List 200 object");
return ResponseEntity.status(HttpStatus.OK).body(ms);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy