1 package org.kuali.ole.patron.maintenance;
2
3 import org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException;
4 import org.kuali.ole.loan.LoanProcessor;
5 import org.kuali.ole.patron.bo.OlePatronDocument;
6 import org.kuali.ole.service.OlePatronService;
7 import org.kuali.ole.service.OlePatronServiceImpl;
8 import org.kuali.rice.kim.api.KimConstants;
9 import org.kuali.rice.kim.impl.identity.entity.EntityBo;
10 import org.kuali.rice.kim.impl.identity.name.EntityNameTypeBo;
11 import org.kuali.rice.kim.impl.identity.type.EntityTypeContactInfoBo;
12 import org.kuali.rice.krad.maintenance.MaintainableImpl;
13 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
14 import org.kuali.rice.krad.service.KRADServiceLocator;
15
16 import java.util.ArrayList;
17 import java.util.Arrays;
18 import java.util.List;
19 import java.util.Map;
20
21
22
23
24
25 public class OlePatronMaintenanceImpl extends MaintainableImpl{
26 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OlePatronMaintenanceImpl.class);
27 OlePatronService olePatronService = new OlePatronServiceImpl();
28
29
30
31
32 @Override
33 public void prepareForSave() {
34 LOG.debug("Inside prepareForSave method");
35 OlePatronDocument patronDocument = (OlePatronDocument)getDataObject();
36 EntityBo kimEntity;
37 List<EntityTypeContactInfoBo> entityTypes;
38 EntityTypeContactInfoBo entityType;
39 if(patronDocument.getEntity() == null) {
40 kimEntity = new EntityBo();
41 entityTypes = new ArrayList<EntityTypeContactInfoBo>();
42 entityType = new EntityTypeContactInfoBo();
43 kimEntity.setActive(true);
44
45 entityType.setEntityTypeCode(KimConstants.EntityTypes.PERSON);
46 entityType.setActive(true);
47 }
48 else {
49 kimEntity = patronDocument.getEntity();
50 kimEntity.setActive(true);
51 entityTypes = kimEntity.getEntityTypeContactInfos();
52 if(!entityTypes.isEmpty()){
53 entityType = entityTypes.get(0);
54 entityType.setActive(true);
55 }
56 else {
57 entityType = new EntityTypeContactInfoBo();
58 entityType.setEntityTypeCode(KimConstants.EntityTypes.PERSON);
59 }
60 }
61 kimEntity.setNames(Arrays.asList(patronDocument.getName()));
62
63 entityType.setAddresses(patronDocument.getAddresses());
64 entityType.setEmailAddresses(patronDocument.getEmails());
65 entityType.setPhoneNumbers(patronDocument.getPhones());
66
67 entityTypes.add(entityType);
68
69 kimEntity.setEntityTypeContactInfos(entityTypes);
70 getBusinessObjectService().save(kimEntity);
71 patronDocument.setEntity(kimEntity);
72 setDataObject(patronDocument);
73 }
74
75
76
77
78
79
80
81 @Override
82 public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
83 LOG.debug("Inside retrieveObjectForEditOrCopy()");
84 Object dataObject = null;
85 OlePatronDocument olePatron = new OlePatronDocument();
86 try {
87 dataObject = getLookupService().findObjectBySearch(getDataObjectClass(), dataObjectKeys);
88 olePatron = (OlePatronDocument)dataObject;
89 EntityBo entity = olePatron.getEntity();
90 olePatron.setName(entity.getNames().get(0));
91 if(!entity.getEntityTypeContactInfos().isEmpty()){
92 olePatron.setAddresses(entity.getEntityTypeContactInfos().get(0).getAddresses());
93 olePatron.setPhones(entity.getEntityTypeContactInfos().get(0).getPhoneNumbers());
94 olePatron.setEmails(entity.getEntityTypeContactInfos().get(0).getEmailAddresses());
95 }
96 if(olePatron.getOlePatronId() != null) {
97 LoanProcessor loanProcessor = new LoanProcessor();
98 try {
99 olePatron.setOleLoanDocuments(loanProcessor.getPatronLoanedItem(olePatron.getOlePatronId()));
100 } catch (Exception e) {
101 e.printStackTrace();
102 }
103 }
104
105 } catch (ClassNotPersistenceCapableException ex) {
106 if (!document.getOldMaintainableObject().isExternalBusinessObject()) {
107 throw new RuntimeException("Data Object Class: "
108 + getDataObjectClass()
109 + " is not persistable and is not externalizable - configuration error");
110 }
111 }
112
113 return olePatron;
114 }
115
116
117
118
119
120
121 @Override
122 public void processAfterNew(MaintenanceDocument document,
123 Map<String, String[]> requestParameters) {
124 LOG.debug("Inside processAfterNew()");
125 EntityNameTypeBo nameTypeBo = (EntityNameTypeBo) KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(EntityNameTypeBo.class, "PRFR");
126 OlePatronDocument patronDocument = (OlePatronDocument)document.getNewMaintainableObject().getDataObject();
127 patronDocument.setActiveIndicator(true);
128 patronDocument.getName().setActive(true);
129 patronDocument.getName().setDefaultValue(true);
130 patronDocument.getName().setNameType(nameTypeBo);
131 document.getNewMaintainableObject().setDataObject(patronDocument);
132 super.processAfterNew(document, requestParameters);
133 document.getDocumentHeader().setDocumentDescription("New Patron Document");
134
135 }
136
137
138
139
140
141
142 @Override
143 public void processAfterCopy(MaintenanceDocument document, Map<String, String[]> requestParameters) {
144 LOG.debug("Inside processAfterCopy()");
145 super.processAfterCopy(document, requestParameters);
146 document.getDocumentHeader().setDocumentDescription("Copied Patron Document");
147 }
148
149
150
151
152
153
154 @Override
155 public void processAfterEdit(MaintenanceDocument document, Map<String, String[]> requestParameters) {
156 LOG.debug("Inside processAfterEdit()");
157 super.processAfterEdit(document,requestParameters);
158 document.getDocumentHeader().setDocumentDescription("Edited Patron Document");
159 }
160 }