@@ -0,0 +1,2101 @@
+/*%0A * Copyright 2012-2014 the original author or authors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage doge.service;%0A%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.util.UUID;%0A%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.data.mongodb.gridfs.GridFsTemplate;%0Aimport org.springframework.stereotype.Service;%0A%0Aimport doge.domain.DogePhoto;%0Aimport doge.domain.DogePhotoRepository;%0Aimport doge.domain.User;%0Aimport doge.photo.Photo;%0Aimport doge.photo.PhotoManipulator;%0A%0A/**%0A * @author Josh Long%0A * @author Phillip Webb%0A */%0A@Service%0Apublic class DogeService %7B%0A%0A%09private final DogePhotoRepository dogePhotoRepository;%0A%0A%09private final PhotoManipulator manipulator;%0A%0A%09private final GridFsTemplate fs;%0A%0A%09@Autowired%0A%09public DogeService(DogePhotoRepository dogePhotoRepository,%0A%09%09%09PhotoManipulator manipulator, GridFsTemplate fs) %7B%0A%09%09this.dogePhotoRepository = dogePhotoRepository;%0A%09%09this.manipulator = manipulator;%0A%09%09this.fs = fs;%0A%09%7D%0A%0A%09public Photo getDogePhoto(User user, String dogeId) throws IOException %7B%0A%09%09DogePhoto dogePhoto = this.dogePhotoRepository.findOneByIdAndUser(dogeId, user);%0A%09%09return () -%3E this.fs.getResource(dogePhoto.getFileRef()).getInputStream();%0A%09%7D%0A%0A%09public DogePhoto addDogePhoto(User user, Photo photo) throws IOException %7B%0A%09%09photo = this.manipulator.manipulate(photo);%0A%09%09String fileRef = UUID.randomUUID() + %22.jpg%22;%0A%09%09try (InputStream inputStream = photo.getInputStream()) %7B%0A%09%09%09this.fs.store(inputStream, fileRef);%0A%09%09%7D%0A%09%09return this.dogePhotoRepository.save(new DogePhoto(user, fileRef));%0A%09%7D%0A%0A%7D%0A

Add service layer