我想将url作为属性返回给我的网上论坛。当返回单个Group时,我可以从GetGroup()方法中做到这一点,但是当我在GetGroups()方法中运行代码(返回Groups的集合)时,我只会得到null。我以为也许我在滥用迭代器,但是我可以用硬编码值更新集合中的对象。从GetGroups()调用时,似乎LinkGenerator找不到我的uri。
我不确定是否有路由问题,或者只是不了解其工作原理。
public Observable<QueryResult> insert(Fetchable fetchable) {
Query query = new Query.QueryBuilder().insert(fetchable).build();
return Observable.create(emitter -> {
CollectionReference collectionReference = getCollectionReference(fetchable);
DocumentReference documentReference;
if(fetchable.getType() == Fetchable.Type.USER){
//USER type uses User UID from FireBase Authentication
documentReference = collectionReference.document(fetchable.getRemoteId());
}else{
documentReference = collectionReference.document();
String id = documentReference.getId();
fetchable.setRemoteId(id);
}
Timber.d(documentReference.getPath());
documentReference.set(fetchable).addOnSuccessListener(aVoid -> {
QueryResult queryResult = new QueryResult(query, fetchable);
Timber.d(queryResult.toString());
emitter.onNext(queryResult);
emitter.onComplete();
}).addOnFailureListener(e ->{
QueryResult queryResult = new QueryResult(query, e);
Timber.d(queryResult.toString());
emitter.onNext(queryResult);
emitter.onComplete();
});
});
public final class Institution implements Fetchable {
public static final String KEY = "institution";
@PrimaryKey(autoGenerate = true)
private int localId;
private String remoteId;
private String name;
private String postalCode;
private List<String> instructionProviderIds;
private List<String> adminIds;
private String creationDate;
private String lastUpdate;
private String createdBy;
private String lastUpdatedBy;
private List<String> accessList;
@Ignore
private final Fetchable.Type type = Type.INSTITUTION;
@Ignore
private Institution() {
instructionProviderIds = new ArrayList<>();
adminIds = new ArrayList<>();
accessList = new ArrayList<>();
}
public Institution(int localId, String remoteId, String name, String postalCode, List<String> instructionProviderIds, List<String> adminIds, String creationDate, String lastUpdate, String createdBy, String lastUpdatedBy, List<String> accessList) {
this.localId = localId;
this.remoteId = remoteId;
this.name = name;
this.postalCode = postalCode;
this.instructionProviderIds = instructionProviderIds;
this.adminIds = adminIds;
this.creationDate = creationDate;
this.lastUpdate = lastUpdate;
this.createdBy = createdBy;
this.lastUpdatedBy = lastUpdatedBy;
this.accessList = accessList;
}
public int getLocalId() {
return localId;
}
public String getRemoteId() {
return remoteId;
}
public void setRemoteId(String remoteId) {
this.remoteId = remoteId;
}
public String getLastUpdate() {
return lastUpdate;
}
@Override
public Type getType() {
return type;
}
@Override
public Date getCreatedOnDate() {
return DateConverter.stringToDate(creationDate);
}
@Override
public Date getLastUpdateOnDate() {
return DateConverter.stringToDate(lastUpdate);
}
@Override
public String getCreatedBy() {
return null;
}
@Override
public String getLastUpdatedBy() {
return null;
}
@Override
public List<String> getAccessList() {
return null;
}
@Override
public void grantAccess(User user) {
}
public String getName() {
return name;
}
public String getPostalCode() {
return postalCode;
}
public List<String> getInstructionProviderIds() {
return instructionProviderIds;
}
public List<String> getAdminIds() {
return adminIds;
}
public String getCreationDate() {
return creationDate;
}
public final class User implements Fetchable {
public static final String KEY = "user";
private String remoteId;
private String email;
private String displayName;
private String creationDate;
private String lastUpdate;
private String createdBy;
private String lastUpdatedBy;
private List<String> accessList;
@Ignore
private final Fetchable.Type type = Type.USER;
private User() {
accessList = new ArrayList<>();
}
public User(String remoteId, String email, String displayName, String creationDate, String lastUpdate, String createdBy, String lastUpdatedBy, List<String> accessList) {
this.remoteId = remoteId;
this.email = email;
this.displayName = displayName;
this.creationDate = creationDate;
this.lastUpdate = lastUpdate;
this.createdBy = createdBy;
this.lastUpdatedBy = lastUpdatedBy;
this.accessList = accessList;
}
public static String getID() {
return KEY;
}
public String getRemoteId() {
return remoteId;
}
public void setRemoteId(String remoteId) {
this.remoteId = remoteId;
}
@Override
public Type getType() {
return type;
}
@Override
public Date getCreatedOnDate() {
return DateConverter.stringToDate(creationDate);
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public String getCreationDate() {
return creationDate;
}
public String getLastUpdate() {
return lastUpdate;
}
@Override
public Date getLastUpdateOnDate() {
return DateConverter.stringToDate(lastUpdate);
}
@Override
public String getCreatedBy() {
return null;
}
@Override
public String getLastUpdatedBy() {
return null;
}
@Override
public List<String> getAccessList() {
return null;
}
@Override
public void grantAccess(User user) {
}
}
答案 0 :(得分:0)
在int providerId之前添加[FromRoute]似乎已修复该问题。我不知道为什么。我改用了How to scanf only integer?,但肯定是[FromRoute]修复了它。