Skip to content

Commit

Permalink
Web service module and configuration moved over to restructure (#22)
Browse files Browse the repository at this point in the history
Web service module and the configurations for the xml and json rest api
moved over from the module.
  • Loading branch information
littlefieldnick committed Jul 9, 2019
1 parent a50eee7 commit 448d5a1
Show file tree
Hide file tree
Showing 78 changed files with 3,977 additions and 298 deletions.
2 changes: 2 additions & 0 deletions .metadata/src/main/webapp/WEB-INF/faces-config.pageflow
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<pageflow:Pageflow xmlns:pageflow="http://www.sybase.com/suade/pageflow" id="pf15617555294340" configfile="/openhds/src/main/webapp/WEB-INF/faces-config.xml"/>
18 changes: 18 additions & 0 deletions .springBeans
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
<pluginVersion><![CDATA[3.9.2.201712210913-RELEASE]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
<enableImports><![CDATA[false]]></enableImports>
<configs>
</configs>
<autoconfigs>
<config>src/main/webapp/WEB-INF/reporter-servlet.xml</config>
<config>src/main/webapp/WEB-INF/autocomplete-servlet.xml</config>
<config>java:org.openhds.OpenhdsServerApplication</config>
</autoconfigs>
<configSets>
</configSets>
</beansProjectDescription>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,4 @@
</plugins>
</build>

</project>
</project>
3 changes: 3 additions & 0 deletions src/main/java/org/openhds/OpenhdsServerApplication.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.openhds;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableAutoConfiguration
public class OpenhdsServerApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.openhds.config;
package org.openhds.config.modules;

import java.util.Properties;

Expand Down Expand Up @@ -59,7 +59,6 @@

@Configuration
@EnableTransactionManagement
@Import({DomainConfig.class} )
@PropertySource({"classpath:database.properties"})
public class DaoConfig {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.openhds.config;
package org.openhds.config.modules;


import org.openhds.service.JsfService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.openhds.config;
package org.openhds.config.modules;

import java.util.Properties;

Expand All @@ -16,7 +16,7 @@
import org.springframework.oxm.jaxb.Jaxb2Marshaller;

@Configuration
@ComponentScan(basePackages = "org.openhds.domain")
@ComponentScan(basePackages = "org.openhds")
public class DomainConfig {
@Bean
public Jaxb2Marshaller jaxb2Marshaller()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.openhds.config;
package org.openhds.config.modules;

import java.util.HashMap;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.openhds.config;
package org.openhds.config.modules;

import java.io.InputStream;
import java.util.Properties;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/openhds/config/modules/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.openhds.config.modules;

public class SecurityConfig {

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.openhds.config;
package org.openhds.config.modules;

import org.openhds.dao.Dao;
import org.openhds.dao.GenericDao;
Expand All @@ -22,8 +22,8 @@


@Configuration
@Import({DomainConfig.class, DaoConfig.class})
@ComponentScan(basePackages= {"org.openhds.service"})
@Import({DaoConfig.class})
@ComponentScan(basePackages= {"org.openhds"})
public class ServiceConfig {


Expand Down Expand Up @@ -168,11 +168,17 @@ public SocialGroupService socialGroupService(GenericDao dao, IndividualService i
return new SocialGroupServiceImpl(dao, individualService, entityService, sgGenerator);
}

@Bean
public UserLookupService userLookupService(GenericDao dao) {
return new UserLookupServiceImpl(dao);
}

@Bean
public ValueConstraintService valueConstraintService() {
return new ValueConstraintServiceImpl();
}


@Bean
public VisitService visitService() {
return new VisitServiceImpl();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.openhds.config;
package org.openhds.config.modules;

import org.openhds.service.JsfService;
import org.openhds.service.SiteConfigService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.openhds.config;
package org.openhds.config.modules;

import java.util.concurrent.Executor;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.openhds.config;
package org.openhds.config.modules;
import java.beans.IntrospectionException;

import javax.faces.convert.Converter;
Expand Down Expand Up @@ -135,7 +135,7 @@

@SuppressWarnings(value = { "unchecked", "rawtypes" })
@Configuration
@ComponentScan(basePackages= {"org.openhds.web", "org.openhds.converter"})
@ComponentScan(basePackages= {"org.openhds"})
public class WebConfig {
Logger logger = LoggerFactory.getLogger(WebConfig.class);

Expand Down Expand Up @@ -322,7 +322,7 @@ public UserService userService(GenericDao dao) {
return userService;
}

@Bean(value="session")
@Bean
public EntityCrud baseCrud() {
EntityCrudImpl base = new EntityCrudImpl(Object.class);
base.setProperties(AppContextAware.getContext().getBean(SitePropertiesService.class));
Expand Down Expand Up @@ -491,7 +491,7 @@ public FacesNavigation faceNavigation() {
}

@Bean
public NavigationMenuBean navigationMenuBean() {
public NavigationMenuBean navController() {
return new NavigationMenuBean();
}

Expand Down Expand Up @@ -768,7 +768,7 @@ public EntityCrud<Whitelist, String> whitelistCrud() {
}

//Beans
@Bean(value="session")
@Bean
public UpdateBean updateBean() {
UpdateBean updateBean = new UpdateBean();
updateBean.setResidencyService((ResidencyService) AppContextAware.getContext().getBean("residencyService"));
Expand All @@ -786,20 +786,22 @@ public TaskBean taskBean(TaskExecutor executor, AsyncTaskService taskService) {
return taskBean;
}

@Bean(value="session")
public BaselineFlowBean baselineFlowBean() {
@Bean
public BaselineFlowBean baselineFlowBean(ResidencyService residencyService, SitePropertiesService siteProperties,
GenericDao genericDao, WebFlowService webFlowService, BaselineService baselineService,
IndividualService individualService, Generator<SocialGroup> socialGroupGenerator) {
BaselineFlowBean baselineFlow = new BaselineFlowBean();
baselineFlow.setResidencyService((ResidencyService) AppContextAware.getContext().getBean("residencyService"));
baselineFlow.setProperties((SitePropertiesService) AppContextAware.getContext().getBean("siteProperties"));
baselineFlow.setGenericDao((GenericDao) AppContextAware.getContext().getBean("genericDao"));
baselineFlow.setWebFlowService((WebFlowService) AppContextAware.getContext().getBean("webFlowService"));
baselineFlow.setBaselineService((BaselineService) AppContextAware.getContext().getBean("baselineService"));
baselineFlow.setIndividualService((IndividualService) AppContextAware.getContext().getBean("individualService"));
baselineFlow.setSocialGroupGenerator((Generator<SocialGroup>) AppContextAware.getContext().getBean("socialGroupGenerator"));
baselineFlow.setResidencyService(residencyService);
baselineFlow.setProperties(siteProperties);
baselineFlow.setGenericDao(genericDao);
baselineFlow.setWebFlowService(webFlowService);
baselineFlow.setBaselineService(baselineService);
baselineFlow.setIndividualService(individualService);
baselineFlow.setSocialGroupGenerator(socialGroupGenerator);
return baselineFlow;
}

@Bean(value="session")
@Bean
public IndividualHistoryBean individualHistoryBean() {
IndividualHistoryBean indHistBean = new IndividualHistoryBean();
indHistBean.setGenericDao((GenericDao) AppContextAware.getContext().getBean("genericDao"));
Expand All @@ -817,7 +819,7 @@ public IndividualHistoryBean individualHistoryBean() {
return indHistBean;
}

@Bean(value="session")
@Bean
public ModifyHOHBean modifyHOHBean() {
ModifyHOHBean modifyHoh = new ModifyHOHBean();
modifyHoh.setGenericDao((GenericDao) AppContextAware.getContext().getBean("genericDao"));
Expand All @@ -828,7 +830,7 @@ public ModifyHOHBean modifyHOHBean() {
return modifyHoh;
}

@Bean(value="session")
@Bean
public DeathHOHBean deathHOHBean() {
DeathHOHBean deathHoh = new DeathHOHBean();
deathHoh.setGenericDao((GenericDao) AppContextAware.getContext().getBean("genericDao"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package org.openhds.config.webapp;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.converter.xml.MarshallingHttpMessageConverter;
import org.springframework.orm.hibernate5.support.OpenSessionInViewFilter;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;

public class JsonWebServiceInitializer extends WebMvcConfigurationSupport{

@Autowired
private ApplicationContext context;

@Bean
public ServletRegistrationBean<DispatcherServlet> jsonRestApi() {
AnnotationConfigWebApplicationContext contextApi = new AnnotationConfigWebApplicationContext();
contextApi.scan("org.openhds.webservice.resources.json");
contextApi.setParent(context);

DispatcherServlet dispatcherServlet = new DispatcherServlet();
dispatcherServlet.setApplicationContext(contextApi);

ServletRegistrationBean<DispatcherServlet> servletRegistrationBean =
new ServletRegistrationBean<DispatcherServlet>(dispatcherServlet, "/api2/rest/*");
servletRegistrationBean.setName("webServices2");
return servletRegistrationBean;
}

@Bean
FilterRegistrationBean transactionFilterRegistration() {
FilterRegistrationBean reg = new FilterRegistrationBean();
reg.setFilter(new OpenSessionInViewFilter());
reg.addUrlPatterns("/api2/rest/*");
return reg;
}

@Bean
public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
RequestMappingHandlerAdapter adapter = super.requestMappingHandlerAdapter();
adapter.getMessageConverters().add(marshallingHttpMessageConverter());
adapter.getMessageConverters().add(mappingJackson2HttpMessageConverter());
return adapter;
}

@Bean
public MarshallingHttpMessageConverter marshallingHttpMessageConverter() {
MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter();;
converter.setMarshaller(new Jaxb2Marshaller());
converter.setUnmarshaller(new Jaxb2Marshaller());

return converter;
}

@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
return new MappingJackson2HttpMessageConverter();
}

@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false).favorParameter(true).parameterName("mediaType")
.ignoreAcceptHeader(true).useRegisteredExtensionsOnly(false)
.defaultContentType(MediaType.APPLICATION_JSON)
.mediaType("xml", MediaType.APPLICATION_XML)
.mediaType("json", MediaType.APPLICATION_JSON);
}


@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}

private List<MediaType> getSupportedMediaTypes() {
final List<MediaType> list = new ArrayList<MediaType>();
list.add(MediaType.APPLICATION_JSON);
list.add(MediaType.APPLICATION_XML);

return list;
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.openhds.config.webapp;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.hibernate5.support.OpenSessionInViewFilter;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class XmlWebServiceInitializer extends WebMvcConfigurationSupport{

@Autowired
private ApplicationContext context;

@Bean
public ServletRegistrationBean<DispatcherServlet> xmlRestApi() {
AnnotationConfigWebApplicationContext contextApi = new AnnotationConfigWebApplicationContext();
contextApi.scan("org.openhds.webservice.resources.xml");
contextApi.setParent(context);

DispatcherServlet dispatcherServlet = new DispatcherServlet();
dispatcherServlet.setApplicationContext(contextApi);

ServletRegistrationBean<DispatcherServlet> servletRegistrationBean =
new ServletRegistrationBean<DispatcherServlet>(dispatcherServlet, "/api/rest/*");
servletRegistrationBean.setName("webServices");
return servletRegistrationBean;
}

@Bean
FilterRegistrationBean transactionFilterRegistration() {
FilterRegistrationBean reg = new FilterRegistrationBean();
reg.setFilter(new OpenSessionInViewFilter());
reg.addUrlPatterns("/api/rest/*");
return reg;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.openhds.domain.wrapper;
package org.openhds.domain.wrappers;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.openhds.domain.wrapper;
package org.openhds.domain.wrappers;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.openhds.domain.wrapper;
package org.openhds.domain.wrappers;

import java.util.List;

Expand Down
Loading

0 comments on commit 448d5a1

Please sign in to comment.