4 * ProjectImporter Class
7 * This file is part of FusionForge.
9 * FusionForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with GForge; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 // Include standard ARC library
25 include_once("arc/ARC2.php");
26 // Include the JSON RDF parser ala OSLC developped in COCLICO
27 include_once('ARC2_OSLCCoreRDFJSONParserPlugin.php');
29 #require_once $gfcommon.'import/import_users.php';
31 //require_once $gfcommon.'import/import_trackers.php';
34 define('FORGEPLUCKER_NS', 'http://planetforge.org/ns/forgeplucker_dump/');
35 define('PLANETFORGE_NS', 'http://coclico-project.org/ontology/planetforge#');
37 class ImportedProject {
39 function ImportedProject($res) {
41 /* $this->name = $res->getPropValue('doap:name');
42 $this->description = $res->getPropValue('dcterms:description');
43 $this->homepage = $res->getPropValue('doap:homepage');
44 $this->hosted_by = $res->getPropValue('planetforge:hosted_by');
46 $this->roles = array();
47 $roles = $res->getPropValues('sioc:scope_of');
48 foreach($roles as $role) {
49 $importer = ProjectImporter::getInstance();
50 $roleres = ProjectImporter::make_resource($role);
51 $role_obj = new ImportedProjectRole($this, $roleres);
52 $this->roles[] = $role_obj;
57 * Returns a project's name
60 return $this->res->getPropValue('doap:name');
64 * Return a project's description
66 function getDescription() {
67 return $this->res->getPropValue('dcterms:description');
71 * Return the spaces used by a project
72 * @param ARC2 resource $projectres
73 * @return array of ARC2 resources
75 function getSpaces() {
80 $importer = ProjectImporter::getInstance();
82 $spaces = $this->res->getPropValues('sioc:has_space');
83 foreach ($spaces as $space) {
84 $spaceres = ProjectImporter::make_resource($space);
85 $provider = $spaceres->getPropValue('planetforge:provided_by');
86 if (! $importer->supportsTool($provider)) {
87 $feedback .= 'error : no supported provider for '. $space .': '. $provider."!\n";
90 $results[$space] = $spaceres;
101 class ImportedProjectRole {
106 function ImportedProjectRole(& $project, $res) {
107 $this->project = $project;
108 $this->name = $res->getPropValue('sioc:name');
109 $this->users = $res->getPropValues('sioc:function_of');
110 //print_r('Role: ' .$this->name);
111 //print_r('Users: ');
112 //print_r($this->users);
119 function getUsers() {
125 protected $initial_role;
128 * TODO Enter description here ...
129 * @author Olivier Berger
132 class ProjectImporter {
133 private static $_instance ;
136 * Index of all triples imported
141 protected $project_dump_res;
144 * Users descriptions found in the dump
145 * @var array of ARC2 resources (keys are URIs)
154 * User names for the users found in the dump
155 * @var array of strings (keys are URIs)
157 protected $user_names;
159 protected $user_roles;
162 * Enter description here ...
165 protected $providers;
168 * Enter description here ...
171 static $allowedprovidertypes = array('planetforge:TrackersTool',
172 'planetforge:ForumsTool',
173 'planetforge:DocumentsTool',
174 'planetforge:MailingListTool',
175 'planetforge:TaskTool',
176 'planetforge:ScmTool',
177 'planetforge:NewsTool',
178 'planetforge:FilesReleasesTool',
179 'planetforge:SvnScmTool');
182 * Enter description here ...
186 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
187 'foaf' => 'http://xmlns.com/foaf/0.1/',
188 'dcterms' => 'http://purl.org/dc/terms/',
189 'oslc' => 'http://open-services.net/ns/core#',
190 'oslc_cm' => 'http://open-services.net/ns/cm#',
191 'forgeplucker' => FORGEPLUCKER_NS,
192 'doap' => 'http://usefulinc.com/ns/doap#',
193 'sioc' => 'http://rdfs.org/sioc/ns#',
194 'planetforge' => PLANETFORGE_NS
197 public static function getInstance() {
198 if (!isset(self::$_instance)) {
200 self::$_instance = new $c;
203 return self::$_instance;
207 * TODO Enter description here ...
208 * @param unknown_type $group_id
210 function ProjectImporter($the_group_id = FALSE) {
212 if (! $the_group_id) {
213 $the_group_id = $group_id;
215 self::$_instance = $this;
216 $this->group_id = $the_group_id;
217 $this->index = False;
220 $this->trackers = array();
221 $this->users = False;
222 $this->persons = False;
223 $this->project_dump_res = False;
224 $this->user_names = array();
225 $this->user_roles = array();
230 * Converts the JSON RDF ala OSLC to ARC2 triples
231 * @param string $json
234 function parse_OSLCCoreRDFJSON($json)
236 $conf = array('ns' => ProjectImporter::$ns);
238 // "load" the ARC2 plugin to parse RDF ala OSLC in JSON
239 $parser = ARC2::getComponent("OSLCCoreRDFJSONParserPlugin", $conf);
242 $arr = json_decode($json, true);
244 // $feedback = "JSON decoded to :";
245 // $message .= '<pre>'. nl2br(print_r($arr, true)) . '</pre>';
248 foreach($arr as $type => $tabType){
249 // $message .= 'type: '.$type.'<br />';
250 // $message .= '<pre>'. nl2br(print_r($tabType, true)) . '</pre>';
255 elseif($type=="roles"){
258 elseif($type=="trackers"){
259 $trackers = $tabType;
261 elseif($type=="docman"){
264 elseif($type=="frs"){
267 elseif($type=='forums'){
270 elseif($type=='forgeplucker:trackers') {
271 foreach($tabType as $bar)
273 $result = json_encode($bar);
277 elseif($type=='prefixes') {
278 $prefixes = $tabType;
281 $result['prefixes']=$prefixes;
282 $message .= '<pre>'. nl2br(print_r($arr, true)) . '</pre>';
283 $arr = $parser->parseData($result);
285 $parser->parseData($json);
286 $triples = $parser->getTriples();
288 // print_r($triples);
289 $this->index = ARC2::getSimpleIndex($triples, false);
294 * Creates an ARC2 resource
295 * @param ARC2 triples index $index
297 * @return ARC2 resource
299 static function make_resource($uri) {
300 $importer = ProjectImporter::getInstance();
301 $index = $importer->index;
302 $conf = array('ns' => ProjectImporter::$ns);
303 $res = ARC2::getResource($conf);
304 $res->setIndex($index);
310 * Returns a Dump object for the index, whose rdf:type is http://planetforge.org/ns/forgeplucker_dump/project_dump#
311 * @return ARC2 resource
313 protected function project_dump() {
314 if (! is_array($this->project_dump_res)) {
318 foreach ($this->index as $uri => $resource) {
319 $res = ProjectImporter::make_resource($uri);
320 if ($res->hasPropValue('rdf:type', 'http://planetforge.org/ns/forgeplucker_dump/project_dump#')) {
321 // if ($this->is_project_dump($resource)) {
326 // found a dump resource
328 // $dumpres = $this->index[$dumpresuri];Enter description here ...
329 $dumpres = ProjectImporter::make_resource($dumpresuri);
331 $this->project_dump_res = $dumpres;
333 return $this->project_dump_res;
336 function has_project_dump() {
338 $dumpres = $this->project_dump();
339 if ($dumpres && count($dumpres)) {
345 function get_user_name($user) {
346 return $this->user_names[$user];
349 * Return a user's email
352 function get_user_email($user) {
353 $res = $this->users[$user];
354 return $res->getPropValue('sioc:email');
357 function get_user_role($user) {
358 return $this->user_roles[$user];
361 function display_user($user) {
364 $username = $this->get_user_name($user);
365 $email = $this->get_user_email($user);
367 $res = $this->users[$user];
368 $person = $res->getPropValue('sioc:account_of');
369 $res = $this->persons[$person];
370 $name = $res->getPropValue('foaf:name');
371 $role = $this->get_user_role($user);
373 $html .= 'User :<br />';
374 $html .= ' account name : '. $username .'<br />';
375 $html .= ' email : '. $email .'<br />';
376 $html .= ' owner : '. $name .'<br />';
377 $html .= ' initial role : '. $role .'<br />';
383 function display_role($role) {
386 $username = $this->get_user_name($user);
387 $email = $this->get_user_email($user);
389 $res = $this->users[$user];
390 $person = $res->getPropValue('sioc:account_of');
391 $res = $this->persons[$person];
392 $name = $res->getPropValue('foaf:name');
393 $role = $this->get_user_role($user);
395 $html .= 'User :<br />';
396 $html .= ' account name : '. $username .'<br />';
397 $html .= ' email : '. $email .'<br />';
398 $html .= ' owner : '. $name .'<br />';
399 $html .= ' role : '. $role .'<br />';
406 * Extract users / persons from the dump
407 * @param unknown_type $dumpres
408 * @return array of ARC2 resource
410 function get_users() {
411 if (! $this->users) {
413 $dumpres = $this->project_dump();
415 $this->users = array();
418 $users = $dumpres->getPropValues('forgeplucker:users');
419 foreach ($users as $user) {
420 // print_r($this->index[$user]);
421 $res = ProjectImporter::make_resource($user);
422 $accountName = $res->getPropValue('foaf:accountName');
423 $this->user_names[$user] = $accountName;
424 $this->users[$user] = $res;
425 // print 'Found user : '. $accountName . "\n";
428 $this->persons = array();
430 // parse persons and link users to the persons
431 $persons = $dumpres->getPropValues('forgeplucker:persons');
432 foreach ($persons as $person) {
433 $res = ProjectImporter::make_resource($person);
435 $this->persons[$person] = $res;
437 // print 'Found person : '. $res->getPropValue('foaf:name') . "\n";
438 // print_r($this->index[$person]);
439 //print_r($res->getProps());
440 $accounts = $res->getPropValues('foaf:holdsAccount');
441 foreach($accounts as $account) {
442 // print 'account : '.$account;
443 $user = $this->users[$account];
444 if (! $user->getPropValue('sioc:account_of')) {
445 $user->setProp('sioc:account_of', $person);
449 /* foreach ($this->users as $user) {
450 print 'this->user : ';
451 print_r($user->getProps());
457 function supportsTool($tool)
459 return in_array($tool, $this->providers);
462 * Analyze the tools description found in the dump
464 function get_tools() {
467 $dumpres = $this->project_dump();
471 $tools = $dumpres->getPropValues('forgeplucker:tools');
473 $providers = array();
474 foreach ($tools as $tool) {
475 $toolres = ProjectImporter::make_resource($tool);
476 // print_r($toolres->getProps()); echo "\n";
477 $provider = $toolres->getPropValue('planetforge:provided_by');
479 $providerres = ProjectImporter::make_resource($provider);
480 $types = $providerres->getPropValues('rdf:type');
481 foreach ($types as $type) {
482 if (!in_array($type, ProjectImporter::$allowedprovidertypes)) {
483 $feedback .= 'Need provider type : '. $type . "\n";
486 if (!in_array($provider, $providers)) {
487 $providers[] = $provider;
494 // print_r($providers); echo "\n";
495 $this->providers = $providers;
499 * Enter description here ...
500 * @param unknown_type $dumpres
501 * @return Ambigous <multitype:, ARC2>
503 function get_projects() {
506 $dumpres = $this->project_dump();
511 $this->get_users($dumpres);
514 // $projects = $this->dump_project_uris($dumpres);
515 $projects = $dumpres->getPropValues('forgeplucker:project');
517 foreach ($projects as $project) {
518 // print 'Found project : '. $project . "\n";
519 // print_r($this->index[$project]);
520 $res = ProjectImporter::make_resource($project);
522 // print_r($res->getProps());
523 //$name = $res->getPropValue('doap:name');
524 //$description = $res->getPropValue('dcterms:description');
525 //$homepage = $res->getPropValue('doap:homepage');
526 //$hosted_by = $res->getPropValue('planetforge:hosted_by');
528 $project_obj = new ImportedProject($res);
530 $results[] = $project_obj;
532 // handle project's roles
533 $this->user_roles=array();
535 foreach($project_obj->getRoles() as $role) {
537 $name = $role->getName();
538 foreach($role->getUsers() as $user) {
540 $this->user_roles[$user] = $name;
543 //print_r($this->user_roles);
544 // print_r($user_roles);
545 // echo "creating roles of existing users in the project\n";
546 // echo "calling user_fill(".'$users'.", $this->group_id)\nwhere ".'$users'." is";
547 // check user_fill : True == check mode
548 // user_fill($user_roles, $this->group_id, True);
549 // print_r($user_roles);
558 * Enter description here ...
560 * @param ARC2 resource $spaceres
562 function decode_space($space, $spaceres) {
564 $types = $spaceres->getPropValues('rdf:type');
565 $supported_type = False;
567 foreach($types as $type) {
569 // Case of the trackers
570 if ($type == PLANETFORGE_NS.'Tracker') {
572 $supported_type = True;
574 // print 'Found tracker :'. $space . "\n";
575 $tracker = array('uri' => $space);
577 // Decode TRACKER contents
578 $artifacts = $spaceres->getPropValues('oslc:results');
579 $tracker['artifacts'] = array();
580 foreach ($artifacts as $artifact) {
582 // print 'Found tracker artifact :'. $artifact . "\n";
583 $cmres = ProjectImporter::make_resource($artifact);
584 $tracker['artifacts'][] = array('uri' => $artifact,
585 'details' => $cmres->getProps());
587 // $this->trackers[] = $tracker;
588 echo '<pre>'. htmlspecialchars(print_r($tracker, True)) . '</pre>';
590 tracker_fill($trackers, $group_id, $users);
603 // c-file-style: "bsd"