use of alien4cloud.images.ImageData in project alien4cloud by alien4cloud.
the class ArchiveImageLoaderTest method checkImages.
private void checkImages(Map<String, ? extends AbstractInheritableToscaType> elements) {
boolean elementHasTags = false;
String currentUUID = null;
ImageData image = null;
Tag iconTag = new Tag("icon", "");
for (Map.Entry<String, ? extends AbstractInheritableToscaType> toscaInheritableElement : elements.entrySet()) {
elementHasTags = toscaInheritableElement.getValue().getTags() != null;
if (elementHasTags) {
int indexOfIcon = toscaInheritableElement.getValue().getTags().indexOf(iconTag);
if (indexOfIcon >= 0) {
currentUUID = toscaInheritableElement.getValue().getTags().get(indexOfIcon).getValue();
image = imageGenericIdDAO.findById(ImageData.class, currentUUID);
// get registered images in ES by the UUID
assertEquals(currentUUID, image.getId());
}
}
}
}
use of alien4cloud.images.ImageData in project alien4cloud by alien4cloud.
the class ArchiveImageLoader method importImage.
private void importImage(Path archiveFile, List<ParsingError> parsingErrors, Tag iconTag) {
FileSystem csarFS = null;
Path iconPath = null;
try {
csarFS = FileSystems.newFileSystem(archiveFile, null);
iconPath = csarFS.getPath(iconTag.getValue());
if (!Files.isDirectory(iconPath)) {
String iconId = UUID.randomUUID().toString();
// Saving the image
ImageData imageData = new ImageData();
imageData.setData(Files.readAllBytes(iconPath));
imageData.setId(iconId);
imageDAO.writeImage(imageData);
// Replace the image uri by the indexed image ID
iconTag.setValue(iconId);
} else {
parsingErrors.add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.INVALID_ICON_FORMAT, "Icon loading", null, "Invalid icon format at path <" + iconPath + ">", null, safeToString(iconPath)));
}
} catch (NoSuchFileException | InvalidPathException e) {
parsingErrors.add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.MISSING_FILE, "Icon loading", null, "No icon file found at path <" + iconPath + ">", null, safeToString(iconPath)));
} catch (ImageUploadException e) {
parsingErrors.add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.INVALID_ICON_FORMAT, "Icon loading", null, "Invalid icon format at path <" + iconPath + ">", null, safeToString(iconPath)));
} catch (IOException e) {
parsingErrors.add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.FAILED_TO_READ_FILE, "Icon loading", null, "IO error while loading icon at path <" + iconPath + ">", null, safeToString(iconPath)));
}
}
use of alien4cloud.images.ImageData in project alien4cloud by alien4cloud.
the class ImageServlet method doGet.
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
final String imageId = req.getParameter("id");
final String quality = req.getParameter("quality");
final ImageQuality imageQuality;
if (quality == null) {
imageQuality = ImageQuality.QUALITY_BEST;
} else {
imageQuality = ImageQuality.valueOf(quality);
}
final ImageData imageData = this.imageDAO.readImage(imageId, imageQuality);
if (imageData != null) {
// Set content type
resp.setContentType(imageData.getMime());
// Set content size
resp.setContentLength(imageData.getData().length);
// Open the file and output streams
final OutputStream out = resp.getOutputStream();
try {
out.write(imageData.getData());
} finally {
out.close();
}
} else {
resp.setStatus(HttpStatus.NOT_FOUND.value());
}
}
Aggregations