01 package com.bigllc.retsiq.examples;
02
03 import java.io.File;
04 import java.net.MalformedURLException;
05 import java.util.Arrays;
06 import java.util.List;
07
08 import com.bigllc.retsiq.simpleclient.ObjectRecord;
09 import com.bigllc.retsiq.simpleclient.RETSClientException;
10 import com.bigllc.retsiq.simpleclient.RETSConnection;
11 import com.bigllc.retsiq.simpleclient.RETSUserSession;
12 import com.bigllc.retsiq.simpleclient.RecordCollectionResponseHandler;
13 import com.bigllc.retsiq.simpleclient.SearchRecord;
14
15 /**
16 * Example to demonstrate how to get object such as photos for a record.
17 * The example performs a search limited to 3 records and then fetches
18 * all the the photos associated with those records.
19 * <br/><br/>
20 * The objects are output to the specified directory with the content ID
21 * and object ID as the filename.
22 *
23 * @author Marc G. Smith
24 */
25 public class GetObjects
26 {
27 public static void main(String[] args) throws MalformedURLException
28 {
29 String loginurl = "http://rets.server.com/rets/login";
30 String username = "username";
31 String password = "password";
32 String path = "/Property/Residential";
33 String query = "(LISTSTATUS=ACTIVE),(OFFICELIST=OFFICE)";
34 String objectPath = "/Property/Photo/";
35 int limit = 3;
36 File directory = new File("/tmp");
37
38 // Create the connection class
39 RETSConnection connection = new RETSConnection(loginurl);
40 RETSUserSession session = null;
41
42 try {
43 // Authenticate the user and get session
44 session = connection.getSession(username, password);
45
46 // Create the output handler. This is a handler that
47 // creates a list of all the records.
48 RecordCollectionResponseHandler handler =
49 new RecordCollectionResponseHandler();
50
51 // Select only the UID for the listing.
52 List<String> select = Arrays.asList(new String[] {
53 "MLSNUM"
54 });
55
56 // Execute the search
57 session.search(path, query, select, limit, 0, handler);
58
59 // Iterate through all the records.
60 for(SearchRecord record: handler.getRecords()) {
61 String uid = record.getValue("MLSNUM");
62
63 // Create the object path for all the photo
64 // objects for the record
65 String objectFullPath = objectPath + uid + ":*";
66
67 // Fetch the objects
68 List<ObjectRecord> objects =
69 session.getObjects(objectFullPath, directory);
70
71 // Iterate through all the objects and print out the
72 // info.
73 System.out.println("Object Info For MLSNUM " + uid);
74 System.out.println("----------------------------------");
75 for(ObjectRecord object: objects) {
76 System.out.println(object);
77 }
78 System.out.println();
79
80 }
81 }
82 catch(RETSClientException e) {
83 System.err.println(e.getMessage());
84 }
85 finally {
86 if(session != null) {
87 try {
88 session.logout();
89 }
90 catch(RETSClientException e) {
91 System.err.println(e.getMessage());
92 }
93 }
94 }
95 }
96 }
|