Commit 22fc72b1 authored by Adrien's avatar Adrien
Browse files

API : Post validation template (schematron OK)

parent 09b40709
Pipeline #280342 failed with stages
in 4 minutes and 26 seconds
package net.ihe.gazelle.evs.client.adapter.api;
import javax.xml.bind.annotation.*;
import java.util.Arrays;
@XmlRootElement(name = "object")
@XmlAccessorType(XmlAccessType.FIELD)
public class ObjectDto {
@XmlAttribute(name = "originalFileName")
private String originalFileName;
@XmlElement(namespace = "http://evsobjects.gazelle.ihe.net/", name = "content")
private byte[] content;
public String getOriginalFileName() {
return originalFileName;
}
public void setOriginalFileName(String originalFileName) {
this.originalFileName = originalFileName;
}
public byte[] getContent() {
return content;
}
public void setContent(byte[] content) {
this.content = content;
}
@Override
public String toString() {
return "ObjectDto{" +
"originalFileName='" + originalFileName + '\'' +
", content=" + Arrays.toString(content) +
'}';
}
}
package net.ihe.gazelle.evs.client.adapter.api;
import javax.xml.bind.annotation.*;
@XmlRootElement(namespace = "http://evsobjects.gazelle.ihe.net/", name="validation")
@XmlAccessorType(XmlAccessType.FIELD)
public class ValidationDto {
@XmlElement(namespace = "http://evsobjects.gazelle.ihe.net/", name = "validationService")
private ValidationServiceDto validationService;
@XmlElement(namespace = "http://evsobjects.gazelle.ihe.net/", name = "object")
private ObjectDto object;
public ValidationServiceDto getValidationService() {
return validationService;
}
public void setValidationService(ValidationServiceDto validationService) {
this.validationService = validationService;
}
public ObjectDto getObject() {
return object;
}
public void setObject(ObjectDto object) {
this.object = object;
}
@Override
public String toString() {
return "ValidationDto{" +
"validationService=" + validationService +
", object=" + object +
'}';
}
}
package net.ihe.gazelle.evs.client.adapter.api;
import net.ihe.gazelle.evs.client.adapter.factory.ApplicationFactory;
import net.ihe.gazelle.evs.client.adapter.factory.GuiFactory;
import net.ihe.gazelle.evs.client.application.validation.ValidationServiceFacade;
import net.ihe.gazelle.evs.client.application.validation.service.ValidationService;
import net.ihe.gazelle.evs.client.application.validation.service.ValidationServiceFactory;
import net.ihe.gazelle.evs.client.business.serviceconf.AbstractValidationServiceConf;
import net.ihe.gazelle.evs.client.business.serviceconf.ReferencedStandard;
import net.ihe.gazelle.evs.client.business.validation.Validation;
import net.ihe.gazelle.evsclient.common.adapters.config.QueryParam;
import net.ihe.gazelle.evsclient.common.application.CallerMetadataFactory;
import net.ihe.gazelle.evsclient.common.business.object.processed.EVSCallerMetadata;
import net.ihe.gazelle.evsclient.common.business.object.processed.EntryPoint;
import net.ihe.gazelle.evsclient.common.business.object.processed.HandledObject;
import net.ihe.gazelle.evsclient.common.business.object.processed.OwnerMetadata;
import org.jboss.resteasy.annotations.Body;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import javax.ejb.Stateless;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.xml.bind.JAXBElement;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
@Stateless
@Name("validationRestApi")
@Path("/validations")
public class ValidationRestApi {
@In(value = "evsApplicationFactory")
private ApplicationFactory evsApplicationFactory;
@In(value = "evsCommonApplicationFactory")
private net.ihe.gazelle.evsclient.common.adapters.factory.ApplicationFactory evsCommonApplicationFactory;
@In(value = "evsGuiFactory")
private GuiFactory guiFactory;
@POST
@Consumes(MediaType.APPLICATION_XML)
public Response newValidation(ValidationDto validationDto) throws Exception {
HandledObject object = new HandledObject(validationDto.getObject().getContent(), validationDto.getObject().getOriginalFileName());
EVSCallerMetadata caller = evsCommonApplicationFactory.getCallerMetadataFactory().getCallerMetadata(null,null,null, EntryPoint.WS);
OwnerMetadata owner = null; // api key
Validation validation = evsApplicationFactory.getValidationServiceFacade().validate(object, caller, owner, validationDto.getValidationService().getValidator(), validationDto.getValidationService().getName());
setReferencedStandardToValidation(validation);
return Response.created(URI.create("validations/" + validation.getOid())).build();
}
// TODO : Move to appropriate service
private void setReferencedStandardToValidation(Validation validation) throws Exception {
AbstractValidationServiceConf validationServiceConf = evsApplicationFactory.getValidationServiceFacade().getValidationServiceByKeyword(validation.getValidationService().getName());
// TODO : Is associated referenced standard mandatory ?
// STEP 1 : Find referencedstandard associated with validation service
List<ReferencedStandard> associatedReferencedStandardByValidationService = evsApplicationFactory.getServiceConfManager().getReferencedStandardsByValidationServiceId(validationServiceConf.getId());
// STEP 2 : Reduce the number of activated referencedstandard through menus
// TODO : is it really necessary ?
if(associatedReferencedStandardByValidationService.size() == 1){
validation.setReferencedStandard(associatedReferencedStandardByValidationService.get(0).getId());
} else {
// STEP 3 : Reduce the number of referencedstandard by comparing the extension with validator name
List<ReferencedStandard> associatedReferencedStandardReducedByExtension = new ArrayList<>();
for(ReferencedStandard rs : associatedReferencedStandardByValidationService) {
ValidationService validationService = evsApplicationFactory.getValidationServiceFactory().getValidationServiceByValidationServiceConf(validationServiceConf, rs.getValidatorFilter());
if(validationService.getAllValidators().contains(validation.getValidationService().getValidator())){
associatedReferencedStandardReducedByExtension.add(rs);
}
}
// STEP 4 : If only one referencedstandard remains, we add it to the validated object. Otherwise, we add the first one.
if(!associatedReferencedStandardReducedByExtension.isEmpty()){
validation.setReferencedStandard(associatedReferencedStandardByValidationService.get(0).getId());
}
}
}
}
package net.ihe.gazelle.evs.client.adapter.api;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "validationService")
@XmlAccessorType(XmlAccessType.FIELD)
public class ValidationServiceDto {
@XmlAttribute(name = "name")
private String name;
@XmlAttribute(name = "validator")
private String validator;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValidator() {
return validator;
}
public void setValidator(String validator) {
this.validator = validator;
}
@Override
public String toString() {
return "ValidationServiceDto{" +
"name='" + name + '\'' +
", validator='" + validator + '\'' +
'}';
}
}
......@@ -42,7 +42,6 @@ public class MbvValidationServiceClient extends AbstractValidationServiceClient
@Override
public byte[] validate(HandledObject[] objects, String validator) {
if (!super.zipTransport) {
return this.mbValidator
.validate(DatatypeConverter.printBase64Binary(objects[0].getContent()), validator, true)
......
package net.ihe.gazelle.evs.client.api;
import com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext;
import net.ihe.gazelle.evs.client.adapter.api.ObjectDto;
import net.ihe.gazelle.evs.client.adapter.api.ValidationDto;
import net.ihe.gazelle.evs.client.adapter.api.ValidationRestApi;
import net.ihe.gazelle.evs.client.adapter.api.ValidationServiceDto;
import net.ihe.gazelle.evs.client.adapter.factory.ApplicationFactory;
import net.ihe.gazelle.evs.client.application.security.ApiKeyDao;
import net.ihe.gazelle.evs.client.application.validation.ValidationServiceFacade;
import net.ihe.gazelle.evs.client.application.validation.service.ValidationServiceFactory;
import net.ihe.gazelle.evs.client.business.validation.Validation;
import net.ihe.gazelle.evsclient.common.application.CallerMetadataFactory;
import net.ihe.gazelle.evsclient.common.business.object.processed.EVSCallerMetadata;
import net.ihe.gazelle.evsclient.common.business.object.processed.HandledObject;
import net.ihe.gazelle.evsclient.common.business.object.processed.OwnerMetadata;
import net.ihe.gazelle.evsclient.sso.adapters.gui.SsoIdentityImpl;
import net.ihe.gazelle.preferences.PreferenceService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.xml.sax.SAXException;
import static org.mockito.Matchers.*;
import javax.ws.rs.core.Response;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import java.io.*;
import java.nio.charset.StandardCharsets;
import static org.junit.Assert.assertEquals;
@RunWith(PowerMockRunner.class)
@PrepareForTest({net.ihe.gazelle.evsclient.common.adapters.factory.ApplicationFactory.class})
public class ValidationRestApiTest {
@Mock
private net.ihe.gazelle.evsclient.common.adapters.factory.ApplicationFactory evsCommonApplicationFactory;
@Mock
private ApplicationFactory evsApplicationFactory;
@Mock
private ValidationServiceFacade validationServiceFacade;
@InjectMocks
private ValidationRestApi validationRestApi;
private ValidationDto validationDto;
@Before
public void init() throws Exception {
mockEvsCommonApplicationFactory();
mockEvsApplicationFactory();
mockValidationServiceFacade();
}
private void mockValidationServiceFacade() throws Exception {
Validation validation = new Validation(null,null,null);
validation.setOid("1.0.0.0");
Mockito.when(validationServiceFacade.validate((HandledObject) notNull(), (EVSCallerMetadata) notNull(), (OwnerMetadata) isNull(), (String) notNull(), (String) notNull())).thenReturn(validation);
}
private void mockEvsCommonApplicationFactory() {
Mockito.when(evsCommonApplicationFactory.getCallerMetadataFactory()).thenReturn(new CallerMetadataFactory());
}
private void mockEvsApplicationFactory() {
Mockito.when(evsApplicationFactory.getValidationServiceFacade()).thenReturn(validationServiceFacade);
}
private void loadValidationDto(String xmlFilePath) throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance(ValidationDto.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
JAXBElement<ValidationDto> jaxbElement = jaxbUnmarshaller
.unmarshal(new StreamSource(xmlFilePath), ValidationDto.class);
validationDto = jaxbElement.getValue();
}
@Test
public void newValidationTest() throws Exception {
// GIVEN
loadValidationDto("src/test/resources/api/validationAPI.xml");
// WHEN
Response response = validationRestApi.newValidation(validationDto);
//THEN
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<validation xmlns="http://evsobjects.gazelle.ihe.net/">
<validationService name="Model-Based CDA Validator" validator="[ITI-44] Patient Identity Feed HL7V3 - Acknowledgement">
</validationService>
<object xmlns="http://evsobjects.gazelle.ihe.net/" originalFileName="validationAPI.xml">
<content>PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiID8+Cjw/eG1sLXN0eWxlc2hlZXQg
dHlwZT0idGV4dC94c2wiICBocmVmPSIjIj8+Cjx4c2w6c3R5bGVzaGVldCB2ZXJzaW9uPSIxLjAi
IAoJeG1sbnM6eHNsPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L1hTTC9UcmFuc2Zvcm0iCgl4bWxu
czpleHNsPSJodHRwOi8vZXhzbHQub3JnL2NvbW1vbiIgCgl4bWxuczp4c2k9Imh0dHA6Ly93d3cu
dzMub3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlIgoJeG1sbnM6ZGF0YT0idXJuOmFzaXAtc2Fu
dGU6Y2ktc2lzIiAKCXhtbG5zOmM9InVybjpobDctb3JnOnYzIgoJeG1sbnM6bGFiPSJ1cm46b2lk
OjEuMy42LjEuNC4xLjE5Mzc2LjEuMy4yIgoJeG1sbnM6ZHM9Imh0dHA6Ly93d3cudzMub3JnLzIw
MDAvMDkveG1sZHNpZyMiPgoKCTxkYXRhOkNvbnRlbnU+CgkJPGM6Q2xpbmljYWxEb2N1bWVudCB4
bWxuczp4c2k9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlIiB4bWxu
czpsYWI9InVybjpvaWQ6MS4zLjYuMS40LjEuMTkzNzYuMS4zLjIiIGNsYXNzQ29kZT0iRE9DQ0xJ
TiIgbW9vZENvZGU9IkVWTiIgeG1sbnM6Yz0idXJuOmhsNy1vcmc6djMiPgoJCTwvYzpDbGluaWNh
bERvY3VtZW50PgoJPC9kYXRhOkNvbnRlbnU+CjwveHNsOnN0eWxlc2hlZXQ+</content>
</object>
</validation>
......@@ -262,7 +262,7 @@
<context-param>
<param-name>resteasy.jndi.resources</param-name>
<param-value>java:app/EVSClient-ejb/GetValidationInfo,java:app/version/VersionProvider,java:app/gazelle-x-validation-ejb/XValidationInfo,java:app/gazelle-x-validation-ws/AssertionCoverageProvider</param-value>
<param-value>java:app/EVSClient-ejb/GetValidationInfo,java:app/EVSClient-ejb/ValidationRestApi,java:app/version/VersionProvider,java:app/gazelle-x-validation-ejb/XValidationInfo,java:app/gazelle-x-validation-ws/AssertionCoverageProvider</param-value>
<!--If you need to declare more than one resource, separate them by comas -->
</context-param>
<!-- The following lines are required only if you decide not to use the
......
......@@ -74,7 +74,7 @@
<sonar.exclusions>file:**/generated-sources/**</sonar.exclusions>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<gazelle.x.validation.version>1.4.5-SNAPSHOT</gazelle.x.validation.version>
<gazelle.ws.client.version>2.2.11</gazelle.ws.client.version>
<gazelle.ws.client.version>2.2.13-SNAPSHOT</gazelle.ws.client.version>
<gazelle.validator.unit.testing.version>1.0.7</gazelle.validator.unit.testing.version>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment