@@ -22,15 +22,22 @@ public class Tag extends TypedData {
2222 private static final Logger logger = LoggerFactory .getLogger ("intercom-java" );
2323 private static final HashMap <String , String > SENTINEL = Maps .newHashMap ();
2424
25+ public static Tag tag (Tag tag , User ... users ) throws InvalidException , AuthorizationException {
26+ return tag (tag , new UserCollection (Lists .newArrayList (users )));
27+ }
2528
2629 public static Tag tag (Tag tag , UserCollection users ) throws InvalidException , AuthorizationException {
27- TagTypedCollection tagTypedCollection = createTagTypedCollection (tag , users );
28- return DataResource .create (tagTypedCollection , "tags" , Tag .class );
30+ TaggableCollection taggableCollection = createTagTypedCollection (tag , users );
31+ return DataResource .create (taggableCollection , "tags" , Tag .class );
32+ }
33+
34+ public static Tag tag (Tag tag , Company ... companies ) throws InvalidException , AuthorizationException {
35+ return tag (tag , new CompanyCollection (Lists .newArrayList (companies )));
2936 }
3037
3138 public static Tag tag (Tag tag , CompanyCollection companies ) throws InvalidException , AuthorizationException {
32- TagTypedCollection tagTypedCollection = createTagTypedCollection (tag , companies );
33- return DataResource .create (tagTypedCollection , "tags" , Tag .class );
39+ TaggableCollection taggableCollection = createTagTypedCollection (tag , companies );
40+ return DataResource .create (taggableCollection , "tags" , Tag .class );
3441 }
3542
3643 public static Tag create (Tag tag ) throws InvalidException , AuthorizationException {
@@ -57,17 +64,22 @@ public static TagCollection list() throws InvalidException, AuthorizationExcepti
5764 }
5865
5966 @ VisibleForTesting
60- static TagTypedCollection createTagTypedCollection (Tag tag , UserCollection users ) {
61- TagTypedCollection tagTypedCollection = new TagTypedCollection ();
62- tagTypedCollection .setName (tag .getName ());
63- tagTypedCollection .setId (tag .getId ());
64- final List <Map <String ,String >> usersLite = Lists .newArrayList ();
67+ static TaggableCollection createTagTypedCollection (Tag tag , UserCollection users ) {
68+ TaggableCollection taggableCollection = new TaggableCollection ();
69+ taggableCollection .setName (tag .getName ());
70+ taggableCollection .setId (tag .getId ());
71+ final List <Map <String , Object >> usersLite = Lists .newArrayList ();
6572 final List <User > pageItems = users .getPageItems ();
6673 for (User user : pageItems ) {
67- Map <String , String > userMap = Maps .newHashMap ();
74+ Map <String , Object > userMap = Maps .newHashMap ();
6875 final String id = user .getId ();
6976 final String email = user .getEmail ();
7077 final String userId = user .getUserId ();
78+
79+ if (user .isUntag ()) {
80+ userMap .put ("untag" , true );
81+ }
82+
7183 if (!Strings .isNullOrEmpty (id )) {
7284 userMap .put ("id" , id );
7385 usersLite .add (userMap );
@@ -81,64 +93,69 @@ static TagTypedCollection createTagTypedCollection(Tag tag, UserCollection users
8193 logger .warn ("no identifiers found for user tag target, skipping [" + tag + "] [" + user .toString () + "]" );
8294 }
8395 }
84- tagTypedCollection .setUsers (usersLite );
85- return tagTypedCollection ;
96+ taggableCollection .setUsers (usersLite );
97+ return taggableCollection ;
8698 }
8799
88100 @ VisibleForTesting
89- static TagTypedCollection createTagTypedCollection (Tag tag , CompanyCollection companies ) {
90- TagTypedCollection tagTypedCollection = new TagTypedCollection ();
91- tagTypedCollection .setName (tag .getName ());
92- tagTypedCollection .setId (tag .getId ());
101+ static TaggableCollection createTagTypedCollection (Tag tag , CompanyCollection companies ) {
102+ TaggableCollection taggableCollection = new TaggableCollection ();
103+ taggableCollection .setName (tag .getName ());
104+ taggableCollection .setId (tag .getId ());
93105
94- final List <Map <String , String >> companiesLite = Lists .newArrayList ();
106+ final List <Map <String , Object >> companiesLite = Lists .newArrayList ();
95107 final List <Company > pageItems = companies .getPageItems ();
96108 for (Company company : pageItems ) {
97- Map <String , String > companyMap = Maps .newHashMap ();
109+ Map <String , Object > companyMap = Maps .newHashMap ();
98110 final String companyID = company .getCompanyID ();
99- final String id1 = company .getId ();
111+ final String id = company .getId ();
100112 final String name = company .getName ();
113+
114+ if (company .isUntag ()) {
115+ companyMap .put ("untag" , true );
116+ }
117+
101118 if (!Strings .isNullOrEmpty (companyID )) {
102119 companyMap .put ("company_id" , companyID );
103120 companiesLite .add (companyMap );
104- } else if (!Strings .isNullOrEmpty (id1 )) {
105- companyMap .put ("id" , id1 );
121+ } else if (!Strings .isNullOrEmpty (id )) {
122+ companyMap .put ("id" , id );
106123 companiesLite .add (companyMap );
107124 } else if (!Strings .isNullOrEmpty (name )) {
108125 companyMap .put ("name" , name );
109126 companiesLite .add (companyMap );
110127 } else {
111128 logger .warn ("no identifiers found for company tag target, skipping [" + tag + "] [" + company .toString () + "]" );
112129 }
113- tagTypedCollection .setCompanies (companiesLite );
130+ taggableCollection .setCompanies (companiesLite );
114131 }
115- return tagTypedCollection ;
132+ return taggableCollection ;
116133 }
117134
118135 @ SuppressWarnings ("UnusedDeclaration" )
119136 @ JsonIgnoreProperties (ignoreUnknown = true )
120137 @ JsonInclude (JsonInclude .Include .NON_DEFAULT )
121- static class TagTypedCollection extends Tag {
138+ static class TaggableCollection extends Tag {
122139
123140 @ JsonProperty ("users" )
124- private List <Map <String , String >> users ;
141+ private List <Map <String , Object >> users ;
125142
126143 @ JsonProperty ("companies" )
127- private List <Map <String , String >> companies ;
144+ private List <Map <String , Object >> companies ;
128145
129- public List <Map <String , String >> getUsers () {
146+ public List <Map <String , Object >> getUsers () {
130147 return users ;
131148 }
132149
133- public void setUsers (List <Map <String , String >> usersLite ) {
150+ public void setUsers (List <Map <String , Object >> usersLite ) {
134151 this .users = usersLite ;
135152 }
136153
137- public List <Map <String , String >> getCompanies () {
154+ public List <Map <String , Object >> getCompanies () {
138155 return companies ;
139156 }
140157
141- public void setCompanies (List <Map <String , String >> companies ) {
158+ public void setCompanies (List <Map <String , Object >> companies ) {
142159 this .companies = companies ;
143160 }
144161 }
0 commit comments