use of com.nedap.archie.rm.changecontrol.Version in project ehrbase by ehrbase.
the class ContributionServiceHelperTest method extractVersionObjects.
@Test
public void extractVersionObjects() {
// pre-step: call splitContent with first test data input (assumed to be correct as tested separately)
Map<String, Object> splitContent = extractVersionObjectsPreStep(ContributionTestDataCanonicalJson.ONE_ENTRY_COMPOSITION.getStream(), CompositionFormat.JSON);
// actual test
Object versionsContent = splitContent.get("versions");
List<Version> versions = ContributionServiceHelper.extractVersionObjects((ArrayList) versionsContent, CompositionFormat.JSON);
extractVersionObjectsCheck(versions, 1);
// pre-step: call splitContent with second test data input (assumed to be correct as tested separately)
Map<String, Object> splitContent2 = extractVersionObjectsPreStep(ContributionTestDataCanonicalJson.TWO_ENTRIES_COMPOSITION.getStream(), CompositionFormat.JSON);
// actual test
Object versionsContent2 = splitContent2.get("versions");
List<Version> versions2 = ContributionServiceHelper.extractVersionObjects((ArrayList) versionsContent2, CompositionFormat.JSON);
extractVersionObjectsCheck(versions2, 2);
// TODO add more test data and XML when ready
}
use of com.nedap.archie.rm.changecontrol.Version in project ehrbase by ehrbase.
the class ContributionServiceHelperTest method extractVersionObjectsCheck.
// helper method with the actual logical tests
private void extractVersionObjectsCheck(List<Version> versions, int numVersions) {
assertEquals(numVersions, versions.size());
for (Version version : versions) {
assertNotNull(version.getData());
assertTrue(version.getData() instanceof LinkedHashMap);
}
}
use of com.nedap.archie.rm.changecontrol.Version in project ehrbase by ehrbase.
the class ContributionServiceImp method getListOfTemplates.
@Override
public Set<String> getListOfTemplates(String contribution, CompositionFormat format) {
List<Version> versions = ContributionServiceHelper.parseVersions(contribution, format);
Set<String> templates = new HashSet<>();
for (Version version : versions) {
Object versionData = version.getData();
// the version contains the optional "data" attribute (i.e. payload), therefore has specific object type (composition, folder,...)
if (versionData != null) {
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:
TemplateId templateId = ((Composition) versionRmObject).getArchetypeDetails().getTemplateId();
if (templateId != null) {
templates.add(templateId.getValue());
}
break;
// TODO: might add later, if other_details support templated content
case EHRSTATUS:
case FOLDER:
default:
throw new IllegalArgumentException("Contribution input contains invalid version class");
}
}
}
return templates;
}
Aggregations