1 package org.kuali.ole.deliver.defaultload;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.ingest.FileUtil;
5 import org.kuali.ole.ingest.KrmsBuilder;
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.Collections;
13 import java.util.List;
14
15
16
17
18
19
20
21
22 public class LoadDefaultLicensesBean {
23 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LoadDefaultLicensesBean.class);
24 protected static final String LOAD_DEFAULT_LICENSES_IND = "LOAD_DEFAULT_LICENSES_IND";
25 protected String fileName;
26 protected KrmsBuilder licenseBuilder;
27 protected ParameterService parameterService;
28
29 public List<String> loadDefaultLicenses(boolean forceLoad) throws Exception {
30 if (forceLoad || parameterService.getParameterValueAsBoolean(OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, LOAD_DEFAULT_LICENSES_IND, Boolean.TRUE)) {
31 LOG.info("Starting Load of Default Licenses");
32
33 URL resource = getClass().getResource(fileName);
34 File file = new File(resource.toURI());
35 String fileContent = new FileUtil().readFile(file);
36 List<String> policies = licenseBuilder.persistKrmsFromFileContent(fileContent);
37
38 LOG.info("Completed Load of Default Licenses");
39
40 Parameter existingParameter = parameterService.getParameter(OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, LOAD_DEFAULT_LICENSES_IND);
41 if (existingParameter != null) {
42 Parameter.Builder updatedParameter = Parameter.Builder.create(existingParameter);
43 updatedParameter.setValue("N");
44 parameterService.updateParameter(updatedParameter.build());
45 } else {
46 Parameter.Builder newParameter = Parameter.Builder.create(OLEConstants.APPL_ID, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, LOAD_DEFAULT_LICENSES_IND, ParameterType.Builder.create("CONFG"));
47 newParameter.setDescription("Set to 'Y' to have the application ingest the default Licenses upon next startup.");
48 newParameter.setValue("N");
49 parameterService.createParameter(newParameter.build());
50 }
51
52 return policies;
53 }
54 return Collections.emptyList();
55 }
56
57 public void setFileName(String fileName) {
58 this.fileName = fileName;
59 }
60
61 public void setLicenseBuilder(KrmsBuilder licenseBuilder) {
62 this.licenseBuilder = licenseBuilder;
63 }
64
65 public void setParameterService(ParameterService parameterService) {
66 this.parameterService = parameterService;
67 }
68 }