/** * {@inheritDoc} */ @Override public boolean detach(Attachment attachment) { boolean found=this.attachments.containsValue(attachment); if(found) { AttachmentId remove = this.attachmentsById.remove(attachment.id()); this.attachmentsByResourceId.remove(attachment.resourceId()); this.attachments.remove(remove); } return found; }
private String generatePathForAttachment(Resource child, Resource parent) throws EndpointNotFoundException { Attachment attachment=parent.findAttachment(child.id()); if(attachment==null) { return null; } Endpoint endpoint=getResourceEndpoint(parent.id()); ResourceTemplate parentTemplate=this.templateManagementService.templateOfId(parent.id().templateId()); AttachedTemplate attachedTemplate = parentTemplate.attachedTemplate(attachment.id()); return PathBuilder. create(). addSegment(endpoint.path()). addSegment(attachedTemplate.path()). addSegment(attachment.version()>0?attachment.version():null). build(); }
boolean removeAttachment(Attachment attachment) { JPAAttachment jpaAttachment = this.indexByAttachmentId.get(attachment.id()); if(jpaAttachment!=null) { jpaAttachment.unbind(); } return jpaAttachment!=null; }
@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()); } }
@Override public final Map<String,PublicResource> attachments() { Map<String,PublicResource> result=new HashMap<String, PublicResource>(); for(Attachment attachment:resolveAs(Resource.class).attachments()) { result.put(attachment.id(), createResource(attachment.resourceId())); } return result; }
static AttachmentSnapshotCollection createFromResource(Resource resource, DelegatedWriteSession session) { AttachmentSnapshotCollection repository=new AttachmentSnapshotCollection(); for(Attachment attachment:resource.attachments()) { DelegatedResourceSnapshot snapshot = session.resolveResource(attachment.resourceId()); checkState(snapshot!=null,"Could not resolve attached resource of attachment %s of resource %s",attachment,resource.id()); DelegatedAttachmentSnapshot newAttachment=new DelegatedAttachmentSnapshot(attachment.id(),snapshot); repository.safeAttach(newAttachment); } return repository; }