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.findTemplateById(parent.id().templateId()); AttachedTemplate attachedTemplate = parentTemplate.attachedTemplate(attachment.id()); StringBuilder builder = new StringBuilder(); addSegment(builder, endpoint.path()); addSegment(builder, attachedTemplate.path()); return builder.toString(); }
private String generatePathForMember(Resource child, Container parent, String desiredPath) throws EndpointNotFoundException { if (parent.hasMember(child.id())) { Endpoint endpoint = getResourceEndpoint(parent.id()); ContainerTemplate parentTemplate = templateManagementService.findTemplateById( parent.id().templateId(), ContainerTemplate.class); if (parentTemplate == null) { throw new IllegalStateException("Could not find template resource '" + parent + "'"); } StringBuilder builder = new StringBuilder(); addSegment(builder, endpoint.path()); addSegment(builder, parentTemplate.memberPath().or("")); addSegment(builder, IdGenerator.nextMemberId(parent)); addSegment(builder, desiredPath); // Object lastSegment = desiredPath; // if(lastSegment==null) { // lastSegment=IdGenerator.nextMemberId(parent); // } // addSegment(builder,lastSegment); return builder.toString(); } return null; }