Resource resourceOfId(final ResourceId resourceId) { return this.resourceRepository.resourceById(resourceId,Resource.class); }
private Resource loadResource(ResourceId resourceId) { return this.resourceRepository.resourceById(resourceId,Resource.class); }
private String calculateResourcePath(Resource resource, String desiredPath) throws EndpointNotFoundException { if(resource.isRoot()) { throw new IllegalStateException("Cannot get path for root resource"); } Resource parent=this.resourceRepository.resourceById(resource.parentId(),Resource.class); if(parent==null) { throw new IllegalStateException("Could not load resource '"+resource.parentId()+"' from the repository"); } String result= parent instanceof Container? generatePathForMember(resource,(Container)parent,desiredPath): null; if(result==null) { result = generatePathForAttachment(resource,parent); if(result==null) { throw new IllegalStateException("Could not determine path for resource '"+resource.id()+"' with parent '"+parent.id()+"'"); } } return result; }
@Override public void execute(ResourceRepository sut) { Resource result1 = sut.resourceOfId(resourceId); debug("Retrieving resource {%s}: %s",resourceId,result1); Container result2 = sut.containerOfId(containerId); debug("Retrieving container {%s}: %s",containerId,result2); Resource result3 = sut.resourceById(memberId,Resource.class); debug("Retrieving member resource {%s}: %s",memberId,result3); Resource result4 = sut.resourceById(attachmentId,Resource.class); debug("Retrieving attached resource {%s}: %s",attachmentId,result4); ConstraintReport report = result1.addConstraintReport(null,new Date(),httpRequest()); debug("Created report {%s}",report.id()); } }
@Override public void execute(ResourceRepository sut) { Resource result1 = sut.resourceOfId(resourceId); debug("Retrieving resource {%s}: %s",resourceId,result1); Container result2 = sut.containerOfId(containerId); debug("Retrieving container {%s}: %s",containerId,result2); Resource result3 = sut.resourceById(memberId,Resource.class); debug("Retrieving member resource {%s}: %s",memberId,result3); } }
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); } } }
@Override public void execute(ResourceRepository sut) { Resource result1 = sut.resourceOfId(resourceId); debug("Retrieving resource {%s}: %s",resourceId,result1); Container result2 = sut.containerOfId(containerId); debug("Retrieving container {%s}: %s",containerId,result2); Resource result3 = sut.resourceById(memberId,Resource.class); debug("Retrieving member resource {%s}: %s",memberId,result3); sut.remove(result2); debug("Deleted resource {%s}",result2.id()); Resource result4 = sut.resourceById(attachmentId,Resource.class); debug("Retrieving attached resource {%s}: %s",attachmentId,result4); Attachment attachment = result1.findAttachment(result4.id()); debug("Retrieving attachment {%s}: %s",result4.id(),attachment); result1.detach(attachment); debug("Detached resource {%s}",attachment.id()); sut.remove(result4); debug("Deleted resource {%s}",result4.id()); } }