use of com.vmware.flowgate.exception.WormholeRequestException in project flowgate by vmware.
the class SDDCSoftwareController method getVROServerConfigsByUser.
// get servers by user
// Confuse, if we only filter out vrops why not set the type field?
@RequestMapping(value = "/user/vrops", method = RequestMethod.GET)
public List<SDDCSoftwareConfig> getVROServerConfigsByUser(HttpServletRequest request) {
SDDCSoftwareConfig example = new SDDCSoftwareConfig();
example.setUserId(getCurrentUserID(request));
List<SDDCSoftwareConfig> datas = sddcRepository.findAllByUserId(getCurrentUserID(request));
if (datas.isEmpty()) {
throw new WormholeRequestException("The result is empty");
}
decryptServerListPassword(datas);
return datas;
}
use of com.vmware.flowgate.exception.WormholeRequestException in project flowgate by vmware.
the class AssetController method updateServerMapping.
// Update serverMapping
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/mapping", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public void updateServerMapping(@RequestBody ServerMapping serverMaping) {
Optional<ServerMapping> mappingOptional = serverMappingRepository.findById(serverMaping.getId());
if (!mappingOptional.isPresent()) {
throw WormholeRequestException.NotFound("ServerMapping", "id", serverMaping.getId());
}
ServerMapping mapping = mappingOptional.get();
try {
mapping.setAsset(serverMaping.getAsset());
serverMappingRepository.save(mapping);
} catch (Exception e) {
throw new WormholeRequestException("Failed to update the ServerMapping", e);
}
}
use of com.vmware.flowgate.exception.WormholeRequestException in project flowgate by vmware.
the class AssetController method update.
// Update
@ResponseStatus(HttpStatus.OK)
@RequestMapping(method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public void update(@RequestBody Asset asset) {
Optional<Asset> oldAssetOptional = assetRepository.findById(asset.getId());
if (!oldAssetOptional.isPresent()) {
throw WormholeRequestException.NotFound("Asset", "id", asset.getId());
}
Asset oldAsset = oldAssetOptional.get();
try {
BaseDocumentUtil.applyChanges(oldAsset, asset);
} catch (Exception e) {
throw new WormholeRequestException("Failed to update the Asset", e);
}
oldAsset.setLastupdate(System.currentTimeMillis());
assetRepository.save(oldAsset);
}
use of com.vmware.flowgate.exception.WormholeRequestException in project flowgate by vmware.
the class AuthController method updateUser.
// Update a user
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/user", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public void updateUser(@RequestBody WormholeUser user, HttpServletRequest request) {
WormholeUserDetails userDetail = accessTokenService.getCurrentUser(request);
Optional<WormholeUser> currentUserOptional = userRepository.findById(userDetail.getUserId());
WormholeUser currentUser = currentUserOptional.get();
WormholeUser old = null;
if (currentUser.getUserName().equals(user.getUserName())) {
old = currentUser;
} else if (currentUser.getRoleNames().contains(FlowgateConstant.Role_admin)) {
Optional<WormholeUser> oldUserOptional = userRepository.findById(user.getId());
old = oldUserOptional.get();
} else {
throw new WormholeRequestException(HttpStatus.FORBIDDEN, "Forbidden", null);
}
if (old == null) {
throw new WormholeRequestException(HttpStatus.NOT_FOUND, "User not found", null);
}
if (user.getPassword() != null && !"".equals(user.getPassword().trim())) {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
old.setPassword(encoder.encode(user.getPassword()));
old.setLastPasswordResetDate(new Date().getTime());
}
if (user.getEmailAddress() != null && !"".equals(user.getEmailAddress().trim())) {
old.setEmailAddress(user.getEmailAddress());
}
if (user.getRoleNames() != null) {
old.setRoleNames(user.getRoleNames());
}
userRepository.save(old);
}
use of com.vmware.flowgate.exception.WormholeRequestException in project flowgate by vmware.
the class AuthController method createUser.
// Create a new user
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = "/user", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public void createUser(@RequestBody WormholeUser user, HttpServletResponse response) {
if (userRepository.findOneByUserName(user.getUserName()) != null) {
String message = user.getUserName() + "is already exsit";
throw new WormholeRequestException(message);
}
user.setCreateTime(new Date());
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
user.setPassword(encoder.encode(user.getPassword().trim()));
user.setLastPasswordResetDate(new Date().getTime());
BaseDocumentUtil.generateID(user);
userRepository.save(user);
}
Aggregations