List of usage examples for org.springframework.dao DataIntegrityViolationException getMostSpecificCause
public Throwable getMostSpecificCause()
From source file:edu.isi.misd.scanner.network.registry.web.controller.AnalysisToolController.java
@RequestMapping(value = ENTITY_PATH, method = RequestMethod.PUT, consumes = HEADER_JSON_MEDIA_TYPE, produces = HEADER_JSON_MEDIA_TYPE) public @ResponseBody AnalysisTool updateAnalysisTool(@RequestHeader(HEADER_LOGIN_NAME) String loginName, @PathVariable(ID_URL_PATH_VAR) Integer id, @RequestBody AnalysisTool tool) { // find the requested resource AnalysisTool toolLib = analysisToolRepository.findOne(id); // if the ID is not found then throw a ResourceNotFoundException (404) if (toolLib == null) { throw new ResourceNotFoundException(id); }/*from w ww . ja v a 2 s .c om*/ // if the ID in the request body is null, use the ID parsed from the URL // if the ID is found in the request body but does not match the ID in // the current data, then throw a ConflictException (409) Integer updateID = tool.getToolId(); if (updateID == null) { tool.setToolId(id); } else if (!tool.getToolId().equals(toolLib.getToolId())) { throw new ConflictException(tool.getToolId(), toolLib.getToolId()); } // check that the user can perform the update if (!registryService.userIsSuperuser(loginName)) { throw new ForbiddenException(loginName, RegistryServiceConstants.MSG_SUPERUSER_ROLE_REQUIRED); } try { analysisToolRepository.save(tool); } catch (DataIntegrityViolationException e) { log.warn(e); throw new ConflictException(e.getMostSpecificCause()); } // force the re-query to ensure a complete result view if updated return analysisToolRepository.findOne(tool.getToolId()); }
From source file:edu.isi.misd.scanner.network.registry.web.controller.DataSetDefinitionController.java
@RequestMapping(value = BASE_PATH, method = RequestMethod.POST, consumes = HEADER_JSON_MEDIA_TYPE, produces = HEADER_JSON_MEDIA_TYPE) @ResponseStatus(value = HttpStatus.CREATED) public @ResponseBody DataSetDefinition createDataSetDefinition( @RequestHeader(HEADER_LOGIN_NAME) String loginName, @RequestBody DataSetDefinition dataSet) { try {/* w w w . j ava 2s. c o m*/ registryService.saveDataSetDefinition(dataSet); } catch (DataIntegrityViolationException e) { log.warn(e); throw new ConflictException(e.getMostSpecificCause()); } // force the re-query to ensure a complete result view if updated return dataSetDefinitionRepository.findOne(dataSet.getDataSetDefinitionId()); }
From source file:edu.isi.misd.scanner.network.registry.web.controller.DataSetDefinitionController.java
@RequestMapping(value = ENTITY_PATH, method = RequestMethod.PUT, consumes = HEADER_JSON_MEDIA_TYPE, produces = HEADER_JSON_MEDIA_TYPE) public @ResponseBody DataSetDefinition updateDataSetDefinition( @RequestHeader(HEADER_LOGIN_NAME) String loginName, @PathVariable(ID_URL_PATH_VAR) Integer id, @RequestBody DataSetDefinition dataSet) { // find the requested resource DataSetDefinition foundDataSet = dataSetDefinitionRepository.findOne(id); // if the ID is not found then throw a ResourceNotFoundException (404) if (foundDataSet == null) { throw new ResourceNotFoundException(id); }/*from ww w.jav a 2 s .c o m*/ // if the ID in the request body is null, use the ID parsed from the URL // if the ID is found in the request body but does not match the ID in // the current data, then throw a ConflictException (409) Integer updateID = dataSet.getDataSetDefinitionId(); if (updateID == null) { dataSet.setDataSetDefinitionId(id); } else if (!dataSet.getDataSetDefinitionId().equals(foundDataSet.getDataSetDefinitionId())) { throw new ConflictException(dataSet.getDataSetDefinitionId(), foundDataSet.getDataSetDefinitionId()); } try { registryService.saveDataSetDefinition(dataSet); } catch (DataIntegrityViolationException e) { log.warn(e); throw new ConflictException(e.getMostSpecificCause()); } // force the re-query to ensure a complete result view if updated return dataSetDefinitionRepository.findOne(dataSet.getDataSetDefinitionId()); }
From source file:edu.isi.misd.scanner.network.registry.web.controller.DataSetInstanceController.java
@RequestMapping(value = BASE_PATH, method = RequestMethod.POST, consumes = HEADER_JSON_MEDIA_TYPE, produces = HEADER_JSON_MEDIA_TYPE) @ResponseStatus(value = HttpStatus.CREATED) public @ResponseBody DataSetInstance createDataSetInstance(@RequestHeader(HEADER_LOGIN_NAME) String loginName, @RequestBody DataSetInstance dataSetInstance) { // check that the user can perform the create if (!registryService.userCanManageDataSetInstance(loginName, dataSetInstance.getDataSetInstanceId())) { throw new ForbiddenException(loginName, RegistryServiceConstants.MSG_SITE_MANAGEMENT_ROLE_REQUIRED); }// ww w . j a va2s . c o m try { dataSetInstanceRepository.save(dataSetInstance); } catch (DataIntegrityViolationException e) { log.warn(e); throw new ConflictException(e.getMostSpecificCause()); } // force the re-query to ensure a complete result view if updated return dataSetInstanceRepository.findOne(dataSetInstance.getDataSetInstanceId()); }
From source file:edu.isi.misd.scanner.network.registry.web.controller.DataSetInstanceController.java
@RequestMapping(value = ENTITY_PATH, method = RequestMethod.PUT, consumes = HEADER_JSON_MEDIA_TYPE, produces = HEADER_JSON_MEDIA_TYPE) public @ResponseBody DataSetInstance updateDataSetInstance(@RequestHeader(HEADER_LOGIN_NAME) String loginName, @PathVariable(ID_URL_PATH_VAR) Integer id, @RequestBody DataSetInstance dataSetInstance) { // find the requested resource DataSetInstance foundDataSetInstance = dataSetInstanceRepository.findOne(id); // if the ID is not found then throw a ResourceNotFoundException (404) if (foundDataSetInstance == null) { throw new ResourceNotFoundException(id); }/* w w w . ja v a 2 s. com*/ // if the ID in the request body is null, use the ID parsed from the URL // if the ID is found in the request body but does not match the ID in // the current data, then throw a ConflictException (409) Integer updateID = dataSetInstance.getDataSetInstanceId(); if (updateID == null) { dataSetInstance.setDataSetInstanceId(id); } else if (!dataSetInstance.getDataSetInstanceId().equals(foundDataSetInstance.getDataSetInstanceId())) { throw new ConflictException(dataSetInstance.getDataSetInstanceId(), foundDataSetInstance.getDataSetInstanceId()); } // check that the user can perform the update if (!registryService.userCanManageDataSetInstance(loginName, dataSetInstance.getDataSetInstanceId())) { throw new ForbiddenException(loginName, RegistryServiceConstants.MSG_SITE_MANAGEMENT_ROLE_REQUIRED); } try { dataSetInstanceRepository.save(dataSetInstance); } catch (DataIntegrityViolationException e) { log.warn(e); throw new ConflictException(e.getMostSpecificCause()); } // force the re-query to ensure a complete result view if updated return dataSetInstanceRepository.findOne(dataSetInstance.getDataSetInstanceId()); }
From source file:edu.isi.misd.scanner.network.registry.web.controller.DataSetVariableMetadataController.java
@RequestMapping(value = BASE_PATH, method = RequestMethod.POST, consumes = HEADER_JSON_MEDIA_TYPE, produces = HEADER_JSON_MEDIA_TYPE) @ResponseStatus(value = HttpStatus.CREATED) public @ResponseBody DataSetVariableMetadata createDataSetVariableMetadata( @RequestHeader(HEADER_LOGIN_NAME) String loginName, @RequestBody DataSetVariableMetadata dataSetVariableMetadata) { try {//from www. j a v a 2 s . c om dataSetVariableMetadataRepository.save(dataSetVariableMetadata); } catch (DataIntegrityViolationException e) { log.warn(e); throw new ConflictException(e.getMostSpecificCause()); } // force the re-query to ensure a complete result view if updated return dataSetVariableMetadataRepository.findOne(dataSetVariableMetadata.getDataSetVariableMetadataId()); }
From source file:edu.isi.misd.scanner.network.registry.web.controller.DataSetVariableMetadataController.java
@RequestMapping(value = ENTITY_PATH, method = RequestMethod.PUT, consumes = HEADER_JSON_MEDIA_TYPE, produces = HEADER_JSON_MEDIA_TYPE) public @ResponseBody DataSetVariableMetadata updateDataSetVariableMetadata( @RequestHeader(HEADER_LOGIN_NAME) String loginName, @PathVariable(ID_URL_PATH_VAR) Integer id, @RequestBody DataSetVariableMetadata dataSetVariableMetadata) { // find the requested resource DataSetVariableMetadata foundDataSetVariableMetadata = dataSetVariableMetadataRepository.findOne(id); // if the ID is not found then throw a ResourceNotFoundException (404) if (foundDataSetVariableMetadata == null) { throw new ResourceNotFoundException(id); }//from w w w. j av a 2 s . c o m // if the ID in the request body is null, use the ID parsed from the URL // if the ID is found in the request body but does not match the ID in // the current data, then throw a ConflictException (409) Integer updateID = dataSetVariableMetadata.getDataSetVariableMetadataId(); if (updateID == null) { dataSetVariableMetadata.setDataSetVariableMetadataId(id); } else if (!dataSetVariableMetadata.getDataSetVariableMetadataId() .equals(foundDataSetVariableMetadata.getDataSetVariableMetadataId())) { throw new ConflictException(dataSetVariableMetadata.getDataSetVariableMetadataId(), foundDataSetVariableMetadata.getDataSetVariableMetadataId()); } try { dataSetVariableMetadataRepository.save(dataSetVariableMetadata); } catch (DataIntegrityViolationException e) { log.warn(e); throw new ConflictException(e.getMostSpecificCause()); } // force the re-query to ensure a complete result view if updated return dataSetVariableMetadataRepository.findOne(dataSetVariableMetadata.getDataSetVariableMetadataId()); }
From source file:edu.isi.misd.scanner.network.registry.web.controller.NodeController.java
@RequestMapping(value = BASE_PATH, method = RequestMethod.POST, consumes = HEADER_JSON_MEDIA_TYPE, produces = HEADER_JSON_MEDIA_TYPE) @ResponseStatus(value = HttpStatus.CREATED) public @ResponseBody Node createNode(@RequestHeader(HEADER_LOGIN_NAME) String loginName, @RequestBody Node node) { // check that the user can perform the create if (!registryService.userCanManageNode(loginName, node.getNodeId())) { throw new ForbiddenException(loginName, RegistryServiceConstants.MSG_SITE_MANAGEMENT_ROLE_REQUIRED); }/*w ww. j a v a2s .com*/ try { nodeRepository.save(node); } catch (DataIntegrityViolationException e) { log.warn(e); throw new ConflictException(e.getMostSpecificCause()); } // force the re-query to ensure a complete result view if updated return nodeRepository.findOne(node.getNodeId()); }
From source file:edu.isi.misd.scanner.network.registry.web.controller.NodeController.java
@RequestMapping(value = ENTITY_PATH, method = RequestMethod.PUT, consumes = HEADER_JSON_MEDIA_TYPE, produces = HEADER_JSON_MEDIA_TYPE) public @ResponseBody Node updateNode(@RequestHeader(HEADER_LOGIN_NAME) String loginName, @PathVariable(ID_URL_PATH_VAR) Integer id, @RequestBody Node node) { // find the requested resource Node foundNode = nodeRepository.findOne(id); // if the ID is not found then throw a ResourceNotFoundException (404) if (foundNode == null) { throw new ResourceNotFoundException(id); }//from w ww. j a va 2s . c om // if the ID in the request body is null, use the ID parsed from the URL // if the ID is found in the request body but does not match the ID in // the current data, then throw a ConflictException (409) Integer updateID = node.getNodeId(); if (updateID == null) { node.setNodeId(id); } else if (!node.getNodeId().equals(foundNode.getNodeId())) { throw new ConflictException(node.getNodeId(), foundNode.getNodeId()); } // check that the user can perform the update if (!registryService.userCanManageNode(loginName, node.getNodeId())) { throw new ForbiddenException(loginName, RegistryServiceConstants.MSG_SITE_MANAGEMENT_ROLE_REQUIRED); } try { nodeRepository.save(node); } catch (DataIntegrityViolationException e) { log.warn(e); throw new ConflictException(e.getMostSpecificCause()); } // force the re-query to ensure a complete result view if updated return nodeRepository.findOne(node.getNodeId()); }
From source file:edu.isi.misd.scanner.network.registry.web.controller.ScannerUserController.java
@RequestMapping(value = BASE_PATH, method = RequestMethod.POST, consumes = HEADER_JSON_MEDIA_TYPE, produces = HEADER_JSON_MEDIA_TYPE) @ResponseStatus(value = HttpStatus.CREATED) public @ResponseBody ScannerUser createScannerUser(@RequestHeader(HEADER_LOGIN_NAME) String loginName, @RequestBody ScannerUser user) { if (!registryService.userIsSuperuser(loginName)) { throw new ForbiddenException(loginName, RegistryServiceConstants.MSG_SUPERUSER_ROLE_REQUIRED); }/*from w w w . ja v a 2s .c o m*/ try { scannerUserRepository.save(user); } catch (DataIntegrityViolationException e) { log.warn(e); throw new ConflictException(e.getMostSpecificCause()); } // force the re-query to ensure a complete result view if updated return scannerUserRepository.findOne(user.getUserId()); }