· 5 years ago · Jun 11, 2020, 09:48 AM
1package org.jleaf.erp.master.bo.partner;
2
3import org.jleaf.common.ComboIdConstants;
4import org.jleaf.common.CommonConstants;
5import org.jleaf.common.CommonExceptionConstants;
6import org.jleaf.common.dao.UserDao;
7import org.jleaf.common.dao.UserLoginInformationDao;
8import org.jleaf.common.dao.UserPropsDao;
9import org.jleaf.common.dao.UserRoleDao;
10import org.jleaf.common.entity.User;
11import org.jleaf.common.entity.UserLoginInformation;
12import org.jleaf.common.entity.UserProps;
13import org.jleaf.common.entity.UserRole;
14import org.jleaf.common.util.PasswordUtil;
15import org.jleaf.core.BusinessFunction;
16import org.jleaf.core.BusinessTransaction;
17import org.jleaf.core.CoreException;
18import org.jleaf.core.DefaultBusinessTransaction;
19import org.jleaf.core.Dto;
20import org.jleaf.core.GeneralConstants;
21import org.jleaf.core.annotation.ErrorList;
22import org.jleaf.core.annotation.Info;
23import org.jleaf.core.annotation.InfoIn;
24import org.jleaf.core.annotation.InfoOut;
25import org.jleaf.erp.master.MasterConstantsForCland;
26import org.jleaf.erp.master.MasterExceptionConstants;
27import org.jleaf.erp.master.bo.ComboIdMasterConstants;
28import org.jleaf.erp.master.dao.PartnerSupplierInfoDao;
29import org.jleaf.erp.master.dao.PartnerTypeDao;
30import org.jleaf.erp.master.dao.PartnerUserDao;
31import org.jleaf.erp.master.dao.SuppPaymentDao;
32import org.jleaf.erp.master.entity.PartnerSupplierInfo;
33import org.jleaf.erp.master.entity.PartnerType;
34import org.jleaf.erp.master.entity.PartnerUser;
35import org.jleaf.erp.master.entity.SuppPayment;
36import org.jleaf.util.GsonUtil;
37import org.jleaf.util.SecurityUtil;
38import org.jleaf.util.ValidationUtil;
39import org.slf4j.Logger;
40import org.slf4j.LoggerFactory;
41import org.springframework.beans.factory.annotation.Autowired;
42import org.springframework.beans.factory.annotation.Qualifier;
43import org.springframework.stereotype.Service;
44
45/**
46* @author Thea, Jul 23, 2014
47* @version 1.0
48*/
49//@formatter:off
50@Service("addPartnerAsSupplier")
51@InfoIn(value= {@Info(name = "partnerId", description = "partner id", type=Long.class, required=true),
52 @Info(name = "typePartnerId", description = "type partner id", type = Long.class, required = true),
53 @Info(name = "currencyCode", description = "currency code", type = String.class, required = true),
54 @Info(name = "amountLimit", description = "amount limit", type = Double.class, required = true),
55 @Info(name = "duePaymentDays", description = "due payments days", type=Long.class, required=true),
56 @Info(name = "dueReceiveDays", description = "due receive days", type = Long.class, required = true),
57 @Info(name = "flagDropship", description = "flagDropship", type = String.class, required = true),
58 @Info(name = "tenantLoginId", description = "tenant login id", type = Long.class),
59 @Info(name = "userLoginId", description = "user login id", type = Long.class),
60 @Info(name = "roleLoginId", description = "role user login id", type = Long.class),
61 @Info(name = "datetime", description = "process date time", type = String.class)})
62@InfoOut(value={@Info(name = "id", description = "partner type id", type=Long.class),
63 @Info(name = "tenantId", description = "tenant id", type=Long.class),
64 @Info(name = "username", description = "username", type=String.class), // dari sini sampai komen selanjutnya milik user
65 @Info(name = "email", description = "email", type=String.class),
66 @Info(name = "fullname", description = "fullname", type=String.class),
67 @Info(name = "password", description = "password", type=String.class),
68 @Info(name = "phone", description = "phone", type=String.class),
69 @Info(name = "roleDefaultId", description = "role Default id", type=Long.class),
70 @Info(name = "privateKey", description = "private key", type=String.class),
71 @Info(name = "ouDefaultId", description = "ou default id", type=Long.class),
72 @Info(name = "policyDefaultId", description = "policy Default id", type=Long.class),
73// @Info(name = "partnerId", description = "partner id", type=Long.class), // dari sini sampai komen di buka milik partner type
74// @Info(name = "groupPartner", description = "group partner", type=String.class),
75// @Info(name = "typePartnerId", description = "type partner id", type=Long.class),
76// @Info(name = "dueDate", description = "dueDate", type = Integer.class),
77// @Info(name = "currencyCode", description = "currency code", type = String.class),
78// @Info(name = "amountLimit", description = "amount limit", type = Double.class),
79// @Info(name = "flagCommision", description = "flag commision", type = String.class),
80 @Info(name = "active", description = "active", type = String.class),
81 @Info(name = "activeDateTime", description = "active date time", type = String.class),
82 @Info(name = "nonActiveDateTime", description = "non active date time", type = String.class),
83 @Info(name = "createDateTime", description = "create date time", type = String.class),
84 @Info(name = "createUserId", description = "create user id", type = Long.class),
85 @Info(name = "updateDateTime", description = "update date time", type = String.class),
86 @Info(name = "updateUserId", description = "update user id", type = Long.class),
87 @Info(name = "version", description = "version", type = Long.class)})
88@ErrorList(errorKeys={ MasterExceptionConstants.AMOUNT_LIMIT_MUST_GREATER_THAN_ZERO,
89 MasterExceptionConstants.DUE_PAYMENTS_DAYS_MUST_GREATER_OR_EQUALS_WITH_ZERO,
90 MasterExceptionConstants.DUE_RECEIVE_DAYS_MUST_GREATER_OR_EQUALS_WITH_ZERO,
91 MasterExceptionConstants.PARTNER_TYPE_ALREADY_EXISTS,
92 MasterExceptionConstants.SUPP_PAYMENT_ALREADY_EXISTS,
93 MasterExceptionConstants.DATA_NOT_ACTIVE,
94 CommonExceptionConstants.DATA_CANT_USE_DIFF_TENANT })
95//@formatter:on
96public class AddPartnerAsSupplierForCland extends DefaultBusinessTransaction implements BusinessTransaction {
97
98 private static final Logger log = LoggerFactory.getLogger(AddPartnerAsSupplierForCland.class);
99
100 @Autowired
101 PartnerTypeDao partnerTypeDao;
102
103 @Autowired
104 SuppPaymentDao suppPaymentDao;
105
106 @Autowired
107 PartnerSupplierInfoDao partnerSupplierInfoDao;
108
109 @Autowired
110 @Qualifier("findPartnerById")
111 private BusinessFunction findPartnerById;
112
113 @Autowired
114 @Qualifier("valComboValueByCode")
115 private BusinessFunction valComboValueByCode;
116
117 @Autowired
118 @Qualifier("valTenantLoginCanUse")
119 private BusinessFunction valTenantLoginCanUse;
120
121 @Autowired
122 @Qualifier("findTypePartnerById")
123 private BusinessFunction findTypePartnerById;
124
125 @Autowired
126 @Qualifier("isPartnerTypeExistsByIndex")
127 private BusinessFunction isPartnerTypeExistsByIndex;
128
129 @Autowired
130 @Qualifier("isSuppPaymentExistsByIndex")
131 private BusinessFunction isSuppPaymentExistsByIndex;
132
133 //TODO
134 @Autowired
135 PartnerUserDao partnerUserDao;
136
137 @Autowired
138 UserDao userDao;
139
140 @Autowired
141 UserRoleDao userRoleDao;
142
143 @Autowired
144 UserPropsDao userPropsDao;
145
146 @Autowired
147 private UserLoginInformationDao userLoginInformationDao;
148
149 @Autowired
150 @Qualifier("findRoleById")
151 BusinessFunction findRoleById;
152
153 @Autowired
154 @Qualifier("findPolicyById")
155 BusinessFunction findPolicyById;
156
157 @Autowired
158 @Qualifier("valRoleIsSuperAdmin")
159 BusinessFunction valRoleIsSuperAdmin;
160
161 @Autowired
162 @Qualifier("valOUAsBusinessUnit")
163 BusinessFunction valOUAsBusinessUnit;
164
165 @Autowired
166 @Qualifier("isUserExistsByIndex")
167 BusinessFunction isUserExistsByIndex;
168
169 @Autowired
170 @Qualifier("isSystemConfigExistsByParameterCode")
171 BusinessFunction isSystemConfigExistsByParameterCode;
172
173 @Override
174 public String getDescription() {
175 return "Add partner as supplier. Add to table partner type and add to table supplier payment";
176 }
177
178 @Override
179 public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
180 // Validation tenant login id can be use
181 Dto loginDto = new Dto();
182 loginDto.put("tenantLoginId", inputDto.getLong("tenantLoginId"));
183 loginDto.put("userLoginId", inputDto.getLong("userLoginId"));
184 loginDto.put("roleLoginId", inputDto.getLong("roleLoginId"));
185 valTenantLoginCanUse.execute(loginDto);
186
187 // Validation value must be valid
188 ValidationUtil.valBlankOrNull(inputDto, "typePartnerId");
189 ValidationUtil.valBlankOrNull(inputDto, "currencyCode");
190 ValidationUtil.valNumber(inputDto, "amountLimit");
191 ValidationUtil.valNumber(inputDto, "duePaymentDays");
192 ValidationUtil.valNumber(inputDto, "dueReceiveDays");
193
194 // Validation partner must exists
195 Dto partnerDto = findPartnerById.execute(new Dto().put("id", inputDto.getLong("partnerId")));
196 valSameTenantId(inputDto, partnerDto, "Partner");
197 valActive(partnerDto.getString("active"), "Partner");
198
199 // Validation currency code must be registered
200 doValComboValueByCode(ComboIdMasterConstants.COMBO_CURRENCY, inputDto.getString("currencyCode"), "Currency Code");
201
202 // Validation amountLimit > 0
203 if (inputDto.getDouble("amountLimit") <= 0D) {
204 throw new CoreException(MasterExceptionConstants.AMOUNT_LIMIT_MUST_GREATER_THAN_ZERO,
205 inputDto.getDouble("amountLimit"));
206 }
207
208 Dto typePartnerDto = new Dto();
209 // Validation typePartnerId must exists
210 if (!GeneralConstants.NULL_REF_VALUE_LONG.equals(inputDto.getLong("typePartnerId"))) {
211 typePartnerDto = findTypePartnerById.execute(new Dto().put("id", inputDto.getLong("typePartnerId")));
212 valSameTenantId(inputDto, typePartnerDto, "Type Partner");
213 valActive(typePartnerDto.getString("active"), "Type Partner");
214 }
215
216 log.debug(">> typePartnerDto = " + typePartnerDto);
217
218 // Validation duePaymentDays and dueReceiveDays >=0
219 if (inputDto.getLong("duePaymentDays") < 0) {
220 throw new CoreException(MasterExceptionConstants.DUE_PAYMENTS_DAYS_MUST_GREATER_OR_EQUALS_WITH_ZERO,
221 inputDto.getLong("duePaymentDays"));
222 }
223
224 if (inputDto.getLong("dueReceiveDays") < 0) {
225 throw new CoreException(MasterExceptionConstants.DUE_RECEIVE_DAYS_MUST_GREATER_OR_EQUALS_WITH_ZERO,
226 inputDto.getLong("dueReceiveDays"));
227 }
228
229 // Validation data (business key) is not exists yet in db (add) FOR Partner Type
230 Dto paramCheckUniquePartnerTypeDto = new Dto();
231 paramCheckUniquePartnerTypeDto.put("tenantId", inputDto.getLong("tenantLoginId"));
232 paramCheckUniquePartnerTypeDto.put("partnerId", inputDto.getLong("partnerId"));
233 paramCheckUniquePartnerTypeDto.put("groupPartner", typePartnerDto.getString("groupPartner"));
234 Dto resultCheckUniquePartnerTypeDto = isPartnerTypeExistsByIndex.execute(paramCheckUniquePartnerTypeDto);
235
236 if (resultCheckUniquePartnerTypeDto.getBoolean("exists")) {
237 throw new CoreException(MasterExceptionConstants.PARTNER_TYPE_ALREADY_EXISTS,
238 resultCheckUniquePartnerTypeDto.getString("partnerTypeDto.partnerId"),
239 resultCheckUniquePartnerTypeDto.getString("partnerTypeDto.groupPartner"));
240 }
241
242 // Validation data (business key) is not exists yet in db (add) FOR Supplier Payment
243 Dto paramCheckUniqueSuppPaymentDto = new Dto();
244 paramCheckUniqueSuppPaymentDto.put("tenantId", inputDto.getLong("tenantLoginId"));
245 paramCheckUniqueSuppPaymentDto.put("partnerId", inputDto.getLong("partnerId"));
246 Dto resultCheckUniqueSuppPaymentDto = isSuppPaymentExistsByIndex.execute(paramCheckUniqueSuppPaymentDto);
247
248 if (resultCheckUniqueSuppPaymentDto.getBoolean("exists")) {
249 throw new CoreException(MasterExceptionConstants.SUPP_PAYMENT_ALREADY_EXISTS,
250 resultCheckUniqueSuppPaymentDto.getString("suppPaymentDto.tenantId"),
251 resultCheckUniqueSuppPaymentDto.getString("suppPaymentDto.partnerId"));
252 }
253
254 /*
255 * Partner Type
256 */
257 Dto partnerTypeDto = new Dto();
258 partnerTypeDto.put("tenantId", inputDto.getLong("tenantLoginId"));
259 partnerTypeDto.put("partnerId", inputDto.getLong("partnerId"));
260 partnerTypeDto.put("groupPartner", typePartnerDto.get("groupPartner"));
261 partnerTypeDto.put("typePartnerId", inputDto.getLong("typePartnerId"));
262 partnerTypeDto.put("dueDate", inputDto.getLong("duePaymentDays").intValue());
263 partnerTypeDto.put("currencyCode", inputDto.getString("currencyCode"));
264 partnerTypeDto.put("amountLimit", inputDto.getDouble("amountLimit"));
265 partnerTypeDto.put("flagCommision", GeneralConstants.NO);
266
267 // Set active = Y
268 partnerTypeDto.put("active", GeneralConstants.YES);
269
270 // Set active datetime
271 partnerTypeDto.put("activeDateTime", inputDto.get("datetime"));
272 partnerTypeDto.put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
273
274 // Copy process date and userId for partner type
275 prepareInsertAudit(partnerTypeDto, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
276 prepareUpdateAudit(partnerTypeDto, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
277
278 /*
279 * Supplier Payment
280 */
281 Dto suppPaymentDto = new Dto();
282 suppPaymentDto.put("tenantId", inputDto.getLong("tenantLoginId"));
283 suppPaymentDto.put("partnerId", inputDto.getLong("partnerId"));
284 suppPaymentDto.put("duePaymentDays", inputDto.getLong("duePaymentDays"));
285 suppPaymentDto.put("dueReceiveDays", inputDto.getLong("dueReceiveDays"));
286
287 // Set active = Y
288 suppPaymentDto.put("active", GeneralConstants.YES);
289
290 // Set active datetime
291 suppPaymentDto.put("activeDateTime", inputDto.get("datetime"));
292 suppPaymentDto.put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
293
294 // Copy process date and userId for supp payment
295 prepareInsertAudit(suppPaymentDto, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
296 prepareUpdateAudit(suppPaymentDto, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
297
298 /*
299 * Partner Supplier
300 */
301 Dto partnerSupplierInfoDto = new Dto();
302 partnerSupplierInfoDto.put("id", inputDto.getLong("partnerId"));
303 partnerSupplierInfoDto.put("flagDropship", inputDto.getString("flagDropship"));
304
305 // Copy process date and userId for partner type
306 prepareInsertAudit(partnerSupplierInfoDto, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
307 prepareUpdateAudit(partnerSupplierInfoDto, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
308
309 inputDto.put("partnerSupplierInfoDto", partnerSupplierInfoDto);
310 inputDto.put("partnerTypeDto", partnerTypeDto);
311 inputDto.put("suppPaymentDto", suppPaymentDto);
312
313 // TODO
314 Dto newUser = new Dto();
315 newUser.put("name", partnerDto.getString("code"));
316 newUser.put("fullName", partnerDto.getString("name"));
317 newUser.put("password", MasterConstantsForCland.DEFAULT_PASSWORD);
318 newUser.put("email", MasterConstantsForCland.DEFAULT_EMAIL);
319 newUser.put("phone", MasterConstantsForCland.DEFAULT_PHONE);
320 newUser.put("tenantLoginId", inputDto.get("tenantLoginId"));
321 newUser.put("roleDefaultId", MasterConstantsForCland.DEFAULT_ROLE_ID);
322 newUser.put("ouDefaultId", MasterConstantsForCland.DEFAULT_TENANT_ID);
323 newUser.put("policyDefaultId", MasterConstantsForCland.DEFAULT_POLICY_ID);
324 newUser.put("active", GeneralConstants.YES);
325 newUser.put("userLoginId", inputDto.get("userLoginId"));
326 newUser.put("roleLoginId", inputDto.get("roleLoginId"));
327 newUser.put("datetime", inputDto.get("datetime"));
328
329 log.debug(" inputDto Add User: " + inputDto.toString());
330
331 Long tenantId = inputDto.getLong("tenantLoginId");
332
333 // Copy process date and userId
334 this.prepareInsertAudit(newUser, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
335 this.prepareUpdateAudit(newUser, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
336
337 //Validation user login id must superadmin if tenant in role id doesn't match with tenant id in param Dto
338 Dto roleDto = findRoleById.execute(new Dto().put("id", newUser.getLong("roleDefaultId")));
339
340 if (roleDto.getString("roleType").equals(CommonConstants.ROLE_TYPE_ADMIN)) {
341 Dto valDto = new Dto();
342 valDto.put("userId", newUser.getLong("userLoginId"));
343 valDto.put("roleId", newUser.getLong("roleLoginId"));
344 valRoleIsSuperAdmin.execute(valDto);
345 }
346
347 if (!newUser.getLong("tenantLoginId").equals(roleDto.getLong("tenantId"))) {
348 throw new CoreException(CommonExceptionConstants.TENANT_USER_ROLE_NOT_MATCH, inputDto.getString("fullName"),
349 roleDto.getString("name"));
350 }
351
352 // Validation ou id must exists and active
353 // validate ou must business unit or sub accounting
354 Dto findOuDto = valOUAsBusinessUnit.execute(new Dto().put("id", newUser.getLong("ouDefaultId")));
355
356 if (!inputDto.getLong("tenantLoginId").equals(findOuDto.getLong("tenantId"))) {
357 throw new CoreException(CommonExceptionConstants.TENANT_USER_OU_NOT_MATCH, inputDto.getString("fullName"),
358 findOuDto.getString("name"));
359 }
360
361 //validation policy id must exist and active
362 Dto policyDto = findPolicyById.execute(new Dto().put("id", newUser.get("policyDefaultId")));
363 if (!policyDto.get("active").equals(GeneralConstants.YES)) {
364 throw new CoreException(CommonExceptionConstants.POLICY_NOT_ACTIVE, newUser.get("policyDefaultId"));
365 }
366
367 // Validation value active must suitable with COMBO YES NO
368 Dto paramDto = new Dto();
369 paramDto.put("comboId", ComboIdConstants.COMBO_YES_NO);
370 paramDto.put("code", newUser.getString("active"));
371 paramDto.put("varName", "active");
372 valComboValueByCode.execute(paramDto);
373
374 // Validation, Username must not exists
375 Dto checkUserDto = new Dto();
376 checkUserDto.put("name", newUser.get("name"));
377 checkUserDto = isUserExistsByIndex.execute(checkUserDto);
378
379 if (checkUserDto.getBoolean("exists").booleanValue()) {
380 throw new CoreException(CommonExceptionConstants.USER_ALREADY_EXISTS, newUser.getString("name"));
381 }
382
383 // Set active datetime if active = Y
384 if (newUser.getString("active").equals(GeneralConstants.YES)) {
385 newUser.put("activeDateTime", newUser.get("datetime"));
386 newUser.put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
387 } else {
388 newUser.put("activeDateTime", GeneralConstants.SPACE_VALUE);
389 newUser.put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
390 }
391
392 // cek configuration password policy and encryption method
393 //boolean usePasswordPolicy = false;
394 String encryption = CommonConstants.ENCRYPTION_DEFAULT;
395
396 Dto outputSystemConfigEncryptionMethod = isSystemConfigExistsByParameterCode.execute(new Dto()
397 .put("tenantId", tenantId)
398 .put("parameterCode", CommonConstants.PARAMETER_PASSWORD_ENCRYPTION_METHOD));
399 if(outputSystemConfigEncryptionMethod.getBoolean("exists")){
400 encryption = outputSystemConfigEncryptionMethod.getDto("systemConfigDto").getString("value");
401 }
402 log.debug("Encryption : " + encryption);
403
404 // Generate password using security util md5 by password value
405 // Generate private key using security JCE
406 // inputDto.put("password", SecurityUtil.md5(inputDto.getString("password")));
407 // log.debug("userDto.getLong(\"tenantLoginId\"), userDto.getString(\"name\"), userDto.getString(\"datetime\"), userDto.getString(\"password\") :"+inputDto.getLong("tenantLoginId")+" , "+inputDto.getString("name")+" , "+inputDto.getString("datetime")+" , "+inputDto.getString("password") );
408 newUser.put("password",
409 PasswordUtil.generatePassword(inputDto.getLong("tenantLoginId"), newUser.getString("name"),
410 newUser.getString("datetime"), newUser.getString("password"), encryption ));
411
412 log.debug("papas : "+ newUser.getString("password"));
413
414 newUser.put("privateKey", SecurityUtil.bytesToHex(SecurityUtil.generatePrivateKey()));
415 newUser.put("tenantId", inputDto.getLong("tenantLoginId"));
416
417 //create userRoleDto
418 Dto userRoleDto = new Dto();
419 userRoleDto.put("roleId", newUser.get("roleDefaultId"));
420 userRoleDto.put("policyId", newUser.get("policyDefaultId"));
421 userRoleDto.put("active", newUser.get("active"));
422 if (newUser.getString("active").equals(GeneralConstants.YES)) {
423 userRoleDto.put("activeDateTime", newUser.get("datetime"));
424 userRoleDto.put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
425 } else {
426 userRoleDto.put("activeDateTime", GeneralConstants.SPACE_VALUE);
427 userRoleDto.put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
428 }
429 this.prepareInsertAudit(userRoleDto, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
430 this.prepareUpdateAudit(userRoleDto, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
431
432 // Create User Login Information
433 UserLoginInformation userLoginInformation = new UserLoginInformation();
434 // userLoginInformation.setId(id);
435 userLoginInformation.setInvalidPasswordAttempts(0L);
436 userLoginInformation.setLastAuthenticated(GeneralConstants.EMPTY_VALUE);
437 userLoginInformation.setLoginCount(0L);
438 userLoginInformation.setCurrentFailedCount(0L);
439 userLoginInformation.setLastFailedLoginMillis(0L);
440 userLoginInformation.setLastLoginMillis(0L);
441 userLoginInformation.setTotalFailedCount(0L);
442 userLoginInformation.setPasswordLastChanged(inputDto.getString("datetime"));
443 userLoginInformation.setRequiresPasswordChange(GeneralConstants.YES);
444 Dto userLoginInformationDto = new Dto(userLoginInformation);
445 this.prepareInsertAudit(userLoginInformationDto, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
446 this.prepareUpdateAudit(userLoginInformationDto, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
447
448 // ini untuk PartnerUser nya karena sudah di validasi di atas, makan tinggal pakai active dan datetime nya
449 Dto partnerUserDto = new Dto();
450 partnerUserDto.put("partnerId", inputDto.getLong("partnerId"));
451 partnerUserDto.put("active", newUser.get("active"));userRoleDto.put("active", newUser.get("active"));
452 if (partnerUserDto.getString("active").equals(GeneralConstants.YES)) {
453 partnerUserDto.put("activeDateTime", newUser.get("datetime"));
454 partnerUserDto.put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
455 } else {
456 partnerUserDto.put("activeDateTime", GeneralConstants.SPACE_VALUE);
457 partnerUserDto.put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
458 }
459
460 this.prepareInsertAudit(partnerUserDto, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
461 this.prepareUpdateAudit(partnerUserDto, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
462
463
464 //put userRoleDto & userLoginInformationDto
465 inputDto.put("userRoleDto", userRoleDto);
466 inputDto.put("userLoginInformationDto", userLoginInformationDto);
467 inputDto.put("newUser", newUser);
468 inputDto.put("partnerUserDto", partnerUserDto);
469
470 log.debug(">> inputDto = " + inputDto);
471 return null;
472 }
473
474 /**
475 * Validate tenantId in refDto must be equals with tenantLoginId in inputDto.
476 *
477 * @param inputDto
478 * @param refDto
479 * @param refName
480 *
481 */
482 private void valSameTenantId(Dto inputDto, Dto refDto, String refName) {
483 if (!inputDto.getLong("tenantLoginId").equals(refDto.getLong("tenantId"))) {
484 throw new CoreException(CommonExceptionConstants.DATA_CANT_USE_DIFF_TENANT, "Partner As Supplier", refName);
485 }
486 }
487
488 /**
489 * Validate code must be suitable with combo constants of given combo id
490 *
491 * @param comboId
492 * @param code
493 * @param varName
494 * @throws Exception
495 *
496 */
497 private void doValComboValueByCode(String comboId, String code, String varName) throws Exception {
498 Dto paramDto = new Dto();
499 paramDto.put("comboId", comboId);
500 paramDto.put("code", code);
501 paramDto.put("varName", varName);
502 valComboValueByCode.execute(paramDto);
503 }
504
505 /**
506 * Validate active
507 *
508 * @param active
509 * @param notActiveData
510 */
511 private void valActive(String active, String notActiveData) {
512 if (!GeneralConstants.YES.equals(active)) {
513 throw new CoreException(MasterExceptionConstants.DATA_NOT_ACTIVE, notActiveData);
514 }
515 }
516
517 @Override
518 public Dto process(Dto inputDto, Dto originalDto) throws Exception {
519 Dto partnerTypeDto = inputDto.getDto("partnerTypeDto");
520 Dto suppPaymentDto = inputDto.getDto("suppPaymentDto");
521 Dto partnerSupplierInfoDto = inputDto.getDto("partnerSupplierInfoDto");
522
523 // Add Partner Type
524 PartnerType partnerType = GsonUtil.fromDto(partnerTypeDto, PartnerType.class);
525 partnerTypeDao.persist(partnerType);
526
527 // Add Supplier Payment
528 SuppPayment suppPayment = GsonUtil.fromDto(suppPaymentDto, SuppPayment.class);
529 suppPaymentDao.persist(suppPayment);
530
531 // Add Partner Supplier Info
532 PartnerSupplierInfo partnerSupplierInfo = GsonUtil.fromDto(partnerSupplierInfoDto, PartnerSupplierInfo.class);
533 partnerSupplierInfoDao.persist(partnerSupplierInfo);
534
535 //TODO
536 // Add user
537 Dto newUser = inputDto.getDto("newUser");
538 User user = GsonUtil.fromDto(newUser, User.class);
539 userDao.persist(user);
540
541 //add user role
542 Dto userRoleDto = inputDto.getDto("userRoleDto");
543 userRoleDto.put("userId", user.getId());
544 UserRole userRole = GsonUtil.fromDto(userRoleDto, UserRole.class);
545 userRoleDao.persist(userRole);
546
547 //add partner user
548 Dto partnerUserDto = inputDto.getDto("partnerUserDto");
549 partnerUserDto.put("userId", user.getId());
550 PartnerUser partnerUser = GsonUtil.fromDto(partnerUserDto, PartnerUser.class);
551 partnerUserDao.persist(partnerUser);
552
553 // Add user properties, counter login
554 Dto userPropsDto = new Dto();
555 userPropsDto.put("userPropsPk.propKey", CommonConstants.USER_PROP_COUNTER_LOGIN);
556 userPropsDto.put("userPropsPk.userId", user.getId());
557 userPropsDto.put("propVal", "0");
558 UserProps userProps = GsonUtil.fromDto(userPropsDto, UserProps.class);
559 userPropsDao.persist(userProps);
560
561 // Add user properties, last login
562 userPropsDto = new Dto();
563 userPropsDto.put("userPropsPk.propKey", CommonConstants.USER_PROP_LAST_LOGIN);
564 userPropsDto.put("userPropsPk.userId", user.getId());
565 userPropsDto.put("propVal", GeneralConstants.SPACE_VALUE);
566 userProps = GsonUtil.fromDto(userPropsDto, UserProps.class);
567 userPropsDao.persist(userProps);
568
569 // Add User Login Information
570 Dto userLoginInformationDto = inputDto.getDto("userLoginInformationDto");
571 UserLoginInformation userLoginInformation = GsonUtil.fromDto(userLoginInformationDto, UserLoginInformation.class);
572 userLoginInformation.setId(user.getId());
573 userLoginInformationDao.persist(userLoginInformation);
574
575// return new Dto(partnerType);
576 return new Dto(user);
577 }
578
579}