Java Code Examples for org.springframework.dao.DataIntegrityViolationException#getMessage()

The following examples show how to use org.springframework.dao.DataIntegrityViolationException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CmRestController.java    From oneops with Apache License 2.0 6 votes vote down vote up
@RequestMapping(method=RequestMethod.POST, value="/cm/simple/relations")
@ResponseBody
public CmsCIRelationSimple createCIRelation(
		@RequestParam(value="value", required = false)  String valueType, 
		@RequestBody CmsCIRelationSimple relSimple,
		@RequestHeader(value="X-Cms-Scope", required = false)  String scope,
		@RequestHeader(value="X-Cms-User", required = false)  String userId) throws CIValidationException {
	
	scopeVerifier.verifyScope(scope, relSimple);
	
	CmsCIRelation rel = cmsUtil.custCIRelationSimple2CIRelation(relSimple, valueType);
	rel.setCreatedBy(userId);
	try {
		CmsCIRelation newRel = cmManager.createRelation(rel);
		return cmsUtil.custCIRelation2CIRelationSimple(newRel, valueType,false);
	} catch (DataIntegrityViolationException dive) {
		if (dive instanceof DuplicateKeyException) {
			throw new CIValidationException(CmsError.CMS_DUPCI_NAME_ERROR, dive.getMessage());
		} else {
			throw new CmsException(CmsError.CMS_EXCEPTION, dive.getMessage());
		}
	}
}
 
Example 2
Source File: TransistorRestController.java    From oneops with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value="/assemblies/{assemblyId}/platforms", method = RequestMethod.POST)
@ResponseBody
public Map<String,Long> generateDesign(
		@PathVariable long assemblyId,
		@RequestBody CmsRfcCISimple platRfcSimple,
		@RequestHeader(value="X-Cms-User", required = false)  String userId,
		@RequestHeader(value="X-Cms-Scope", required = false)  String scope){

	if (userId == null) userId = "oneops-system";
	
	long startTime = System.currentTimeMillis(); 
	
	CmsRfcCI platRfc = util.custRfcCISimple2RfcCI(platRfcSimple);
	try {
		long platformCiId = dManager.generatePlatform(platRfc, assemblyId, userId, scope);  
		Map<String,Long> result = new HashMap<>(1);
		result.put("platformCiId", platformCiId);

		long tookTime = System.currentTimeMillis() - startTime;
		logger.debug("Time to generate Design - " + tookTime);

		return result;
	} catch (DataIntegrityViolationException dive) {
		if (dive instanceof DuplicateKeyException) {
			throw new CIValidationException(CmsError.CMS_DUPCI_NAME_ERROR, dive.getMessage());
		} else {
			throw new TransistorException(CmsError.CMS_EXCEPTION, dive.getMessage());
		}
	} catch (CmsBaseException te) {
		logger.error(te);
		te.printStackTrace();
		throw te;
	}
}
 
Example 3
Source File: TransistorRestController.java    From oneops with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value="/platforms/{fromPlatformId}/clone", method = RequestMethod.POST)
@ResponseBody
public Map<String,Long> clonePlatform(
		@PathVariable long fromPlatformId,
		@RequestBody CmsRfcCISimple platRfcSimple,
		@RequestHeader(value="X-Cms-User", required = false)  String userId,
		@RequestHeader(value="X-Cms-Scope", required = false)  String scope){

	if (userId == null) userId = "oneops-system";
	try {
		long startTime = System.currentTimeMillis(); 
		
		CmsRfcCI platRfc = util.custRfcCISimple2RfcCI(platRfcSimple);
		
		long platformId = dManager.clonePlatform(platRfc, null, fromPlatformId, userId, scope);  
		
		Map<String,Long> result = new HashMap<>(1);
		result.put("platformCiId", platformId);

		long tookTime = System.currentTimeMillis() - startTime;
		logger.debug("Time to generate Design - " + tookTime);

		return result;
	} catch (DataIntegrityViolationException dive) {
		if (dive instanceof DuplicateKeyException) {
			throw new CIValidationException(CmsError.CMS_DUPCI_NAME_ERROR, dive.getMessage());
		} else {
			throw new TransistorException(CmsError.CMS_EXCEPTION, dive.getMessage());
		}
	} catch (CmsBaseException te) {
		logger.error(te);
		te.printStackTrace();
		throw te;
	}
}
 
