use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class MapController method putJsonObject.
@Override
@RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void putJsonObject(@PathVariable String uid, HttpServletRequest request, HttpServletResponse response) throws Exception {
Map map = mappingService.getMap(uid);
if (map == null) {
throw new WebMessageException(WebMessageUtils.notFound("Map does not exist: " + uid));
}
MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap());
Map newMap = deserializeJsonEntity(request, response);
newMap.setUid(uid);
mergeService.merge(new MergeParams<>(newMap, map).setMergeMode(params.getMergeMode()));
mappingService.updateMap(map);
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class DefaultMetadataSyncService method getParamsFromMap.
@Override
public MetadataSyncParams getParamsFromMap(Map<String, List<String>> parameters) {
List<String> versionName = getVersionsFromParams(parameters);
MetadataImportParams importParams = new MetadataImportParams();
importParams.setMetadataSyncImport(true);
MetadataSyncParams syncParams = new MetadataSyncParams();
syncParams.setImportParams(importParams);
String versionNameStr = versionName.get(0);
if (StringUtils.isNotEmpty(versionNameStr)) {
MetadataVersion version;
try {
version = metadataVersionDelegate.getRemoteMetadataVersion(versionNameStr);
} catch (MetadataVersionServiceException e) {
throw new MetadataSyncServiceException(e.getMessage(), e);
}
if (version == null) {
throw new MetadataSyncServiceException("The MetadataVersion could not be fetched from the remote server for the versionName: " + versionNameStr);
}
syncParams.setVersion(version);
}
syncParams.setParameters(parameters);
return syncParams;
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams 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.MetadataImportParams 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.MetadataImportParams in project dhis2-core by dhis2.
the class MetadataImportParams method addMetadata.
@SuppressWarnings("unchecked")
public MetadataImportParams addMetadata(List<Schema> schemas, Metadata metadata) {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> objectMap = new HashMap<>();
for (Schema schema : schemas) {
if (schema.isIdentifiableObject()) {
Class<? extends IdentifiableObject> key = (Class<? extends IdentifiableObject>) schema.getKlass();
List<? extends IdentifiableObject> schemaObjects = metadata.getValues(key);
if (!schemaObjects.isEmpty()) {
objectMap.put(key, new ArrayList<>(schemaObjects));
}
}
}
setObjects(objectMap);
return this;
}
Aggregations