1 | |
package org.kuali.student.enrollment.class2.courseregistration.service.assembler; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.List; |
5 | |
|
6 | |
import org.kuali.student.enrollment.courseregistration.dto.RegResponseInfo; |
7 | |
import org.kuali.student.enrollment.courseregistration.dto.RegResponseItemInfo; |
8 | |
import org.kuali.student.enrollment.lpr.dto.LprTransactionInfo; |
9 | |
import org.kuali.student.enrollment.lpr.dto.LprTransactionItemInfo; |
10 | |
import org.kuali.student.r2.common.assembler.AssemblyException; |
11 | |
import org.kuali.student.r2.common.assembler.DTOAssembler; |
12 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
13 | |
import org.kuali.student.r2.common.dto.OperationStatusInfo; |
14 | |
import org.kuali.student.r2.common.util.constants.LuiPersonRelationServiceConstants; |
15 | |
|
16 | 0 | public class RegResponseAssembler implements DTOAssembler<RegResponseInfo, LprTransactionInfo> { |
17 | |
|
18 | |
@Override |
19 | |
public RegResponseInfo assemble(LprTransactionInfo baseDTO, ContextInfo context) throws AssemblyException { |
20 | 0 | RegResponseInfo regResponse = new RegResponseInfo(); |
21 | 0 | regResponse.setRegRequestId(baseDTO.getId()); |
22 | 0 | List<RegResponseItemInfo> resgRespItems = new ArrayList<RegResponseItemInfo>(); |
23 | 0 | for (LprTransactionItemInfo lprTransItems : baseDTO.getLprTransactionItems()) { |
24 | 0 | resgRespItems.add(assembleItem(lprTransItems, context)); |
25 | |
} |
26 | 0 | regResponse.setRegResponseItems(resgRespItems); |
27 | 0 | regResponse.setOperationStatus(createOverallOperationStatus(baseDTO)); |
28 | 0 | return regResponse; |
29 | |
} |
30 | |
|
31 | |
@Override |
32 | |
public LprTransactionInfo disassemble(RegResponseInfo businessDTO, ContextInfo context) throws AssemblyException { |
33 | |
|
34 | 0 | return null; |
35 | |
} |
36 | |
|
37 | |
public RegResponseItemInfo assembleItem(LprTransactionItemInfo baseDTO, ContextInfo context) { |
38 | 0 | RegResponseItemInfo regResponseItem = new RegResponseItemInfo(); |
39 | 0 | if (baseDTO.getTypeKey().equals(LuiPersonRelationServiceConstants.LPRTRANS_ITEM_ADD_TO_WAITLIST_TYPE_KEY)) { |
40 | 0 | regResponseItem.setCourseWaitlistEntryId(baseDTO.getLprTransactionItemResult().getResultingLprId()); |
41 | |
} else { |
42 | 0 | regResponseItem.setCourseRegistrationId(baseDTO.getLprTransactionItemResult().getResultingLprId()); |
43 | |
} |
44 | 0 | regResponseItem.setRegRequestItemId(baseDTO.getId()); |
45 | 0 | OperationStatusInfo operationStatus = new OperationStatusInfo(); |
46 | 0 | operationStatus.setStatus(baseDTO.getLprTransactionItemResult().getStatus()); |
47 | 0 | operationStatus.setMessages(baseDTO.getLprTransactionItemResult().getMessages()); |
48 | |
|
49 | 0 | regResponseItem.setOperationStatus(operationStatus); |
50 | 0 | return regResponseItem; |
51 | |
} |
52 | |
|
53 | |
|
54 | |
private OperationStatusInfo createOverallOperationStatus(LprTransactionInfo lprTransaction) { |
55 | 0 | OperationStatusInfo opStatusInfo = new OperationStatusInfo(); |
56 | 0 | boolean isSuccessful = true; |
57 | 0 | for (LprTransactionItemInfo transItem : lprTransaction.getLprTransactionItems()) { |
58 | 0 | if (transItem.getLprTransactionItemResult() != null) { |
59 | 0 | if (transItem.getLprTransactionItemResult().getStatus() != "SUCCESS") { |
60 | 0 | isSuccessful = false; |
61 | |
} |
62 | |
} |
63 | |
} |
64 | 0 | if (isSuccessful) |
65 | 0 | opStatusInfo.setStatus("SUCCESS"); |
66 | |
else |
67 | 0 | opStatusInfo.setStatus("FAILURE"); |
68 | |
|
69 | 0 | return opStatusInfo; |
70 | |
} |
71 | |
|
72 | |
} |