use of org.springframework.http.MediaType.APPLICATION_JSON_VALUE in project dhis2-core by dhis2.
the class EnrollmentController method postEnrollmentJson.
// -------------------------------------------------------------------------
// CREATE
// -------------------------------------------------------------------------
@PostMapping(value = "", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage postEnrollmentJson(@RequestParam(defaultValue = "CREATE_AND_UPDATE") ImportStrategy strategy, ImportOptions importOptions, HttpServletRequest request) throws IOException {
importOptions.setStrategy(strategy);
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
if (!importOptions.isAsync()) {
ImportSummaries importSummaries = enrollmentService.addEnrollmentsJson(inputStream, importOptions);
importSummaries.setImportOptions(importOptions);
importSummaries.getImportSummaries().stream().filter(importSummary -> !importOptions.isDryRun() && !importSummary.getStatus().equals(ImportStatus.ERROR) && !importOptions.getImportStrategy().isDelete() && (!importOptions.getImportStrategy().isSync() || importSummary.getImportCount().getDeleted() == 0)).forEach(importSummary -> importSummary.setHref(ContextUtils.getRootPath(request) + RESOURCE_PATH + "/" + importSummary.getReference()));
if (importSummaries.getImportSummaries().size() == 1) {
ImportSummary importSummary = importSummaries.getImportSummaries().get(0);
importSummary.setImportOptions(importOptions);
if (!importSummary.getStatus().equals(ImportStatus.ERROR)) {
importSummaries(importSummaries).setHttpStatus(HttpStatus.CREATED).setLocation("/api/" + "enrollments" + "/" + importSummary.getReference());
}
}
return importSummaries(importSummaries).setHttpStatus(HttpStatus.CREATED);
}
return startAsyncImport(importOptions, enrollmentService.getEnrollmentsJson(inputStream));
}
use of org.springframework.http.MediaType.APPLICATION_JSON_VALUE in project molgenis by molgenis.
the class RestControllerV2 method createEntities.
/**
* Try to create multiple entities in one transaction. If one fails all fails.
*
* @param entityTypeId name of the entity where the entities are going to be added.
* @param request EntityCollectionCreateRequestV2
* @param response HttpServletResponse
* @return EntityCollectionCreateResponseBodyV2
*/
@Transactional
@PostMapping(value = "/{entityTypeId}", produces = APPLICATION_JSON_VALUE)
public EntityCollectionBatchCreateResponseBodyV2 createEntities(@PathVariable("entityTypeId") String entityTypeId, @RequestBody @Valid EntityCollectionBatchRequestV2 request, HttpServletResponse response) throws Exception {
final EntityType meta = dataService.getEntityType(entityTypeId);
if (meta == null) {
throw createUnknownEntityException(entityTypeId);
}
try {
final List<Entity> entities = request.getEntities().stream().map(e -> this.restService.toEntity(meta, e)).collect(toList());
final EntityCollectionBatchCreateResponseBodyV2 responseBody = new EntityCollectionBatchCreateResponseBodyV2();
final List<String> ids = new ArrayList<>();
// Add all entities
if (ATTRIBUTE_META_DATA.equals(entityTypeId)) {
entities.stream().map(attribute -> (Attribute) attribute).forEach(attribute -> dataService.getMeta().addAttribute(attribute));
} else {
this.dataService.add(entityTypeId, entities.stream());
}
entities.forEach(entity -> {
restService.updateMappedByEntities(entity);
String id = entity.getIdValue().toString();
ids.add(id);
responseBody.getResources().add(new AutoValue_ResourcesResponseV2(Href.concatEntityHref(RestControllerV2.BASE_URI, entityTypeId, id)));
});
responseBody.setLocation(Href.concatEntityCollectionHref(RestControllerV2.BASE_URI, entityTypeId, meta.getIdAttribute().getName(), ids));
response.setStatus(HttpServletResponse.SC_CREATED);
return responseBody;
} catch (Exception e) {
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
throw e;
}
}
use of org.springframework.http.MediaType.APPLICATION_JSON_VALUE in project data-prep by Talend.
the class DataSetAPI method listSummary.
@RequestMapping(value = "/api/datasets/summary", method = GET, produces = APPLICATION_JSON_VALUE)
@ApiOperation(value = "List data sets summary.", produces = APPLICATION_JSON_VALUE, notes = "Returns a list of data sets summary the user can use.")
@Timed
public Callable<Stream<EnrichedDataSetMetadata>> listSummary(@ApiParam(value = "Sort key (by name or date), defaults to 'date'.") @RequestParam(defaultValue = "creationDate") Sort sort, @ApiParam(value = "Order for sort key (desc or asc), defaults to 'desc'.") @RequestParam(defaultValue = "desc") Order order, @ApiParam(value = "Filter on name containing the specified name") @RequestParam(defaultValue = "") String name, @ApiParam(value = "Filter on certified data sets") @RequestParam(defaultValue = "false") boolean certified, @ApiParam(value = "Filter on favorite data sets") @RequestParam(defaultValue = "false") boolean favorite, @ApiParam(value = "Filter on recent data sets") @RequestParam(defaultValue = "false") boolean limit) {
if (LOG.isDebugEnabled()) {
LOG.debug("Listing datasets summary (pool: {})...", getConnectionStats());
}
return () -> {
GenericCommand<InputStream> listDataSets = getCommand(DataSetList.class, sort, order, name, certified, favorite, limit);
return //
Flux.from(CommandHelper.toPublisher(UserDataSetMetadata.class, mapper, listDataSets)).map(m -> {
LOG.debug("found dataset {} in the summary list" + m.getName());
// Add the related preparations list to the given dataset metadata.
final PreparationSearchByDataSetId getPreparations = getCommand(PreparationSearchByDataSetId.class, m.getId());
return //
Flux.from(CommandHelper.toPublisher(Preparation.class, mapper, getPreparations)).collectList().map(preparations -> {
final List<Preparation> list = //
preparations.stream().filter(//
p -> p.getSteps() != null).collect(Collectors.toList());
return new EnrichedDataSetMetadata(m, list);
}).block();
}).toStream(1);
};
}
use of org.springframework.http.MediaType.APPLICATION_JSON_VALUE in project dhis2-core by dhis2.
the class TrackerImportController method getJobReport.
@GetMapping(value = "/jobs/{uid}/report", produces = APPLICATION_JSON_VALUE)
public TrackerImportReport getJobReport(@PathVariable String uid, @RequestParam(defaultValue = "errors", required = false) String reportMode, HttpServletResponse response) throws HttpStatusCodeException, NotFoundException {
TrackerBundleReportMode trackerBundleReportMode = TrackerBundleReportMode.getTrackerBundleReportMode(reportMode);
setNoStore(response);
return Optional.ofNullable(notifier.getJobSummaryByJobId(JobType.TRACKER_IMPORT_JOB, uid)).map(report -> trackerImportService.buildImportReport((TrackerImportReport) report, trackerBundleReportMode)).orElseThrow(() -> NotFoundException.notFoundUid(uid));
}
Aggregations