[Pki-devel] [PATCH] 568 Simplified login response formats
Fraser Tweedale
ftweedal at redhat.com
Mon Apr 13 06:43:35 UTC 2015
On Fri, Apr 10, 2015 at 04:31:06PM -0500, Endi Sukma Dewata wrote:
> The formats of XML and JSON responses of the AccountService.login()
> have been modified to be more consistent and user-friendly.
>
> https://fedorahosted.org/pki/ticket/1343
>
> --
> Endi S. Dewata
ACK.
> From 3838a83fa749ab7ed038e1b0463d3f908485cfd1 Mon Sep 17 00:00:00 2001
> From: "Endi S. Dewata" <edewata at redhat.com>
> Date: Fri, 10 Apr 2015 04:44:30 -0400
> Subject: [PATCH] Simplified login response formats
>
> The formats of XML and JSON responses of the AccountService.login()
> have been modified to be more consistent and user-friendly.
>
> https://fedorahosted.org/pki/ticket/1343
> ---
> .../com/netscape/certsrv/account/AccountInfo.java | 42 +++++++++-------------
> 1 file changed, 16 insertions(+), 26 deletions(-)
>
> diff --git a/base/common/src/com/netscape/certsrv/account/AccountInfo.java b/base/common/src/com/netscape/certsrv/account/AccountInfo.java
> index 02e40746a41c1f42b174567c0c73e88138a2fbdc..7943d229a23198771d06d288cf31c78604995f77 100644
> --- a/base/common/src/com/netscape/certsrv/account/AccountInfo.java
> +++ b/base/common/src/com/netscape/certsrv/account/AccountInfo.java
> @@ -20,9 +20,9 @@ package com.netscape.certsrv.account;
>
> import java.io.StringReader;
> import java.io.StringWriter;
> -import java.util.ArrayList;
> import java.util.Arrays;
> -import java.util.List;
> +import java.util.Collection;
> +import java.util.TreeSet;
>
> import javax.xml.bind.JAXBContext;
> import javax.xml.bind.Marshaller;
> @@ -30,7 +30,6 @@ import javax.xml.bind.Unmarshaller;
> import javax.xml.bind.annotation.XmlAttribute;
> import javax.xml.bind.annotation.XmlElement;
> import javax.xml.bind.annotation.XmlRootElement;
> -import javax.xml.bind.annotation.XmlValue;
> import javax.xml.bind.annotation.adapters.XmlAdapter;
> import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
>
> @@ -56,7 +55,7 @@ public class AccountInfo {
> String id;
> String fullName;
> String email;
> - List<String> roles;
> + Collection<String> roles = new TreeSet<String>();
>
> @XmlAttribute(name="id")
> public String getID() {
> @@ -87,12 +86,13 @@ public class AccountInfo {
>
> @XmlElement(name="Roles")
> @XmlJavaTypeAdapter(RolesAdapter.class)
> - public List<String> getRoles() {
> + public Collection<String> getRoles() {
> return roles;
> }
>
> - public void setRoles(List<String> roles) {
> - this.roles = roles;
> + public void setRoles(Collection<String> roles) {
> + this.roles.clear();
> + this.roles.addAll(roles);
> }
>
> @Override
> @@ -157,39 +157,29 @@ public class AccountInfo {
> }
> }
>
> - public static class RolesAdapter extends XmlAdapter<RoleList, List<String>> {
> + public static class RolesAdapter extends XmlAdapter<RoleList, Collection<String>> {
>
> - public RoleList marshal(List<String> roles) {
> + public RoleList marshal(Collection<String> roles) {
> RoleList list = new RoleList();
> - for (String value : roles) {
> - Role role = new Role();
> - role.value = value;
> - list.entries.add(role);
> - }
> + list.roles = roles.toArray(new String[roles.size()]);
> return list;
> }
>
> - public List<String> unmarshal(RoleList list) {
> - List<String> roles = new ArrayList<String>();
> - for (Role role : list.entries) {
> - roles.add(role.value);
> + public Collection<String> unmarshal(RoleList list) {
> + Collection<String> roles = new TreeSet<String>();
> + if (list.roles != null) {
> + roles.addAll(Arrays.asList(list.roles));
> }
> return roles;
> }
> }
>
> public static class RoleList {
> - public List<Role> entries = new ArrayList<Role>();
> - }
> -
> - @XmlRootElement(name="Role")
> - public static class Role {
>
> - @XmlValue
> - public String value;
> + @XmlElement(name="Role")
> + public String[] roles;
> }
>
> -
> public static void main(String args[]) throws Exception {
>
> AccountInfo before = new AccountInfo();
> --
> 1.9.3
>
> _______________________________________________
> Pki-devel mailing list
> Pki-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/pki-devel
More information about the Pki-devel
mailing list