Checks to see if a resource record is a duplicate.

@param string $service
@param string $resource
@param mixed  $value
@param string $key

@return bool
@throws \DreamFactory\Core\Exceptions\RestException
768251
protected function isDuplicate($service, $resource, $value, $key = 'name')
    {
        $api = $service . '/' . $resource;
        switch ($api) {
            case 'system/role':
                return Role::where($key, $value)->exists();
            case 'system/service':
                return Service::where($key, $value)->exists();
            case 'system/app':
                return App::where($key, $value)->exists();
            case 'system/event_script':
            case 'system/custom':
            case 'user/custom':
            case $service . '/_schema':
                try {
                    $result = ServiceManager::handleRequest($service, Verbs::GET, $resource . '/' . $value);
                    if ($result->getStatusCode() === 404) {
                        return false;
                    }
                    if ($result->getStatusCode() >= 300) {
                        throw ResponseFactory::createExceptionFromResponse($result);
                    }

                    $result = $result->getContent();
                    if (is_string($result)) {
                        $result = ['value' => $result];
                    }
                    $result = array_get($result, config('df.resources_wrapper'), $result);

                    return (count($result) > 0) ? true : false;
                } catch (NotFoundException $e) {
                    return false;
                }
            default:
                try {
                    $result = ServiceManager::handleRequest($service, Verbs::GET, $resource,
                        ['filter' => "$key = $value"]);
                    if ($result->getStatusCode() === 404) {
                        return false;
                    }
                    if ($result->getStatusCode() >= 300) {
                        throw ResponseFactory::createExceptionFromResponse($result);
                    }

                    $result = $result->getContent();
                    if (is_string($result)) {
                        $result = ['value' => $result];
                    }
                    $result = array_get($result, config('df.resources_wrapper'), $result);

                    return (count($result) > 0) ? true : false;
                } catch (NotFoundException $e) {
                    return false;
                }
        }
    }
276456
public function query($key, $value = null)
    {
        if ($value) {
            return $this->replicate(['query' => [$key => $value]]);
        }

        return $this->replicate(['query' => $key]);
    }
207310
public function cacheValue(string $key, $value)
    {
        if (!Config::get('activateDbCache')) {
            return false;
        }

        if ($this->getValue($key)) {
            throw new \Exception('Duplicate entry in tl_db_cache for key '.$key);
        }

        $now = time();

        $this->database->prepare('INSERT INTO tl_db_cache (tstamp, expiration, cacheKey, cacheValue) VALUES (?, ?, ?, ?)')->execute(
            $now,
            $now + $this->container->get('huh.utils.date')->getTimePeriodInSeconds(
                StringUtil::deserialize(Config::get('dbCacheMaxTime'), true)
            ),
            $key,
            $value
        );

        return true;
    }
947131
public function hasSharedLock($resource = null): bool
    {
        if (null !== $resource) {
            return isset($this->sharedLock[$this->getResourceId($resource)]);
        }

        return !empty($this->sharedLock);
    }
1090119
public function force($value, $rule, AppliesToResource $resource=null)
    {
        if (!$this->check($value, $rule, $resource)) {
            throw new ConstraintViolationException('Value does not match constraint.');
        }

        return true;
    }
872654
public function duplicate( core_kernel_classes_Resource $resource, $excludedProperties = array())
    {
        $returnValue = null;
    	$newUri = common_Utils::getNewUri();
    	$collection = $this->getRdfTriples($resource);
        
    	if ($collection->count() > 0) {
    		
    		$platform = $this->getPersistence()->getPlatForm();
            $user = $this->getServiceLocator()->get(SessionService::SERVICE_ID)->getCurrentUser()->getIdentifier();
            $valuesToInsert = [];
    		
    		foreach ($collection->getIterator() as $triple) {
    			if (!in_array($triple->predicate, $excludedProperties)) {
                    $valuesToInsert[] = [
                        'modelid' => $this->getNewTripleModelId(),
                        'subject' => $newUri,
                        'predicate'=> $triple->predicate,
                        'object' => ($triple->object == null) ? '' : $triple->object,
                        'l_language' => ($triple->lg == null) ? '' : $triple->lg,
                        'author' => $user,
                        'epoch' => $platform->getNowExpression()
                    ];
    			}
	    	}
	    	
        	if ($this->getPersistence()->insertMultiple('statements', $valuesToInsert)) {
        		$returnValue = new core_kernel_classes_Resource($newUri);
        	}
    	}
        
        return $returnValue;
    }
