@Override public void execute(EndpointRepository sut) { sut.add(ep1); } }
Endpoint resolveResource(ResourceId id) { return this.endpointRepository.endpointOfResource(id); }
public Endpoint resolveEndpoint(String path) { checkNotNull(path,PATH_CANNOT_BE_NULL); return this.endpointRepository.endpointOfPath(path); }
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(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); } }
@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); } }
@Override public void execute(EndpointRepository sut) { sut.add(ep1); } }
public Endpoint getResourceEndpoint(ResourceId resourceId) throws EndpointNotFoundException { checkNotNull(resourceId,RESOURCE_IDENTIFIER_CANNOT_BE_NULL); Endpoint endpoint = this.endpointRepository.endpointOfResource(resourceId); if(endpoint==null) { throw new EndpointNotFoundException(resourceId); } return endpoint; }
@Override public void execute(EndpointRepository sut) { Endpoint result = sut.endpointOfPath(ep1.path()); System.out.println(result); } }
@Override public void execute(EndpointRepository sut) { sut.add(ep1); } }
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; }
@Override public void execute(EndpointRepository sut) { Endpoint endpoint = sut.endpointOfPath(ep1.path()); endpoint.delete(deleted); } }
@Override public void execute(EndpointRepository sut) { sut.add(ep2); } }
@Override public void execute(EndpointRepository sut) { Endpoint result = sut.endpointOfResource(ep1.resourceId()); System.out.println(result); } }
private Endpoint createEndpoint(Resource resource, String relativePath, EntityTag entityTag, Date lastModified) throws EndpointCreationException { String candidatePath=relativePath; int repetitions=0; while(repetitions<MAX_ENDPOINT_CREATION_FAILURE) { LOGGER.debug("({}) Creating endpoint for {} [{},{},{}]",repetitions,resource.id(),entityTag,lastModified,relativePath); try { String resourcePath = calculateResourcePath(resource,candidatePath); LOGGER.debug("({}) Trying resource path {} ",repetitions,resourcePath); Endpoint newEndpoint = this.modelFactory.createEndpoint(resourcePath, resource, lastModified, entityTag); this.endpointRepository.add(newEndpoint); return newEndpoint; } catch (EndpointNotFoundException e) { throw new EndpointCreationException("Could not calculate path for resource '"+resource.id()+"'",e); } catch (IllegalArgumentException e) { LOGGER.debug("Could not create endpoint ({} --> {})",repetitions,candidatePath,e); repetitions++; candidatePath=null; } } throw new EndpointCreationException("Could not create endpoint for resource '"+resource.id()+"' after "+MAX_ENDPOINT_CREATION_FAILURE+" tries"); }
private Endpoint findEndpoint(Resource resource) { return this.endpointRepository.endpointOfResource(resource.id()); }
@Override public void execute(EndpointRepository sut) { Endpoint newEndpoint = endpoint(path,resource); sut.add(newEndpoint); debug("Adding endpoint: %s",newEndpoint); } }
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; }
@Test public void testPublishResource$preexisting$noClash() throws ApplicationConfigurationException { this.endpointRepository.add(this.endpoint); this.resourceRepository.add(this.resource); this.sut.publishResource(NAME1,PersonHandler.class,VALID_PATH); this.sut.configureRootResources(); Resource resource1 = verifyResource(NAME1, PersonHandler.class); assertThat(resource1,sameInstance(this.resource)); Endpoint endpoint1 = verifyEndpoint(VALID_PATH, resource1); assertThat(endpoint1,sameInstance(this.endpoint)); }
private Endpoint endpoint(Resource resource) { EndpointRepository er = RuntimeDelegate.getInstance().getEndpointRepository(); Endpoint endpoint = er.endpointOfResource(resource.id()); return endpoint; }