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);
}
}
}