-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.xml
6933 lines (6059 loc) · 333 KB
/
data.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">
<changeSet id="#4150_20190415 - Disable standard jobs" author="EdwardPLegaspi">
<update tableName="meveo_job_instance">
<column name="timerentity_id" value="NULL"></column>
<column name="disabled" valueNumeric="0"></column>
</update>
<delete tableName="meveo_timer">
</delete>
</changeSet>
<changeSet id="#4092_20190415 - Add SelfCare Settings" author="EdwardPLegaspi">
<insert tableName="adm_permission">
<column name="id" valueNumeric="-117" />
<column name="name" value="API User" />
<column name="permission" value="apiAccess" />
</insert>
<insert tableName="adm_permission">
<column name="id" valueNumeric="-118" />
<column name="name" value="Administration visualization" />
<column name="permission" value="administrationVisualization" />
</insert>
<insert tableName="adm_role">
<column name="id" valueNumeric="-112" />
<column name="version" valueNumeric="0" />
<column name="role_description" value="selfcareDefault" />
<column name="role_name" value="selfcareDefault" />
</insert>
<insert tableName="adm_role_permission">
<column name="role_id" value="-112"></column>
<column name="permission_id" value="-117"></column>
</insert>
<insert tableName="adm_role_permission">
<column name="role_id" value="-112"></column>
<column name="permission_id" value="-118"></column>
</insert>
<insert tableName="adm_user">
<column name="id" valueNumeric="-5" />
<column name="version" valueNumeric="0" />
<column name="created" valueDate="${db.current.time}" />
<column name="email" value="[email protected]"/>
<column name="firstname" value="selfcare.api"/>
<column name="lastname" value="DEMO"/>
<column name="username" value="DEMO.selfcare.api" />
<column name="uuid" value="DEMO.selfcare.api" />
</insert>
<insert tableName="adm_user_role">
<column name="user_id" value="-5"></column>
<column name="role_id" value="-112"></column>
</insert>
<sql><![CDATA[
INSERT INTO ${db.schema.adapted}meveo_script_instance (id, version, disabled, created, code, description, src_type, script) VALUES (-20, 0, 0, ${db.current.time}, 'org.meveo.service.script.selfcare.CreateAccess', 'AddAccess', 'JAVA', '
package org.meveo.service.script.selfcare;
import java.util.Date;
import java.util.Map;
import org.meveo.admin.exception.BusinessException;
import org.meveo.model.admin.User;
import org.meveo.model.billing.Subscription;
import org.meveo.service.medina.impl.AccessService;
import org.meveo.service.script.module.ModuleScript;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CreateAccess extends ModuleScript {
private static final Logger log = LoggerFactory.getLogger(CreateAccess.class);
@Override
public void execute(Map<String, Object> methodContext) throws BusinessException {
AccessService accessService = (AccessService) getServiceInterface("AccessService");
Subscription subscription = (Subscription) methodContext.get("subscription");
if(subscription == null){
throw new BusinessException("subscription is null");
}
log.debug("subscription.getCode() : "+subscription.getCode());
org.meveo.model.mediation.Access access = new org.meveo.model.mediation.Access();
access.setSubscription(subscription);
access.setAccessUserId("ACC_"+subscription.getCode());
access.setStartDate(new Date());
access.setEndDate(null);
accessService.create(access);
}
}
');
]]></sql>
<insert tableName="meveo_module">
<column name="id" valueNumeric="-1"></column>
<column name="version" value="0"></column>
<column name="disabled" value="0"></column>
<column name="created" valueDate="${db.current.time}"></column>
<column name="creator" value="applicationInitializer"></column>
<column name="code" value="AddAccessModule"></column>
<column name="description" value="AddAccessModule"></column>
<column name="module_license" value="GPL"></column>
<column name="installed" value="0"></column>
<column name="script_instance_id" valueNumeric="-20"></column>
</insert>
<sql>
<![CDATA[UPDATE ${db.schema.adapted}meveo_module
SET module_source='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Module license="GPL" code="AddAccessModule" description="AddAccessModule">
<script code="org.meveo.service.script.selfcare.CreateAccess" description="AddAccess"></script>
<moduleItems>
<notification code="AddAccessNotif">
<classNameFilter>org.meveo.model.billing.Subscription</classNameFilter>
<eventTypeFilter>CREATED</eventTypeFilter>
<elFilter></elFilter>
<scriptInstanceCode>org.meveo.service.script.selfcare.CreateAccess</scriptInstanceCode>
<scriptParams>
<entry>
<key>subscription</key>
<value>#{event}</value>
</entry>
</scriptParams>
<priority>0</priority>
</notification>
</moduleItems>
</Module>
'
WHERE id=-1;]]>
</sql>
<sql><![CDATA[
INSERT INTO ${db.schema.adapted}meveo_script_instance (id, version, disabled, created, code, description, src_type, script) VALUES (-21, 0, 0, ${db.current.time}, 'org.meveo.service.script.SelfcareAccountScript', 'Script BAM for selfcare accounts', 'JAVA', '
package org.meveo.service.script;
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.HashSet;
import java.util.Map;
import org.meveo.admin.exception.BusinessException;
import org.meveo.api.dto.account.CRMAccountHierarchyDto;
import org.meveo.api.dto.UserDto;
import org.meveo.api.exception.MeveoApiException;
import org.meveo.commons.utils.StringUtils;
import org.meveo.model.admin.User;
import org.meveo.service.script.account.AccountScript;
import org.meveo.model.AccountEntity;
import org.slf4j.Logger;
import java.util.Set;
import java.util.ArrayList;
import org.meveo.model.security.Role;
import org.meveo.service.crm.impl.CustomerService;
import org.slf4j.LoggerFactory;
import org.meveo.model.crm.Customer;
import org.meveo.service.crm.impl.CustomFieldInstanceService;
import org.meveo.api.UserApi;
public class SelfcareAccountScript extends AccountScript {
private static final Logger log = LoggerFactory.getLogger(SelfcareAccountScript.class);
private Map<String, Object> initContext = null;
static MessageDigest messageDigest = null;
static {
try {
messageDigest = MessageDigest.getInstance("MD5");
}
catch (NoSuchAlgorithmException e) {
}
}
CustomFieldInstanceService customFieldInstanceService = (CustomFieldInstanceService) getServiceInterface("CustomFieldInstanceService");
CustomerService customerService = (CustomerService) getServiceInterface("CustomerService");
UserApi userApi = (UserApi) getServiceInterface("UserApi");
@Override
public void createAccount(Map<String, Object> methodContext) throws BusinessException {
AccountEntity account = (AccountEntity) methodContext.get(Script.CONTEXT_ENTITY);
UserDto user = new UserDto();
CRMAccountHierarchyDto accountDto = (CRMAccountHierarchyDto) methodContext.get(AccountScript.CONTEXT_ACCOUNT_HIERARCHY_DTO);
Customer customer = customerService.findByCode(accountDto.getCode());
log.debug("accountCode : "+accountDto.getCode(), " crmAccountType :"+accountDto.getCrmAccountType());
String email = accountDto.getContactInformation().getEmail();
user.setEmail(email);
if(accountDto.getName()!=null){
user.setFirstName(accountDto.getName().getFirstName());
user.setLastName(accountDto.getName().getLastName());
}
user.setUsername(accountDto.getCode());
/*
String password =(String) customFieldInstanceService.getCFValue(customer, "password");
if( password != null )
{
user.setPassword(password);
}
else
{
log.warn("password CF is null, using username");
user.setPassword(user.getUsername());
}
*/
List<String> roles = new ArrayList<String>();
roles.add("selfcareDefault");
user.setRoles(roles);
log.debug("lastName :"+user.getLastName() + " firstName : "+user.getFirstName() + " email : "+user.getEmail());
try{
userApi.createOrUpdate(user);
}
catch(MeveoApiException e){
log.error("failed to create user ",e);
e.printStackTrace();
}
}
}
');
]]></sql>
<sql><![CDATA[
INSERT INTO ${db.schema.adapted}meveo_script_instance (id, version, disabled, created, code, description, src_type, script) VALUES (-22, 0, 0, ${db.current.time}, 'org.meveo.service.script.selfcare.RegisterHierarchy', 'Register crm hierarchy', 'JAVA', '
package org.meveo.service.script.selfcare;
import java.util.Map;
import org.meveo.admin.exception.BusinessException;
import org.meveo.api.account.AccountHierarchyApi;
import org.meveo.api.dto.account.CRMAccountHierarchyDto;
import org.meveo.api.exception.MeveoApiException;
import org.meveo.commons.utils.JsonUtils;
import org.meveo.model.admin.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RegisterHierarchy extends org.meveo.service.script.Script {
private static final Logger log = LoggerFactory.getLogger(RegisterHierarchy.class);
public void execute(Map<String, Object> initContext) throws BusinessException {
log.info("Execute...");
AccountHierarchyApi accountHierarchyApi = (AccountHierarchyApi) getServiceInterface("AccountHierarchyApi");
String body = (String) initContext.get("body");
log.info("body:"+body);
CRMAccountHierarchyDto crmAccountHierarchyDto = JsonUtils.toObject(body, CRMAccountHierarchyDto.class);
log.info("crmAccountHierarchyDto"+crmAccountHierarchyDto);
try {
accountHierarchyApi.createCRMAccountHierarchy(crmAccountHierarchyDto);
} catch (MeveoApiException e) {
e.printStackTrace();
}
}
}
');
]]></sql>
<insert tableName="meveo_module">
<column name="id" valueNumeric="-2"></column>
<column name="version" value="0"></column>
<column name="disabled" value="0"></column>
<column name="created" valueDate="${db.current.time}"></column>
<column name="creator" value="applicationInitializer"></column>
<column name="code" value="Client"></column>
<column name="description" value="Individual customer"></column>
<column name="module_license" value="GPL"></column>
<column name="installed" value="0"></column>
<column name="script_instance_id" valueNumeric="-21"></column>
</insert>
<insert tableName="crm_business_account_model">
<column name="id" valueNumeric="-2"></column>
<column name="hierarchy_type" value="C_UA"></column>
</insert>
<sql>
<![CDATA[UPDATE ${db.schema.adapted}meveo_module
SET module_source='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<BusinessAccountModel license="GPL" code="Client" description="Individual customer">
<script code="org.meveo.service.script.SelfcareAccountScript" description="Script BAM for selfcare accounts"></script>
<moduleItems>
<emailNotif code="AccountCreationNotif">
<classNameFilter>org.meveo.model.admin.User</classNameFilter>
<eventTypeFilter>CREATED</eventTypeFilter>
<scriptParams/>
<priority>0</priority>
<emailFrom>[email protected]</emailFrom>
<emailToEl>#{event.email}</emailToEl>
<subject>Account creation confirmation</subject>
<body>Hello,
Your login has been created:
user name : #{event.userName}
access url : http://opencell_url/frontend/DEMO/cc/index.html
</body>
</emailNotif>
<notification code="SelfcareRegistration">
<classNameFilter>org.meveo.model.notification.InboundRequest</classNameFilter>
<eventTypeFilter>INBOUND_REQ</eventTypeFilter>
<elFilter>#{event.pathInfo.startsWith("/DEMO/registration")}</elFilter>
<scriptInstanceCode>org.meveo.service.script.selfcare.RegisterHierarchy</scriptInstanceCode>
<scriptParams>
<entry>
<key>body</key>
<value>#{event.getBody()}</value>
</entry>
</scriptParams>
<priority>0</priority>
</notification>
<script code="org.meveo.service.script.selfcare.RegisterHierarchy" description="Register crm hierarchy">
<type>JAVA</type>
<script>
package org.meveo.service.script.selfcare;
import java.util.Map;
import org.meveo.admin.exception.BusinessException;
import org.meveo.api.account.AccountHierarchyApi;
import org.meveo.api.dto.account.CRMAccountHierarchyDto;
import org.meveo.api.exception.MeveoApiException;
import org.meveo.commons.utils.JsonUtils;
import org.meveo.model.admin.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RegisterHierarchy extends org.meveo.service.script.Script {
private static final Logger log = LoggerFactory.getLogger(RegisterHierarchy.class);
public void execute(Map<String, Object> initContext) throws BusinessException {
log.info("Execute...");
AccountHierarchyApi accountHierarchyApi = (AccountHierarchyApi) getServiceInterface("AccountHierarchyApi");
String body = (String) initContext.get("body");
log.info("body:"+body);
CRMAccountHierarchyDto crmAccountHierarchyDto = JsonUtils.toObject(body, CRMAccountHierarchyDto.class);
log.info("crmAccountHierarchyDto"+crmAccountHierarchyDto);
try {
accountHierarchyApi.createCRMAccountHierarchy(crmAccountHierarchyDto);
} catch (MeveoApiException e) {
e.printStackTrace();
}
}
}
</script>
</script>
</moduleItems>
<hierarchyType>C_UA</hierarchyType>
</BusinessAccountModel>
'
WHERE id=-2;]]>
</sql>
</changeSet>
<changeSet author="EdwardPLegaspi" id="#4150_20190424 - Bring back the timers">
<insert tableName="meveo_timer">
<column name="id" valueNumeric="-1" />
<column name="version" valueNumeric="0" />
<column name="sc_d_o_month" value="*" />
<column name="sc_d_o_week" value="*" />
<column name="sc_hour" value="*" />
<column name="sc_min" value="0" />
<column name="sc_month" value="*" />
<column name="sc_sec" value="0" />
<column name="sc_year" value="*" />
<column name="code" value="Hourly" />
<column name="created" valueDate="2015-03-19 00:04:19.913" />
</insert>
<insert tableName="meveo_timer">
<column name="id" valueNumeric="-2" />
<column name="version" valueNumeric="0" />
<column name="sc_d_o_month" value="Last" />
<column name="sc_d_o_week" value="0" />
<column name="sc_hour" value="23" />
<column name="sc_min" value="59" />
<column name="sc_month" value="*" />
<column name="sc_sec" value="59" />
<column name="sc_year" value="*" />
<column name="code" value="Monthly" />
<column name="created" valueDate="2015-03-19 00:04:19.913" />
</insert>
<insert tableName="meveo_timer">
<column name="id" valueNumeric="-3" />
<column name="version" valueNumeric="0" />
<column name="sc_d_o_month" value="*" />
<column name="sc_d_o_week" value="*" />
<column name="sc_hour" value="23" />
<column name="sc_min" value="59" />
<column name="sc_month" value="*" />
<column name="sc_sec" value="59" />
<column name="sc_year" value="*" />
<column name="code" value="Daily-midnight" />
<column name="created" valueDate="2017-06-29 00:04:19.913" />
</insert>
</changeSet>
<changeSet id="#4082_20190404" author="SaidRamli">
<sql dbms="postgresql"><![CDATA[INSERT INTO ${db.schema.adapted}meveo_script_instance (id, version, disabled, created, code, description, src_type, script) VALUES (-23, 0, 0, ${db.current.time}, 'org.meveo.service.script.DeleteCustomersScript', 'DeleteCustomersScript', 'JAVA', '
package org.meveo.service.script;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections4.MapUtils;
import org.meveo.admin.exception.BusinessException;
import org.meveo.model.billing.WalletInstance;
import org.meveo.model.crm.Customer;
import org.meveo.service.base.BusinessEntityService;
import org.meveo.service.billing.impl.ChargeInstanceService;
import org.meveo.service.billing.impl.CounterInstanceService;
import org.meveo.service.billing.impl.CounterPeriodService;
import org.meveo.service.billing.impl.EdrService;
import org.meveo.service.billing.impl.InvoiceService;
import org.meveo.service.billing.impl.ProductInstanceService;
import org.meveo.service.billing.impl.RatedTransactionService;
import org.meveo.service.billing.impl.RejectedBillingAccountService;
import org.meveo.service.billing.impl.ServiceInstanceService;
import org.meveo.service.billing.impl.SubscriptionService;
import org.meveo.service.billing.impl.WalletOperationService;
import org.meveo.service.billing.impl.WalletService;
import org.meveo.service.crm.impl.CustomerService;
import org.meveo.service.medina.impl.AccessService;
import org.meveo.service.order.OrderItemService;
import org.meveo.service.payments.impl.AccountOperationService;
import org.meveo.service.payments.impl.MatchingAmountService;
/**
*
* @author Said Ramli
*/
@SuppressWarnings({ "unchecked", "unused" })
public class DeleteCustomersScript extends Script {
private final AccountOperationService accountOperationService = (AccountOperationService) getServiceInterface(
AccountOperationService.class.getSimpleName());
private final CustomerService customerService = (CustomerService) getServiceInterface(
CustomerService.class.getSimpleName());
private final InvoiceService invoiceService = (InvoiceService) getServiceInterface(
InvoiceService.class.getSimpleName());
private final SubscriptionService subscriptionService = (SubscriptionService) getServiceInterface(
SubscriptionService.class.getSimpleName());
private final RatedTransactionService ratedTransactionService = (RatedTransactionService) getServiceInterface(
RatedTransactionService.class.getSimpleName());
private final WalletService walletService = (WalletService) getServiceInterface(
WalletService.class.getSimpleName());
private final RejectedBillingAccountService rejectedBillingAccountService = (RejectedBillingAccountService) getServiceInterface(
RejectedBillingAccountService.class.getSimpleName());
private final CounterInstanceService counterInstanceService = (CounterInstanceService) getServiceInterface(
CounterInstanceService.class.getSimpleName());
private final CounterPeriodService counterPeriodService = (CounterPeriodService) getServiceInterface(
CounterPeriodService.class.getSimpleName());
private final OrderItemService orderItemService = (OrderItemService) getServiceInterface(
OrderItemService.class.getSimpleName());
private final ProductInstanceService productInstanceService = (ProductInstanceService) getServiceInterface(
ProductInstanceService.class.getSimpleName());
private final BusinessEntityService businessEntityService = (BusinessEntityService) getServiceInterface(
BusinessEntityService.class.getSimpleName());
private final WalletOperationService walletOperationService = (WalletOperationService) getServiceInterface(
WalletOperationService.class.getSimpleName());
private final ServiceInstanceService serviceInstanceService = (ServiceInstanceService) getServiceInterface(
ServiceInstanceService.class.getSimpleName());
private final EdrService edrService = (EdrService) getServiceInterface(EdrService.class.getSimpleName());
@SuppressWarnings("rawtypes")
private final ChargeInstanceService chargeInstanceService = (ChargeInstanceService) getServiceInterface(
ChargeInstanceService.class.getSimpleName());
private static final List<String> noCheckAllowedValues = Arrays.asList("0", "1");
@Override
public void execute(Map<String, Object> methodContext) throws BusinessException {
log.debug(" >>> execute {} ", methodContext.entrySet());
try {
Map<String, String> record = (Map<String, String>) methodContext.get("RECORD");
if (MapUtils.isEmpty(record)) {
throw new BusinessException(String.format("Parameter RECORD is missing"));
}
final String customerCode = record.get("customerCode");
Customer customer = customerService.findByCode(customerCode);
if (customer == null) {
throw new BusinessException(String.format("No customer found having code = %s ", customerCode));
}
String noCheckVal = record.get("noCheck");
if (isNotBlank(noCheckVal) && !noCheckAllowedValues.contains(noCheckVal)) {
throw new BusinessException(
String.format("Invalid ''noCheck'' value = %s , allowed values are [0,1]", noCheckVal));
}
boolean noCheck = "1".contentEquals(noCheckVal);
if (!noCheck) {
// If noCheck is 0 then the following conditions must be met in order to allow
// deletion:
// No unmatched AO
// No open EDR/WO/RT
this.checkUnmatchedAOs(customer);
this.checkOpenEDRs(customer);
this.checkOpenWOs(customer);
this.checkOpenRTs(customer);
}
this.removeCustomerHirarchy(customer);
} catch (BusinessException be) {
throw be;
} catch (Exception e) {
log.error(" Error executing DeleteCustomersScript ", e);
throw new BusinessException(e.getMessage());
}
}
private void checkOpenEDRs(Customer customer) throws BusinessException {
try {
log.debug(" Start checkOpenEDRs for customer = {} ", customer);
String query = "select count(edr.id) from EDR edr where edr.status = ''OPEN'' and edr.subscription.userAccount.billingAccount.customerAccount.customer.id =:customerId ";
Object count = edrService.getEntityManager().createQuery(query).setParameter("customerId", customer.getId())
.getSingleResult();
log.debug(" count of open EDRs = {} ", count);
log.debug(" End checkOpenEDRs for customer = {} ", customer);
if (((Long) count).intValue() > 0) {
throw new BusinessException(" Customer has [" + count + "] open EDRs ");
}
} catch (Exception e) {
log.error(" Error on checkOpenEDRs : [{}] ", e.getMessage(), e);
throw new BusinessException(e);
}
}
private void checkOpenWOs(Customer customer) throws BusinessException {
try {
log.debug(" Start checkOpenWOs for customer = {} ", customer);
String query = "select count(wo.id) from WalletOperation wo where wo.status = ''OPEN'' and wo.chargeInstance.userAccount.billingAccount.customerAccount.customer.id =:customerId ";
final WalletOperationService walletOperationService = (WalletOperationService) getServiceInterface(
WalletOperationService.class.getSimpleName());
Object count = walletOperationService.getEntityManager().createQuery(query)
.setParameter("customerId", customer.getId()).getSingleResult();
log.debug(" count of open WOs = {} ", count);
log.debug(" End checkOpenWOs for customer = {} ", customer);
if (((Long) count).intValue() > 0) {
throw new BusinessException(" Customer has [" + count + "] open WOs ");
}
} catch (Exception e) {
log.error(" Error on checkOpenWOs : [{}] ", e.getMessage(), e);
throw new BusinessException(e);
}
}
private void checkOpenRTs(Customer customer) throws BusinessException {
try {
log.debug(" Start checkOpenRTs for customer = {} ", customer);
String query = "select count(rt.id) from RatedTransaction rt where rt.status = ''OPEN'' and rt.billingAccount.customerAccount.customer.id =:customerId ";
Object count = this.ratedTransactionService.getEntityManager().createQuery(query)
.setParameter("customerId", customer.getId()).getSingleResult();
log.debug(" count of open RTs = {} ", count);
log.debug(" End checkOpenRTs for customer = {} ", customer);
if (((Long) count).intValue() > 0) {
throw new BusinessException(" Customer has [" + count + "] open RTs ");
}
} catch (Exception e) {
log.error(" Error on checkOpenRTs : [{}] ", e.getMessage(), e);
throw new BusinessException(e);
}
}
private void checkUnmatchedAOs(Customer customer) throws BusinessException {
try {
log.debug(" Start checkUnmatchedAOs for customer = {} ", customer);
String query = "select count(ao.id) from AccountOperation ao where ao.matchingStatus = ''O'' and ao.customerAccount.customer.id =:customerId ";
final AccountOperationService accountOperationService = (AccountOperationService) getServiceInterface(
AccountOperationService.class.getSimpleName());
Object count = accountOperationService.getEntityManager().createQuery(query)
.setParameter("customerId", customer.getId()).getSingleResult();
log.debug(" count of unmatched AOs = {} ", count);
log.debug(" End checkUnmatchedAOs for customer = {} ", customer);
if (((Long) count).intValue() > 0) {
throw new BusinessException(" Customer has [" + count + "] unmatched AOs ");
}
} catch (Exception e) {
log.error(" Error on checkUnmatchedAOs : [{}] ", e.getMessage(), e);
throw new BusinessException(e);
}
}
private void removeCustomerHirarchy(Customer customer) throws BusinessException {
log.debug(" Start removeCustomerHirarchy for customer = {} ", customer);
//
// A workaround for #4134 , no need for this method if #4134 is fixed (only
// 6.1.X is concerned)!
this.nullifyAOsSeller(customer);
this.removeWalletOperations(customer);
this.removeChargeInstances(customer);
// the relationship [SubCategoryInvoiceAgregate <=> WalletInstance] should be broke fisrt
this.nullifySubCategoryInvoiceAgregatesWallet(customer);
this.removeWalletInstances(customer);
this.removePaymentHistory(customer);
this.removeRatedTransactions(customer);
this.removeInvoices(customer);
this.removeServiceInstances(customer);
this.removeAccess(customer);
this.removeEDRs(customer);
this.removeSubscriptions(customer);
this.removeRejectedBAs(customer);
this.removeCounterPeriods(customer);
this.removeCounterInstances(customer);
this.removeOrderItems(customer);
this.removeProductInstances(customer);
this.removeMatchingAmounts(customer);
this.customerService.remove(customer);
log.debug(" End removeCustomerHirarchy for customer = {} ", customer);
}
private void removeEDRs(Customer customer) throws BusinessException {
try {
log.debug(" Start removeEDRs for customer = {} ", customer);
String query = "select edr.id from EDR edr where edr.subscription.userAccount.billingAccount.customerAccount.customer.id =:customerId ";
Map<String, Object> queryParams = new HashMap<>();
queryParams.put("customerId", customer.getId());
Object result = edrService.executeSelectQuery(query.toString(), queryParams);
Collection<Long> ids = safe(result != null ? ((List<Long>) result) : null);
log.debug(" {} EDR to delete ", ids.size());
for (Long id : ids) {
edrService.remove(id);
}
log.debug(" End removeEDRs for customer = {} ", customer);
} catch (Exception e) {
log.error(" Error on removeEDRs : [{}] ", e.getMessage(), e);
throw new BusinessException(e);
}
}
private void removeMatchingAmounts(Customer customer) throws BusinessException {
try {
log.debug(" Start removeMatchingAmounts for customer = {} ", customer);
final MatchingAmountService matchingAmountService = (MatchingAmountService) getServiceInterface(MatchingAmountService.class.getSimpleName());
final String query = "select ma.id from MatchingAmount ma where ma.accountOperation.customerAccount.customer.id =:customerId ";
Map<String, Object> queryParams = new HashMap<>();
queryParams.put("customerId", customer.getId());
Object result = matchingAmountService.executeSelectQuery(query.toString(), queryParams);
Collection<Long> ids = safe(result != null ? ((List<Long>) result) : null);
log.debug(" {} MatchingAmount to delete ", ids.size());
for (Long id : ids) {
matchingAmountService.remove(id);
}
log.debug(" End removeMatchingAmounts for customer = {} ", customer);
} catch (Exception e) {
log.error(" Error on removeMatchingAmounts : [{}] ", e.getMessage(), e);
throw new BusinessException(e);
}
}
private void removeAccess(Customer customer) throws BusinessException {
try {
log.debug(" Start removeAccess for customer = {} ", customer);
final AccessService accessService = (AccessService) getServiceInterface(
AccessService.class.getSimpleName());
final String query = "select a.id from Access a where a.subscription.userAccount.billingAccount.customerAccount.customer.id =:customerId ";
Map<String, Object> queryParams = new HashMap<>();
queryParams.put("customerId", customer.getId());
Object result = accessService.executeSelectQuery(query.toString(), queryParams);
Collection<Long> ids = safe(result != null ? ((List<Long>) result) : null);
log.debug(" {} Access to delete ", ids.size());
for (Long id : ids) {
accessService.remove(id);
}
log.debug(" End removeAccess for customer = {} ", customer);
} catch (Exception e) {
log.error(" Error on removeAccess : [{}] ", e.getMessage(), e);
throw new BusinessException(e);
}
}
private void removeServiceInstances(Customer customer) throws BusinessException {
try {
log.debug(" Start removeServiceInstances for customer = {} ", customer);
Collection<Long> ids = safe(this.findServiceInstances(customer));
log.debug(" {} ServiceInstance to delete ", ids.size());
for (Long id : ids) {
this.serviceInstanceService.remove(id);
}
log.debug(" End removeServiceInstances for customer = {} ", customer);
} catch (Exception e) {
log.error(" Error on removeServiceInstances : [{}] ", e.getMessage(), e);
throw new BusinessException(e);
}
}
private List<Long> findServiceInstances(Customer customer) {
try {
log.debug(" findServiceInstances for customer={} ", customer);
String query = "select si.id from ServiceInstance si where si.subscription.userAccount.billingAccount.customerAccount.customer.id =:customerId ";
Map<String, Object> queryParams = new HashMap<>();
queryParams.put("customerId", customer.getId());
Object ids = this.serviceInstanceService.executeSelectQuery(query.toString(), queryParams);
return ids != null ? ((List<Long>) ids) : null;
} catch (Exception e) {
log.error(" Error on findServiceInstances : [{}] ", e.getMessage(), e);
return null;
}
}
private void removeWalletOperations(Customer customer) throws BusinessException {
try {
log.debug(" Start removeWalletOperations for customer = {} ", customer);
Collection<Long> ids = safe(this.findWalletOperations(customer));
log.debug(" {} WalletOperation to delete ", ids.size());
for (Long id : ids) {
this.walletOperationService.remove(id);
}
log.debug(" End removeWalletOperations for customer = {} ", customer);
} catch (Exception e) {
log.error(" Error on removeWalletOperations : [{}] ", e.getMessage(), e);
throw new BusinessException(e);
}
}
private List<Long> findWalletOperations(Customer customer) {
try {
log.debug(" findWalletOperations for customer={} ", customer);
String query = "select wo.id from WalletOperation wo where wo.chargeInstance.userAccount.billingAccount.customerAccount.customer.id =:customerId ";
Map<String, Object> queryParams = new HashMap<>();
queryParams.put("customerId", customer.getId());
Object ids = this.walletOperationService.executeSelectQuery(query.toString(), queryParams);
return ids != null ? ((List<Long>) ids) : null;
} catch (Exception e) {
log.error(" Error on findWalletOperations : [{}] ", e.getMessage(), e);
return null;
}
}
/**
* using Sub-queries to Resolve Error: ERROR: syntax error at or near "cross"
*
* @param customer
* @throws BusinessException
*/
private void removePaymentHistory(Customer customer) throws BusinessException {
try {
log.debug(" Start removePaymentHistory for customer = {} ", customer);
String query = "delete from PaymentHistory ph1 where ph1.id in (select ph2.id from PaymentHistory ph2 where ph2.customerCode=:customerCode) ";
int count = this.businessEntityService.getEntityManager().createQuery(query)
.setParameter("customerCode", customer.getCode()).executeUpdate();
log.debug(" {} PaymentHistory to delete ", count);
log.debug(" End removePaymentHistory for customer = {} ", customer);
} catch (Exception e) {
log.error(" Error on removePaymentHistory : [{}] ", e.getMessage(), e);
throw new BusinessException(e);
}
}
/**
* using Sub-queries to Resolve Error: ERROR: syntax error at or near "cross"
*
* @param customer
* @throws BusinessException
*/
private void nullifyAOsSeller(Customer customer) throws BusinessException {
try {
log.debug(" Start nullifyAOsSeller for customer = {} ", customer);
String query = "UPDATE AccountOperation ao1 SET ao1.seller = null where ao1.id in (select ao2.id from AccountOperation ao2 where ao2.customerAccount.customer.id =:customerId) ";
int count = this.accountOperationService.getEntityManager().createQuery(query)
.setParameter("customerId", customer.getId()).executeUpdate();
log.debug(" seller to nullify for {} AOs ", count);
log.debug(" End nullifyAOsSeller for customer = {} ", customer);
} catch (Exception e) {
log.error(" Error on nullifyAOsSeller : [{}] ", e.getMessage(), e);
throw new BusinessException(e);
}
}
private void nullifySubCategoryInvoiceAgregatesWallet(Customer customer) throws BusinessException {
try {
log.debug(" Start nullifySubCategoryInvoiceAgregatesWallet for customer = {} ", customer);
StringBuilder query = new StringBuilder( "UPDATE SubCategoryInvoiceAgregate subCat SET subCat.wallet = null ")
.append(" where subCat.id in (select subCatIn.id from SubCategoryInvoiceAgregate subCatIn where subCatIn.wallet.userAccount.billingAccount.customerAccount.customer.id =:customerId) ");
int count = this.accountOperationService.getEntityManager().createQuery(query.toString()).setParameter("customerId", customer.getId()).executeUpdate();
log.debug(" wallet to nullify for {} SubCategoryInvoiceAgregate ", count);
log.debug(" End nullifySubCategoryInvoiceAgregatesWallet for customer = {} ", customer);
} catch (Exception e) {
log.error(" Error on nullifySubCategoryInvoiceAgregatesWallet : [{}] ", e.getMessage(), e);
throw new BusinessException(e);
}
}
private void removeProductInstances(Customer customer) throws BusinessException {
try {
log.debug(" Start removeProductInstances for customer = {} ", customer);
Collection<Long> ids = safe(this.findProductInstances(customer));
log.debug(" {} ProductInstance to delete ", ids.size());
for (Long id : ids) {
this.productInstanceService.remove(id);
}
log.debug(" End removeProductInstances for customer = {} ", customer);
} catch (Exception e) {
log.error(" Error on removeProductInstances : [{}] ", e.getMessage(), e);
throw new BusinessException(e);
}
}
private List<Long> findProductInstances(Customer customer) {
try {
log.debug(" findProductInstances for customer={} ", customer);
String query = "select p.id from ProductInstance p where p.userAccount.billingAccount.customerAccount.customer.id =:customerId ";
Map<String, Object> queryParams = new HashMap<>();
queryParams.put("customerId", customer.getId());
Object ids = this.productInstanceService.executeSelectQuery(query.toString(), queryParams);
return ids != null ? ((List<Long>) ids) : null;
} catch (Exception e) {
log.error(" Error on findProductInstances : [{}] ", e.getMessage(), e);
return null;
}
}
private void removeOrderItems(Customer customer) throws BusinessException {
try {
log.debug(" Start removeOrderItem for customer = {} ", customer);
Collection<Long> ids = safe(this.findOrderItems(customer));
log.debug(" {} OrderItem to delete ", ids.size());
for (Long id : ids) {
this.orderItemService.remove(id);
}
log.debug(" End removeOrderItem for customer = {} ", customer);
} catch (Exception e) {
log.error(" Error on removeOrderItem : [{}] ", e.getMessage(), e);
throw new BusinessException(e);
}
}
private List<Long> findOrderItems(Customer customer) {
try {
log.debug(" findOrderItems for customer={} ", customer);
String query = "select p.id from OrderItem p where p.userAccount.billingAccount.customerAccount.customer.id =:customerId ";
Map<String, Object> queryParams = new HashMap<>();
queryParams.put("customerId", customer.getId());
Object ids = this.orderItemService.executeSelectQuery(query.toString(), queryParams);
return ids != null ? ((List<Long>) ids) : null;
} catch (Exception e) {
log.error(" Error on findCounterPeriods : [{}] ", e.getMessage(), e);
return null;
}
}
private void removeCounterPeriods(Customer customer) throws BusinessException {
try {
log.debug(" Start removeCounterPeriods for customer = {} ", customer);
Collection<Long> ids = safe(this.findCounterPeriods(customer));
log.debug(" {} CounterPeriod to delete ", ids.size());
for (Long id : ids) {
this.counterPeriodService.remove(id);
}
log.debug(" End removeCounterPeriods for customer = {} ", customer);
} catch (Exception e) {
log.error(" Error on removeCounterPeriods : [{}] ", e.getMessage(), e);
throw new BusinessException(e);
}
}
private List<Long> findCounterPeriods(Customer customer) {
try {
log.debug(" findCounterPeriods for customer={} ", customer);
String query = "select c.id from CounterPeriod c where c.counterInstance.userAccount.billingAccount.customerAccount.customer.id =:customerId ";
Map<String, Object> queryParams = new HashMap<>();
queryParams.put("customerId", customer.getId());
Object ids = this.counterPeriodService.executeSelectQuery(query.toString(), queryParams);
return ids != null ? ((List<Long>) ids) : null;
} catch (Exception e) {
log.error(" Error on findCounterPeriods : [{}] ", e.getMessage(), e);
return null;
}
}
private void removeCounterInstances(Customer customer) throws BusinessException {
try {
log.debug(" Start removeCounterInstances for customer = {} ", customer);
Collection<Long> ids = safe(this.findCounterInstances(customer));
log.debug(" {} CounterInstance to delete ", ids.size());
for (Long id : ids) {
this.counterInstanceService.remove(id);
}
log.debug(" End removeCounterInstances for customer = {} ", customer);
} catch (Exception e) {
log.error(" Error on removeCounterInstances : [{}] ", e.getMessage(), e);
throw new BusinessException(e);
}
}
private List<Long> findCounterInstances(Customer customer) {
try {
log.debug(" findCounterInstances for customer={} ", customer);
String query = "select c.id from CounterInstance c where c.userAccount.billingAccount.customerAccount.customer.id =:customerId ";
Map<String, Object> queryParams = new HashMap<>();
queryParams.put("customerId", customer.getId());
Object ids = this.counterInstanceService.executeSelectQuery(query.toString(), queryParams);
return ids != null ? ((List<Long>) ids) : null;
} catch (Exception e) {
log.error(" Error on findCounterInstances : [{}] ", e.getMessage(), e);
return null;
}
}
private void removeRejectedBAs(Customer customer) throws BusinessException {
try {
log.debug(" Start removeRejectedBAs for customer = {} ", customer);
Collection<Long> ids = safe(this.findRejectedBillingAccounts(customer));
log.debug(" {} RejectedBillingAccount to delete ", ids.size());
for (Long id : ids) {
this.rejectedBillingAccountService.remove(id);
}
log.debug(" End removeRejectedBAs for customer = {} ", customer);
} catch (Exception e) {
log.error(" Error on removeRejectedBAs : [{}] ", e.getMessage(), e);
throw new BusinessException(e);
}
}
private List<Long> findRejectedBillingAccounts(Customer customer) {
try {