1 24 package org.riotfamily.components.editor; 25 26 import org.riotfamily.cachius.Cache; 27 import org.riotfamily.common.beans.PropertyUtils; 28 import org.riotfamily.riot.dao.RiotDao; 29 import org.riotfamily.riot.list.RiotDaoService; 30 import org.riotfamily.riot.security.AccessController; 31 import org.riotfamily.website.cache.CacheInvalidationUtils; 32 import org.springframework.beans.BeanWrapper; 33 import org.springframework.beans.BeanWrapperImpl; 34 35 39 public class EntityEditorImpl implements EntityEditor { 40 41 private RiotDaoService daoService; 42 43 private Cache cache; 44 45 public EntityEditorImpl(RiotDaoService daoService) { 46 this.daoService = daoService; 47 } 48 49 public void setCache(Cache cache) { 50 this.cache = cache; 51 } 52 53 public String createObject(String listId) { 54 RiotDao dao = daoService.getDao(listId); 55 BeanWrapper wrapper = new BeanWrapperImpl(dao.getEntityClass()); 56 Object entity = wrapper.getWrappedInstance(); 57 AccessController.checkPermission("edit", entity); 58 dao.save(entity, null); 59 CacheInvalidationUtils.invalidate(cache, dao); 60 return dao.getObjectId(entity); 61 } 62 63 public void deleteObject(String listId, String objectId) { 64 RiotDao dao = daoService.getDao(listId); 65 Object entity = dao.load(objectId); 66 AccessController.checkPermission("delete", entity); 67 dao.delete(entity, null); 68 CacheInvalidationUtils.invalidate(cache, dao, entity); 69 } 70 71 public String getText(String listId, String objectId, String property) { 72 RiotDao dao = daoService.getDao(listId); 73 Object entity = dao.load(objectId); 74 return PropertyUtils.getPropertyAsString(entity, property); 75 } 76 77 public void updateText(String listId, String objectId, String property, 78 String value) { 79 80 RiotDao dao = daoService.getDao(listId); 81 Object entity = dao.load(objectId); 82 AccessController.checkPermission("edit", entity); 83 BeanWrapper wrapper = new BeanWrapperImpl(entity); 84 wrapper.setPropertyValue(property, value); 85 dao.update(entity); 86 CacheInvalidationUtils.invalidate(cache, dao, entity); 87 } 88 } 89 | Popular Tags |