Пример #1
0
function checkwriteable($pdphandler, $user, $item)
{
    $subject = new Subject(Subject::SUBJECT_CATEGORY_DEFAULT);
    $subject->getAttributes()->add(new Attribute(new Uri(SubjectIdentifier::SUBJECT_ID), new Uri(DataTypes::STRING), StringAttribute::getInstance($user)));
    $resource = new Resource();
    $resource->getAttributes()->add(new Attribute(new Uri(ResourceIdentifier::RESOURCE_ID), new Uri(DataTypes::STRING), StringAttribute::getInstance($item)));
    $writeaction = new Action();
    $writeaction->getAttributes()->add(new Attribute(new Uri(ActionIdentifier::ACTION_ID), new Uri(DataTypes::STRING), StringAttribute::getInstance('info:escidoc/names:aa:1.0:action:update-item')));
    $writerequest = new Request($resource, $writeaction);
    $writerequest->add($subject);
    $requestarray = array($writerequest);
    $requests = new Requests();
    $requests->addAll($requestarray);
    $pdpresults = $pdphandler->evaluate($requests);
    if (!$pdpresults->get(0)->getDecision() === Decision::PERMIT) {
        throw new Exception("You are not allowed to update the dataset");
    }
}
Пример #2
0
    $_SESSION["pdphandler"] = new PDPHandler(new Net_URL($escidoccoreservice));
    $_SESSION["pdphandler"]->setHandle($_SESSION["eSciDocUserHandle"]);
    $user = $_SESSION["userhandler"]->retrieveCurrentUser();
    $escidocitemid = $_REQUEST["item"];
    $targeturl = $_REQUEST["dataciteurl"];
    $registermode = $_REQUEST["dataciteregistry"];
    $subject = new Subject(Subject::SUBJECT_CATEGORY_DEFAULT);
    $subject->getAttributes()->add(new Attribute(new Uri(SubjectIdentifier::SUBJECT_ID), new Uri(DataTypes::STRING), StringAttribute::getInstance($user->getObjid())));
    $resource = new Resource();
    $resource->getAttributes()->add(new Attribute(new Uri(ResourceIdentifier::RESOURCE_ID), new Uri(DataTypes::STRING), StringAttribute::getInstance($escidocitemid)));
    $writeaction = new Action();
    $writeaction->getAttributes()->add(new Attribute(new Uri(ActionIdentifier::ACTION_ID), new Uri(DataTypes::STRING), StringAttribute::getInstance('info:escidoc/names:aa:1.0:action:update-item')));
    $writerequest = new Request($resource, $writeaction);
    $writerequest->add($subject);
    $requestarray[0] = $writerequest;
    $requests = new Requests();
    $requests->addAll($requestarray);
    //    echo DOMMapper::marshal($requests);
    $pdpresults = $_SESSION["pdphandler"]->evaluate($requests);
    if ($pdpresults->get(0)->getDecision() !== Decision::PERMIT) {
        throw new Exception("To register a DOI you need write access to the dataset.");
    }
    if (!($registermode === 'register' || $registermode === 'metadata' || $registermode === 'deactivate')) {
        throw new Exception("Please choose as registration mode one of: <br>register DOI, <br>update DOI metadata, or <br>deactivate DOI.");
    }
    $item = $_SESSION["itemhandler"]->retrieve($escidocitemid);
    uniquedoi($dbo, $item, $pmdinstance);
    $successmessage = registerDOIFromItem($item, $targeturl, $publication, $doidbrestserver, $registermode);
    echo json_encode(array("success" => true, "message" => $successmessage));
} catch (Exception $e) {
    echo json_encode(array("success" => false, "message" => $e->getMessage()));