001    package org.kuali.ole.patron;
002    
003    import org.kuali.ole.ingest.FileUtil;
004    import org.kuali.ole.patron.bo.OlePatronDocument;
005    import org.kuali.ole.patron.bo.OlePatronIngestSummaryRecord;
006    import org.kuali.ole.service.OlePatronConverterService;
007    
008    import java.io.File;
009    import java.net.URL;
010    import java.util.List;
011    
012    /**
013     * Created with IntelliJ IDEA.
014     * User: peris
015     * Date: 10/31/12
016     * Time: 11:06 AM
017     * To change this template use File | Settings | File Templates.
018     */
019    public class LoadDefaultPatronsBean {
020        private String fileName;
021        private OlePatronConverterService olePatronIngestService;
022    
023        public List<OlePatronDocument> loadDefaultPatrons() throws Exception {
024            URL resource = getClass().getResource(fileName);
025            File file = new File(resource.toURI());
026            String fileContent = new FileUtil().readFile(file);
027            List<OlePatronDocument> olePatronDocuments =
028                    olePatronIngestService.persistPatronFromFileContent(fileContent,
029                            true,
030                            file.getName(),
031                            new OlePatronIngestSummaryRecord());
032            return olePatronDocuments;
033        }
034    
035        public String getFileName() {
036            return fileName;
037        }
038    
039        public void setFileName(String fileName) {
040            this.fileName = fileName;
041        }
042    
043        public OlePatronConverterService getOlePatronIngestService() {
044            return olePatronIngestService;
045        }
046    
047        public void setOlePatronIngestService(OlePatronConverterService olePatronIngestService) {
048            this.olePatronIngestService = olePatronIngestService;
049        }
050    }