1 package org.kuali.ole.ingest;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.ingest.krms.builder.OleKrmsBuilder;
5 import org.kuali.rice.coreservice.api.parameter.Parameter;
6 import org.kuali.rice.coreservice.api.parameter.ParameterType;
7 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
8
9 import java.io.File;
10 import java.net.URL;
11 import java.util.Collections;
12 import java.util.List;
13
14
15
16
17
18
19
20
21 public class LoadDefaultIngestProfileBean {
22 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LoadDefaultIngestProfileBean.class);
23 protected static final String LOAD_DEFAULT_INGEST_POLICIES_IND = "LOAD_DEFAULT_INGEST_POLICIES_IND";
24 protected String fileName;
25 protected OleKrmsBuilder oleKrmsBuilder;
26 protected ParameterService parameterService;
27
28 public List<String> loadDefaultIngestProfile( boolean forceLoad ) throws Exception {
29 if ( forceLoad || parameterService.getParameterValueAsBoolean(OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, LOAD_DEFAULT_INGEST_POLICIES_IND, Boolean.TRUE) ) {
30 LOG.info("Starting Load of Default Ingest Profiles");
31 URL resource = getClass().getResource(fileName);
32 File file = new File(resource.toURI());
33 String fileContent = new FileUtil().readFile(file);
34 List<String> policies= oleKrmsBuilder.persistKrmsFromFileContent(fileContent);
35 LOG.info("Completed Load of Default Ingest Profiles");
36
37 Parameter existingParameter = parameterService.getParameter(OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, LOAD_DEFAULT_INGEST_POLICIES_IND);
38 if ( existingParameter != null ) {
39 Parameter.Builder updatedParameter = Parameter.Builder.create(existingParameter);
40 updatedParameter.setValue("N");
41 parameterService.updateParameter(updatedParameter.build());
42 } else {
43 Parameter.Builder newParameter = Parameter.Builder.create(OLEConstants.APPL_ID, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, LOAD_DEFAULT_INGEST_POLICIES_IND, ParameterType.Builder.create("CONFG"));
44 newParameter.setDescription( "Set to 'Y' to have the application ingest the default circulation policies upon next startup." );
45 newParameter.setValue("N");
46 parameterService.createParameter(newParameter.build());
47 }
48
49 return policies;
50 }
51 return Collections.emptyList();
52 }
53
54 public void setFileName(String fileName) {
55 this.fileName = fileName;
56 }
57 public void setOleKrmsBuilder(OleKrmsBuilder oleKrmsBuilder) {
58 this.oleKrmsBuilder = oleKrmsBuilder;
59 }
60 public void setParameterService(ParameterService parameterService) {
61 this.parameterService = parameterService;
62 }
63 }