/*
Copyright 2006 - 2010 Under Dusken
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 no.dusken.aranea.service;
import no.dusken.aranea.model.MediaResource;
import no.dusken.common.service.impl.GenericServiceImpl;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
@Service("mediaResourceService")
@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.DEFAULT, readOnly = true)
public class MediaResourceServiceImpl extends GenericServiceImpl<MediaResource>
implements MediaResourceService {
public MediaResourceServiceImpl(){
super(MediaResource.class);
}
public MediaResource getMediaResource(String title) {
return null;
}
public List<MediaResource> getMediaResourcesByTitle(String title) {
List<MediaResource> list = Collections.emptyList();
Map<String, Object> map = Collections.<String, Object>singletonMap("title", title);
try{
list = genericDao.getByNamedQuery("mediaResources_by_title", map);
} catch (DataAccessException e) {
log.error("Unable to get pages by getPagesByDateAndNotPri", e);
}
return list;
}
public List<MediaResource> getMediaResourcesByDate(Calendar from, Calendar to) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("from", from);
map.put("to", to);
List<MediaResource> list = Collections.emptyList();
try {
list = genericDao.getByNamedQuery("mediaresources_bydate", map);
} catch (DataAccessException e) {
log.error("Unable to get pages by mediaresources_bydate", e);
}
return list;
}
public List<MediaResource> getMediaResourcesLastMonth() {
Calendar lastMonth = new GregorianCalendar();
lastMonth.add(GregorianCalendar.MONTH, -1);
return getMediaResourcesByDate(lastMonth, new GregorianCalendar());
}
public List<MediaResource> getAllMediaResources(int offset, int number) {
List<MediaResource> list = Collections.emptyList();
try {
list = genericDao.getByNamedQuery("all_mediaResources", null, offset, number);
} catch (DataAccessException e) {
log.error("Unable to get all mediaresources", e);
}
return list;
}
public List<MediaResource> getMediaResourceByUrl(String url) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("url", url);
List<MediaResource> mr = Collections.emptyList();
try {
mr = genericDao.getByNamedQuery("mediaResources_by_url", map);
} catch (DataAccessException e) {
log.error("Unable to get mediaresource", e);
}
return mr;
}
}