{"action":"created","issue":{"url":"https://api.github.com/repos/stormpath/stormpath-sdk-java/issues/127","labels_url":"https://api.github.com/repos/stormpath/stormpath-sdk-java/issues/127/labels{/name}","comments_url":"https://api.github.com/repos/stormpath/stormpath-sdk-java/issues/127/comments","events_url":"https://api.github.com/repos/stormpath/stormpath-sdk-java/issues/127/events","html_url":"https://github.com/stormpath/stormpath-sdk-java/issues/127","id":54267907,"number":127,"title":"Support getSingle*() methods","user":{"login":"chrylis","id":2394512,"avatar_url":"https://avatars.githubusercontent.com/u/2394512?v=3","gravatar_id":"","url":"https://api.github.com/users/chrylis","html_url":"https://github.com/chrylis","followers_url":"https://api.github.com/users/chrylis/followers","following_url":"https://api.github.com/users/chrylis/following{/other_user}","gists_url":"https://api.github.com/users/chrylis/gists{/gist_id}","starred_url":"https://api.github.com/users/chrylis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrylis/subscriptions","organizations_url":"https://api.github.com/users/chrylis/orgs","repos_url":"https://api.github.com/users/chrylis/repos","events_url":"https://api.github.com/users/chrylis/events{/privacy}","received_events_url":"https://api.github.com/users/chrylis/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-01-14T00:17:34Z","updated_at":"2015-04-01T18:52:27Z","closed_at":null,"body":"A number of methods (e.g., `getApplications()`) are frequently used to just select a single result (e.g., by name), but the methods all return `CollectionResource` objects. It would be helpful to have JPA-style `getSingle` methods (e.g., `client.getSingleApplication(criteria)`) that verified that exactly one item matches and return that single item.\r\n\r\nInstead of:\r\n\r\n    client.getApplications(Applications.where(Applications.name().eqIgnoreCase(stormpathInfo.getApplication()))).iterator().next();\r\n    // plus sanity checks\r\n\r\njust\r\n\r\n    client.getSingleApplication(Applications.where(Applications.name().eqIgnoreCase(stormpathInfo.getApplication())));"},"comment":{"url":"https://api.github.com/repos/stormpath/stormpath-sdk-java/issues/comments/88593428","html_url":"https://github.com/stormpath/stormpath-sdk-java/issues/127#issuecomment-88593428","issue_url":"https://api.github.com/repos/stormpath/stormpath-sdk-java/issues/127","id":88593428,"user":{"login":"antollinim","id":717498,"avatar_url":"https://avatars.githubusercontent.com/u/717498?v=3","gravatar_id":"","url":"https://api.github.com/users/antollinim","html_url":"https://github.com/antollinim","followers_url":"https://api.github.com/users/antollinim/followers","following_url":"https://api.github.com/users/antollinim/following{/other_user}","gists_url":"https://api.github.com/users/antollinim/gists{/gist_id}","starred_url":"https://api.github.com/users/antollinim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antollinim/subscriptions","organizations_url":"https://api.github.com/users/antollinim/orgs","repos_url":"https://api.github.com/users/antollinim/repos","events_url":"https://api.github.com/users/antollinim/events{/privacy}","received_events_url":"https://api.github.com/users/antollinim/received_events","type":"User","site_admin":false},"created_at":"2015-04-01T18:52:27Z","updated_at":"2015-04-01T18:52:27Z","body":"Hello @chrylis. We are going to add the `getSingle()` method to the `CollectionResource` interface. This will materialize this kind of operations:\r\n```java\r\nApplication app = client.getApplications(Applications.where(Applications.name().eqIgnoreCase(stormpathInfo.getApplication()))).getSingle();\r\nAccount account  = application.getAccounts(Accounts.where(Accounts.username().eqIgnoreCase(\"test@stormpath.com\"))).getSingle();\r\nGroup group = account.getGroups(Groups.criteria().withAccountMemberships(1, 0).and(Groups.name().endsWithIgnoreCase(\"X\"))).getSingle();\r\nAccount account = directory.getAccounts(Accounts.surname().eqIgnoreCase(\"Doe\")).getSingle();\r\n```\r\n\r\nThe `getSingle()` method will throw when the list contains zero or more than one item.\r\n\r\nAny thoughts?"}}