use of com.vmware.flowgate.exception.WormholeRequestException in project flowgate by vmware.
the class SDDCSoftwareController method createServer.
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(method = RequestMethod.POST)
public void createServer(@RequestBody SDDCSoftwareConfig server, HttpServletRequest request) {
String ip = server.getServerURL();
SDDCSoftwareConfig example = sddcRepository.findOneByServerURL(ip);
if (example != null) {
String message = String.format("The server %s is already exsit.", ip);
throw new WormholeRequestException(message);
}
switch(server.getType()) {
case VRO:
serverValidationService.validateVROServer(server);
break;
case VCENTER:
serverValidationService.validVCServer(server);
break;
case VROPSMP:
break;
default:
throw WormholeRequestException.InvalidFiled("type", server.getType().toString());
}
WormholeUserDetails user = accessTokenService.getCurrentUser(request);
server.setUserId(user.getUserId());
IntegrationStatus integrationStatus = new IntegrationStatus();
integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
integrationStatus.setStatus(IntegrationStatus.Status.ACTIVE);
server.setIntegrationStatus(integrationStatus);
// encrypt the password
encryptServerPassword(server);
BaseDocumentUtil.generateID(server);
sddcRepository.save(server);
// notify worker for the start jobs
decryptServerPassword(server);
notifySDDCWorker(server);
}
use of com.vmware.flowgate.exception.WormholeRequestException in project flowgate by vmware.
the class SensorSettingController method updateSensorSetting.
// Update
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/setting", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public void updateSensorSetting(@RequestBody SensorSetting sensorSetting) {
Optional<SensorSetting> oldSensorSettingOptional = repository.findById(sensorSetting.getId());
if (!oldSensorSettingOptional.isPresent()) {
throw WormholeRequestException.NotFound("SensorSetting", "id", sensorSetting.getId());
}
SensorSetting old = oldSensorSettingOptional.get();
try {
BaseDocumentUtil.applyChanges(old, sensorSetting);
} catch (Exception e) {
throw new WormholeRequestException("Failed to update the Sensor setting.", e);
}
repository.save(old);
}
Aggregations