3 * FusionForge ADMS.SW plugin - RDF serializable extension of FRSFile
5 * Copyright 2013, Olivier Berger and Institut Mines-Telecom
7 * This file is part of FusionForge. FusionForge is free software;
8 * you can redistribute it and/or modify it under the terms of the
9 * GNU General Public License as published by the Free Software
10 * Foundation; either version 2 of the Licence, or (at your option)
13 * FusionForge is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 // This class overloads FRSFile to add RDF representation, based on ADMS.SW, using ARC2 and Graphite
25 require_once $gfcommon.'frs/FRSFile.class.php';
26 require_once 'RDFedFRSRelease.class.php';
29 * Factory method which creates a RDFedFRSFile from an file id
31 * @param int The file id
32 * @param array The result array, if it's passed in
33 * @return object RDFedFRSFile object
35 function &rdfed_frsfile_get_object($file_id, $data=false) {
36 global $RDFED_FRSFILE_OBJ;
37 if (!isset($RDFED_FRSFILE_OBJ['_'.$file_id.'_'])) {
39 //the db result handle was passed in
41 $res = db_query_params ('SELECT * FROM frs_file WHERE file_id=$1',
43 if (db_numrows($res)<1 ) {
44 $RDFED_FRSFILE_OBJ['_'.$file_id.'_']=false;
47 $data = db_fetch_array($res);
49 $FRSRelease =& rdfed_frsrelease_get_object($data['release_id']);
50 $RDFED_FRSFILE_OBJ['_'.$file_id.'_']= new RDFedFRSFile($FRSRelease,$data['file_id'],$data);
52 return $RDFED_FRSFILE_OBJ['_'.$file_id.'_'];
56 class RDFedFRSFile extends FRSFile {
59 * getDownloadUrl - constructs the download URL
63 public function getDownloadUrl() {
64 return util_make_url('/frs/download.php/file/'.$this->getID().'/'.rawurlencode($this->getName()));
68 * getUri - constructs the resource URI
70 * @return string resource URI
72 public function getUri() {
73 return $this->getDownloadUrl().'#package';
77 * saveToGraph - updates a Graphite graph to add the resource's triples
79 * @param Graphite a Graphite graph to be updated
81 public function saveToGraph(&$graph) {
83 // Construct an ARC2_Resource containing the RDFedFRSFile RDF description
91 $res = ARC2::getResource($conf);
93 $frs_release = $this->getFRSRelease();
94 $frs_package = $frs_release->getFRSPackage();
95 $group = $frs_package->getGroup();
97 $frs_file_name = $this->getName();
99 $file_uri = $this->getUri();
100 $res->setURI($file_uri);
102 // $res->setRel('rdf:type', 'admssw:SoftwarePackage');
103 rdfutils_setPropToUri($res, 'rdf:type', 'admssw:SoftwarePackage');
105 $res->setProp('rdfs:label', $frs_file_name);
106 $description = $frs_file_name. _(', part of ') .$frs_package->getName(). ' ' .$frs_release->getName();
107 $res->setProp('dcterms:description', $description);
109 rdfutils_setPropToUri($res, 'schema:downloadUrl', $this->getDownloadUrl());
110 rdfutils_setPropToXSDdateTime($res, 'dcterms:created', date('c', $this->getReleaseTime()));
111 $res->setProp('schema:fileSize', $this->getSize());
113 $frs_filetype_id = $this->getTypeID();
114 $frs_filetype = new FRSFileType($frs_filetype_id);
116 // This is hackish... ultimately, FusionForge should support proper mime-types
118 $frs_filetype_name = $frs_filetype->getName();
119 switch ($frs_filetype_name) {
121 $mime_type = 'application/x-deb';
124 $mime_type = 'application/x-rpm';
127 $mime_type = 'application/zip';
130 $mime_type = 'application/x-bzip2';
133 $mime_type = 'application/x-gzip';
136 $mime_type = 'image/jpeg';
139 $mime_type = 'text/plain';
142 $mime_type = 'text/html';
145 $mime_type = 'application/pdf';
147 /* we won't treat these
156 $mime_type = 'application/binary';
159 rdfutils_setPropToUri($res, 'dcterms:format', 'http://purl.org/NET/mediatypes/'. $mime_type);
161 rdfutils_setPropToUri($res, 'admssw:release', $frs_release->getUri());
163 rdfutils_setPropToUri($res, 'dcterms:license', $this->getDownloadUrl().'#unspecified_license');
165 $count = $graph->addTriples( ARC2::getTriplesFromIndex($res->index) );
167 // Add a resource for the license, that is an explicit "unspecified license", rather than not setting it... the ADMS.SW seem to require a mandatory license
168 $res = ARC2::getResource($conf);
169 $res->setURI($this->getDownloadUrl().'#unspecified_license');
170 $res->setProp('rdfs:label', 'Unspecified license (unavailable meta-data in the FusionForge File Release System)');
172 $count = $graph->addTriples( ARC2::getTriplesFromIndex($res->index) );
179 // c-file-style: "bsd"