private FileData<PatientVisitDTO> doPut(FileData<PatientVisitDTO> entity) throws RestLoaderException { Response response = hbRestClient.doPut(entity.getEntity()); try { switch (response.getStatus()) { case 200: PayloadStatus result = response.readEntity(PayloadStatus.class); String id = HBUtil.getIdFromURI(result.getIdentifier()); entity.setSuccess(true); entity.setResult(DataLoaderConstants.SUCCESS_MSG + id); break; case 400: RestApiError badRequestError = response.readEntity(RestApiError.class); entity.setSuccess(false); entity.setResult(DataLoaderConstants.ERROR_MSG + badRequestError.toString()); break; case 404: RestApiError notFoundError = response.readEntity(RestApiError.class); entity.setSuccess(false); entity.setResult(DataLoaderConstants.ERROR_MSG + notFoundError.toString()); break; default: } } catch (MessageBodyProviderNotFoundException e) { log.warning(e.getMessage()); entity.setSuccess(false); entity.setResult(DataLoaderConstants.UNKNOWN_ERROR_MSG); } return entity; }
public void addQueryParam(String key, String value) { hbRestClient.addQueryParam(key, value); }
public void setResource(String resource) { hbRestClient.setResource(resource); }
private List<FileData<PatientVisitDTO>> doPost( Map<String, List<FileData<PatientVisitDTO>>> entitiesMap) throws RestLoaderException { List<FileData<PatientVisitDTO>> allPostedEntities = new ArrayList<>(); entitiesMap.forEach( (k, v) -> { List<FileData<PatientVisitDTO>> entities = v; int listSize = 0; if (entities != null) { listSize = entities.size(); } int fromIndex = 0; int toIndex = 0; while (listSize > 0) { if (listSize >= BATCH_SIZE) { toIndex += BATCH_SIZE; } else { toIndex += listSize; } List<FileData<PatientVisitDTO>> patientVisitBatch = entities.subList(fromIndex, toIndex); List<PatientVisitDTO> patientVisits = patientVisitBatch .stream() .map(entity -> extractPatientVisitDTO(entity)) .collect(Collectors.toCollection(ArrayList::new)); try { addPathParam( env.getProperty(DataLoaderConstants.PATIENT_ID_KEY), patientVisits.get(0).getPatientNumber()); Response response = hbRestClient.doPost(patientVisits); switch (response.getStatus()) { case 201: GenericType<List<PayloadStatus>> type = new GenericType<List<PayloadStatus>>() {}; List<PayloadStatus> result = response.readEntity(type); resultExtractionService.processSuccessURI(patientVisitBatch, result); break; case 207: MultiStatusError mse = response.readEntity(MultiStatusError.class); resultExtractionService.processMultiStatusResult(patientVisitBatch, mse); break; case 400: RestApiError rae = response.readEntity(RestApiError.class); resultExtractionService.extractBadRequestResult(patientVisitBatch, rae); break; default: } } catch (MessageBodyProviderNotFoundException e) { log.warning(e.getMessage()); patientVisitBatch.forEach( entity -> { entity.setSuccess(false); entity.setResult("Error : Reason Unknown"); }); } catch (RestLoaderException e) { log.warning(e.getMessage()); } allPostedEntities.addAll(patientVisitBatch); listSize = listSize - BATCH_SIZE; fromIndex = toIndex; } }); return allPostedEntities; }