1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.coeus.s2sgen.impl.generate;
20
21 import org.apache.xmlbeans.XmlOptions;
22 import org.kuali.coeus.s2sgen.api.core.S2SException;
23 import org.kuali.coeus.s2sgen.api.generate.FormMappingInfo;
24 import org.kuali.coeus.s2sgen.api.generate.FormMappingService;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import org.springframework.beans.BeansException;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.beans.factory.annotation.Qualifier;
30 import org.springframework.context.ApplicationContext;
31 import org.springframework.stereotype.Component;
32
33 import java.util.HashMap;
34 import java.util.Map;
35
36
37
38
39
40
41
42
43 @Component("s2SFormGeneratorRetrievalService")
44 public class S2SFormGeneratorRetrievalServiceImpl implements S2SFormGeneratorRetrievalService {
45 private static final Logger LOG = LoggerFactory.getLogger(S2SFormGeneratorRetrievalServiceImpl.class);
46
47 @Autowired
48 @Qualifier("formMappingService")
49 private FormMappingService formMappingService;
50
51 @Autowired
52 private ApplicationContext applicationContext;
53
54
55
56
57
58
59
60
61
62
63
64 public final S2SFormGenerator getS2SGenerator(String proposalNumber,String namespace) throws S2SException {
65 FormMappingInfo formInfo = formMappingService.getFormInfo(namespace,proposalNumber);
66 S2SFormGenerator formGenerator = (S2SFormGenerator) applicationContext.getBean(formInfo.getGeneratorName());
67
68 if (formGenerator == null) {
69 throw new S2SException("Generator not found with name: " + formInfo.getGeneratorName());
70 }
71
72 if (formGenerator instanceof DynamicNamespace) {
73 ((DynamicNamespace) formGenerator).setNamespace(namespace);
74 }
75
76 return formGenerator;
77 }
78
79
80 public XmlOptions getXmlOptionsPrefixes() {
81 XmlOptions xmlOptions = new XmlOptions();
82 Map<String, String> prefixMap = new HashMap<String, String>();
83 prefixMap.put(
84 "http://apply.grants.gov/system/MetaGrantApplication", "");
85 prefixMap.put(
86 "http://apply.grants.gov/forms/RR_SubawardBudget-V1.0",
87 "RR_SubawardBudget");
88 prefixMap.put(
89 "http://apply.grants.gov/forms/RR_SubawardBudget-V1.1",
90 "RR_SubawardBudget");
91 prefixMap.put(
92 "http://apply.grants.gov/forms/RR_SubawardBudget-V1.2",
93 "RR_SubawardBudget");
94
95
96 xmlOptions.setSaveSuggestedPrefixes(prefixMap);
97 return xmlOptions;
98 }
99
100 public FormMappingService getFormMappingService() {
101 return formMappingService;
102 }
103
104 public void setFormMappingService(FormMappingService formMappingService) {
105 this.formMappingService = formMappingService;
106 }
107
108 public ApplicationContext getApplicationContext() {
109 return applicationContext;
110 }
111
112 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
113 this.applicationContext = applicationContext;
114 }
115 }