use of com.vsct.vboard.models.VBoardException in project vboard by voyages-sncf-technologies.
the class UsersController method addNewUser.
@RequestMapping(value = "", method = RequestMethod.POST)
@ResponseBody
@Valid
public // Parsing the params in the JSON body requires using a dedicated @RequestBody annotated class instead of simple @RequestParam arguments
User addNewUser(@Valid @RequestBody UserParams params) {
final String email = params.getEmail();
final String firstName = params.getFirst_name();
final String lastName = params.getLast_name();
final User newUser = new User(email, firstName, lastName);
try {
this.logger.debug("addNewUser: email={} - first_name={} - last_name={}", email, firstName, lastName);
return this.userDAO.save(newUser);
} catch (UnexpectedRollbackException e) {
throw new VBoardException(e.getMessage(), e.getMostSpecificCause());
}
}
use of com.vsct.vboard.models.VBoardException in project vboard by voyages-sncf-technologies.
the class UploadsManager method savePinImage.
// img should be the base64 encoded image (exception: url)
public void savePinImage(String img, String name) {
if (!img.startsWith("http")) {
// If the image is an url, the image is downloaded and uploaded on the pinImg folder (NAS)
byte[] data = Base64.getDecoder().decode(img);
try (OutputStream stream = new FileOutputStream(getPinsImagesDirectory().resolve(name + ".png").toFile())) {
stream.write(data);
stream.close();
} catch (Exception e) {
this.logger.error(e.getMessage());
}
} else if (!img.endsWith("svg") && !img.endsWith("gif")) {
URL url;
try {
if (proxyConfig.getProxy() != Proxy.NO_PROXY) {
url = new URL("http", proxyConfig.getHostname(), proxyConfig.getPort(), img);
} else {
url = new URL(img);
}
} catch (MalformedURLException e) {
throw new VBoardException("Could not retrieve pin image from the web", e);
}
try {
InputStream is = url.openStream();
OutputStream os = new FileOutputStream(getPinsImagesDirectory().resolve(name + ".png").toFile());
byte[] b = new byte[2048];
int length;
while ((length = is.read(b)) != -1) {
os.write(b, 0, length);
}
is.close();
os.close();
} catch (IOException e) {
throw new VBoardException("Could not write pin image to filesystem", e);
}
}
}
use of com.vsct.vboard.models.VBoardException in project vboard by voyages-sncf-technologies.
the class UploadsManager method getImage.
/**
* Get the base64 encoded image of a pin (entry parameter: id)
*
* @return String base64 encoded image
*/
public String getImage(String name) {
try {
BufferedImage img = ImageIO.read(getPinsImagesDirectory().resolve(name + ".png").toFile());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ImageIO.write(img, "png", bos);
byte[] imageBytes = bos.toByteArray();
bos.close();
return Base64.getEncoder().encodeToString(imageBytes);
} catch (IOException e) {
throw new VBoardException("Image encoding error", e);
}
}
Aggregations