//Note that we don't have to check the service errors map for nulls, because its taken care
//of in populateErrors below.
serviceErrors = batchResult.getErrors();
}
final ServerResourceContext context = (ServerResourceContext) routingResult.getContext();
final Map<Object, ErrorResponse> errors =
BatchResponseUtil.populateErrors(serviceErrors, routingResult, _errorResponseBuilder);
final Set<Object> mergedKeys = new HashSet<Object>(entities.keySet());
mergedKeys.addAll(statuses.keySet());
mergedKeys.addAll(errors.keySet());
final Map<Object, EntityResponse<RecordTemplate>> results =
new HashMap<Object, EntityResponse<RecordTemplate>>((int) Math.ceil(mergedKeys.size() / 0.75));
for (Object key : mergedKeys)
{
final EntityResponse<RecordTemplate> entityResponse;
final RecordTemplate entityTemplate = entities.get(key);
if (entityTemplate == null)
{
entityResponse = new EntityResponse<RecordTemplate>(null);
}
else
{
@SuppressWarnings("unchecked")
final Class<RecordTemplate> entityClass = (Class<RecordTemplate>) entityTemplate.getClass();
entityResponse = new EntityResponse<RecordTemplate>(entityClass);
final DataMap projectedData =
RestUtils.projectFields(entityTemplate.data(), context.getProjectionMode(), context.getProjectionMask());
CheckedUtil.putWithoutChecking(entityResponse.data(), EntityResponse.ENTITY, projectedData);
}
entityResponse.setStatus(statuses.get(key), SetMode.IGNORE_NULL);
entityResponse.setError(errors.get(key), SetMode.IGNORE_NULL);