Full Text 01
Full Text 01
Full Text 01
November 5, 2012
Master’s Thesis in Interaction and Design, 30 credits
Supervisor at UmU: Åsa Holmner Rocklöv
Examiner: Håkan Gulliksson
Umeå University
Department of Applied Physics and Electronics
SE-901 87 UMEÅ
SWEDEN
Abstract
Smartphones are used by incredibly many people, and in 2011 there where a total of 491.4
million units soled worldwide. Smartphones are known as advanced phones, or personal
digital assistants (PDAs). This makes a relevant technique for performing dietary studies
when the test patients are on the move. This thesis shows how to create a back end en-
vironment for an Android application with existing techniques linked together, using MS
SQL database, Visual Studio Web Service, web pages and C# classes and ASP.NET secu-
rity. The back end development is used in a dietary study on Gothenburg University, but
could be applied on many similar back end projects using databases and server develop-
ment. Techniques used in this thesis are: REST (Representational State Transfer) -client
implementation and development inside the Android application, using HTTP methods to
set and get information from the server and database, and JSON-format to read and trans-
fer information in an easy and understandable way, both from the Android application and
from the database. FileMaker is also used in this project as a third part programme to
visualise the information in the database.
ii
Contents
1 Introduction 1
1.1 Gothenburg and Umeå university . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Statens livsmedelsverk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Paper outline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Background 5
2.1 PhD thesis project plan by Åsa Svensson . . . . . . . . . . . . . . . . . . . . 5
2.2 The database from SLV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Mats Högdals Android application . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3.1 Application database . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3 Problem Description 15
3.1 Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2 Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
iii
iv CONTENTS
5 Methodology 33
5.1 Android . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
5.2 Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
5.2.1 Web page design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
5.3 Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
5.4 FileMaker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
5.5 User guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
6 Resulting work 35
6.1 Android . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
6.1.1 Implementing REST-client . . . . . . . . . . . . . . . . . . . . . . . . 35
6.1.2 Programming and design . . . . . . . . . . . . . . . . . . . . . . . . . 37
6.2 Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
6.2.1 Web Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
6.2.2 Web page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
6.2.3 Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
6.3 Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
6.3.1 Database of dietary study . . . . . . . . . . . . . . . . . . . . . . . . . 46
6.3.2 ODBC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
6.4 FileMaker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
7 Conclusions 51
7.1 Future work and changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
8 Acknowledgements 53
References 55
A User guide 59
List of Figures
v
vi LIST OF FIGURES
vii
viii LIST OF TABLES
Chapter 1
Introduction
The focus of this thesis has been the back-end development of a pre-developed phone appli-
cation using an Android[16] operating system. The application is a dietary tracker which
will be used in a study aiming to teach children and teenagers to understand their dietary
habits.
The development of Internet and smartphones offers an unprecedented opportunity to
perform dietary studies. The possibilities given by the smartphones are many, as they
make it easy to have high definition graphic screens right in the pocket of its users, and
enough capacity to perform advanced technical computing such as video or image capitation,
downloading from Wifi or surfing on the Internet.
Android is the largest selling operating system in the forth quarter of 2010 according to
Canalys[9], making it the preferred choice.
1
2 Chapter 1. Introduction
techniques such as JSON-file format and REST-clients used in the android application as
well as the server is explained.
Background
This thesis is a part of a research project at the Department of food, nutrition and sport
science at GU, aiming to perform dietary studies on children using mobile technology. Specif-
ically, the outcome of the development performed in this thesis will be applied and evaluated
within the PhD project of Åsa Svensson. A front-end application has been designed and
developed by Mats Högdal, whereas this thesis was limited to the back-end component al-
lowing the application to retrieve data on specific food type and store data in a database
from SLV.
The development of smartphones the resent years has made it simpler to use advanced
techniques, which leads to the possibility to perform advanced studies on test persons out-
side of a usual laboratory or test environment, and the test persons could perform the test
on there own terms within the tests conduct rules. The capability of smartphones and
their ability to use external devices through cable, Bluetooth, Wi-Fi or some other technol-
ogy gives the test participant the possibility to preform advanced measurements on blood
pressure[35] and sleep rhythm.
Performing dietary studies with traditional methods, such as food diaries, questionnaires
and interviews are somewhat complicated and time consuming, both for the test participant
and the scientist. Moreover, these methods are relatively unreliable, since they all rely on
the participant’s memory, truthfulness and ability to judge the correct amounts of food
eaten[15].
5
6 Chapter 2. Background
of a new smartphone application necessary, and the development of this application is the
basis of a master thesis project.
– Food category (Livsmedelskategori): E.g. oil, rice, white bread, drinks and sweeteners.
– Dishes with (Rätter med): E.g. Pasta dishes, mushroom dishes and meat dishes.
Figure 2.1: Illustration of the graphical user interface. Start page (a) allows a new user to
register or an old user to log in, and registration page (b) where personal information can
be entered upon registration.
8 Chapter 2. Background
Figure 2.2: In the menu page (a), you are able to register the day, or look at saved days.
The saved days (b) page is showing meals and physical activity saved from earlier days. It
is also possible to choose statistics (c)(d), showing how much energy etc. your intake has
been.
2.3. Mats Högdals Android application 9
Figure 2.3: When registering food intake (a) the test participant could choose between date
(b), meal (c) and time (d).
10 Chapter 2. Background
Figure 2.4: When the test participant needs to find some kind of food (a), he or she could
either search by typing the name (b), or searching through categories of food (c). When the
food is found, it is saved on a specific date (d).
2.3. Mats Högdals Android application 11
Figure 2.5: When finding the food the test participant chose, it is given the choice of different
sizes of food on a plate to estimate how much food they have eaten.
12 Chapter 2. Background
Figure 2.6: When registering physical activity(a)(b), the test participant registers not only
the amount of physical exercise, but also if there has been any psychological problems that
day, or if the person actively has tried to change his or her weigh.
Problem Description
This project is part of a larger development involving an android application, divided into
front-end development and back-end development. The task is to develop the back-end part
of this application. For the application to work it is necessary to use a back-end developed
part that is able to contact and send information back and fourth to a database, since the
database is holding all information used in the nutrition study, and all information that is
going to be saved from the study.
To help the database to communicate, a server is necessary, with the capability to com-
municate between the smartphone and the database over the Internet.
Also a third part programme is used, to show the database information in an accessible
and readable way, and not only as values from a database column.
3.1 Goals
There are some specific goals that need’s to be reached in order for the application to work.
All the goals are set in a back-end point of view when developing, with the assumption that
the front-end part is fully developed.
These goals are parts used in an opening plan to make the back-end work as smoothly
as possible. The goals/parts shouldn’t be to many, making it hard to keep track of what is
doing what, e.g. in the source code.
Application goals: The application is using android OS, and to write an application
in android the code is written in Java[18] and XML[37]. The goal in the application is to
make it possible to communicate with the server, being able to send and collect information
when needed. It should be able to make a connection using Wi-Fi and if necessary translate
the values from the database.
Server goals: The main purpose of the server is to connect to the application and
database, and act as a translator/delivery agent for the values collected. The server goals
are divided into two: the first is that it should be possible to collect information coming
from a source over the Internet, being the android application, and make something useful
of the information, e.g. placing it into the database or using it to confirm values. The
second goal is that the server should be able to send information back to the source brought
from the database and sent back over the Internet.
Database goals: The database should contain the values given from SLV, and also
the new values collected by the application. The database should be made as simple as
15
16 Chapter 3. Problem Description
possible, using relations that is a common technique in database connections. Relations are
the connections between the tables in the database.
Database information goals: This programme or application should be used to show
the values from the database in a way that is readable in the programme SPSS[19]. The
possibility to alter or only show parts of the information in the database should also be
given though there is no one with technical education that is going to use the database.
This makes it necessary to show the information in an accessible and readable way.
Download goals: The goal is to make it possible to distribute the application to a
large number of users. The application should either be handed out or downloaded from a
webpage or similar.
Smart and simple code goals: the goal is to write code that is smart and simple,
making it easier to understand and read. When the project has ended, there is no one who is
going to continue working with the code as a developer. If someone wants to make updates
or change something it shouldn’t be too hard to achieve.
Security and integrity goals: All parts of the project should be protected. The
applications and the server traffic over the Internet should be encrypted. Also the server
connection to the database should be encrypted, since it contains information about private
individuals and measurement data from SLV.
3.2 Limitations
Limitations of the project are technical knowhow and physical restriction.
technical knowhow: The persons leading the project are not experienced in the pro-
grammes and techniques used in this back-end project. This makes it hard to know exactly
what the limitations in the project should be set at, e.g. what if some programme needs to
be changed or updated, what could happen then?
physical restriction: The smartphone should be able to use the application without
any phone card, making it reliable only to Wi-Fi. This means that the application is
restricted to send its information and communicate to the server freely.
Chapter 4
This chapter of the report contains an explanation on why some software where used. There
will also be a theoretical study consistent with the goals and what is required from the
project.
SVN
Eclipse is foremost used by Java developers, and since android is written in Java, it is a
good match combining the two. To help the project SVN[4] was used. SVN is a version
control system specifically developed to overcome some limitations in CVS (older version).
A version control system keeps track of history and change and makes it possible to step
back in time or to track who made previous changes. It allows for collaboration on the same
project for developers who are spread across the world.
To use SVN you need to download an appropriate SVN plug-in. An SVN suitable for
using in Eclipse are: http://www.eclipse.org/subversive/
17
18 Chapter 4. Technology and software
Given that the database from SLV where in MS SQL (Microsoft structured query language)
format, the obvious choice of main programme for creating the database was Microsoft SQL.
Also, it is not possible to use any other SQL programme other then Microsoft own when
using a MS SQL database. This means it is possible to get and set values in the database,
as with any other database, but it would not be possible to alter the database to the same
extent as if you were developing the database from scratch.
ODBC
To make it possible to connect a third party programme to the database, the use of ODBC
is needed. ODBC (Open DataBase Connectivity) is used as a separate small programme,
making a connection to the database usable from many different applications or operation
systems.
The third part programme in this project is used to show what is saved in the database,
in a simple and useful way and also making it possible to export the information in specific
format.
The choice of software for the server was (for obvious reasons) based on the choice of database
language. Thus, to make it easy to connect to the database, the natural choice fell on a
software capable of using ASP. ASP is a technique developed to read and write dynamic
web pages and application using information from databases. Microsoft programme Visual
Studio is used when making Web pages, Web services and Web applications, containing
ASP.NET[5], which are a web application framework and the successor of Microsoft ASP.
Web service
To make a connection between the android application and the database, the use of Internet
application capable of GET and SET methods to and from the database is important.
Creating a web service in visual studio makes this possible, since it contains web methods,
web pages, and C#[27] classes. C# is a simple object-oriented programming language
with similarities to Java, which was developed by Microsoft to be used within .NET. This
is particularly useful when there is a need to perform more complicated, object-oriented
programming, which is harder to do using only .NET.
4.1. Limitations in software 19
Figure 4.2: Complete software overview. The unknown third part programme is FileMaker,
but it is not combined in this illustration since it is used as a separate part.
20 Chapter 4. Technology and software
Mobile Web applications are the opposite of native applications, meaning they are de-
veloped on a separate platform, being able to be used on different native platforms. The
application is constructed as a webpage, but it is encapsulated inside a native shell. This
means an application could be used on Android, iPhone and Blackberry phones, looking
similar and operating in a similar way. The disadvantage with using Mobile Web applica-
tions is that the developer doesn’t get access to the phones hardware, such as camera, GPS
and Bluetooth.
API as the native applications preinstalled in Android smartphones. This makes it possible
to use all Android features, and to create custom made applications suitable for your own
purpose[25]. Some examples of useful features are:
– GSM, EDGE and 3G networks for data transfer, enabling you to send or receive data
across mobile networks.
– Web browser.
HTTP-connection
The possibility to create a native Internet-based application is offered in Android. This
means the application is relying on raw data coming from the Internet, e.g. XML or JSON-
files. This possibility of creating an Internet-based application is preferred when creating
social media application, not needing to go through Androids WebKit. I.e. cutting out the
middle hand[34]. Since the application is using raw data from the Internet, the methods
used for getting the data are HTTP methods, e.g. GET or POST[33].
Threads
In the beginning, every application runs on one main ”thread”, containing al tasks. A thread
is the smallest sequence of programmed instructions that can be managed independently.
This means that a simple task, such as downloading a image occupies the process. But
when using multiple threads, it is possible to download the image and do other tasks at the
same time, since different tasks are performed on different threads. To avoid a main thread
to freeze, hang up or even close down the application, the usage of multiple threading is
sometimes necessary. The reason to use threading is important, since the main thread don’t
perform any other task while the requested task is operational[34].
state. When the client has passed a request, and is waiting for an answer, the client is said
to be in transition. When the client receives the answer, it is ready to initiate a new state.
The name Representational State Transfer is chosen to simulate the transition the client
goes through. E.g. when a client requests a webpage it needs to wait for the request to
return (the webpage to show) before being able to initiate a new state (change to the next
page)[13].
REST-client/server communication is a stateless communication, meaning there is no
client information saved on the server. This makes it possible to change the client or server
independently, without having to change the mode of communication[13].
When a client is sending a request, it passes the information inside the URI as parameters
in the HTTP-header. Example[22]:
– URI: http://www.example.com/login
Additional information is sent inside the HTTP body, as metadata (data in data). This
metadata could be JSON, XML or another valid Internet media type. The response from
the server is then packed inside a HTTP-body (also containing metadata if requested), and
returned to the client[22].
The large advantage of using a REST is the ability to request information from a server,
e.g. a database server, and pass the information in a format easily read by the client (e.g.
JSON or XML).
4.3.2 JSON
JavaScript Object Notation (JSON) is a lightweight text-data interchange format, which is
language and platform independent. This makes it easy for both humans to read and for
machines to parse and generate[38]. JSON is built on two structures[23]:
The official Internet media type of JSON is application/JSON, and the primary usage of
JSON is to send and receive data from a server as an alternative to XML. E.g. suppose an
application wants to request something from a web page, if you are using XML the response
from the server needs to be parsed and structure by a Document Object Model (DOM), and
then used to update the web page. Alternatively, you could use JSON and get a JavaScript
Object represented as a string (i.e. a JSON-String) back from the server and use directly
as it is[20].
Making use of the server programme, many different parts are used in one web project. As
seen in picture 4.1, there are different parts needed, which has to cooperate to make the
server work. Some of these parts are more specifically about programming, while some are
a question about design, e.g. the web page.
Using the .NET framework when developing the web project is preferred since the frame-
work is highly supported by the database and server, which are coming from the same devel-
oper. The .NET framework is made from four different parts, Common Language Runtime,
a set of class libraries, a set of programming languages, and the ASP.NET environment [12].
24 Chapter 4. Technology and software
Common Language Runtime (CLR) makes it possible to use all the programming lan-
guages together in one runtime environment. A runtime environment provides a set of
operating system services to the executable code. These services take care of details in the
low-level operations system, such as physical memory allocation. Previous to the .NET
framework, e.g. Visual Basic and C++ hade there own runtime environments, making it
impossible for one language to work together with another, meaning they used double the
amount of memory needed, since they couldn’t share functions. With the introduction of
CLR it was possible to interoperate with each other, being able to allocate memory in one
language and release it in another language[12].
WebForms
Figure 4.5: WebForm uses a function called round-trips. When a user interacts with a
WebForm on a browser, it is requesting a process on the server, and the information is
submitted by the server and processed, returning the information back through a browser
(if an answer is requested) .[12]
Two different technologies are used when defining a Web service, the discovery mech-
anism and the service description. The discovery mechanism uses an XML document on
the server to enable client applications to detect if the web service exists, and if there are
any detailed description of that service. The service description describes the input and
outputs of the Web service. A Web service can be invoked ether by using raw HTTP, or by
using an XML message in a specific form called SOAP (Simple Object Access Protocol)[12].
Unfortunately Android does not support SOAP, making raw HTTP-code the option to use
when making the connection to the Web service.
26 Chapter 4. Technology and software
4.4.2 C#
C# or C Sharp as it is also called, is an object oriented programming language developed
by Microsoft in 2000. Since C# is object oriented it uses encapsulation, heritage and poly-
morphism. Encapsulation is when you place the functionality inside one package, heritage
is a structured way to extend code and functionality to new programmes or part of the
programme. Polymorphism is the ability to create a variable, a function, or an object that
has more than one form [6].
Another programming language used in .NET framework is Visual Basic.NET (VB.NET),
which is a BASIC programming language (Beginners All-purpose Symbolic Instruction
Code) developed to show college students a basic and understandable language when first
encountering computer programming. Both VB.NET and C# is part of the same .NET de-
velopment framework from Microsoft. The difference between the two languages is mostly
the syntactic, i.e. the words you use to write the code. Otherwise both of the languages
compile to the same runtime framework in .NET, and are both object-oriented languages.
This makes the choice between C# or VB.NET hard, but since there is a shorter learning
curve to C# than VB.NET, when using Java as a prior language (Which is used in the
Android application), C# would become the more natural choice of developing language.
should be named Default, index or iisstart, since this is the default value of the start page
IIS is searching for when opening a web page.
4.4.4 Security
It is quite important to keep a web service Internet secured, keeping unauthorised people
from altering or gaining your private information. Security in Microsoft platforms, as when
using web services, are divided into group 1. Security on IIS. 2. Client authentication. 3.
Client rights. The main difference when managing security on a public Internet application
like this, is that you don’t know who the users are, in comparison to when you manage
security on a local area network[31].
Client authentication
Client authentication is using the class FormsAuthentication inside the web project. This
class makes it possible to verify users using cookies and authorisation. In the web project
there is a file called Web.Config. Inside this file there is a section about the security on
the web project, and this is where you would alter the content if forms authentication were
used. As default, there are no restrictions in Web.Config, but by assigning authorisation
groups, ASP.NET directs all traffic to a specific form, where authentication is checked[31].
are used in many different sizes of systems and are called singel-user systems when de-
scribing smaller machines e.g. the phone book in a smartphone, and multi-user systems
if many users are able to use the database at the same time[10].
Between the physical database and the user, there needs to be a Database Management
System (DBMS). The DBSM in this project is MS SQL Server 2008 R2. MS SQL is a
database using a relational system, not to be compared with relationship in databases, even
though MS SQL uses relationship also.
Relation is how the database is built, and shown to users. The relational database is
based on logic and mathematic, making it easy teaching the foundations and principles[10].
The relational database could be explained as:
2. The operators available to the user for (e.g.) retrieval are operators that derive ”new”
tables from ”old” tables.
Relationship are the connections made between the tables in the database, used to
facilitate the user when retrieving information from the database.
4.5. Working with database 29
As seen from the name, Graph databases are databases who´s not using the traditional
relational database structure, where you save information in tables. Large companies as
Facebook, Google and Amazon have made their own versions of this kind of database, for
its capability to handle large amounts of data. The idea of a graph database is not new,
going back to the eighties, but in recent years the large-scale usage of graph databases
has emerged thanks to foremost social network developing companies having thousands of
people connection to their databases at once[3].
The essential theory about graph database is similar to object oriented programming
(OOP), making it’s structure understandable for developers using OOP languages. The
idea is to have the information in the database inside nodes (or sometimes called vertex),
and to have a connection between nodes called edge[28]. This means that the the database
is using a graph as its primary data structure.
30 Chapter 4. Technology and software
Figure 4.12: In social web pages as Facebook, many users are connected to each other. This
makes the connections aware of each other, making notifications to many people at the same
time. On social web applications like Twitter, the users are followers of each other. This
means that the information sent over the database are sent in a linear direction, going from
one person to the next.
The usage of graph database is a natural evolution coming from the progress of Internet
structure. In the beginning there where one person going on to one webpage, finding the
information this person needed. This developed to becoming several webpages working
together, moving on to become the social web. Social web are a way of social interaction
using internet. It could mean online shopping, gaming or social web sites as Facebook[28].
4.5. Working with database 31
Figure 4.13: Difference in web, from early usage to todays social web.
Methodology
Creating the solutions and designs in this project was not advanced work, but it was more
time consuming then originally planed, resulting in a delay of several weeks. One of the
main reasons for this time consumption were the project specifications who kept altering,
making the design from one week obsolete, and new ones needed to be created.
Since this was not a front-end project (front-end development were made by Mats
Högdal), it was not a question about drawing buttons and interfaces, and making user
test on the interface. It was about how the back-end parts as simple as possible is made to
fit in the goals description.
Using the goals to perform and plan the back-end development gave some specific parts
needed. The ability to secure information from the application, and sending it to the server
were one of the most important goals. THe information should also be structured and stored
in a efficient way.
5.1 Android
The android development started with the search on how to transfer information from the
smartphone onto the Internet.
The first step of development was what format the information should be. The choice was
between XML and JSON. JSON where chosen because of the easy readability in Android.
It could be contradictory since Android applications are written in Java and XML. But it
does not mean that XML would be easier to use when sending the information using server
and database.
The second step of development were to send the information using a REST-client. Hav-
ing read about REST-clients techniques, it suited this project well. REST uses a standardi-
sation, easy to adapt to the projects Internet transfer. Using this technique, the information
could be easily packed and a connection to the server would be created at the same time.
5.2 Server
In the beginning of the project, there was a discussion on whether or not to use PHP to
transfer information. PHP uses simple codes and do not take much space on the server.
However, this would mean that that the application would be responsible of all calculations
needed to be done before sending the information to the database. When the database
33
34 Chapter 5. Methodology
from SLV were used, it were in MS SQL format, making the choice to use PHP obsolete
since PHP and MS SQL connections were a new technique. That gave the point of using
Microsoft developer programmes, being adaptable and commonly used techniques. Thus,
the connection to the database would be of minimal problem, and the transition between
programmes would be easy.
Inside the Web Project, a Web Service were made. This Web Service could do a numerous
things, e.g. send and read HTTP methods (GET,PUT,POST,UPDATE), and it would fit
the REST-client made in the application.
Inside the Web Service, the need to calculate information and transform information
from the database to JSON, was possible because of the ability to use programming files
next to the Web Service. These files could ether be made in C#, the programming language
in ASP.NET or by Visual Basic. C# were more similar to the object oriented language
Java, and therefor C# was chosen.
5.3 Database
The design of the database were made to be a copy of the parts needed from the database
in the application, and were made in a lowest necessary need basis. Some of the tables were
direct copies from the application database, since it was identified to be the easiest way of
sending information.
If the table in the application containing personal information were lost, the backup on
the server wouldn’t have all the necessary information needed, but now the user don’t need
to fill in the gaps. The other tables are a collection of information from the application
database and the information needed from SLVs database.
5.4 FileMaker
The main function of FileMaker was its ability to show information easily from a database,
and to export it to SPSS. The design used in FileMaker is simple, directly made from
FileMakers own standard templates. There were no need to make any extra interface, since
it only would show the information as it is inside the database.
Resulting work
Inside this chapter a thorough overview on the work is shown containing all parts of the
project. First of is the android application back-end development, implementing a REST-
client and how to use it. The next step is the server, showing the web pages, security and
how the information from the android application is received, translated and sent back if
requested from the application. The database is explained, showing how it is created, and
how to use it. FileMaker is the third part programme used to how the information in the
database. It is explained and it is shown how to be used.
6.1 Android
Inside the Android project, different main parts where made to complete the goals. The first
part where the ability to connect to the server, using a REST- client, with specific attributes
to fit the applications purpose. The second part is going a bit deeper inside the project,
focusing on the programming design and how the different classes are working together.
Since the android application is developed on two separate locations, the android classes
inside this project are developed as autonomous as possible. This makes it easier for all
project developer to make changes without disturbances or delaying.
The REST-client is using a client to communication with the server, where the client passes
the information to the server, the server process the information and returns a response
[13]. This kind of information transfer is useful in an application, when its main Internet
connection purpose is to send and receive simple information from a server, being the data
to and from the database containing dietary information about the test participant.
35
36 Chapter 6. Resulting work
Figure 6.1: The REST-client path. (1) The information is sent from the android application
to the translator class. (2) The translator class transforms the information to JSON-format
and transfer it to connect class. (3) The connect class makes the connection to the server,
and sends the information. (4) If the connect class requests a answer from the server, it is
sent back in JSON-format. (5) The information is sent back to the translator class, and
extracted. The translator class checks where to send the information inside the application
before it is sent. (6) The information is used inside the application.
The Internet status control is used since the application can’t be relying on Internet
connection as Wi-Fi or 3G. When a test participant wishes to send information to the
server, and there is no Wi-Fi close by, this information needs to be sent at a later time.
If the Internet connection is closed down, the application could easily save the information
and send it as soon as it goes online. To do this, it needs to know the connection status of
the application.
Creating new threads are important for the application to perform correctly and without
delay. The main thread in Android is the one responsible for all main graphics, if nothing is
altered or added to the project by the developer. For example, if the test participant needs
to get dietary information from the server using the REST-client, it would try to connect
to Internet (i.e. Web Service) and wait for the answer. Since this request is done on the
main thread, all other activities would freeze until the task is complete. If the information
(file size) is large it could take minutes to download and the application would be frozen.
To solve this potential problem, a new thread is created for every request made by the
application user, and the download is not noticeable.
The timer is used with a Service, which is not a thread, but a means in Android to do
background processing inside the main activity thread. This is used for time consuming
(but not process consuming) activities, such as a timer. Since it is part of the main thread,
it will follow the applications warnings and interruptions.
38 Chapter 6. Resulting work
Figure 6.3: This image shows the REST-client process. When the test participant sends
the information, it firstly needs to check if it is connected to the Internet. If there is no
connection, it saves the information and starts a timer trying to see if there is any connection
possible. If there is a connection, or the timer finds a connection, a new thread is created
to send the information.
6.2 Server
In this project, the server is used as a communicator, project holder, storage and calculation
devise. All of this was made possible inside the Web Service.
.apk file
One of the main reasons to use a server was the ability to place an application package file
(.apk) file on it, and being able to downloading it from the server simply by clicking on
the file. This is done from the web browser, on the test participant’s Android phone. This
makes it much easier as a developer to give the application to whoever needs it. I.e. only
people performing the test have access to the web page containing the application file. The
android phone has a restriction when using application files from unknown sources. To use
the application the user needs to remove the restriction inside the phone, on the settings.
This is simply done by accepting it inside the settings of the phone, and accepting that the
application is using the phones Internet when installing it. Many other applications use the
6.2. Server 39
same technique as this application; the only difference is that the test participants now need
to accept the settings.
Creating a connection to the database inside the Web Service is the primary function of
this Web Service. It is done by using an .asmx file containing the web methods called from
the Android application. All of these methods are written specifically to handle one task,
but the most common one are simple GET or SET information to the database. When
getting information from the database, it is called by the application, given some or none
parameters of what is should get, and retrieves the information by using SQL Queries. The
information is then packaged and sent back to the application.
Sending information to the database through the Web Service is a bit more complicated.
The information needs to be sent through the REST-client (see section Android). When the
information is collected by the web method, the information is passed on to the web service
classes and placed inside the right database table. If the information is about updating the
database, it is passed down using SQL queries. However, if the information needs to be
controlled against the database or calculated, it is sent from the web method into the right
C# class, where it is calculated and passed down to the database.
40 Chapter 6. Resulting work
The ConvertClass is the most important class inside the Web Service. It is the class that
takes the information given from the database and transforms it into a JSON-array. The
information from the database is shown the same way as they are placed, in tables. It is
possible to send this information directly to the application, but then it would be harder to
pinpoint some exact value, as it only would be read as a text file.
CheckClass
The Checkclass is the class used when some information needs to be confirmed inside the
database. If the test participant is passing on some new private information, this class
checks if the user exist, if the information in the database needs to be altered or replaced,
and gives the correct response back to the web method. This class also examines if there are
some food types needed to be changed in the database, or the information passed is older
then the one in the database.
CalculateMealClass
CalculateMealClass takes the meal information from the application, and places it in the
correct database table. This is demanding some GET and SET methods from the database,
since the food needs to be calculated depending on how much you eat, what you eat and
when you eat. E.g. if the test participant eats an apple, with a weight of 46 gram. The
information is sent to the web method and passed to the CalculateMealClass. The class
then finds out what kind of nutrition an apple contains, and since it is given in 100 gram,
the nutrition needs to be reduced from 100 gram to 46 gram. The information is placed in
the database, in the tables containing nutrition, nutrition per meal, nutrition per day and
nutrition per main group. If the test participant changes the information, from an apple to
an orange, all the information in the tables needs to be changed.
6.2. Server 41
CalculateTranspondClass
To make the information in the tables usable in the programme SPSS[19], It has to be
transponded, that is, shifted from row pairs into table columns. This is so the information
is easily read and used inside FileMaker and SPSS. This kind of information altering is not
something MS SQL does easily, so it was necessarily to make this kind of change manually
using C# methods. The tables containing this information is made to match the tables used
by CalculateMealClass, except that they are shifted to the side.
DeleteMealClass
DeleteMealClass has the simple task of deleting information inside the database, though all
information is not always replaced with new. It is also the class responsible for altering or
deleting information when the user changes a meal item or some nutrition in the database.
Since the database is containing nutrition information over different aspects, such as meal,
day etc. it is important that the final amount is calculated correctly at the end of the day.
6.2.3 Security
Security inside the Web Service is most important, otherwise all kinds of different persons
could easily gain information from the database. It is also important to ensure the integrity
of the participants by keeping names, personal information and dietary habits concealed to
unauthorised people.
Security have been implemented in the server, and Web page security using cookies was
used. This means that the login information is saved a short time, since the cookie used
inside this Web Project is using a timeout after 10 minutes. Besides using the Login.aspx
web page, there needs to be more backside information for this to work. Inside the Web
Service Web.config file (the file where authentications and behaviour of the Web Service is
written), the permission to all the web pages are given.
6.3. Database 45
Figure 6.10: The ? (questionmark) means all users, and the * (star) means all registered
users. The * could also be replaced with a specific name, or a group meaning only this
person/group have access to the webpage.
Figure 6.11: This is how the forms authentication is processing when it checks if a user is
valid[26].
The Web service uses the same database as the food measurements, giving it a couple
of extra tables to keep track of new users. These are the tables the Forms authentication
and the AdminPage.aspx use. Inside the AdminPage are you able to see the username,
all available users, create new users, change password on old users and remove users if not
needed anymore.
6.3 Database
The database is divided into three parts. The first part is from SLV, the second part is
the one used in the dietary measurements and the third part is the one used by the Web
Service.
46 Chapter 6. Resulting work
The first part, containing all the different tables from SLV is explained in chapter 2
(Background). The third part is created and used by the Web Service containing all tables
to keep track of all users of the web pages and the security if those. This is also where you
assign administrators to the project.
Figure 6.12: The dietary study database is connected to several tables from the SLV
database, taking all information from those tables and placing it inside the dietary study
tables.
6.4. FileMaker 47
6.3.2 ODBC
ODBC (Open DataBase Connectivity) is used to create a connection between FileMaker
and the database. In windows, a ODBC source is available for free, but for Macintosh it
has to be downloaded as a third part programme.
6.4 FileMaker
FileMaker was the programme chosen to simplify for the non-developers of the project to
access and visualise the data. This programme is a way of reading database information
in a simple manner and to export the information to a format readable to SPSS. First of,
there are seven different pages created. All of these contain different information:
– (1) Get all users.
48 Chapter 6. Resulting work
The top three pages shows simple information as usernames etc. The later four shows
the more important information of the project, e.g. nutrition. The information sent to
these comes from the tables that are transponded (see chapter 6, section 3), and therefor
these tables are also transponded and ready to be exported. In FileMaker, it is possible to
search for a specific person or meal, making it possible to filter the information and show
only information that is relevant for a certain user. Also, in the later four, the information
about the test participants is added.
6.4. FileMaker 49
Conclusions
The work in this project contained many different implementations, from the implemen-
tations of databases, programming classes to web pages. This makes it hard and time
consuming to deliver all the pieces needed, and the focus on the work is to make the parts
work together, and identify and choose parts that do work together.
The biggest challenge in this project was the time aspect. When needed to optimise
and create a system with parts never been used by the developer, a lot of time is needed to
understand the software and workflow. Creating a Web Service was in the beginning a bit
confusing, but when understanding the GUI and workflow, it showed real good capacity.
All the original goals where reached, and the back-end is fulfilling its purpose. From the
beginning, the goals where not set in stone, they where more guidelines of what was needed
in the project. When the project developed forward, more specific goals could be created.
51
52 Chapter 7. Conclusions
FileMaker fills it purpose of use, but it has a flaw. It could only contain 66 columns
[14] after each other in the views, making it necessary to create two separate views for one
database containing all 53 nutrition values plus the information about the user. If this were
changed in a newer version of FileMaker, it would be much appreciated and used.
Chapter 8
Acknowledgements
I’d like to give a big thanks to everyone who has been involved in the project:
53
54 Chapter 8. Acknowledgements
References
[3] R. Angles and C. Gutierrez. Survey of graph database models. ACM Computing
Surveys (CSUR), 40(1):1, 2008.
[5] ASP.net. Web development with power, productivity and speed. http://www.asp.net/.
[Online; accessed 26-April-2012].
[6] J Bradley. Lär dig C# på tre veckor, pages 10–13. Pagina Förlags, 2002.
[8] T.L. Burrows, R.J. Martin, and C.E. Collins. A systematic review of the validity of
dietary assessment methods in children when compared with the method of doubly
labeled water. Journal of the American Dietetic Association, 110(10):1501–1510, 2010.
[9] Canalys.com. Google´s android becomes the world´s leading smart phone platform.
http://www.canalys.com/newsroom/google [Online; accessed 27-March-2012].
[10] C.J. Date. An introduction to database systems, pages 3–104. Pearson, 2008.
[12] J. Ferguson, P. Boutquin, and M Gupta. C# Bible, pages 4–16, 422, 533–549. Wiley
Technology Publishing, 2002.
[13] R.T. Fielding. Architectural styles and the design of network-based software architec-
tures. PhD thesis, University of California, 2000.
[15] R.S. Gibson. Principles of nutritional assessment. Oxford University Press, USA, 2005.
55
56 REFERENCES
[20] IBM. Using xml and json with android, part 1: Explore the benefits of json
and xml in android applications. IBM developerWorks, August 2010. [On-
line; accessed 25-April-2012] http://www.ibm.com/developerworks/web/library/x-
andbene1/index.html?ca=drs-.
[21] iki.gu.se. Göteborgs university (gu) and the department of food and nutrition, and
sport science. http://www.iki.gu.se. [Online; accessed 27-March-2012].
[22] E. Jansson and N. Jonasson. Speedflirt of android, a study of porting a mobile appli-
cation and it’s affects on user experience. Master’s thesis, University of Umeå, 2011.
[24] kost.umu.se. Umeå university and the department of food and nutrition.
http://www.kost.umu.se/. [Online; accessed 27-March-2012].
[31] G Shepherd. Microsoft ASP.Net 2.0 Steg för steg, pages 229–256. Pagina förlags AB,
2006.
[34] J. Steele and N. To. The Android developers cookbook - building applications with the
Android SDK. Addison-Wesley, 2010.
REFERENCES 57
[35] S. Sultan and P. Mohan. How to interact: Evaluating the interface between mobile
healthcare systems and the monitoring of blood sugar and blood pressure. In Mobile
and Ubiquitous Systems: Networking & Services, MobiQuitous, 2009. MobiQuitous’ 09.
6th Annual International, pages 1–6. IEEE, 2009.
[36] Å. Svensson. Validering av olika kostundersökningsmetoder samt utveckling och valid-
ering av en ny kostundersökningsmetod för användning med mobiltelefon. Doktorand-
projektplan för en sammanläggningsavhandling, March 2010.
[37] W3C. extensible markup language. http://www.w3.org/standards/xml/. [Online;
accessed 13-April-2012].
User guide
59
Sammanfattningsdokument
Kostapplikationen
Fredrik
Bäck
Inloggningsuppgifter
GU-‐konto:
Användarnamn:
Lösenord:
MS-‐Server
Serverutrymme:
URL:
http:
Användarnamn:
Lösenord:
MSSQL-‐databas
Namn:
Användarnamn:
Lösenord:
URL:
IP-‐adress:
VPN
Samma
som
GU-‐konto
Filemaker
FTP:
www.ftp.gu.se
(Användning
av
VPN
nödvändig
om
man
är
utanför
GU-‐nätet).
I
programmet
används
samma
som
till
MSSQL-‐databasen.
Installationsuppgifter:
Användarnamn:
Organisation:
Licensnyckel:
SVN
(Sourceforge)
URL:
Användarnamn:
Lösenord:
Användning
VPN
Virtual
private
network
(VPN),
på
svenska
”virtuellt
privat
nätverk”,
är
en
teknik
som
används
för
att
skapa
säkra
förbindelser,
så
kallade
tunnlar,
mellan
två
punkter
i
ett
osäkert
datanätverk.
VPN
måste
alltid
användas
när
man
inte
är
inne
på
GU:s
nätverk/Eduroam
för
att
komma
åt
servern
eller
databasen.
http://www.it.gu.se/foranvandare/guwlan/eduroam/
För
att
skaffa
VPN,
gå
in
på:
http://www.it.gu.se/foranvandare/vpn
MS-‐server
(Microsoft-‐server)
Till
MAC:
För
att
komma
åt
serverutrymmet
använder
man
SMB
(Server
Message
Block).
För
att
logga
in
på
SMB
från
MAC
används
denna
guide:
http://support.apple.com/kb/ht1568
Till
Windows
(rekommenderat):
För
att
komma
åt
utrymmet
med
Windows
lägger
man
till
en
ny
nätverksenhet.
1. Gå
in
på
Dator.
2. Välj
anslut
nätverksenhet.
3. Välj
en
ledig
enhet
(B,C…X,Y,Z).
4. Ange
länken
till
serverutrymmet.
a. Ange
användarnamn
och
lösenord
där
det
är
nödvändigt.
b. Om
du
inte
kan
logga
in,
kontrollera
att
du
är
på
GU:s
nätverk
inloggad
med
x-‐konto,
eller
att
du
använder
VPN
med
x-‐konto.
Denna
nätverksenhet
används
sedan
när
man
ska
lägga
upp
hemsidor
eller
liknande
från
Microsoft
Visual
Studio
som
ska
användas
på
matmobil.ped.gu.se
Det
som
finns
på
nätverksenheten(servern)
nu
är
skapat
som
ett
webbprojekt
i
Microsoft
Visual
Studio,
vilket
är
ett
lämpligt
program
att
använda.
3.
Om
anslutningen
fungerar
kommer
databasen
synas
till
vänster
i
programmet.
Microsoft
Visual
Studio:
1. Gå
in
på
View,
Server
explorer.
2. Tryck
på
connect
to
database.
3. Skriv
in
uppgifterna
till
databasen,
testa
sedan
anslutningen
(test
connection).
4.
Fungerar
anslutningen
som
den
ska,
tryck
ok.
Databasen
ska
då
komma
upp
i
Server
Explorer
till
vänster.
Visual
Studio
I
Microsoft
Visual
Studio
är
webbprojektet
skapat.
För
att
kunna
ladda
upp
projektet
till
servern
behöver
man
först
skapat
en
nätverksenhet
(se
MS-‐server
ovan).
1. Kolla
så
att
nätverksenheten
är
igång.
2. Starta
VS-‐projektet.
3. Välj
Build,
Publish
”namn
på
projektet”.
4. Ange
nätverksenheten
som
mottagare.
2. Ange
System-‐DNS,
Lägg
till.
3. Välj
SQL
Server
Native
Client
10.0.
Finns
inte
den
behöver
man
ladda
ner
en
uppdatering
till
Windows:
http://www.microsoft.com/download/en/details.aspx?id=16177,
välj
sedan
Microsoft
SQL
Server
2008
Native
Client
som
finns
listat
en
bit
ner
på
sidan.
4. Döp
kopplingen
till
wh-‐matmobil
OL.
Det
är
viktigt
då
kopplingen
i
FileMaker
heter
så.
5. Ange
användarnamn
och
lösenord
till
SQL-‐databasen.
6. Ange
att
default
database
ska
vara
WH-‐Matmobil.
7. Testa
anslutningen
och
spara.
ODBC-‐källan
kommer
sedan
hittas
automatiskt
av
program
som
använder
ODBC,
som
t.ex.
FileMaker.
OBS.
Om
anslutningen
inte
syns
i
FileMaker
är
det
för
att
man
har
angett
en
64-‐bit
version
av
ODBC
källa.
FileMaker
kan
endast
läsa
32-‐bit
ODBC-‐källor.
Då
behöver
man
gå
in
på
C:\Windows\SysWOW64\odbcad32.exe.
Dubbelklicka
på
filen
odbcad32.exe.
Där
får
man
ange
en
ny
ODBC-‐källa
enligt
anvisningarna
ovan.
Filemaker
OBS.
Innan
man
kan
starta
FileMaker
behöver
ODBC-‐kopplingen
vara
skapad.
Om
man
inte
är
inne
på
GU:s
nätverk
eller
Eduroam
behöver
VPN-‐anslutningen
vara
på.
Filemaker
laddas
hem
från
www.ftp.gu.se
och
installeras
som
ett
vanligt
program.
Starta
projektet
i
FileMaker:
1. Kontrollera
att
ODBC-‐kopplingen
är
skapad
med
namnet
wh-‐matmobil
OL.
2. Starta
FileMaker.
3. Starta
projektet
genom
att
trycka
på
Bläddra
i
mitten
längst
ner
och
välj
FileMakerfilen.
4. Projektet
kommer
då
vilja
att
du
anger
inloggningsuppgifter
för
databasen
som
den
hämtar
information
ifrån.
Hoppa
över
detta
steg
genom
att
trycka
på
Avbryt.
5. FileMaker
kommer
då
starta
men
visa
tomma
tabeller.
6. Gå
in
på
Arkiv,
Hantera,
Externa
datakällor.
7. Markera
den
ODBC-‐källa
som
finns.
Tryck
sedan
Redigera.
8. Välj
Ange
för
DNS.
9.
Markera
den
nyskapade
datakällan
(SQL
server
native
client
10.0).
Tryck
OK.
9. Tryck
OK
i
programfönstret
”Redigera
datakälla”.
10. Tryck
OK
i
programfönstret
”Hantera
externa
datakällor”.
11. Nu
ska
databasen
synas
i
FileMaker.
3. Gå
in
på
hemsidan
som
apk-‐filen
finns
genom
telefonens
internet.
Ladda
hem
filen.
4. Installera
applikationen
i
telefonen.
5. Hittar
man
inte
programmet
eller
ska
ta
bort
det
finns
det
under
hantera
program
(manage
applications,
se
bild
ovan).
SVN(Sourceforge)
SVN
är
ett
versionshanteringssystem
speciellt
utvecklat
för
att
komma
tillrätta
med
vissa
begränsningar
i
CVS(äldre
version).
Ett
versionshanteringssystem
håller
reda
på
historik
och
förändringar
och
gör
det
möjligt
att
backa
tillbaka
i
tiden
eller
att
spåra
vem
som
gjort
vad.
Dessutom
möjliggör
det
samarbete
på
samma
projekt
för
utvecklare
som
är
spridda
över
världen.
Till
SVN
används
ett
konto
på
www.Sourceforge.net.
För
att
använda
SVN
behöver
man
ladda
hem
ett
lämpligt
SVN-‐tilläggsprogram,
där
man
sedan
använder
inloggningsuppgifterna
för
att
ladda
hem
projektet.
Ett
SVN
som
är
lämpligt
att
använda
är:
http://www.eclipse.org/subversive/
För
att
programmera
applikationen
används
ett
program
som
heter
Eclipse.
Eclipse
finns
att
ladda
ner
från:
http://www.eclipse.org/downloads/.
För
att
kunna
utveckla
Android
behöver
man
Android
SDK,
vilket
man
laddar
ner
från
http://developer.android.com/sdk/index.html
Använda
SVN
i
Eclipse:
1. Gå
in
på
File,
Import,
SVN,
Project
from
SVN.
Tryck
Next.
2. Välj
create
a
new
repository
loation.
3. Ange
den
URL
som
finns
vid
inloggningsuppgifterna,
samt
användarnamn
och
lösenord.
4. Tryck
Finish.
Projektet
ska
då
dyka
upp
till
vänster
i
programmet.
5. För
att
uppdatera
versionen
högerklickar
man
på
projektet,
sedan
Team,
update.
Om
man
vill
skicka
upp
en
ny
version
gör
man
lika,
men
trycker
commit
istället
för
update.
Uppbyggnad
Databasen
Kontaktuppgifter
Fredrik
Bäck
Tel:
0733
52
43
93
Mail:
beck.fredrik@gmail.com
SLV
Marianne
Arnemo
Tel:
018-‐175500
Mail:
marianne.arnemo@slv.se
Tekniker:
Fredrik
Willander
Tel:
0733-‐899
558
Mail:
Fredrik.Willander@slv.se
GU
Servertekniker:
Joakim
Larsson
Tel:
031-‐7865313,
0768-‐880255
Mail:
Joakim.larsson@handels.gu.se