├── .gitignore ├── Dockerfile ├── FAQ.md ├── LICENSE.md ├── README.docker.md ├── README.md ├── boot.sh ├── constants.js ├── gencerts.sh ├── lib ├── checks.js ├── endpoints.js ├── models.js ├── models │ ├── Checkin.model.js │ ├── City.model.js │ ├── Comment.model.js │ ├── Like.model.js │ ├── Media.model.js │ ├── Poi.model.js │ ├── Rating.model.js │ ├── SocialAttributes.model.js │ └── User.model.js ├── resources │ ├── Category.js │ ├── City.js │ ├── Media.js │ ├── Poi.js │ ├── User.js │ └── opendata │ │ └── import.opendata.brussels.be.js └── rest.js ├── main.js ├── package.json ├── playground.json ├── startdb.sh ├── stopdb.sh ├── tests ├── README.md └── docker_smoketest.sh └── web_root ├── api ├── swagger.json └── swagger.yaml ├── css ├── jquery.dataTables.css └── style.css ├── images ├── Sorting icons.psd ├── back_disabled.png ├── back_enabled.png ├── back_enabled_hover.png ├── forward_disabled.png ├── forward_enabled.png ├── forward_enabled_hover.png ├── sort_asc.png ├── sort_asc_disabled.png ├── sort_both.png ├── sort_desc.png └── sort_desc_disabled.png ├── index.html ├── index.js ├── jquery.dataTables.css ├── jquery.dataTables.js ├── jquery.js ├── ocdb-client.js ├── ocdb.html ├── playground ├── README.md ├── index.html └── index.js ├── root.html └── style.css /.gitignore: -------------------------------------------------------------------------------- 1 | db/ 2 | node_modules/ -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:0.10-slim 2 | 3 | # https://github.com/fraunhoferfokus/OCDB 4 | 5 | WORKDIR /root/ocdb 6 | 7 | RUN apt-get -y update && \ 8 | apt-get -y install wget apg netcat git curl 9 | 10 | RUN git clone https://github.com/fraunhoferfokus/ocdb /root/ocdb 11 | 12 | RUN npm install 13 | 14 | RUN mkdir -p db/mongodb/bin && \ 15 | wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.6.tgz -P /tmp/ && \ 16 | tar -xvf /tmp/mongodb-linux-x86_64-2.6.6.tgz --strip-components 2 -C db/mongodb/bin mongodb-linux-x86_64-2.6.6/bin 17 | 18 | EXPOSE 443 19 | 20 | COPY boot.sh /root/ocdb/ 21 | 22 | CMD ["/root/ocdb/boot.sh"] 23 | -------------------------------------------------------------------------------- /FAQ.md: -------------------------------------------------------------------------------- 1 | 2 | FAQ 3 | === 4 | 5 | What is the OCDB? 6 | ----------------- 7 | 8 | OCDB stands for Open City Database - Quick and easy deployable cities related data service with read/write access to user generated content, points of interest and social interactions (likes, comments, ratings, check-ins). Software is based on and integrating a set of proven and widely used technologies. 9 | 10 | What is the reason to use the OCDB? 11 | ----------------------------------- 12 | 13 | Among many others, probably the most important: YOU remain ownership of the data, the POIs and the social interactions. 14 | 15 | How come the OCDB was developed? 16 | -------------------------------- 17 | 18 | It is part of a European Union funded project called [FIcontent](http://mediafi.org/). This project contributed with so-called technological "enablers", where one of these the OCDB is. 19 | 20 | Was this software already used somewhere in production? 21 | ------------------------------------------------------- 22 | 23 | Yes. The OCDB has powered the "LIVE FALLAS" app for the Event 2015 in Valencia/Spain with several thousands participants. Available on Google Play and Apple AppStore. 24 | 25 | Can i just try out this technology and play around with it before diving deeper? 26 | -------------------------------------------------------------------------------- 27 | 28 | Sure. Try out the [API console](http://fraunhoferfokus.github.io/OCDB/) or have a look at the [code example](http://jsfiddle.net/Lu7cjev0/). 29 | 30 | Can i host the OCDB on my own? 31 | ------------------------------ 32 | 33 | Yes. See the [instructions](README.md) to get an idea of the prerequisites. 34 | 35 | How long does it take to setup an own instance? 36 | ----------------------------------------------- 37 | 38 | Minutes. Depending on your environment and skills ;) 39 | Using our Dockerfile you spin a fully functional container providing an OCDB instance without any great effort. 40 | 41 | Can this service be used by native apps? 42 | ---------------------------------------- 43 | 44 | Yes. Client SDKs are available for Andoid, C#, Java, Jax, node.js/io.js, Objective-C, PHP, Python, Ruby, Scala, Spring MVC, Tizen. See [SDK](SDK.md) for more details. 45 | 46 | I've found a bug or another problem. What can i do? 47 | --------------------------------------------------- 48 | 49 | Please file an [issue](https://github.com/fraunhoferfokus/OCDB/issues). Our team will take care. 50 | 51 | Can i contribute to the OCDB project? 52 | ------------------------------------- 53 | 54 | Yes, please! Your are more than welcome to raise a pull request. 55 | 56 | How is the software licensed? 57 | ----------------------------- 58 | 59 | [Apache License, Version 2.0](LICENSE.md) 60 | 61 | Who maintains the OCDB project? 62 | ------------------------------- 63 | 64 | [Fraunhofer FOKUS - Competence Center Future Applications and Media](https://www.fokus.fraunhofer.de/fame) 65 | 66 | 67 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2014 Fraunhofer FOKUS 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.docker.md: -------------------------------------------------------------------------------- 1 | ## OCDB Dockerfile 2 | 3 | This directory contains a Dockerfile of [OCDB](https://github.com/fraunhoferfokus/OCDB). 4 | 5 | 6 | ### Requirements 7 | 8 | * Install [Docker](https://www.docker.com) 9 | 10 | 11 | ### Usage 12 | 13 | The `ocdb` endpoint is exposed internally on the port 443. 14 | The webservice can be launched and made accessible on e.g. the host's port 8080 with the command: 15 | 16 | ``` 17 | $ docker run -d -p 8080:443 fraunhoferfokus/ocdb:latest 18 | ``` 19 | 20 | You can now test the service by opening in your browser: [https://localhost:8080/v1/frontend/index.html](https://localhost:8080/v1/frontend/index.html) 21 | 22 | The service API can be consumed with (where $at is your access token): 23 | 24 | ``` 25 | $ curl -s -k -X GET "https://$HOST:$PORT/v1/cities?lat=52.5258885&lon=13.3142135&offset=0&limit=10" -H "Accept: application/json" -H "Authorization: token "$at 26 | ``` 27 | 28 | #### Use specific ssl certificates 29 | 30 | During the launch process, a random ssl certificate is created. 31 | Overwriting the `/root/.ocdb` directory allows to inject private certificates: 32 | 33 | ``` 34 | $ docker run -d -p 8080:443 -v "/tmp:/root/.ocdb" fraunhoferfokus/ocdb:latest 35 | ``` 36 | 37 | The directory must follow this naming convention: 38 | 39 | ``` 40 | $ ls /root/.ocdb/ 41 | cert.pem csr.pem key.pem 42 | ``` 43 | 44 | ### Docker image build 45 | 46 | * Use the following command inside the cloned repository: 47 | 48 | ``` 49 | $ docker build -t 'fraunhoferfokus/ocdb:latest' . 50 | ``` 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | OCDB 2 | ==== 3 | 4 | This documentation provides information on how to setup one instance of the OCDB service. After setup, an RESTful API with JavaScript Object Notion (JSON) as data transport format will be available to be used within your native and web apps. The API provides access to the content made available in the OCDB and provides means to input user generated content (UCG). Using an API the data for different cities and their Points of Interests (POI) can be retrieved for a usage within your applications. 5 | 6 | TL;DR 7 | ----- 8 | 9 | ``` 10 | $ # on a debian-based (# and osx) system. Notice: accatping PRs with instructions for your system! 11 | $ git clone https://github.com/fraunhoferfokus/ocdb 12 | $ cd ocdb 13 | $ npm install 14 | 15 | $ # db 16 | $ mkdir -p db/mongodb/bin 17 | $ curl -o /tmp/mongodb.tgz https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.2.tgz # osx: https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-3.0.2.tgz 18 | $ tar -xvf /tmp/mongodb.tgz --strip-components 2 -C db/mongodb/bin mongodb-linux-x86_64-3.0.2/bin # osx: mongodb-osx-x86_64-3.0.2/bin 19 | $ ./startdb.sh 20 | 21 | $ # certs 22 | $ ./gencerts.sh 23 | 24 | $ # start the service 25 | $ sudo node . 26 | $ # let it start until it says "Up and running ;)" 27 | 28 | $ # on a second shell/terminal 29 | $ curl -s -k -X POST "https://localhost/v1/users" -H "Accept: application/json" -H "Content-Type: application/json" -d "{\"n\":\"user\",\"a\":\"user@domain.com\",\"b\":\"441d05da1f570f55e0c8172787cdc1302ecad5db\"}" 30 | $ at=`curl -s -k -X GET "https://localhost/v1/users?a=12dea96fec20593566ab75692c9949596833adc9&b=441d05da1f570f55e0c8172787cdc1302ecad5db" -H "Accept: application/json" | cut -f 4 -d \" -` 31 | $ curl -s -k -X GET "https://localhost/v1/cities?lat=52.5258885&lon=13.3142135&offset=0&limit=10" -H "Accept: application/json" -H "Authorization: token "$at 32 | $ echo "Your token for the try out API console: "$at 33 | ``` 34 | 35 | Congrats. You did it! Want to explore the API? Try out the API console with [your private installation](http://fraunhoferfokus.github.io/OCDB/apiconsole/index.html?url=https://localhost/v1/frontend/api.json) (Notice: this will only work if you succeeded with the steps before) or try out [our public installation](http://fraunhoferfokus.github.io/OCDB/) (Notice: see the details there). 36 | 37 | 38 | Installation 39 | ------------ 40 | 41 | Required software components for a successful installation and operation. Make sure the following components are available on the installation machine / server: 42 | * git 43 | * node.js 44 | * mongoDB (see details below) 45 | 46 | Execute the following steps to install a OCDB instance on your machine / server. 47 | 48 | ``` 49 | $ git clone https://github.com/fraunhoferfokus/ocdb 50 | $ cd ocdb 51 | $ npm install 52 | ``` 53 | 54 | Please consider a 64 bit host machine for mongoDB. 55 | The underlying database is a document-oriented database, in particular mongoDB. Choose the appropriate binaries from the Mongo DB website (http://www.mongodb.org/downloads) and extract them into `` ocdb/db/mongodb ``. Afterwards the mongoDB deamon should be available at `` ocdb/db/mongodb/bin/mongod `` 56 | 57 | Important notice: remember to review the default configuration of mongoDB when going to deploy on a public machine! 58 | 59 | Configuration 60 | ------------- 61 | 62 | Check the configuration file at `` ocdb/constants.js `` and change if necessary. Place the SSL certificates at the location specified in the configuration file. See http://nodejs.org/api/tls.html on more inforamtion on how to generate certificates if none at hand. 63 | 64 | For development purposes you might wish to use self-signed certificates. Just run the following script to accomplish this. 65 | 66 | ``` 67 | $ cd ocdb 68 | $ ./gencerts.sh 69 | ``` 70 | 71 | Running 72 | ------- 73 | 74 | Firstly, start mongoDB using the provided start script: 75 | (Note: This step is only for your convenience and if you have unpacked the appropriate mongoDB package as described above. You might wish to skip this step, if you wish to use your own mongoDB installation.) 76 | 77 | ``` 78 | $ cd ocdb 79 | $ ./startdb.sh 80 | ``` 81 | 82 | Secondly, start the service by executing the follwing command: 83 | 84 | ``` 85 | $ cd ocdb 86 | $ node . 87 | ``` 88 | 89 | Hint: In case of a port below 1024 start the service using sudo. 90 | 91 | To check if everything has worked fine and your OCDB instance is up and running, navigate your browser to the address: https://localhost/v1/frontend/ 92 | 93 | Tests 94 | ----- 95 | 96 | A CURL based [smoke test](tests/docker_smoketest.sh) is available. 97 | 98 | Playground Example App 99 | ---------------------- 100 | 101 | Having got up to this point successfully you may now with to play around with the service. 102 | Have a look at the [playground source code](web_root/playground) for a fully functional first example. At the [project's web page](http://fraunhoferfokus.github.io/OCDB/) a hosted version of this example is linked. 103 | 104 | 105 | Deployment (Docker) 106 | ------------------- 107 | 108 | You may wish to deploy an instance of OCDB using docker. See [OCDB docker instructions](README.docker.md) for more information. Using docker you can install an instance of the OCDB on a [broad range of systems](https://docs.docker.com/installation/#installation) 109 | 110 | 111 | For impatient: 112 | 113 | ``` 114 | $ docker run -d -p 8080:443 fraunhoferfokus/ocdb:latest 115 | $ docker ps # to get your $CONTAINER_ID 116 | $ # after a while (initial city names import takes approx. 5 minutes) execute the following... 117 | $ docker exec $CONTAINER_ID sh tests/docker_smoketest.sh 118 | ``` 119 | You should see an output like this: 120 | 121 | ``` 122 | $ docker exec 36cea3499fbd sh tests/docker_smoketest.sh 123 | Using host: https://localhost:443 124 | Registering user...(user may already be registered) 125 | {"name":"user"}Log in... 126 | Got this access token: 796aa7a0-d171-11e4-95ab-77c3c5d38528 127 | Sample request (Get 10 cities around given location)... 128 | [{"_id":"55102d39c06ca52100dc385f","displayName":"Berlin","coords":[13.3888599,52.5170365]},{"_id":"55102d39c06ca52100dc385e","displayName":"Potsdam","coords":[13.0591397,52.4009309]},{"_id":"55102d39c06ca52100dc385d","displayName":"Dessau-Roßlau","coords":[12.2429261,51.8311104]},{"_id":"55102d39c06ca52100dc3857","displayName":"Leipzig","coords":[12.3810549,51.3391827]},{"_id":"55102d39c06ca52100dc3910","displayName":"Szczecin","coords":[14.5509784,53.4302122]},{"_id":"55102d39c06ca52100dc38ee","displayName":"Dresden","coords":[13.7381437,51.0493286]},{"_id":"55102d39c06ca52100dc3856","displayName":"Halle (Saale)","coords":[11.9705452,51.4825041]},{"_id":"55102d39c06ca52100dc385c","displayName":"Magdeburg","coords":[11.6399609,52.1315889]},{"_id":"55102d39c06ca52100dc3858","displayName":"Chemnitz","coords":[12.9252977,50.8322608]},{"_id":"55102d39c06ca52100dc38f7","displayName":"Gorzów Wielkopolski","coords":[15.2400451,52.7309926]}] 129 | OCDB: Smoke test ran successful. 130 | ``` 131 | 132 | API authentication requirements 133 | ------------------------------- 134 | 135 | Requests towards the OCDB API require an authentication. The required access token can be aquired with the following HTTP request: 136 | 137 | ```sh 138 | curl -s -k -X GET "https://$HOST:$PORT/v1/users?a=$SHA1USEROREMAIL&b=$SHA1PASSWORD" -H "Accept: application/json" 139 | ``` 140 | 141 | Where the environment variables have the following meaning 142 | * *$HOST*: the host of the OCDB instance 143 | * *$PORT*: the port 144 | * *$SHA1USEROREMAIL*: SHA1 hashed user name or email 145 | * *$SHA1PASSWORD*: SHA1 hashed password 146 | 147 | Neaturally, the account must exists in advance to make the access token request a success. 148 | For more information see the [API documentation](http://fraunhoferfokus.github.io/OCDB/apiconsole/index.html). 149 | 150 | API usage and JavaScript abstraction 151 | ------------------------------------ 152 | 153 | Once you OCDB instance is deployed you are ready to use the service within you Web based application. Simply add the JavaScript abstraction of the REST API into your HTML code: 154 | 155 | ``` 156 | 157 | ``` 158 | 159 | The available API calls can be viewed in the [OCDB client script](web_root/ocdb-client.js#L196) 160 | 161 | Problems 162 | -------- 163 | 164 | Please use the issue tracker to report any problems you might encounter. 165 | 166 | FAQ? 167 | -------- 168 | 169 | [Yes, of course](FAQ.md). 170 | 171 | License 172 | ------- 173 | ``` 174 | /******************************************************************************* 175 | * 176 | * Licensed under the Apache License, Version 2.0 (the "License"); 177 | * you may not use this file except in compliance with the License. 178 | * You may obtain a copy of the License at 179 | * 180 | * http://www.apache.org/licenses/LICENSE-2.0 181 | * 182 | * Unless required by applicable law or agreed to in writing, software 183 | * distributed under the License is distributed on an "AS IS" BASIS, 184 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 185 | * See the License for the specific language governing permissions and 186 | * limitations under the License. 187 | * 188 | * Copyright 2014 Fraunhofer FOKUS 189 | *******************************************************************************/ 190 | ``` 191 | -------------------------------------------------------------------------------- /boot.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash -e 2 | 3 | set -x 4 | 5 | D=$(pwd) 6 | 7 | if [ ! -d /root/.ocdb ]; then 8 | mkdir /root/.ocdb 9 | cd /root/.ocdb 10 | P=$(apg -n 1 -c "$RANDOM" -M SNCL -m 20 -x 22) 11 | echo -e "$P\n$P" | openssl genrsa -out key.pem 2048 12 | echo -e "\n\n\n\n\n\n\n\n\n" | openssl req -new -sha256 -key key.pem -out csr.pem 13 | openssl x509 -req -in csr.pem -signkey key.pem -out cert.pem 14 | fi 15 | 16 | cd $D 17 | ./startdb.sh 18 | # wait for mongo to be available 19 | until nc -z localhost 27017 20 | do 21 | sleep 2s 22 | done 23 | 24 | # fix to convince docker where our home is 25 | export HOME=/root 26 | node . & 27 | node_pid=$! 28 | 29 | # wait for the service to be available 30 | until nc -z localhost 443 31 | do 32 | # check if there was a problem during service start already 33 | ps | grep $node_pid | grep -v grep 34 | ec=$? 35 | if [ $ec -ne 0 ]; then 36 | wait $node_pid 37 | node_status=$? 38 | echo "node/iojs process exited with return code: $node_status"; 39 | exit 1; 40 | fi 41 | sleep 2s 42 | done 43 | 44 | # keep this container alive until service terminates 45 | while ps | grep $node_pid | grep -v grep 46 | do 47 | sleep 60 48 | done 49 | 50 | wait $node_pid 51 | node_status=$? 52 | echo "node/iojs process exited with return code: $node_status"; 53 | exit $node_status; 54 | -------------------------------------------------------------------------------- /constants.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | module.exports = { 19 | CERTIFICATE_LOCATION : "~/.ocdb/", 20 | REQUIRED_MIMETYPE : "application/json", 21 | FILE_ENDPOINTS : "./endpoints", 22 | LOCATION_RESOURCES : "./resources/", 23 | SERVER_PORT : 443, 24 | BASEURL_PATH : "/", 25 | API_VERSION : "v1", 26 | SESSION_LEASE : 43200000, 27 | ERROR_OK : "ok", 28 | ERROR_WRONG_MIMETYPE : "wrong_mimetype", 29 | ERROR_METHOD_NOT_ALLOWED : "method_not_allowed", 30 | ERROR_NOT_FOUND : "resource_not_found", 31 | ERROR_CONFLICT : "resource_conflict", 32 | ERROR_REQUEST_INVALID : "request_invalid", 33 | ERROR_REQUEST_UNAUTHORIZED : "request_unauthorized", 34 | ERROR_INTERNAL : "internal_server_error" 35 | } 36 | -------------------------------------------------------------------------------- /gencerts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Creating self-signed certificates in $HOME/.ocdb ..." 4 | 5 | mkdir -p $HOME/.ocdb 6 | command -v openssl >/dev/null 2>&1 || { echo >&2 "... requires openssl but it's not installed. Aborting."; exit 1; } 7 | 8 | openssl genrsa -out $HOME/.ocdb/key.pem 2048 9 | openssl req -new -key $HOME/.ocdb/key.pem -out $HOME/.ocdb/csr.pem 10 | openssl x509 -req -in $HOME/.ocdb/csr.pem -signkey $HOME/.ocdb/key.pem -out $HOME/.ocdb/cert.pem 11 | 12 | echo "End." 13 | -------------------------------------------------------------------------------- /lib/checks.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | var mandatoryModule = [ 19 | "express", 20 | "mongoose" 21 | ]; 22 | 23 | var moduleNotFoundErrorHandler = function(name){ 24 | throw new Error("Mandatory module "+ name + " is missing. " + 25 | "Please run 'npm install "+name+"' at command prompt to proceed."); 26 | }; 27 | 28 | var checkForMandatoryModules = function() { 29 | mandatoryModule.forEach(function(name) { 30 | try{ 31 | if (!require.resolve(name)) 32 | moduleNotFoundErrorHandler(name); 33 | } catch (e) { 34 | moduleNotFoundErrorHandler(name); 35 | console.trace(e); 36 | } 37 | }); 38 | }; 39 | 40 | module.exports = { 41 | "checkForMandatoryModules" : checkForMandatoryModules 42 | } 43 | 44 | -------------------------------------------------------------------------------- /lib/endpoints.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | //OCDB V1 Specification 19 | 20 | exports.endpoints = [ 21 | { 22 | "path" : "/cities", 23 | "type" : "collection", 24 | "resource" : "City" 25 | }, 26 | { 27 | "path" : "/cities/:cityid", 28 | "type" : "instance", 29 | "resource" : "City" 30 | }, 31 | { 32 | "path" : "/cities/:cityid/checkin", 33 | "type" : "instance", 34 | "resource" : "City" 35 | }, 36 | { 37 | "path" : "/cities/:cityid/comment", 38 | "type" : "instance", 39 | "resource" : "City" 40 | }, 41 | { 42 | "path" : "/cities/:cityid/like", 43 | "type" : "instance", 44 | "resource" : "City" 45 | }, 46 | { 47 | "path" : "/cities/:cityid/rating", 48 | "type" : "instance", 49 | "resource" : "City" 50 | }, 51 | 52 | 53 | 54 | { 55 | "path" : "/cities/:cityid/pois", 56 | "type" : "collection", 57 | "resource" : "Poi" 58 | }, 59 | { 60 | "path" : "/pois", 61 | "type" : "collection", 62 | "resource" : "Poi" 63 | }, 64 | { 65 | "path" : "/pois/:poiid", 66 | "type" : "instance", 67 | "resource" : "Poi" 68 | }, 69 | { 70 | "path" : "/pois/:poiid/checkin", 71 | "type" : "instance", 72 | "resource" : "Poi" 73 | }, 74 | { 75 | "path" : "/pois/:poiid/comment", 76 | "type" : "instance", 77 | "resource" : "Poi" 78 | }, 79 | { 80 | "path" : "/pois/:poiid/like", 81 | "type" : "instance", 82 | "resource" : "Poi" 83 | }, 84 | { 85 | "path" : "/pois/:poiid/rating", 86 | "type" : "instance", 87 | "resource" : "Poi" 88 | }, 89 | 90 | 91 | 92 | { 93 | "path" : "/pois/:poiid/media", 94 | "type" : "collection", 95 | "resource" : "Media" 96 | }, 97 | { 98 | "path" : "/media/:mediaid", 99 | "type" : "instance", 100 | "resource" : "Media" 101 | }, 102 | 103 | 104 | 105 | { 106 | "path" : "/users", 107 | "type" : "collection", 108 | "resource" : "User" 109 | } 110 | ] -------------------------------------------------------------------------------- /lib/models.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | var mongoose = require('mongoose'); 19 | if(!mongoose.connection.readyState){ 20 | mongoose.connect('localhost', 'ocdb'); 21 | } 22 | 23 | var UserModel = require('./models/User.model.js').model; 24 | var User = mongoose.model('User', new mongoose.Schema(UserModel)); 25 | 26 | var CityModel = require('./models/City.model.js').model; 27 | var City = mongoose.model('Cities', new mongoose.Schema(CityModel)); 28 | 29 | var PoiModel = require('./models/Poi.model.js').model; 30 | var Poi = mongoose.model('Pois', new mongoose.Schema(PoiModel)); 31 | 32 | var MediaModel = require('./models/Media.model.js').model; 33 | var Media = mongoose.model('Media', new mongoose.Schema(MediaModel)); 34 | 35 | var SocialAttributesModel = require('./models/SocialAttributes.model.js').model; 36 | var SocialAttributes = mongoose.model('SocialAttributes', new mongoose.Schema(SocialAttributesModel)); 37 | 38 | var CheckinModel = require('./models/Checkin.model.js').model; 39 | var Checkin = mongoose.model('Checkin', new mongoose.Schema(CheckinModel)); 40 | 41 | var CommentModel = require('./models/Comment.model.js').model; 42 | var Comment = mongoose.model('Comment', new mongoose.Schema(CommentModel)); 43 | 44 | var LikeModel = require('./models/Like.model.js').model; 45 | var Like = mongoose.model('Like', new mongoose.Schema(LikeModel)); 46 | 47 | var RatingModel = require('./models/Rating.model.js').model; 48 | var Rating = mongoose.model('Rating', new mongoose.Schema(RatingModel)); 49 | 50 | module.exports = { 51 | model : { 52 | "User" : User, 53 | "City" : City, 54 | "Poi" : Poi, 55 | "Media" : Media, 56 | "SocialAttributes" : SocialAttributes, 57 | "Checkin" : Checkin, 58 | "Comment" : Comment, 59 | "Like" : Like, 60 | "Rating" : Rating 61 | } 62 | } -------------------------------------------------------------------------------- /lib/models/Checkin.model.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | var mongoose = require('mongoose'); 19 | var ObjectId = mongoose.Schema.Types.ObjectId; 20 | 21 | //checkin model 22 | exports.model = { 23 | "user": { 24 | "refurl": String, 25 | "_user":{ "type": ObjectId, "ref": 'User' }, 26 | }, 27 | "ts": Number, 28 | "coords": { "type": [], "index": '2d' }, 29 | "city": { 30 | "refurl": String, 31 | "_city":{ "type": ObjectId, "ref": 'City' } 32 | } 33 | } -------------------------------------------------------------------------------- /lib/models/City.model.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | var mongoose = require('mongoose'); 19 | var ObjectId = mongoose.Schema.Types.ObjectId; 20 | exports.model = { 21 | "locode": String, 22 | "displayName": String, 23 | "description": String, 24 | "locale": String, 25 | "coords": { "type": [], "index": '2d', "unique": true }, 26 | "socatt": { "type": ObjectId, "ref": 'SocialAttributes' } 27 | } -------------------------------------------------------------------------------- /lib/models/Comment.model.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | var mongoose = require('mongoose'); 19 | var ObjectId = mongoose.Schema.Types.ObjectId; 20 | 21 | //Comment model 22 | exports.model = { 23 | "user": { 24 | "refurl": String, 25 | "_user":{ "type": ObjectId, "ref": 'User' }, 26 | }, 27 | "comment": String, 28 | "ts": Number, 29 | "coords": { "type": [], "index": '2d' }, 30 | "city": { 31 | "refurl": String, 32 | "_city":{ "type": ObjectId, "ref": 'City' } 33 | } 34 | } -------------------------------------------------------------------------------- /lib/models/Like.model.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | var mongoose = require('mongoose'); 19 | var ObjectId = mongoose.Schema.Types.ObjectId; 20 | 21 | //Like model 22 | exports.model = { 23 | "user": { 24 | "refurl": String, 25 | "_user":{ "type": ObjectId, "ref": 'User' }, 26 | }, 27 | "like": Boolean, 28 | "ts": Number, 29 | "coords": { "type": [], "index": '2d' }, 30 | "city": { 31 | "refurl": String, 32 | "_city":{ "type": ObjectId, "ref": 'City' } 33 | } 34 | } -------------------------------------------------------------------------------- /lib/models/Media.model.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | //Media schema 19 | var mongoose = require('mongoose'); 20 | var ObjectId = mongoose.Schema.Types.ObjectId; 21 | exports.model = { 22 | "title": String, 23 | "url": [ String ] , 24 | "type": String, 25 | "user": { 26 | "refurl": String, 27 | "_user":{ "type": ObjectId, "ref": 'User' }, 28 | }, 29 | "timestamp": String, 30 | "featured": Boolean, 31 | "coords": { "type": [], "index": '2d' }, 32 | "poi": { 33 | "refurl": String, 34 | "_poi":{ "type": ObjectId, "ref": 'Poi' } 35 | }, 36 | "attributes": mongoose.Schema.Types.Mixed, 37 | "socatt": { "type": ObjectId, "ref": 'SocialAttributes' } 38 | } 39 | -------------------------------------------------------------------------------- /lib/models/Poi.model.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | //Poi schema 19 | var mongoose = require('mongoose'); 20 | var ObjectId = mongoose.Schema.Types.ObjectId; 21 | exports.model = { 22 | "name": String, 23 | "description": String, 24 | "contact": { 25 | "address": String, 26 | "phone": String, 27 | "link": String, 28 | "email": String 29 | }, 30 | "openHours":[ 31 | { 32 | "fromdow": Number, 33 | "fromtime": Number, 34 | "todow": Number, 35 | "totime": Number, 36 | "startdate": Number, 37 | "occurance": Number, 38 | "every": Number 39 | } 40 | ], 41 | "fee": [ 42 | { 43 | "currency": String, 44 | "value": Number, 45 | "hint": String 46 | } 47 | ], 48 | "tags": [ 49 | String 50 | ], 51 | "coords": { "type": [], "index": '2d' }, 52 | "city": { 53 | "refurl": String, 54 | "_city":{ "type": ObjectId, "ref": 'City' } 55 | }, 56 | "media": { 57 | "refurl": String, 58 | "mediaCount": Number, 59 | "_media": [ { "type": ObjectId, "ref": 'Media' } ] 60 | }, 61 | "public": {type:Boolean, default: false}, 62 | "user": { 63 | "refurl": String, 64 | "_user":{ "type": ObjectId, "ref": 'User' }, 65 | }, 66 | "socatt": { "type": ObjectId, "ref": 'SocialAttributes' }, 67 | "source": { "type": String, "unique": true, "sparse": true} 68 | } 69 | -------------------------------------------------------------------------------- /lib/models/Rating.model.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | var mongoose = require('mongoose'); 19 | var ObjectId = mongoose.Schema.Types.ObjectId; 20 | 21 | //Rating model 22 | exports.model = { 23 | "user": { 24 | "refurl": String, 25 | "_user":{ "type": ObjectId, "ref": 'User' }, 26 | }, 27 | "rating": Number, 28 | "ts": Number, 29 | "coords": { "type": [], "index": '2d' }, 30 | "city": { 31 | "refurl": String, 32 | "_city":{ "type": ObjectId, "ref": 'City' } 33 | }, 34 | "_socatt":{ "type": ObjectId, "ref": 'SocialAttributes' } 35 | } -------------------------------------------------------------------------------- /lib/models/SocialAttributes.model.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | var mongoose = require('mongoose'); 19 | var ObjectId = mongoose.Schema.Types.ObjectId; 20 | 21 | exports.model = { 22 | "likes": { 23 | "refurl": String, 24 | "count": { "type": Number, default: 0 }, 25 | "like": [ { "type": ObjectId, "ref": 'Like' } ] 26 | }, 27 | "checkins": { 28 | "refurl": String, 29 | "count": { "type": Number, default: 0 }, 30 | "checkin": [ { "type": ObjectId, "ref": 'Checkin' } ] 31 | }, 32 | "ratings": { 33 | "refurl": String, 34 | "count": { "type": Number, default: 0 }, 35 | "average": { "type": Number, default: 0 }, 36 | "rating": [ { "type": ObjectId, "ref": 'Rating' } ] 37 | }, 38 | "comments": { 39 | "refurl": String, 40 | "count": { "type": Number, default: 0 }, 41 | "comment": [ { "type": ObjectId, "ref": 'Comment' } ] 42 | } 43 | } -------------------------------------------------------------------------------- /lib/models/User.model.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | //User schema 19 | var mongoose = require('mongoose'); 20 | var ObjectId = mongoose.Schema.Types.ObjectId; 21 | 22 | exports.model = { 23 | "name": String, 24 | "namesha1": { "type": String, "unique": true }, 25 | "parents": [ { "type": ObjectId, "ref": 'User' } ], 26 | "email": String, 27 | "emailsha1": { "type": String, "unique": true }, 28 | "access": [ { "token": String, "lease": Number } ], 29 | "attributes": mongoose.Schema.Types.Mixed, 30 | "statistics": mongoose.Schema.Types.Mixed, 31 | "socatt": { "type": ObjectId, "ref": 'SocialAttributes' } 32 | } 33 | -------------------------------------------------------------------------------- /lib/resources/Category.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | var getResource = function(ep,params,query,body,cb){ 19 | cb(0,{resource:"category-resource-get",ep:ep,params:params,body:body,query:query}); 20 | } 21 | 22 | var postResource = function(ep,params,query,body,cb){ 23 | cb(0,{resource:"category-resource-post",ep:ep,params:params,body:body,query:query}); 24 | } 25 | 26 | var putResource = function(ep,params,query,body,cb){ 27 | cb(0,{resource:"category-resource-put",ep:ep,params:params,body:body,query:query}); 28 | } 29 | 30 | var deleteResource = function(ep,params,query,body,cb){ 31 | cb(0,{resource:"category-resource-delete",ep:ep,params:params,body:body,query:query}); 32 | } 33 | 34 | 35 | module.exports = { 36 | "GET" : getResource, 37 | "POST" : postResource, 38 | "PUT" : putResource, 39 | "DELETE" : deleteResource 40 | }; -------------------------------------------------------------------------------- /lib/resources/City.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | var _ = require("underscore"); 19 | var http = require("http"); 20 | var City = require('../models.js').model.City; 21 | 22 | console.log("Loading city resources..."); 23 | 24 | var fieldsFilteredOut = { '__v': 0 }; 25 | 26 | //check if we have all the cities ;) 27 | City.find({}).limit(1).exec(function(e,r){ 28 | if(e || !r.length){ 29 | console.log("Hold on, grab a coffee. going to import cities..."); 30 | importCities(0,0,function(importResult){ 31 | console.log("Imported "+importResult.length+" cities. Some errors while saving may occur. That's not that bad ;)"); 32 | console.log("Up and running ;)"); 33 | }); 34 | } else { 35 | console.log("Up and running ;)"); 36 | } 37 | }) 38 | 39 | //Resources 40 | var getResource = function(type,params,query,body,cb){ 41 | if(typeof query.name!="undefined"){ 42 | getCitiesByLocationAndName(parseFloat(query.lon), parseFloat(query.lat), query.name, function(res, meta){ 43 | cb(0, res, meta); 44 | },{limit: (parseInt(query.limit) || 1), offset: (parseInt(query.offset) || 0) }); 45 | } if(typeof query.search=="undefined") { 46 | getCitiesFromDB(parseFloat(query.lon), parseFloat(query.lat), function(res, meta){ 47 | cb(0, res, meta); 48 | },{limit: (parseInt(query.limit) || 20), offset: (parseInt(query.offset) || 0) }); 49 | } else { 50 | searchCities(query.search, function(res, meta){ 51 | cb(0, res, meta); 52 | },{limit: (parseInt(query.limit) || 20), offset: (parseInt(query.offset) || 0) }); 53 | } 54 | } 55 | 56 | var postResource = function(type,params,query,body,cb){ 57 | cb(0,{resource:"City-resource-post",type:type,params:params,body:body,query:query}); 58 | } 59 | 60 | var putResource = function(type,params,query,body,cb){ 61 | cb(0,{resource:"City-resource-put",type:type,params:params,body:body,query:query}); 62 | } 63 | 64 | var deleteResource = function(type,params,query,body,cb){ 65 | cb(0,{resource:"City-resource-delete",type:type,params:params,body:body,query:query}); 66 | } 67 | 68 | //DB 69 | var getCitiesFromDB = function(lon, lat, cb, options){ 70 | City.find({ coords : { $near : [ lon , lat ] }}) 71 | .skip(options.offset) 72 | .limit(options.offset+options.limit) 73 | .select(fieldsFilteredOut) 74 | .exec(function(e,r){ 75 | City.count({},function(err,recordsTotal){ 76 | if(err) recordsTotal=-1; 77 | cb((!e)?r:[],{recordsFiltered:recordsTotal,recordsTotal:recordsTotal}); 78 | }); 79 | } ); 80 | } 81 | 82 | var getCitiesByLocationAndName = function(lon, lat, name, cb, options){ 83 | City.find({ coords : { $near : [ lon , lat ] }, displayName: new RegExp('^'+name+'$', "i") }) 84 | .skip(options.offset) 85 | .limit(options.offset+options.limit) 86 | .select(fieldsFilteredOut) 87 | .exec(function(e,r){ 88 | City.count({},function(err,recordsTotal){ 89 | if(err) recordsTotal=-1; 90 | City.count({ displayName: new RegExp('^'+name+'$', "i") },function(err,recordsFiltered){ 91 | if(err) recordsFiltered=-1; 92 | cb((!e)?r:[],{recordsFiltered:recordsFiltered,recordsTotal:recordsTotal}); 93 | }); 94 | }); 95 | } ); 96 | } 97 | 98 | var searchCities = function(search, cb, options){ 99 | City.find({ displayName: new RegExp(search, "i") }) 100 | .skip(options.offset) 101 | .limit(options.offset+options.limit) 102 | .select(fieldsFilteredOut) 103 | .exec(function(e,r){ 104 | City.count({},function(err,recordsTotal){ 105 | if(err) recordsTotal=-1; 106 | City.count({ displayName: new RegExp(search, "i") },function(err,recordsFiltered){ 107 | if(err) recordsFiltered=-1; 108 | cb((!e)?r:[],{recordsFiltered:recordsFiltered,recordsTotal:recordsTotal}); 109 | }); 110 | }); 111 | } ); 112 | } 113 | 114 | // City functions 115 | var importCities = function(lat, lon, cb){ 116 | 117 | 118 | var cityNameProvider = "http://overpass-api.de/api/interpreter?data="+ 119 | "[out:json][timeout:300];("+ 120 | "node[%22place%22=%22city%22]("+(lat-90)+","+(lon-180)+","+(lat-(-90))+","+(lon-(-180))+");" + 121 | //smaller cities,towns: 122 | //"node[%22place%22=%22town%22]("+(lat-0.5)+","+(lon-0.5)+","+(lat-(-0.5))+","+(lon-(-0.5))+");" + 123 | ");out%20body%20qt;"; 124 | 125 | http.get(cityNameProvider, function(res) { 126 | var result = '', length=0; 127 | 128 | res.on('data', function(chunk) { 129 | length += chunk.length; 130 | process.stdout.write("Downloading " + length + " bytes\r"); 131 | result += chunk; 132 | }); 133 | 134 | res.on('end', function() { 135 | var datares = JSON.parse(result); 136 | console.log("end."); 137 | 138 | console.log(datares.elements?datares.elements.length:""); 139 | 140 | var formatted = _.compact( 141 | _.map(datares.elements, function(v) { 142 | if(!v.tags || !v.tags.name || !v.lon || !v.lat ) 143 | return; 144 | return { 145 | displayName: v.tags.name, 146 | coords: [ parseFloat(v.lon), parseFloat(v.lat) ] 147 | } 148 | }) 149 | ); 150 | 151 | var storeCity = function(v) { 152 | new City(v).save(function(err) { 153 | if(err) console.log('error saving #' + v.displayName); 154 | else process.stdout.write("saved #" + v.displayName + " \r"); 155 | }) 156 | }; 157 | 158 | _.each(formatted, storeCity); 159 | cb(formatted || []); 160 | }); 161 | }).on('error', function(e) { 162 | console.log("provider error: ",e); 163 | cb([]); 164 | }); 165 | }; 166 | 167 | module.exports = { 168 | "GET" : getResource, 169 | "POST" : postResource, 170 | "PUT" : putResource, 171 | "DELETE" : deleteResource 172 | }; 173 | -------------------------------------------------------------------------------- /lib/resources/Media.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | var _ = require("underscore"); 19 | var Media = require('../models.js').model.Media; 20 | var Poi = require('../models.js').model.Poi; 21 | 22 | console.log("Loading media resources..."); 23 | 24 | var fieldsFilteredOut = { '__v': 0 }; 25 | 26 | var getResource = function(ep,params,query,body,cb){ 27 | //city attached pois 28 | if(params.poiid && ep.type==="collection"){ 29 | getMediaByPoiID(params.poiid, function(res){ 30 | cb(0, res); 31 | },{limit: (parseInt(query.limit) || 20), offset: (parseInt(query.offset) || 0) }); 32 | return; 33 | } 34 | 35 | //resource not matched/found 36 | cb(404,[]); 37 | } 38 | 39 | var postResource = function(ep,params,query,body,cb){ 40 | if(params.poiid){ 41 | saveMedia(params.poiid, body, cb); 42 | return; 43 | } 44 | if(params.mediaid){ 45 | console.log(); 46 | delete body._id; 47 | Media.update({_id:params.mediaid}, { $set: body }, {}, function(err,affected,raw){ 48 | if(err){ 49 | cb(400,{}); 50 | } else { 51 | cb(0,raw); 52 | } 53 | }) 54 | return; 55 | } 56 | cb(400,[]); 57 | } 58 | 59 | var putResource = function(ep,params,query,body,cb){ 60 | cb(0,{resource:"media-resource-put",ep:ep,params:params,body:body,query:query}); 61 | } 62 | 63 | var deleteResource = function(ep,params,query,body,cb){ 64 | //media delete 65 | 66 | if(params.mediaid && ep.type==="instance"){ 67 | console.log("Deleting media: ",params.mediaid); 68 | Media.find({ _id:params.mediaid }).remove( function(err, res){ 69 | console.log(err, res); 70 | if (err) { 71 | return cb(404, {affected:res}); 72 | }; 73 | return cb(0, {affected:res}); 74 | } ); 75 | 76 | return; 77 | } 78 | 79 | //resource not matched/found 80 | cb(404,[]); 81 | } 82 | 83 | var getPoiById = function(id,cb){ 84 | Poi.findById(id) 85 | .populate('media._media') 86 | .select(fieldsFilteredOut) 87 | .exec(function(e,r){ 88 | cb((!e)?r:{}); 89 | } ); 90 | } 91 | 92 | var saveMedia = function(poiid, media, cb){ 93 | getPoiById(poiid, function(poi){ 94 | if(!poi._id){ 95 | cb(404,{}); 96 | return; 97 | } 98 | if(!media || !media.url || !media.url.length || !media.url[0]){ 99 | cb(400,{}); 100 | return; 101 | } 102 | var resultArray = []; 103 | if(media && media.length){ 104 | var returnResult = _.after(media.length, function(){ 105 | if(resultArray.length){ 106 | cb(0,resultArray); 107 | } else { 108 | cb(400,[]); 109 | } 110 | }); 111 | _.each(media, function(mediaItem) { 112 | mediaItem.poi = { refurl:"pois/"+poiid, "_poi": poiid}; 113 | new Media(mediaItem).save(function(err,mediaProduct) { 114 | if(err) { 115 | console.log('error saving media: ', err); 116 | returnResult(); 117 | } 118 | else { 119 | delete mediaProduct.__v; 120 | resultArray.push(mediaProduct); 121 | if(!poi.media) poi.media = {refurl: "pois/"+poiid+"/media", "_media": [], "mediaCount": 0} 122 | poi.media["_media"].push(mediaProduct._id); 123 | poi.media["mediaCount"]=(poi.media["mediaCount"])?poi.media["mediaCount"]+1:1; 124 | poi.save(function(e,p) { 125 | if(e) {console.log("Error saving media to poi. ",e); } 126 | else console.log('saved media.'); 127 | returnResult(); 128 | }); 129 | } 130 | })} 131 | ); 132 | } else { 133 | //single media save request 134 | media.poi = { refurl:"pois/"+poiid, "_poi": poiid}; 135 | new Media(media).save(function(err,mediaProduct) { 136 | if(err) { 137 | console.log('error saving media: ', err); 138 | cb(400,{}); 139 | } 140 | else { 141 | delete mediaProduct.__v; 142 | if(!poi.media) poi.media = {refurl: "pois/"+poiid+"/media", "_media": [], "mediaCount": 0} 143 | poi.media["_media"].push(mediaProduct._id); 144 | poi.media["mediaCount"]=(poi.media["mediaCount"])?poi.media["mediaCount"]+1:1; 145 | poi.save(function(e,p) { 146 | if(e) {console.log("Error saving media to poi. ",e); } 147 | else console.log('saved media.'); 148 | cb(0,mediaProduct); 149 | }); 150 | } 151 | }) 152 | } 153 | }); 154 | } 155 | 156 | 157 | var getMediaByPoiID = function(poiid, cb, options){ 158 | 159 | //TODO: this really does not have to be initialized more than once! 160 | var opts = [ 161 | {path:"user._user", model:"User", select: "name _id email"}, 162 | {path:"user._user", model:"User", select: "name _id email"}, 163 | {path:"user._user", model:"User", select: "name _id email"}, 164 | {path:"user._user", model:"User", select: "name _id email"}, 165 | ]; 166 | 167 | Media.find({ "poi._poi": poiid }) 168 | .skip(options.offset) 169 | .limit(options.offset+options.limit) 170 | .select(fieldsFilteredOut) 171 | .exec(function(e,r){ 172 | if(e) return cb(e,[]); 173 | Media.populate(r,opts,function(err,res){ 174 | cb((!err)?res:[]); 175 | }) 176 | } ); 177 | } 178 | 179 | module.exports = { 180 | "GET" : getResource, 181 | "POST" : postResource, 182 | "PUT" : putResource, 183 | "DELETE" : deleteResource 184 | }; 185 | -------------------------------------------------------------------------------- /lib/resources/Poi.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | var _ = require("underscore"); 19 | var Poi = require('../models.js').model.Poi; 20 | var Media = require('../models.js').model.Media; 21 | var SocialAttributes = require('../models.js').model.SocialAttributes; 22 | var Checkin = require('../models.js').model.Checkin; 23 | var Comment = require('../models.js').model.Comment; 24 | var Like = require('../models.js').model.Like; 25 | var Rating = require('../models.js').model.Rating; 26 | 27 | console.log("Loading poi resources..."); 28 | 29 | var fieldsFilteredOut = { '__v': 0 }; 30 | 31 | var getResource = function(ep,params,query,body,cb,uid){ 32 | //poi direct access 33 | if(params.poiid && ep.type==="instance"){ 34 | var options={}; 35 | if(ep.path.indexOf("comment")>=0){ 36 | options.commentOffset=query.offset?query.offset:0; 37 | options.commentLimit=query.limit?query.limit:5; 38 | } 39 | if(query.expand){ 40 | options.expand=query.expand; 41 | } 42 | getPoiById(params.poiid,function(c,r){cb(c,r)},uid,options); 43 | return; 44 | } 45 | 46 | //city attached pois 47 | if(params.cityid && ep.type==="collection"){ 48 | if(typeof query.lon2!="undefined" && typeof query.lat2!="undefined" ){ 49 | getPoisByBBAndCity(parseFloat(query.lon), parseFloat(query.lat), parseFloat(query.lon2), parseFloat(query.lat2), params.cityid, function(err,res){ 50 | cb(err, res); 51 | },{limit: (parseInt(query.limit) || 20), offset: (parseInt(query.offset) || 0), uid:uid }); 52 | } else { 53 | getPoisByLocationAndCity(parseFloat(query.lon), parseFloat(query.lat), params.cityid, function(err,res,meta){ 54 | cb(err, res, meta); 55 | },{search: query.search||'', limit: (parseInt(query.limit) || 20), offset: (parseInt(query.offset) || 0), uid:uid }); 56 | } 57 | return; 58 | } 59 | 60 | //resource not matched/found 61 | cb(404,[]); 62 | } 63 | 64 | var postResource = function(ep,params,query,body,cb,uid){ 65 | var mediaTmp = body.media; 66 | delete body.media; 67 | 68 | //city attached pois 69 | if(params.cityid && ep.type==="collection"){ 70 | body.city = {"refurl": "cities/"+params.cityid, "_city":params.cityid}; 71 | 72 | //do we have an id already, so only update... 73 | var poiid = body._id; 74 | delete body._id; 75 | 76 | if(poiid) { 77 | Poi.findById(poiid) 78 | .exec(function(e,product){ 79 | if(!e){ 80 | var conditions = { _id: poiid }; 81 | // TODO(mla): temporary remove location update 82 | delete body.coords; 83 | var update = { $set: body }; 84 | var options = { upsert: false }; 85 | Poi.update(conditions, update, options, function(err, changesElements) { 86 | 87 | if(err && !changesElements) { 88 | console.log('error saving poi. ',err); 89 | cb(400,{}); 90 | } else { 91 | //save attached media 92 | if (mediaTmp && mediaTmp._media && mediaTmp._media.length) { 93 | var mediaObjects = _.map(mediaTmp._media, function(v) { var m = new Media(v); m.save(); return m; } ); 94 | Poi.update({_id: poiid},{$pushAll: { 'media._media': mediaObjects }, $inc: { 'media.mediaCount': mediaObjects.length } }, 95 | {upsert: true}, 96 | function(e,r){ 97 | if(!e && r) { 98 | Poi.findById(r._id) 99 | .populate("socatt media._media") 100 | .exec(function(e,product){ 101 | getPopulatedPoi(product, cb, uid); 102 | }); 103 | } else { 104 | console.log(e); 105 | cb(500,{}); 106 | } 107 | } 108 | ); 109 | } else { 110 | console.log("no media to save"); 111 | Poi.findById(poiid) 112 | .populate("socatt media._media") 113 | .exec(function(e,product){ 114 | getPopulatedPoi(product, cb, uid); 115 | }); 116 | } 117 | } 118 | 119 | }); 120 | 121 | } else { 122 | cb(404,{}); 123 | } 124 | } ); 125 | 126 | } else { 127 | //post of a new poi 128 | var sa = new SocialAttributes(); 129 | sa.save(); 130 | body.socatt = sa._id; 131 | 132 | //assign the owner 133 | body.user = { 134 | refurl: "", 135 | "_user":uid 136 | }; 137 | 138 | new Poi(body).save(function(e,r){ 139 | if(!e && r) { 140 | if (mediaTmp && mediaTmp._media && mediaTmp._media.length) { 141 | var mediaObjects = _.map(mediaTmp._media, function(v) { var m = new Media(v); m.save(); return m; } ); 142 | Poi.update({_id: r._id},{$pushAll: { 'media._media': mediaObjects }, $inc: { 'media.mediaCount': mediaObjects.length } }, 143 | {upsert: true}, 144 | function(e,updatedDocs){ 145 | if(!e && r) { 146 | Poi.findById(r._id) 147 | .populate("socatt media._media") 148 | .exec(function(e,product){ 149 | getPopulatedPoi(product, cb, uid); 150 | }); 151 | } else { 152 | cb(500,{}); 153 | } 154 | } 155 | ); 156 | } else { 157 | console.log("no media to save"); 158 | Poi.findById(r._id) 159 | .populate("socatt media._media") 160 | .exec(function(e,product){ 161 | getPopulatedPoi(product, cb, uid); 162 | }); 163 | } 164 | } else { 165 | cb(500,{}); 166 | } 167 | }); 168 | 169 | 170 | } 171 | return; 172 | } 173 | 174 | if(params.poiid && ep.type==="instance"){ 175 | 176 | //update existing poi 177 | if(ep.path.indexOf("checkin")==0 && 178 | ep.path.indexOf("comment")==0 && 179 | ep.path.indexOf("like")==0 && 180 | ep.path.indexOf("rating")==0 ){ 181 | delete body._id; 182 | delete body.media; 183 | var conditions = { _id: params.poiid }; 184 | var update = { $set: body}; 185 | var options = { upsert: false }; 186 | 187 | Poi.update(conditions, update, options, function(e,r){ 188 | if(!e && r) { 189 | cb(0,r); 190 | } else { 191 | cb(400,{}); 192 | } 193 | }); 194 | return; 195 | } 196 | 197 | 198 | //check input: uid, pid, cid, lat, lon 199 | var input = {} , lon = body.coords && parseFloat(body.coords[0]), lat = body.coords && parseFloat(body.coords[1]); 200 | if (typeof lon != "number" || typeof lat != "number" || !uid) { 201 | cb(400,{}); 202 | return; 203 | } 204 | input.coords = [lon,lat]; 205 | input.user = { 206 | refurl: "", 207 | "_user":uid 208 | }; 209 | input.ts = Date.now(); 210 | 211 | var poiFoundCB = function(poi){ 212 | 213 | if (!poi.socatt) { 214 | var sa = new SocialAttributes(); 215 | sa.save(function(err){ 216 | if (err) return console.log(err); 217 | console.log("added socatt to existing poi."); 218 | poi.socatt = sa._id; 219 | poi.save(function(err){ 220 | if (err) return console.log(err); 221 | poiFoundCB(poi); 222 | }); 223 | }); 224 | return; 225 | } 226 | 227 | if(ep.path.indexOf("checkin")>=0){ 228 | //input: - 229 | var ci = new Checkin(input); 230 | ci.save(); 231 | SocialAttributes.update({_id: poi.socatt},{$push: { 'checkins.checkin': ci}, $inc: { 'checkins.count': 1 } }, 232 | function(e,r){ 233 | if(!e && r) { 234 | Poi.findById(poi._id) 235 | .populate("media._media socatt") 236 | .exec(function(e,product){ 237 | getPopulatedPoi(product, cb, uid); 238 | }); 239 | } else { 240 | console.log(e); 241 | cb(500,{}); 242 | } 243 | } 244 | ); 245 | return; 246 | } 247 | if(ep.path.indexOf("comment")>=0){ 248 | //input: comment 249 | console.log("comment",body); 250 | if (typeof body.comment != "string") { 251 | cb(400,{}); 252 | return; 253 | } 254 | input.comment = body.comment; 255 | var co = new Comment(input); 256 | co.save(); 257 | SocialAttributes.update({_id: poi.socatt},{$push: { 'comments.comment': co}, $inc: { 'comments.count': 1 } }, 258 | function(e,r){ 259 | if(!e && r) { 260 | Poi.findById(poi._id) 261 | .populate("media._media socatt") 262 | .exec(function(e,product){ 263 | getPopulatedPoi(product, cb, uid); 264 | }); 265 | } else { 266 | cb(500,{}); 267 | } 268 | } 269 | ); 270 | return; 271 | } 272 | 273 | if(ep.path.indexOf("like")>=0){ 274 | //input: like 275 | console.log("like",body); 276 | if (typeof body.like != "boolean") { 277 | cb(400,{}); 278 | return; 279 | } 280 | input.like = body.like; 281 | var li = new Like(input); 282 | li.save(); 283 | SocialAttributes.update({_id: poi.socatt},{$push: { 'likes.like': li}, $inc: { 'likes.count': input.like?1:-1 } }, 284 | function(e,r){ 285 | if(!e && r) { 286 | Poi.findById(poi._id) 287 | .populate("media._media socatt") 288 | .exec(function(e,product){ 289 | getPopulatedPoi(product, cb, uid); 290 | }); 291 | } else { 292 | cb(500,{}); 293 | } 294 | } 295 | ); 296 | return; 297 | } 298 | if(ep.path.indexOf("rating")>=0){ 299 | //input: rating 300 | console.log("rating",body); 301 | if (typeof body.rating != "number" && body.rating >= 0 && body.rating <= 5) { 302 | cb(400,{}); 303 | return; 304 | } 305 | input.rating = body.rating; 306 | input._socatt = poi.socatt; 307 | var ra = new Rating(input); 308 | ra.save(); 309 | SocialAttributes.update({_id: poi.socatt},{$push: { 'ratings.rating': ra}, $inc: { 'ratings.count': 1 } }, 310 | function(e,r){ 311 | if(!e && r) { 312 | // TODO(mla): isnt there a better way to keep the avg value up to date? 313 | Rating.aggregate({ $match: {_socatt: poi.socatt._id || poi.socatt }}) 314 | .group({_id: '$_socatt', rating: { $avg: '$rating'}}) 315 | .exec(function(e,r){ 316 | if(!e && r.length && typeof r[0].rating === "number" ){ 317 | //store the average 318 | SocialAttributes.update({_id: poi.socatt},{$set: { 'ratings.average': r[0].rating} }, 319 | function(e,r){ 320 | if(!e && r){ 321 | Poi.findById(poi._id) 322 | .populate("media._media socatt") 323 | .exec(function(e,product){ 324 | getPopulatedPoi(product, cb, uid); 325 | }); 326 | } else { 327 | cb(500,{}); 328 | } 329 | }); 330 | } else { 331 | cb(500,{}); 332 | } 333 | }); 334 | 335 | } else { 336 | cb(500,{}); 337 | } 338 | } 339 | ); 340 | return; 341 | } 342 | } 343 | 344 | Poi.findById(params.poiid).populate("socatt").select({}).exec(function(e,r){ 345 | if(!e && r){ 346 | poiFoundCB(r); 347 | } else { 348 | cb(404,{}); 349 | } 350 | } ); 351 | 352 | return; 353 | } 354 | 355 | //resource not matched/found 356 | cb(404,{}); 357 | } 358 | 359 | var putResource = function(ep,params,query,body,cb){ 360 | cb(0,{resource:"poi-resource-put",ep:ep,params:params,body:body,query:query}); 361 | } 362 | 363 | var deleteResource = function(ep,params,query,body,cb){ 364 | cb(0,{resource:"poi-resource-delete",ep:ep,params:params,body:body,query:query}); 365 | } 366 | 367 | 368 | //DB 369 | var getPoiById = function(id,cb,uid,options){ 370 | Poi.findById(id) 371 | .populate('media._media socatt') 372 | .select(fieldsFilteredOut) 373 | .exec(function(e,product){ 374 | if(!e){ 375 | getPopulatedPoi(product, cb, uid, options); 376 | } else { 377 | cb(e,{}); 378 | } 379 | } ); 380 | } 381 | 382 | var getPopulatedPoi = function(product, cb, uid, options, cid){ 383 | options=options||{commentLimit:5,commentOffset:0}; 384 | var opts = [ 385 | {path:"socatt.likes.like", model:"Like", match:{"user._user":uid}, options:{sort: { ts: -1 }, limit:1}}, 386 | {path:"socatt.checkins.checkin", model:"Checkin", match:{"user._user":uid}, options:{sort: { ts: -1 }, limit:1}}, 387 | {path:"socatt.ratings.rating", model:"Rating", match:{"user._user":uid}, options:{sort: { ts: -1 }, limit:1}}, 388 | {path:"socatt.comments.comment", model:"Comment", options:{sort: { ts: -1 }, limit:options.commentLimit, skip: options.commentOffset}}, 389 | ]; 390 | if(options.expand==="socatt"){ 391 | opts = [ 392 | {path:"socatt.likes.like", model:"Like", options:{sort: { ts: -1 }}}, 393 | {path:"socatt.checkins.checkin", model:"Checkin", options:{sort: { ts: -1 }}}, 394 | {path:"socatt.ratings.rating", model:"Rating", options:{sort: { ts: -1 }}}, 395 | {path:"socatt.comments.comment", model:"Comment", options:{sort: { ts: -1 }}}, 396 | ]; 397 | } 398 | Poi.populate(product,opts,function(err,res){ 399 | if(err) return console.log(err) || cb(err); 400 | var opts = [ 401 | {path:"socatt.comments.comment.user._user", model:"User", select: "name _id attributes"}, 402 | {path:"socatt.checkins.checkin.user._user", model:"User", select: "name _id attributes"}, 403 | {path:"socatt.ratings.rating.user._user", model:"User", select: "name _id attributes"}, 404 | {path:"socatt.likes.like.user._user", model:"User", select: "name _id attributes"}, 405 | ]; 406 | if(options.expand==="socatt"){ 407 | opts = [ 408 | {path:"socatt.comments.comment.user._user", model:"User", select: "name _id email"}, 409 | {path:"socatt.checkins.checkin.user._user", model:"User", select: "name _id email"}, 410 | {path:"socatt.ratings.rating.user._user", model:"User", select: "name _id email"}, 411 | {path:"socatt.likes.like.user._user", model:"User", select: "name _id email"}, 412 | ]; 413 | } 414 | Poi.populate(product,opts,function(err,res){ 415 | if(err) console.log(err); 416 | Poi.count({"city._city": cid},function(err2,recordsTotal){ 417 | if(err2) recordsTotal=-1; 418 | Poi.count({"user._user": uid, "city._city": cid},function(err3,recordsOwned){ 419 | if(err3) recordsOwned=-1; 420 | cb(err,res,{recordsOwned:recordsOwned,recordsTotal:recordsTotal,recordsFiltered:recordsTotal}); 421 | }); 422 | }); 423 | }); 424 | }); 425 | } 426 | 427 | var getPoisByLocationAndCity = function(lon, lat, cityid, cb, options){ 428 | console.log("ll"); 429 | var q = { coords : { $near : [ lon , lat ] }, "city._city": cityid }; 430 | if(options.search){ 431 | q.name=new RegExp(options.search, "i"); 432 | } 433 | Poi.find(q) 434 | .or([{"public": true}, {"user._user": options.uid}]) 435 | .skip(options.offset) 436 | .limit(options.offset+options.limit) 437 | .populate('media._media socatt') 438 | .select(fieldsFilteredOut) 439 | .exec(function(e,product){ 440 | if(!e){ 441 | getPopulatedPoi(product, function(err,res,meta){ 442 | Poi.count({name: new RegExp(options.search, "i"), "city._city": cityid},function(err3,recordsFiltered){ 443 | if(err3) recordsFiltered=-1; 444 | meta.recordsFiltered=recordsFiltered; 445 | cb(err,res,meta); 446 | }); 447 | }, options.uid, null, cityid); 448 | } else { 449 | cb(e,{}); 450 | } 451 | } ); 452 | } 453 | 454 | var getPoisByBBAndCity = function(lon, lat, lon2, lat2, cityid, cb, options){ 455 | console.log("bb"); 456 | Poi.find({ coords : { $geoWithin : { $box: [ [ lon , lat ], [ lon2 , lat2 ] ] } }, "city._city": cityid }) 457 | .or([{"public": true}, {"user._user": options.uid}]) 458 | .skip(options.offset) 459 | .limit(options.offset+options.limit) 460 | .populate('media._media socatt') 461 | .select(fieldsFilteredOut) 462 | .exec(function(e,product){ 463 | if(!e){ 464 | getPopulatedPoi(product, cb, options.uid); 465 | } else { 466 | cb(e,{}); 467 | } 468 | } ); 469 | } 470 | 471 | // Poi functions 472 | var importPois = function(cityid,inFile, cb){ 473 | 474 | var input = require(inFile); 475 | 476 | var formatted = _.compact( 477 | _.map(input, function(v) { 478 | if(!v.name || !v.lon || !v.lat ) 479 | return; 480 | return { 481 | "name": v.name, 482 | "description": v.description?v.description:"", 483 | "contact": { 484 | "address": v.contact.address&&v.contact.address!="null"?v.contact.address:"", 485 | "phone": v.contact.phone&&v.contact.phone.length&&v.contact.phone[0]!="null"?v.contact.phone[0]:"", 486 | "link": v.contact.link&&v.contact.link!="null"?v.contact.link:"", 487 | "email": v.contact.email&&v.contact.email!="null"?v.contact.email:"" 488 | }, 489 | "openHours":[], 490 | "fee": [], 491 | "tags": [ 492 | "city" 493 | ], 494 | "coords": [parseFloat(v.lon), parseFloat(v.lat) ], 495 | "city": { 496 | "refurl": "cities/"+cityid, 497 | "_city":cityid 498 | }, 499 | "media": { 500 | "mediaCount": 0, 501 | "_media": [] 502 | } 503 | } 504 | }) 505 | ); 506 | var storePoi = function(v) { 507 | new Poi(v).save(function(err) { 508 | if(err) console.log('error saving #' + v.name); 509 | else console.log('saved #' + v.name); 510 | }) 511 | }; 512 | 513 | _.each(formatted, storePoi); 514 | cb(formatted || []); 515 | 516 | }; 517 | 518 | //check if we have to import some pois 519 | var args = {}; 520 | process.argv.forEach(function (val, index, array) { 521 | if(val.indexOf("=")!=-1){ 522 | var arg = val.split("="); 523 | args[arg[0]]=arg[1]; 524 | } 525 | }); 526 | console.log(args); 527 | if(args["cityid"] && args["infile"]){ 528 | console.log("hold on, grab a coffee. going to import pois..."); 529 | importPois(args["cityid"],args["infile"],function(importResult){ 530 | console.log("imported/ing pois."); 531 | }); 532 | } 533 | 534 | 535 | 536 | module.exports = { 537 | "GET" : getResource, 538 | "POST" : postResource, 539 | "PUT" : putResource, 540 | "DELETE" : deleteResource 541 | }; 542 | -------------------------------------------------------------------------------- /lib/resources/User.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | var uuid = require('node-uuid'); 19 | 20 | var User = require('../models.js').model.User; 21 | var constants = require('../../constants.js'); 22 | 23 | var getResource = function(ep,params,query,body,cb,uid){ 24 | 25 | //get user attributes 26 | if (uid && query["p"]) { 27 | User.findById(uid).exec(function(e,r){ 28 | if(e || !r) { 29 | cb(404,{}); 30 | } else { 31 | cb(0,{"attributes":((r.attributes && r.attributes[query["p"]])?r.attributes[query["p"]]:{})}); 32 | } 33 | }); 34 | return; 35 | } 36 | 37 | //user login 38 | var a = query.a || '', b = query.b || ''; 39 | 40 | //logoff 41 | if(!a && !b && query['access_token']){ 42 | 43 | User.find({"access.token": query['access_token'] }).limit(1).exec(function(e,r){ 44 | if(e || !r.length) { 45 | cb(401,{}); 46 | } else { 47 | for (var i = r[0].access.length - 1; i >= 0; i--) { 48 | if (r[0].access[i].lease != -1 && r[0].access[i].token === query['access_token']) { 49 | r[0].access.remove(r[0].access[i]._id); 50 | r[0].save(); 51 | cb(0,{"msg":"logoff"}); 52 | break; 53 | } 54 | }; 55 | } 56 | }); 57 | 58 | } else { 59 | 60 | //check existance 61 | User.find({emailsha1:a}).limit(1).exec(function(e,users){ 62 | if(e || !users.length) { 63 | User.find({namesha1:a}).limit(1).exec(function(e,users){ 64 | if(e || !users.length) { 65 | cb(404,{}); 66 | } else { 67 | loginUser(users[0],b,cb); 68 | } 69 | }); 70 | } else { 71 | loginUser(users[0],b,cb); 72 | } 73 | }); 74 | } 75 | } 76 | 77 | var loginUser = function(user, b, cb){ 78 | var authN = false, authZ = "", toBePurge = []; 79 | for (var i = user.access.length - 1; i >= 0; i--) { 80 | if (user.access[i].lease === -1 && user.access[i].token === b) { 81 | authN = true; 82 | } 83 | 84 | if (user.access[i].lease != -1) { 85 | if(Date.now()-constants.SESSION_LEASE>user.access[i].lease){ 86 | toBePurge.push(user.access[i]._id); 87 | } 88 | } 89 | }; 90 | 91 | //clear old tokens 92 | for (var i = toBePurge.length - 1; i >= 0; i--) { 93 | user.access.remove(toBePurge[i]); 94 | } 95 | 96 | if(authN){ 97 | authZ = uuid.v1(); 98 | var ak = { 99 | "token": authZ, 100 | "lease": Date.now() 101 | }; 102 | user.access.push(ak); 103 | user.save(); 104 | //update user 105 | cb(0,{"access_token": authZ, "uid": user._id}); 106 | } else { 107 | user.save(); 108 | cb(401,{}); 109 | } 110 | } 111 | 112 | var postResource = function(ep,params,query,body,cb,uid){ 113 | 114 | //enrich user with attributes 115 | if (uid && body["p"] && body["r"] && typeof body["r"] === "object") { 116 | User.findById(uid).exec(function(e,r){ 117 | if(e || !r) { 118 | cb(404,{}); 119 | } else { 120 | if(!r.attributes){ 121 | r.attributes = {}; 122 | } 123 | r.set("attributes."+body["p"], body["r"]); 124 | r.save(); 125 | cb(200,{}); 126 | } 127 | }); 128 | return; 129 | } 130 | 131 | 132 | //user registration 133 | var a = body.a, b = body.b, n = body.n; 134 | 135 | if(!a && !b && !n) { 136 | //request invalid 137 | cb(400,{}); 138 | return; 139 | } 140 | 141 | //deferred registration 142 | if(query['access_token']){ 143 | 144 | User.find({"access.token": query['access_token'] }).limit(1).exec(function(e,r){ 145 | if(e || !r.length) { 146 | cb(401,{}); 147 | } else { 148 | createUser(a, b, n, r[0]._id, cb); 149 | } 150 | }); 151 | } else { 152 | //self registration 153 | createUser(a, b, n, null, cb); 154 | } 155 | } 156 | 157 | var createUser = function(a, b, n, p, cb){ 158 | 159 | User.find({email:a}).limit(1).exec(function(e,r){ 160 | if(r.length) { 161 | 162 | // TODO(mla): pw forgotten functionality 163 | 164 | cb(409,{}); 165 | } else { 166 | 167 | // TODO(mla): send mail with verification link, save then user in db 168 | var u = { 169 | "name": n, 170 | "namesha1": SHA1(n), 171 | "email": a, 172 | "emailsha1": SHA1(a), 173 | "access": [ {"token": b, "lease":-1} ] 174 | }; 175 | if(p) { 176 | u.parents = p; 177 | console.log("creating deferred user...parent:",p); 178 | } 179 | 180 | new User(u).save(function(err) { 181 | if(err) console.log('error saving #' + u.name);// TODO(mla): send error code 182 | else console.log("saved #" + u.name); 183 | cb(0,{name:n}); 184 | }); 185 | } 186 | }); 187 | } 188 | 189 | var putResource = function(ep,params,query,body,cb){ 190 | cb(0,{resource:"user-resource-put",ep:ep,params:params,body:body,query:query}); 191 | } 192 | 193 | var deleteResource = function(ep,params,query,body,cb){ 194 | cb(0,{resource:"user-resource-delete",ep:ep,params:params,body:body,query:query}); 195 | } 196 | 197 | var getUserid = function(auth,cb){ 198 | User.find({"access.token": auth }).limit(1).exec(function(e,r){ 199 | if(e || !r.length) { 200 | cb(false); 201 | } else { 202 | var authFound=false, toBePurge = []; 203 | for (var i = r[0].access.length - 1; i >= 0; i--) { 204 | //ok and refresh lease? 205 | if (r[0].access[i].lease != -1 && r[0].access[i].token === auth) { 206 | authFound = true; 207 | if(Date.now()-constants.SESSION_LEASE>>(32-b))}function P(a,b,c){return a^b^c}function A(a,b){var c=(b&0xFFFF)+(a&0xFFFF),d=(b>>>16)+(a>>>16)+(c>>>16);return((d&0xFFFF)<<16)|(c&0xFFFF)}var B="0123456789abcdef";return(function(a){var c=[],d=a.length*4,e;for(var i=0;i>2]>>((3-(i%4))*8);c.push(B.charAt((e>>4)&0xF)+B.charAt(e&0xF))}return c.join('')}((function(a,b){var c,d,e,f,g,h=a.length,v=0x67452301,w=0xefcdab89,x=0x98badcfe,y=0x10325476,z=0xc3d2e1f0,M=[];U(M,0x5a827999,20);U(M,0x6ed9eba1,20);U(M,0x8f1bbcdc,20);U(M,0xca62c1d6,20);a[b>>5]|=0x80<<(24-(b%32));a[(((b+65)>>9)<<4)+15]=b;for(var i=0;i>>16)+(a>>>16)+(b>>>16)+(c>>>16)+(d>>>16)+(f>>>16);return((g&0xFFFF)<<16)|(f&0xFFFF)})(j<20?(function(t,a,b){return(t&a)^(~t&b)}(d,e,f)):j<40?P(d,e,f):j<60?(function(t,a,b){return(t&a)^(t&b)^(a&b)}(d,e,f)):P(d,e,f),g,M[j],O[j],L(c,5));g=f;f=e;e=L(d,30);d=c;c=k}v=A(v,c);w=A(w,d);x=A(x,e);y=A(y,f);z=A(z,g)}return[v,w,x,y,z]}((function(t){var a=[],b=255,c=t.length*8;for(var i=0;i>5]|=(t.charCodeAt(i/8)&b)<<(24-(i%32))}return a}(s)).slice(),s.length*8))))} 234 | -------------------------------------------------------------------------------- /lib/resources/opendata/import.opendata.brussels.be.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | var _ = require("underscore"); 19 | var http = require("http"); 20 | var argv = require('minimist')(process.argv.slice(2)); 21 | 22 | var Model = require('../../models.js').model; 23 | 24 | var APIURL = "http://opendata.brussels.be/api/records/1.0/search?"; 25 | var DATASETS = [ 26 | { ds: "cultural-places", nameField: "cultural_place" }, 27 | // TODO(mla): check why the API does not accept multiple 28 | // dataset records search. 29 | //{ ds: "bxl_urinals", nameField: "urinoir" } 30 | ]; 31 | var execcmd = true; 32 | 33 | if(execcmd && (argv.id || argv.i)) { 34 | var dataSets = ""; 35 | var dataSetsMap = {}; 36 | _.each(DATASETS,function(d){dataSets+="&dataset="+(d.ds); dataSetsMap[d.ds]=d; }); 37 | http.get(APIURL+"rows=10000"+dataSets, function(res) { 38 | var result = '', length=0; 39 | 40 | res.on('data', function(chunk) { 41 | length += chunk.length; 42 | process.stdout.write("Downloading " + length + " bytes\r"); 43 | result += chunk; 44 | }); 45 | 46 | res.on('end', function() { 47 | var datares = JSON.parse(result); 48 | console.log("\nend.",datares); 49 | 50 | _.each(datares.records,function(r){ 51 | var poi = {}; 52 | poi.coords = r.geometry.coordinates; 53 | poi.source = APIURL+";"+r.datasetid+";"+r.recordid; 54 | poi.name = r.fields[dataSetsMap[r.datasetid]["nameField"]]; 55 | poi.city = {"refurl": "cities/"+(argv.id || argv.i), "_city":(argv.id || argv.i)}; 56 | new Model.Poi(poi).save(function(err) { 57 | if(err) console.log('error saving #' + poi.name); 58 | else process.stdout.write("saved #" + poi.name + " \r"); 59 | }) 60 | }); 61 | 62 | setTimeout(function(){ 63 | process.exit(0); 64 | },10000); 65 | }); 66 | }).on('error', function(e) { 67 | console.log("Open data API error: ",e); 68 | process.exit(1); 69 | }); 70 | execcmd = false; 71 | } 72 | 73 | if(execcmd && (argv.city || argv.c)) { 74 | Model.City.find({displayName:new RegExp((argv.city || argv.c), 'i')}).exec(function(e,r){ 75 | if(e || !r.length){ 76 | console.log("No city with this name is available in the db yet."); 77 | process.exit(1); 78 | } else { 79 | _.each(r, function(c){console.log(c.displayName+", ID: ", c._id)}); 80 | } 81 | process.exit(0); 82 | }); 83 | execcmd = false; 84 | } 85 | 86 | if (execcmd) { 87 | var script = __filename.split('/'); 88 | script = (script.length)?script[script.length-1]:script; 89 | console.log("\nImport script using opendata API:"); 90 | console.log(" "+APIURL); 91 | console.log("\nUsage:\n",script, "(parameters)"); 92 | console.log("Parameters:") 93 | console.log(" -c \"CityName\" || --city=\"CityName\" "); 94 | console.log(" -i \"CityID\" || --id=\"CityID\" "); 95 | process.exit(1); 96 | } 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /lib/rest.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | var fs = require('fs'); 19 | var path = require('path'); 20 | var https = require('https'); 21 | var express = require('express'); 22 | var bodyParser = require('body-parser'); 23 | var app = express(); 24 | var constants = require('../constants'); 25 | var endpoints = require(constants.FILE_ENDPOINTS).endpoints; 26 | var resources = {}; 27 | 28 | var errors = { 29 | 200: constants.ERROR_OK, 30 | 400: constants.ERROR_REQUEST_INVALID, 31 | 401: constants.ERROR_REQUEST_UNAUTHORIZED, 32 | 404: constants.ERROR_NOT_FOUND, 33 | 405: constants.ERROR_METHOD_NOT_ALLOWED, 34 | 409: constants.ERROR_CONFLICT, 35 | 415: constants.ERROR_WRONG_MIMETYPE, 36 | 500: constants.ERROR_INTERNAL 37 | }; 38 | 39 | var makeEndpointCB = function(ep){ 40 | return function(req,res){ 41 | var cb = function(uid){ 42 | //uid == false-> no auth, otherwise known user/anonymous access 43 | if(!uid) return; 44 | process.nextTick(function(){ 45 | resources[ep.resource][req.method](ep,req.params,req.query,req.body,function(err, result, meta){ 46 | if(err){ 47 | sendError(req,res,err); 48 | } else { 49 | if(!res.issent) { 50 | res.issent = true; 51 | if(meta&&meta.recordsTotal){ 52 | res.setHeader("x-ocdb-recordsTotal", meta.recordsTotal); 53 | } 54 | if(meta&&meta.recordsFiltered){ 55 | res.setHeader("x-ocdb-recordsFiltered", meta.recordsFiltered); 56 | } 57 | if(meta&&meta.recordsOwned){ 58 | res.setHeader("x-ocdb-recordsOwned", meta.recordsOwned); 59 | } 60 | res.send(result); 61 | } 62 | } 63 | },uid); 64 | }); 65 | } 66 | checkRequest(req,res,ep,cb); 67 | } 68 | } 69 | 70 | var checkRequest = function(req,res,ep,cb){ 71 | if (!req.headers['accept'] || req.headers['accept'].toLowerCase()!==constants.REQUIRED_MIMETYPE) return cb( sendError(req,res,400) ); 72 | if (!resources[ep.resource] || !resources[ep.resource][req.method]) return cb( sendError(req,res,405) ); 73 | if (req.method==="POST" || req.method==="PUT"){ 74 | if(!req.headers['content-type'] || req.headers['content-type'].indexOf(constants.REQUIRED_MIMETYPE)===-1) return cb( sendError(req,res,400) ); 75 | } 76 | 77 | var regOrLogin = false, auth = (req.headers['authorization'] && req.headers['authorization'].split(" ")[0]==="token" && req.headers['authorization'].split(" ")[1]) || req.query['access_token']; 78 | req.query['access_token'] = auth; 79 | 80 | //allow users to login 81 | if (req.method==="GET" && ep.resource==="User" && req.query && req.query['a'] && req.query['b']) { 82 | regOrLogin = true; 83 | } 84 | 85 | //allow users to register 86 | if (req.method==="POST" && ep.resource==="User" && req.body && req.body.a && req.body.b && req.body.n) { 87 | regOrLogin = true; 88 | } 89 | 90 | //check if immediate not auth should be send 91 | if(!auth && !regOrLogin) return cb( sendError(req,res,401) ); 92 | 93 | if(auth){ 94 | resources["User"]["AUTH"](auth,function(uid){ 95 | if(!uid) sendError(req,res,401); 96 | cb(uid); 97 | }); 98 | } else { 99 | if(regOrLogin) cb( true ); 100 | } 101 | } 102 | 103 | var sendError = function(req,res,code){ 104 | if (res.issent) return; 105 | res.set('Content-Type', constants.REQUIRED_MIMETYPE); 106 | switch(code){ 107 | case 200: 108 | case 401: 109 | case 400: 110 | case 404: 111 | case 405: 112 | case 409: 113 | case 415: 114 | res.status(code); 115 | res.send({"errorType": errors[code]}); 116 | break; 117 | default: 118 | res.status(500); 119 | res.send({"errorType": errors[code]}); 120 | break; 121 | } 122 | res.issent = true; 123 | return false; 124 | } 125 | 126 | var initializeRestInterface = function(){ 127 | 128 | app.use(function(req, res, next) { 129 | res.header("Access-Control-Allow-Origin", "*"); 130 | res.header("Access-Control-Allow-Headers", "X-Requested-With,Authorization,Content-type"); 131 | res.header("Access-Control-Allow-Methods", "GET,POST,DELETE"); 132 | // intercept OPTIONS method 133 | if ('OPTIONS' == req.method) { 134 | res.status(200).end(); 135 | } 136 | else { 137 | next(); 138 | } 139 | }); 140 | 141 | app.use(bodyParser()); 142 | //frontend route 143 | console.log(path.join(__dirname, '../web_root')); 144 | app.use(constants.BASEURL_PATH+constants.API_VERSION+"/frontend", express.static(path.join(__dirname, '../web_root'))); 145 | //root route 146 | app.use(constants.BASEURL_PATH+constants.API_VERSION+"/", express.static(path.join(__dirname, '../web_root/root.html'))); 147 | 148 | 149 | 150 | //register HTTP actions for each resource 151 | console.log("Registering routes..."); 152 | for(var epx=0; epx See how to create certificates at: http://nodejs.org/api/tls.html"); 171 | process.exit(1); 172 | } 173 | var https_options = { 174 | key: key, 175 | cert: cert 176 | }; 177 | https.createServer(https_options, app).listen(constants.SERVER_PORT); 178 | 179 | } 180 | 181 | initializeRestInterface(); 182 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | * Copyright 2014 Fraunhofer FOKUS 16 | *******************************************************************************/ 17 | 18 | require('./lib/checks.js').checkForMandatoryModules(); 19 | require('./lib/rest.js'); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ocdb", 3 | "description": "Open City Database", 4 | "version": "0.1.0", 5 | "author": "Martin Lasak ", 6 | "dependencies": { 7 | "express": "4.x.x", 8 | "body-parser" : "1.0.0", 9 | "mongoose": "4.x.x", 10 | "underscore": "1.6.x", 11 | "node-uuid": "1.4.x", 12 | "minimist": "1.1.x" 13 | }, 14 | "devDependencies": { 15 | }, 16 | "keywords": [ 17 | "open", 18 | "city", 19 | "database", 20 | "web", 21 | "rest", 22 | "api" 23 | ], 24 | "repository": "git://github.com/fraunhoferfokus/ocdb", 25 | "scripts": { 26 | }, 27 | "engines": { 28 | "node": ">= 0.8.0" 29 | }, 30 | "main": "./main.js", 31 | "license": "http://www.apache.org/licenses/LICENSE-2.0" 32 | } 33 | -------------------------------------------------------------------------------- /playground.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": { 3 | "path": "web_root/playground", 4 | "file": "index.html" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /startdb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | BASEDIR=$(dirname $0) 4 | echo "DB PATH: $BASEDIR" 5 | $BASEDIR/db/mongodb/bin/mongod --dbpath $BASEDIR/db --logpath $BASEDIR/db/ocdb.log & 6 | echo "DB startup done. Everything fine so far, if no errors appeared. You might want to check ./db/ocdb.log" 7 | -------------------------------------------------------------------------------- /stopdb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | BASEDIR=$(dirname $0) 4 | echo "shutting down..." 5 | $BASEDIR/db/mongodb/bin/mongo --eval "db.getSiblingDB('min').shutdownServer()" 6 | -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | Tests 2 | ===== 3 | 4 | -------------------------------------------------------------------------------- /tests/docker_smoketest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | HOST=$1 4 | PORT=$2 5 | 6 | [ "$HOST" ] || HOST="localhost" 7 | [ "$PORT" ] || PORT="443" 8 | 9 | echo "Using host: https://$HOST:$PORT" 10 | 11 | echo "Registering user...(user may already be registered)" 12 | curl -s -k -X POST "https://$HOST:$PORT/v1/users" -H "Accept: application/json" -H "Content-Type: application/json" -d "{\"n\":\"user\",\"a\":\"user@domain.com\",\"b\":\"441d05da1f570f55e0c8172787cdc1302ecad5db\"}" 13 | ec=$? 14 | if [ $ec -ne 0 ]; then 15 | echo "Failed with cURL return code: $ec"; 16 | exit 1; 17 | fi 18 | 19 | echo "Log in..." 20 | at=`curl -s -k -X GET "https://$HOST:$PORT/v1/users?a=12dea96fec20593566ab75692c9949596833adc9&b=441d05da1f570f55e0c8172787cdc1302ecad5db" -H "Accept: application/json" | cut -f 4 -d \" -` 21 | ec=$? 22 | if [ $ec -ne 0 ]; then 23 | echo "Failed with cURL return code: $ec"; 24 | exit 1; 25 | fi 26 | echo "Got this access token: "$at 27 | 28 | echo "Sample request (Get 10 cities around given location)..." 29 | curl -s -k -X GET "https://$HOST:$PORT/v1/cities?lat=52.5258885&lon=13.3142135&offset=0&limit=10" -H "Accept: application/json" -H "Authorization: token "$at 30 | ec=$? 31 | if [ $ec -ne 0 ]; then 32 | echo "Failed with cURL return code: $ec"; 33 | exit 1; 34 | fi 35 | 36 | echo "\nOCDB: Smoke test ran successful." 37 | -------------------------------------------------------------------------------- /web_root/api/swagger.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | title: Open City Database API 4 | description: Quick and easy deployable cities related data service with read/write access to user generated content, points of interest and social interactions (likes, comments, ratings, check-ins). Notice:Beware the authentication requirements for the OCDB API. A appropriately configured API console is available at http://fraunhoferfokus.github.io/OCDB/apiconsole/index.html 5 | version: "1.0.2" 6 | license: 7 | name: Apache 2.0 8 | # array of all schemes that the OCDB API supports 9 | schemes: 10 | - https 11 | # will be prefixed to all paths 12 | basePath: /v1 13 | produces: 14 | - application/json 15 | consumes: 16 | - application/json 17 | paths: 18 | /users: 19 | get: 20 | summary: Login/logout a user 21 | description: 22 | To access any OCDB instance a authorization token needs to be created. For this purpose the login request must be performed 23 | parameters: 24 | - name: a 25 | in: query 26 | description: (SHA1) hashed user name or email of the user to log in. For a log out just leave this parameter empty 27 | required: true 28 | type: string 29 | format: string 30 | - name: b 31 | in: query 32 | description: (SHA1) hashed password of the user to log in. For a log out just leave this parameter empty 33 | required: true 34 | type: string 35 | format: string 36 | tags: 37 | - User 38 | responses: 39 | 200: 40 | description: Access object 41 | schema: 42 | $ref: '#/definitions/Access' 43 | 400: 44 | description: Bad request 45 | schema: 46 | $ref: '#/definitions/Error' 47 | 401: 48 | description: Unauthorized request 49 | schema: 50 | $ref: '#/definitions/Error' 51 | 404: 52 | description: User not found 53 | schema: 54 | $ref: '#/definitions/Error' 55 | 500: 56 | description: Internal error 57 | schema: 58 | $ref: '#/definitions/Error' 59 | post: 60 | summary: Register a user 61 | description: 62 | To access any OCDB instance a authorization token needs to be created. For this purpose the login request must be performed 63 | parameters: 64 | - name: user 65 | in: body 66 | required: true 67 | schema: 68 | $ref: '#/definitions/AccessRequest' 69 | tags: 70 | - User 71 | responses: 72 | 200: 73 | description: Registration confirmation 74 | schema: 75 | $ref: '#/definitions/AccessRequestResponse' 76 | 400: 77 | description: Bad request 78 | schema: 79 | $ref: '#/definitions/Error' 80 | 401: 81 | description: Unauthorized request 82 | schema: 83 | $ref: '#/definitions/Error' 84 | 409: 85 | description: User exists already 86 | schema: 87 | $ref: '#/definitions/Error' 88 | 500: 89 | description: Internal error 90 | schema: 91 | $ref: '#/definitions/Error' 92 | /cities: 93 | get: 94 | summary: Get a list of cities 95 | description: 96 | A list of cities based on a location and an optional name can be requested. Location and name will be discarded if fulltext search parameter is used. 97 | parameters: 98 | - name: lat 99 | in: query 100 | description: Latitude of the center point to start the query from 101 | required: true 102 | type: string 103 | format: string 104 | - name: lon 105 | in: query 106 | description: Longitude of the center point to start the query from 107 | required: true 108 | type: string 109 | format: string 110 | - name: name 111 | in: query 112 | description: Query explicitely by city name (can be combined with lat/lon) 113 | type: string 114 | format: string 115 | - name: search 116 | in: query 117 | description: Fulltext search to be applied (can NOT be combined with lat/lon) 118 | type: string 119 | format: string 120 | - name: offset 121 | in: query 122 | description: The offset of the first index in the result array 123 | type: string 124 | format: string 125 | - name: limit 126 | in: query 127 | description: Limit the returned item count to this value 128 | type: string 129 | format: string 130 | tags: 131 | - City 132 | responses: 133 | 200: 134 | description: An array of cities. May be an empty Array. 135 | schema: 136 | type: array 137 | items: 138 | $ref: '#/definitions/City' 139 | 400: 140 | description: Bad request 141 | schema: 142 | $ref: '#/definitions/Error' 143 | 401: 144 | description: Unauthorized request 145 | schema: 146 | $ref: '#/definitions/Error' 147 | 500: 148 | description: Internal error 149 | schema: 150 | $ref: '#/definitions/Error' 151 | /cities/{cityid}: 152 | get: 153 | summary: Get a single city record 154 | description: 155 | A single city record can be requested by its id 156 | parameters: 157 | - name: cityid 158 | in: path 159 | description: The id of the city 160 | required: true 161 | type: string 162 | format: string 163 | tags: 164 | - City 165 | responses: 166 | 200: 167 | description: A single city record 168 | schema: 169 | $ref: '#/definitions/City' 170 | 400: 171 | description: Bad request 172 | schema: 173 | $ref: '#/definitions/Error' 174 | 401: 175 | description: Unauthorized request 176 | schema: 177 | $ref: '#/definitions/Error' 178 | 404: 179 | description: City not found 180 | schema: 181 | $ref: '#/definitions/Error' 182 | 500: 183 | description: Internal error 184 | schema: 185 | $ref: '#/definitions/Error' 186 | /cities/{cityid}/pois: 187 | get: 188 | summary: Get a list of pois for a selected city 189 | description: 190 | A list of pois based on a location and an optional search query can be requested. 191 | parameters: 192 | - name: cityid 193 | in: path 194 | description: The id of the city 195 | required: true 196 | type: string 197 | format: string 198 | - name: lat 199 | in: query 200 | description: Latitude of the center point to start the query from 201 | required: true 202 | type: string 203 | format: string 204 | - name: lon 205 | in: query 206 | description: Longitude of the center point to start the query from 207 | required: true 208 | type: string 209 | format: string 210 | - name: lat2 211 | in: query 212 | description: Secondary Latitude for bounding box search 213 | type: string 214 | format: string 215 | - name: lon2 216 | in: query 217 | description: Secondary Longitude for bounding box search 218 | type: string 219 | format: string 220 | - name: search 221 | in: query 222 | description: Fulltext search to be applied 223 | type: string 224 | format: string 225 | - name: offset 226 | in: query 227 | description: The offset of the first index in the result array 228 | type: string 229 | format: string 230 | - name: limit 231 | in: query 232 | description: Limit the returned item count to this value 233 | type: string 234 | format: string 235 | tags: 236 | - Poi 237 | responses: 238 | 200: 239 | description: An array of pois. May be an empty Array. 240 | schema: 241 | type: array 242 | items: 243 | $ref: '#/definitions/Poi' 244 | 400: 245 | description: Bad request 246 | schema: 247 | $ref: '#/definitions/Error' 248 | 401: 249 | description: Unauthorized request 250 | schema: 251 | $ref: '#/definitions/Error' 252 | 500: 253 | description: Internal error 254 | schema: 255 | $ref: '#/definitions/Error' 256 | post: 257 | summary: Create a new poi 258 | description: 259 | To create a new poi record a document with relevant information needs to be posted 260 | parameters: 261 | - name: cityid 262 | in: path 263 | description: The id of the city 264 | required: true 265 | type: string 266 | format: string 267 | - name: poi 268 | in: body 269 | required: true 270 | schema: 271 | $ref: '#/definitions/Poi' 272 | tags: 273 | - Poi 274 | responses: 275 | 200: 276 | description: Registration confirmation 277 | schema: 278 | $ref: '#/definitions/Poi' 279 | 400: 280 | description: Bad request 281 | schema: 282 | $ref: '#/definitions/Error' 283 | 401: 284 | description: Unauthorized request 285 | schema: 286 | $ref: '#/definitions/Error' 287 | 409: 288 | description: User exists already 289 | schema: 290 | $ref: '#/definitions/Error' 291 | 500: 292 | description: Internal error 293 | schema: 294 | $ref: '#/definitions/Error' 295 | /pois: 296 | get: 297 | summary: Get a list of pois for a selected city 298 | description: 299 | A list of pois based on a location and an optional search query can be requested. 300 | parameters: 301 | - name: cityid 302 | in: query 303 | description: The id of the city 304 | required: true 305 | type: string 306 | format: string 307 | - name: lat 308 | in: query 309 | description: Latitude of the center point to start the query from 310 | required: true 311 | type: string 312 | format: string 313 | - name: lon 314 | in: query 315 | description: Longitude of the center point to start the query from 316 | required: true 317 | type: string 318 | format: string 319 | - name: lat2 320 | in: query 321 | description: Secondary Latitude for bounding box search 322 | type: string 323 | format: string 324 | - name: lon2 325 | in: query 326 | description: Secondary Longitude for bounding box search 327 | type: string 328 | format: string 329 | - name: search 330 | in: query 331 | description: Fulltext search to be applied 332 | type: string 333 | format: string 334 | - name: offset 335 | in: query 336 | description: The offset of the first index in the result array 337 | type: string 338 | format: string 339 | - name: limit 340 | in: query 341 | description: Limit the returned item count to this value 342 | type: string 343 | format: string 344 | tags: 345 | - Poi 346 | responses: 347 | 200: 348 | description: An array of pois. May be an empty Array. 349 | schema: 350 | type: array 351 | items: 352 | $ref: '#/definitions/Poi' 353 | 400: 354 | description: Bad request 355 | schema: 356 | $ref: '#/definitions/Error' 357 | 401: 358 | description: Unauthorized request 359 | schema: 360 | $ref: '#/definitions/Error' 361 | 500: 362 | description: Internal error 363 | schema: 364 | $ref: '#/definitions/Error' 365 | post: 366 | summary: Create a new poi 367 | description: 368 | To create a new poi record a document with relevant information needs to be posted 369 | parameters: 370 | - name: cityid 371 | in: query 372 | description: The id of the city 373 | required: true 374 | type: string 375 | format: string 376 | - name: poi 377 | in: body 378 | required: true 379 | schema: 380 | $ref: '#/definitions/Poi' 381 | tags: 382 | - Poi 383 | responses: 384 | 200: 385 | description: Registration confirmation 386 | schema: 387 | $ref: '#/definitions/Poi' 388 | 400: 389 | description: Bad request 390 | schema: 391 | $ref: '#/definitions/Error' 392 | 401: 393 | description: Unauthorized request 394 | schema: 395 | $ref: '#/definitions/Error' 396 | 409: 397 | description: User exists already 398 | schema: 399 | $ref: '#/definitions/Error' 400 | 500: 401 | description: Internal error 402 | schema: 403 | $ref: '#/definitions/Error' 404 | /pois/{poiid}: 405 | get: 406 | summary: Get a single specific poi 407 | description: 408 | A single poi record can be requested by its id 409 | parameters: 410 | - name: poiid 411 | in: path 412 | description: The id of the poi 413 | required: true 414 | type: string 415 | format: string 416 | - name: expand 417 | in: query 418 | description: Name of the poi attribute to fully expand 419 | type: string 420 | format: string 421 | tags: 422 | - Poi 423 | responses: 424 | 200: 425 | description: The poi record 426 | schema: 427 | $ref: '#/definitions/Poi' 428 | 400: 429 | description: Bad request 430 | schema: 431 | $ref: '#/definitions/Error' 432 | 401: 433 | description: Unauthorized request 434 | schema: 435 | $ref: '#/definitions/Error' 436 | 404: 437 | description: Poi not found 438 | schema: 439 | $ref: '#/definitions/Error' 440 | 500: 441 | description: Internal error 442 | schema: 443 | $ref: '#/definitions/Error' 444 | definitions: 445 | Poi: 446 | properties: 447 | name: 448 | type: string 449 | description: 450 | type: string 451 | contact: 452 | $ref: '#/definitions/Contact' 453 | openHours: 454 | type: array 455 | items: 456 | $ref: '#/definitions/OpenHours' 457 | fee: 458 | type: array 459 | items: 460 | $ref: '#/definitions/Fee' 461 | tags: 462 | type: array 463 | items: 464 | type: string 465 | coords: 466 | type: array 467 | items: 468 | type: integer 469 | city: 470 | $ref: '#/definitions/City' 471 | media: 472 | $ref: '#/definitions/Medias' 473 | public: 474 | type: boolean 475 | user: 476 | $ref: '#/definitions/User' 477 | socatt: 478 | $ref: '#/definitions/SocialAttributes' 479 | source: 480 | type: string 481 | Contact: 482 | properties: 483 | address: 484 | type: string 485 | phone: 486 | type: string 487 | link: 488 | type: string 489 | email: 490 | type: string 491 | Fee: 492 | properties: 493 | currency: 494 | type: string 495 | value: 496 | type: number 497 | hint: 498 | type: string 499 | OpenHours: 500 | properties: 501 | frondow: 502 | type: integer 503 | fromtime: 504 | type: integer 505 | todow: 506 | type: integer 507 | totime: 508 | type: integer 509 | startdate: 510 | type: integer 511 | occurance: 512 | type: integer 513 | every: 514 | type: integer 515 | Medias: 516 | properties: 517 | refurl: 518 | type: string 519 | mediaCount: 520 | type: integer 521 | _media: 522 | type: array 523 | items: 524 | $ref: '#/definitions/Media' 525 | Media: 526 | properties: 527 | title: 528 | type: string 529 | url: 530 | type: array 531 | items: 532 | type: string 533 | type: 534 | type: string 535 | user: 536 | $ref: '#/definitions/User' 537 | timestamp: 538 | type: string 539 | featured: 540 | type: boolean 541 | poi: 542 | $ref: '#/definitions/Poi' 543 | attributes: 544 | type: object 545 | coords: 546 | type: array 547 | items: 548 | type: integer 549 | socatt: 550 | $ref: '#/definitions/SocialAttributes' 551 | City: 552 | properties: 553 | locode: 554 | type: string 555 | displayName: 556 | type: string 557 | description: 558 | type: string 559 | locale: 560 | type: string 561 | coords: 562 | type: array 563 | items: 564 | type: integer 565 | socatt: 566 | $ref: '#/definitions/SocialAttributes' 567 | SocialAttributes: 568 | properties: 569 | likes: 570 | $ref: '#/definitions/Likes' 571 | checkins : 572 | $ref: '#/definitions/Checkins' 573 | ratings: 574 | $ref: '#/definitions/Ratings' 575 | comments: 576 | $ref: '#/definitions/Comments' 577 | Likes: 578 | properties: 579 | count: 580 | type: integer 581 | like: 582 | type: array 583 | items: 584 | $ref: '#/definitions/Like' 585 | Like: 586 | properties: 587 | user._user: 588 | $ref: '#/definitions/User' 589 | like: 590 | type: boolean 591 | ts: 592 | type: integer 593 | coords: 594 | type: array 595 | items: 596 | type: integer 597 | city._city: 598 | $ref: '#/definitions/City' 599 | Checkins: 600 | properties: 601 | count: 602 | type: integer 603 | checkin: 604 | type: array 605 | items: 606 | $ref: '#/definitions/Checkin' 607 | Checkin: 608 | properties: 609 | user._user: 610 | $ref: '#/definitions/User' 611 | ts: 612 | type: integer 613 | coords: 614 | type: array 615 | items: 616 | type: integer 617 | city._city: 618 | $ref: '#/definitions/City' 619 | Ratings: 620 | properties: 621 | count: 622 | type: integer 623 | average: 624 | type: integer 625 | rating: 626 | type: array 627 | items: 628 | $ref: '#/definitions/Rating' 629 | Rating: 630 | properties: 631 | user._user: 632 | $ref: '#/definitions/User' 633 | rating: 634 | type: number 635 | ts: 636 | type: integer 637 | coords: 638 | type: array 639 | items: 640 | type: integer 641 | city._city: 642 | $ref: '#/definitions/City' 643 | Comments: 644 | properties: 645 | count: 646 | type: integer 647 | comment: 648 | type: array 649 | items: 650 | $ref: '#/definitions/Comment' 651 | Comment: 652 | properties: 653 | user._user: 654 | $ref: '#/definitions/User' 655 | comment: 656 | type: string 657 | ts: 658 | type: integer 659 | coords: 660 | type: array 661 | items: 662 | type: integer 663 | city._city: 664 | $ref: '#/definitions/City' 665 | Access: 666 | properties: 667 | access_token: 668 | type: string 669 | description: The access token after successful log in. This token is to be used in any subsequent request as header parameter 670 | uid: 671 | type: string 672 | description: The unique identifier for the logged in user 673 | AccessRequest: 674 | properties: 675 | n: 676 | type: string 677 | description: user name of the user to register 678 | a: 679 | type: string 680 | description: email of the user to register 681 | b: 682 | type: string 683 | description: (SHA1) hashed password of the user to register 684 | AccessRequestResponse: 685 | properties: 686 | name: 687 | type: string 688 | description: user name of the registered user 689 | User: 690 | properties: 691 | name: 692 | type: string 693 | description: user name of the linked user 694 | email: 695 | type: string 696 | description: email of the linked user 697 | Error: 698 | properties: 699 | errorType: 700 | type: string 701 | description: One of the following possible values with regard to the request and correlation to the HTTP error code - "wrong_mimetype", "method_not_allowed", "resource_not_found", "resource_conflict", "request_invalid", "request_unauthorized", "internal_server_error" 702 | 703 | 704 | -------------------------------------------------------------------------------- /web_root/css/jquery.dataTables.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Table styles 3 | */ 4 | table.dataTable { 5 | width: 100%; 6 | margin: 0 auto; 7 | clear: both; 8 | border-collapse: separate; 9 | border-spacing: 0; 10 | /* 11 | * Header and footer styles 12 | */ 13 | /* 14 | * Body styles 15 | */ 16 | } 17 | table.dataTable thead th, 18 | table.dataTable tfoot th { 19 | font-weight: bold; 20 | } 21 | table.dataTable thead th, 22 | table.dataTable thead td { 23 | padding: 10px 18px; 24 | border-bottom: 1px solid #111111; 25 | } 26 | table.dataTable thead th:active, 27 | table.dataTable thead td:active { 28 | outline: none; 29 | } 30 | table.dataTable tfoot th, 31 | table.dataTable tfoot td { 32 | padding: 10px 18px 6px 18px; 33 | border-top: 1px solid #111111; 34 | } 35 | table.dataTable thead .sorting_asc, 36 | table.dataTable thead .sorting_desc, 37 | table.dataTable thead .sorting { 38 | cursor: pointer; 39 | *cursor: hand; 40 | } 41 | table.dataTable thead .sorting { 42 | background: url("../images/sort_both.png") no-repeat center right; 43 | } 44 | table.dataTable thead .sorting_asc { 45 | background: url("../images/sort_asc.png") no-repeat center right; 46 | } 47 | table.dataTable thead .sorting_desc { 48 | background: url("../images/sort_desc.png") no-repeat center right; 49 | } 50 | table.dataTable thead .sorting_asc_disabled { 51 | background: url("../images/sort_asc_disabled.png") no-repeat center right; 52 | } 53 | table.dataTable thead .sorting_desc_disabled { 54 | background: url("../images/sort_desc_disabled.png") no-repeat center right; 55 | } 56 | table.dataTable tbody tr { 57 | background-color: white; 58 | } 59 | table.dataTable tbody tr.selected { 60 | background-color: #b0bed9; 61 | } 62 | table.dataTable tbody th, 63 | table.dataTable tbody td { 64 | padding: 8px 10px; 65 | } 66 | table.dataTable.row-border tbody th, table.dataTable.row-border tbody td, table.dataTable.display tbody th, table.dataTable.display tbody td { 67 | border-top: 1px solid #dddddd; 68 | } 69 | table.dataTable.row-border tbody tr:first-child th, 70 | table.dataTable.row-border tbody tr:first-child td, table.dataTable.display tbody tr:first-child th, 71 | table.dataTable.display tbody tr:first-child td { 72 | border-top: none; 73 | } 74 | table.dataTable.cell-border tbody th, table.dataTable.cell-border tbody td { 75 | border-top: 1px solid #dddddd; 76 | border-right: 1px solid #dddddd; 77 | } 78 | table.dataTable.cell-border tbody tr th:first-child, 79 | table.dataTable.cell-border tbody tr td:first-child { 80 | border-left: 1px solid #dddddd; 81 | } 82 | table.dataTable.cell-border tbody tr:first-child th, 83 | table.dataTable.cell-border tbody tr:first-child td { 84 | border-top: none; 85 | } 86 | table.dataTable.stripe tbody tr.odd, table.dataTable.display tbody tr.odd { 87 | background-color: #f9f9f9; 88 | } 89 | table.dataTable.stripe tbody tr.odd.selected, table.dataTable.display tbody tr.odd.selected { 90 | background-color: #abb9d3; 91 | } 92 | table.dataTable.hover tbody tr:hover, 93 | table.dataTable.hover tbody tr.odd:hover, 94 | table.dataTable.hover tbody tr.even:hover, table.dataTable.display tbody tr:hover, 95 | table.dataTable.display tbody tr.odd:hover, 96 | table.dataTable.display tbody tr.even:hover { 97 | background-color: whitesmoke; 98 | } 99 | table.dataTable.hover tbody tr:hover.selected, 100 | table.dataTable.hover tbody tr.odd:hover.selected, 101 | table.dataTable.hover tbody tr.even:hover.selected, table.dataTable.display tbody tr:hover.selected, 102 | table.dataTable.display tbody tr.odd:hover.selected, 103 | table.dataTable.display tbody tr.even:hover.selected { 104 | background-color: #a9b7d1; 105 | } 106 | table.dataTable.order-column tbody tr > .sorting_1, 107 | table.dataTable.order-column tbody tr > .sorting_2, 108 | table.dataTable.order-column tbody tr > .sorting_3, table.dataTable.display tbody tr > .sorting_1, 109 | table.dataTable.display tbody tr > .sorting_2, 110 | table.dataTable.display tbody tr > .sorting_3 { 111 | background-color: #f9f9f9; 112 | } 113 | table.dataTable.order-column tbody tr.selected > .sorting_1, 114 | table.dataTable.order-column tbody tr.selected > .sorting_2, 115 | table.dataTable.order-column tbody tr.selected > .sorting_3, table.dataTable.display tbody tr.selected > .sorting_1, 116 | table.dataTable.display tbody tr.selected > .sorting_2, 117 | table.dataTable.display tbody tr.selected > .sorting_3 { 118 | background-color: #acbad4; 119 | } 120 | table.dataTable.display tbody tr.odd > .sorting_1, table.dataTable.order-column.stripe tbody tr.odd > .sorting_1 { 121 | background-color: #f1f1f1; 122 | } 123 | table.dataTable.display tbody tr.odd > .sorting_2, table.dataTable.order-column.stripe tbody tr.odd > .sorting_2 { 124 | background-color: #f3f3f3; 125 | } 126 | table.dataTable.display tbody tr.odd > .sorting_3, table.dataTable.order-column.stripe tbody tr.odd > .sorting_3 { 127 | background-color: whitesmoke; 128 | } 129 | table.dataTable.display tbody tr.odd.selected > .sorting_1, table.dataTable.order-column.stripe tbody tr.odd.selected > .sorting_1 { 130 | background-color: #a6b3cd; 131 | } 132 | table.dataTable.display tbody tr.odd.selected > .sorting_2, table.dataTable.order-column.stripe tbody tr.odd.selected > .sorting_2 { 133 | background-color: #a7b5ce; 134 | } 135 | table.dataTable.display tbody tr.odd.selected > .sorting_3, table.dataTable.order-column.stripe tbody tr.odd.selected > .sorting_3 { 136 | background-color: #a9b6d0; 137 | } 138 | table.dataTable.display tbody tr.even > .sorting_1, table.dataTable.order-column.stripe tbody tr.even > .sorting_1 { 139 | background-color: #f9f9f9; 140 | } 141 | table.dataTable.display tbody tr.even > .sorting_2, table.dataTable.order-column.stripe tbody tr.even > .sorting_2 { 142 | background-color: #fbfbfb; 143 | } 144 | table.dataTable.display tbody tr.even > .sorting_3, table.dataTable.order-column.stripe tbody tr.even > .sorting_3 { 145 | background-color: #fdfdfd; 146 | } 147 | table.dataTable.display tbody tr.even.selected > .sorting_1, table.dataTable.order-column.stripe tbody tr.even.selected > .sorting_1 { 148 | background-color: #acbad4; 149 | } 150 | table.dataTable.display tbody tr.even.selected > .sorting_2, table.dataTable.order-column.stripe tbody tr.even.selected > .sorting_2 { 151 | background-color: #adbbd6; 152 | } 153 | table.dataTable.display tbody tr.even.selected > .sorting_3, table.dataTable.order-column.stripe tbody tr.even.selected > .sorting_3 { 154 | background-color: #afbdd8; 155 | } 156 | table.dataTable.display tbody tr:hover > .sorting_1, 157 | table.dataTable.display tbody tr.odd:hover > .sorting_1, 158 | table.dataTable.display tbody tr.even:hover > .sorting_1, table.dataTable.order-column.hover tbody tr:hover > .sorting_1, 159 | table.dataTable.order-column.hover tbody tr.odd:hover > .sorting_1, 160 | table.dataTable.order-column.hover tbody tr.even:hover > .sorting_1 { 161 | background-color: #eaeaea; 162 | } 163 | table.dataTable.display tbody tr:hover > .sorting_2, 164 | table.dataTable.display tbody tr.odd:hover > .sorting_2, 165 | table.dataTable.display tbody tr.even:hover > .sorting_2, table.dataTable.order-column.hover tbody tr:hover > .sorting_2, 166 | table.dataTable.order-column.hover tbody tr.odd:hover > .sorting_2, 167 | table.dataTable.order-column.hover tbody tr.even:hover > .sorting_2 { 168 | background-color: #ebebeb; 169 | } 170 | table.dataTable.display tbody tr:hover > .sorting_3, 171 | table.dataTable.display tbody tr.odd:hover > .sorting_3, 172 | table.dataTable.display tbody tr.even:hover > .sorting_3, table.dataTable.order-column.hover tbody tr:hover > .sorting_3, 173 | table.dataTable.order-column.hover tbody tr.odd:hover > .sorting_3, 174 | table.dataTable.order-column.hover tbody tr.even:hover > .sorting_3 { 175 | background-color: #eeeeee; 176 | } 177 | table.dataTable.display tbody tr:hover.selected > .sorting_1, 178 | table.dataTable.display tbody tr.odd:hover.selected > .sorting_1, 179 | table.dataTable.display tbody tr.even:hover.selected > .sorting_1, table.dataTable.order-column.hover tbody tr:hover.selected > .sorting_1, 180 | table.dataTable.order-column.hover tbody tr.odd:hover.selected > .sorting_1, 181 | table.dataTable.order-column.hover tbody tr.even:hover.selected > .sorting_1 { 182 | background-color: #a1aec7; 183 | } 184 | table.dataTable.display tbody tr:hover.selected > .sorting_2, 185 | table.dataTable.display tbody tr.odd:hover.selected > .sorting_2, 186 | table.dataTable.display tbody tr.even:hover.selected > .sorting_2, table.dataTable.order-column.hover tbody tr:hover.selected > .sorting_2, 187 | table.dataTable.order-column.hover tbody tr.odd:hover.selected > .sorting_2, 188 | table.dataTable.order-column.hover tbody tr.even:hover.selected > .sorting_2 { 189 | background-color: #a2afc8; 190 | } 191 | table.dataTable.display tbody tr:hover.selected > .sorting_3, 192 | table.dataTable.display tbody tr.odd:hover.selected > .sorting_3, 193 | table.dataTable.display tbody tr.even:hover.selected > .sorting_3, table.dataTable.order-column.hover tbody tr:hover.selected > .sorting_3, 194 | table.dataTable.order-column.hover tbody tr.odd:hover.selected > .sorting_3, 195 | table.dataTable.order-column.hover tbody tr.even:hover.selected > .sorting_3 { 196 | background-color: #a4b2cb; 197 | } 198 | table.dataTable.no-footer { 199 | border-bottom: 1px solid #111111; 200 | } 201 | table.dataTable.nowrap th, table.dataTable.nowrap td { 202 | white-space: nowrap; 203 | } 204 | table.dataTable.compact thead th, 205 | table.dataTable.compact thead td { 206 | padding: 5px 9px; 207 | } 208 | table.dataTable.compact tfoot th, 209 | table.dataTable.compact tfoot td { 210 | padding: 5px 9px 3px 9px; 211 | } 212 | table.dataTable.compact tbody th, 213 | table.dataTable.compact tbody td { 214 | padding: 4px 5px; 215 | } 216 | table.dataTable th.dt-left, 217 | table.dataTable td.dt-left { 218 | text-align: left; 219 | } 220 | table.dataTable th.dt-center, 221 | table.dataTable td.dt-center, 222 | table.dataTable td.dataTables_empty { 223 | text-align: center; 224 | } 225 | table.dataTable th.dt-right, 226 | table.dataTable td.dt-right { 227 | text-align: right; 228 | } 229 | table.dataTable th.dt-justify, 230 | table.dataTable td.dt-justify { 231 | text-align: justify; 232 | } 233 | table.dataTable th.dt-nowrap, 234 | table.dataTable td.dt-nowrap { 235 | white-space: nowrap; 236 | } 237 | table.dataTable thead th.dt-head-left, 238 | table.dataTable thead td.dt-head-left, 239 | table.dataTable tfoot th.dt-head-left, 240 | table.dataTable tfoot td.dt-head-left { 241 | text-align: left; 242 | } 243 | table.dataTable thead th.dt-head-center, 244 | table.dataTable thead td.dt-head-center, 245 | table.dataTable tfoot th.dt-head-center, 246 | table.dataTable tfoot td.dt-head-center { 247 | text-align: center; 248 | } 249 | table.dataTable thead th.dt-head-right, 250 | table.dataTable thead td.dt-head-right, 251 | table.dataTable tfoot th.dt-head-right, 252 | table.dataTable tfoot td.dt-head-right { 253 | text-align: right; 254 | } 255 | table.dataTable thead th.dt-head-justify, 256 | table.dataTable thead td.dt-head-justify, 257 | table.dataTable tfoot th.dt-head-justify, 258 | table.dataTable tfoot td.dt-head-justify { 259 | text-align: justify; 260 | } 261 | table.dataTable thead th.dt-head-nowrap, 262 | table.dataTable thead td.dt-head-nowrap, 263 | table.dataTable tfoot th.dt-head-nowrap, 264 | table.dataTable tfoot td.dt-head-nowrap { 265 | white-space: nowrap; 266 | } 267 | table.dataTable tbody th.dt-body-left, 268 | table.dataTable tbody td.dt-body-left { 269 | text-align: left; 270 | } 271 | table.dataTable tbody th.dt-body-center, 272 | table.dataTable tbody td.dt-body-center { 273 | text-align: center; 274 | } 275 | table.dataTable tbody th.dt-body-right, 276 | table.dataTable tbody td.dt-body-right { 277 | text-align: right; 278 | } 279 | table.dataTable tbody th.dt-body-justify, 280 | table.dataTable tbody td.dt-body-justify { 281 | text-align: justify; 282 | } 283 | table.dataTable tbody th.dt-body-nowrap, 284 | table.dataTable tbody td.dt-body-nowrap { 285 | white-space: nowrap; 286 | } 287 | 288 | table.dataTable, 289 | table.dataTable th, 290 | table.dataTable td { 291 | -webkit-box-sizing: content-box; 292 | -moz-box-sizing: content-box; 293 | box-sizing: content-box; 294 | } 295 | 296 | /* 297 | * Control feature layout 298 | */ 299 | .dataTables_wrapper { 300 | position: relative; 301 | clear: both; 302 | *zoom: 1; 303 | zoom: 1; 304 | } 305 | .dataTables_wrapper .dataTables_length { 306 | float: left; 307 | } 308 | .dataTables_wrapper .dataTables_filter { 309 | float: right; 310 | text-align: right; 311 | } 312 | .dataTables_wrapper .dataTables_filter input { 313 | margin-left: 0.5em; 314 | } 315 | .dataTables_wrapper .dataTables_info { 316 | clear: both; 317 | float: left; 318 | padding-top: 0.755em; 319 | } 320 | .dataTables_wrapper .dataTables_paginate { 321 | float: right; 322 | text-align: right; 323 | padding-top: 0.25em; 324 | } 325 | .dataTables_wrapper .dataTables_paginate .paginate_button { 326 | box-sizing: border-box; 327 | display: inline-block; 328 | min-width: 1.5em; 329 | padding: 0.5em 1em; 330 | margin-left: 2px; 331 | text-align: center; 332 | text-decoration: none !important; 333 | cursor: pointer; 334 | *cursor: hand; 335 | color: #333333 !important; 336 | border: 1px solid transparent; 337 | } 338 | .dataTables_wrapper .dataTables_paginate .paginate_button.current, .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover { 339 | color: #333333 !important; 340 | border: 1px solid #cacaca; 341 | background-color: white; 342 | background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, white), color-stop(100%, gainsboro)); 343 | /* Chrome,Safari4+ */ 344 | background: -webkit-linear-gradient(top, white 0%, gainsboro 100%); 345 | /* Chrome10+,Safari5.1+ */ 346 | background: -moz-linear-gradient(top, white 0%, gainsboro 100%); 347 | /* FF3.6+ */ 348 | background: -ms-linear-gradient(top, white 0%, gainsboro 100%); 349 | /* IE10+ */ 350 | background: -o-linear-gradient(top, white 0%, gainsboro 100%); 351 | /* Opera 11.10+ */ 352 | background: linear-gradient(to bottom, white 0%, gainsboro 100%); 353 | /* W3C */ 354 | } 355 | .dataTables_wrapper .dataTables_paginate .paginate_button.disabled, .dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover, .dataTables_wrapper .dataTables_paginate .paginate_button.disabled:active { 356 | cursor: default; 357 | color: #666 !important; 358 | border: 1px solid transparent; 359 | background: transparent; 360 | box-shadow: none; 361 | } 362 | .dataTables_wrapper .dataTables_paginate .paginate_button:hover { 363 | color: white !important; 364 | border: 1px solid #111111; 365 | background-color: #585858; 366 | background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #585858), color-stop(100%, #111111)); 367 | /* Chrome,Safari4+ */ 368 | background: -webkit-linear-gradient(top, #585858 0%, #111111 100%); 369 | /* Chrome10+,Safari5.1+ */ 370 | background: -moz-linear-gradient(top, #585858 0%, #111111 100%); 371 | /* FF3.6+ */ 372 | background: -ms-linear-gradient(top, #585858 0%, #111111 100%); 373 | /* IE10+ */ 374 | background: -o-linear-gradient(top, #585858 0%, #111111 100%); 375 | /* Opera 11.10+ */ 376 | background: linear-gradient(to bottom, #585858 0%, #111111 100%); 377 | /* W3C */ 378 | } 379 | .dataTables_wrapper .dataTables_paginate .paginate_button:active { 380 | outline: none; 381 | background-color: #2b2b2b; 382 | background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #2b2b2b), color-stop(100%, #0c0c0c)); 383 | /* Chrome,Safari4+ */ 384 | background: -webkit-linear-gradient(top, #2b2b2b 0%, #0c0c0c 100%); 385 | /* Chrome10+,Safari5.1+ */ 386 | background: -moz-linear-gradient(top, #2b2b2b 0%, #0c0c0c 100%); 387 | /* FF3.6+ */ 388 | background: -ms-linear-gradient(top, #2b2b2b 0%, #0c0c0c 100%); 389 | /* IE10+ */ 390 | background: -o-linear-gradient(top, #2b2b2b 0%, #0c0c0c 100%); 391 | /* Opera 11.10+ */ 392 | background: linear-gradient(to bottom, #2b2b2b 0%, #0c0c0c 100%); 393 | /* W3C */ 394 | box-shadow: inset 0 0 3px #111; 395 | } 396 | .dataTables_wrapper .dataTables_processing { 397 | position: absolute; 398 | top: 50%; 399 | left: 50%; 400 | width: 100%; 401 | height: 40px; 402 | margin-left: -50%; 403 | margin-top: -25px; 404 | padding-top: 20px; 405 | text-align: center; 406 | font-size: 1.2em; 407 | background-color: white; 408 | background: -webkit-gradient(linear, left top, right top, color-stop(0%, rgba(255, 255, 255, 0)), color-stop(25%, rgba(255, 255, 255, 0.9)), color-stop(75%, rgba(255, 255, 255, 0.9)), color-stop(100%, rgba(255, 255, 255, 0))); 409 | /* Chrome,Safari4+ */ 410 | background: -webkit-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 0.9) 75%, rgba(255, 255, 255, 0) 100%); 411 | /* Chrome10+,Safari5.1+ */ 412 | background: -moz-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 0.9) 75%, rgba(255, 255, 255, 0) 100%); 413 | /* FF3.6+ */ 414 | background: -ms-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 0.9) 75%, rgba(255, 255, 255, 0) 100%); 415 | /* IE10+ */ 416 | background: -o-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 0.9) 75%, rgba(255, 255, 255, 0) 100%); 417 | /* Opera 11.10+ */ 418 | background: linear-gradient(to right, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 0.9) 75%, rgba(255, 255, 255, 0) 100%); 419 | /* W3C */ 420 | } 421 | .dataTables_wrapper .dataTables_length, 422 | .dataTables_wrapper .dataTables_filter, 423 | .dataTables_wrapper .dataTables_info, 424 | .dataTables_wrapper .dataTables_processing, 425 | .dataTables_wrapper .dataTables_paginate { 426 | color: #333333; 427 | } 428 | .dataTables_wrapper .dataTables_scroll { 429 | clear: both; 430 | } 431 | .dataTables_wrapper .dataTables_scroll div.dataTables_scrollBody { 432 | *margin-top: -1px; 433 | -webkit-overflow-scrolling: touch; 434 | } 435 | .dataTables_wrapper .dataTables_scroll div.dataTables_scrollBody th > div.dataTables_sizing, 436 | .dataTables_wrapper .dataTables_scroll div.dataTables_scrollBody td > div.dataTables_sizing { 437 | height: 0; 438 | overflow: hidden; 439 | margin: 0 !important; 440 | padding: 0 !important; 441 | } 442 | .dataTables_wrapper.no-footer .dataTables_scrollBody { 443 | border-bottom: 1px solid #111111; 444 | } 445 | .dataTables_wrapper.no-footer div.dataTables_scrollHead table, 446 | .dataTables_wrapper.no-footer div.dataTables_scrollBody table { 447 | border-bottom: none; 448 | } 449 | .dataTables_wrapper:after { 450 | visibility: hidden; 451 | display: block; 452 | content: ""; 453 | clear: both; 454 | height: 0; 455 | } 456 | 457 | @media screen and (max-width: 767px) { 458 | .dataTables_wrapper .dataTables_info, 459 | .dataTables_wrapper .dataTables_paginate { 460 | float: none; 461 | text-align: center; 462 | } 463 | .dataTables_wrapper .dataTables_paginate { 464 | margin-top: 0.5em; 465 | } 466 | } 467 | @media screen and (max-width: 640px) { 468 | .dataTables_wrapper .dataTables_length, 469 | .dataTables_wrapper .dataTables_filter { 470 | float: none; 471 | text-align: center; 472 | } 473 | .dataTables_wrapper .dataTables_filter { 474 | margin-top: 0.5em; 475 | } 476 | } 477 | -------------------------------------------------------------------------------- /web_root/css/style.css: -------------------------------------------------------------------------------- 1 | #socials ul{ 2 | list-style: none inside; 3 | -webkit-padding-start: 0px; 4 | padding-start: 0px; 5 | } 6 | 7 | .logoutPane { 8 | display: none; 9 | } 10 | -------------------------------------------------------------------------------- /web_root/images/Sorting icons.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fraunhoferfokus/OCDB/1eafe7b57729acbf9a7f361a58809330e9a13274/web_root/images/Sorting icons.psd -------------------------------------------------------------------------------- /web_root/images/back_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fraunhoferfokus/OCDB/1eafe7b57729acbf9a7f361a58809330e9a13274/web_root/images/back_disabled.png -------------------------------------------------------------------------------- /web_root/images/back_enabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fraunhoferfokus/OCDB/1eafe7b57729acbf9a7f361a58809330e9a13274/web_root/images/back_enabled.png -------------------------------------------------------------------------------- /web_root/images/back_enabled_hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fraunhoferfokus/OCDB/1eafe7b57729acbf9a7f361a58809330e9a13274/web_root/images/back_enabled_hover.png -------------------------------------------------------------------------------- /web_root/images/forward_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fraunhoferfokus/OCDB/1eafe7b57729acbf9a7f361a58809330e9a13274/web_root/images/forward_disabled.png -------------------------------------------------------------------------------- /web_root/images/forward_enabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fraunhoferfokus/OCDB/1eafe7b57729acbf9a7f361a58809330e9a13274/web_root/images/forward_enabled.png -------------------------------------------------------------------------------- /web_root/images/forward_enabled_hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fraunhoferfokus/OCDB/1eafe7b57729acbf9a7f361a58809330e9a13274/web_root/images/forward_enabled_hover.png -------------------------------------------------------------------------------- /web_root/images/sort_asc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fraunhoferfokus/OCDB/1eafe7b57729acbf9a7f361a58809330e9a13274/web_root/images/sort_asc.png -------------------------------------------------------------------------------- /web_root/images/sort_asc_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fraunhoferfokus/OCDB/1eafe7b57729acbf9a7f361a58809330e9a13274/web_root/images/sort_asc_disabled.png -------------------------------------------------------------------------------- /web_root/images/sort_both.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fraunhoferfokus/OCDB/1eafe7b57729acbf9a7f361a58809330e9a13274/web_root/images/sort_both.png -------------------------------------------------------------------------------- /web_root/images/sort_desc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fraunhoferfokus/OCDB/1eafe7b57729acbf9a7f361a58809330e9a13274/web_root/images/sort_desc.png -------------------------------------------------------------------------------- /web_root/images/sort_desc_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fraunhoferfokus/OCDB/1eafe7b57729acbf9a7f361a58809330e9a13274/web_root/images/sort_desc_disabled.png -------------------------------------------------------------------------------- /web_root/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Open City Database | Frontend 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |

