use of org.hisp.dhis.commons.timer.Timer in project dhis2-core by dhis2.
the class AbstractJdbcTableManager method populateAndLog.
/**
* Executes the given table population SQL statement, log and times the operation.
*/
protected void populateAndLog(String sql, String tableName) {
log.debug(String.format("Populate table: %s with SQL: ", tableName, sql));
Timer timer = new SystemTimer().start();
jdbcTemplate.execute(sql);
log.info(String.format("Populated table in %s: %s", timer.stop().toString(), tableName));
}
use of org.hisp.dhis.commons.timer.Timer in project dhis2-core by dhis2.
the class AbstractJdbcTableManager method invokeTimeAndLog.
/**
* Executes the given SQL statement. Logs and times the operation.
*
* @param sql the SQL statement.
* @param logMessage the custom log message to include in the log statement.
*/
protected void invokeTimeAndLog(String sql, String logMessage) {
log.debug("{} with SQL: '{}'", logMessage, sql);
Timer timer = new SystemTimer().start();
jdbcTemplate.execute(sql);
log.info("{} in: {}", logMessage, timer.stop().toString());
}
use of org.hisp.dhis.commons.timer.Timer in project dhis2-core by dhis2.
the class DefaultMetadataExportService method getMetadata.
@Override
@SuppressWarnings("unchecked")
public Map<Class<? extends IdentifiableObject>, List<? extends IdentifiableObject>> getMetadata(MetadataExportParams params) {
Timer timer = new SystemTimer().start();
Map<Class<? extends IdentifiableObject>, List<? extends IdentifiableObject>> metadata = new HashMap<>();
if (params.getUser() == null) {
params.setUser(currentUserService.getCurrentUser());
}
if (params.getClasses().isEmpty()) {
schemaService.getMetadataSchemas().stream().filter(schema -> schema.isIdentifiableObject() && schema.isPersisted()).filter(s -> !s.isSecondaryMetadata()).forEach(schema -> params.getClasses().add((Class<? extends IdentifiableObject>) schema.getKlass()));
}
log.info("(" + params.getUsername() + ") Export:Start");
for (Class<? extends IdentifiableObject> klass : params.getClasses()) {
Query query;
if (params.getQuery(klass) != null) {
query = params.getQuery(klass);
} else {
OrderParams orderParams = new OrderParams(Sets.newHashSet(params.getDefaultOrder()));
query = queryService.getQueryFromUrl(klass, params.getDefaultFilter(), orderParams.getOrders(schemaService.getDynamicSchema(klass)));
}
if (query.getUser() == null) {
query.setUser(params.getUser());
}
query.setDefaultOrder();
query.setDefaults(params.getDefaults());
List<? extends IdentifiableObject> objects = queryService.query(query);
if (!objects.isEmpty()) {
log.info("(" + params.getUsername() + ") Exported " + objects.size() + " objects of type " + klass.getSimpleName());
metadata.put(klass, objects);
}
}
log.info("(" + params.getUsername() + ") Export:Done took " + timer.toString());
return metadata;
}
use of org.hisp.dhis.commons.timer.Timer 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.commons.timer.Timer in project dhis2-core by dhis2.
the class DefaultObjectBundleValidationService method validate.
@Override
@Transactional(readOnly = true)
public ObjectBundleValidationReport validate(ObjectBundle bundle) {
Timer timer = new SystemTimer().start();
ObjectBundleValidationReport validation = new ObjectBundleValidationReport();
if ((bundle.getUser() == null || bundle.getUser().isSuper()) && bundle.isSkipValidation()) {
log.warn("Skipping validation for metadata import by user '" + bundle.getUsername() + "'. Not recommended.");
return validation;
}
List<Class<? extends IdentifiableObject>> klasses = getSortedClasses(bundle);
for (Class<? extends IdentifiableObject> klass : klasses) {
validateObjectType(bundle, validation, klass);
}
validateAtomicity(bundle, validation);
bundle.setObjectBundleStatus(ObjectBundleStatus.VALIDATED);
log.info("(" + bundle.getUsername() + ") Import:Validation took " + timer.toString());
return validation;
}
Aggregations