GaWis Profile
|
|
GaWis profiles
GaWis DB stores a huge amount of data concerning mobile devices and
their attributes and capabilities. GaWis users may be interested in a
subset of these data. GaWis provides a feature that allows users
to define subsets of data of interest, this abstraction is called
“profile”.
A profile contains data that is useful for specific user’s needs.
It’s possible to define various custom profiles.
GaWis: how to define a new profile
Step 0
Choose the data you are interested in, e.g.:
- User agent
- Number of display colors
- Video support
- Supported video formats
Step 1
Find the corresponding data in GaWis DB, e.g.:
- User agent -> COLUMN `useragent` from TABLE `devices`
- Number of display colors -> COLUMN `colors` from TABLE `devices`
- Video support -> COLUMN `video` from TABLE `devices`
- Supported video formats -> TABLE `streaming_gc`
Step 2
Create a new java bean in package
it.reply.open.gawis.dao.beans.profilebeans that implements interface
ProfileBean, e.g. TestProfileBean.java:
package it.reply.open.gawis.dao.beans.profilebeans;
public class TestProfileBean implements ProfileBean {
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
} |
Step 3
Add one property (and relative getter and setter) for each field you
chose that corresponds to a DB column, e.g. `useragent`, `colors`,
`video` (see step 1):
package it.reply.open.gawis.dao.beans.profilebeans;
public class TestProfileBean implements ProfileBean {
private Integer id;
private String useragent;
private Integer colors;
private Boolean video;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUseragent() {
return useragent;
}
public void setUseragent(String useragent) {
this.useragent = useragent;
}
public Integer getColors() {
return colors;
}
public void setColors(Integer colors) {
this.colors = colors;
}
public Boolean getVideo() {
return video;
}
public void setVideo(Boolean video) {
this.video = video;
}
} |
Step 4
In package it.reply.open.gawis.dao.beans.profilebeans, define an
Hibernate mapping (e.g. TestProfileBean.hbm.xml) for the new profile
bean:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE
hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="it.reply.open.gawis.dao.beans.profilebeans">
<class name="TestProfileBean" table="devices" optimistic-lock="none">
<id name="id" type="integer" unsaved-value="null">
<column name="id" not-null="true" unique="true" index="PRIMARY"/>
<generator class="native"/>
</id>
<property name="useragent" type="string" column="useragent" length="200" index="UserAgent"/>
<property name="colors" type="integer" column="colors"/>
<property name="video" type="boolean" column="video"/>
</class>
</hibernate-mapping>
|
Step 5
Create a new java class in package it.reply.open.gawis.profiles that extends abstract class Profile:
package it.reply.open.gawis.profiles;
import java.util.HashMap;
public class TestProfile extends Profile{
@Override
public HashMap<String, Object> getProperties() {
return null;
}
@Override
public HashMap<String, Object> initProperties() {
return null;
}
@Override
public Boolean updateProperties(HashMap<String, Object> properties) {
return null;
}
}
|
Step 6
Add one property (and relative getter and setter) for each ProfileBean (e.g. TestProfileBean) or table (e.g. streaming_gc, see step 1) which will be part of the new profile:
package it.reply.open.gawis.profiles;
import it.reply.open.gawis.dao.beans.profilebeans.TestProfileBean;
import java.util.Collection;
import java.util.HashMap;
public class TestProfile extends Profile{
private TestProfileBean testProfileBean;
private Collection streamingGcMany;
@Override
public HashMap<String, Object> getProperties() {
return null;
}
@Override
public HashMap<String, Object> initProperties() {
return null;
}
@Override
public Boolean updateProperties(HashMap<String, Object> properties) {
return null;
}
public TestProfileBean getTestProfileBean() {
return testProfileBean;
}
public void setTestProfileBean(TestProfileBean testProfileBean) {
this.testProfileBean = testProfileBean;
}
public Collection getStreamingGcMany() {
return streamingGcMany;
}
public void setStreamingGcMany(Collection streamingGcMany) {
this.streamingGcMany = streamingGcMany;
}
}
|
Step 7
If the new profile contains lookup tables such as streaming_gc[1], create in package it.reply.open.gawis.dao a new java interface extending ProfileDAO.
This interface has to define one init method for each lookup table (gc
table) the new profile contains. E.g. initStreamingGcMany():
package it.reply.open.gawis.dao;
import java.util.Collection;
public interface TestProfileDAO extends ProfileDAO {
public Collection initStreamingGcMany();
} |
Step 8
Create in package it.reply.open.gawis.dao a new java class that extends
abstract class DAOUtil and implements the interface ProfileDAO or, if
the new profile contains gc tables such as streaming_gc, the
interface that extends ProfileDAO (see step 7):
package it.reply.open.gawis.dao;
import it.reply.open.gawis.profiles.Profile;
import java.util.Collection;
public class TestProfileDAOImpl extends DAOUtil implements TestProfileDAO {
public Collection initStreamingGcMany() {
return null;
}
public Profile getProfileFromUA(String userAgent) {
return null;
}
public Profile getProfileFromWurflId(String wurflId) {
return null;
}
public void initAndSave(Profile profile) {
}
public void saveOrUpdate(Profile profile) {
}
} |
Step 9
Implement interface methods, e.g.:
package it.reply.open.gawis.dao;
import it.reply.open.gawis.dao.beans.Devices;
import it.reply.open.gawis.dao.beans.StreamingGc;
import it.reply.open.gawis.dao.beans.profilebeans.TestProfileBean;
import it.reply.open.gawis.profiles.Profile;
import it.reply.open.gawis.profiles.TestProfile;
import java.util.ArrayList;
import java.util.Collection;
public class TestProfileDAOImpl extends DAOUtil implements TestProfileDAO {
public Collection initStreamingGcMany() {
return super.initGcMany("StreamingGc");
}
public Profile getProfileFromUA(String userAgent) {
TestProfile testProfile = new TestProfile();
testProfile.setStreamingGcMany(super.getGcMany(userAgent,
"streamingGcMany", "StreamingGc"));
testProfile.setTestProfileBean((TestProfileBean)
super.getProfileBean(userAgent, "TestProfileBean"));
return testProfile;
}
public void initAndSave(Profile profile) {
TestProfile testProfile = (TestProfile) profile;
TestProfileBean bean = new TestProfileBean();
try{
bean= (TestProfileBean) getHibernateTemplate()
.find("from TestProfileBean where id=?",
testProfile.getDeviceId()).get(0);
}catch (Exception e) {
}
testProfile.setTestProfileBean(bean);
getHibernateTemplate().saveOrUpdate(testProfile.getTestProfileBean());
}
public void saveOrUpdate(Profile profile) {
TestProfile testProfile = (TestProfile) profile;
getHibernateTemplate().saveOrUpdate(testProfile.getTestProfileBean());
Devices device = (Devices) getHibernateTemplate()
.find("from
Devices where id=?", testProfile.getTestProfileBean().getId()).get(0);
device.setStreamingGcMany(((ArrayList<ArrayList<StreamingGc>>)testProfile.getStreamingGcMany()).get(0));
getHibernateTemplate().saveOrUpdate(device);
}
}
|
Step 10
Implement getProperties(), initProperties() and updateProperties() methods for the profile class created at step 5, e.g.:
package it.reply.open.gawis.profiles;
import it.reply.open.gawis.constants.Constants;
import it.reply.open.gawis.dao.TestProfileDAO;
import it.reply.open.gawis.dao.beans.profilebeans.TestProfileBean;
import it.reply.open.gawis.spring.ApplicationContextFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
public class TestProfile extends Profile{
private TestProfileBean testProfileBean;
private Collection streamingGcMany;
@Override
public HashMap<String, Object> getProperties() {
HashMap<String, Object> properties = new HashMap<String, Object>();
properties.put("Streaming", ((ArrayList<ArrayList>)this.streamingGcMany));
properties.put(Constants.USER_AGENT_LABEL, this.testProfileBean.getUseragent());
properties.put("Colors", this.testProfileBean.getColors());
properties.put("Video", this.testProfileBean.getVideo());
return properties;
}
@Override
public HashMap<String, Object> initProperties() {
HashMap<String, Object> properties = new HashMap<String, Object>();
TestProfileDAO profileDAO = (TestProfileDAO)
ApplicationContextFactory.getApplicationContext().getBean("TestProfileDAOTarget");
properties.put("Streaming", profileDAO.initStreamingGcMany());
properties.put(Constants.USER_AGENT_LABEL, null);
properties.put("Colors", null);
properties.put("Video", null);
return properties;
}
@Override
public Boolean updateProperties(HashMap<String, Object> properties) {
try {
this.testProfileBean.setUseragent(setPropertyAsString(properties.get(Constants.USER_AGENT_LABEL)));
this.testProfileBean.setColors(setPropertyAsInteger(properties.get("Colors")));
this.testProfileBean.setVideo(setPropertyAsBoolean(properties.get("Video")));
this.streamingGcMany = (Collection) properties.get("Streaming");
return true;
}catch (Exception e) {
return false;
}
}
public TestProfileBean getTestProfileBean() {
return testProfileBean;
}
public void setTestProfileBean(TestProfileBean testProfileBean) {
this.testProfileBean = testProfileBean;
}
public Collection getStreamingGcMany() {
return streamingGcMany;
}
public void setStreamingGcMany(Collection streamingGcMany) {
this.streamingGcMany = streamingGcMany;
}
}
|
Step 11
Update application context:
<bean id="TestProfileDAOTarget" class="it.reply.open.gawis.dao.TestProfileDAOImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="TestProfile" class="it.reply.open.gawis.profiles.TestProfile">
<property name="profileDAO">
<ref bean="TestProfileDAOTarget"/>
</property>
</bean>
<bean id="ProfileContainer" class="it.reply.open.gawis.container.ProfilesContainer">
<property name="profilesList">
<list>
…
<ref
bean="TestProfile"/>
…
</list>
</property>
<property name="profilesMap">
<map>
…
<entry>
<key>
<value>TestProfile</value>
</key>
<ref bean="TestProfile"/>
</entry>
…
</map>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
…
<property name="mappingResources">
<list>
…
<value>
it/reply/open/gawis/dao/beans/profilebeans/TestProfileBean.hbm.xml
</value>
…
</list>
</property>
…
</bean> |
[1] Naming convention: in GaWis DB every lookup
table name ends with suffix “_gc” (i.e. group capability)
If you are interested in more details about the release of GAIA Reply
as Open Source software and want to join us in the development of GaWis
please contact opensource@gaiareply.eu.
For more information about GAIA Reply please visit www.gaiareply.eu.
|
|
|