private void createResource(final Resource resource, final Date lastModified, final String relativePath, final URI indirectId) { try { resource.setIndirectId(indirectId); this.resourceRepository.add(resource); final Endpoint newEndpoint= this.endpointManagementService. createEndpointForResource( resource, relativePath, generateEntityTag(resource), lastModified); if(LOGGER.isTraceEnabled()) { LOGGER.trace("Created "+resource); LOGGER.trace("Created "+newEndpoint); } } catch (final EndpointCreationException e) { throw new IllegalStateException(e); } }
@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)); }
@Test public void testPublishResource$preexisting$idClash() throws ApplicationConfigurationException { this.endpointRepository.add(this.endpoint); this.resourceRepository.add(this.resource); this.sut.publishResource(NAME1,PersonHandler.class,"anotherPath/"); try { this.sut.configureRootResources(); fail("Should not allow publishing root resources with preexisting id clash"); } catch (ApplicationConfigurationException e) { logFailure(e); } }
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); } } }
@Test public void testPublishResource$preexisting$pathClash() throws ApplicationConfigurationException { this.endpointRepository.add(this.endpoint); this.resourceRepository.add(this.resource); this.sut.publishResource(NAME2,PersonHandler.class,VALID_PATH); try { this.sut.configureRootResources(); fail("Should not allow publishing root resources with preexisting path clash"); } catch (ApplicationConfigurationException e) { logFailure(e); } }
@Override public void execute(ResourceRepository sut) { Resource result1 = sut.resourceOfId(resourceId); debug("Retrieving resource {%s}: %s",resourceId,result1); Resource attachment = result1.attach(PersonHandler.ADDRESS_ID,attachmentId); sut.add(attachment); debug("Created attachment: %s",attachment); Container result2 = sut.containerOfId(containerId); debug("Retrieving container {%s}: %s",containerId,result2); Slug slug1=result2.addSlug("test"); debug("Created slug: %s",slug1); Slug slug2=result2.addSlug("anotherTest"); debug("Created slug: %s",slug2); Resource member = result2.addMember(memberId); sut.add(member); debug("Created member: %s",member); } }
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; }
@Test public void testPublishResource$preexisting$corrupted() throws ApplicationConfigurationException { Resource createResource = TestingModelFactory.createResource(NAME1, "UnknownTemplate"); this.endpointRepository.add(createEndpoint(VALID_PATH, createResource)); this.resourceRepository.add(createResource); this.sut.publishResource(NAME2,PersonHandler.class,VALID_PATH); try { this.sut.configureRootResources(); fail("Should not allow publishing root resources with preexisting path clash"); } catch (ApplicationConfigurationException e) { logFailure(e); } }
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(); } } }