[Fusionforge-commits] r11806 - in trunk/src/plugins/oslc/include/oslc-zend/application: controllers models views/scripts/fusionforgecm

Sabri LABBENE labbenes at libremir.placard.fr.eu.org
Wed Dec 15 13:33:53 CET 2010


Author: labbenes
Date: 2010-12-15 13:33:53 +0100 (Wed, 15 Dec 2010)
New Revision: 11806

Added:
   trunk/src/plugins/oslc/include/oslc-zend/application/views/scripts/fusionforgecm/oslc-service-catalog-project.phtml
Modified:
   trunk/src/plugins/oslc/include/oslc-zend/application/controllers/FusionForgeCmController.php
   trunk/src/plugins/oslc/include/oslc-zend/application/controllers/FusionForgeOSLCConnector.php
   trunk/src/plugins/oslc/include/oslc-zend/application/models/fusionforge.inc.php
   trunk/src/plugins/oslc/include/oslc-zend/application/views/scripts/fusionforgecm/_service-catalog_xml.php
Log:
Fix bug #228.
- OSLC services are FusionForge projects.
- OSLC-CM services of a FusionForge project lists trackers in a project.
- OSLC-CM service document describes a FusionForge tracker capabilities.



Modified: trunk/src/plugins/oslc/include/oslc-zend/application/controllers/FusionForgeCmController.php
===================================================================
--- trunk/src/plugins/oslc/include/oslc-zend/application/controllers/FusionForgeCmController.php	2010-12-15 09:24:06 UTC (rev 11805)
+++ trunk/src/plugins/oslc/include/oslc-zend/application/controllers/FusionForgeCmController.php	2010-12-15 12:33:53 UTC (rev 11806)
@@ -40,12 +40,18 @@
 	 * @var array
 	 */
 	private static $supportedAcceptMimeTypes = array();
