private Endpoint createEndpoint(String path, Resource resource) { return this.modelFactory. createEndpoint(path, resource, new Date(), EntityTag.createStrong("etag")); }
private Resource createResource(Class<? extends ResourceHandler> handlerClass, Name<?> name) { return this.modelFactory. createResource( this.templateManagementService.templateOfHandler(handlerClass), name); }
private void updateState(TemplateManager manager) { if(!this.state.compareAndSet(this.state.get(),new ConfiguredServiceState(manager))) { throw new IllegalStateException("Template management service is already configured"); } this.resourceFactory.useTemplates(manager.templateLibrary()); }
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); } } }
private <T extends Resource> T publishResource(Class<? extends T> clazz, String templateId, Name<?> resourceName, String path) { Transaction transaction = RuntimeDelegate.getInstance().getTransactionManager().currentTransaction(); transaction.begin(); Resource newResource=this.modelFactory.createResource(this.tms.templateOfId(templateId),resourceName); T resource=clazz.cast(newResource); RuntimeDelegate.getInstance().getResourceRepository().add(resource); Endpoint endpoint=this.modelFactory.createEndpoint(path,resource,new Date(),EntityTag.createStrong(path)); RuntimeDelegate.getInstance().getEndpointRepository().add(endpoint); transaction.commit(); return resource; }
private Resource initialize(final String id, final String path) { final Transaction transaction= RuntimeDelegate. getInstance(). getTransactionManager(). currentTransaction(); transaction.begin(); try { this.uow = UnitOfWork.newCurrent(); final Resource resource= this.modelFactory.createResource( this.templateManagementService.templateOfId("personTemplate"), name(id)); final Endpoint endpoint=this.modelFactory.createEndpoint(path,resource,new Date(),EntityTag.createStrong(path)); RuntimeDelegate.getInstance().getResourceRepository().add(resource); RuntimeDelegate.getInstance().getEndpointRepository().add(endpoint); UnitOfWork.setCurrent(null); transaction.commit(); return resource; } finally { if(transaction.isActive()) { transaction.rollback(); } } }
protected final Container rootContainer(Name<?> name, String templateId) { return (Container)this.delegate.getModelFactory().createResource(ServiceRegistry.getInstance().getService(TemplateManagementService.class).templateOfId(templateId), name); }
protected final Endpoint endpoint(String path, Resource resource) { return this.delegate.getModelFactory().createEndpoint(path, resource, new Date(),EntityTag.createStrong("tag")); }
protected final Resource rootResource(Name<?> name, String templateId) { return this.delegate.getModelFactory().createResource(ServiceRegistry.getInstance().getService(TemplateManagementService.class).templateOfId(templateId), name); }
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 void prepareSession(final Action action, final ResourceSnapshot snapshot) { logAction(Stage.PREPARATION,action,snapshot); final Resource resource= this.modelFactory. createResource(this.templateManagementService.templateOfId(snapshot.templateId()), snapshot.name()); doPrepareSession(resource); }