Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
Conflicts:
	README.md
	src/tdt/core/model/ResourcesModel.php
	src/tdt/core/strategies/DB.php
  • Loading branch information
Michiel Vancoillie committed Jan 31, 2013
2 parents d3c4cc0 + 68a152e commit 88b5f9b
Show file tree
Hide file tree
Showing 546 changed files with 1,564 additions and 216 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: php
services: mysql
php:
- "5.4"
- "5.3"
env:
- DB=mysql
before_script:
- composer install
- mysql -e 'create database myapp_test;'

script: phpunit tests/APITest.php
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# tdt/core

[![Build Status](https://travis-ci.org/tdt/core.png?branch=development)](https://travis-ci.org/tdt/core)

# Installation

To install The DataTank core, the best practice is to install [tdt/start](https://www.github.com/tdt/start), it contains an installer that load the necessary components to make the datatank structure work. Currently it will install [tdt/framework](https://www.github.com/tdt/framework) and [tdt/core](https://www.github.com/tdt/core).
To install the datatank core, the best practice is to install tdt/start. This repository is located at http://www.github.com/tdt/start and contains an installer that load the necessary
components to make the datatank structure work. Currently it will install the requirements for tdt/core found in the composer.json file.

This can be done by using [composer](http://getcomposer.org/) and performing <b>composer install</b> in the directory of the tdt/start location. You can recognize this location by the presence of a composer.json file.

Expand Down Expand Up @@ -30,7 +35,7 @@ example:
This will lead a URL passed by a HTTP GET request, existing out of any given string ending with a dot followed by a string representing a format, to our RController. This controller will then apply further logic to provide
this request of an answer.

If you want to use The DataTank core without the use of tdt/start, you can still fill out the config of tdt\core\utility\Config::setConfig($array) documented in the README of the tdt/framework.
If you want to use The DataTank core without the use of tdt/start, you can still fill out the config of tdt\core\utility\Config::setConfig($array).

### formatters

Expand Down Expand Up @@ -108,7 +113,7 @@ This section covers some problems encountered with The DataTank installed on a W

#### cURL execution of the TDTAdmin/Export not working

We could just let the user search for this problem by themselves, as it's a bit far from the datatank's focus. However, since export is a very handy functionality we want to make sure the user can
We could just let the user search for this problem by themselves, as it's a bit far from the datatank's focus. However, since export is a very handy functionality we want to make sure the user can
use it without much trouble. The one problem we've encountered with this is that the cURL binaries on wampserver aren't always the correct ones. The thing you should do is replace them by pre-compiled ones.

First of all shut down your wampserver completely, as replacing these binaries might cause inconsistencies in the log files of the wampserver that will cause failures while restarting the stack.
Expand Down
Empty file modified agpl-3.0.txt
100644 → 100755
Empty file.
Empty file modified composer.json
100644 → 100755
Empty file.
Empty file modified lib/gcp/lang-apollo.js
100644 → 100755
Empty file.
Empty file modified lib/gcp/lang-clj.js
100644 → 100755
Empty file.
Empty file modified lib/gcp/lang-css.js
100644 → 100755
Empty file.
Empty file modified lib/gcp/lang-go.js
100644 → 100755
Empty file.
Empty file modified lib/gcp/lang-hs.js
100644 → 100755
Empty file.
Empty file modified lib/gcp/lang-lisp.js
100644 → 100755
Empty file.
Empty file modified lib/gcp/lang-lua.js
100644 → 100755
Empty file.
Empty file modified lib/gcp/lang-ml.js
100644 → 100755
Empty file.
Empty file modified lib/gcp/lang-n.js
100644 → 100755
Empty file.
Empty file modified lib/gcp/lang-proto.js
100644 → 100755
Empty file.
Empty file modified lib/gcp/lang-scala.js
100644 → 100755
Empty file.
Empty file modified lib/gcp/lang-sql.js
100644 → 100755
Empty file.
Empty file modified lib/gcp/lang-tex.js
100644 → 100755
Empty file.
Empty file modified lib/gcp/lang-vb.js
100644 → 100755
Empty file.
Empty file modified lib/gcp/lang-vhdl.js
100644 → 100755
Empty file.
Empty file modified lib/gcp/lang-wiki.js
100644 → 100755
Empty file.
Empty file modified lib/gcp/lang-xq.js
100644 → 100755
Empty file.
Empty file modified lib/gcp/lang-yaml.js
100644 → 100755
Empty file.
Empty file modified lib/gcp/prettify.css
100644 → 100755
Empty file.
Empty file modified lib/gcp/prettify.js
100644 → 100755
Empty file.
Empty file modified lib/parse_engine.php
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions src/tdt/core/controllers/AController.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* Class inheriting from the AController from tdt\framework
* Class inheriting from the AController
* and adding some functionality specifically for Core controllers
*/

Expand Down Expand Up @@ -47,7 +47,7 @@ public function __construct() {
}

public function setFormat($format) {
$this->format_through_url = $format;
$this->format_through_url = $format;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/tdt/core/controllers/CUDController.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function HEAD($matches) {
$RController->HEAD($matches);
}

function PUT($matches) {
function PUT($matches) {

$packageresourcestring = $matches["packageresourcestring"];
$pieces = explode("/", $packageresourcestring);
Expand Down
27 changes: 20 additions & 7 deletions src/tdt/core/controllers/RController.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function GET($matches) {
*/
if ($resourcename == "") {
$packageDoc = $model->getAllPackagesDoc();
$allPackages = array_keys(get_object_vars($packageDoc));
$allPackages = array_keys(get_object_vars($packageDoc));
$linkObject = new \stdClass();
$links = array();

Expand All @@ -83,7 +83,7 @@ public function GET($matches) {
}

if (isset($doc->$package)) {
$resourcenames = get_object_vars($doc->$package);
$resourcenames = get_object_vars($doc->$package);
foreach ($resourcenames as $resourcename => $value) {
$link = $this->hostname . $this->subdir . $package . "/" . $resourcename;
$links[] = $link;
Expand All @@ -97,7 +97,7 @@ public function GET($matches) {
//This will create an instance of a factory depending on which format is set
$this->formatterfactory = FormatterFactory::getInstance($matches["format"]);

$printer = $this->formatterfactory->getPrinter(strtolower($package), $linkObject);
$printer = $this->formatterfactory->getPrinter($package, $linkObject);
$printer->printAll();

exit();
Expand Down Expand Up @@ -170,9 +170,22 @@ public function GET($matches) {
$o->$RESTresource = $result;
$result = $o;

/**
* Before printing the object, check the headers
* For example, a Link header may be set in order to foresee in paging!
* The controller can enhance this header by replacing the standard .about redirect
* by the format given by the user.
*/
foreach(headers_list() as $header){
if(substr($header,0,4) == "Link"){
$header = str_replace(".about",".".$matches["format"],$header);
header($header);
}
}

// get the according formatter from the factory
$printer = $this->formatterfactory->getPrinter($resourcename, $result);
$printer->printAll();
$printer = $this->formatterfactory->getPrinter($resourcename, $result);
$printer->printAll();
}

private function getAllSubPackages($package, &$linkObject, &$links) {
Expand Down Expand Up @@ -308,7 +321,7 @@ public function HEAD($matches) {
//This will create an instance of a factory depending on which format is set
$this->formatterfactory = FormatterFactory::getInstance($matches["format"]);

$printer = $this->formatterfactory->getPrinter(strtolower($package), $linkObject);
$printer = $this->formatterfactory->getPrinter($package, $linkObject);
$printer->printHeader();
exit();
}
Expand Down Expand Up @@ -401,7 +414,7 @@ public function HEAD($matches) {
$result = $o;

// get the according formatter from the factory
$printer = $this->formatterfactory->getPrinter(strtolower($resourcename), $result);
$printer = $this->formatterfactory->getPrinter($resourcename, $result);
$printer->printHeader();
}

Expand Down
Empty file modified src/tdt/core/controllers/README.md
100644 → 100755
Empty file.
Empty file modified src/tdt/core/controllers/RedirectController.php
100644 → 100755
Empty file.
61 changes: 55 additions & 6 deletions src/tdt/core/controllers/SPECTQLController.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use tdt\core\utility\RequestURI;
use tdt\exceptions\TDTException;
use app\core\Config;
use tdt\core\universalfilter\interpreter\debugging\TreePrinter;

class SPECTQLController extends AController {

Expand Down Expand Up @@ -116,12 +117,12 @@ public function GET($matches) {
* uncomment to view the Querytree from the spectql query
*/
/*
$treePrinter = new TreePrinter();
$tree = $treePrinter->treeToString($universalquery);
echo "<pre>";
echo $tree;
echo "</pre>";
*/
$treePrinter = new TreePrinter();
$tree = $treePrinter->treeToString($universalquery);
echo "<pre>";
echo $tree;
echo "</pre>";
*/

$interpreter = new UniversalInterpreter(new UniversalFilterTableManager());
$result = $interpreter->interpret($universalquery);
Expand All @@ -140,6 +141,54 @@ public function GET($matches) {
$formatterfactory->setFormat($format);
$rootname = "spectqlquery";

/**
* adjust header if given from the read() of a resource
*/
foreach(headers_list() as $header){
if(substr($header,0,4) == "Link"){
$ru = RequestURI::getInstance(Config::getConfigArray());
$pageURL = $ru->getURI();
$new_link_header= "Link:";


/**
* Link to next
* Get the link to next, if present
* Adjust the spectql query URL with the next limit(..,..) and format
*/
$matches = array();
if(preg_match('/page=(.*)&page_size=(.*);rel=next.*/',$header,$matches)){
$query_matches = array();
preg_match('/(.*)\.limit\(.*\)?(:.*)/',$pageURL,$query_matches);
$next_query_url = $query_matches[1];
$limit = $matches[2];
$offset = $limit * ($matches[1] -1 );
$next_query_url.= ".limit(" . $offset . "," . $limit . "):" . $format;
$new_link_header.= $next_query_url . ";rel=next;";
}

/**
* Link to previous
*/
$matches = array();
if(preg_match('/page=(\d{1,})&page_size=(\d{1,});rel=previous.*/',$header,$matches)){
$query_matches = array();
preg_match('/(.*)\.limit\(.*\)?(:.*)/',$pageURL,$query_matches);
$next_query_url = $query_matches[1];
$limit = $matches[2];
$offset = $limit * ($matches[1] -1 );
$next_query_url.= ".limit(" . $offset . "," . $limit . "):" . $format;
$new_link_header.= $next_query_url . ";rel=previous";
}

$new_link_header = rtrim($new_link_header,";");
/**
* Set the adjusted Link header
*/

header($new_link_header);
}
}

$printer = $formatterfactory->getPrinter(strtolower($rootname), $result);
$printer->printAll();
Expand Down
Empty file modified src/tdt/core/controllers/SQL/README.md
100644 → 100755
Empty file.
Empty file modified src/tdt/core/controllers/SQL/READMEgrammar.txt
100644 → 100755
Empty file.
Empty file modified src/tdt/core/controllers/SQL/SQLGrammarFunctions.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/controllers/spectql/README.md
100644 → 100755
Empty file.
Empty file modified src/tdt/core/controllers/spectql/SPECTQLParser.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/controllers/spectql/SPECTQLResource.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/controllers/spectql/SPECTQLTokenizer.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/controllers/spectql/SPECTQLTools.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/controllers/spectql/spectql.class
100644 → 100755
Empty file.
Empty file modified src/tdt/core/controllers/spectql/spectql.lime
100644 → 100755
Empty file.
Empty file modified src/tdt/core/controllers/spectql/spectql.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/formatters/AFormatter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/formatters/CsvFormatter.php
100644 → 100755
Empty file.
19 changes: 16 additions & 3 deletions src/tdt/core/formatters/FormatterFactory.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static function getInstance($urlformat = "") {
* @param string $urlformat The format of the request i.e. json,xml,....
*/
public function setFormat($urlformat) {

//We define the format like this:
// * Check if $urlformat has been set
// - if not: probably something fishy happened, set format as error for logging purpose
Expand All @@ -47,19 +48,31 @@ public function setFormat($urlformat) {
$urlformat = ucfirst(strtolower($urlformat));

if (strtolower($urlformat) == "about" || $urlformat == "") { //urlformat can be empty on SPECTQL query
$cn = new ContentNegotiator();

/**
* Prepare
*/
$default = Config::get("general","defaultformat");
$config = array();
$config["log_dir"] = Config::get("general","logging","path");
$config["enabled"] = Config::get("general","logging","enabled");

$cn = new ContentNegotiator($default,$config);
$format = $cn->pop();

while (!$this->formatExists($format) && $cn->hasNext()) {
$format = $cn->pop();
if ($format == "*") {
$format == "Xml";
}
}

if (!$this->formatExists($format)) {
$this->format = Config::get("general", "defaultformat");
//$exception_config = array(); $exception_config["log_dir"] = Config::get("general","logging","path"); $exception_config["url"] = Config::get("general","hostname") . Config::get("general","subdir") . "error"; throw new TDTException(451,array($format),$exception_config); // could not find a suitible format
$this->format = Config::get("general", "defaultformat");
}

$this->format = $format;

//We've found our format through about, so let's set the header for content-location to the right one
//to do this we're building our current URL and changing .about in .format
$format = strtolower($this->format);
Expand Down
Empty file modified src/tdt/core/formatters/HtmlFormatter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/formatters/HtmltableFormatter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/formatters/JsonFormatter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/formatters/JsonpFormatter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/formatters/KmlFormatter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/formatters/N3Formatter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/formatters/NtFormatter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/formatters/PhpFormatter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/formatters/README.md
100644 → 100755
Empty file.
Empty file modified src/tdt/core/formatters/RdfFormatter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/formatters/RhtmlFormatter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/formatters/RjsonFormatter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/formatters/TtlFormatter.php
100644 → 100755
Empty file.
8 changes: 5 additions & 3 deletions src/tdt/core/formatters/XmlFormatter.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ public function printHeader() {

public function printBody() {
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
$rootname = $this->rootname;
$rootname = $this->rootname;

if (!isset($this->objectToPrint->$rootname)) {
$rootname = ucfirst($this->rootname);
if (!isset($this->objectToPrint->$rootname)) {
$this->rootname = $rootname;
$wrapper = new \stdClass();
$wrapper->$rootname = $this->objectToPrint;
$this->objectToPrint = $wrapper;
}

/*
Expand Down
Empty file modified src/tdt/core/formatters/visualizations/BarFormatter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/formatters/visualizations/ChartdataFormatter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/formatters/visualizations/ColumnFormatter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/formatters/visualizations/GridFormatter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/formatters/visualizations/MapFormatter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/formatters/visualizations/PieFormatter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/formatters/visualizations/README.md
100644 → 100755
Empty file.
Empty file modified src/tdt/core/model/AResourceFactory.php
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion src/tdt/core/model/CoreResourceFactory.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct() {
}

protected function getAllResourceNames() {
return array("TDTInfo" => array("Resources", "Packages", "Exceptions", "Admin", "Formatters", "Visualizations"),
return array("TDTInfo" => array("Resources", "Packages","Admin", "Formatters", "Visualizations","Statistics"),
"TDTAdmin" => array("Resources", "Export")
);
}
Expand Down
15 changes: 15 additions & 0 deletions src/tdt/core/model/DBQueries.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,21 @@ static function deleteGenericResource($package, $resource) {
);
}

/**
* Delete a strategy entry
*/
static function deleteStrategy($package,$resource,$table){
return R::exec(
"DELETE FROM $table
WHERE gen_resource_id IN
(SELECT generic_resource.id FROM generic_resource,package,resource
WHERE resource.resource_name=:resource
and package.package_name=:package
and resource_id = resource.id
and package.id=package_id)", array(":package" => $package, ":resource" => $resource)
);
}

/**
* Retrieve a specific remote resource
*/
Expand Down
6 changes: 3 additions & 3 deletions src/tdt/core/model/Doc.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ public function __construct() {
*/

private function prepareCacheConfig() {
$cache_config = array();
$cache_config = array();

$cache_config["system"] = Config::get("general", "cache", "system");
$cache_config["host"] = Config::get("general", "cache", "host");
$cache_config["port"] = Config::get("general", "cache", "port");

$cache_config["port"] = Config::get("general", "cache", "port");
return $cache_config;
}

Expand Down
Empty file modified src/tdt/core/model/GenericResourceFactory.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/model/InstalledResourceFactory.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/model/README.md
100644 → 100755
Empty file.
Empty file modified src/tdt/core/model/RemoteResourceFactory.php
100644 → 100755
Empty file.
9 changes: 5 additions & 4 deletions src/tdt/core/model/ResourcesModel.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -642,24 +642,25 @@ public function isResourceIFilter($package, $resource) {
if ($factory->hasResource($package, $resource)) {

// remote resource just proxies the url so we don't need to take that into account
if (get_class($factory) == "GenericResourceFactory") {
if (get_class($factory) == "tdt\core\model\GenericResourceFactory") {

$genericResource = new GenericResource($package, $resource);
$strategy = $genericResource->getStrategy();

$interfaces = class_implements($strategy);

if (in_array("IFilter", $interfaces)) {

if (in_array("tdt\\core\\model\\resources\\read\IFilter", $interfaces)) {
return $genericResource;
} else {
return FALSE;
}
} elseif (get_class($factory) == "InstalledResourceFactory") {
} elseif (get_class($factory) == "tdt\core\model\InstalledResourceFactory") {

$reader = $factory->createReader($package, $resource, array(), array());
$interfaces = class_implements($reader);

if (in_array("IFilter", $interfaces)) {
if (in_array("tdt\\core\\model\\resources\\read\IFilter", $interfaces)) {
return $reader;
} else {
return FALSE;
Expand Down
Empty file modified src/tdt/core/model/filters/AFilter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/model/filters/FilterFactory.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/model/filters/RESTFilter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/model/filters/SearchFilter.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/model/packages/README.md
100644 → 100755
Empty file.
Empty file modified src/tdt/core/model/packages/TDTAdmin/TDTAdminExport.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/model/packages/TDTAdmin/TDTAdminResources.php
100644 → 100755
Empty file.
Empty file modified src/tdt/core/model/packages/TDTInfo/TDTInfoAdmin.php
100644 → 100755
Empty file.

3 comments on commit 88b5f9b

@pietercolpaert
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File modes 644 tot 755. Why?

@dive-michiel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coreation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woops! Did not know file permissions were something that could be pushed as well. Was trying to figure out why git couldnt change files probably.

Please sign in to comment.