/** * Copyright 2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.bricket.plugin.gallery_picture.service.impl; import java.util.List; import javax.annotation.Resource; import org.bricket.plugin.gallery.domain.Gallery; import org.bricket.plugin.gallery_picture.domain.GalleryPicture; import org.bricket.plugin.gallery_picture.domain.GalleryPicture.Type; import org.bricket.plugin.gallery_picture.repository.GalleryPictureDao; import org.bricket.plugin.gallery_picture.service.GalleryPictureService; import org.bricket.plugin.picture.service.PictureService; import org.bricket.service.BricketServiceImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.synyx.hades.domain.Order; import org.synyx.hades.domain.PageRequest; /** * @author Ingo Renner * @author Henning Teek * */ @Service(value = "galleryPictureService") @Transactional(readOnly = true) public class GalleryPictureServiceImpl extends BricketServiceImpl implements GalleryPictureService { private final Logger log = LoggerFactory.getLogger(GalleryPictureServiceImpl.class); @Autowired private PictureService pictureService; @Resource private GalleryPictureDao galleryPictureDao; @Override protected void onInit() { log.info("gallery picture service initialized"); } @Override @Transactional public GalleryPicture saveGalleryPicture(GalleryPicture galleryPicture) { galleryPicture.setPicture(pictureService.savePicture(galleryPicture.getPicture())); return galleryPictureDao.save(galleryPicture); } @Override @Transactional public void deleteGalleryPicture(GalleryPicture galleryPicture) { galleryPictureDao.delete(galleryPictureDao.readByPrimaryKey(galleryPicture.getId())); } @Override public GalleryPicture loadGalleryPicture(Long id) { return galleryPictureDao.readByPrimaryKey(id); } @Override public List<GalleryPicture> loadAllGalleryPicture() { return galleryPictureDao.readAll(); } @Override public List<GalleryPicture> loadGalleryPictureByGallery(Gallery gallery, int from, int count, String sortProperty, boolean sortAsc) { final PageRequest pageable; int page; if (from > 0) { page = from / count; } else { page = 0; } if (sortProperty == null || "".equals(sortProperty.trim())) { pageable = new PageRequest(page, count); } else { pageable = new PageRequest(page, count, sortAsc ? Order.ASCENDING : Order.DESCENDING, sortProperty); } return galleryPictureDao.findByGallery(gallery, pageable); } @Override public int getCountByGallery(Gallery gallery) { return galleryPictureDao.countByGallery(gallery).intValue(); } @Override public GalleryPicture createDomainObject() { GalleryPicture galleryPicture = new GalleryPicture(); galleryPicture.setType(Type.DEFAULT); galleryPicture.setPicture(pictureService.createDomainObject()); return galleryPicture; } }