【发布时间】:2019-09-02 08:27:57
【问题描述】:
public Single<Content> createContent(final Content content) {
BackendACL acl = new BackendACL();
acl.setPublicRead(false);
acl.setPublicWrite(false);
content.setAcl(acl);
return content.create().flatMap(backendEntity -> {
Content newContent = (Content) backendEntity;
newContent.setEntityId(backendEntity.getEntityId());
newContent.setSchema(content.getSchema());
return Single.just(newContent);
}).flatMap(content1 -> {
return content1.setLink("schema", content1.getSchema().getEntityId());
}).flatMap(isLinked -> {
// Code section 1
//return content1.setLink("user", getLoggedInUser().getEntityId());
return Single.just(true); // just a dummy to illustrate
}).flatMap(isLinked -> {
return Single.just(content);
// Code section 2
// should be: return Single.jus(content1);
});
}
在上面的代码中,Code section 1和Code section 2中使用content1变量的解决方案是什么?
【问题讨论】:
-
setLink是做什么的?顾名思义就是设置内容的链接,但是从用法来看,好像也是返回值的? -
请看answer
-
@Gustavo 我不认为这是重复的,因为
setLink方法是Single而不仅仅是布尔值。 -
意思是你可以做
content1.setLink("schema", content1.getSchema().getEntityId()).subscribe(...)因此问题是如何调用 setLink 并且返回content1