use of com.erudika.para.core.ParaObject in project scoold by Erudika.
the class Post method delete.
public void delete() {
// delete post
ArrayList<ParaObject> children = new ArrayList<ParaObject>();
ArrayList<String> ids = new ArrayList<String>();
// delete Comments
children.addAll(client().getChildren(this, Utils.type(Comment.class)));
// delete Revisions
children.addAll(client().getChildren(this, Utils.type(Revision.class)));
for (ParaObject reply : client().getChildren(this, Utils.type(Reply.class))) {
// delete answer
children.add(reply);
// delete Comments
children.addAll(client().getChildren(reply, Utils.type(Comment.class)));
// delete Revisions
children.addAll(client().getChildren(reply, Utils.type(Revision.class)));
}
for (ParaObject child : children) {
ids.add(child.getId());
}
updateTags(getTags(), null);
client().deleteAll(ids);
client().delete(this);
}
use of com.erudika.para.core.ParaObject in project scoold by Erudika.
the class ScooldUtils method fetchProfiles.
public void fetchProfiles(List<? extends ParaObject> objects) {
if (objects == null || objects.isEmpty()) {
return;
}
Map<String, String> authorids = new HashMap<String, String>(objects.size());
Map<String, Profile> authors = new HashMap<String, Profile>(objects.size());
for (ParaObject obj : objects) {
if (obj.getCreatorid() != null) {
authorids.put(obj.getId(), obj.getCreatorid());
}
}
List<String> ids = new ArrayList<String>(new HashSet<String>(authorids.values()));
if (ids.isEmpty()) {
return;
}
// read all post authors in batch
for (ParaObject author : pc.readAll(ids)) {
authors.put(author.getId(), (Profile) author);
}
// add system profile
authors.put(API_USER.getId(), API_USER);
// set author object for each post
for (ParaObject obj : objects) {
if (obj instanceof Post) {
((Post) obj).setAuthor(authors.get(authorids.get(obj.getId())));
} else if (obj instanceof Revision) {
((Revision) obj).setAuthor(authors.get(authorids.get(obj.getId())));
}
}
}
Aggregations