scieee AI-readable full text Open interactive document viewer

Study and development of a device tracking software

Diaz i Benitez, Albert

Abstract

Aquest projecte consisteix a desenvolupar una nova versió de l'API de geolocalització de TooPath utilitzant les tecnologies actuals. La nova versió oferirà un sistema de seguiment per a qualsevol tipus de dispositiu electrònic i una web per consumir i demostrar les funcionalitats de l'API.

Full text

Universitat Polit` ecnica de Catalunya Facultat d’Inform` atica de Barcelona Grau en Enginyeria Inform` atica (GEI) Software Engineering Study and development of a device tracking software Author: Albert D´ ıaz Benitez Director: Jaume Figueras i Jov´ e Ponent: Dr. Antoni Guasch i Petit Thursday 18th January, 2018 i Abstract A device tracking software is a software installed in an electronic device that is capable of reporting the device’s location remotely. The average individual is likely to utilize multiple mobile technology applications daily. The applications have gained the ability to process more and more information to further enhance their features. The geolocation is one of the most important feature of these mobile applications. There are a lot of geolocation software but most of them aren’t open source and they need to be bought to be used. Open source software applications are those in which the source code or the base code is available for modification or enhancement by anyone. InLab FIB has developed the TooPath environment for tracking mobile devices with a GPS. TooPath is the first free tracking system made of 100% free and open source data and technologies. However, the current version of TooPath is no longer maintained and non operative. This project consists on developing a new version of the TooPath geolocation API using current technologies. The new version will offer a geotracking system for any kind of electronic device and a web to consume and demonstrate the API functionalities. A study and analysis of the open source licenses is done on the project as the API is offered as open source software. ii Resum Un software de seguiment de dispositius ´es un software instal·lat en un dispositiu electr`onic capa¸c de transmetre la ubicaci´o del dispositiu de manera remota. ´ Es probable que l’usuari mitj`a utilitzi diverses aplicacions m`obils cada dia. Les aplicacions han guanyat la capacitat de processar m´es i m´es informaci´o per millorar encara m´es les seves caracter´ıstiques. La geolocalitzaci´o ´es una de les caracter´ıstiques m´es importants d’aquestes aplicacions m`obils. Hi ha molts softwares de geolocalitzaci´o, per`o la majoria d’ells no s´on de codi obert o open-source i cal pagar per utilitzar-los. Les aplicacions de software de codi obert s´on aquelles en qu`e el codi font o el codi base estan disponibles per a la seva modificaci´o o millora per part de qualsevol persona. InLab FIB ha desenvolupat l’entorn de TooPath per al seguiment de dispositius m`obils amb un GPS. TooPath ´es el primer sistema de seguiment gratu¨ıt fet al 100% de dades i tecnologies de codi obert. No obstant aix`o, la versi´o actual de TooPath ja no es mant´e i no est`a operativa. Aquest projecte consisteix a desenvolupar una nova versi´o de l’API de geolocalitzaci´o de TooPath utilitzant les tecnologies actuals. La nova versi´o oferir`a un sistema de seguiment per a qualsevol tipus de dispositiu electr`onic i una web per consumir i demostrar les funcionalitats de l’API. Tamb´e s’ha fet un estudi i an`alisi de les llic`encies de codi obert dins del projecte, ja que l’API s’ofereix com a programari de codi obert. iii Resumen Un software de seguimiento de dispositivos es un software instalado en un dispositivo electr´onico que es capaz de informar de la ubicaci´on del este de forma remota. Es probable que el individuo promedio use m´ultiples aplicaciones de tecnolog´ıa m´ovil diariamente. Dichas aplicaciones han adquirido la capacidad de procesar m´as y m´as informaci´on para mejorar a´un m´as sus caracter´ısticas. La geolocalizaci´on es una de las caracter´ısticas m´as importantes de estas aplicaciones m´oviles. Hay un gran cantidad de software de geolocalizaci´on, pero la mayor´ıa de estos no son de c´odigo abierto y deben comprarse para ser utilizados. Las aplicaciones de software de c´odigo abierto son aquellas en las que el c´odigo fuente o el c´odigo base est´an disponibles para modificaci´on o mejora por parte de cualquier persona. InLab FIB ha desarrollado el entorno de TooPath para rastrear dispositivos m´oviles con un GPS. TooPath es el primer sistema de seguimiento gratuito hecho de tecnolog´ıas 100% de c´odigo abierto. Sin embargo, la versi´on actual de TooPath no se mantiene y no es operativa. Este proyecto consiste en desarrollar una nueva versi´on de la API de geolocalizaci´on TooPath utilizando las tecnolog´ıas actuales. La nueva versi´on ofrecer´a un sistema de seguimiento para cualquier tipo de dispositivo electr´onico y una web para consumir y demostrar las funcionalidades de la API. Tambi´en se realiza un estudio y an´alisis de las licencias de c´odigo abierto en el proyecto, ya que la API se ofrece como software de c´odigo abierto. iv Acknowledgements I would like to thank inLab FIB for giving me the opportunity to do this project as my Final Degree Project. Specially, to my project manager Jose Francisco who has helped me, taught me a lot of development patterns and given me some tips. Also, I would like to thank my colleague, Sergio Paredes, for helping me improve and giving me his opinion as developer when I had doubts. I would like to thank Antoni Guasch and Jaume Figueras for supervising the project and giving me some useful advice. Also, to Jaume for the job done as product owner. I would like to thank my family for support me all these years during the bachelor degree. I would to thank all the classmates and specifically, Gerard Pradas and Pau Vilanova. Lastly, I would like to thank my girlfriend, Gabriela L´opez, for giving me strength to finish this project and support me on these hard months of work. Without her I couldn’t have finished this degree. v Index List of Figures ix List of Tables x List of Listings xi Glossary xii Acronyms xv 1 Introduction 1 1.1 Context .............................. 1 1.2 Stakeholders............................ 2 1.3 Problem formulation . . . . . . . . . . . . . . . . . . . . . . . 3 1.4 Stateoftheart .......................... 4 1.5 Scope ............................... 5 1.5.1 Projectgoals ....................... 6 1.6 Methodology ........................... 7 1.7 Monitoring and development tools . . . . . . . . . . . . . . . . 10 2 Project management 11 2.1 Schedule.............................. 11 2.2 Generalplanning ......................... 11 2.3 Projectplanning ......................... 14 2.3.1 Sprints description . . . . . . . . . . . . . . . . . . . . 14 2.3.2 Estimated time . . . . . . . . . . . . . . . . . . . . . . 17 2.3.3 Ganttchart ........................ 17 2.4 Projectbudget .......................... 18 2.4.1 Human resources budget . . . . . . . . . . . . . . . . . 18 vi 2.4.2 Hardware budget . . . . . . . . . . . . . . . . . . . . . 21 2.4.3 Software budget . . . . . . . . . . . . . . . . . . . . . . 21 2.4.4 Unexpected costs . . . . . . . . . . . . . . . . . . . . . 22 2.4.5 Indirect costs . . . . . . . . . . . . . . . . . . . . . . . 22 2.4.6 Budget monitoring . . . . . . . . . . . . . . . . . . . . 23 2.4.7 Totalbudget ....................... 23 2.5 Sustainability ........................... 24 2.5.1 Economical ........................ 24 2.5.2 Social ........................... 25 2.5.3 Environmental . . . . . . . . . . . . . . . . . . . . . . 26 3 Requirements analysis 27 3.1 Non functional requirements . . . . . . . . . . . . . . . . . . . 28 3.2 Functional requirements . . . . . . . . . . . . . . . . . . . . . 29 4 Specification 31 4.1 APIspecification ......................... 31 4.1.1 Functionalities . . . . . . . . . . . . . . . . . . . . . . 32 4.1.2 Conceptual schema . . . . . . . . . . . . . . . . . . . . 46 4.2 Webspecification......................... 47 4.2.1 Functionalities . . . . . . . . . . . . . . . . . . . . . . 47 4.2.2 Conceptual schema . . . . . . . . . . . . . . . . . . . . 50 5 Design 51 5.1 System architecture . . . . . . . . . . . . . . . . . . . . . . . . 51 5.1.1 Server ........................... 51 5.1.2 API ............................ 51 5.1.3 Web application . . . . . . . . . . . . . . . . . . . . . . 52 5.1.4 Components communication . . . . . . . . . . . . . . . 52 5.2 APIdesign............................. 52 5.2.1 Technologies........................ 52 5.2.2 Pattern applied . . . . . . . . . . . . . . . . . . . . . . 54 5.2.3 Application to software . . . . . . . . . . . . . . . . . . 55 5.3 Databasedesign.......................... 61 5.4 Webdesign ............................ 62 5.4.1 Technologies........................ 62 5.4.2 Mockups.......................... 63 5.4.3 Pattern applied . . . . . . . . . . . . . . . . . . . . . . 64 vii 5.4.4 Application to software . . . . . . . . . . . . . . . . . . 64 6 Development 68 6.1 Sprint 0 - Project analysis and design . . . . . . . . . . . . . . 68 6.2 Sprint 1 - Project kickoff and environment setup . . . . . . . . 69 6.3 Sprint 2 - CarGuard functionalities . . . . . . . . . . . . . . . 69 6.4 Sprint 3 - Performance and CarGuard functionalities . . . . . 70 6.5 Sprint 4 - Users and permissions . . . . . . . . . . . . . . . . . 71 6.6 Sprint 5 - Social log in and first Track model . . . . . . . . . . 72 6.7 Sprint 6 - Tracks implementation . . . . . . . . . . . . . . . . 72 6.8 Sprint 7 - API finalization and Web kickoff . . . . . . . . . . . 73 6.9 Sprint 8 - Web implementation . . . . . . . . . . . . . . . . . 74 6.10 Sprint 9 - Extra Sprint . . . . . . . . . . . . . . . . . . . . . . 74 6.11Closingphase ........................... 75 7 Validation 76 7.1 Tests................................ 76 7.2 Continuous integration . . . . . . . . . . . . . . . . . . . . . . 77 7.3 Productowner .......................... 78 8 Software publishing 79 8.1 APIpublication.......................... 79 8.2 Open-source license study and analysis . . . . . . . . . . . . . 79 9 Integration of knowledge 83 9.1 Integration of knowledge from the bachelor degree . . . . . . . 83 9.2 Valoration of technical competences of the project . . . . . . . 84 10 Project obstacles 87 10.1 GDAL installation . . . . . . . . . . . . . . . . . . . . . . . . 87 10.2 Google log in feature . . . . . . . . . . . . . . . . . . . . . . . 87 11 Future work 89 11.1 Tracks algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 89 11.2BrowsableAPI .......................... 90 11.3Webimprovements ........................ 90 12 Conclusions 91 viii References 93 A Database conceptual schema 95 B OpenAPI Specification 97 C Web mockups 135 xv Acronyms GDAL Geospatial Data Abstraction Library. 87 GPS Global Positioning System. 1, 2 IDE Integrated Development Environment. 10, 12, 69, 80 JSON JavaScript Object Notation. 29, 30, 33–46, 53, 59, 73, 76 JWT JSON Web Tokens. 31, 53, 72, 88 PSF Python Software Foundation. 80 TDD Test-Driven Development. 9, 13, 14, 19, 29, 70, 76, 86 UML Unified Model Language. 46 URL Uniform Resource Locator. 33–35, 38, 39, 41–46, 54, 56, 58 YAGNI You Aren’t Gonna Need It. 9 1 Chapter 1 Introduction This project is a Degree Final Project at FIB-UPC, directed by Jaume Figueras i Jov´e and supervised by Antoni Guasch i Petit. It has been developed at inLab FIB[16] as part of CarGuard project[7]. The main goal of this Degree Final Project is to develop a device tracking software with its software architecture design. The technologies selected to develop this kind of software are also studied. 1.1 Context Device tracking software is a software installed in an electronic device that is capable of reporting the device’s location remotely. Depending on the software and the device in which it is installed, the software may obtain the location of the device by means of GPS, WiFi-location, IP address, or accelerometer readings, and it may report the position by means of e-mail, SMS, or other means of communications. The average individual is likely to utilize multiple mobile technology applications daily. Some of those applications may be tools to help the user in several different ways (e.g., communication, information gathering, directional navigation, etc.). As applications have become more complicated and advanced with regard to their features, they have gained the ability to process more and more information to further enhance their features. CHAPTER 1. INTRODUCTION 2 One source of information required for many applications is device location, and by extension the user’s location. This allows certain applications to function more efficiently and improve the user experience (e.g., if a user is searching for a restaurant, the device application can narrow the recommendations based on the user’s location). There are a variety of ways to retrieve a user’s location information, (e.g., GPS, Galileo1, Wi-Fi connections, etc.). This project aims to cover the need to have geolocation and other related services for any application. Apart from the need for applications to use geolocation there is also an economic limitation. Most of the existing software requires a certain amount of money to be able to use it and, besides, they are restrictive and so are the modifications or updates. For that reason, carrying out the project following the guidelines of the open-source[21] software allows to not restrict the use of the software and possible personal modifications. There is clearly a need to use geolocation software in most applications, computer systems and electronics. This need emerged specifically during the planning of a CarGuard project of the SEAT UPC Chair[29] in collaboration with the inLab FIB. 1.2 Stakeholders The Stakeholders or actors involved are those people or entities interested in the development of the project. In this case, they can be classified in various groups according to their interests. Developer The developer is the person in charge of doing the research and implementation and also, of accomplishing the deadlines. In addition, the developer is responsible for the writing and delivering of the necessary documentation. This actor works as agreed with the director and project manager following the concrete requirements of the client. In particular, Albert D´ıaz Benitez, student of the UPC and report author. 1Galileo is the global navigation satellite system CHAPTER 1. INTRODUCTION 3 Director The director is the person responsible for guiding, giving advice and helping the developer in the project terms and objectives. The director’s primary responsibility is to explain and specify the main functionalities that the software must have. This actor works as agreed with the project manager, and for this project the director also works as product owner. In particular, Jaume Figueras i Jov´e, PDI2from the UPC campus of Terrasa and project collaborator for inLab FIB. Project Manager The project manager is the person responsible for the management and guidelines of the whole project. This actor works as agreed with the director. The project manager also helps the developer in a more technical way in order to achieve a more correct development while taking into account the methodology chosen. In particular, Jos´e Francisco Crespo, PAS3from the FIB and project manager of inLab FIB. Beneficiaries This actor stands out as its main interest lies on the proper functioning of the project. In this case, being the software open-source everyone has access to it, this adds even more interest and benefits. In addition to the use of the software, the beneficiary actor can also be someone who wants the software to be used and known in order to gain fame and recognition. In this particular case, the development and production of such a software would fit the inLab FIB interests perfectly. In particular, SEAT[28] for the CarGuard project. 1.3 Problem formulation During the analysis and design of CarGuard some functionalities generated the necessity to develop a new software. These functionalities are: the car’s location when it’s parked, the car track’s history and the management 2”Personal Docent i Investigador” 3”Personal d’Administraci´o i Serveis” CHAPTER 1. INTRODUCTION 4 of the car’s location. Also, there is an interest from the inLab FIB to update an old and non functional software that can offer the functionalities mentioned. 1.4 State of the art As mentioned on the context section, geolocation is highly demanded and used by most applications, therefore, there will be many software that offer a similar solution. The goal of this section is to give information about the state of the art of the technologies that can help to achieve the goals of the project, and also, the existing software that have an approach to the project solution. One obvious approach is the previous version of TooPath[34]. It was developed on 2010 and released on 2013 by inLab FIB. The technologies used were Apache, Joomla and mySQL. This version had two principal functionalities that the new version will also have: real-time display of the position of the device on the OpenStreetMap[9] and a track representation on the map. However, this software is no longer maintained and non functional in the present time. When talking about geolocation software, developers always face problems to store raw geographical data on databases. However, there exist solutions and software implemented to solve these problems, one of these is PostGIS[27]. PostGIS is a spatial database extender for PostgreSQL[26] object-relational database. It adds support for geographic objects allowing location queries to be run in SQL. One existent framework that can be use to develop the software is the Django REST[8], with geographic add-ons. This framework supports full integration with PostGIS and Django REST Framework that allows to develop a API with full integration of geolocation raw data. Another existent technology that can be useful is OpenStreetMap. It is a collaborative project to create a free editable map of the world, so, it is an open-source map. It can be useful to express the solution. CHAPTER 1. INTRODUCTION 5 1.5 Scope The principal scope of this project is focused on the development and design of a functional new version of TooPath. This new version includes the full API development and testing, the full web development and all the architectural design of the software. This project will be developed in a team of three people: a project manager, a product owner and an intern as software architect and developer. It will be managed using the Agile[1] methodology, Sprints of 3 or 4 weeks (for specifically reasons), weekly meetings with all the team and daily meetings with the project manager and developer. The first task will be setting up the environment, installing all the necessary requirements to have the Django REST Framework ready and functional in advance to the development of the software. After the environment preparation it is important to test if the technologies suggested by the the project director (Django REST Framework and PostgreSQL with PostGIS) work correctly and achieve the expected results. In other words, it is primordial to test if the raw geographical data can be stored and expressed. If not, it can be assumed that the technology selected has been erroneous and therefore the research must continue. If everything works correctly the full developing of the software integrating all the functionalities can be pursued. These functionalities are: users and external authentication, historic of tracks and geotracking position. It is mandatory to test all these functionalities to ensure their correct functioning. A web will be developed to demonstrate the API functionalities on the project presentation and offer a user level solution to use the API. This web will be developed with full OpenStreetMap integration and it will use all the functionalities of the API. The Angular framework[2] and the Bootstrap 4[5] library are the chosen technologies for the web development. Also, because the software developed will be open-source, the whole API will be on a public Git repository (with the correspondent README4to achieve its functionality). In consequence, the people interested on the soft- 4Repository file that gives information about the project installation, uses, license, etc CHAPTER 1. INTRODUCTION 6 ware can pull the project and make all the updates/changes that they want or simply use the functionalities already implemented. 1.5.1 Project goals The main goal of the project is to develop a new version of the TooPath geolocation API using current technologies. The new version will offer a geotracking system for any kind of electronic device and a web to consume and demonstrate the API functionalities. This main goal can be decomposed on these concrete goals: •Update TooPath with the current geolocation technologies. •Make a website for the direct use of the API functionalities. •Offer this API as open-source software. In consequence, all the technologies used must be open-source or free. Regarding the functionalities that must be implemented in this project, the technical objectives are: •Design a geolocation API model to store and process. •Develop an authentication and permissions system. •Develop the functionalities for the tracking system: add, update and delete locations and tracks. •Make the software protected and secured. •Develop a web that will consume the API. CHAPTER 1. INTRODUCTION 7 1.6 Methodology This section explains the chosen methodology and all consortia and guidelines used for the development of the project. The Agile methodology has been chosen since it allows total flexibility with respect to future changes or differences of implementation, it implies a total integration of the equipment and therefore, each participating has a global vision of the project for its complete understanding. The recommendations of the project manager have also been taken into account along with the philosophy of work of the company when choosing the methodology and guidelines of the project. The guidelines and characteristics chosen from the Agile methodology are described below. Short development cycle By using an iterative approach with short cycles it is much easier to keep the project on schedule and be conscious about the current state of the project. These short cycles are called Sprints on Agile methodology. A Sprint is a set period of time during which specific work has to be completed and be ready for review. Each Sprint begins with a planning meeting. During the meeting, the product owner (the person requesting the work) and the development team agree exactly upon what work will be accomplished during the Sprint. The development team has the final say when it comes to determining how much work can realistically be accomplished during the Sprint, and the product owner has the final say on what criteria need to be met for the work to be approved and accepted. At the end of every Sprint, the features and tasks developed are shown on a demonstration with the client (product owner for this project). Retrospectives At the end of every Sprint a meeting called retrospective takes place. During the retrospective, the team discusses what went well in the Sprint, what could be improved, and what they commit to improve in the next Sprint. CHAPTER 1. INTRODUCTION 8 By the end of the retrospective, the development team should have identified improvements that will be implemented in the next Sprint. Although improvements may be implemented at any time, the Retrospective provides a formal opportunity to focus on inspection and adaptation. Code Review Code review is a systematic examination of computer source code. It is intended to find mistakes overlooked in software development, improving the overall quality of software. In this particular project the Code reviews are done via regular meetings with the Development Team. It allows to improve the quality of the software code, share knowledge between the team members, locate possible errors or misuse of the technologies, etc. Frequent product owner feedback In this particular project, the product owner acts as a client as it is the actor who knows what must be done and has full interest in the completion of the project. By letting the product owner check the project state as frequently as possible, chances for misunderstandings are greatly reduced and, if they occur, are corrected much faster. Pair Programming Pair Programming[25] is an Extreme Programming[11] practice in which two programmers work together at one workstation. One, the driver, writes code while the other, the observer or navigator, reviews each line of code as it is typed in. The two programmers switch roles frequently. In this project, the Pair Programming is used on casual situations like fixing errors and implementations that help to achieve knowledge at least in one of the participants. This type of programming also works as code reviewing and allows to reduce the number of possible errors during the development phase. CHAPTER 1. INTRODUCTION 9 TDD TDD [17] stands for Test-Driven Development, it refers to a style of programming in which three activities are tightly interwoven: coding, testing (through writing unit tests) and design (in the form of refactoring). It can be succinctly described by the following set of rules: 1. Write a unit test describing an aspect of the program 2. Run the test, which should fail because the program lacks that feature 3. Write just enough code, the simplest possible, to make the test pass 4. Refactor the code until it conforms to the simplicity criteria, repeat accumulating unit tests over time This style of programming allows to accomplish the YAGNI[12] develop philosophy that states a programmer should not add a functionality until deemed necessary. It also allows a better quality code design and an easier error location. Git Flow If this work flow is implemented, whenever something is done in the code, a corresponding branch will have to be created, the code worked on and incorporated to the main branch and the created branch closed. Throughout the working day the git, merge, push and pull commands will need to be executed several times a day, as well as checkouts of different branches, delete them, etc. Git-flow[10] is created to solve this lack of time problem, it is a set of extensions that save enough work to execute all these commands, simplifying the management of the branches of the repository. For this project, using Git-flow model for branching allow to organize the git branches and make the work flow more traceable. CHAPTER 2. PROJECT MANAGEMENT 16 that CarGuard project needs. Both Sprints have one extra week of duration due to the complexity of the integration for the CarGuard use. Sprint 3 - Performance and CarGuard functionalities: This Sprint starts on July 3rd and ends on July 28th. This Sprint has a more technical specification because it is focused on a better performance of the implementation in the second Sprint and also in following the API patterns for the models implemented. Sprint 4 - Users and permissions: This Sprint starts on September 12th and ends on September 29th. This Sprint is focused on following the API patterns of the permissions and users. Sprint 5 - Google log in and first Tracks model: This Sprint starts on October 2nd and ends on October 20th. After the implementation of the users and token authentication on the previous Sprint, Google log in functionality is added. Sprint 6 - Tracks implementation: This Sprint starts on October 23th and ends on November 10th. This Sprint is focused on the most important functionality of the project, the tracks. Sprint 7 - API finalization and Web kickoff: This Sprint starts on November 13th and ends on December 1st. On this Sprint it is mandatory to make all the adjustments, if necessary, to finalize the API implementation. Also, the development of the website used to validate and demonstrate the API functionalities will start. This website has a map, a user/device management and tracks historical. Sprint 8 - Web implementation: This Sprint starts on December 4th and ends on December 22th. This Sprint is reserved to implement and finalize the website. CHAPTER 2. PROJECT MANAGEMENT 17 Sprint 9 - Extra sprint for possible bugs or improvements: This Sprint starts, if necessary, on January 8th and will end on the final deadline. This Sprint is optional as it’s only necessary if there are bugs or/and mandatory improvements. Otherwise this Sprint won’t happen. Closing Phase: The main objective of this phase is to review and close the project. Also, the report and all the necessary documentation will be written during this phase. 2.3.2 Estimated time Sprint Time spent (hours) Project planning and feasibility 30 Project analysis and design 65 Project kickoff and environment setup 45 CarGuard functionalities 70 Performance and CarGuard functionalities 66 Users and permissions 56 Google log in and first Tracks model 50 Tracks implementation 70 API finalization and Web kickoff 58 Web implementation 80 Closing phase 20 Extra sprint for possible bugs or improvements 40 Total 650 Table 2.2: Estimated time of the Sprints 2.3.3 Gantt chart The Gantt Chart can’t be showed in this section partially due to the big size of the chart. See the following link to see it in full. CHAPTER 2. PROJECT MANAGEMENT 18 2.4 Project budget In order to carry out this project, the resources mentioned previously will be needed. In this section, an estimation of the cost of the project is presented, taking into account the mentioned hardware and software resources, and the corresponding amortizations. In addition, the indirect costs and unexpected costs of the project are taken into consideration. 2.4.1 Human resources budget This project is going to be developed by three people: •Jos´e Francisco Crespo as project manager in inLab FIB. •Jaume Figueras as product owner in inLab FIB. •Albert D´ıaz as software developer and architect in inLab FIB. To know the hour/salary of every role the website Page Personnel[24] is used. It is also important to consider that the price of software architect and developer is extracted from the actual salary of an intern in inLab FIB. The table 2.3 shows the costs of the human resources needed in the development of the project. Role Price per hour Hours Cost Project Manager 20 e305 6100 e Product Owner 20 e152 3040 e Software Architect 8 e95 760 e Software Developer 8 e515 4120 e Total 14020 e Table 2.3: Human resources budget The project manager role is working on the project planning, and also, helping the software developer if it is needed. CHAPTER 2. PROJECT MANAGEMENT 19 The software architect role is working on the software architecture design (model diagrams and database design) during the project planning and feasibility phase and also on the project analysis and design phase. The software developer role is working on the software development and also, testing it because of the TDD use. The product owner role is deciding and making clear the specification and functionalities desired for the final software. Sprint and Tasks Hours estimated Roles Cost Project planning and feasibility 15 Project Manager 300 e 7 Product Owner 150 e 30 Software Architect 240 e 52 690 e Project analysis and design 32 Project Manager 640 e 16 Product Owner 320 e 65 Software Architect 520 e 113 1480 e Sprint 1 23 Project Manager 460 e 11 Product Owner 220 e 45 Software Developer 360 e 79 1040 e Sprint 2 35 Project Manager 700 e 17 Product Owner 340 e 70 Software Developer 560 e 87 1600 e Sprint 3 33 Project Manager 660 e 16 Product Owner 320 e 66 Software Developer 528 e 115 1508 e Sprint 4 28 Project Manager 560 e 14 Product Owner 280 e 56 Software Developer 448 e 98 1288 e Continued on next page CHAPTER 2. PROJECT MANAGEMENT 20 Table 2.4 – Continued from previous page Sprint and Tasks Hours estimated Roles Cost Sprint 5 25 Project Manager 500 e 12 Product Owner 240 e 50 Software Developer 400 e 87 1140 e Sprint 6 35 Project Manager 700 e 17 Product Owner 340 e 70 Software Developer 560 e 122 1600 e Sprint 7 29 Project Manager 580 e 15 Product Owner 300 e 58 Software Developer 464 e 283 1344 e Sprint 8 40 Project Manager 800 e 20 Product Owner 400 e 80 Software Developer 640 e 140 1840 e Sprint 9 20 Project Manager 400 e 10 Product Owner 200 e 40 Software Developer 800 e 70 1400 e Closing Phase 10 Project Manager 200 e 5 Product Owner 100 e 20 Software Developer 400 e 35 700 e Table 2.4: Sprints and tasks budget CHAPTER 2. PROJECT MANAGEMENT 21 2.4.2 Hardware budget In order to implement TooPath a set of hardware will be needed for various purposes. It is important to consider that the hardware used are from inLab FIB, so it has been used by previous workers. This fact is considered to calculate the useful life and amortization. The table 2.5 shows the hardware amortization and cost. Product Price Time Percentage Useful life Amortization HP Compaq 8100 Elite SFF 660 e6 month and a half - 5 years 71.50 e SkyLab Server 1300 e6 month and a half - 5 years 200 e Total 1960 e271.50 e Table 2.5: Hardware resources budget 2.4.3 Software budget The table 2.6 summarizes the costs and amortization of the software that are going to be needed to develop the project. Product Price Time Useful life Amortization PyCharm License 199.00 e6 month and a half 1 year 107.79 e WebStorm License 129.00 e6 month and a half 1 year 69.87 e Git 0 e- - 0 e GatLab 0 e- - 0 e Django REST 0 e- - 0 e Django Rest-gis 0 e- - 0 e Postgres with PostGIS 0 e- - 0 e Vagrant 0 e- - 0 e OpenStreetMap 0 e- - 0 e ShareLatex 0 e- - 0 e Total 328.00 e177.66 e Table 2.6: Software resources budget CHAPTER 2. PROJECT MANAGEMENT 22 2.4.4 Unexpected costs Table 2.7 shows the unexpected costs that may appear. This allows to have a certain budget margin that will help against unexpected events that may occur during the project development. Event Cost Probability Event Cost Extra Sprint 9 1400 e10% 140e PC failure 660 e5% 33 e Server failure 1300 e0.036% 46.80 e Total 3360 e6.54% 219.80 e Table 2.7: Unexpected costs of the project There might be be two types of unexpected events: •Extra Sprint 9: It is possible to have an extra sprint due to the possible bugs or improvements. This extra Sprint increments the total hours of the project in 40 hours. •Hardware failure: In case of a problem with the hardware, it must be repaired or replaced, increasing the cost of the project. 2.4.5 Indirect costs Next, table 2.8 provides an estimation of the indirect costs that are not comprised in any of the previous categories. Product Price Percentage Cost Workplace 3000 e1.43% 42.90 e Internet connection 40.00/month 1.43% 0.57 e Transport 0.00 e- 0.00 e Total 43.47 e Table 2.8: Indirect costs of the project CHAPTER 2. PROJECT MANAGEMENT 23 These indirect cost are described here: •Internet connection: Each member must have an internet connection to be able to work on the project. Given that the company already has an internet connection, only the bandwidth percentage used is calculated. The project involves 3 members and the company is made up of 70 people, so it will be 4.28% of bandwidth contracted. •Workplace: For the four members of the team there is space available to work in an office with all the necessary facilities. The cost includes: office rent, maintenance (cleaning and repairs) and basic services (electricity, air conditioning, heating, etc). In this section the costs of the office will be taken into account under the same conditions that the internet connection, with 4.28 of the total of the invoices. •Transport: The project will be carried out in the same company, therefore, since aren’t trips for the meetings because the product owner will be in the same company, this cost is not taken on account. 2.4.6 Budget monitoring Constant cost control will be done in order to see if there are deviations in the project. The costs derived from human resources will be controlled for each iteration of the project and it will be observed if there are deviations. These deviations will be calculated with the hours each team member has assigned with the ones performed during each of the iterations. At the end of the project the estimated initial cost will be compared with the final cost. If the final cost is greater than the estimated initial cost, it will be studied if the difference has been caused by the known unforeseen events and if it can be covered with the corresponding budget. If not, the contingency budget will be used to cover these deviations. 2.4.7 Total budget Using data shown in the previous tables the following table can be used to describe the total cost of the project. Also, being a long-term project, six months and a half, it was decided to save a part of the budget for the contingency plan, more specifically 15% of the direct and indirect costs obtained previously. CHAPTER 2. PROJECT MANAGEMENT 24 Concept Cost Human resources 14020 e Hardware resources 271.50 e Software resources 177.66 e Unexpected costs 219.80 e Indirect costs 43.47 e Subtotal 14696.68 e Contingency 2204.50 e Total 16936.93 e Table 2.9: Total costs of the project 2.5 Sustainability In this section the sustainability of the project will be evaluated in three different areas: economical area, social area and environmental area. This analysis will be based on the application of the sustainability matrix to the project, shown in table 2.10. Project Development Exploitation Risks Environmental Design consumption Ecological Footprint Environmental risks 9/10 17/20 -20/-1 Economical Bill Viability Plan Economical Risks 9/10 18/20 -20/-1 Social Personal Impact Social Impact Social Risks 8/10 15/20 -20/0 Sustainability range 26/30 50/60 -60/-2 74/90 Table 2.10: Sustainability of the project 2.5.1 Economical A detailed quantification of all the costs involved in the project has been done, both of material and human resources, as shown in previous sections of CHAPTER 2. PROJECT MANAGEMENT 25 this document. It’s relevant to notice the use of mostly open-source software. So, it is feasible and competitive in economic terms. The duration of each activity is estimated and fitted in relation of its importance. As stated in the context of the project there is not actual similar functional solution, so no existing technology can be reused. The proposed solution will be less expensive than current solutions from an economical point of view because the use of all the free software possible and because of open-source, so the updates and improvements will be cheaper. Hence, it is a totally free software, so the end-user won’t need to pay to use it. Also, this project may have impact in the economy of organizations: they may have minimum costs in the use of this software. It is also important to highlight that the development team is formed by three people. This is the minimum possible for a software development team. This fact allows to minimize the human costs as much as possible, and in consequence, the possible hardware and software resources. 2.5.2 Social This project is done to update an old software that was used to track and manage vehicles fleets and manage their locations. This update is needed because some companies, like Aigues de Matar´o, are interested on using it. Also, as it is previously mentioned this new version is needed for inLab and the CarGuard project. Personally, this software won’t have an impact because of the use but it will have an impact because of the development. This impact will be caused by the new technologies that will be used and that will improve the working experience of a software developer. On the other hand, this new version is gonna be open-source, which means it’s going to be a free software. This fact allows free software use for any kind of user, and also, possible improvements or new versions that can be useful for anyone who wants to use it and work on this software. Ultimately, this software will have a good impact and zero social risks. CHAPTER 4. SPECIFICATION 32 •Data returned •Errors handled The guidelines found on the Web API Design[19] is used to specify the PATCH and PUT methods. In summary, the PUT method is used to change the representation of a resource and the PATCH method is used to update the content fields of a resource that won’t affect this representation. For example, if the email of a user needs to be changed (which is unique), a PUT method must be used. If this email isn’t part of a resource representation a PATCH method can be used. Also following this guidelines, it has been decided that the identifier of all the resources will be the ID. Also, the API has been specified following the OpenAPI Specification[20] (formerly known as the Swagger Specification). This specification type is easy-to-learn, language agnostic, and both human and machine readable. This specification can be read on the appendix B. 4.1.1 Functionalities The different groups are: users management, devices management, tracks management, locations management and authentication. Users management This group is formed for the petitions that create, edit, delete and retrieve information about the users resource. On the API the user is identified by the id and also, by its username or email which are unique fields. Every user has an owner permission for the resources created and also, it allows to protect the reading and editing of these resources. User creation: •HTTP Method: POST •Endpoint: /users/ •Authentication: No CHAPTER 4. SPECIFICATION 33 •Description: This method allows the creation of a user. This method doesn’t require authentication. For security reasons the password provided is saved codified and it isn’t presented on any response of the API. Also, the username and email are unique fields and the format of this last one is verified. •Required fields: username, email and password in the request body. •Data returned: 201 Created status code and a JSON object with the user fields instance created excluding the password field due to security reasons. •Errors handled: 400 Bad Request and 409 Conflict. User information retrieving: •HTTP Method: GET •Endpoint: /users/:user id/ •Authentication: Yes •Description: This method allows to retrieve the information of a user identified with the ID passed by parameter. This information can only be accessed if the id of the user authenticated corresponds with the ID passed by parameter. •Required fields: user id as URL parameter. •Data returned: 200 OK status code and a JSON object with the user fields except the password due to security reasons. •Errors handled: 401 Unauthorized, 403 Forbidden and 404 Not Found. Change user representation: •HTTP Method: PUT •Endpoint: /users/:user id/ •Authentication: Yes CHAPTER 4. SPECIFICATION 34 •Description: This method allows to change the representation of a user identified with the ID passed by parameter. This change can only be done if the id of the user authenticated corresponds with the id passed by parameter. Also, the request body must contain all the fields that represent the user resource. •Required fields: user id as URL parameter and username, email and password in the request body. •Data returned: 200 OK status code and a JSON object with the new user representation and all the other fields except the password due to security reasons. •Errors handled: 400 Bad Request, 401 Unauthorized, 403 Forbidden and 404 Not Found. Delete user: •HTTP Method: DELETE •Endpoint: /users/:user id/ •Authentication: Yes •Description: This method allows to delete the user resource identified with the ID passed by parameter. This delete can only be done if the id of the user authenticated corresponds with the id passed by parameter. •Required fields: user id as URL parameter. •Data returned: 204 No Content status code. •Errors handled: 401 Unauthorized, 403 Forbidden and 404 Not Found. Update user fields: •HTTP Method: PATCH •Endpoint: /users/:user id/ •Authentication: Yes CHAPTER 4. SPECIFICATION 35 •Description: This method allows to update the fields of a user identified with the ID passed by parameter. This update can only be done if the id of the user authenticated corresponds with the id passed by parameter. •Required fields: user id as URL parameter. •Data returned: 200 OK status code and a JSON object with the user fields and its new values, except the password due to security reasons. •Errors handled: 400 Bad Request, 401 Unauthorized, 403 Forbidden and 404 Not Found. Authentication This group is formed by the petitions that perform the user authentication and the token refresh and verification. When a user performs a log in a token is provided, this token identifies and authenticates the user. Also, for security reasons this token will expire on a short period of time and must be refreshed during this period of time. This token will be on every request that needs authentication to identify the user and apply the owner permissions. User log in: •HTTP Method: POST •Endpoint: /login/ •Authentication: No •Description: This method allows the user to authenticate and retrieve the token. •Required fields: email and password in the request body. •Data returned: 200 OK status code and a JSON object with a valid token. •Errors handled: 400 Bad Request and 404 Not Found. CHAPTER 4. SPECIFICATION 36 User Google log in: •HTTP Method: POST •Endpoint: /login-google/ •Authentication: No •Description: This method allows the user to authenticate and retrieve the token using the Google account. •Required fields: email and Google token in the request body. •Data returned: 200 OK status code and a JSON object with a valid token. •Errors handled: 400 Bad Request and 404 Not Found. Token verification: •HTTP Method: POST •Endpoint: /api-token-verify/ •Authentication: No •Description: This method allows the user to check the token validation. The token that must be checked is passed in the request body. •Required fields: token in the request body. •Data returned: 200 OK status code that confirms the token validation. •Errors handled: 400 Bad Request. Refresh a token: •HTTP Method: POST •Endpoint: /api-token-refresh/ •Authentication: No CHAPTER 4. SPECIFICATION 37 •Description: This method allows the user to refresh a token. The token that must be refreshed is passed in the request body. If the token is already expired, the user must log in again. •Required fields: token in the request body. •Data returned: 200 OK status code and a JSON object with the new token refreshed. •Errors handled: 400 Bad Request. Devices management This group is formed by the petitions related with the devices resource: create, edit, delete and retrieve information of a device. The device resource is the main resource of the API. This resource is associated with the user creator as owner, the tracks resources and its actual location. Get all devices information: •HTTP Method: GET •Endpoint: /devices/ •Authentication: Yes •Description: This method allows to retrieve all the devices information. It only returns the devices owned by the request user. All the devices returned have all the information of the tracks related and its locations. •Required fields: None. •Data returned: 200 OK status code and a JSON array with every device and all the information and fields. •Errors handled: 401 Unauthorized and 403 Forbidden. CHAPTER 4. SPECIFICATION 38 Create a device: •HTTP Method: POST •Endpoint: /devices/ •Authentication: Yes •Description: This method allows the creation of a device. When a device is created automatically is created and associated an actual location instance (wich is empty until is updated). •Required fields: name, trash, device type and device privcay. •Data returned: 201 Created status code and a JSON object with the fields of the device created. •Errors handled: 400 Bad Request, 401 Unauthorized, 403 Forbidden and 409 Conflict. Device information retrieving: •HTTP Method: GET •Endpoint: /devices/:device id/ •Authentication: Yes •Description: This method allows to retrieve information of the device identified with the ID passed by parameter. This information can only be accessed if the id of the user authenticated corresponds with the ID of the device owner. •Required fields: device id as URL parameter. •Data returned: 200 OK status code and a JSON object with the device fields (including tracks and locations). •Errors handled: 401 Unauthorized, 403 Forbidden and 404 Not Found. CHAPTER 4. SPECIFICATION 39 Change device representation: •HTTP Method: PUT •Endpoint: /devices/:device id/ •Authentication: Yes •Description: This method allows to change the representation of the device identified with the ID passed by parameter. This change can only be done if the id of the user authenticated corresponds with the ID of the device owner. Also, the request body must contain all the fields that represent the device resource. With this method instances related to this device like the tracks or their locations and the actual location can’t be changed. •Required fields: device id as URL parameter and the name in the request body. •Data returned: 200 OK status code and a JSON object with the device fields (including tracks and locations). •Errors handled: 400 Bad Request, 401 Unauthorized, 403 Forbidden and 404 Not Found. Update device fields: •HTTP Method: PATCH •Endpoint: /devices/:device id/ •Authentication: Yes •Description: This method allows to update the fields of the device identified with the ID passed by parameter. This change can only be done if the id of the user authenticated corresponds with the ID of the device owner. With this method instances related to this device like the tracks or their locations and the actual location can’t be updated. •Required fields: device id as URL parameter. CHAPTER 4. SPECIFICATION 40 •Data returned: 200 OK status code and a JSON object with the device fields updated (including tracks and locations). •Errors handled: 400 Bad Request, 401 Unauthorized, 403 Forbidden and 404 Not Found. Delete device: •HTTP Method: DELETE •Endpoint: /devices/:device id/ •Authentication: Yes •Description: This method allows to delete the device identified with the ID passed by parameter. This delete can only be done if the id of the user authenticated corresponds with the ID of the device owner. •Required fields: device id as URL parameter. •Data returned: 204 No Content status code. •Errors handled: 401 Unauthorized, 403 Forbidden and 404 Not Found. Tracks management This group is formed by the petitions related with the tracks resource: create, edit, delete and retrieve information of a track. A track is associated with a device and use its owner permission. Also, the track is associated with various locations. Get all tracks information: •HTTP Method: GET •Endpoint: /devices/:device id/tracks/ •Authentication: Yes CHAPTER 4. SPECIFICATION 41 •Description: This method allows to retrieve all the tracks information associated with the device identified by the ID parameter. This information can only be accessed if the ID of the user authenticated corresponds with the ID of the device owner. •Required fields: device id as URL parameter. •Data returned: 200 OK status code and a JSON array with every track and all the information and fields. •Errors handled: 401 Unauthorized, 403 Forbidden and 404 Not Found. Create a track: •HTTP Method: POST •Endpoint: /devices/:device id/tracks/ •Authentication: Yes •Description: This method allows the creation of a tracks. This creation can only be performed if the ID of the user authenticated corresponds with the ID of the device owner. Also, when the track is created will be associated to the device identified with the parameter ID. •Required fields: device id as URL parameter and the name in the request body. •Data returned: 201 Created status code and a JSON object with the track instance created and its fields. •Errors handled: 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found and 409 Conflict. Retrieve track information: •HTTP Method: GET •Endpoint: /devices/:device id/tracks/:tracks id/ •Authentication: Yes CHAPTER 4. SPECIFICATION 48 User management This group is formed by all the functionalities related to the users. As the web isn’t a social network it isn’t needed to have a user interaction. In particular, the functionalities related to this group are: •Sign Up: The web offers a registration form with the fields that the user API resource accepts. Users can also sign up using the Google credentials. •Log In: Once registered users can log in to access to all the devices and tracks functionalities. If users have registered using Google they can log in with this credentials. •Edit profile: A user can change the email, first and last name. Resources management This group is formed by all the functionalities related with the device, tracks and locations resource management. This management references the functionalities of create, edit this resources. Also, the resources raw info can be seen on different views. So, this functionalities will be divided in devices, tracks and locations. The device resource can be created with a form with the fields that the device API resource accepts. Besides this functionality, the user will be able to see all his devices with all the tracks associated and locations. Also, the device field, device type will be seen as a icon (Android, Apple, Windows or Fedora logo). This resource also allows the possibility to edit all the information (except the id) via a form. The track resource can be created with a form with the fields that the track API resource accepts. When the track is created it will be associated directly to the correspondent device. The track location resource can be created with a form with the fields that the track location API resource accepts. Every location created will be associated to the correspondent track. CHAPTER 4. SPECIFICATION 49 Tracks visualization This group is formed by the two most visible functionalities: track view on demand in a map and a map view with the tracks selected of the user logged devices. The map selected for the website is the OpenStreetMap and its technologies. To view a track the user can navigate on the devices information and click on a track see it on the map. Once the user clicks on a track, it will be seen on the map joining all the points and forming a line on the map. In this way, this functionality can show the track locations in a more visual way. Besides this first way to visualize a track there will be a second one. there will be a map view with all the devices and their tracks as filters. This map will be empty of tracks as a first state, and when a track is selected it will be painted on the map following the same pattern described bellow. As different tracks on the map can be seen, the color to paint each track will vary depending on their device. CHAPTER 4. SPECIFICATION 50 4.2.2 Conceptual schema The web conceptual model is represented by the following navigability diagram: Figure 4.2: Web navigability diagram 51 Chapter 5 Design This chapter presents and describes the system design on a physical and logic level and also, the technologies used. 5.1 System architecture This section is focused on the system’s architecture that the software needs to work. The system consists on a server with a database, the API and the Web application. 5.1.1 Server The system has a unique server. This server is owned by inLab and offered as a service for its collaborators. InLab offers this service using the OpenNebula[23] technology. Concretely, inLab offers a Linux Virtual Machine to work as server. For this system the Virtual Machine selected is an Ubuntu 16. The database is on the same server so a different connection to retrieve and manage the data isn’t necessary. 5.1.2 API The API is located on the server’s side and it works as a service to interact with the server and its database. The communication of this API is via internet and the HTTP protocol. CHAPTER 5. DESIGN 52 5.1.3 Web application This web application will interact with the server using the API. Also, a good server connection will be necessary to ensure the correct use. 5.1.4 Components communication The users can access the system using the web application from their laptops and computers. This diagram shows the communication of all the components: Figure 5.1: System components communication 5.2 API design This section shows the technologies used on the API and the patterns applied. Also, the database technology is described on this section. 5.2.1 Technologies The technologies selected for the API and the database were the Django REST Framework using the django-rest-gis[6] add-on and the PostgreSQL CHAPTER 5. DESIGN 53 with PostGIS. All these technologies allow to solve the geographical data problem. Django REST This framework is a powerful and flexible toolkit for building Web APIs. This framework extends from the Django Framework which is a Python ORM1Framework. Django REST has some functionalities that are essential for our software: •Serialization: allow complex data such as querysets and model instances to be converted to native Python datatypes that can be easily rendered into JSON, XML or other content types. Serializers also provide deserialization allowing parsed data to be converted back into complex types, after first validating the incoming data. •Authentication polices: REST framework provides a number of authentication schemes out of the box, and also allows for the implementation of custom schemes. One of the authentication policies, and the selected one is the use of JWT. •Customizable: This framework is entirely customizable. It doesn’t have restrictions on the use of all the features. •Client testing: REST framework includes a few helper classes that extend Django’s existing test framework, and improve the support for making API requests. For example, any type of client requests and all their work flow can be easily tested. Also, this framework has a lot of different add-ons and plugins to access to new features and functionalities. For example, the geographical add-on selected for this API (Django REST-gis). Django-rest-gis add-on Django-rest-gis is a geographical add-on for Django REST Framework. This add-on adds geographical fields, serializers, pagination and filters to the 1Object Relational Model CHAPTER 5. DESIGN 54 REST Framework. The most significant features for the software are the geographical fields that allow to manage and store all the geographical data and the geographical serializers that ensure the GeoJSON compatibility. PostgreSQL with PostGIS PostgreSQL is an object-relational database management system that uses the SQL language. PostGIS is a spatial database extender for PostgreSQL. It adds support for geographic objects allowing location queries to be run in SQL. 5.2.2 Pattern applied The patterns of Web API design book[19] have been followed for the API resource and URL design. Some of the guidelines followed are: •Nouns are good; Verbs are bad: To keep the URL simple and understandable the use of nouns instead of verbs is recommended. •Plural nouns and concrete names: The use of plural nouns makes the API more intuitive for the developers. Also, the use of concrete names to avoid resource abstraction. •Simply associations: It’s common to have relations between resources. These relations are represented allowing a better system understanding. •Handling errors: It is very important to handle the errors that might happen on the API. It is recommended to follow and use the HTTP status codes as they are the standards for the developers. For example, to access on a concrete track resource the correct URL will be /devices/:device id/tracks/:track id/. First of all, the access to the device must be associated with the track (following simply associations guidelines seen above). Also plural nouns must be used for all the resources and concrete names to avoid misunderstandings. A custom Model-View-Controller pattern has been followed for the API development. CHAPTER 5. DESIGN 55 This pattern consists on separating the data and business logic from the user interface and the module in charge of managing the actions and communications. This software architecture pattern is based on the ideas of reusing code and the separation of concepts to facilitate development and the subsequent maintenance. For these reasons there are three different components: •Model: Defines the data models with whom the application will work and it is the only class that has communication with the database. It is in charge of search, retrieve and store the data. •View: Shows the information on a format for a proper user interaction. •Controller: In charge of requesting the necessary data to the model, processing and sending it to the view. It is the key element for the use of this pattern, since it is the component that communicates the other two. Figure 5.2: Model View Controller structure 5.2.3 Application to software As it is mentioned before, a custom model view controller is used for the API development. This section describes the differences and adaptations that make it custom. CHAPTER 5. DESIGN 56 Figure 5.3: custom API Model View Controller structure On the figure shown above the absence of controllers and new components called URLs and Serializers can be seen. As Django REST provides direct communication using models the existence of a controller component isn’t required. These two new components are from Django REST, the URLs defines all the URL accepted and their views and the Serializers components are used to serialize and deserialize data. An example for every component implemented will be shown for a better understanding of this custom pattern. To avoid complexity a simple request as the creation of a user is used as an example. Before starting with the example, the next figure shows the structure followed to order the different packages. All the components, except URLs and models, are grouped on Python packages corresponding with a model name. For example, the devices package will have its views, serializers and another components as tests, signals, etc. CHAPTER 5. DESIGN 57 1TooPath3/ 2|-- apps.py 3|-- constants.py 4|-- models.py 5|-- urls.py 6|-- utils.py 7|-- wsgi.py 8|-- __init__.py 9|-- devices/ 10 | |-- permissions.py 11 | |-- serializers.py 12 | |-- signals.py 13 | |-- tests.py 14 | |-- views.py 15 | |-- __init__.py 16 |--locations/ 17 | 18 |-- migrations/ 19 | |-- 0001_initial.py 20 | |-- 0002_auto_20171107_1657.py 21 | |-- 0003_tracks.py 22 | |-- 0004_auto_20171107_1921.py 23 | |-- 0005_auto_20171108_1252.py 24 | |-- 0006_auto_20171108_1628.py 25 | |-- __init__.py 26 |-- settings/ 27 | |-- base.py 28 | |-- local.py 29 | |-- production.py 30 | |-- __init__.py 31 |-- tracks/ 32 | 33 |-- users/ Listing 1: API project structure Also, there are two more packages, settings and migrations. In the set- CHAPTER 5. DESIGN 64 5.4.3 Pattern applied Angular tries to stay pattern-agnostic and can be used with conventional MV* patterns, it was designed with reactive programming in mind and it really shines when used with reactive data flow patterns. As the framework is pattern-agnostic the web was developed following the official documentation and using these framework object types: •Component: Component decorator allows to mark a class as an Angular component and provide additional metadata that determines how the component should be processed, instantiated and used at run time. •Injectable: It is a type of object applied on the Dependency Injection (DI). DI is a way to create objects that depend upon other objects. •App module: This is the main piece of the framework. All the modules imported and declared, web routes, providers, etc are declared on this object. •TypeScript class: There are object classes based on the TypeScript language. 5.4.4 Application to software The different component types described previously are shown next using examples of the web. These examples corresponds with the web log in functionality. First of all, a common TypeScript object class is showed: 1export class User { 2first_name: string; 3last_name: string; 4username: string; 5email: string; 6password: string; 7} Listing 6: User TypeScript object class CHAPTER 5. DESIGN 65 Next, the App Module file is shown: 1import ... 2const appRoutes: Routes =[ 3{path:'signUp', component: AppSignUpComponent}, 4{path:'logIn', component: AppLogInComponent}, 5... 6]; 7@NgModule({ 8declarations:[ 9AppComponent, 10 AppLogInComponent, 11 ... 12 ], 13 imports:[ 14 NgbModule.forRoot(), 15 RouterModule.forRoot(appRoutes), 16 ... 17 ], 18 providers:[ 19 HttpService, 20 LogInService, 21 ... 22 ], 23 bootstrap:[AppComponent] 24 }) 25 export class AppModule { 26 } Listing 7: App Module file The App Module file has three important parts. First, the constant called appRoutes is in charge of connecting every valid path with its Component. Second, the declarations, imports and providers arrays are in charge of declare the custom Components implemented for the web, the Components imported and the injectable Providers respectively. Third, @NgModule wrap all these arrays as a global module to be accessible for all the files. CHAPTER 5. DESIGN 66 Next, the log in Component is showed: 1import ... 2 3@Component({ 4selector:'app-app-log-in', 5templateUrl:'./log-in.component.html', 6styleUrls:['./log-in.component.css'] 7}) 8export class AppLogInComponent implements OnInit { 9 10 user: User; 11 12 constructor(private _logInService: LogInService,private _router: Router) {,→ 13 } 14 15 ngOnInit() { 16 this.user =new User(); 17 } 18 19 async sendLogIn() { 20 try { 21 await this._logInService.postLogin(this.user); 22 this._router.navigate(['']); 23 }catch (error) { 24 console.log(error); 25 } 26 } 27 } Listing 8: Log in Component The @Component variable defines the template and the styles files for this Component. The Injectable are passed as parameters on the constructor function. The constructor of the example has two Injectable objects, the Router which is explained before and the LogInService which is an object CHAPTER 5. DESIGN 67 that acts as an intern service and is shown on the next listing. The ngOnInit function is called on the Component initialization and allows to initialize and create objects needed for the correct Component behaviour. Last, the asynchronous function, sendLogIn is called when a user click on the log in button on the web: This function calls the LogInService and perform the log in on the API. Next, the log in service Injectable is showed: 1import ... 2 3@Injectable() 4export class LogInService { 5 6constructor(private _logInApiService: LogInApiService) { 7} 8 9async postLogin(user: User) { 10 let response =await this._logInApiService.postLogIn(user); 11 if (response.status === 200) { 12 localStorage.setItem('currentUser', JSON.stringify({ 13 id: response.json().id, 14 email: response.json().email, 15 first_name: response.json().first_name, 16 last_name: response.json().last_name, 17 username: response.json().username, 18 token: response.json() 19 })); 20 } 21 } 22 } Listing 9: Log in service Injectable The @Injectable variable makes this object Injectable. It has a constructor function with another object Injectable on the parameters. The asynchronous function postLogin call the API using the logInApiService. 68 Chapter 6 Development This chapter describes how the process and the implementation have been in the system development. The description is divided for every Sprint mentioned on the project planning section. Every task and functionalities mentioned in the project planning section and specification chapter are implemented on these Sprints. Some Sprints had difficulties that are explained next. 6.1 Sprint 0 - Project analysis and design Duration: 4 weeks (18/04/2017 - 12/05/2017) The methodologies study and requirement analysis were done during this Sprint. All the study and analysis was performed by the product owner, project manager and developer on several meetings. Also, the software architecture was designed. CHAPTER 6. DEVELOPMENT 69 6.2 Sprint 1 - Project kickoff and environment setup Duration: 3 weeks (15/05/2017 - 02/06/2017) Figure 6.1: Sprint 1 completed tasks All the environment was prepared and configured on this Sprint. All the software needed and their dependencies were installed: Python, Django, Django REST, djangorest-gis, PostgreSQL, PostGIS, Py- Charm IDE, Vagrant, etc. There was a dependency problem with the Django REST-gis installation for windows which ended up in a small waste of time. This problem is described on the section 10.2. Figure 6.2: Sprint 2 completed tasks Also, a concept test was done to ensure the correct functionality of the framework, database and server. This concept test was very important because future configuration and dependencies might end up in an important waste of time. Therefore, the critical functionalities of the technologies were focused on this concept test. 6.3 Sprint 2 - CarGuard functionalities Duration: 4 weeks (05/06/2017 - 30/06/2017) The main functionality for CarGuard project was implemented in this Sprint. This functionality is the actual location of a car. This functionality requires the Device and Location models which were implemented and migrated to the database. Location model wasn’t abstract on this point because CHAPTER 6. DEVELOPMENT 70 the functionality didn’t require it. A succesful demo and meeting took place at the end of this Sprint with the CarGuard client, to review and ensure the achievement of the functionalities. The TDD methodology was applied since this Sprint. The two previous Sprints weren’t following this methodology because there wasn’t any code implementation. 6.4 Sprint 3 - Performance and CarGuard functionalities Duration: 4 weeks (03/07/2017 - 27/07/2017) Figure 6.3: Sprint 3 completed tasks This Sprint main focus was finishing the functionalities needed for the CarGuard project. CarGuard needed to retrieve and store the car information, so the GET, PUT, POST methods must be implemented. These functionalities didn’t require any new model implementation, just a new view. The location storage was implemented on the previous Sprint, but this storage didn’t validate the coordinates. This validation was implemented using the Serializer component of Django REST. There was another succesful demo with the CarGuard client (SEAT) on the end of this Sprint. The development for the CarGuard functionalities finalized in this Sprint, and after, the functionalities were specified by the Product Owner. CHAPTER 6. DEVELOPMENT 71 6.5 Sprint 4 - Users and permissions Duration: 3 weeks (12/09/2017 - 29/09/2017) Figure 6.4: Sprint 4 completed tasks The main objective of this Sprint was to implement the ownership permissions for the device resource. This type of permission requires of the existence of a user resource and the log in feature. So, the user model class was implemented and migrated before start with the permissions implementation. The device model class was also migrated again to add the owner attribute. The user model of the API is called CustomUser and as it is mentioned in the previous section 5.2.3 it extends the AbstractUser model class from Django. It was decided to extend this model because the framework has a functional user resource model and it would be a waste of time and effort to implement what has already been implemented. The GET, POST and PUT methods for the user resource view were also implemented. The log in feature was implemented after the user model and view implementation. This feature allows to identify the user on every request done with a simple token generated from the framework. The Django REST documentation was followed to implement the permissions of device ownership. These permissions allow to protect the access and manage of the device resource. For example, if a user makes a PUT request for a device that doesn’t own the request can’t be performed and it returns the 403 Forbidden status code. Also, the permissions were added to the views implemented on the previous Sprints. CHAPTER 6. DEVELOPMENT 72 6.6 Sprint 5 - Social log in and first Track model Duration: 3 weeks (02/10/2017 - 20/10/2017) Figure 6.5: Sprint 5 completed tasks This Sprint was focused on implementing the social log in feature via Google and the addition of JWT for the user request authentication. There was some difficulties with the social log in feature which delayed its implementation. These difficulties are described on the section 10.2. The JWT authentication was implemented using the django-rest- framework-jwt[4] library for Django REST framework. These tokens allow to authenticate the user that has made the request. Also, every user created has a secret unique token which identifies the user and generates the tokens sent with the request. The tokens sent with the request have a determined time validation for security reasons. Also, if the tokens are stolen changing the secret token will automatically leave all the previous tokens generated invalid. So, the JWT give a good security level for the API. Also, the track model class was implemented and migrated on this Sprint. The GET, POST and PUT methods for the tracks resource were also implemented. 6.7 Sprint 6 - Tracks implementation Duration: 3 weeks (23/10/2017 - 10/11/2017) The Location model implemented on the Sprint 2 was made abstract to apply the extends model feature. The ActualLocation and TrackLocation model were implemented and migrated to the database. These models extend from the Location model. The POST and PUT methods for the track CHAPTER 6. DEVELOPMENT 73 location resource were also implemented. Figure 6.6: Sprint 6 completed tasks Since all the models were implemented their relations were also integrated on the view responses. For example, the response for the GET method on the devices view returns all the devices with its tracks and tracks locations on the same JSON. Having relations on the responses allows to maintain the models relations on it. 6.8 Sprint 7 - API finalization and Web kickoff Duration: 3 weeks (13/11/2017 - 01/12/2017) Figure 6.7: Sprint 7 completed tasks The API implementation was finished on this Sprint. The PATCH and DELETE methods for all the resources views were implemented on this Sprint. With these methods, every resource can be retrieved, updated, created and deleted. As the API was finished, the tools and the framework with its dependencies needed for the web development were installed. The mockups and the web conceptual schema were designed on this Sprint. Also, the license study and analysis were performed on this Sprint. This study can be seen on the section 8.2. CHAPTER 8. SOFTWARE PUBLISHING 80 To be approved by the Open Source Initiative (OSI), a license must go through the Open Source Initiative’s license review process. First of all, all the technologies used and its dependencies are open source or free software. This is very important because an open source software can’t be developed with private software. There are exceptions like the IDEs used or the operative system of the PC. All these exceptions were previously installed and the project could be implemented with a GNU/Linux based system and the free versions of the IDEs. A dependencies study was performed before selecting the license for the software. The next table shows all the development dependencies and the software used for the TooPath API and the web with their licenses: Dependency License Django Own (Free) Django REST Framework BSD 2-clause ”Simplified” Gunicorn MIT PyJWT MIT appdirs MIT django-cors-headers MIT django-rest-framework-gis MIT djangorestframework-jwt MIT packaging Apache 2.0 or BSD 2-clause ”Simplified” psycopg2 LGPL pyparsing MIT pytz MIT six MIT Angular MIT Bootstrap 4 MIT PostreSQL PostgreSQL license PostGIS GPL-2.0 Python PSF Typescript Apache 2.0 GDAL MIT Git GNU-2.0 Table 8.1: Development software and dependencies licenses CHAPTER 8. SOFTWARE PUBLISHING 81 All the software and its dependencies have open source licenses which don’t cause any problem. Different possibilities for the open source license of the API are studied. It is important to know the interests of the author company or entity and why the software should be open source in order to know which license choose. For example, the company can be concerned about patents which make an Apache License 2.0 the most appropriate. Instead, if the company is concerned about sharing improvements the GNU GPL 3.0 is the most appropriate. Also it is possible to just want the software to be used as the users wanted as long as the attribution is provided. On the last case the MIT license is the most appropriate. The main reason to make the software open source for the inLab company is to give free access to the software but always provide the author attribution. Also, inLab isn’t concerned about software patents or coerce the distribution of improvements. In consequence, the MIT license was selected. This license has the following contents: CHAPTER 8. SOFTWARE PUBLISHING 82 Copyright <YEAR> <COPYRIGHT HOLDER> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Listing 11: MIT license template 83 Chapter 9 Integration of knowledge The knowledge obtained from the bachelor degree is described on this chapter. Also, the technical competences are described to justify their grade of achievement. 9.1 Integration of knowledge from the bachelor degree The subjects of the bachelor degree mentioned bellow are extracted from the university website[15]. •Web Applications and Services (ASW): Developing of an API and a web that will consume it. Design of the architecture of a web service. •Software Architecture (AS): Programming patterns that can be applied like: Singleton and Transactional Pattern among others. Also, object oriented patterns and architecture design. •Database Design (DBD): Design of relational databases, schema and tables. •Requirements Engineering (ER): Evaluation of budget and context of software project. •Software Project Management (GPS): Concepts and experience of Agile methodology and a brief introduction of TDD. CHAPTER 9. INTEGRATION OF KNOWLEDGE 84 •Software Engineering Project (PES): Software development experience from a real project. •Knowledge Engineering and Distributed Intelligent Systems (ECSDI): Brief introduction to Python language and first project developed with this language. •Operating Systems Administration (ASO): Linux management. 9.2 Valoration of technical competences of the project Finally, the technical competences of the specialty will be justified. Next, the table shows the grade of achievement. CES1.1 CES1.2 CES1.3 CES1.4 CES1.5 CES1.6 CES1.7 CES1.8 In profundity X X X X X Enough X A little X X CES1.1 - To develop, maintain and evaluate complex and/or critical software systems and services The project consists on developing a geolocation API and a web. Also, it will include authentication and secure permissions for user management and a complex model and database integration. This competence will achieve the correspondent grade with the use of good developing patterns and a qualitative management from the development team of the project to ensure the completion of the API and web. CES1.2 - To solve integration problems in function of the strategies, standards and available technologies The main integration problem of this project is the use and management of geolocation raw data. This will be solved with the use of the Django REST Framework and the PostGIS add on. There are other integration CHAPTER 9. INTEGRATION OF KNOWLEDGE 85 problems like the API integration for the web and the server integration with the releases of the software. These problems will be solved following good patterns of web design and implementation and the use of tools like Jenkins to control the integration on the server. Ultimately, this competence will achieve the correspondent grade. CES1.3 - To identify, evaluate and manage potential risks related to software building which could arise. A complex software like this project can have potential risks like integration problems with the actual technologies, failures on the specification and proper functionalities. It is also important to consider that this software will be open-source, this fact is another possible risk as we need to use free software and tools to develop this project. To avoid these risks we will have constant meetings and monitoring of the software state to prevent and solve these risks. Also, all the technologies of the project analysis will be specified to ensure that the open-source milestone is possible. CES1.4 - To develop, maintain and evaluate distributed services and applications with network support This competence is achieved with the minimum grade due to the minimum use of network support. All the network environment like the server will be developed with the Project Manager help and supervision to ensure the good setup. In fact, the developer will only need few knowledge of the server functioning. CES1.5 - To specify, design, implement and evaluate databases This project needs a specific database with a design that can accomplish the API restrictions and store/manage geolocation data. This competence will achieve the correspondent grade because of the use of database schema, it will use add ons (like PostGIS) that will assure the store/manage of geolocation data. The database will be also designed following the knowledge acquired in the degree and following the API models restrictions. CHAPTER 9. INTEGRATION OF KNOWLEDGE 86 CES1.6 - To administrate databases The database is already designed and functional and will need minimum administration. Due to this, the selected grade is ”a little” and it will be accomplished with a good use of the migration system from Django and possible backups in case of failure. CES 1.7 -To control the quality and design tests in the software production This project will be a full quality software with a full final version release. It will also have integration and unit testing of the software. This competence is achieved with the maximum grade because the TDD methodology will be followed for the project development, and this will ensure a quality software with minimum possible bugs. CES2.1 - To define and manage the requirements of a software system. The project will be defined on the first weeks through team meetings and specifying the full functionalities and scope. The possible requirements will be studied and managed with the Project Manager to ensure the good development of the project and that the analysis is well done. 87 Chapter 10 Project obstacles The problems and obstacles of this project are described on this chapter. Every obstacle has its section. All this obstacles are briefly mentioned on previous. Every obstacle has a homonym section and an explanation with the cause and the solution of the obstacle or problem. 10.1 GDAL installation This obstacle appeared the Sprint 1. There was an obstacle with the installation of GDAL which is a dependency for the django-rest-framework- gis and PostGIS use. The geospatial features can’t be used without GDAL so it was an obstacle that needed to be solved with maximum priority. This obstacle was solved on the same Sprint but spending more time with the environment setup which wasn’t planned. The problem was caused by a bit version incompatibility between Python and OSGeo4W1. 10.2 Google log in feature This obstacle appeared on the Sprint 5. This feature was planned to be implemented on the Sprint 5 but it wasn’t as it is mentioned on the section 6.6. This feature was estimated as a simple feature to implement but it wasn’t. 1binary distribution for Windows to install GDAL CHAPTER 10. PROJECT OBSTACLES 88 Initially, some libraries provided by the framework were studied to implement this feature. This libraries were focused on all the social OAuth2 possibilities as Facebook, Twitter, Google and others. These libraries were rejected for two reasons: •OAuth was unnecessary: The API uses JWT, the use of OAuth system was unnecessary. •Unnecessary features: These libraries have a lot of features and social platform integration which aren’t needed to implement a Google log in. The Google Identity Platform[14] was studied and selected to implement this feature. This secure authentication system allows to implement this feature without dependencies and also to implement it easily on the web. Finally, the Google log in feature was implemented during the Sprint 8 as it is mentioned on the section 6.9. 2open standard for access delegation, commonly used as a way for Internet users to grant websites or applications access but without giving them the passwords 89 Chapter 11 Future work The possible features and functionalities that can be implemented for the API are described on this chapter. Also, possible improvements and new features of the web are mentioned. 11.1 Tracks algorithm The tracks algorithm implementation is the main API feature to be implemented in the future. The algorithm will allow the API to know when a track is finished and also, if a new track needs to be created. The main idea that the algorithm helps to check if the distance between the last position sent and the last position saved is possible within the time difference between these positions. For the algorithm implementation the fact that just one track can be on open state will be considered as a restriction. These will be the simple rules for the algorithm: •Track opened: –New track location sent and correct distance-time relation: track location added to track. –New track location sent and incorrect distance-time relation: track closed and new track created with the track location sent as first location. APPENDIX A. DATABASE CONCEPTUAL SCHEMA 96 Figure A.1: Database models conceptual schema 97 Appendix B OpenAPI Specification 1swagger: '2.0' 2info: 3version: 1.0.0 4title: TooPath 5description: TooPath is a device tracking software offered as a service.,→ 6contact: 7email: [email protected] 8license: 9name: MIT License 10 url: 'https://opensource.org/licenses/MIT' 11 host: '127.0.0.1:8000' 12 schemes: 13 - http 14 tags: 15 - name: users 16 description: petitions for the user management 17 - name: login 18 description: petitions for login 19 - name: token 20 description: petitions to manage tokens 21 - name: devices 22 description: petitions to manage devices 23 - name: track APPENDIX B. OPENAPI SPECIFICATION 98 24 description: petitions to manage tracks 25 - name: track location 26 description: petitions to manage the tracks locations 27 - name: actual location 28 description: petitions to manage the actual location of a device 29 paths: 30 /devices/: 31 get: 32 tags: 33 - devices 34 summary: Get all the user devices 35 description: >- 36 Petition to retrieve all the devices instances associated with the user,→ 37 identified by the JWT 38 produces: 39 - application/json 40 consumes: 41 - application/json 42 security: 43 - JWT: [] 44 responses: 45 '200': 46 description: devices information retrieved 47 schema: 48 type: array 49 items: 50 $ref: '#/definitions/DeviceResponse' 51 '401': 52 description: Unauthorized 53 schema: 54 $ref: '#/definitions/Error401' 55 '403': 56 description: Forbidden resource 57 schema: 58 $ref: '#/definitions/Error403' 59 post: APPENDIX B. OPENAPI SPECIFICATION 99 60 tags: 61 - devices 62 summary: Create a new device 63 description: >- 64 Petition to create a device instance with all the fields passed on the,→ 65 body and associated with the user identified by the JWT 66 produces: 67 - application/json 68 consumes: 69 - application/json 70 security: 71 - JWT: [] 72 parameters: 73 - in: body 74 name: body 75 description: User info 76 required: true 77 schema: 78 $ref: '#/definitions/Device' 79 responses: 80 '200': 81 description: device created succesfully 82 schema: 83 $ref: '#/definitions/DeviceResponse' 84 '400': 85 description: Bad Request due to invalid body or fields format 86 schema: 87 $ref: '#/definitions/Error400' 88 '401': 89 description: Unauthorized 90 schema: 91 $ref: '#/definitions/Error401' 92 '403': 93 description: Forbidden resource 94 schema: 95 $ref: '#/definitions/Error403' APPENDIX B. OPENAPI SPECIFICATION 100 96 '409': 97 description: Resource conflict 98 schema: 99 $ref: '#/definitions/Error409' 100 '/devices/{deviceId}/': 101 get: 102 tags: 103 - devices 104 summary: Get device info 105 description: >- 106 Petition to retrieve the device instance associated with the user 107 identified by the JWT and identified by the ID on the URL 108 produces: 109 - application/json 110 consumes: 111 - application/json 112 security: 113 - JWT: [] 114 parameters: 115 - name: deviceId 116 in: path 117 description: ID of device to retrieve 118 required: true 119 type: integer 120 format: int64 121 responses: 122 '200': 123 description: Device information retrieved 124 schema: 125 $ref: '#/definitions/DeviceResponse' 126 '401': 127 description: Unauthorized 128 schema: 129 $ref: '#/definitions/Error401' 130 '403': 131 description: Forbidden resource 132 schema: APPENDIX B. OPENAPI SPECIFICATION 101 133 $ref: '#/definitions/Error403' 134 '404': 135 description: Device not found 136 schema: 137 $ref: '#/definitions/Error404' 138 put: 139 tags: 140 - devices 141 summary: Change representation of a device 142 description: >- 143 Petition to change the representation of the device associated with the,→ 144 user identified by the JWT and identified by the ID on the URL 145 produces: 146 - application/json 147 consumes: 148 - application/json 149 security: 150 - JWT: [] 151 parameters: 152 - name: deviceId 153 in: path 154 description: ID of device to change the representation 155 required: true 156 type: integer 157 format: int64 158 - in: body 159 name: body 160 description: Device representation to change 161 required: true 162 schema: 163 $ref: '#/definitions/Device' 164 responses: 165 '201': 166 description: Device representation changed succesfully 167 schema: 168 $ref: '#/definitions/DeviceResponse' APPENDIX B. OPENAPI SPECIFICATION 102 169 '400': 170 description: Bad Request due to invalid body or fields format 171 schema: 172 $ref: '#/definitions/Error400' 173 '401': 174 description: Unauthorized 175 schema: 176 $ref: '#/definitions/Error401' 177 '403': 178 description: Forbidden resource 179 schema: 180 $ref: '#/definitions/Error403' 181 '404': 182 description: Device not found 183 schema: 184 $ref: '#/definitions/Error404' 185 patch: 186 tags: 187 - devices 188 summary: Update fields of a device 189 description: >- 190 Petition to update or change fields of the device instance associated,→ 191 with the user identified by the JWT and identified by the ID on the URL,→ 192 produces: 193 - application/json 194 consumes: 195 - application/json 196 security: 197 - JWT: [] 198 parameters: 199 - name: deviceId 200 in: path 201 description: ID of device to update fields 202 required: true 203 type: integer APPENDIX B. OPENAPI SPECIFICATION 103 204 format: int64 205 - in: body 206 name: body 207 description: Device fields to update 208 required: true 209 schema: 210 $ref: '#/definitions/Device' 211 responses: 212 '201': 213 description: Device updated succesfully 214 schema: 215 $ref: '#/definitions/DeviceResponse' 216 '400': 217 description: Bad Request due to invalid body or fields format 218 schema: 219 $ref: '#/definitions/Error400' 220 '401': 221 description: Unauthorized 222 schema: 223 $ref: '#/definitions/Error401' 224 '403': 225 description: Forbidden resource 226 schema: 227 $ref: '#/definitions/Error403' 228 '404': 229 description: Device not found 230 schema: 231 $ref: '#/definitions/Error404' 232 delete: 233 tags: 234 - devices 235 summary: Delete a device instance 236 description: >- 237 This petition allow to delete the device instance identified by the ID,→ 238 located on the URL 239 produces: APPENDIX B. OPENAPI SPECIFICATION 104 240 - application/json 241 consumes: 242 - application/json 243 security: 244 - JWT: [] 245 parameters: 246 - name: deviceId 247 in: path 248 description: ID of device to be deleted 249 required: true 250 type: integer 251 format: int64 252 responses: 253 '204': 254 description: Device deleted succesfully 255 '401': 256 description: Unauthorized 257 schema: 258 $ref: '#/definitions/Error401' 259 '403': 260 description: Forbidden resource 261 schema: 262 $ref: '#/definitions/Error403' 263 '404': 264 description: Device not found 265 schema: 266 $ref: '#/definitions/Error404' 267 '/devices/{deviceId}/actualLocation/': 268 get: 269 tags: 270 - actual location 271 summary: Retrieve the Actual Location of a device 272 description: >- 273 Petition to retrieve the actual location instance associated with the,→ 274 device identified by the ID on the URL 275 produces: APPENDIX B. OPENAPI SPECIFICATION 105 276 - application/json 277 consumes: 278 - application/json 279 security: 280 - JWT: [] 281 parameters: 282 - name: deviceId 283 in: path 284 description: device ID of the actual location 285 required: true 286 type: integer 287 format: int64 288 responses: 289 '200': 290 description: Actual Location retrieved succesfully 291 schema: 292 $ref: '#/definitions/ActualLocationResponse' 293 '401': 294 description: Unauthorized 295 schema: 296 $ref: '#/definitions/Error401' 297 '403': 298 description: Forbidden resource 299 schema: 300 $ref: '#/definitions/Error403' 301 '404': 302 description: Device not found 303 schema: 304 $ref: '#/definitions/Error404' 305 put: 306 tags: 307 - actual location 308 summary: Change representation of the actual location of a device 309 description: >- 310 Petition to change representation of the actual location associated with,→ 311 the device identified by the ID on the URL APPENDIX B. OPENAPI SPECIFICATION 112 529 '401': 530 description: Unauthorized 531 schema: 532 $ref: '#/definitions/Error401' 533 '403': 534 description: Forbidden resource 535 schema: 536 $ref: '#/definitions/Error403' 537 '404': 538 description: Device or Track not found 539 schema: 540 $ref: '#/definitions/Error404' 541 patch: 542 tags: 543 - track 544 summary: Update fields of a track 545 description: >- 546 Petition to update the fields of the track instance identified by the ID,→ 547 on the URL associated with the device identified by the ID on the URL,→ 548 produces: 549 - application/json 550 consumes: 551 - application/json 552 security: 553 - JWT: [] 554 parameters: 555 - name: deviceId 556 in: path 557 description: device ID of the track 558 required: true 559 type: integer 560 format: int64 561 - name: trackId 562 in: path 563 description: ID of the track to be updated APPENDIX B. OPENAPI SPECIFICATION 113 564 required: true 565 type: integer 566 format: int64 567 - in: body 568 name: body 569 description: New track fields values info 570 required: true 571 schema: 572 $ref: '#/definitions/Track' 573 responses: 574 '201': 575 description: Track fields updated succesfully 576 schema: 577 $ref: '#/definitions/TrackResponse' 578 '400': 579 description: Bad Request due to invalid body or fields format 580 schema: 581 $ref: '#/definitions/Error400' 582 '401': 583 description: Unauthorized 584 schema: 585 $ref: '#/definitions/Error401' 586 '403': 587 description: Forbidden resource 588 schema: 589 $ref: '#/definitions/Error403' 590 '404': 591 description: Device or Track not found 592 schema: 593 $ref: '#/definitions/Error404' 594 delete: 595 tags: 596 - track 597 summary: Delete a track 598 description: >- 599 Petition to delete the track instance identified by the ID on the URL,→ APPENDIX B. OPENAPI SPECIFICATION 114 600 associated with the device identified by the ID on the URL 601 produces: 602 - application/json 603 consumes: 604 - application/json 605 security: 606 - JWT: [] 607 parameters: 608 - name: deviceId 609 in: path 610 description: device ID of the track 611 required: true 612 type: integer 613 format: int64 614 - name: trackId 615 in: path 616 description: ID of the track to be deleted 617 required: true 618 type: integer 619 format: int64 620 responses: 621 '204': 622 description: Track deleted succesfully 623 '401': 624 description: Unauthorized 625 schema: 626 $ref: '#/definitions/Error401' 627 '403': 628 description: Forbidden resource 629 schema: 630 $ref: '#/definitions/Error403' 631 '404': 632 description: Device or Track not found 633 schema: 634 $ref: '#/definitions/Error404' 635 '/devices/{deviceId}/tracks/{trackId}/trackLocations/': 636 post: APPENDIX B. OPENAPI SPECIFICATION 115 637 tags: 638 - track location 639 summary: Create a new track location 640 description: >- 641 Petition to create the track location instance asociated on the track,→ 642 identified by the ID on the URL associated with the device identified by,→ 643 the ID on the URL 644 produces: 645 - application/json 646 consumes: 647 - application/json 648 security: 649 - JWT: [] 650 parameters: 651 - name: deviceId 652 in: path 653 description: ID of device of the track 654 required: true 655 type: integer 656 format: int64 657 - name: trackId 658 in: path 659 description: ID of the track to create the new track location 660 required: true 661 type: integer 662 format: int64 663 - in: body 664 name: body 665 description: Track location info 666 required: true 667 schema: 668 $ref: '#/definitions/TrackLocation' 669 responses: 670 '201': 671 description: Track Location created succesfully APPENDIX B. OPENAPI SPECIFICATION 116 672 schema: 673 $ref: '#/definitions/TrackLocationResponse' 674 '400': 675 description: Bad Request due to invalid body or fields format 676 schema: 677 $ref: '#/definitions/Error400' 678 '401': 679 description: Unauthorized 680 schema: 681 $ref: '#/definitions/Error401' 682 '403': 683 description: Forbidden resource 684 schema: 685 $ref: '#/definitions/Error403' 686 '404': 687 description: Device or Track not found 688 schema: 689 $ref: '#/definitions/Error404' 690 '/devices/{deviceId}/tracks/{trackId}/trackLocations/{trackLocationId}':,→ 691 put: 692 tags: 693 - track location 694 summary: Change the representation of the track location 695 description: >- 696 Petition to delete the track location instance asociated on the track,→ 697 identified by the ID on the URL associated with the device identified by,→ 698 the ID on the URL 699 produces: 700 - application/json 701 consumes: 702 - application/json 703 security: 704 - JWT: [] 705 parameters: APPENDIX B. OPENAPI SPECIFICATION 117 706 - name: deviceId 707 in: path 708 description: ID of device of the track 709 required: true 710 type: integer 711 format: int64 712 - name: trackId 713 in: path 714 description: ID of the track to update the new track location 715 required: true 716 type: integer 717 format: int64 718 - name: trackLocationId 719 in: path 720 description: ID of the track location to be updated 721 required: true 722 type: integer 723 format: int64 724 responses: 725 '204': 726 description: Track Location representation changed succesfully 727 schema: 728 $ref: '#/definitions/TrackLocationResponse' 729 '401': 730 description: Unauthorized 731 schema: 732 $ref: '#/definitions/Error401' 733 '403': 734 description: Forbidden resource 735 schema: 736 $ref: '#/definitions/Error403' 737 '404': 738 description: 'Device, Track or Track Location not found' 739 schema: 740 $ref: '#/definitions/Error404' 741 delete: 742 tags: APPENDIX B. OPENAPI SPECIFICATION 118 743 - track location 744 summary: Delete a track location instance 745 description: >- 746 Petition to delete the track location instance asociated on the track,→ 747 identified by the ID on the URL associated with the device identified by,→ 748 the ID on the URL 749 produces: 750 - application/json 751 consumes: 752 - application/json 753 security: 754 - JWT: [] 755 parameters: 756 - name: deviceId 757 in: path 758 description: ID of device of the track 759 required: true 760 type: integer 761 format: int64 762 - name: trackId 763 in: path 764 description: ID of the track to delete the new track location 765 required: true 766 type: integer 767 format: int64 768 - name: trackLocationId 769 in: path 770 description: ID of the track location to be deleted 771 required: true 772 type: integer 773 format: int64 774 responses: 775 '204': 776 description: Track Location deleted succesfully 777 '401': APPENDIX B. OPENAPI SPECIFICATION 119 778 description: Unauthorized 779 schema: 780 $ref: '#/definitions/Error401' 781 '403': 782 description: Forbidden resource 783 schema: 784 $ref: '#/definitions/Error403' 785 '404': 786 description: 'Device, Track or Track Location not found' 787 schema: 788 $ref: '#/definitions/Error404' 789 /users/: 790 post: 791 tags: 792 - users 793 summary: Create a new user 794 description: Petition to create the user instance with the info passed on the body,→ 795 produces: 796 - application/json 797 consumes: 798 - application/json 799 parameters: 800 - in: body 801 name: body 802 description: User info 803 required: true 804 schema: 805 $ref: '#/definitions/User' 806 responses: 807 '201': 808 description: User created 809 schema: 810 $ref: '#/definitions/UserResponse' 811 '400': 812 description: This field is required 813 schema: APPENDIX B. OPENAPI SPECIFICATION 120 814 $ref: '#/definitions/Error400' 815 '409': 816 description: Resource conflict 817 schema: 818 $ref: '#/definitions/Error409' 819 '/users/{userId}/': 820 get: 821 tags: 822 - users 823 summary: Get information of the user 824 description: Petition to retrieve the user instance identified by the ID on the URL,→ 825 produces: 826 - application/json 827 consumes: 828 - application/json 829 security: 830 - JWT: [] 831 parameters: 832 - name: userId 833 in: path 834 description: ID of user to return 835 required: true 836 type: integer 837 format: int64 838 responses: 839 '200': 840 description: OK 841 schema: 842 $ref: '#/definitions/UserResponse' 843 '401': 844 description: Unauthorized 845 schema: 846 $ref: '#/definitions/Error401' 847 '403': 848 description: Forbidden resource 849 schema: APPENDIX B. OPENAPI SPECIFICATION 121 850 $ref: '#/definitions/Error403' 851 '404': 852 description: User not found 853 schema: 854 $ref: '#/definitions/Error404' 855 put: 856 tags: 857 - users 858 summary: Change representation of the user 859 description: >- 860 Petition to change the representation of the user instance identified by,→ 861 the ID on the URL 862 produces: 863 - application/json 864 consumes: 865 - application/json 866 security: 867 - JWT: [] 868 parameters: 869 - name: userId 870 in: path 871 description: ID of user to return 872 required: true 873 type: integer 874 format: int64 875 - in: body 876 name: body 877 description: User representation to be changed 878 required: true 879 schema: 880 $ref: '#/definitions/User' 881 responses: 882 '200': 883 description: Representation changed succcesfully 884 schema: 885 $ref: '#/definitions/UserResponse' APPENDIX B. OPENAPI SPECIFICATION 128 1104 type: number 1105 heading: 1106 type: number 1107 utc: 1108 type: string 1109 device_privacy: 1110 type: string 1111 device_type: 1112 type: string 1113 device_imei: 1114 type: string 1115 Track: 1116 type: object 1117 properties: 1118 name: 1119 type: string 1120 description: 1121 type: string 1122 TrackLocation: 1123 type: object 1124 properties: 1125 point: 1126 type: object 1127 properties: 1128 type: 1129 type: string 1130 coordinates: 1131 type: array 1132 items: 1133 type: number 1134 format: float 1135 maxItems: 2 1136 minItems: 2 1137 ActualLocation: 1138 type: object 1139 properties: 1140 point: APPENDIX B. OPENAPI SPECIFICATION 129 1141 type: object 1142 properties: 1143 type: 1144 type: string 1145 coordinates: 1146 type: array 1147 items: 1148 type: number 1149 format: float 1150 maxItems: 2 1151 minItems: 2 1152 Login: 1153 type: object 1154 properties: 1155 username: 1156 type: string 1157 password: 1158 type: string 1159 GoogleLogin: 1160 type: object 1161 properties: 1162 email: 1163 type: string 1164 google-token: 1165 type: string 1166 User: 1167 type: object 1168 properties: 1169 username: 1170 type: string 1171 email: 1172 type: string 1173 first_name: 1174 type: string 1175 last_name: 1176 type: string 1177 password: APPENDIX B. OPENAPI SPECIFICATION 130 1178 type: string 1179 DeviceResponse: 1180 type: object 1181 properties: 1182 did: 1183 type: integer 1184 format: int64 1185 owner: 1186 type: string 1187 tracks: 1188 type: array 1189 items: 1190 $ref: '#/definitions/TrackResponse' 1191 name: 1192 type: string 1193 description: 1194 type: string 1195 created_at: 1196 type: string 1197 updated_at: 1198 type: string 1199 trash: 1200 type: boolean 1201 ip_address: 1202 type: string 1203 port_number: 1204 type: integer 1205 height: 1206 type: number 1207 speed: 1208 type: number 1209 heading: 1210 type: number 1211 utc: 1212 type: string 1213 device_privacy: 1214 type: string APPENDIX B. OPENAPI SPECIFICATION 131 1215 device_type: 1216 type: string 1217 device_imei: 1218 type: string 1219 TrackResponse: 1220 type: object 1221 properties: 1222 tid: 1223 type: integer 1224 format: int64 1225 name: 1226 type: string 1227 description: 1228 type: string 1229 device: 1230 type: integer 1231 format: int64 1232 locations: 1233 type: object 1234 properties: 1235 type: 1236 type: string 1237 features: 1238 type: array 1239 items: 1240 $ref: '#/definitions/TrackLocationResponse' 1241 TrackLocationResponse: 1242 type: object 1243 properties: 1244 id: 1245 type: integer 1246 format: int64 1247 type: 1248 type: string 1249 geometry: 1250 type: object 1251 properties: APPENDIX B. OPENAPI SPECIFICATION 132 1252 type: 1253 type: string 1254 coordinates: 1255 type: array 1256 items: 1257 type: number 1258 format: float 1259 maxItems: 2 1260 minItems: 2 1261 properties: 1262 type: object 1263 properties: 1264 created_at: 1265 type: string 1266 updated_at: 1267 type: string 1268 track: 1269 type: integer 1270 format: int64 1271 ActualLocationResponse: 1272 type: object 1273 properties: 1274 id: 1275 type: integer 1276 format: int64 1277 type: 1278 type: string 1279 geometry: 1280 type: object 1281 properties: 1282 type: 1283 type: string 1284 coordinates: 1285 type: array 1286 items: 1287 type: number 1288 format: float APPENDIX B. OPENAPI SPECIFICATION 133 1289 maxItems: 2 1290 minItems: 2 1291 properties: 1292 type: object 1293 properties: 1294 created_at: 1295 type: string 1296 updated_at: 1297 type: string 1298 device: 1299 type: integer 1300 format: int64 1301 UserResponse: 1302 type: object 1303 properties: 1304 id: 1305 type: integer 1306 format: int64 1307 username: 1308 type: string 1309 email: 1310 type: string 1311 first_name: 1312 type: string 1313 last_name: 1314 type: string 1315 date_joined: 1316 type: string 1317 last_login: 1318 type: string 1319 TokenResponse: 1320 type: object 1321 properties: 1322 token: 1323 type: string 1324 Error403: 1325 type: object APPENDIX B. OPENAPI SPECIFICATION 134 1326 properties: 1327 detail: 1328 type: string 1329 Error401: 1330 type: object 1331 properties: 1332 detail: 1333 type: string 1334 Error400: 1335 type: object 1336 properties: 1337 field_error: 1338 type: string 1339 Error404: 1340 type: object 1341 properties: 1342 detail: 1343 type: string 1344 Error409: 1345 type: object 1346 properties: 1347 detail: 1348 type: string 135 Appendix C Web mockups Figure C.1: Home page (not logged) APPENDIX C. WEB MOCKUPS 136 Figure C.2: Sign Up page Figure C.3: Log In page APPENDIX C. WEB MOCKUPS 137 Figure C.4: Home page (logged) Figure C.5: Create a device page