1280061
public function claimUsedResourceIdentifier(ResourceInterface $resource) {
		if ($resource->getResource()->hasIdentification() === false) {
			throw new InputException('can not validate resource without identifier, set type and id first');
		}
		
		$resourceKey = $resource->getResource()->getIdentificationKey();
		if (isset($this->usedResourceIdentifiers[$resourceKey]) === false) {
			$this->usedResourceIdentifiers[$resourceKey] = true;
			return;
		}
		
		throw new DuplicateException('can not have multiple resources with the same identification');
	}
618873
public function deserialize($data, Resource $resource = null)
    {
        if (empty($resource)) {
            $resource = new Resource();
        }
        if (isset($data['resourceType']) && isset($data['resourceType']['name'])) {
            $resourceType = $this->resourceTypeRepo->findOneBy(['name' => $data['resourceType']['name']]);
            $resource->setResourceType($resourceType);
        }
        if (isset($data['name'])) {
            $resource->setName($data['name']);
        }
        if (isset($data['maxTimeReservation'])) {
            $resource->setMaxTimeReservation($data['maxTimeReservation']);
        }
        if (isset($data['description'])) {
            $resource->setDescription($data['description']);
        }
        if (isset($data['localization'])) {
            $resource->setLocalisation($data['localization']);
        }
        if (isset($data['quantity'])) {
            $resource->setQuantity($data['quantity']);
        }
        if (isset($data['color'])) {
            $resource->setColor($data['color']);
        }
        if (isset($data['organizations'])) {
            $this->deserializeOrganizations($resource, $data['organizations']);
        }

        return $resource;
    }
262994
public function offsetSet($key, $service)
    {
        if ( ! is_callable($service)) {
            throw new BindingResolutionException("Service definition [{$service}] is not an instance of Closure");
        }

        $this->bind($key, $service);
    }
253041
protected function createRecord($key, $value)
    {
        return $this->propertyBag()->save(
            new PropertyBag([
                'key'   => $key,
                'value' => $this->valueToJson($value),
            ])
        );
    }
621504
public function resolveMapping($resource, $parameters = [], $key = 'default', $method = null)
	{
		$resourceName = $resource;

		if( is_object($resource) )
		{
			$resourceName = get_class($resource);
		}

		$mappings = $this->getMappings($resourceName, $key);

		if(empty($mappings))
		{
			throw new Exception('No resolvers mapped for resource: ' . $resourceName . '.');
		}

		$result = null;

		if(is_array($mappings))
		{
			return $this->runResolver($mappings[0], $parameters, $method);
		}

		return $this->runResolver($mappings, $parameters, $method);
	}
1215017
public function update(Request $request, $key)
    {
        $this->getFormRequestInstance();

        $model = $this->findFirstByKey($key);

        if (!$model) {
            return $this->validNotFoundJsonResponse();
        }

        DB::beginTransaction();
       
        try { 
            $instance = $this->repository->update($model, $request->all());
            $model = $instance[1];
            $mergedRequest = $this->uploadFiles($request, $model);
            $this->updateOrCreateRelations($mergedRequest, $model);
        } catch (\Exception $e) {
            DB::rollback();

            $message = $this->updateFailedMessage($key, $e->getMessage());
            throw new ResourceControllerException($message);
        }

        DB::commit();

        $message = $this->updateSuccessfulMessage($key);
        $data = [$model];

        return $this->validSuccessJsonResponse($message, $data);
    }
1332018
public function isMultiple( core_kernel_classes_Resource $resource)
    {
        $returnValue = (bool) false;

        
        
        throw new core_kernel_persistence_ProhibitedFunctionException("not implemented => The function (".__METHOD__.") is not available in this persistence implementation (".__CLASS__.")");
        
        

        return (bool) $returnValue;
    }
1178429
public function set($key, $value, $ttl = 0) {
        if (is_resource($value)) {
            return false;
        }
        $used_key = $this->getUsedKey($key);
        $res = $this->redis->set($used_key, $this->esc($value));

        if ($res !== 'OK') {
            return false;
        }

        if ($ttl === 0) {
            return true;
        }
        if ($ttl != 0 && $ttl > 2592000) {
            $ttl -= time();
        }
        if ($ttl <= 0) {
            return true;
        }

        return ($this->redis->expire($used_key, $ttl) == 1);
    }
913500
protected function setParameter($key, $value)
    {
        if (null !== $this->response) {
            throw new RuntimeException('Request cannot be modified after it has been sent!');
        }

        return $this->setParameterTrait($key, $value);
    }
248618
public function equals(ResourceInterface $resource) {
		if ($this->hasIdentification() === false || $resource->getResource()->hasIdentification() === false) {
			throw new Exception('can not compare resources if identification is missing');
		}
		
		return ($this->getIdentificationKey() === $resource->getResource()->getIdentificationKey());
	}
357609
public function set( $key, $value ) {

		if ( isset( $this->redactedFields[$key] ) ) {
			return null;
		}

		$this->recordFields[$key] = $value;
	}