Permalink
Browse files

Added backend for bookmarking. Full save and upload. REMEMBER TO SYNC…

… SCHEMA.XML
  • Loading branch information...
1 parent 5c5ca5e commit 574e14e590ffed2e28195adee5304cbc35ed66d0 @chrim chrim committed Nov 24, 2010
View
@@ -437,9 +437,10 @@
<field name="linkedin" type="textgen" indexed="false" stored="true"/>
<field name="twitter" type="textgen" indexed="false" stored="true"/>
<field name="irc" type="textgen" indexed="true" stored="true"/>
- <field name="picture" type="text" indexed="true" stored="true"/>
+ <field name="picture" type="text" indexed="false" stored="true"/>
<field name="email2" type="textgen" indexed="true" stored="true"/>
<field name="phone2" type="textgen" indexed="true" stored="true"/>
+ <field name="bookmarks" type="string" indexed="false" stored="true"/>
<field name="permissions" type="string" indexed="false" stored="true"/>
<field name="user_credential" type="string" indexed="false" stored="true" />
@@ -167,8 +167,8 @@ public Person loadPerson(SearchResult record) throws NamingException {
return person;
}
}
-/*
- try {
+
+/* try {
//create the default set of Search Controls
SearchControls controls = new SearchControls();
@@ -52,9 +52,9 @@ public static void main(String[] args) throws NamingException, SolrServerExcepti
SolrSession test_session = new SolrSession(Person.getAdmin(), test_solr);
Person result = new Person();
result = test_session.loadPersonByName("Jared\\ Williams");
- TreeSet<String> skills= new TreeSet<String>();
- skills.add("java");
- skills.add("programming");
+ TreeSet<String> fullname= new TreeSet<String>();
+ fullname.add("Jared Chausow");
+ result.getBookmarks().put("chausow", fullname);
// //result.
//result.setSkills(skills);
@@ -76,6 +76,7 @@ public static void main(String[] args) throws NamingException, SolrServerExcepti
System.out.println(result.getFirstName());
System.out.println(result.getPermissions());
System.out.println(result.getSkills());
+ System.out.println(result.getBookmarks());
/*SolrQuery query = new SolrQuery();
query.setQuery("id:codetes*");
@@ -16,8 +16,19 @@ public Person() {}
//VARIABLES NEED TO BE EXACT STRING MATCHES OF SOLR SCHEMA.XML
+ /*If you want to add variables, you also have to add in logic in
+ * SolrSession.addPerson(), SecureLoader.loadPerson(), and Person.getDefaultPermissions()
+ *
+ * If you want to add a Hashmap you also have to copy logic in
+ * SolrSession.Permissions() and SolrSession.Bookmarks().
+ * Also, pay particular attention to SecureLoader.loadPerson() and
+ * see the if statements regarding the fields "permission" and "bookmarks"
+ */
+
+
private TreeSet<String> credentials;
private HashMap<String,TreeSet<String>> permissions;
+ private HashMap<String, TreeSet<String>> bookmarks;
private TreeSet<String> skills;
private TreeSet<String> interests;
@@ -109,7 +120,13 @@ public String getEmail2() {
public String getIrc() {
return irc;
}
+ public HashMap<String, TreeSet<String>> getBookmarks() {
+ return bookmarks;
+ }
+ public void setBookmarks(HashMap<String, TreeSet<String>> bookmarks) {
+ this.bookmarks = bookmarks;
+ }
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@@ -273,11 +290,11 @@ public static Person getAdmin() {
admin = new Person();
admin.setFullName("Administrator");
- TreeSet<String> cred_default = new TreeSet<String>();
- cred_default.add("public");
- cred_default.add("admin");
+ TreeSet<String> cred_admin = new TreeSet<String>();
+ cred_admin.add("public");
+ cred_admin.add("admin");
admin.setPermissions(new HashMap<String,TreeSet<String>>());
- admin.setCredentials(cred_default);
+ admin.setCredentials(cred_admin);
}
return admin;
}
@@ -305,6 +322,8 @@ public static Person getAnon() {
//for each field put in default permission
permissions.put("permissions", cred_admin);
permissions.put("user_credential", cred_admin);
+ permissions.put("bookmarks", cred_admin);
+
permissions.put("uid", cred_default);
permissions.put("email", cred_default);
permissions.put("phone", cred_default);
@@ -326,7 +345,6 @@ public static Person getAnon() {
permissions.put("skills", cred_default);
permissions.put("interests", cred_default);
-
return permissions;
}
@@ -19,15 +19,15 @@
public SecureLoader(Person user) {
this.user = user;
}
-
+
public Person loadPerson(SolrDocument profile) {
//Do the loading here
Person person = new Person();
//Dependent on matching user credentials and field credentials
//load into the person object
String permissions_xml = (String)profile.getFieldValue("permissions");
-
+
try {
DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
@@ -62,8 +62,6 @@ public Person loadPerson(SolrDocument profile) {
String fieldname = (String)fields.item(c).getAttributes().item(1).getNodeValue();
if(fieldname.equals("user_credential") || fieldname.equals("skills") || fieldname.equals("interests")) {
-
- //System.out.println(fieldname);
if(approved)
person.setCredentials(Credentials((String)profile.getFieldValue(fieldname)));
else
@@ -83,7 +81,14 @@ public Person loadPerson(SolrDocument profile) {
person.setPermissions(permission);
}
- } else {
+ } else if(fieldname.equals("bookmarks")){
+ if(!approved)
+ person.setBookmarks(null);
+ else{
+ person.setBookmarks(loadBookmarks((String)profile.getFieldValue("bookmarks")));
+ }
+ }
+ else {
String setFieldName = "set"+fieldname.substring(0, 1).toUpperCase()+fieldname.substring(1);
Method setMethod = person.getClass().getMethod(setFieldName, String.class);
if(approved)
@@ -99,7 +104,37 @@ public Person loadPerson(SolrDocument profile) {
}
return person;
}
-
+
+ public HashMap<String, TreeSet<String>> loadBookmarks(String bookmarks_xml){
+ HashMap<String, TreeSet<String>> bookmark = new HashMap<String, TreeSet<String>>();
+
+ try {
+ DocumentBuilderFactory dbf =
+ DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ InputSource is = new InputSource();
+ is.setCharacterStream(new StringReader(bookmarks_xml));
+
+ Document doc = db.parse(is);
+ NodeList users = doc.getDocumentElement().getChildNodes();
+
+ //This is the TreeSet that will house fullnames for each userID
+ TreeSet<String> fullname = new TreeSet<String>();
+ String userid;
+
+ for(int c=0; c<users.getLength(); c++){
+ fullname= Credentials((String)users.item(c).getAttributes().item(0).getNodeValue());
+ userid = (String)users.item(c).getAttributes().item(1).getNodeValue();
+ bookmark.put(userid, fullname);
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return bookmark;
+ }
+
public TreeSet<String> Credentials(String credentials){
TreeSet<String> Credentials = new TreeSet<String>();
@@ -101,19 +101,28 @@ private void addPerson(Person person) throws SolrServerException, IOException {
person.setPermissions(Person.getDefaultPermissions());
person.setCredentials(cred_default);
- person.setBio(" ");
- person.setEmail2(" ");
- person.setPhone2(" ");
- person.setTwitter(" ");
- person.setFacebook(" ");
- person.setLinkedin(" ");
- person.setIrc(" ");
+ person.setBio("");
+ person.setEmail2("");
+ person.setPhone2("");
+ person.setTwitter("");
+ person.setFacebook("");
+ person.setLinkedin("");
+ person.setIrc("");
person.setSkills(null);
person.setInterests(null);
- person.setPicture(" ");
+ person.setBookmarks(null);
+ person.setPicture("");
}
+ //to pull in HashMap Permissions
String permissions = Permissions(person.getPermissions());
+
+ //to pull in HashMap bookmarks
+ String bookmarks="";
+ if(person.getBookmarks()!=null)
+ bookmarks= Bookmarks(person.getBookmarks());
+
+ //to pull in interests and skills TreeSets
String credentials = person.getCredentials().toString().substring(1, person.getCredentials().toString().length()-1);
String skills="";
String interests="";
@@ -123,7 +132,7 @@ private void addPerson(Person person) throws SolrServerException, IOException {
if(person.getInterests()!=null)
interests = person.getInterests().toString().substring(1, person.getInterests().toString().length()-1);
-
+
solr_person.addField("otype", "person", 1.0f);
solr_person.addField("firstName", person.getFirstName(), 1.0f);
solr_person.addField("lastName", person.getLastName(), 1.0f);
@@ -138,7 +147,8 @@ private void addPerson(Person person) throws SolrServerException, IOException {
solr_person.addField("permissions", permissions);
solr_person.addField("user_credential", credentials);
-
+ //add bookmarks
+ solr_person.addField("bookmarks", bookmarks);
//additional contact info
solr_person.addField("bio", person.getBio(), 1.0f);
@@ -199,26 +209,46 @@ public String Permissions(HashMap<String,TreeSet<String>> permissions)
String credentials = new String();
credentials="<fields>";
- String key;
+ String field;
String credential_list;
- String temp;
+ String access_level;
while(permission.hasNext())
{
- key = permission.next().toString();
- credential_list = permissions.get(key).toString();
- temp = credential_list.substring(1, credential_list.length()- 1);
+ field = permission.next().toString();
+ credential_list = permissions.get(field).toString();
+ access_level = credential_list.substring(1, credential_list.length()- 1);
- credentials+="<field name=\"" + key + "\" allow = \"" +
- temp + "\"/>";
+ credentials+="<field name=\"" + field + "\" allow = \"" +
+ access_level + "\"/>";
}
-
-
credentials+="</fields>";
- //System.out.println(credentials);
-
return credentials;
+ }
+
+ public String Bookmarks(HashMap<String, TreeSet<String>> BOOKMARK)
+ {
+ Iterator<?> bookmark_iterator = BOOKMARK.keySet().iterator();
+
+ //XML to be written
+ String bookmarks= new String();
+ bookmarks="<users>";
+
+ String id;
+ String employee_list;
+ String fullname;
+
+ while(bookmark_iterator.hasNext())
+ {
+ id = bookmark_iterator.next().toString();
+ employee_list = BOOKMARK.get(id).toString();
+ fullname = employee_list.substring(1, employee_list.length()-1);
+
+ bookmarks+="<user id=\"" + id + "\" fullName = \"" + fullname + "\"/>";
+ }
+ bookmarks+="</users>";
+ return bookmarks;
}
}

0 comments on commit 574e14e

Please sign in to comment.