Example 4
Source File: CmRestController.java    From oneops with Apache License 2.0 5 votes vote down vote up
@RequestMapping(method=RequestMethod.POST, value="/cm/simple/cis")
@ResponseBody
public CmsCISimple createCISimple(
		@RequestParam(value="value", required = false)  String valueType, 
		@RequestBody CmsCISimple ciSimple,
		@RequestHeader(value="X-Cms-Scope", required = false)  String scope,
		@RequestHeader(value="X-Cms-User", required = false)  String userId) throws CIValidationException {	
	
	scopeVerifier.verifyScope(scope, ciSimple);
	
	CmsCI newCi = cmsUtil.custCISimple2CI(ciSimple, valueType);
	newCi.setCiId(0);
	newCi.setCiGoid(null);
	newCi.setCreatedBy(userId);
	try {
		CmsCI ci = cmManager.createCI(newCi);
		updateAltNs(ci.getCiId(), ciSimple);
		logger.debug(ci.getCiId());
		CmsCISimple cmsCISimple = cmsUtil.custCI2CISimple(ci, valueType);
		cmsCISimple.setAltNs(ciSimple.getAltNs());
		return cmsCISimple;
	} catch (DataIntegrityViolationException dive) {
		if (dive instanceof DuplicateKeyException) {
			throw new CIValidationException(CmsError.CMS_DUPCI_NAME_ERROR, dive.getMessage());
		} else {
			throw new CmsException(CmsError.CMS_EXCEPTION, dive.getMessage());
		}
	}
}
 
Example 5
Source File: TransistorRestController.java    From oneops with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value="/assemblies/{fromAssemblyId}/clone", method = RequestMethod.POST)
@ResponseBody
public Map<String,Long> cloneAssembly(
		@PathVariable long fromAssemblyId,
		@RequestBody CmsCISimple targetCISimple,
		@RequestHeader(value="X-Cms-User", required = false)  String userId,
		@RequestHeader(value="X-Cms-Scope", required = false)  String scope){

	if (userId == null) userId = "oneops-system";
	try {
		long startTime = System.currentTimeMillis(); 
		
		if (targetCISimple.getCiAttributes().get("description") == null) {
			targetCISimple.addCiAttribute("description", null);
		}
		
		CmsCI targetCI = util.custCISimple2CI(targetCISimple, null);
		
		long resultCiId;
		if ("account.Assembly".equals(targetCI.getCiClassName())) {
			resultCiId = dManager.cloneAssembly(targetCI, fromAssemblyId, userId, scope);
		} else if ("account.Design".equals(targetCI.getCiClassName())) {
			resultCiId = dManager.saveAssemblyAsCatalog(targetCI, fromAssemblyId, userId, scope);
		} else {
			throw new TransistorException(CmsError.TRANSISTOR_BAD_CLASS_NAME, "Bad class name");
		}
		
		Map<String,Long> result = new HashMap<>(1);
		result.put("resultCiId", resultCiId);

		long tookTime = System.currentTimeMillis() - startTime;
		logger.debug("Time to generate Assembly/Catalog - " + tookTime);

		return result;
	} catch (DataIntegrityViolationException dive) {
		if (dive instanceof DuplicateKeyException) {
			throw new CIValidationException(CmsError.CMS_DUPCI_NAME_ERROR, dive.getMessage());
		} else {
			throw new TransistorException(CmsError.CMS_EXCEPTION, dive.getMessage());
		}
	} catch (CmsBaseException te) {
		logger.error(te);
		te.printStackTrace();
		throw te;
	}
}