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