Search in sources :

Example 1 with Timer

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));
}
Also used : SystemTimer(org.hisp.dhis.commons.timer.SystemTimer) Timer(org.hisp.dhis.commons.timer.Timer) SystemTimer(org.hisp.dhis.commons.timer.SystemTimer)

Example 2 with Timer

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());
}
Also used : SystemTimer(org.hisp.dhis.commons.timer.SystemTimer) Timer(org.hisp.dhis.commons.timer.Timer) SystemTimer(org.hisp.dhis.commons.timer.SystemTimer)

Example 3 with Timer

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;
}
Also used : FieldFilterService(org.hisp.dhis.fieldfiltering.FieldFilterService) SystemInfo(org.hisp.dhis.system.SystemInfo) ProgramRuleVariableService(org.hisp.dhis.programrule.ProgramRuleVariableService) Authorities(org.hisp.dhis.security.Authorities) Date(java.util.Date) CategoryOption(org.hisp.dhis.category.CategoryOption) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) Visualization(org.hisp.dhis.visualization.Visualization) Document(org.hisp.dhis.document.Document) SystemService(org.hisp.dhis.system.SystemService) EventChart(org.hisp.dhis.eventchart.EventChart) Map(java.util.Map) DataEntryForm(org.hisp.dhis.dataentryform.DataEntryForm) Query(org.hisp.dhis.query.Query) ProgramNotificationTemplate(org.hisp.dhis.program.notification.ProgramNotificationTemplate) Set(java.util.Set) Category(org.hisp.dhis.category.Category) SchemaService(org.hisp.dhis.schema.SchemaService) QueryService(org.hisp.dhis.query.QueryService) SetMap(org.hisp.dhis.common.SetMap) Sets(com.google.common.collect.Sets) Section(org.hisp.dhis.dataset.Section) ProgramRule(org.hisp.dhis.programrule.ProgramRule) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) AttributeService(org.hisp.dhis.attribute.AttributeService) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) ProgramRuleService(org.hisp.dhis.programrule.ProgramRuleService) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) CategoryCombo(org.hisp.dhis.category.CategoryCombo) Schema(org.hisp.dhis.schema.Schema) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Legend(org.hisp.dhis.legend.Legend) Report(org.hisp.dhis.report.Report) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) DataSetElement(org.hisp.dhis.dataset.DataSetElement) DataSet(org.hisp.dhis.dataset.DataSet) ProgramRuleVariable(org.hisp.dhis.programrule.ProgramRuleVariable) HashMap(java.util.HashMap) EventReport(org.hisp.dhis.eventreport.EventReport) MapView(org.hisp.dhis.mapping.MapView) ProgramRuleAction(org.hisp.dhis.programrule.ProgramRuleAction) Attribute(org.hisp.dhis.attribute.Attribute) Program(org.hisp.dhis.program.Program) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DataElement(org.hisp.dhis.dataelement.DataElement) FieldFilterParams(org.hisp.dhis.fieldfiltering.FieldFilterParams) Service(org.springframework.stereotype.Service) Interpretation(org.hisp.dhis.interpretation.Interpretation) LegendSet(org.hisp.dhis.legend.LegendSet) Indicator(org.hisp.dhis.indicator.Indicator) User(org.hisp.dhis.user.User) IndicatorType(org.hisp.dhis.indicator.IndicatorType) Nonnull(javax.annotation.Nonnull) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) SystemTimer(org.hisp.dhis.commons.timer.SystemTimer) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DashboardItem(org.hisp.dhis.dashboard.DashboardItem) Timer(org.hisp.dhis.commons.timer.Timer) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) ProgramStage(org.hisp.dhis.program.ProgramStage) Dashboard(org.hisp.dhis.dashboard.Dashboard) ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) InterpretableObject(org.hisp.dhis.common.InterpretableObject) Option(org.hisp.dhis.option.Option) OrderParams(org.hisp.dhis.dxf2.common.OrderParams) OptionSet(org.hisp.dhis.option.OptionSet) CurrentUserService(org.hisp.dhis.user.CurrentUserService) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) AllArgsConstructor(lombok.AllArgsConstructor) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) DateUtils(org.hisp.dhis.util.DateUtils) SystemTimer(org.hisp.dhis.commons.timer.SystemTimer) Timer(org.hisp.dhis.commons.timer.Timer) Query(org.hisp.dhis.query.Query) HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList) OrderParams(org.hisp.dhis.dxf2.common.OrderParams) SystemTimer(org.hisp.dhis.commons.timer.SystemTimer) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 4 with Timer

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;
}
Also used : ObjectBundleParams(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams) ObjectBundleCommitReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleCommitReport) ObjectBundle(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle) SystemTimer(org.hisp.dhis.commons.timer.SystemTimer) Timer(org.hisp.dhis.commons.timer.Timer) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) ImportReportMode(org.hisp.dhis.dxf2.metadata.feedback.ImportReportMode) SystemTimer(org.hisp.dhis.commons.timer.SystemTimer) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Timer

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;
}
Also used : SystemTimer(org.hisp.dhis.commons.timer.SystemTimer) Timer(org.hisp.dhis.commons.timer.Timer) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) SystemTimer(org.hisp.dhis.commons.timer.SystemTimer) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Timer (org.hisp.dhis.commons.timer.Timer)11 SystemTimer (org.hisp.dhis.commons.timer.SystemTimer)10 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)3 User (org.hisp.dhis.user.User)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 FlattenedDataIntegrityReport (org.hisp.dhis.dataintegrity.FlattenedDataIntegrityReport)2 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)2 Query (org.hisp.dhis.query.Query)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Sets (com.google.common.collect.Sets)1 Date (java.util.Date)1 Nonnull (javax.annotation.Nonnull)1 AllArgsConstructor (lombok.AllArgsConstructor)1 Slf4j (lombok.extern.slf4j.Slf4j)1