@Override public void visitResource(Resource resource) { InMemoryResourceRepository.this.resources.put(resource.id(),resource); } @Override
@Override public String toString() { return MoreObjects. toStringHelper(getClass()). add("child.id()", this.child.id()). toString(); }
private PersistentResourceState(Resource delegate, ResourceTemplate template, AttachmentSnapshotCollection attachmentRepository, MemberCollection memberRepository) { super(delegate.id(),template,attachmentRepository,memberRepository); setDelegate(delegate); this.newAttachments=new LinkedHashMap<String,DelegatedAttachmentSnapshot>(); this.deletedAttachments=new LinkedHashMap<String,DelegatedAttachmentSnapshot>(); this.newMembers=new LinkedHashMap<ResourceId, DelegatedResourceSnapshot>(); this.deletedMembers=new LinkedHashMap<ResourceId, DelegatedResourceSnapshot>(); }
@Override public Endpoint createEndpoint(String path, Resource resource, Date created, EntityTag entityTag) { checkNotNull(resource,"Resource cannot be null"); return InMemoryEndpoint.create(path, resource.id(), created, entityTag); }
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); }
protected final ResourceTemplate template() { if(this.template==null) { this.template = this.applicationContext.resourceTemplate(resolveAs(Resource.class)); if(this.template==null) { throw new IllegalStateException("Could not find template for resource "+resource.id()); } } return this.template; }
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; }
private ResourceSnapshot getTargetSnapshot() { ResourceSnapshot targetSnapshot=null; Resource target=this.configuration.getTarget(); if(target!=null) { targetSnapshot=find(ResourceSnapshot.class, target.id()); } return targetSnapshot; }
@Override public void visitResource(Resource resource) { DelegatedResourceSnapshot snapshot=new DelegatedResourceSnapshot(resource.id(),template.handlerClass()); snapshot.setParentState(ParentState.parentOf(resource)); snapshot.setPersistencyState(PersistencyState.newPersistentReferenceState(resource.id(),template)); result.set(snapshot); } @Override
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; }
@Override public Resource call() throws Exception { Resource result=sut.createResource(resource,initialData,getSessionConfiguration(resource)); assertThat(result,notNullValue()); assertThat((Object)result.id().name(),equalTo((Object)id)); assertThat(result.id().templateId(),equalTo(BookHandler.ID)); assertThat(resourceHandler.hasResource(resourceName),equalTo(false)); return result; } }
private Resource verifyResource(Name<String> name, Class<? extends ResourceHandler> clazz) { Resource resource = findResource(name, clazz); assertThat(resource,notNullValue()); assertThat((Object)resource.id().name(),equalTo((Object)name)); return resource; }
static Adapter newAdapter(Resource resource, ResourceHandler resourceHandler, WriteSessionService writeSessionService, WriteSessionConfiguration configuration) { WriteSession session = writeSessionService.createSession(configuration); ResourceSnapshot snapshot = writeSessionService.attach(session,resource,resourceHandler.getClass()); FactoryVistor factory = new FactoryVistor(resource.id(),session,writeSessionService,resourceHandler); snapshot.accept(factory); return factory.getAdapter(); }
private <T extends Resource> Adapter adapter(T resource, WriteSessionConfiguration configuration) { ResourceTemplate template=this.templateManagementService.templateOfId(resource.id().templateId()); Class<? extends ResourceHandler> handlerClass = template.handlerClass(); ResourceHandler delegate=this.templateManagementService.getHandler(handlerClass); return AdapterFactory.newAdapter(resource,delegate,this.writeSessionService,configuration); }
static AttachmentSnapshotCollection createFromResource(Resource resource, DelegatedWriteSession session) { AttachmentSnapshotCollection repository=new AttachmentSnapshotCollection(); for(Attachment attachment:resource.attachments()) { DelegatedResourceSnapshot snapshot = session.resolveResource(attachment.resourceId()); checkState(snapshot!=null,"Could not resolve attached resource of attachment %s of resource %s",attachment,resource.id()); DelegatedAttachmentSnapshot newAttachment=new DelegatedAttachmentSnapshot(attachment.id(),snapshot); repository.safeAttach(newAttachment); } return repository; }
@SuppressWarnings("rawtypes") private ConstraintReportTransformer(Resource resource, ConstraintReport report) { this.report = report; ManagedIndividualId tId = ManagedIndividualId.createId(resource.id().name(), resource.id().templateId()); ManagedIndividualId rId = ManagedIndividualId.createId(URI.create("?ldp:constrainedBy="+report.id().failureId()), tId); this.dataset=DataSets.createDataSet(rId.name()); this.constraintReport= dataset.individual(rId, ManagedIndividual.class); this.targetResource = dataset.individual(tId, ManagedIndividual.class); this.failedRequest=dataset.individual((Name)NamingScheme.getDefault().name("request"), LocalIndividual.class); }
@Override public void execute(EndpointRepository sut) { Endpoint endpointByPath = sut.endpointOfPath(ep1.path()); debug("Retrieving endpoint by path {%s} : %s",ep1.path(),endpointByPath); Endpoint endpointByResource = sut.endpointOfResource(resource.id()); debug("Retrieving endpoint by resource {%s} : %s",resource.id(),endpointByResource); } }
private Endpoint endpoint(Resource resource) { EndpointRepository er = RuntimeDelegate.getInstance().getEndpointRepository(); Endpoint endpoint = er.endpointOfResource(resource.id()); return endpoint; }
/** * {@inheritDoc} */ @Override public DefaultPublicResource createResource(DataSet dataSet, CreationPreferences preferences) throws ApplicationExecutionException { verifyInteractionModel(preferences.getInteractionModel()); Resource resource=applicationContext().createResource(endpoint(),dataSet,preferences.getPath()); return createResource(resource.id()); }
@Override public void execute(EndpointRepository sut) { Endpoint legacyEndpointByPath = sut.endpointOfPath(ep1.path()); debug("Retrieving endpoint by path {%s} : %s",ep1.path(),legacyEndpointByPath); Endpoint endpointByPath = sut.endpointOfPath(path); debug("Retrieving endpoint by path {%s} : %s",path,endpointByPath); Endpoint endpointByResource = sut.endpointOfResource(resource.id()); debug("Retrieving endpoint by resource {%s} : %s",resource.id(),endpointByResource); } }