use of org.hisp.dhis.dxf2.metadata.feedback.ImportReportMode in project dhis2-core by dhis2.
the class DefaultMetadataImportService method getParamsFromMap.
@Override
@Transactional(readOnly = true)
public MetadataImportParams getParamsFromMap(Map<String, List<String>> parameters) {
MetadataImportParams params = new MetadataImportParams();
if (params.getUser() == null) {
params.setUser(currentUserService.getCurrentUser());
}
params.setSkipSharing(getBooleanWithDefault(parameters, "skipSharing", false));
params.setSkipTranslation(getBooleanWithDefault(parameters, "skipTranslation", false));
params.setSkipValidation(getBooleanWithDefault(parameters, "skipValidation", false));
params.setUserOverrideMode(getEnumWithDefault(UserOverrideMode.class, parameters, "userOverrideMode", UserOverrideMode.NONE));
params.setImportMode(getEnumWithDefault(ObjectBundleMode.class, parameters, "importMode", ObjectBundleMode.COMMIT));
params.setPreheatMode(getEnumWithDefault(PreheatMode.class, parameters, "preheatMode", PreheatMode.REFERENCE));
params.setIdentifier(getEnumWithDefault(PreheatIdentifier.class, parameters, "identifier", PreheatIdentifier.UID));
params.setImportStrategy(getEnumWithDefault(ImportStrategy.class, parameters, "importStrategy", ImportStrategy.CREATE_AND_UPDATE));
params.setAtomicMode(getEnumWithDefault(AtomicMode.class, parameters, "atomicMode", AtomicMode.ALL));
params.setMergeMode(getEnumWithDefault(MergeMode.class, parameters, "mergeMode", MergeMode.REPLACE));
params.setFlushMode(getEnumWithDefault(FlushMode.class, parameters, "flushMode", FlushMode.AUTO));
params.setImportReportMode(getEnumWithDefault(ImportReportMode.class, parameters, "importReportMode", ImportReportMode.ERRORS));
params.setFirstRowIsHeader(getBooleanWithDefault(parameters, "firstRowIsHeader", true));
if (getBooleanWithDefault(parameters, "async", false)) {
JobConfiguration jobId = new JobConfiguration("metadataImport", JobType.METADATA_IMPORT, params.getUser().getUid(), true);
notifier.clear(jobId);
params.setId(jobId);
}
if (params.getUserOverrideMode() == UserOverrideMode.SELECTED) {
User overrideUser = null;
if (parameters.containsKey("overrideUser")) {
List<String> overrideUsers = parameters.get("overrideUser");
overrideUser = manager.get(User.class, overrideUsers.get(0));
}
if (overrideUser == null) {
throw new MetadataImportException("UserOverrideMode.SELECTED is enabled, but overrideUser parameter does not point to a valid user.");
} else {
params.setOverrideUser(overrideUser);
}
}
return params;
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReportMode in project dhis2-core by dhis2.
the class DefaultMetadataImportService method importMetadata.
@Override
@Transactional
public ImportReport importMetadata(MetadataImportParams params) {
Timer timer = new SystemTimer().start();
ImportReport importReport = new ImportReport();
importReport.setImportParams(params);
importReport.setStatus(Status.OK);
if (params.getUser() == null) {
params.setUser(currentUserService.getCurrentUser());
}
if (params.getUserOverrideMode() == UserOverrideMode.CURRENT) {
params.setOverrideUser(currentUserService.getCurrentUser());
}
String message = "(" + params.getUsername() + ") Import:Start";
log.info(message);
if (params.hasJobId()) {
notifier.notify(params.getId(), message);
}
preCreateBundle(params);
ObjectBundleParams bundleParams = params.toObjectBundleParams();
handleDeprecationIfEventReport(bundleParams);
ObjectBundle bundle = objectBundleService.create(bundleParams);
postCreateBundle(bundle, bundleParams);
ObjectBundleValidationReport validationReport = objectBundleValidationService.validate(bundle);
importReport.addTypeReports(validationReport);
if (!validationReport.hasErrorReports() || AtomicMode.NONE == bundle.getAtomicMode()) {
Timer commitTimer = new SystemTimer().start();
ObjectBundleCommitReport commitReport = objectBundleService.commit(bundle);
importReport.addTypeReports(commitReport);
if (importReport.hasErrorReports()) {
importReport.setStatus(Status.WARNING);
}
log.info("(" + bundle.getUsername() + ") Import:Commit took " + commitTimer.toString());
} else {
importReport.getStats().ignored();
importReport.getTypeReports().forEach(tr -> tr.getStats().ignored());
importReport.setStatus(Status.ERROR);
}
message = "(" + bundle.getUsername() + ") Import:Done took " + timer.toString();
log.info(message);
if (bundle.hasJobId()) {
notifier.notify(bundle.getJobId(), NotificationLevel.INFO, message, true).addJobSummary(bundle.getJobId(), importReport, ImportReport.class);
}
if (ObjectBundleMode.VALIDATE == params.getImportMode()) {
return importReport;
}
importReport.clean();
importReport.forEachTypeReport(typeReport -> {
ImportReportMode mode = params.getImportReportMode();
if (ImportReportMode.ERRORS == mode) {
typeReport.clean();
}
if (ImportReportMode.DEBUG != mode) {
typeReport.getObjectReports().forEach(objectReport -> objectReport.setDisplayName(null));
}
});
return importReport;
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReportMode in project dhis2-core by dhis2.
the class AbstractCrudController method patchObject.
// --------------------------------------------------------------------------
// PATCH
// --------------------------------------------------------------------------
/**
* Adds support for HTTP Patch using JSON Patch (RFC 6902), updated object
* is run through normal metadata importer and internally looks like a
* normal PUT (after the JSON Patch has been applied).
*
* For now we only support the official mimetype
* "application/json-patch+json" but in future releases we might also want
* to support "application/json" after the old patch behavior has been
* removed.
*/
@ResponseBody
@PatchMapping(path = "/{uid}", consumes = "application/json-patch+json")
public WebMessage patchObject(@PathVariable("uid") String pvUid, @RequestParam Map<String, String> rpParameters, @CurrentUser User currentUser, HttpServletRequest request) throws Exception {
WebOptions options = new WebOptions(rpParameters);
List<T> entities = getEntity(pvUid, options);
if (entities.isEmpty()) {
return notFound(getEntityClass(), pvUid);
}
final T persistedObject = entities.get(0);
if (!aclService.canUpdate(currentUser, persistedObject)) {
throw new UpdateAccessDeniedException("You don't have the proper permissions to update this object.");
}
manager.resetNonOwnerProperties(persistedObject);
prePatchEntity(persistedObject);
final JsonPatch patch = jsonMapper.readValue(request.getInputStream(), JsonPatch.class);
final T patchedObject = jsonPatchManager.apply(patch, persistedObject);
// we don't allow changing IDs
((BaseIdentifiableObject) patchedObject).setId(persistedObject.getId());
// we don't allow changing UIDs
((BaseIdentifiableObject) patchedObject).setUid(persistedObject.getUid());
// Only supports new Sharing format
((BaseIdentifiableObject) patchedObject).clearLegacySharingCollections();
prePatchEntity(persistedObject, patchedObject);
Map<String, List<String>> parameterValuesMap = contextService.getParameterValuesMap();
if (!parameterValuesMap.containsKey("importReportMode")) {
parameterValuesMap.put("importReportMode", Collections.singletonList("ERRORS_NOT_OWNER"));
}
MetadataImportParams params = importService.getParamsFromMap(parameterValuesMap);
params.setUser(currentUser).setImportStrategy(ImportStrategy.UPDATE).addObject(patchedObject);
ImportReport importReport = importService.importMetadata(params);
WebMessage webMessage = objectReport(importReport);
if (importReport.getStatus() == Status.OK) {
T entity = manager.get(getEntityClass(), pvUid);
postPatchEntity(entity);
} else {
webMessage.setStatus(Status.ERROR);
}
return webMessage;
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReportMode in project dhis2-core by dhis2.
the class MetadataImportParams method toObjectBundleParams.
public ObjectBundleParams toObjectBundleParams() {
ObjectBundleParams params = new ObjectBundleParams();
params.setUser(user);
params.setUserOverrideMode(userOverrideMode);
params.setOverrideUser(overrideUser);
params.setSkipSharing(skipSharing);
params.setSkipTranslation(skipTranslation);
params.setSkipValidation(skipValidation);
params.setJobId(id);
params.setImportStrategy(importStrategy);
params.setAtomicMode(atomicMode);
params.setObjects(objects);
params.setPreheatIdentifier(identifier);
params.setPreheatMode(preheatMode);
params.setObjectBundleMode(importMode);
params.setMergeMode(mergeMode);
params.setFlushMode(flushMode);
params.setImportReportMode(importReportMode);
params.setMetadataSyncImport(metadataSyncImport);
return params;
}
Aggregations