Skip to content

Commit

Permalink
Adjusted default configuration and bug fixing.
Browse files Browse the repository at this point in the history
  • Loading branch information
volsch committed Nov 19, 2018
1 parent 6e067a4 commit 11084f9
Show file tree
Hide file tree
Showing 11 changed files with 587 additions and 246 deletions.
2 changes: 1 addition & 1 deletion app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<parent>
<groupId>org.dhis2.fhir.adapter</groupId>
<artifactId>dhis2-fhir-adapter</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

Expand Down
39 changes: 39 additions & 0 deletions app/src/main/java/org/dhis2/fhir/adapter/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import org.apache.commons.lang3.StringUtils;
import org.dhis2.fhir.adapter.spring.YamlPropertySourceFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand All @@ -39,6 +40,8 @@
import org.springframework.context.annotation.PropertySource;
import org.springframework.jms.annotation.EnableJms;

import java.io.File;

/**
* Main application entry point.
*
Expand All @@ -51,14 +54,50 @@
@PropertySource( value = { "classpath:default-application.yml", "file:///${dhis2.home}/services/fhir-adapter/application.yml" }, factory = YamlPropertySourceFactory.class )
public class App extends SpringBootServletInitializer
{
public static final String DHIS2_HOME_ENV = "DHIS2_HOME";

public static final String DHIS2_HOME_PROP = "dhis2.home";

@Override
protected SpringApplicationBuilder configure( SpringApplicationBuilder application )
{
checkEnv();
return application.sources( App.class );
}

public static void main( String[] args )
{
try
{
checkEnv();
}
catch ( AppException e )
{
System.err.println( e.getMessage() );
System.exit( 10 );
}

SpringApplication.run( App.class, args );
}

protected static void checkEnv() throws AppException
{
String home = System.getenv( DHIS2_HOME_ENV );
final String alternativeHome = System.getProperty( DHIS2_HOME_PROP );
if ( alternativeHome != null )
{
home = alternativeHome;
}

if ( StringUtils.isBlank( home ) )
{
throw new AppException( "DHIS2 home environment variable " + DHIS2_HOME_ENV + " has not been set." );
}

final File configFile = new File( home + "/services/fhir-adapter/application.yml" );
if ( !configFile.canRead() )
{
throw new AppException( "Adapter configuration file does not exist or cannot be read: " + configFile.getAbsolutePath() );
}
}
}
44 changes: 44 additions & 0 deletions app/src/main/java/org/dhis2/fhir/adapter/AppException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.dhis2.fhir.adapter;

/*
* Copyright (c) 2004-2018, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/**
* Thrown if the application cannot be started because of an environment problem.
*
* @author volsch
*/
public class AppException extends RuntimeException
{
private static final long serialVersionUID = 8600075604012344988L;

public AppException( String message )
{
super( message );
}
}
Loading

0 comments on commit 11084f9

Please sign in to comment.