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