Open City Database | Frontend

20 |

Interface for Application Providers and Users

21 |
22 | Login 23 |
24 | 25 | 26 | 27 | 28 |
29 |
30 |
31 | 32 |
33 | 34 | Logout 35 |
36 | 37 |
38 |
39 | 40 |
41 | Registration 42 |
43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
password: must contain at least one digit, one lowercase and one uppercase character and must be 6 characters at minimum. 51 |
52 |
53 |
54 | 55 |
56 |

Cities

57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 |
City IDNameDescriptionLatitudeLongitudeAction
73 | 74 | 75 | 76 |
77 |

Pois

78 | Selected City: 79 | 80 |

81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 |
POI IDNameDescriptionLatitudeLongitudePublic?Social
99 | 100 |
101 |

Social Interactions

102 | Selected Poi: 103 | 104 |

105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 |
POI IDCheckinsCommentsLikesRatings
121 | 122 |
123 |

Media

124 | Selected Poi: 125 | 126 |

127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 |
Media IDTypeCreation TimeUserPreviewAction
144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /web_root/index.js: -------------------------------------------------------------------------------- 1 | var loginForm, logoutForm, registerForm; 2 | 3 | window.onload=function(){ 4 | var forms = document.querySelectorAll("form"); 5 | for(var s in forms){ 6 | var action = forms[s].getAttribute && forms[s].getAttribute("action"); 7 | if(action && action.indexOf("login")!==-1){ 8 | loginForm=forms[s]; 9 | loginForm.onsubmit=loginHandler; 10 | } 11 | if(action && action.indexOf("logout")!==-1){ 12 | logoutForm=forms[s]; 13 | logoutForm.onsubmit=logoutHandler; 14 | } 15 | if(action && action.indexOf("register")!==-1){ 16 | registerForm=forms[s]; 17 | registerForm.onsubmit=registerHandler; 18 | } 19 | } 20 | } 21 | 22 | var loginHandler = function(e){ 23 | e.preventDefault(); 24 | var email = ocdb.tools.SHA1(loginForm.querySelector('input[name="email"]').value); 25 | var password = ocdb.tools.SHA1(loginForm.querySelector('input[name="password"]').value); 26 | ocdb.user.login(email, password, loginRequestHandler); 27 | return false; 28 | }; 29 | 30 | var logoutHandler = function(e){ 31 | e.preventDefault(); 32 | ocdb.user.logout(logoutRequestHandler); 33 | return false; 34 | }; 35 | 36 | var registerHandler = function(e){ 37 | e.preventDefault(); 38 | var name = registerForm.querySelector('input[name="name"]').value; 39 | var email = registerForm.querySelector('input[name="email"]').value; 40 | var password = ocdb.tools.SHA1(registerForm.querySelector('input[name="password"]').value); 41 | var password2 = ocdb.tools.SHA1(registerForm.querySelector('input[name="repassword"]').value); 42 | 43 | if(password!==password2){ 44 | registerForm.querySelector('input[name="repassword"]').value=""; 45 | registerForm.querySelector('input[name="repassword"]').setAttribute("placeholder","passwords do not match!"); 46 | return false; 47 | } 48 | 49 | ocdb.user.register(name, email, password, registerRequestHandler); 50 | return false; 51 | }; 52 | 53 | var loginRequestHandler = function(err,response){ 54 | if(err){ 55 | document.querySelector("#loginErr").innerText="error:"+err; 56 | return; 57 | } 58 | document.querySelector("#loginErr").innerText=""; 59 | document.querySelector(".logoutPane").style.display="inherit"; 60 | document.querySelector(".loginPane").style.display="none"; 61 | document.querySelector(".registerPane").style.display="none"; 62 | if(response&&response.access_token){ 63 | document.querySelector("#accesstoken").innerHTML="Access token: "+response.access_token+ 64 | '
View data below or use the API console.

' 67 | 68 | } 69 | console.log(err,response); 70 | if(ocdb.user.getUid()){ 71 | //$('#cities').DataTable(); 72 | initCityDt('#cities', 73 | (function(){ 74 | return function(options,cb){ 75 | var opt={lat:53,lon:13}; 76 | opt.limit=options.length; 77 | opt.offset=options.start; 78 | opt.search=options.search&&options.search.value||''; 79 | ocdb.cities.get(opt,function(e,r,meta){ 80 | if(!e) 81 | cb({data:r,draw:options.draw,recordsTotal:meta.recordsTotal,recordsFiltered:meta.recordsFiltered}); 82 | })} 83 | })() 84 | ); 85 | } 86 | } 87 | 88 | var logoutRequestHandler = function(err,response){ 89 | console.log(err,response); 90 | document.querySelector(".logoutPane").style.display="none"; 91 | document.querySelector(".loginPane").style.display=""; 92 | document.querySelector(".registerPane").style.display=""; 93 | $("#cities").DataTable().clear().destroy(); 94 | $("#pois").DataTable().clear().destroy(); 95 | $("#socials").DataTable().clear().destroy(); 96 | $("#medias").DataTable().clear().destroy(); 97 | } 98 | 99 | var registerRequestHandler = function(err,response){ 100 | console.log(err,response); 101 | if(err){ 102 | document.querySelector("#registerErr").innerText="error:"+err; 103 | return; 104 | } 105 | document.querySelector("#registerErr").innerText=""; 106 | } 107 | 108 | window.addEventListener("hashchange",function(){ 109 | var hashMap={}, hash = location.hash.substring(1); 110 | hash=hash.split("&"); 111 | for(var i=0;iview'; 221 | } } 222 | ], 223 | "preDrawCallback" : function() { 224 | // Initialize the responsive datatables helper once. 225 | 226 | }, 227 | "rowCallback" : function(nRow) { 228 | }, 229 | "drawCallback" : function(oSettings) { 230 | 231 | } 232 | }); 233 | }; 234 | 235 | var initPoiDt = function(tableId, ajaxFn) { 236 | var $table = $(tableId); 237 | $table.DataTable().clear().destroy(); 238 | 239 | // names for column ordering 240 | $table.data('colnames', ['_id', 'name', 'description', 'lat', 'lon', 'public', '']); 241 | 242 | return $table.dataTable({ 243 | "autoWidth" : true, 244 | "processing": true, 245 | "serverSide": true, 246 | "ajax": ajaxFn, 247 | "columns": [ 248 | 249 | { "data": "_id" }, 250 | { "data": "name" }, 251 | { "data": function ( data, type, row) { 252 | return data.description || ''; 253 | } }, 254 | { "data": function ( data, type, row) { 255 | return data && data.coords[1] || ''; 256 | } }, 257 | { "data": function ( data, type, row) { 258 | return data && data.coords[0] || ''; 259 | } }, 260 | { "data": function ( data, type, row) { 261 | var str = 'yes*'; 262 | if(data.user&&(ocdb.user.getUid()===data.user._user||ocdb.user.getUid()===data.user._user._id)){ 263 | if(data && data.public){ 264 | str = '
yes'; 265 | } else { 266 | str = '
no'; 267 | } 268 | } 269 | return str; 270 | } }, 271 | { "data": function ( data, type, row) { 272 | var str=''; 273 | if(data.socatt){ 274 | if(data.socatt.checkins.count){ 275 | str=str+data.socatt.checkins.count+' checkins.
'; 276 | } 277 | if(data.socatt.comments.count){ 278 | str=str+data.socatt.comments.count+' comments.
'; 279 | } 280 | if(data.socatt.likes.count){ 281 | str=str+data.socatt.likes.count+' likes.
'; 282 | } 283 | if(data.socatt.ratings.count){ 284 | str=str+data.socatt.ratings.count+' ratings with ave '+data.socatt.ratings.average+'.
'; 285 | } 286 | } 287 | if(str){ 288 | str = str + 'view'; 289 | } 290 | if(data.media && data.media._media &&data.media._media.length){ 291 | if(str) str+="
" 292 | str=str+data.media._media.length+' images. '; 293 | } 294 | return str||'-'; 295 | } }, 296 | ], 297 | "preDrawCallback" : function() { 298 | // Initialize the responsive datatables helper once. 299 | 300 | }, 301 | "rowCallback" : function(nRow) { 302 | }, 303 | "drawCallback" : function(oSettings) { 304 | 305 | } 306 | }); 307 | }; 308 | 309 | var initSocialDt = function(tableId, ajaxFn) { 310 | var $table = $(tableId); 311 | $table.DataTable().clear().destroy(); 312 | 313 | // names for column ordering 314 | $table.data('colnames', ['_id', 'checkins', 'comments', 'likes', 'ratings']); 315 | 316 | return $table.dataTable({ 317 | "bPaginate": false, 318 | "bFilter": false, 319 | "bInfo": false, 320 | 'bSortable': false, 321 | "autoWidth" : true, 322 | "processing": true, 323 | "serverSide": true, 324 | "ajax": ajaxFn, 325 | "columns": [ 326 | 327 | { "data": "_id" }, 328 | { "data": function ( data, type, row) { 329 | //checkins 330 | var str=""; 331 | if(data.socatt){ 332 | if(data.socatt.checkins.checkin.length){ 333 | str+=""; 338 | } 339 | } 340 | return str?str:"-"; 341 | } }, 342 | { "data": function ( data, type, row) { 343 | //comments 344 | var str=""; 345 | if(data.socatt){ 346 | if(data.socatt.comments.comment.length){ 347 | str+=""; 352 | } 353 | if(data.socatt.likes.like.length){ 354 | 355 | } 356 | if(data.socatt.ratings.rating.length){ 357 | 358 | } 359 | } 360 | return str?str:"-"; 361 | } }, 362 | { "data": function ( data, type, row) { 363 | var str=""; 364 | if(data.socatt){ 365 | if(data.socatt.likes.like.length){ 366 | str+=""; 371 | } 372 | } 373 | return str?str:"-"; 374 | } }, 375 | { "data": function ( data, type, row) { 376 | var str=""; 377 | if(data.socatt){ 378 | if(data.socatt.ratings.rating.length){ 379 | str+=""; 384 | } 385 | } 386 | return str?str:"-"; 387 | } }, 388 | ], 389 | "preDrawCallback" : function() { 390 | // Initialize the responsive datatables helper once. 391 | 392 | }, 393 | "rowCallback" : function(nRow) { 394 | }, 395 | "drawCallback" : function(oSettings) { 396 | 397 | } 398 | }); 399 | }; 400 | 401 | var initMediaDt = function(tableId, ajaxFn) { 402 | var $table = $(tableId); 403 | $table.DataTable().clear().destroy(); 404 | 405 | // names for column ordering 406 | $table.data('colnames', ['_id', 'type', 'timestamp', 'user', 'url', '']); 407 | 408 | return $table.dataTable({ 409 | "bPaginate": false, 410 | "bFilter": false, 411 | "bInfo": false, 412 | 'bSortable': false, 413 | "autoWidth" : true, 414 | "processing": true, 415 | "serverSide": true, 416 | "ajax": ajaxFn, 417 | "columns": [ 418 | 419 | { "data": "_id" }, 420 | { "data": "type" }, 421 | { "data": function ( data, type, row) { 422 | return new Date(parseInt(data.timestamp)).toString(); 423 | } }, 424 | { "data": function ( data, type, row) { 425 | if(!data.user||!data.user._user) return "-"; 426 | return "by "+data.user._user.name+""; 427 | } }, 428 | { "data": function ( data, type, row) { 429 | return ""; 430 | } }, 431 | { "data": function ( data, type, row) { 432 | if(!data.user||!data.user._user||ocdb.user.getUid()===data.user._user._id){ 433 | return ' delete!'; 434 | } 435 | return "-"; 436 | } }, 437 | ], 438 | "preDrawCallback" : function() { 439 | // Initialize the responsive datatables helper once. 440 | 441 | }, 442 | "rowCallback" : function(nRow) { 443 | }, 444 | "drawCallback" : function(oSettings) { 445 | 446 | } 447 | }); 448 | }; 449 | -------------------------------------------------------------------------------- /web_root/jquery.dataTables.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Table styles 3 | */ 4 | table.dataTable { 5 | width: 100%; 6 | margin: 0 auto; 7 | clear: both; 8 | border-collapse: separate; 9 | border-spacing: 0; 10 | /* 11 | * Header and footer styles 12 | */ 13 | /* 14 | * Body styles 15 | */ 16 | } 17 | table.dataTable thead th, 18 | table.dataTable tfoot th { 19 | font-weight: bold; 20 | } 21 | table.dataTable thead th, 22 | table.dataTable thead td { 23 | padding: 10px 18px; 24 | border-bottom: 1px solid #111111; 25 | } 26 | table.dataTable thead th:active, 27 | table.dataTable thead td:active { 28 | outline: none; 29 | } 30 | table.dataTable tfoot th, 31 | table.dataTable tfoot td { 32 | padding: 10px 18px 6px 18px; 33 | border-top: 1px solid #111111; 34 | } 35 | table.dataTable thead .sorting_asc, 36 | table.dataTable thead .sorting_desc, 37 | table.dataTable thead .sorting { 38 | cursor: pointer; 39 | *cursor: hand; 40 | } 41 | table.dataTable thead .sorting { 42 | background: url("../images/sort_both.png") no-repeat center right; 43 | } 44 | table.dataTable thead .sorting_asc { 45 | background: url("../images/sort_asc.png") no-repeat center right; 46 | } 47 | table.dataTable thead .sorting_desc { 48 | background: url("../images/sort_desc.png") no-repeat center right; 49 | } 50 | table.dataTable thead .sorting_asc_disabled { 51 | background: url("../images/sort_asc_disabled.png") no-repeat center right; 52 | } 53 | table.dataTable thead .sorting_desc_disabled { 54 | background: url("../images/sort_desc_disabled.png") no-repeat center right; 55 | } 56 | table.dataTable tbody tr { 57 | background-color: white; 58 | } 59 | table.dataTable tbody tr.selected { 60 | background-color: #b0bed9; 61 | } 62 | table.dataTable tbody th, 63 | table.dataTable tbody td { 64 | padding: 8px 10px; 65 | } 66 | table.dataTable.row-border tbody th, table.dataTable.row-border tbody td, table.dataTable.display tbody th, table.dataTable.display tbody td { 67 | border-top: 1px solid #dddddd; 68 | } 69 | table.dataTable.row-border tbody tr:first-child th, 70 | table.dataTable.row-border tbody tr:first-child td, table.dataTable.display tbody tr:first-child th, 71 | table.dataTable.display tbody tr:first-child td { 72 | border-top: none; 73 | } 74 | table.dataTable.cell-border tbody th, table.dataTable.cell-border tbody td { 75 | border-top: 1px solid #dddddd; 76 | border-right: 1px solid #dddddd; 77 | } 78 | table.dataTable.cell-border tbody tr th:first-child, 79 | table.dataTable.cell-border tbody tr td:first-child { 80 | border-left: 1px solid #dddddd; 81 | } 82 | table.dataTable.cell-border tbody tr:first-child th, 83 | table.dataTable.cell-border tbody tr:first-child td { 84 | border-top: none; 85 | } 86 | table.dataTable.stripe tbody tr.odd, table.dataTable.display tbody tr.odd { 87 | background-color: #f9f9f9; 88 | } 89 | table.dataTable.stripe tbody tr.odd.selected, table.dataTable.display tbody tr.odd.selected { 90 | background-color: #abb9d3; 91 | } 92 | table.dataTable.hover tbody tr:hover, 93 | table.dataTable.hover tbody tr.odd:hover, 94 | table.dataTable.hover tbody tr.even:hover, table.dataTable.display tbody tr:hover, 95 | table.dataTable.display tbody tr.odd:hover, 96 | table.dataTable.display tbody tr.even:hover { 97 | background-color: whitesmoke; 98 | } 99 | table.dataTable.hover tbody tr:hover.selected, 100 | table.dataTable.hover tbody tr.odd:hover.selected, 101 | table.dataTable.hover tbody tr.even:hover.selected, table.dataTable.display tbody tr:hover.selected, 102 | table.dataTable.display tbody tr.odd:hover.selected, 103 | table.dataTable.display tbody tr.even:hover.selected { 104 | background-color: #a9b7d1; 105 | } 106 | table.dataTable.order-column tbody tr > .sorting_1, 107 | table.dataTable.order-column tbody tr > .sorting_2, 108 | table.dataTable.order-column tbody tr > .sorting_3, table.dataTable.display tbody tr > .sorting_1, 109 | table.dataTable.display tbody tr > .sorting_2, 110 | table.dataTable.display tbody tr > .sorting_3 { 111 | background-color: #f9f9f9; 112 | } 113 | table.dataTable.order-column tbody tr.selected > .sorting_1, 114 | table.dataTable.order-column tbody tr.selected > .sorting_2, 115 | table.dataTable.order-column tbody tr.selected > .sorting_3, table.dataTable.display tbody tr.selected > .sorting_1, 116 | table.dataTable.display tbody tr.selected > .sorting_2, 117 | table.dataTable.display tbody tr.selected > .sorting_3 { 118 | background-color: #acbad4; 119 | } 120 | table.dataTable.display tbody tr.odd > .sorting_1, table.dataTable.order-column.stripe tbody tr.odd > .sorting_1 { 121 | background-color: #f1f1f1; 122 | } 123 | table.dataTable.display tbody tr.odd > .sorting_2, table.dataTable.order-column.stripe tbody tr.odd > .sorting_2 { 124 | background-color: #f3f3f3; 125 | } 126 | table.dataTable.display tbody tr.odd > .sorting_3, table.dataTable.order-column.stripe tbody tr.odd > .sorting_3 { 127 | background-color: whitesmoke; 128 | } 129 | table.dataTable.display tbody tr.odd.selected > .sorting_1, table.dataTable.order-column.stripe tbody tr.odd.selected > .sorting_1 { 130 | background-color: #a6b3cd; 131 | } 132 | table.dataTable.display tbody tr.odd.selected > .sorting_2, table.dataTable.order-column.stripe tbody tr.odd.selected > .sorting_2 { 133 | background-color: #a7b5ce; 134 | } 135 | table.dataTable.display tbody tr.odd.selected > .sorting_3, table.dataTable.order-column.stripe tbody tr.odd.selected > .sorting_3 { 136 | background-color: #a9b6d0; 137 | } 138 | table.dataTable.display tbody tr.even > .sorting_1, table.dataTable.order-column.stripe tbody tr.even > .sorting_1 { 139 | background-color: #f9f9f9; 140 | } 141 | table.dataTable.display tbody tr.even > .sorting_2, table.dataTable.order-column.stripe tbody tr.even > .sorting_2 { 142 | background-color: #fbfbfb; 143 | } 144 | table.dataTable.display tbody tr.even > .sorting_3, table.dataTable.order-column.stripe tbody tr.even > .sorting_3 { 145 | background-color: #fdfdfd; 146 | } 147 | table.dataTable.display tbody tr.even.selected > .sorting_1, table.dataTable.order-column.stripe tbody tr.even.selected > .sorting_1 { 148 | background-color: #acbad4; 149 | } 150 | table.dataTable.display tbody tr.even.selected > .sorting_2, table.dataTable.order-column.stripe tbody tr.even.selected > .sorting_2 { 151 | background-color: #adbbd6; 152 | } 153 | table.dataTable.display tbody tr.even.selected > .sorting_3, table.dataTable.order-column.stripe tbody tr.even.selected > .sorting_3 { 154 | background-color: #afbdd8; 155 | } 156 | table.dataTable.display tbody tr:hover > .sorting_1, 157 | table.dataTable.display tbody tr.odd:hover > .sorting_1, 158 | table.dataTable.display tbody tr.even:hover > .sorting_1, table.dataTable.order-column.hover tbody tr:hover > .sorting_1, 159 | table.dataTable.order-column.hover tbody tr.odd:hover > .sorting_1, 160 | table.dataTable.order-column.hover tbody tr.even:hover > .sorting_1 { 161 | background-color: #eaeaea; 162 | } 163 | table.dataTable.display tbody tr:hover > .sorting_2, 164 | table.dataTable.display tbody tr.odd:hover > .sorting_2, 165 | table.dataTable.display tbody tr.even:hover > .sorting_2, table.dataTable.order-column.hover tbody tr:hover > .sorting_2, 166 | table.dataTable.order-column.hover tbody tr.odd:hover > .sorting_2, 167 | table.dataTable.order-column.hover tbody tr.even:hover > .sorting_2 { 168 | background-color: #ebebeb; 169 | } 170 | table.dataTable.display tbody tr:hover > .sorting_3, 171 | table.dataTable.display tbody tr.odd:hover > .sorting_3, 172 | table.dataTable.display tbody tr.even:hover > .sorting_3, table.dataTable.order-column.hover tbody tr:hover > .sorting_3, 173 | table.dataTable.order-column.hover tbody tr.odd:hover > .sorting_3, 174 | table.dataTable.order-column.hover tbody tr.even:hover > .sorting_3 { 175 | background-color: #eeeeee; 176 | } 177 | table.dataTable.display tbody tr:hover.selected > .sorting_1, 178 | table.dataTable.display tbody tr.odd:hover.selected > .sorting_1, 179 | table.dataTable.display tbody tr.even:hover.selected > .sorting_1, table.dataTable.order-column.hover tbody tr:hover.selected > .sorting_1, 180 | table.dataTable.order-column.hover tbody tr.odd:hover.selected > .sorting_1, 181 | table.dataTable.order-column.hover tbody tr.even:hover.selected > .sorting_1 { 182 | background-color: #a1aec7; 183 | } 184 | table.dataTable.display tbody tr:hover.selected > .sorting_2, 185 | table.dataTable.display tbody tr.odd:hover.selected > .sorting_2, 186 | table.dataTable.display tbody tr.even:hover.selected > .sorting_2, table.dataTable.order-column.hover tbody tr:hover.selected > .sorting_2, 187 | table.dataTable.order-column.hover tbody tr.odd:hover.selected > .sorting_2, 188 | table.dataTable.order-column.hover tbody tr.even:hover.selected > .sorting_2 { 189 | background-color: #a2afc8; 190 | } 191 | table.dataTable.display tbody tr:hover.selected > .sorting_3, 192 | table.dataTable.display tbody tr.odd:hover.selected > .sorting_3, 193 | table.dataTable.display tbody tr.even:hover.selected > .sorting_3, table.dataTable.order-column.hover tbody tr:hover.selected > .sorting_3, 194 | table.dataTable.order-column.hover tbody tr.odd:hover.selected > .sorting_3, 195 | table.dataTable.order-column.hover tbody tr.even:hover.selected > .sorting_3 { 196 | background-color: #a4b2cb; 197 | } 198 | table.dataTable.no-footer { 199 | border-bottom: 1px solid #111111; 200 | } 201 | table.dataTable.nowrap th, table.dataTable.nowrap td { 202 | white-space: nowrap; 203 | } 204 | table.dataTable.compact thead th, 205 | table.dataTable.compact thead td { 206 | padding: 5px 9px; 207 | } 208 | table.dataTable.compact tfoot th, 209 | table.dataTable.compact tfoot td { 210 | padding: 5px 9px 3px 9px; 211 | } 212 | table.dataTable.compact tbody th, 213 | table.dataTable.compact tbody td { 214 | padding: 4px 5px; 215 | } 216 | table.dataTable th.dt-left, 217 | table.dataTable td.dt-left { 218 | text-align: left; 219 | } 220 | table.dataTable th.dt-center, 221 | table.dataTable td.dt-center, 222 | table.dataTable td.dataTables_empty { 223 | text-align: center; 224 | } 225 | table.dataTable th.dt-right, 226 | table.dataTable td.dt-right { 227 | text-align: right; 228 | } 229 | table.dataTable th.dt-justify, 230 | table.dataTable td.dt-justify { 231 | text-align: justify; 232 | } 233 | table.dataTable th.dt-nowrap, 234 | table.dataTable td.dt-nowrap { 235 | white-space: nowrap; 236 | } 237 | table.dataTable thead th.dt-head-left, 238 | table.dataTable thead td.dt-head-left, 239 | table.dataTable tfoot th.dt-head-left, 240 | table.dataTable tfoot td.dt-head-left { 241 | text-align: left; 242 | } 243 | table.dataTable thead th.dt-head-center, 244 | table.dataTable thead td.dt-head-center, 245 | table.dataTable tfoot th.dt-head-center, 246 | table.dataTable tfoot td.dt-head-center { 247 | text-align: center; 248 | } 249 | table.dataTable thead th.dt-head-right, 250 | table.dataTable thead td.dt-head-right, 251 | table.dataTable tfoot th.dt-head-right, 252 | table.dataTable tfoot td.dt-head-right { 253 | text-align: right; 254 | } 255 | table.dataTable thead th.dt-head-justify, 256 | table.dataTable thead td.dt-head-justify, 257 | table.dataTable tfoot th.dt-head-justify, 258 | table.dataTable tfoot td.dt-head-justify { 259 | text-align: justify; 260 | } 261 | table.dataTable thead th.dt-head-nowrap, 262 | table.dataTable thead td.dt-head-nowrap, 263 | table.dataTable tfoot th.dt-head-nowrap, 264 | table.dataTable tfoot td.dt-head-nowrap { 265 | white-space: nowrap; 266 | } 267 | table.dataTable tbody th.dt-body-left, 268 | table.dataTable tbody td.dt-body-left { 269 | text-align: left; 270 | } 271 | table.dataTable tbody th.dt-body-center, 272 | table.dataTable tbody td.dt-body-center { 273 | text-align: center; 274 | } 275 | table.dataTable tbody th.dt-body-right, 276 | table.dataTable tbody td.dt-body-right { 277 | text-align: right; 278 | } 279 | table.dataTable tbody th.dt-body-justify, 280 | table.dataTable tbody td.dt-body-justify { 281 | text-align: justify; 282 | } 283 | table.dataTable tbody th.dt-body-nowrap, 284 | table.dataTable tbody td.dt-body-nowrap { 285 | white-space: nowrap; 286 | } 287 | 288 | table.dataTable, 289 | table.dataTable th, 290 | table.dataTable td { 291 | -webkit-box-sizing: content-box; 292 | -moz-box-sizing: content-box; 293 | box-sizing: content-box; 294 | } 295 | 296 | /* 297 | * Control feature layout 298 | */ 299 | .dataTables_wrapper { 300 | position: relative; 301 | clear: both; 302 | *zoom: 1; 303 | zoom: 1; 304 | } 305 | .dataTables_wrapper .dataTables_length { 306 | float: left; 307 | } 308 | .dataTables_wrapper .dataTables_filter { 309 | float: right; 310 | text-align: right; 311 | } 312 | .dataTables_wrapper .dataTables_filter input { 313 | margin-left: 0.5em; 314 | } 315 | .dataTables_wrapper .dataTables_info { 316 | clear: both; 317 | float: left; 318 | padding-top: 0.755em; 319 | } 320 | .dataTables_wrapper .dataTables_paginate { 321 | float: right; 322 | text-align: right; 323 | padding-top: 0.25em; 324 | } 325 | .dataTables_wrapper .dataTables_paginate .paginate_button { 326 | box-sizing: border-box; 327 | display: inline-block; 328 | min-width: 1.5em; 329 | padding: 0.5em 1em; 330 | margin-left: 2px; 331 | text-align: center; 332 | text-decoration: none !important; 333 | cursor: pointer; 334 | *cursor: hand; 335 | color: #333333 !important; 336 | border: 1px solid transparent; 337 | } 338 | .dataTables_wrapper .dataTables_paginate .paginate_button.current, .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover { 339 | color: #333333 !important; 340 | border: 1px solid #cacaca; 341 | background-color: white; 342 | background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, white), color-stop(100%, gainsboro)); 343 | /* Chrome,Safari4+ */ 344 | background: -webkit-linear-gradient(top, white 0%, gainsboro 100%); 345 | /* Chrome10+,Safari5.1+ */ 346 | background: -moz-linear-gradient(top, white 0%, gainsboro 100%); 347 | /* FF3.6+ */ 348 | background: -ms-linear-gradient(top, white 0%, gainsboro 100%); 349 | /* IE10+ */ 350 | background: -o-linear-gradient(top, white 0%, gainsboro 100%); 351 | /* Opera 11.10+ */ 352 | background: linear-gradient(to bottom, white 0%, gainsboro 100%); 353 | /* W3C */ 354 | } 355 | .dataTables_wrapper .dataTables_paginate .paginate_button.disabled, .dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover, .dataTables_wrapper .dataTables_paginate .paginate_button.disabled:active { 356 | cursor: default; 357 | color: #666 !important; 358 | border: 1px solid transparent; 359 | background: transparent; 360 | box-shadow: none; 361 | } 362 | .dataTables_wrapper .dataTables_paginate .paginate_button:hover { 363 | color: white !important; 364 | border: 1px solid #111111; 365 | background-color: #585858; 366 | background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #585858), color-stop(100%, #111111)); 367 | /* Chrome,Safari4+ */ 368 | background: -webkit-linear-gradient(top, #585858 0%, #111111 100%); 369 | /* Chrome10+,Safari5.1+ */ 370 | background: -moz-linear-gradient(top, #585858 0%, #111111 100%); 371 | /* FF3.6+ */ 372 | background: -ms-linear-gradient(top, #585858 0%, #111111 100%); 373 | /* IE10+ */ 374 | background: -o-linear-gradient(top, #585858 0%, #111111 100%); 375 | /* Opera 11.10+ */ 376 | background: linear-gradient(to bottom, #585858 0%, #111111 100%); 377 | /* W3C */ 378 | } 379 | .dataTables_wrapper .dataTables_paginate .paginate_button:active { 380 | outline: none; 381 | background-color: #2b2b2b; 382 | background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #2b2b2b), color-stop(100%, #0c0c0c)); 383 | /* Chrome,Safari4+ */ 384 | background: -webkit-linear-gradient(top, #2b2b2b 0%, #0c0c0c 100%); 385 | /* Chrome10+,Safari5.1+ */ 386 | background: -moz-linear-gradient(top, #2b2b2b 0%, #0c0c0c 100%); 387 | /* FF3.6+ */ 388 | background: -ms-linear-gradient(top, #2b2b2b 0%, #0c0c0c 100%); 389 | /* IE10+ */ 390 | background: -o-linear-gradient(top, #2b2b2b 0%, #0c0c0c 100%); 391 | /* Opera 11.10+ */ 392 | background: linear-gradient(to bottom, #2b2b2b 0%, #0c0c0c 100%); 393 | /* W3C */ 394 | box-shadow: inset 0 0 3px #111; 395 | } 396 | .dataTables_wrapper .dataTables_processing { 397 | position: absolute; 398 | top: 50%; 399 | left: 50%; 400 | width: 100%; 401 | height: 40px; 402 | margin-left: -50%; 403 | margin-top: -25px; 404 | padding-top: 20px; 405 | text-align: center; 406 | font-size: 1.2em; 407 | background-color: white; 408 | background: -webkit-gradient(linear, left top, right top, color-stop(0%, rgba(255, 255, 255, 0)), color-stop(25%, rgba(255, 255, 255, 0.9)), color-stop(75%, rgba(255, 255, 255, 0.9)), color-stop(100%, rgba(255, 255, 255, 0))); 409 | /* Chrome,Safari4+ */ 410 | background: -webkit-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 0.9) 75%, rgba(255, 255, 255, 0) 100%); 411 | /* Chrome10+,Safari5.1+ */ 412 | background: -moz-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 0.9) 75%, rgba(255, 255, 255, 0) 100%); 413 | /* FF3.6+ */ 414 | background: -ms-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 0.9) 75%, rgba(255, 255, 255, 0) 100%); 415 | /* IE10+ */ 416 | background: -o-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 0.9) 75%, rgba(255, 255, 255, 0) 100%); 417 | /* Opera 11.10+ */ 418 | background: linear-gradient(to right, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 0.9) 75%, rgba(255, 255, 255, 0) 100%); 419 | /* W3C */ 420 | } 421 | .dataTables_wrapper .dataTables_length, 422 | .dataTables_wrapper .dataTables_filter, 423 | .dataTables_wrapper .dataTables_info, 424 | .dataTables_wrapper .dataTables_processing, 425 | .dataTables_wrapper .dataTables_paginate { 426 | color: #333333; 427 | } 428 | .dataTables_wrapper .dataTables_scroll { 429 | clear: both; 430 | } 431 | .dataTables_wrapper .dataTables_scroll div.dataTables_scrollBody { 432 | *margin-top: -1px; 433 | -webkit-overflow-scrolling: touch; 434 | } 435 | .dataTables_wrapper .dataTables_scroll div.dataTables_scrollBody th > div.dataTables_sizing, 436 | .dataTables_wrapper .dataTables_scroll div.dataTables_scrollBody td > div.dataTables_sizing { 437 | height: 0; 438 | overflow: hidden; 439 | margin: 0 !important; 440 | padding: 0 !important; 441 | } 442 | .dataTables_wrapper.no-footer .dataTables_scrollBody { 443 | border-bottom: 1px solid #111111; 444 | } 445 | .dataTables_wrapper.no-footer div.dataTables_scrollHead table, 446 | .dataTables_wrapper.no-footer div.dataTables_scrollBody table { 447 | border-bottom: none; 448 | } 449 | .dataTables_wrapper:after { 450 | visibility: hidden; 451 | display: block; 452 | content: ""; 453 | clear: both; 454 | height: 0; 455 | } 456 | 457 | @media screen and (max-width: 767px) { 458 | .dataTables_wrapper .dataTables_info, 459 | .dataTables_wrapper .dataTables_paginate { 460 | float: none; 461 | text-align: center; 462 | } 463 | .dataTables_wrapper .dataTables_paginate { 464 | margin-top: 0.5em; 465 | } 466 | } 467 | @media screen and (max-width: 640px) { 468 | .dataTables_wrapper .dataTables_length, 469 | .dataTables_wrapper .dataTables_filter { 470 | float: none; 471 | text-align: center; 472 | } 473 | .dataTables_wrapper .dataTables_filter { 474 | margin-top: 0.5em; 475 | } 476 | } 477 | -------------------------------------------------------------------------------- /web_root/ocdb-client.js: -------------------------------------------------------------------------------- 1 | //var OCDBBASEURL = "///"+location.host+"/v1/"; 2 | var OCDBHOST = "localhost"; 3 | if(document.location.hash && document.location.hash.split("#ocdb=")[1]){ 4 | OCDBHOST = document.location.hash.split("#ocdb=")[1]; 5 | } 6 | 7 | var OCDBBASEURL = "https://"+OCDBHOST+"/v1/"; 8 | 9 | //ocdb related 10 | (function(){ 11 | 12 | var getCities = function(options, cb){ 13 | var url = OCDBBASEURL+"cities/?q=1"; 14 | if(options.lat) url+="&lat="+options.lat; 15 | if(options.lon) url+="&lon="+options.lon; 16 | if(options.offset) url+="&offset="+options.offset; 17 | if(options.limit) url+="&limit="+options.limit; 18 | if(options.search) url+="&search="+options.search; 19 | sendRequest(url,cb,0); 20 | }; 21 | 22 | var getCity = function(options, cb){ 23 | var url = OCDBBASEURL+"cities/?q=1"; 24 | if(options.lat) url+="&lat="+options.lat; 25 | if(options.lon) url+="&lon="+options.lon; 26 | if(options.offset) url+="&offset=0"; 27 | if(options.limit) url+="&limit=1"; 28 | if(options.name) url+="&name="+options.name; 29 | sendRequest(url,cb,0); 30 | }; 31 | 32 | var postPoi = function(poi, cityid, options, cb){ 33 | var url = OCDBBASEURL+"cities/"+cityid+"/pois?q=1"; 34 | sendRequest(url,cb,poi); 35 | }; 36 | 37 | var getPois = function(cityid, options, cb){ 38 | var url = OCDBBASEURL+"cities/"+cityid+"/pois?q=1"; 39 | if(options.lat) url+="&lat="+options.lat; 40 | if(options.lon) url+="&lon="+options.lon; 41 | if(options.offset) url+="&offset="+options.offset; 42 | if(options.limit) url+="&limit="+options.limit; 43 | if(options.expand) url+="&expand="+options.expand; 44 | if(options.search) url+="&search="+options.search; 45 | sendRequest(url,cb,0); 46 | }; 47 | 48 | var getPoi = function(poiid, options, cb){ 49 | var url = OCDBBASEURL+"pois/"+poiid+"/?q=1"; 50 | if(options.expand) url+="&expand="+options.expand; 51 | sendRequest(url,cb,0); 52 | }; 53 | 54 | var checkinPoi = function(poiid, options, cb){ 55 | var url = OCDBBASEURL+"pois/"+poiid+"/checkin?q=1"; 56 | var body = {}; 57 | if(options.lat && options.lon) body.coords = [options.lon, options.lat]; 58 | sendRequest(url,cb,body); 59 | }; 60 | 61 | var commentPoi = function(poiid, options, cb){ 62 | var url = OCDBBASEURL+"pois/"+poiid+"/comment?q=1"; 63 | var body = {}; 64 | if(options.lat && options.lon) body.coords = [options.lon, options.lat]; 65 | if(options.comment) body.comment = options.comment; 66 | sendRequest(url,cb,body); 67 | }; 68 | 69 | var getPoiComments = function(poiid, options, cb){ 70 | var url = OCDBBASEURL+"pois/"+poiid+"/comment?q=1"; 71 | if(options.offset) url+="&offset="+options.offset; 72 | if(options.limit) url+="&limit="+options.limit; 73 | sendRequest(url,cb,0); 74 | }; 75 | 76 | var likePoi = function(poiid, options, cb){ 77 | var url = OCDBBASEURL+"pois/"+poiid+"/like?q=1"; 78 | var body = {}; 79 | if(options.lat && options.lon) body.coords = [options.lon, options.lat]; 80 | if(typeof options.like === "boolean") body.like = options.like; 81 | sendRequest(url,cb,body); 82 | }; 83 | 84 | var ratingPoi = function(poiid, options, cb){ 85 | var url = OCDBBASEURL+"pois/"+poiid+"/rating?q=1"; 86 | var body = {}; 87 | if(options.lat && options.lon) body.coords = [options.lon, options.lat]; 88 | if(typeof options.rating === "number") body.rating = options.rating; 89 | sendRequest(url,cb,body); 90 | }; 91 | 92 | var getMedia = function(poiid, options, cb){ 93 | var url = OCDBBASEURL+"pois/"+poiid+"/media?q=1"; 94 | if(options.offset) url+="&offset="+options.offset; 95 | if(options.limit) url+="&limit="+options.limit; 96 | sendRequest(url,cb,0); 97 | }; 98 | 99 | var removeMedia = function(mediaid, options, cb){ 100 | var url = OCDBBASEURL+"media/"+mediaid+"/?q=1"; 101 | sendRequest(url,cb,0,"DELETE"); 102 | }; 103 | 104 | var postMedia = function(media, poiid, options, cb){ 105 | var url = OCDBBASEURL+"pois/"+poiid+"/media?q=1"; 106 | sendRequest(url,cb,media); 107 | }; 108 | 109 | var updateMedia = function(media, options, cb){ 110 | if(!media._id) { 111 | cb(404,{}); 112 | return; 113 | } 114 | var url = OCDBBASEURL+"media/"+media._id+"?q=1"; 115 | sendRequest(url,cb,media); 116 | }; 117 | 118 | var authZ = false, uid = null; 119 | 120 | var login = function(email, password, cb){ 121 | if(!email || !password) { 122 | cb(404,{}); 123 | return; 124 | } 125 | var url = OCDBBASEURL+"users?a="+email+"&b="+password; 126 | sendRequest(url,function(e,r){ 127 | if(e || !r || !r.access_token){ 128 | authZ = false; 129 | uid = null; 130 | } else { 131 | authZ = r.access_token; 132 | uid = r.uid; 133 | } 134 | cb(e,r); 135 | }); 136 | }; 137 | 138 | var setAttributes = function(appPrefix, attributes, cb){ 139 | if(!appPrefix || !attributes) { 140 | cb(404,{}); 141 | return; 142 | } 143 | var url = OCDBBASEURL+"users"; 144 | sendRequest(url,cb,{p:appPrefix, r:attributes}); 145 | } 146 | 147 | var getAttributes = function(appPrefix, cb){ 148 | var url = OCDBBASEURL+"users?p="+appPrefix; 149 | sendRequest(url,cb); 150 | } 151 | 152 | var setAuthZ = function(_authZ){ 153 | authZ = _authZ; 154 | } 155 | 156 | var getUid = function(){ 157 | return uid; 158 | } 159 | 160 | var logout = function(cb){ 161 | var url = OCDBBASEURL+"users?a=&b="; 162 | sendRequest(url,function(e,r){ 163 | if(!e && r){ 164 | authZ = false; 165 | } 166 | cb(e,r); 167 | }); 168 | }; 169 | 170 | var register = function(name, email, password, cb){ 171 | if(!name || !email || !password) { 172 | cb(404,{}); 173 | return; 174 | } 175 | var url = OCDBBASEURL+"users"; 176 | sendRequest(url,cb,{n:name,a:email,b:password}); 177 | }; 178 | 179 | var distinctLocations = function(l1, l2){ 180 | if(!l1 || !l2) return true; 181 | //roughly check if new location is much different than the one we already know 182 | var R = 6371; 183 | var dLat = (l2.coords.latitude-l1.coords.latitude)*(Math.PI/180); 184 | var dLon = (l2.coords.longitude-l1.coords.longitude)*(Math.PI/180); 185 | var a = 186 | Math.sin(dLat/2) * Math.sin(dLat/2) + 187 | Math.cos((Math.PI/180)*(l1.coords.latitude)) * Math.cos((Math.PI/180)*(l2.coords.latitude)) * 188 | Math.sin(dLon/2) * Math.sin(dLon/2); 189 | var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 190 | var d = R * c; // Distance in km 191 | return d>0.1; 192 | }; 193 | 194 | if(!window.ocdb) window.ocdb={}; 195 | if(!window.ocdb.cities) window.ocdb.cities={}; 196 | window.ocdb.cities = { 197 | get:getCities 198 | }; 199 | window.ocdb.city = { 200 | get:getCity 201 | }; 202 | window.ocdb.pois = { 203 | get:getPois, 204 | post:postPoi 205 | }; 206 | window.ocdb.poi = { 207 | get:getPoi, 208 | getComments:getPoiComments, 209 | checkin:checkinPoi, 210 | comment:commentPoi, 211 | like:likePoi, 212 | rating:ratingPoi 213 | }; 214 | window.ocdb.media = { 215 | get:getMedia, 216 | post:postMedia, 217 | put:updateMedia, 218 | remove:removeMedia 219 | }; 220 | 221 | window.ocdb.user = { 222 | login:login, 223 | setAuthZ:setAuthZ, 224 | logout:logout, 225 | register:register, 226 | getUid:getUid, 227 | getAttributes:getAttributes, 228 | setAttributes:setAttributes 229 | } 230 | 231 | //XHR Tools 232 | var sendRequest = function(url,callback,postData,meth) { 233 | var req = createXMLHTTPObject(); 234 | if (!req) return callback("XHR not supported by this browser."); 235 | var method = (postData) ? "POST" : "GET"; 236 | method = (meth) ? meth : method; 237 | req.open(method,url,true); 238 | req.setRequestHeader('Accept','application/json'); 239 | if(authZ) req.setRequestHeader('Authorization','token '+authZ); 240 | if (postData) 241 | req.setRequestHeader('Content-type','application/json'); 242 | req.onreadystatechange = function () { 243 | if (req.readyState != 4) return; 244 | if (req.status == 401) { 245 | setAuthZ(false); 246 | //force app to reload in case of unauthorized access 247 | location.reload(); 248 | } 249 | try{ 250 | if (req.status != 200 && req.status != 304) { 251 | callback(req.status?req.status:"error",JSON.parse(req.responseText)); 252 | return; 253 | } 254 | var meta={}; 255 | var h,headersMap={},headers=req.getAllResponseHeaders().split('\n'); 256 | for(var i=0;i>>(32-b))}function P(a,b,c){return a^b^c}function A(a,b){var c=(b&0xFFFF)+(a&0xFFFF),d=(b>>>16)+(a>>>16)+(c>>>16);return((d&0xFFFF)<<16)|(c&0xFFFF)}var B="0123456789abcdef";return(function(a){var c=[],d=a.length*4,e;for(var i=0;i>2]>>((3-(i%4))*8);c.push(B.charAt((e>>4)&0xF)+B.charAt(e&0xF))}return c.join('')}((function(a,b){var c,d,e,f,g,h=a.length,v=0x67452301,w=0xefcdab89,x=0x98badcfe,y=0x10325476,z=0xc3d2e1f0,M=[];U(M,0x5a827999,20);U(M,0x6ed9eba1,20);U(M,0x8f1bbcdc,20);U(M,0xca62c1d6,20);a[b>>5]|=0x80<<(24-(b%32));a[(((b+65)>>9)<<4)+15]=b;for(var i=0;i>>16)+(a>>>16)+(b>>>16)+(c>>>16)+(d>>>16)+(f>>>16);return((g&0xFFFF)<<16)|(f&0xFFFF)})(j<20?(function(t,a,b){return(t&a)^(~t&b)}(d,e,f)):j<40?P(d,e,f):j<60?(function(t,a,b){return(t&a)^(t&b)^(a&b)}(d,e,f)):P(d,e,f),g,M[j],O[j],L(c,5));g=f;f=e;e=L(d,30);d=c;c=k}v=A(v,c);w=A(w,d);x=A(x,e);y=A(y,f);z=A(z,g)}return[v,w,x,y,z]}((function(t){var a=[],b=255,c=t.length*8;for(var i=0;i>5]|=(t.charCodeAt(i/8)&b)<<(24-(i%32))}return a}(s)).slice(),s.length*8))))} 297 | 298 | window.ocdb.tools = { 299 | sendRequest: sendRequest, 300 | SHA1: SHA1 301 | } 302 | 303 | //load from ocdb host to trigger certificate consent dialog 304 | /* getCities({lat:53,lon:13,offset:0,limit:1},function(err,res){ 305 | if(err){ 306 | document.location.href=OCDBBASEURL+"frontend/ocdb.html"; 307 | } 308 | }); 309 | */ 310 | 311 | })(); 312 | 313 | -------------------------------------------------------------------------------- /web_root/ocdb.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

DEV MODE

8 | Accept your self signed certificate and go back 9 | 10 | 11 | -------------------------------------------------------------------------------- /web_root/playground/README.md: -------------------------------------------------------------------------------- 1 | OCDB - Playground Example App 2 | ============================= 3 | 4 | Simple "Hello world"-like example showcasing the uasge of the OCDB service. 5 | Just serve the index.* files by your Web server, surf the location and follow 6 | the instructions. 7 | 8 | If OCDB service is running then the example is available at [https://localhost/v1/frontend/playground/](https://localhost/v1/frontend/playground/) 9 | 10 | At the [project's web page](http://fraunhoferfokus.github.io/OCDB/) a hosted version of this example is linked. 11 | 12 | License 13 | ------- 14 | ``` 15 | /******************************************************************************* 16 | * 17 | * Licensed under the Apache License, Version 2.0 (the "License"); 18 | * you may not use this file except in compliance with the License. 19 | * You may obtain a copy of the License at 20 | * 21 | * http://www.apache.org/licenses/LICENSE-2.0 22 | * 23 | * Unless required by applicable law or agreed to in writing, software 24 | * distributed under the License is distributed on an "AS IS" BASIS, 25 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | * See the License for the specific language governing permissions and 27 | * limitations under the License. 28 | * 29 | * Copyright 2015 Fraunhofer FOKUS 30 | *******************************************************************************/ 31 | ``` 32 | -------------------------------------------------------------------------------- /web_root/playground/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | OCDB - Playground Example App 8 | 9 | 10 | 11 | 12 | 13 |

Simply, getting a list of cities around your current position:

14 |
15 | after registering at the frontend ...type in 16 |
17 | 18 | 19 | 20 | and (* make sure your Wi-Fi is turned on) 21 | 22 |
    23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /web_root/playground/index.js: -------------------------------------------------------------------------------- 1 | window.onload=function(){ 2 | 3 | document.querySelector("#getCities").addEventListener("click",function(){ 4 | ocdb.user.login( 5 | ocdb.tools.SHA1(document.querySelector("#a").value), 6 | ocdb.tools.SHA1(document.querySelector("#b").value), 7 | loginCallback 8 | ); 9 | }) 10 | 11 | var loginCallback = function(err, res){ 12 | if(err||!res||!res.access_token){ 13 | document.querySelector("#list").innerHTML="access denied!"; 14 | return; 15 | } 16 | document.querySelector("#list").innerHTML="loading...be pacient."; 17 | navigator.geolocation.getCurrentPosition( 18 | function(){ 19 | ocdb.cities.get({lat:52,lon:13},function(err, res){ 20 | if(err||!res||!res.length){ 21 | document.querySelector("#list").innerHTML= 22 | "
  • error: "+err+" with result "+JSON.stringify(res)+"
  • "; 23 | return; 24 | } 25 | var list=""; 26 | for(var i=0; i"; 28 | } 29 | document.querySelector("#list").innerHTML=list; 30 | }); 31 | 32 | }, 33 | function(){ 34 | document.querySelector("#list").innerHTML="Wi-Fi activated?"; 35 | } 36 | ); 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /web_root/root.html: -------------------------------------------------------------------------------- 1 | 2 |
     3 | Public OCDB instance.
     4 | =====================
     5 | 
     6 | USAGE ON A "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
     7 | 
     8 | We highly encourage to set up an own instance.
     9 | For more information visit
    10 | 
    11 | http://fraunhoferfokus.github.io/OCDB/ 12 | 13 | -------------------------------------------------------------------------------- /web_root/style.css: -------------------------------------------------------------------------------- 1 | #socials ul{ 2 | list-style: none inside; 3 | -webkit-padding-start: 0px; 4 | padding-start: 0px; 5 | } 6 | 7 | .logoutPane { 8 | display: none; 9 | } 10 | --------------------------------------------------------------------------------