1 package org.kuali.ole.deliver.defaultload;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.deliver.bo.OlePatronDocument;
5 import org.kuali.ole.deliver.bo.OlePatronIngestSummaryRecord;
6 import org.kuali.ole.ingest.FileUtil;
7 import org.kuali.ole.service.OlePatronConverterService;
8 import org.kuali.rice.coreservice.api.parameter.Parameter;
9 import org.kuali.rice.coreservice.api.parameter.ParameterType;
10 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
11
12 import java.io.File;
13 import java.net.URL;
14 import java.util.Collections;
15 import java.util.List;
16
17
18
19
20
21
22
23
24 public class LoadDefaultPatronsBean {
25 private String fileName;
26 private OlePatronConverterService olePatronIngestService;
27 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LoadDefaultPatronsBean.class);
28 protected static final String LOAD_DEFAULT_PATRONS_IND = "LOAD_DEFAULT_PATRONS_IND";
29 protected ParameterService parameterService;
30
31 public List<OlePatronDocument> loadDefaultPatrons(boolean forceLoad) throws Exception {
32 if (forceLoad || parameterService.getParameterValueAsBoolean(OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, LOAD_DEFAULT_PATRONS_IND, Boolean.TRUE)) {
33 LOG.debug("Starting Load of Default Patrons");
34
35 URL resource = getClass().getResource(fileName);
36 File file = new File(resource.toURI());
37 String fileContent = new FileUtil().readFile(file);
38 List<OlePatronDocument> olePatronDocuments =
39 olePatronIngestService.persistPatronFromFileContent(fileContent,
40 true,
41 file.getName(),
42 new OlePatronIngestSummaryRecord(), null, "");
43 LOG.debug("Completed Load of Default Patrons");
44 Parameter existingParameter = parameterService.getParameter(OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, LOAD_DEFAULT_PATRONS_IND);
45 if (existingParameter != null) {
46 Parameter.Builder updatedParameter = Parameter.Builder.create(existingParameter);
47 updatedParameter.setValue("N");
48 parameterService.updateParameter(updatedParameter.build());
49 } else {
50 Parameter.Builder newParameter = Parameter.Builder.create(OLEConstants.APPL_ID, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, LOAD_DEFAULT_PATRONS_IND, ParameterType.Builder.create("CONFG"));
51 newParameter.setDescription("Set to 'Y' to have the application ingest the default patrons upon next startup.");
52 newParameter.setValue("N");
53 parameterService.createParameter(newParameter.build());
54 }
55 return olePatronDocuments;
56 }
57 return Collections.emptyList();
58 }
59
60 public String getFileName() {
61 return fileName;
62 }
63
64 public void setFileName(String fileName) {
65 this.fileName = fileName;
66 }
67
68 public OlePatronConverterService getOlePatronIngestService() {
69 return olePatronIngestService;
70 }
71
72 public void setOlePatronIngestService(OlePatronConverterService olePatronIngestService) {
73 this.olePatronIngestService = olePatronIngestService;
74 }
75
76 public void setParameterService(ParameterService parameterService) {
77 this.parameterService = parameterService;
78 }
79 }