src/snac/server/ServerExecutor.php
/**
     * Write Resource
     *
     * Writes the resource based on the input to the server.
     *
     * @param string[] $input Input array from the Server object
     * @throws \snac\exceptions\SNACException
     * @return string[] The response to send to the client
     */
Write Resource
Writes the resource based on the input to the server.

@param string[] $input Input array from the Server object
@throws \snac\exceptions\SNACException
@return string[] The response to send to the client
Write Resource Writes the resource based on the input to the server . @param string [] $input Input array from the Server object @throws \ snac \ exceptions \ SNACException @return string [] The response to send to the client
public function writeResource(&$input) {
        $response = array();
        if (isset($input["resource"])) {
            $resource = new \snac\data\Resource($input["resource"]);
            if ($resource->getOperation() === \snac\data\AbstractData::$OPERATION_INSERT) {
                $resourceCheck = $this->cStore->readResourceByData($resource);
                if ($resourceCheck !== false) {
                    $response['resource'] = $resourceCheck->toArray();
                    $response["result"] = "success-notice";
                    $response["message"] = [
                        "text" => "This resource already exists."
                    ];
                    return $response;
                }
            }
            try {
                $resource->setID((string) $resource->getID());
                $resource->setVersion((string) $resource->getVersion());
                $result = $this->cStore->writeResource($this->user, $resource);
                if (isset($result) && $result != false) {
                    $this->elasticSearch->writeToResourceIndices($resource);
                    $this->neo4J->updateResourceIndex($resource);
                    $this->logger->addDebug("successfully wrote resource");
                    $response["resource"] = $result->toArray();
                    $response["result"] = "success";
                } else {
                    $this->logger->addDebug("writeResource returned a null result or edits not allowed");
                    $response["result"] = "failure";
                    $response["error"] = "could not write the resource";
                }
            } catch (\Exception $e) {
                $this->logger->addError("writeResource threw an exception");
                throw $e;
            }
        } else {
            $this->logger->addDebug("Resource input value wasn't set to write");
            $response["result"] = "failure";
            $response["error"] = "no resource to write";
        }
        return $response;
    }
public function writeResource ( & $ input ) { $ response = array ( ) ; if ( isset ( $ input [ " resource " ] ) ) { $ resource = new \ snac \ data \ Resource ( $ input [ " resource " ] ) ; if ( $ resource -> getOperation ( ) === \ snac \ data \ AbstractData :: $ OPERATION_INSERT ) { $ resourceCheck = $ this -> cStore -> readResourceByData ( $ resource ) ; if ( $ resourceCheck !== false ) { $ response [ 'resource' ] = $ resourceCheck -> toArray ( ) ; $ response [ " result " ] = " success-notice " ; $ response [ " message " ] = [ " text " => " This resource already exists. " ] ; return $ response ; } } try { $ resource -> setID ( ( string ) $ resource -> getID ( ) ) ; $ resource -> setVersion ( ( string ) $ resource -> getVersion ( ) ) ; $ result = $ this -> cStore -> writeResource ( $ this -> user , $ resource ) ; if ( isset ( $ result ) && $ result != false ) { $ this -> elasticSearch -> writeToResourceIndices ( $ resource ) ; $ this -> neo4J -> updateResourceIndex ( $ resource ) ; $ this -> logger -> addDebug ( " successfully wrote resource " ) ; $ response [ " resource " ] = $ result -> toArray ( ) ; $ response [ " result " ] = " success " ; } else { $ this -> logger -> addDebug ( " writeResource returned a null result or edits not allowed " ) ; $ response [ " result " ] = " failure " ; $ response [ " error " ] = " could not write the resource " ; } } catch ( \ Exception $ e ) { $ this -> logger -> addError ( " writeResource threw an exception " ) ; throw $ e ; } } else { $ this -> logger -> addDebug ( " Resource input value wasn't set to write " ) ; $ response [ " result " ] = " failure " ; $ response [ " error " ] = " no resource to write " ; } return $ response ; }
Write Resource
 Writes the resource based on the input to the server.
Write Resource Writes the resource based on the input to the server .
//check if resource is already in database, if so, return it // ensure resource id and version are strings for neo4j compatability. // Rethrow it, since we just wanted a log statement