Skip to content

Commit

Permalink
Implemented setup wizard.
Browse files Browse the repository at this point in the history
  • Loading branch information
volsch committed Nov 8, 2018
1 parent a356f0a commit c9ce995
Show file tree
Hide file tree
Showing 75 changed files with 2,460 additions and 234 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
LICENSE text
*.MF text
*.csv text
*.html text
*.java text
*.json text
*.md text
Expand All @@ -20,6 +21,7 @@ LICENSE text

# Denote all files that are truly binary and should not be modified.
*.pdf binary
*.ico binary

# Denote all files that must use UNIX style line endings.
*.sh text eol=lf
Expand Down
10 changes: 10 additions & 0 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.dhis2.fhir.adapter</groupId>
<artifactId>dhis2-fhir-adapter-fhir</artifactId>
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/org/dhis2/fhir/adapter/DemoClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static void main( String[] args )
Patient child = new Patient();
child.setIdElement( IdType.newRandomUuid() );
child.addIdentifier()
.setSystem( "http://example.sl/national-patient-id" )
.setSystem( "http://example.sl/patients" )
.setValue( childNationalId );
child.addName()
.setFamily( "West" )
Expand Down Expand Up @@ -147,7 +147,7 @@ public static void main( String[] args )
Patient mother = new Patient();
mother.setIdElement( IdType.newRandomUuid() );
mother.addIdentifier()
.setSystem( "http://example.sl/national-patient-id" )
.setSystem( "http://example.sl/patients" )
.setValue( motherNationalId );
mother.addName()
.setFamily( "West" )
Expand Down Expand Up @@ -358,13 +358,13 @@ public static void main( String[] args )
.setFullUrl( child.getId() )
.getRequest()
.setMethod( Bundle.HTTPVerb.PUT )
.setUrl( "Patient?identifier=http://example.sl/national-patient-id|" + childNationalId );
.setUrl( "Patient?identifier=http://example.sl/patients|" + childNationalId );
bundle.addEntry()
.setResource( mother )
.setFullUrl( mother.getId() )
.getRequest()
.setMethod( Bundle.HTTPVerb.PUT )
.setUrl( "Patient?identifier=http://example.sl/national-patient-id|" + motherNationalId );
.setUrl( "Patient?identifier=http://example.sl/patients|" + motherNationalId );
bundle.addEntry()
.setResource( location )
.setFullUrl( location.getId() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.dhis2.fhir.adapter.dhis.security.SecurityConfig;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
Expand Down Expand Up @@ -75,6 +76,7 @@ protected void configure( @Nonnull HttpSecurity http ) throws Exception
http
.authorizeRequests()
.antMatchers( "/remote-fhir-rest-hook/**" ).permitAll()
.antMatchers( HttpMethod.GET, "/setup" ).permitAll()
.anyRequest().authenticated()
.and()
.httpBasic().realmName( DHIS_BASIC_REALM );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.dhis2.fhir.adapter.setup;

/*
* 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.
*/

import javax.annotation.Nonnull;
import java.io.Serializable;

/**
* The mapping between FHIR and DHIS2 code.
*
* @author volsch
*/
public class FhirDhisCodeMapping implements Serializable
{
private static final long serialVersionUID = 1954015049643872444L;

private final String fhirCode;

private final String dhisCode;

public FhirDhisCodeMapping( @Nonnull String fhirCode, @Nonnull String dhisCode )
{
this.fhirCode = fhirCode;
this.dhisCode = dhisCode;
}

@Nonnull
public String getFhirCode()
{
return fhirCode;
}

@Nonnull
public String getDhisCode()
{
return dhisCode;
}
}
53 changes: 53 additions & 0 deletions app/src/main/java/org/dhis2/fhir/adapter/setup/HttpUrl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.dhis2.fhir.adapter.setup;

/*
* 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.
*/

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Validation that a URL is a valid HTTP/HTTPS URL.
*
* @author volsch
*/
@Constraint( validatedBy = HttpUrlValidator.class )
@Target( { ElementType.FIELD } )
@Retention( RetentionPolicy.RUNTIME )
public @interface HttpUrl
{
String message() default "Not a valid HTTP/HTTPS URL.";

Class<?>[] groups() default {};

Class<? extends Payload>[] payload() default {};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.dhis2.fhir.adapter.setup;

/*
* 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.
*/

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.net.MalformedURLException;
import java.net.URL;

/**
* Validator that checks that a URL is a valid HTTP/HTTPS URL.
*
* @author volsch
*/
public class HttpUrlValidator implements ConstraintValidator<HttpUrl, String>
{
@Override
public boolean isValid( String value, ConstraintValidatorContext context )
{
if ( value == null )
{
return true;
}

final String protocol;
try
{
protocol = new URL( value ).getProtocol();
}
catch ( MalformedURLException e )
{
context.buildConstraintViolationWithTemplate( "Not a valid URL." );
return false;
}

if ( !"http".equals( protocol ) && !"https".equals( protocol ) )
{
context.buildConstraintViolationWithTemplate( "URL must use protocol HTTP or HTTPS." );
return false;
}

return true;
}
}
Loading

0 comments on commit c9ce995

Please sign in to comment.