Skip to content

Commit

Permalink
throw exception in custom filter for import of extension if some prop…
Browse files Browse the repository at this point in the history
…erties are missing
  • Loading branch information
jbrekle committed Mar 23, 2012
1 parent 0e1652b commit 2b32492
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions extensions/reposerver/ReposerverController.php
Expand Up @@ -59,6 +59,8 @@ public function updateAction()
return $this->_sendResponse($res, 'the wrapper run threw an unexpected exception.'); return $this->_sendResponse($res, 'the wrapper run threw an unexpected exception.');
} else if($res == DatagatheringController::IMPORT_WRAPPER_NOT_AVAILABLE){ } else if($res == DatagatheringController::IMPORT_WRAPPER_NOT_AVAILABLE){
return $this->_sendResponse($res, 'the data is not available. is the url correct?'); return $this->_sendResponse($res, 'the data is not available. is the url correct?');
} elseif($res == DatagatheringController::IMPORT_CUSTOMFILTER_EXCEPTION){
return $this->_sendResponse($res, 'the doap data misses required properties');
} else { } else {
return $this->_sendResponse($res, 'unexpected return value.'); return $this->_sendResponse($res, 'unexpected return value.');
} }
Expand Down Expand Up @@ -122,8 +124,8 @@ static function filter($statements)
foreach ($releases as $value) { foreach ($releases as $value) {
$allowedSubjects[] = $value['value']; //add release versions as allowed subjects $allowedSubjects[] = $value['value']; //add release versions as allowed subjects
} }
$logger = Erfurt_App::getInstance()->getLog('repo'); //$logger = Erfurt_App::getInstance()->getLog('repo');
$logger->log('$allowedSubjects: '. print_r($allowedSubjects, true), 1); //$logger->log('$allowedSubjects: '. print_r($allowedSubjects, true), 1);


$allowedPredicates = array( $allowedPredicates = array(
EF_RDF_TYPE, EF_RDF_TYPE,
Expand All @@ -139,19 +141,34 @@ static function filter($statements)
self::DOAP_NS.'created', self::DOAP_NS.'created',
self::DOAP_NS.'file-release' self::DOAP_NS.'file-release'
); );

$requiredPredicates = array(
EF_RDF_TYPE,
EF_RDFS_LABEL,
self::DOAP_NS.'name',
self::DOAP_NS.'description',
self::DOAP_NS.'maintainer',
self::OW_CONFIG_NS.'latestZip',
self::OW_CONFIG_NS.'latestRevision'
);
$foundPredicates = array();
foreach($requiredPredicates as $p){
$foundPredicates[$p] = false;
}


foreach ($model->getSubjects() as $subject) { foreach ($model->getSubjects() as $subject) {
if (!in_array($subject, $allowedSubjects)) { if (!in_array($subject, $allowedSubjects)) {
$model->removeS($subject); $model->removeS($subject);
} else { } else {
foreach ($model->getPO($subject) as $predicate => $values) { foreach ($model->getPO($subject) as $predicate => $values) {
$foundPredicates[$predicate] = true;
if (!in_array($predicate, $allowedPredicates)) { if (!in_array($predicate, $allowedPredicates)) {
$model->removeSP($subject, $predicate); $model->removeSP($subject, $predicate);
} }
} }
} }
} }

//generate latest version triple, if not present (the extensionlist cannot display the indirect property of the version) //generate latest version triple, if not present (the extensionlist cannot display the indirect property of the version)
if($model->getValue($extensionUri, self::OW_CONFIG_NS.'latestZip') == null){ if($model->getValue($extensionUri, self::OW_CONFIG_NS.'latestZip') == null){
$newestVersion = null; $newestVersion = null;
Expand All @@ -170,6 +187,15 @@ static function filter($statements)
if($newestFile != null){ if($newestFile != null){
$model->addRelation($extensionUri, self::OW_CONFIG_NS.'latestZip', $newestFile); $model->addRelation($extensionUri, self::OW_CONFIG_NS.'latestZip', $newestFile);
$model->addAttribute($extensionUri, self::OW_CONFIG_NS.'latestRevision', $newestRevisionNumber); $model->addAttribute($extensionUri, self::OW_CONFIG_NS.'latestRevision', $newestRevisionNumber);
$foundPredicates[self::OW_CONFIG_NS.'latestZip'] = true;
$foundPredicates[self::OW_CONFIG_NS.'latestRevision'] = true;
}
}

//check if all required predicates occured
foreach($foundPredicates as $property => $found){
if(!$found){
throw new Exception('missing property '.$property);
} }
} }


Expand Down

0 comments on commit 2b32492

Please sign in to comment.