Search in sources :

Example 16 with ParaObject

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);
}
Also used : ParaObject(com.erudika.para.core.ParaObject) ArrayList(java.util.ArrayList)

Example 17 with ParaObject

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())));
        }
    }
}
Also used : Revision(com.erudika.scoold.core.Revision) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ParaObject(com.erudika.para.core.ParaObject) Post(com.erudika.scoold.core.Post) ArrayList(java.util.ArrayList) Profile(com.erudika.scoold.core.Profile)

Aggregations

ParaObject (com.erudika.para.core.ParaObject)17 Profile (com.erudika.scoold.core.Profile)10 Comment (com.erudika.scoold.core.Comment)7 Post (com.erudika.scoold.core.Post)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 LinkedHashMap (java.util.LinkedHashMap)5 LinkedList (java.util.LinkedList)5 Pager (com.erudika.para.core.utils.Pager)4 IOException (java.io.IOException)4 List (java.util.List)4 Tag (com.erudika.para.core.Tag)3 User (com.erudika.para.core.User)3 Question (com.erudika.scoold.core.Question)3 Reply (com.erudika.scoold.core.Reply)3 Map (java.util.Map)3 PostMapping (org.springframework.web.bind.annotation.PostMapping)3 ParaClient (com.erudika.para.client.ParaClient)2 Sysprop (com.erudika.para.core.Sysprop)2 Webhook (com.erudika.para.core.Webhook)2