-
+	private static $fusionforgeSupportedAcceptMimeTypes = array(
+		'oslcServiceCatalogProject' => array(
+			'application/x-oslc-disc-service-provider-catalog+xml' => 'xml',
+		 	'application/xml' => 'xml',
+			'application/json' => 'json'
+		),
+	);
 	/**
 	 * Init FusionForge REST controller.
 	 */
 	public function init(){
-		self::$supportedAcceptMimeTypes = parent::getSupportedAcceptMimeTypes();
+		self::$supportedAcceptMimeTypes = array_merge(parent::getSupportedAcceptMimeTypes(), self::$fusionforgeSupportedAcceptMimeTypes);
 		
 		// TODO : render this path configurable
 		//		$writer = new Zend_Log_Writer_Stream('/tmp/zend-log.txt');
@@ -115,11 +121,20 @@
 
 		// handle OSLC services catalog access (http://open-services.net/bin/view/Main/OslcServiceProviderCatalogV1)
 		if ( isset($params['id']) && ($params['id'] == "oslc-services")) {
-			$this->_forward('oslcServiceCatalog');
+				$this->_forward('oslcServiceCatalog');
+				return;
+		}
+		
+		// Handle OSLC-CM services catalog for specific project
+		// An OSLC-CM services catalog in FusionForge lists all the trackers 
+		// of a specific project.
+		elseif (isset($params['oslc-cm-services'])){
+			$this->_forward('oslcServiceCatalogProject');
 			return;
 		}
 		
 		// handle OSLC-CM service document access
+		// An OSLC-CM service document describes capabilities of a FusionForge tracker.
 		elseif (isset($params['oslc-cm-service'])) {
 			$this->_forward('oslcCmServiceDocument');
 			return;
@@ -474,6 +489,8 @@
 	
 	/**
 	 * Handle OSLC services catalog access (http://open-services.net/bin/view/Main/OslcServiceProviderCatalogV1)
+	 * Will show the list of prjects.
+	 * 
 	 */
 	public function oslcservicecatalogAction() {
 		
@@ -491,6 +508,31 @@
 		
 		$this->getResponse()->setHeader('Content-Type', $content_type);
 	}
+	
+	/**
+	 * Handle OSLC services catalog access per project.
+	 * Accessed by uris like ".../cm/oslc-services/project/x"
+	 * where x is a project id.
+	 * 
+	 */
+	public function oslcservicecatalogprojectAction() {
+		$content_type = parent::checkSupportedActionMimeType(self::$supportedAcceptMimeTypes, $this->getRequest()->getActionName());
+		if (! $content_type) {
+			$this->_forward('UnknownAcceptType','error');
+			return;
+		}
+		
+		$req = $this->getRequest();
+		$params = $req->getParams();
+		
+		$project = $params['oslc-cm-services'];
+		$trackers = $this->oslc->getProjectTrackers($project);
+		
+		$this->view->project = $project;
+		$this->view->trackers = $trackers;
+		
+		$this->getResponse()->setHeader('Content-Type', $content_type);
+	}
 
 	/**
 	 * 
@@ -500,9 +542,8 @@
 	public function oslccmservicedocumentAction() {
 		$content_type = parent::checkSupportedActionMimeType(self::$supportedAcceptMimeTypes, $this->getRequest()->getActionName());
 		if (! $content_type) {
-		  //			print_r("error");
-		  $this->_forward('UnknownAcceptType','error');
-		  return;
+			$this->_forward('UnknownAcceptType','error');
+			return;
 		}
 		
 		$req = $this->getRequest();

Modified: trunk/src/plugins/oslc/include/oslc-zend/application/controllers/FusionForgeOSLCConnector.php
===================================================================
--- trunk/src/plugins/oslc/include/oslc-zend/application/controllers/FusionForgeOSLCConnector.php	2010-12-15 09:24:06 UTC (rev 11805)
+++ trunk/src/plugins/oslc/include/oslc-zend/application/controllers/FusionForgeOSLCConnector.php	2010-12-15 12:33:53 UTC (rev 11806)
@@ -40,6 +40,7 @@
 require_once $gfwww.'include/pre.php';
 
 require_once $gfwww.'tracker/include/ArtifactTypeHtml.class.php';
+require_once $gfcommon.'tracker/ArtifactTypeFactory.class.php';
 require_once $gfcommon.'tracker/ArtifactType.class.php';
 require_once $gfcommon.'tracker/ArtifactFactory.class.php';
 require_once $gfcommon.'include/Group.class.php';
@@ -673,6 +674,31 @@
 	
 	}
 	
+	/**
+	 * 
+	 * Returns a formatted array of trackers of a project
+	 * Trackers Array is indexed by tracker ids and for each one we set
+	 * the id, name and description.
+	 * 
+	 * @param int $project project id.
+	 * 
+	 * @return Array of trackers
+	 */
+	public function getProjectTrackers($project) {
+		$group = group_get_object($project);
+		$trackers = array();
+		$atf = new ArtifactTypeFactory($group);
+		foreach($atf->getArtifactTypes() as $at) {
+			$trackers[$at->getID()] = array(
+				'id'          => $at->getID(),
+				'group_id'    => $project,
+				'name'        => $at->getName(),
+				'description' => $at->getDescription()
+			);
+		}
+		return $trackers;
+	}
+	
 	public function getHttpAuthBasicResolver($login, $password) {
 		$basicResolver = new FusionForge_Http_Auth_Resolver($login, $password);
 		return $basicResolver;

Modified: trunk/src/plugins/oslc/include/oslc-zend/application/models/fusionforge.inc.php
===================================================================
--- trunk/src/plugins/oslc/include/oslc-zend/application/models/fusionforge.inc.php	2010-12-15 09:24:06 UTC (rev 11805)
+++ trunk/src/plugins/oslc/include/oslc-zend/application/models/fusionforge.inc.php	2010-12-15 12:33:53 UTC (rev 11806)
@@ -33,6 +33,8 @@
  * For FusionForge
  *  
  * @package FusionForgeModel 
+ * 
+ * @TODO: Replace helios_bt by OSLC ontology
  */
 
 /**
@@ -113,6 +115,7 @@
 							$resource[$field] = $value;
 						}
 					}
+					//TODO: Replace helios_bt by OSLC ontology
 					foreach ($changerequest->children('http://heliosplatform.sourceforge.net/ontologies/2010/05/helios_bt.owl') as $child) {
 						$field = $child->getName();
 						if(!$field){

Modified: trunk/src/plugins/oslc/include/oslc-zend/application/views/scripts/fusionforgecm/_service-catalog_xml.php
===================================================================
--- trunk/src/plugins/oslc/include/oslc-zend/application/views/scripts/fusionforgecm/_service-catalog_xml.php	2010-12-15 09:24:06 UTC (rev 11805)
+++ trunk/src/plugins/oslc/include/oslc-zend/application/views/scripts/fusionforgecm/_service-catalog_xml.php	2010-12-15 12:33:53 UTC (rev 11806)
@@ -27,6 +27,58 @@
 
 // Generate a OSLC-CM V1 Service Catalog document (http://open-services.net/bin/view/Main/OslcServiceProviderCatalogV1)
 
+function project_trackers_to_service_catalog($base_url, $trackers, $project) {
+	$doc = new DOMDocument();
+	$doc->formatOutput = true;
+	
+	$root = $doc->createElementNS("http://open-services.net/xmlns/discovery/1.0/", "oslc_disc:ServiceProviderCatalog");
+	$root = $doc->appendChild($root);
+
+	$child = $doc->createAttributeNS("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf:about");
+	$about = $root->appendChild($child);
+	$child = $doc->createTextNode("");
+	$child = $about->appendChild($child);
+
+	$child = $doc->createElementNS("http://purl.org/dc/terms/", "dc:title");
+	$title = $root->appendChild($child);
+
+	$child = $doc->createTextNode(TRACKER_TYPE. " Change management service provider catalog for project " . $project);
+	$child = $title->appendChild($child);
+
+	foreach ($trackers as $tracker) {
+			// entry
+			$child = $doc->createElementNS("http://open-services.net/xmlns/discovery/1.0/", "oslc_disc:entry");
+			$entry = $root->appendChild($child);
+
+			$child = $doc->createElementNS("http://open-services.net/xmlns/discovery/1.0/", "oslc_disc:ServiceProvider");
+			$sp = $entry->appendChild($child);
+			
+			$child = $doc->createElementNS("http://purl.org/dc/terms/", "dc:identifier");
+			$title = $sp->appendChild($child);
+			$child = $doc->createTextNode($tracker['id']);
+			$child = $title->appendChild($child);
+
+			$child = $doc->createElementNS("http://purl.org/dc/terms/", "dc:title");
+			$title = $sp->appendChild($child);
+			$child = $doc->createTextNode($tracker['name']);
+			$child = $title->appendChild($child);
+			
+			$child = $doc->createElementNS("http://purl.org/dc/terms/", "dc:description");
+			$title = $sp->appendChild($child);
+			$child = $doc->createTextNode($tracker['description']);
+			$child = $title->appendChild($child);
+
+			$child = $doc->createElementNS("http://open-services.net/xmlns/discovery/1.0/", "oslc_disc:services");
+			$services = $sp->appendChild($child);
+			$child = $doc->createAttributeNS("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf:resource");
+			$resource = $services->appendChild($child);
+			$child = $doc->createTextNode($base_url.'/cm/oslc-cm-service/'.$tracker['group_id'].'/tracker/'.$tracker['id']);
+			$child = $resource->appendChild($child);
+		
+	}
+	return $doc->saveXML();
+}
+
 function projects_to_service_catalog($base_url, $projects) {
 
 	$doc = new DOMDocument();
@@ -68,7 +120,7 @@
 			$services = $sp->appendChild($child);
 			$child = $doc->createAttributeNS("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf:resource");
 			$resource = $services->appendChild($child);
-			$child = $doc->createTextNode($base_url.'/cm/oslc-cm-service/'.$proj['id']);
+			$child = $doc->createTextNode($base_url.'/cm/oslc-cm-services/'.$proj['id']);
 			$child = $resource->appendChild($child);
 
 

Added: trunk/src/plugins/oslc/include/oslc-zend/application/views/scripts/fusionforgecm/oslc-service-catalog-project.phtml
===================================================================
--- trunk/src/plugins/oslc/include/oslc-zend/application/views/scripts/fusionforgecm/oslc-service-catalog-project.phtml	                        (rev 0)
+++ trunk/src/plugins/oslc/include/oslc-zend/application/views/scripts/fusionforgecm/oslc-service-catalog-project.phtml	2010-12-15 12:33:53 UTC (rev 11806)
@@ -0,0 +1,41 @@
+<?php
+/**
+ * This file is (c) Copyright 2010 by Sabri LABBENE, Institut
+ * TELECOM
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * This program has been developed in the frame of the HELIOS
+ * project with financial support of its funders.
+ *
+ */
+
+require_once('_service-catalog_xml.php');
+require_once('_add_hyperlinks.php');
+
+?>
+<body>
+<h1>OSLC-CM V1 Service Catalog document</h1>
+<pre>
+<?php
+	$xml = project_trackers_to_service_catalog($this->baseUrl(), $this->trackers, $this->project);
+	//print $xml;
+	$text = str_replace('>', '&gt;', str_replace('<', '&lt;', $xml));
+	$text = add_links($text, "http");
+	$text = add_links($text, $this->baseUrl());
+	echo $text;
+?>
+</pre>
+</body>




More information about the Fusionforge-commits mailing list