@Override protected final ResourceId id() { return endpoint().resourceId(); }
/** * {@inheritDoc} */ @Override public void add(Endpoint endpoint) { this.writeLock.lock(); try { if(this.endpointsByPath.containsKey(endpoint.path())) { throw new IllegalArgumentException("An endpoint with path '"+endpoint.path()+"' already exists"); } Endpoint other=endpointOfResource(endpoint.resourceId()); if(other!=null) { throw new IllegalArgumentException("An endpoint with resource name '"+endpoint.resourceId()+"' already exists ("+other+")"); } this.endpointsByPath.put(endpoint.path(), endpoint); this.endpointsByResourceName.put(endpoint.resourceId(),endpoint); } finally { this.writeLock.unlock(); } }
/** * {@inheritDoc} */ @Override public final String path() { return this.endpoint.path(); }
/** * {@inheritDoc} */ @Override public final Status status() { Status result=Status.PUBLISHED; if(this.endpoint.deleted()!=null) { return Status.GONE; } return result; }
private void populateResourceIndividual(Endpoint endpoint) { resourceInd().addValue(ldp4jTerm("entityTag"), literal(endpoint.entityTag())); resourceInd().addValue(ldp4jTerm("lastModified"), literal(endpoint.lastModified())); resourceInd().addValue(ldpTerm("constrainedBy"), reportInd()); }
/** * Enforce http://tools.ietf.org/html/rfc7232#section-2.2: * if the clock in the request is ahead of the clock of the origin * server (e.g., I request from Spain the update of a resource held in USA) * the last-modified data should be changed to that of the request and not * a generated date from the origin server */ private Date getModificationDate(Endpoint endpoint, Date modificationDate) { Date result=endpoint.lastModified(); if(modificationDate.after(result)) { result=modificationDate; } return result; }
/** * {@inheritDoc} */ @Override public final EntityTag entityTag() { return this.endpoint.entityTag(); }
public Endpoint modifyResourceEndpoint(Resource resource, EntityTag entityTag, Date lastModified) throws EndpointNotFoundException { checkNotNull(resource,RESOURCE_CANNOT_BE_NULL); checkNotNull(entityTag,ENTITY_TAG_CANNOT_BE_NULL); checkNotNull(lastModified,LAST_MODIFIED_CANNOT_BE_NULL); Endpoint endpoint = this.endpointRepository.endpointOfResource(resource.id()); if(endpoint==null) { throw new EndpointNotFoundException(resource.id()); } endpoint. modify( entityTag, getModificationDate(endpoint,lastModified)); return endpoint; }
public Endpoint deleteResourceEndpoint(Resource resource, Date deletionDate) throws EndpointNotFoundException { checkNotNull(resource,RESOURCE_CANNOT_BE_NULL); Endpoint endpoint = this.endpointRepository.endpointOfResource(resource.id()); if(endpoint==null) { throw new EndpointNotFoundException(resource.id()); } endpoint.delete(getModificationDate(endpoint,deletionDate)); this.listenerManager.notify(new EndpointDeletionNotification(endpoint)); return endpoint; }
protected final <T extends Resource> T resolveAs(Class<? extends T> clazz) { if(this.resource==null) { this.resource = this.applicationContext.resolveResource(this.endpoint); if(this.resource==null) { throw new IllegalStateException("Expected resource at "+endpoint().path()); } } if(!clazz.isInstance(this.resource)) { throw new IllegalStateException("Expected resource "+this.resource.id()+" to be an instance of "+clazz.getCanonicalName()); } return clazz.cast(this.resource); }
private void publish(RootResource rootResource, Date creationDate) throws ApplicationConfigurationException { ResourceId resourceId = rootResource.resourceId(); String path = rootResource.path(); Resource prevResource = this.resourceRepository.resourceById(resourceId,Resource.class); Endpoint prevEndpoint = this.endpointRepository.endpointOfPath(path); if(prevEndpoint!=null && !prevEndpoint.resourceId().equals(resourceId)) { throw new ApplicationConfigurationException(String.format("Resource %s cannot be published at '%s' as that path is already in use by a resource %s",toString(resourceId),path,toString(prevEndpoint.resourceId()))); } if(prevEndpoint==null) { if(prevResource!=null) { throw new ApplicationConfigurationException(String.format("Resource %s cannot be published at '%s' as it is already published at '%s'",toString(resourceId),path,this.endpointRepository.endpointOfResource(resourceId).path())); } else { Resource resource=this.modelFactory.createResource(rootResource.template(),rootResource.name()); this.resourceRepository.add(resource); Endpoint endpoint=this.modelFactory.createEndpoint(path,resource,creationDate,EntityTag.createStrong(path)); this.endpointRepository.add(endpoint); } } }
/** * {@inheritDoc} */ @Override public Endpoint endpointOfResource(ResourceId id) { this.readLock.lock(); try { Endpoint endpoint = this.endpointsByResourceName.get(id); if(endpoint!=null && endpoint.deleted()!=null) { endpoint=null; } return endpoint; } finally { this.readLock.unlock(); } }
/** * {@inheritDoc} */ @Override public final Date lastModified() { return new Date(endpoint.lastModified().getTime()); }
@Override public URI resolve(ResourceSnapshot resource) { ResourceId resourceId = ResourceId.createId( resource.name(), resource.templateId()); try { Endpoint endpoint = context(). resolveResource( resourceId); URI result = null; if(endpoint!=null && endpoint.deleted()==null) { result=this.canonicalBase.resolve(endpoint.path()); } return result; } catch (ApplicationEngineException e) { throw new SnapshotResolutionException("Could not resolve endpoint for resource '"+resourceId+"'",e); } }
private ResourceTemplate resolveTemplate(Endpoint endpoint) { Resource resource = this.applicationContext.resolveResource(endpoint); checkState(resource!=null,"Could not resolve endpoint %s",endpoint.path()); ResourceTemplate template = this.applicationContext.resourceTemplate(resource); checkState(template!=null,"Could not find template for resource %s",resource.id()); return template; }
Resource resolveResource(Endpoint endpoint) { return loadResource(endpoint.resourceId()); }
private ResourceSnapshot resolveManagedResource(URI path) { try { Endpoint endpoint= applicationEngine(). endpointManagementService(). resolveEndpoint(path.toString()); ResourceSnapshot result=null; if(endpoint!=null && endpoint.deleted()==null) { org.ldp4j.application.kernel.resource.Resource resource = context(). resolveResource(endpoint); if(resource!=null) { ResourceId resourceId = resource.id(); result= this.session. find( ResourceSnapshot.class, resourceId.name(), context().resourceTemplate(resource).handlerClass()); } } return result; } catch (Exception e) { throw new SnapshotResolutionException("Could not resolve resource for endpoint '"+this.canonicalBase.resolve(path)+"'",e); } } }