private Note findAlreadyExistingNoteWithSameAssociatedElement(final CreateNote newNote) { SingleElementHandler<Note> handler = new SingleElementHandler<Note>() { @Override public void handle(Note oldNote) { if(newNote.hasAssociatedElement()) { String firstCommentText = oldNote.comments.get(0).text; String newNoteRegex = getAssociatedElementRegex(newNote); if(firstCommentText.matches(newNoteRegex)) { super.handle(oldNote); } } } }; final int hideClosedNoteAfter = 7; osmDao.getAll(new BoundingBox( newNote.position.getLatitude(), newNote.position.getLongitude(), newNote.position.getLatitude(), newNote.position.getLongitude() ), handler, 10, hideClosedNoteAfter); return handler.get(); }
/** * @param id id of the note * @param text comment to be added to the note. Must not be null or empty * * @throws OsmConflictException if the note has already been closed. * @throws OsmAuthorizationException if this application is not authorized to write notes * (Permission.WRITE_NOTES) * @throws OsmNotFoundException if the note with the given id does not exist (anymore) * * @return the updated commented note */ public Note comment(long id, String text) { if(text.isEmpty()) { throw new IllegalArgumentException("comment must not be empty"); } SingleElementHandler<Note> noteHandler = new SingleElementHandler<>(); makeSingleNoteRequest(id, "comment", text, new NotesParser(noteHandler)); return noteHandler.get(); }
/** @return the user info of the current user * @throws OsmAuthorizationException if the user does not have the permission * Permission.READ_PREFERENCES_AND_USER_DETAILS*/ public UserDetails getMine() { SingleElementHandler<UserInfo> handler = new SingleElementHandler<>(); osm.makeAuthenticatedRequest("user/details", null, new UserDetailsParser(handler)); return (UserDetails) handler.get(); }
/** * Reopen the given note with the given reason. The reason is optional. * * @throws OsmConflictException if the note has already been reopened. * @throws OsmAuthorizationException if this application is not authorized to write notes * (Permission.WRITE_NOTES) * @throws OsmNotFoundException if the note with the given id does not exist (anymore) * * @return the updated reopened note */ public Note reopen(long id, String reason) { SingleElementHandler<Note> noteHandler = new SingleElementHandler<>(); makeSingleNoteRequest(id, "reopen", reason, new NotesParser(noteHandler)); return noteHandler.get(); }
/** * @throws OsmAuthorizationException if not logged in * @return the user info of the given user. Null if the user does not exist. * */ public UserInfo get(long userId) { try { SingleElementHandler<UserInfo> handler = new SingleElementHandler<>(); osm.makeAuthenticatedRequest("user/" + userId, null, new UserInfoParser(handler)); return handler.get(); } catch(OsmNotFoundException e) { return null; } }
/** * Add a comment to the given changeset. The changeset must already be closed. Adding a comment * to a changeset automatically subscribes the user to it. * * TODO monitor https://github.com/openstreetmap/openstreetmap-website/issues/1165 * * @param id id of the changeset * @param text text to add to the changeset. Must not be empty * * @return the updated changeset * * @throws OsmAuthorizationException if this application is not authorized to modify the map * (Permission.MODIFY_MAP) * @throws OsmConflictException if the changeset is not yet closed. (Only closed changesets can * be commented */ public ChangesetInfo comment(long id, String text) { if(text.isEmpty()) { throw new IllegalArgumentException("Text must not be empty"); } SingleElementHandler<ChangesetInfo> handler = new SingleElementHandler<>(); String apiCall = CHANGESET + "/" + id + "/comment?text=" + urlEncodeText(text); osm.makeAuthenticatedRequest(apiCall, "POST", new ChangesetParser(handler)); return handler.get(); }
/** Get the changeset information with the given id. Always includes the changeset discussion. * * @param id changeset id * @throws OsmAuthorizationException if not logged in * @return info for the given changeset. Null if it does not exist. */ public ChangesetInfo get(long id) { SingleElementHandler<ChangesetInfo> handler = new SingleElementHandler<>(); String query = CHANGESET + "/" + id + "?include_discussion=true"; try { osm.makeAuthenticatedRequest(query, null, new ChangesetParser(handler)); } catch(OsmNotFoundException e) { return null; } return handler.get(); }
/** * Close aka resolve the note with the given id and reason. * * @param id id of the note * @param reason comment to be added to the note as a reason for it being closed. Optional. * * @throws OsmConflictException if the note has already been closed. * @throws OsmAuthorizationException if this application is not authorized to write notes * (Permission.WRITE_NOTES) * @throws OsmNotFoundException if the note with the given id does not exist (anymore) * * @return the closed note */ public Note close(long id, String reason) { SingleElementHandler<Note> noteHandler = new SingleElementHandler<>(); makeSingleNoteRequest(id, "close", reason, new NotesParser(noteHandler)); return noteHandler.get(); }
/** * @param id id of the note * * @throws OsmAuthorizationException if not logged in * * @return the note with the given id. null if the note with that id does not exist (anymore). */ public Note get(long id) { SingleElementHandler<Note> noteHandler = new SingleElementHandler<>(); try { osm.makeAuthenticatedRequest(NOTES + "/" + id, null, new NotesParser(noteHandler)); } catch (OsmNotFoundException e) { return null; } return noteHandler.get(); }
/** * Create a new note at the given location * * @param pos position of the note. Must not be null. * @param text text for the new note. Must not be empty nor null. * * @throws OsmAuthorizationException if this application is not authorized to write notes * (Permission.WRITE_NOTES) * * @return the new note */ public Note create(LatLon pos, String text) { if(text.isEmpty()) { throw new IllegalArgumentException("Text may not be empty"); } String data = "lat=" + numberFormat.format(pos.getLatitude()) + "&lon=" + numberFormat.format(pos.getLongitude()) + "&text=" + urlEncode(text); String call = NOTES + "?" + data; SingleElementHandler<Note> noteHandler = new SingleElementHandler<>(); osm.makeAuthenticatedRequest(call, "POST", new NotesParser(noteHandler)); return noteHandler.get(); }
/** * Get information about a given GPS trace or null if it does not exist. * * @throws OsmAuthorizationException if this application is not authorized to read the user's * traces (Permission.READ_GPS_TRACES) * OR if the trace in question is not the user's own trace * and at the same time it is not public * OR if not logged in at all */ public GpsTraceDetails get(long id) { SingleElementHandler<GpsTraceDetails> handler = new SingleElementHandler<>(); try { osm.makeAuthenticatedRequest(GPX + "/" + id, "GET", new GpsTracesParser(handler) ); } catch(OsmNotFoundException e) { return null; } return handler.get(); }
private GpsTrackpoint parseOne(String xml) { SingleElementHandler<GpsTrackpoint> handler = new SingleElementHandler<>(); parse(xml, handler); return handler.get(); }
private Note parseOne(String xml) { SingleElementHandler<Note> handler = new SingleElementHandler<>(); parse(xml, handler); return handler.get(); }
private ChangesetInfo parseOne(String xml) { SingleElementHandler<ChangesetInfo> handler = new SingleElementHandler<>(); parse(xml, handler); return handler.get(); }
private GpsTraceDetails parseOne(String xml) { try { SingleElementHandler<GpsTraceDetails> handler = new SingleElementHandler<>(); new GpsTracesParser(handler).parse(TestUtils.asInputStream(xml)); return handler.get(); } catch(IOException e) { throw new RuntimeException(e); } }
private UserDetails parseOneDetails(String xml) { try { SingleElementHandler<UserInfo> handler = new SingleElementHandler<>(); new UserDetailsParser(handler).parse(TestUtils.asInputStream(xml)); return (UserDetails) handler.get(); } catch(IOException e) { throw new RuntimeException(e); } } }
private UserInfo parseOne(String xml) { try { SingleElementHandler<UserInfo> handler = new SingleElementHandler<>(); new UserInfoParser(handler).parse(TestUtils.asInputStream(xml)); return handler.get(); } catch(IOException e) { throw new RuntimeException(e); } }
private DiffElement parseOne(String xml) { try { SingleElementHandler<DiffElement> handler = new SingleElementHandler<>(); new MapDataDiffParser(handler).parse(TestUtils.asInputStream(xml)); return handler.get(); } catch(IOException e) { throw new RuntimeException(e); } } }
private GpsTraceDetails writeAndRead(long id, GpsTraceDetails.Visibility visibility, String description, List<String> tags) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); new GpsTraceWriter(id, visibility, description, tags).write(out); String xml = TestUtils.asString(out); SingleElementHandler<GpsTraceDetails> handler = new SingleElementHandler<>(); new GpsTracesParser(handler).parse(TestUtils.asInputStream(xml)); return handler.get(); }
public void testReadDiff() { MapDataDao mapDataDao = new MapDataDao(privilegedConnection); final LatLon POS = new OsmLatLon(55.42313, 50.13221); final long PLACEHOLDER_ID = -33; Element node = new OsmNode(PLACEHOLDER_ID, 1, POS, null); SingleElementHandler<DiffElement> handlerCreated = new SingleElementHandler<>(); mapDataDao.updateMap("test", "test", Arrays.asList(node), handlerCreated); DiffElement diffCreated = handlerCreated.get(); // update id and delete again... (clean up before asserting) OsmNode deleteNode = new OsmNode(diffCreated.serverId, diffCreated.serverVersion, POS, null); deleteNode.setDeleted(true); SingleElementHandler<DiffElement> handlerDeleted = new SingleElementHandler<>(); mapDataDao.updateMap("clean up test", "test", Arrays.asList((Element) deleteNode), handlerDeleted); DiffElement diffDeleted = handlerDeleted.get(); assertEquals(PLACEHOLDER_ID, diffCreated.clientId); assertEquals(Element.Type.NODE, diffCreated.type); assertNotNull(diffCreated.serverVersion); assertEquals(1, (int) diffCreated.serverVersion); assertEquals((long) diffCreated.serverId, diffDeleted.clientId); assertEquals(Element.Type.NODE, diffDeleted.type); assertNull(diffDeleted.serverId); assertNull(diffDeleted.serverVersion); }