class ImageExploratoryServiceImpl implements ImageExploratoryService {

	@Override
	public String createImage(UserInfo user, String project, String exploratoryName, String imageName, String imageDescription) {
		ProjectDTO projectDTO = projectService.get(project);
		UserInstanceDTO userInstance = exploratoryDAO.fetchRunningExploratoryFields(user.getName(), project, exploratoryName);

		if (imageExploratoryDao.exist(imageName, userInstance.getProject())) {
			log.error(String.format(IMAGE_EXISTS_MSG, imageName, userInstance.getProject()));
			throw new ResourceAlreadyExistException(String.format(IMAGE_EXISTS_MSG, imageName, userInstance.getProject()));
		}
		final List<Library> libraries = libDAO.getLibraries(user.getName(), project, exploratoryName);

		imageExploratoryDao.save(Image.builder()
				.name(imageName)
				.description(imageDescription)
				.status(ImageStatus.CREATING)
				.user(user.getName())
				.libraries(fetchExploratoryLibs(libraries))
				.computationalLibraries(fetchComputationalLibs(libraries))
				.dockerImage(userInstance.getImageName())
				.exploratoryId(userInstance.getId())
				.project(userInstance.getProject())
				.endpoint(userInstance.getEndpoint())
				.build());

		exploratoryDAO.updateExploratoryStatus(new ExploratoryStatusDTO()
				.withUser(user.getName())
				.withProject(project)
				.withExploratoryName(exploratoryName)
				.withStatus(UserInstanceStatus.CREATING_IMAGE));

		EndpointDTO endpointDTO = endpointService.get(userInstance.getEndpoint());
		return provisioningService.post(endpointDTO.getUrl() + ExploratoryAPI.EXPLORATORY_IMAGE,
				user.getAccessToken(),
				requestBuilder.newExploratoryImageCreate(user, userInstance, imageName, endpointDTO, projectDTO), String.class);
	}

}