use of org.ehrbase.api.exception.UnexpectedSwitchCaseException 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 org.ehrbase.api.exception.UnexpectedSwitchCaseException in project ehrbase by ehrbase.
the class ContributionServiceHelper method parseAuditDetails.
/**
* Helper that parses the AuditDetails from the contribution input.
* @param content Plain string content
* @param format Format of content
* @return AuditDetails object
*/
public static AuditDetails parseAuditDetails(String content, CompositionFormat format) {
// extract both per standard parts of the content: data block containing versions & audit
Map<String, Object> splitContent = splitContent(content, format);
Object auditContent = splitContent.get("audit");
AuditDetails auditResult;
switch(format) {
case JSON:
try {
String json = JacksonUtil.getObjectMapper().writeValueAsString(auditContent);
auditResult = new CanonicalJson().unmarshal(json, AuditDetails.class);
} catch (JsonProcessingException e) {
throw new IllegalArgumentException("Error while processing given json input: " + e.getMessage());
}
break;
case XML:
default:
throw new UnexpectedSwitchCaseException(format);
}
return auditResult;
}
Aggregations