1 package org.apache.jetspeed.om.dbpsml; 2 3 import java.util.List ; 5 import java.sql.Connection ; 6 7 8 import org.apache.torque.util.Criteria; 10 import org.apache.torque.util.BasePeer; 11 12 import org.apache.jetspeed.om.security.Group; 13 import org.apache.jetspeed.om.profile.Profile; 14 import org.apache.jetspeed.om.profile.ProfileLocator; 15 import org.apache.jetspeed.services.psmlmanager.db.DBOperations; 16 import org.apache.jetspeed.services.psmlmanager.db.DBUtils; 17 import org.apache.jetspeed.services.psmlmanager.db.DatabasePsmlManager; 18 import org.apache.jetspeed.services.PsmlManager; 19 import org.apache.jetspeed.services.Profiler; 20 21 33 public class JetspeedGroupProfilePeer 34 extends org.apache.jetspeed.om.dbpsml.BaseJetspeedGroupProfilePeer 35 implements DBOperations 36 { 37 38 41 public JetspeedGroupProfilePeer() {} 42 43 44 50 public void insert(Profile profile, Connection connection) throws Exception 51 { 52 doInsertOrUpdate(profile, INSERT, connection); 53 } 54 55 61 public void update(Profile profile, Connection connection) throws Exception 62 { 63 doInsertOrUpdate(profile, UPDATE, connection); 64 } 65 66 67 private void doInsertOrUpdate(Profile profile, int operation, Connection connection) 68 throws Exception 69 { 70 JetspeedGroupProfile groupProfile = new JetspeedGroupProfile(); 71 DatabasePsmlManager service = (DatabasePsmlManager)PsmlManager.getService(); 72 73 groupProfile.setGroupName(profile.getGroup().getName()); 74 groupProfile.setMediaType(profile.getMediaType()); 75 76 String language = profile.getLanguage(); 77 if(language != null && (!language.equals("-1"))) 78 { 79 groupProfile.setLanguage(language); 80 } 81 else 82 { 83 groupProfile.setLanguage(null); 84 } 85 86 String country = profile.getCountry(); 87 if(country != null && (!country.equals("-1"))) 88 { 89 groupProfile.setCountry(country); 90 } 91 else 92 { 93 groupProfile.setCountry(null); 94 } 95 String name = profile.getName(); 96 if (name == null || name.equals("")) 97 { 98 profile.setName(Profiler.FULL_DEFAULT_PROFILE); 99 } 100 else if (!name.endsWith(Profiler.DEFAULT_EXTENSION)) 101 { 102 profile.setName(name + Profiler.DEFAULT_EXTENSION); 103 } 104 groupProfile.setPage(profile.getName()); 105 groupProfile.setProfile(DBUtils.portletsToBytes( 106 profile.getDocument().getPortlets(), service.getMapping())); 107 108 if (operation == INSERT) 109 { 110 super.doInsert(groupProfile, connection); 111 } 112 else if (operation == UPDATE) 113 { 114 Criteria values = buildCriteria(groupProfile); 115 Criteria select = buildCriteria(groupProfile); 116 select.remove(PROFILE); 117 BasePeer.doUpdate( select, values, connection ); 118 } 119 } 120 121 122 128 public void delete(ProfileLocator locator, Connection connection) throws Exception 129 { 130 super.doDelete(buildCriteria(locator), connection); 131 } 132 133 142 public List select(ProfileLocator locator, Connection connection) throws Exception 143 { 144 return super.doSelect(buildCriteria(locator), connection); 145 } 146 147 156 public List selectOrdered(ProfileLocator locator, Connection connection) throws Exception 157 { 158 Criteria criteria = buildCriteria(locator); 159 160 criteria.addAscendingOrderByColumn(GROUP_NAME); 161 criteria.addAscendingOrderByColumn(MEDIA_TYPE); 162 criteria.addAscendingOrderByColumn(LANGUAGE); 163 criteria.addAscendingOrderByColumn(COUNTRY); 164 criteria.addAscendingOrderByColumn(PAGE); 165 166 return super.doSelect(criteria, connection); 167 } 168 169 175 public void delete(Group group, Connection connection) throws Exception 176 { 177 Criteria criteria = new Criteria(); 178 179 criteria.add(GROUP_NAME, group.getName()); 180 181 super.doDelete(criteria, connection); 182 } 183 184 185 189 protected Criteria buildCriteria(ProfileLocator locator) 190 { 191 Criteria criteria = new Criteria(); 192 193 String mediaType = locator.getMediaType(); 194 String language = locator.getLanguage(); 195 String country = locator.getCountry(); 196 String pageName = locator.getName(); 197 String groupName = null; 198 199 Group group = locator.getGroup(); 200 if (group != null) { 201 groupName = group.getName(); 202 } 203 204 if (groupName != null && groupName.length() > 0) 205 { 206 criteria.add(GROUP_NAME, groupName); 207 } 208 209 if (pageName != null && pageName.length() > 0) 210 { 211 criteria.add(PAGE, pageName); 212 } 213 214 if (mediaType != null && mediaType.length() > 0) 215 { 216 criteria.add(MEDIA_TYPE, locator.getMediaType()); 217 } 218 219 if (language != null && language.length() > 0 && (!language.equals("-1"))) 220 { 221 criteria.add(LANGUAGE, language); 222 } 223 else if(language != null && language.equals("-1")) 224 { 225 criteria.add(LANGUAGE, null); 226 } 227 228 if (country != null && country.length() > 0 && (!country.equals("-1"))) 229 { 230 criteria.add(COUNTRY, country); 231 } 232 else if(country != null && country.equals("-1")) 233 { 234 criteria.add(COUNTRY, null); 235 } 236 237 return criteria; 238 } 239 240 } 241 242 | Popular Tags |