From 3838a83fa749ab7ed038e1b0463d3f908485cfd1 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" 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 roles; + Collection roles = new TreeSet(); @XmlAttribute(name="id") public String getID() { @@ -87,12 +86,13 @@ public class AccountInfo { @XmlElement(name="Roles") @XmlJavaTypeAdapter(RolesAdapter.class) - public List getRoles() { + public Collection getRoles() { return roles; } - public void setRoles(List roles) { - this.roles = roles; + public void setRoles(Collection roles) { + this.roles.clear(); + this.roles.addAll(roles); } @Override @@ -157,39 +157,29 @@ public class AccountInfo { } } - public static class RolesAdapter extends XmlAdapter> { + public static class RolesAdapter extends XmlAdapter> { - public RoleList marshal(List roles) { + public RoleList marshal(Collection 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 unmarshal(RoleList list) { - List roles = new ArrayList(); - for (Role role : list.entries) { - roles.add(role.value); + public Collection unmarshal(RoleList list) { + Collection roles = new TreeSet(); + if (list.roles != null) { + roles.addAll(Arrays.asList(list.roles)); } return roles; } } public static class RoleList { - public List entries = new ArrayList(); - } - - @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