@@ -11,23 +11,36 @@ class CompanyUpdateBuilder {
1111 /**
1212 * Provide restrictions on the company data that can be sent via a user update
1313 */
14- static List <CompanyWithStringPlan > buildUserUpdateCompanies (CompanyCollection c ) {
14+ static List <CompanyWithStringPlan > buildUserUpdateCompanies (CompanyCollection add , CompanyCollection remove ) {
15+
1516 final ArrayList <CompanyWithStringPlan > updatableCompanies = Lists .newArrayList ();
16- if (c != null ) {
17- final List <Company > companies = c .getPage ();
17+ if (add != null ) {
18+ final List <Company > companies = add .getPage ();
19+ for (Company company : companies ) {
20+ updatableCompanies .add (prepareUpdatableCompany (company ));
21+ }
22+ }
23+
24+ if (remove != null ) {
25+ final List <Company > companies = remove .getPage ();
1826 for (Company company : companies ) {
19- final CompanyWithStringPlan updatableCompany = new CompanyWithStringPlan ();
20- updatableCompany .setCompanyID (company .getCompanyID ());
21- updatableCompany .setName (company .getName ());
22- updatableCompany .setSessionCount (company .getSessionCount ());
23- updatableCompany .setMonthlySpend (company .getMonthlySpend ());
24- updatableCompany .setRemoteCreatedAt (company .getRemoteCreatedAt ());
25- if (company .getPlan () != null ) {
26- updatableCompany .setPlan (company .getPlan ().getName ());
27- }
28- updatableCompanies .add (updatableCompany );
27+ updatableCompanies .add (prepareUpdatableCompany (company ).setRemove (Boolean .TRUE ));
2928 }
3029 }
30+
3131 return updatableCompanies ;
3232 }
33+
34+ private static CompanyWithStringPlan prepareUpdatableCompany (Company company ) {
35+ final CompanyWithStringPlan updatableCompany = new CompanyWithStringPlan ();
36+ updatableCompany .setCompanyID (company .getCompanyID ());
37+ updatableCompany .setName (company .getName ());
38+ updatableCompany .setSessionCount (company .getSessionCount ());
39+ updatableCompany .setMonthlySpend (company .getMonthlySpend ());
40+ updatableCompany .setRemoteCreatedAt (company .getRemoteCreatedAt ());
41+ if (company .getPlan () != null ) {
42+ updatableCompany .setPlan (company .getPlan ().getName ());
43+ }
44+ return updatableCompany ;
45+ }
3346}
0 commit comments