Update.java
01 package com.bigllc.retsiq.examples;
02 
03 import java.net.MalformedURLException;
04 import java.util.HashMap;
05 import java.util.Map;
06 import java.util.Map.Entry;
07 
08 import com.bigllc.retsiq.simpleclient.RETSClientException;
09 import com.bigllc.retsiq.simpleclient.RETSConnection;
10 import com.bigllc.retsiq.simpleclient.RETSUserSession;
11 import com.bigllc.retsiq.simpleclient.UpdateError;
12 import com.bigllc.retsiq.simpleclient.UpdateResponse;
13 
14 /**
15  * Example to demonstrate update the example shows how to edit a record.
16  
17  @author Marc G. Smith
18  */
19 public class Update 
20 {
21   public static void main(String[] argsthrows MalformedURLException 
22   {
23     String loginurl   = "http://rets.server.com/rets/login";
24     String username   = "username";
25     String password   = "password";
26     String path     = "/Property/Residential/EDIT";
27     
28     // Create the connection class
29     RETSConnection connection = new RETSConnection(loginurl);
30     RETSUserSession session = null;
31     
32     try {
33       // Authenticate the user and get session
34       session = connection.getSession(username, password);
35       
36       // Fields to update
37       Map<String, String> record = new HashMap<String, String>();
38       record.put("UID""123456");
39       record.put("AGENTLIST",      "AGENT1");
40       record.put("OFFICELIST",     "OFFICE1");
41       record.put("STREETNUM",     "123");
42       
43       // Execute the update
44       UpdateResponse response = session.update(
45         path, record, RETSUserSession.VALIDATEFLAG_UPDATE);
46       
47       // Check for errors and print them out
48       if(!response.getUpdateSuccess()) {
49         for(UpdateError err: response.getErrors()) {
50           System.out.println("Error=" + err);
51         }
52       }
53 
54       System.out.println("-------------");
55       
56       // Print out the returned record
57       Map<String, String> returnedRecord = response.getReturnedRecord();
58       for(Entry<String, String> entry : returnedRecord.entrySet()) {
59         System.out.println(
60           entry.getKey() "=" + entry.getValue());
61       }
62     }
63     catch(RETSClientException e) {
64       System.err.println(e.getMessage());
65     }
66     finally {
67       if(session != null) { 
68         try {
69           session.logout()
70         
71         catch(RETSClientException e) {
72           System.err.println(e.getMessage());
73         }
74       }
75     }
76   }
77 }