1 package org.kuali.ole.describe.defaultload;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.ingest.FileUtil;
5 import org.kuali.ole.service.OleLocationConverterService;
6 import org.kuali.rice.coreservice.api.parameter.Parameter;
7 import org.kuali.rice.coreservice.api.parameter.ParameterType;
8 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
9
10 import java.io.File;
11 import java.net.URL;
12 import java.util.ArrayList;
13 import java.util.List;
14
15
16
17
18
19
20
21
22 public class LoadDefaultLocationsBean {
23 private String fileName;
24 private List<String> locationFiles = new ArrayList<String>();
25 private OleLocationConverterService oleLocationIngestService;
26 protected ParameterService parameterService;
27
28 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LoadDefaultLocationsBean.class);
29 protected static final String LOAD_DEFAULT_LOCATIONS_IND = "LOAD_DEFAULT_LOCATIONS_IND";
30
31 public void loadDefaultLocations(boolean forceLoad) throws Exception {
32 if (forceLoad || parameterService.getParameterValueAsBoolean(OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, LOAD_DEFAULT_LOCATIONS_IND, Boolean.TRUE)) {
33 LOG.info("Starting Load of Default Locations");
34
35 for (int i = 0; i < locationFiles.size(); i++) {
36 fileName = this.locationFiles.get(i);
37 URL resource = getClass().getResource(fileName);
38 File file = new File(resource.toURI());
39 String fileContent = new FileUtil().readFile(file);
40 oleLocationIngestService.persistLocationFromFileContent(fileContent, file.getName());
41 LOG.info("Completed Load of Default Locations");
42
43 Parameter existingParameter = parameterService.getParameter(OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, LOAD_DEFAULT_LOCATIONS_IND);
44 if (existingParameter != null) {
45 Parameter.Builder updatedParameter = Parameter.Builder.create(existingParameter);
46 updatedParameter.setValue("N");
47 parameterService.updateParameter(updatedParameter.build());
48 } else {
49 Parameter.Builder newParameter = Parameter.Builder.create(OLEConstants.APPL_ID, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, LOAD_DEFAULT_LOCATIONS_IND, ParameterType.Builder.create("CONFG"));
50 newParameter.setDescription("Set to 'Y' to have the application ingest the default circulation policies upon next startup.");
51 newParameter.setValue("N");
52 parameterService.createParameter(newParameter.build());
53 }
54 }
55 }
56 }
57
58 public String getFileName() {
59 return fileName;
60 }
61
62 public void setFileName(String fileName) {
63 this.fileName = fileName;
64 }
65
66 public OleLocationConverterService getOleLocationIngestService() {
67 return oleLocationIngestService;
68 }
69
70 public void setOleLocationIngestService(OleLocationConverterService oleLocationIngestService) {
71 this.oleLocationIngestService = oleLocationIngestService;
72 }
73
74 public List<String> getLocationFiles() {
75 return locationFiles;
76 }
77
78 public void setLocationFiles(List<String> locationFiles) {
79 this.locationFiles = locationFiles;
80 }
81
82 public void setParameterService(ParameterService parameterService) {
83 this.parameterService = parameterService;
84 }
85 }