use of com.nedap.archie.rm.RMObject in project ehrbase by ehrbase.
the class ContributionServiceHelperTest method unmarshalMapContentToRmObjectCheck.
// helper method with the actual logical tests
private void unmarshalMapContentToRmObjectCheck(List<Version> versions, CompositionFormat format, ContributionServiceImp.SupportedClasses classType) {
for (Version version : versions) {
RMObject versionRmObject = ContributionServiceHelper.unmarshalMapContentToRmObject((LinkedHashMap) version.getData(), format);
assertNotNull(ContributionServiceImp.SupportedClasses.valueOf(versionRmObject.getClass().getSimpleName().toUpperCase()));
assertEquals(classType, ContributionServiceImp.SupportedClasses.valueOf(versionRmObject.getClass().getSimpleName().toUpperCase()));
}
}
use of com.nedap.archie.rm.RMObject in project ehrbase by ehrbase.
the class ContributionServiceHelper method extractVersionObjects.
/**
* returns a list of RM VERSIONs extracted from given serialization
* @param listVersions List of still serialized version objects
* @param format Format of the serialization
* @return List of deserialized version objects
* @throws IllegalArgumentException when processing of given input fails
*/
public static List<Version> extractVersionObjects(ArrayList listVersions, CompositionFormat format) {
List<Version> versionsList = new LinkedList<>();
switch(format) {
case JSON:
for (Object version : listVersions) {
try {
// TODO CONTRIBUTION: round trip ((string->)object->string->object) really necessary?
String json = JacksonUtil.getObjectMapper().writeValueAsString(version);
RMObject versionRmObject = new CanonicalJson().unmarshal(json, RMObject.class);
if (versionRmObject instanceof Version) {
versionsList.add((Version) versionRmObject);
} else {
throw new IllegalArgumentException("Wrong input. At least one VERSION in this contribution is invalid.");
}
} catch (JsonProcessingException e) {
throw new IllegalArgumentException("Error while processing given json input: " + e.getMessage());
}
}
break;
case XML:
default:
throw new UnexpectedSwitchCaseException(format);
}
return versionsList;
}
use of com.nedap.archie.rm.RMObject in project ehrbase by ehrbase.
the class ContributionServiceImp method commitContribution.
@Override
public UUID commitContribution(UUID ehrId, String content, CompositionFormat format) {
// pre-step: check for valid ehrId
if (!ehrService.hasEhr(ehrId)) {
throw new ObjectNotFoundException("ehr", "No EHR found with given ID: " + ehrId.toString());
}
// create new empty/standard-value contribution - will be updated later with full details
I_ContributionAccess contributionAccess = I_ContributionAccess.getInstance(this.getDataAccess(), ehrId);
// parse and set audit information from input
AuditDetails audit = ContributionServiceHelper.parseAuditDetails(content, format);
contributionAccess.setAuditDetailsValues(audit);
// commits with all default values (but without audit handling as it is done above)
UUID contributionId = contributionAccess.commit(null, null, null);
List<Version> versions = ContributionServiceHelper.parseVersions(content, format);
if (versions.isEmpty())
throw new InvalidApiParameterException("Invalid Contribution, must have at least one Version object.");
// go through those RM objects and execute the action of it (as listed in its audit) and connect it to new contribution
for (Version version : versions) {
Object versionData = version.getData();
if (versionData != null) {
// the version contains the optional "data" attribute (i.e. payload), therefore has specific object type (composition, folder,...)
RMObject versionRmObject;
if (versionData instanceof LinkedHashMap) {
versionRmObject = ContributionServiceHelper.unmarshalMapContentToRmObject((LinkedHashMap) versionData, format);
} else {
throw new IllegalArgumentException("Contribution input can't be processed");
}
// switch to allow acting depending on exact type
SupportedClasses versionClass;
try {
versionClass = SupportedClasses.valueOf(versionRmObject.getClass().getSimpleName().toUpperCase());
} catch (Exception e) {
throw new InvalidApiParameterException("Invalid version object in contribution. " + versionRmObject.getClass().getSimpleName().toUpperCase() + " not supported.");
}
switch(versionClass) {
case COMPOSITION:
try {
processCompositionVersion(ehrId, contributionId, version, (Composition) versionRmObject);
} catch (UnprocessableEntityException e) {
throw new ValidationException(e.getMessage());
}
break;
case EHRSTATUS:
processEhrStatusVersion(ehrId, contributionId, version, (EhrStatus) versionRmObject);
break;
case FOLDER:
processFolderVersion(ehrId, contributionId, version, (Folder) versionRmObject);
break;
default:
throw new UnexpectedSwitchCaseException(versionClass);
}
} else {
// version doesn't contain "data", so it is only a metadata one to, for instance, delete a specific object via ID regardless of type
processMetadataVersion(ehrId, contributionId, version);
}
}
return contributionId;
}
use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.
the class RoundTripTest method checkTestCase.
public void checkTestCase(TestCase testCase, SoftAssertions softly) throws IOException {
String value = IOUtils.toString(testCase.simSDTJson.getStream(), UTF_8);
RMDataFormat flatJson = new FlatJasonProvider(new TestDataTemplateProvider()).buildFlatJson(FlatFormat.SIM_SDT, testCase.templateId);
Composition composition = flatJson.unmarshal(value);
Flattener flattener = new Flattener(new TestDataTemplateProvider());
Object flatten = flattener.flatten(composition, testCase.dtoClass);
Unflattener unflattener = new Unflattener(new TestDataTemplateProvider());
RMObject actual = unflattener.unflatten(flatten);
String actualFlat = flatJson.marshal(actual);
List<String> errors = compere(actualFlat, value);
softly.assertThat(errors).filteredOn(s -> s.startsWith("Missing")).as("Test Case %s", testCase.id).containsExactlyInAnyOrder(testCase.missing);
softly.assertThat(errors).filteredOn(s -> s.startsWith("Extra")).as("Test Case %s", testCase.id).containsExactlyInAnyOrder(testCase.extra);
}
use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.
the class NormalizerTest method normalize.
@Test
public void normalize() throws IOException, XmlException {
OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.ALL_TYPES.getStream()).getTemplate();
OptSkeletonBuilder skeletonBuilder = new OptSkeletonBuilder();
RMObject rmObject = skeletonBuilder.generate(template);
Normalizer cut = new Normalizer();
Composition actual = (Composition) cut.normalize(rmObject);
assertThat(actual).isNotNull();
assertThat(actual.getContent()).size().isEqualTo(0);
}
Aggregations