Created
November 11, 2016 14:03
-
-
Save PatrickKwinten/31e63f04ab1044af57ab33fc189de451 to your computer and use it in GitHub Desktop.
Class to control Profile class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.wordpress.quintessens.graph.teamroom.controller; | |
import java.io.Serializable; | |
import org.openntf.domino.graph2.impl.DFramedTransactionalGraph; | |
import org.openntf.domino.graph2.impl.DGraph; | |
import com.ibm.commons.util.io.json.JsonJavaArray; | |
import com.ibm.commons.util.io.json.JsonJavaObject; | |
import com.wordpress.quintessens.graph.teamroom.GraphHelper; | |
import com.wordpress.quintessens.graph.teamroom.Post; | |
import com.wordpress.quintessens.graph.teamroom.Profile; | |
public class ProfilesController implements Serializable { | |
private static final long serialVersionUID = 1L; | |
public JsonJavaArray getProfiles() { | |
DFramedTransactionalGraph<DGraph> graph = GraphHelper.getObjectsGraph(); | |
Iterable<Profile> all = graph.getElements(Profile.class); | |
JsonJavaArray json = new JsonJavaArray(); | |
int count = 0; | |
for (Profile profile : all) { | |
JsonJavaObject jo = new JsonJavaObject(); | |
jo.putString("name", profile.getName()); | |
jo.putString("department", profile.getDepartment()); | |
jo.putString("location", profile.getLocation()); | |
jo.putString("job", profile.getJob()); | |
json.put(count, jo); | |
count++; | |
} | |
return json; | |
} | |
public JsonJavaArray getTopics() { | |
String fullname = "Patrick Kwinten/quintessens"; | |
System.out.println("looking for post for:" + fullname); | |
DFramedTransactionalGraph<DGraph> graph = GraphHelper.getObjectsGraph(); | |
System.out.println("DFramedTransactionalGraph<DGraph> graph = GraphHelper.getProfilesGraph(); OK"); | |
//Profile profile = graph.getElement(id,Profile.class); | |
Profile profile = graph.getElement(fullname,Profile.class); | |
System.out.println("Profile found. " + profile.getName()); | |
Iterable<Post> all = profile.getPosts(); | |
JsonJavaArray json = new JsonJavaArray(); | |
int count = 0; | |
for (Post post : all) { | |
JsonJavaObject jo = new JsonJavaObject(); | |
jo.putString("title", post.getSubject()); | |
jo.putString("summary", post.getAbstract()); | |
json.put(count, jo); | |
count++; | |
} | |
return json; | |
} | |
public JsonJavaArray getTopics(String name) { | |
System.out.println("*start******************************************"); | |
System.out.println("**" + this.getClass().getSimpleName() + "** getTopics(String name)"); | |
String fullname = name; | |
System.out.println("looking for post for:" + fullname); | |
DFramedTransactionalGraph<DGraph> graph = GraphHelper.getObjectsGraph(); | |
System.out.println("DFramedTransactionalGraph<DGraph> graph = GraphHelper.getProfilesGraph(); OK"); | |
//Profile profile = graph.getElement(id,Profile.class); | |
Profile profile = graph.getElement(fullname,Profile.class); | |
System.out.println("Profile found. " + profile.getName()); | |
Iterable<Post> all = profile.getPosts(); | |
JsonJavaArray json = new JsonJavaArray(); | |
int count = 0; | |
for (Post post : all) { | |
JsonJavaObject jo = new JsonJavaObject(); | |
jo.putString("id", post.getKey()); | |
jo.putString("title", post.getSubject()); | |
jo.putString("summary", post.getAbstract()); | |
json.put(count, jo); | |
count++; | |
} | |
System.out.println("Number of post found:" + count); | |
System.out.println("*end******************************************"); | |
return json; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment