Version 1.2: Refactored JDBLabsWebTimeline, cleaned up libs.
* Removed superfluous ``signpost`` library used by ``HTTPBuilder`` for OAuth support. * Refactored JDBLabsWebTimeline to throw appropriate exceptions when problems occur while communicating with the server.
This commit is contained in:
		
							
								
								
									
										9
									
								
								doc/issues/0000tn5.rst
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								doc/issues/0000tn5.rst
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					Add unit tests.
 | 
				
			||||||
 | 
					===============
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					----
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					=========  ==========
 | 
				
			||||||
 | 
					Created:   2011-06-28
 | 
				
			||||||
 | 
					Resolved:  YYYY-MM-DD
 | 
				
			||||||
 | 
					=========  ==========
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								release/timestamper-lib-1.2.jar
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								release/timestamper-lib-1.2.jar
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							@@ -37,9 +37,20 @@ public class JDBLabsWebTimelineSource extends TimelineSource {
 | 
				
			|||||||
        password = config.getProperty(CONFIG_PWD, "")
 | 
					        password = config.getProperty(CONFIG_PWD, "")
 | 
				
			||||||
        timelineId = config.getProperty(CONFIG_TIMELINE, "")
 | 
					        timelineId = config.getProperty(CONFIG_TIMELINE, "")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        baseUri = new URI(uri.scheme + "://" + uri.authority)
 | 
					        baseUri = new URI(uri.scheme + "://" + uri.authority + "/ts_api/")
 | 
				
			||||||
        http = new HTTPBuilder(baseUri)
 | 
					        http = new HTTPBuilder(baseUri)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // set some default error handlers
 | 
				
			||||||
 | 
					        http.handler.'500' = { resp, json ->
 | 
				
			||||||
 | 
					            throw new IOException("The web timeline reported an internal " +
 | 
				
			||||||
 | 
					                "error: ${json.error ?: 'no details available'}") }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        http.handler.failure = {resp, json ->
 | 
				
			||||||
 | 
					            throw new IOException("Unable to complete the operation: error " +
 | 
				
			||||||
 | 
					                "communicating to the web timeline.\n" +
 | 
				
			||||||
 | 
					                "${resp.statusLine}: ${json}") }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // init our hash of known entries
 | 
				
			||||||
        entryHashes = [:]
 | 
					        entryHashes = [:]
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -53,9 +64,15 @@ public class JDBLabsWebTimelineSource extends TimelineSource {
 | 
				
			|||||||
        authenticate()
 | 
					        authenticate()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // load the timeline information
 | 
					        // load the timeline information
 | 
				
			||||||
        timelineJSON = http.get(
 | 
					        http.request(GET, JSON) {
 | 
				
			||||||
            path: "/ts_api/timelines/${username}/${timelineId}",
 | 
					            uri.path = "timelines/${username}/${timelineId}"
 | 
				
			||||||
            contentType: JSON) { resp, json -> json }
 | 
					
 | 
				
			||||||
 | 
					            response.'404' = { resp ->
 | 
				
			||||||
 | 
					                throw new IOException("No timeline '${timelineId}' for user " +
 | 
				
			||||||
 | 
					                    "'${username}'") }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            response.success = { resp, json -> timelineJSON = json }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        timeline = new Timeline()
 | 
					        timeline = new Timeline()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -68,7 +85,7 @@ public class JDBLabsWebTimelineSource extends TimelineSource {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // load the timeline entries
 | 
					        // load the timeline entries
 | 
				
			||||||
        entryListJSON = http.get(
 | 
					        entryListJSON = http.get(
 | 
				
			||||||
            path: "/ts_api/entries/${username}/${timelineId}",
 | 
					            path: "entries/${username}/${timelineId}",
 | 
				
			||||||
            contentType: JSON,
 | 
					            contentType: JSON,
 | 
				
			||||||
            query: [
 | 
					            query: [
 | 
				
			||||||
                byDate: true,
 | 
					                byDate: true,
 | 
				
			||||||
@@ -115,11 +132,11 @@ public class JDBLabsWebTimelineSource extends TimelineSource {
 | 
				
			|||||||
        // delete all entries that used to be present but are not any longer
 | 
					        // delete all entries that used to be present but are not any longer
 | 
				
			||||||
        deletedEntries.each { hash, entryId ->
 | 
					        deletedEntries.each { hash, entryId ->
 | 
				
			||||||
            http.request(DELETE) {
 | 
					            http.request(DELETE) {
 | 
				
			||||||
                uri.path = "/ts_api/entries/${username}/${timelineId}/${entryId}"
 | 
					                uri.path = "entries/${username}/${timelineId}/${entryId}"
 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // TODO: error handling, make sure this only happens on success
 | 
					                response.'404' = { resp -> entryHashes.remove(hash) }
 | 
				
			||||||
            entryHashes.remove(hash)
 | 
					                response.success = { resp -> entryHashes.remove(hash) }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // add all new entries
 | 
					        // add all new entries
 | 
				
			||||||
@@ -131,32 +148,30 @@ public class JDBLabsWebTimelineSource extends TimelineSource {
 | 
				
			|||||||
                timestamp: isoDateFormat.format(entry.timestamp)
 | 
					                timestamp: isoDateFormat.format(entry.timestamp)
 | 
				
			||||||
            ]
 | 
					            ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // TODO: error handling
 | 
					            http.request(POST, JSON) {
 | 
				
			||||||
            http.post(
 | 
					                uri.path = "entries/${username}/${timelineId}"
 | 
				
			||||||
                path: "/ts_api/entries/${username}/${timelineId}",
 | 
					                requestContentType = JSON
 | 
				
			||||||
                contentType: JSON,
 | 
					                body = entryBody
 | 
				
			||||||
                requestContentType: JSON,
 | 
					
 | 
				
			||||||
                body: entryBody) { resp, json ->
 | 
					                response.success = { entryHashes.put(fullHash(entry), entry.id) }
 | 
				
			||||||
                    entryHashes.put(fullHash(entry), entry)
 | 
					            }
 | 
				
			||||||
                    json
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public boolean isAuthenticated() { return false; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void authenticate() throws AuthenticationException {
 | 
				
			||||||
 | 
					        http.request(POST, JSON) { req ->
 | 
				
			||||||
 | 
					            uri.path = '/ts_api/login'
 | 
				
			||||||
 | 
					            requestContentType = JSON
 | 
				
			||||||
 | 
					            body = [ username: this.username,
 | 
				
			||||||
 | 
					                    password: this.password ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            response.'401' = { resp ->
 | 
				
			||||||
 | 
					                throw new AuthenticationException(
 | 
				
			||||||
 | 
					                    "Unable to connect to ${baseUri}: " +
 | 
				
			||||||
 | 
					                    "Invalid username/password combination.") }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean isAuthenticated() {
 | 
					 | 
				
			||||||
        // TODO
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void authenticate() {
 | 
					 | 
				
			||||||
        // TODO: error detection
 | 
					 | 
				
			||||||
        http.post(
 | 
					 | 
				
			||||||
            path: '/ts_api/login',
 | 
					 | 
				
			||||||
            contentType: JSON,
 | 
					 | 
				
			||||||
            requestContentType: JSON,
 | 
					 | 
				
			||||||
            body: [ username: this.username,
 | 
					 | 
				
			||||||
                    password: this.password ]) { resp, json -> json }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected int fullHash(TimelineMarker tm) {
 | 
					    protected int fullHash(TimelineMarker tm) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user