use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.
the class MetadataImportController method postXmlMetadata.
@RequestMapping(value = "", method = RequestMethod.POST, consumes = MediaType.APPLICATION_XML_VALUE)
public void postXmlMetadata(HttpServletRequest request, HttpServletResponse response) throws IOException {
MetadataImportParams params = metadataImportService.getParamsFromMap(contextService.getParameterValuesMap());
Metadata metadata = renderService.fromXml(StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream()), Metadata.class);
params.addMetadata(schemaService.getMetadataSchemas(), metadata);
if (params.hasTaskId()) {
startAsync(params);
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
} else {
ImportReport importReport = metadataImportService.importMetadata(params);
renderService.toXml(response.getOutputStream(), importReport);
}
}
use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.
the class MetadataSyncController method metadataSync.
@PreAuthorize("hasRole('ALL') or hasRole('F_METADATA_MANAGE')")
@GetMapping
public ResponseEntity<? extends WebMessageResponse> metadataSync(HttpServletRequest request, HttpServletResponse response) throws MetadataSyncException, BadRequestException, MetadataImportConflictException, OperationNotAllowedException {
MetadataSyncParams syncParams;
MetadataSyncSummary metadataSyncSummary = null;
synchronized (metadataSyncService) {
try {
syncParams = metadataSyncService.getParamsFromMap(contextService.getParameterValuesMap());
} catch (RemoteServerUnavailableException exception) {
throw new MetadataSyncException(exception.getMessage(), exception);
} catch (MetadataSyncServiceException serviceException) {
throw new BadRequestException("Error in parsing inputParams " + serviceException.getMessage(), serviceException);
}
try {
boolean isSyncRequired = metadataSyncService.isSyncRequired(syncParams);
if (isSyncRequired) {
metadataSyncSummary = metadataSyncService.doMetadataSync(syncParams);
validateSyncSummaryResponse(metadataSyncSummary);
} else {
throw new MetadataImportConflictException("Version already exists in system and hence not starting the sync.");
}
} catch (MetadataSyncImportException importerException) {
throw new MetadataSyncException("Runtime exception occurred while doing import: " + importerException.getMessage());
} catch (MetadataSyncServiceException serviceException) {
throw new MetadataSyncException("Exception occurred while doing metadata sync: " + serviceException.getMessage());
} catch (DhisVersionMismatchException versionMismatchException) {
throw new OperationNotAllowedException("Exception occurred while doing metadata sync: " + versionMismatchException.getMessage());
}
}
return new ResponseEntity<MetadataSyncSummary>(metadataSyncSummary, HttpStatus.OK);
}
use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.
the class MetadataVersionController method getMetaDataVersionHistory.
//Gets the list of all versions in between the passed version name and latest system version
@RequestMapping(value = MetadataVersionSchemaDescriptor.API_ENDPOINT + "/history", method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getMetaDataVersionHistory(@RequestParam(value = "baseline", required = false) String versionName) throws MetadataVersionException, BadRequestException {
List<MetadataVersion> allVersionsInBetween = new ArrayList<>();
boolean enabled = isMetadataVersioningEnabled();
try {
if (!enabled) {
throw new BadRequestException("Metadata versioning is not enabled for this instance.");
}
Date startDate;
if (versionName == null || versionName.isEmpty()) {
MetadataVersion initialVersion = versionService.getInitialVersion();
if (initialVersion == null) {
return versionService.getMetadataVersionsAsNode(allVersionsInBetween);
}
startDate = initialVersion.getCreated();
} else {
startDate = versionService.getCreatedDate(versionName);
}
if (startDate == null) {
throw new MetadataVersionException("There is no such metadata version. The latest version is Version " + versionService.getCurrentVersion().getName());
}
Date endDate = new Date();
allVersionsInBetween = versionService.getAllVersionsInBetween(startDate, endDate);
if (allVersionsInBetween != null) {
//now remove the baseline version details
for (Iterator<MetadataVersion> iterator = allVersionsInBetween.iterator(); iterator.hasNext(); ) {
MetadataVersion m = iterator.next();
if (m.getName().equals(versionName)) {
iterator.remove();
break;
}
}
if (!allVersionsInBetween.isEmpty()) {
return versionService.getMetadataVersionsAsNode(allVersionsInBetween);
}
}
} catch (MetadataVersionServiceException ex) {
throw new MetadataVersionException(ex.getMessage(), ex);
}
return null;
}
use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.
the class MetadataVersionController method createSystemVersion.
//Creates version in versioning table, exports the metadata and saves the snapshot in datastore
@PreAuthorize("hasRole('ALL') or hasRole('F_METADATA_MANAGE')")
@RequestMapping(value = MetadataVersionSchemaDescriptor.API_ENDPOINT + "/create", method = RequestMethod.POST, produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public MetadataVersion createSystemVersion(@RequestParam(value = "type") VersionType versionType) throws MetadataVersionException, BadRequestException {
MetadataVersion versionToReturn = null;
boolean enabled = isMetadataVersioningEnabled();
try {
if (!enabled) {
throw new BadRequestException("Metadata versioning is not enabled for this instance.");
}
synchronized (versionService) {
versionService.saveVersion(versionType);
versionToReturn = versionService.getCurrentVersion();
return versionToReturn;
}
} catch (MetadataVersionServiceException ex) {
throw new MetadataVersionException("Unable to create version in system. " + ex.getMessage());
}
}
use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.
the class FilledOrganisationUnitLevelController method setList.
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public void setList(HttpServletRequest request, HttpServletResponse response) throws Exception {
Metadata metadata = DefaultRenderService.getJsonMapper().readValue(request.getInputStream(), Metadata.class);
List<OrganisationUnitLevel> levels = metadata.getOrganisationUnitLevels();
for (OrganisationUnitLevel level : levels) {
if (level.getLevel() <= 0) {
throw new WebMessageException(WebMessageUtils.conflict("Level must be greater than zero"));
}
if (StringUtils.isBlank(level.getName())) {
throw new WebMessageException(WebMessageUtils.conflict("Name must be specified"));
}
organisationUnitService.addOrUpdateOrganisationUnitLevel(new OrganisationUnitLevel(level.getLevel(), level.getName(), level.getOfflineLevels()));
}
}
Aggregations