Search in sources :

Example 6 with CREATED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.CREATED in project dhis2-core by dhis2.

the class MetadataSyncPostProcessor method sendSuccessMailToAdmin.

public void sendSuccessMailToAdmin(MetadataSyncSummary metadataSyncSummary) {
    ImportReport importReport = metadataSyncSummary.getImportReport();
    StringBuilder text = new StringBuilder("Successful Import Report for the scheduler run for Metadata synchronization \n\n").append("Imported Version Details \n ").append("Version Name: " + metadataSyncSummary.getMetadataVersion().getName() + "\n").append("Version Type: " + metadataSyncSummary.getMetadataVersion().getType() + "\n");
    if (importReport.getTypeReportCount() == 0) {
        text.append("New Version created. It does not have any metadata changes. \n");
    } else {
        text.append("Imported Object Details: \n");
        importReport.forEachTypeReport(typeReport -> {
            Stats stats = typeReport.getStats();
            text.append("Metadata Object Type: ").append(typeReport.getKlass()).append("\n").append("Stats: \n").append("total: " + stats.getTotal() + "\n");
            if (stats.getCreated() > 0) {
                text.append(" created: " + stats.getCreated() + "\n");
            }
            if (stats.getUpdated() > 0) {
                text.append(" updated: " + stats.getUpdated() + "\n");
            }
            if (stats.getIgnored() > 0) {
                text.append(" ignored: " + stats.getIgnored() + "\n");
            }
        });
        text.append("\n\n");
    }
    if (text.length() > 0) {
        log.info("Success mail will be sent with the following message: " + text);
        emailService.sendSystemEmail(new Email("Success Notification: Metadata Synchronization", text.toString()));
    }
}
Also used : Email(org.hisp.dhis.email.Email) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) Stats(org.hisp.dhis.feedback.Stats)

Example 7 with CREATED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.CREATED in project dhis2-core by dhis2.

the class DefaultMetadataVersionService method getMetadataExport.

// --------------------------------------------------------------------------
// Private methods
// --------------------------------------------------------------------------
/**
 * Generates the metadata export based on the created date of the current
 * version.
 */
private ByteArrayOutputStream getMetadataExport(Date minDate) {
    ByteArrayOutputStream os;
    try {
        MetadataExportParams exportParams = new MetadataExportParams();
        if (minDate != null) {
            List<String> defaultFilterList = new ArrayList<>();
            defaultFilterList.add("lastUpdated:gte:" + DateUtils.getLongGmtDateString(minDate));
            exportParams.setDefaultFilter(defaultFilterList);
            exportParams.setDefaultFields(Lists.newArrayList(":all"));
            metadataExportService.validate(exportParams);
        }
        os = new ByteArrayOutputStream(1024);
        ObjectNode metadata = metadataExportService.getMetadataAsNode(exportParams);
        renderService.toJson(os, metadata);
    } catch (// We have to catch the "Exception" object as no
    Exception ex) // specific exception on the contract.
    {
        String message = "Exception occurred while exporting metadata for capturing a metadata version" + ex.getMessage();
        log.error(message, ex);
        throw new MetadataVersionServiceException(message, ex);
    }
    return os;
}
Also used : MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MetadataExportParams(org.hisp.dhis.dxf2.metadata.MetadataExportParams) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 8 with CREATED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.CREATED in project dhis2-core by dhis2.

the class NoteRowCallbackHandler method getNote.

private Note getNote(ResultSet rs) throws SQLException {
    Note note = new Note();
    note.setNote(rs.getString("uid"));
    note.setValue(rs.getString("commenttext"));
    note.setStoredBy(rs.getString("creator"));
    note.setStoredDate(DateUtils.getIso8601NoTz(rs.getDate("created")));
    return note;
}
Also used : Note(org.hisp.dhis.dxf2.events.event.Note)

Example 9 with CREATED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.CREATED in project dhis2-core by dhis2.

the class ProgramStageInstanceMapper method mapForInsert.

public ProgramStageInstance mapForInsert(Event event) {
    ImportOptions importOptions = workContext.getImportOptions();
    ProgramStageInstance psi = new ProgramStageInstance();
    if (importOptions.getIdSchemes().getProgramStageInstanceIdScheme().equals(CODE)) {
        psi.setCode(event.getEvent());
    } else if (importOptions.getIdSchemes().getProgramStageIdScheme().equals(UID)) {
        psi.setUid(event.getUid());
    }
    // Program Instance
    psi.setProgramInstance(this.workContext.getProgramInstanceMap().get(event.getUid()));
    // Program Stage
    psi.setProgramStage(this.workContext.getProgramStage(importOptions.getIdSchemes().getProgramStageIdScheme(), event.getProgramStage()));
    // Org Unit
    psi.setOrganisationUnit(this.workContext.getOrganisationUnitMap().get(event.getUid()));
    // Status
    psi.setStatus(fromInt(event.getStatus().getValue()));
    // Attribute Option Combo
    psi.setAttributeOptionCombo(this.workContext.getCategoryOptionComboMap().get(event.getUid()));
    // Geometry
    psi.setGeometry(event.getGeometry());
    // Notes
    psi.setComments(convertNotes(event, this.workContext));
    // Data Values
    psi.setEventDataValues(workContext.getEventDataValueMap().get(event.getUid()));
    Date dueDate = new Date();
    if (event.getDueDate() != null) {
        dueDate = parseDate(event.getDueDate());
    }
    psi.setDueDate(dueDate);
    setCompletedDate(event, psi);
    // Note that execution date can be null
    setExecutionDate(event, psi);
    if (psi.getProgramStage() != null && psi.getProgramStage().isEnableUserAssignment()) {
        psi.setAssignedUser(this.workContext.getAssignedUserMap().get(event.getUid()));
    }
    // CREATED AT CLIENT + UPDATED AT CLIENT
    psi.setCreatedAtClient(parseDate(event.getCreatedAtClient()));
    psi.setLastUpdatedAtClient(parseDate(event.getLastUpdatedAtClient()));
    psi.setStoredBy(event.getStoredBy());
    psi.setCompletedBy(event.getCompletedBy());
    psi.setCreatedByUserInfo(event.getCreatedByUserInfo());
    psi.setLastUpdatedByUserInfo(event.getLastUpdatedByUserInfo());
    return psi;
}
Also used : ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) Date(java.util.Date) DateUtils.parseDate(org.hisp.dhis.util.DateUtils.parseDate)

Example 10 with CREATED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.CREATED in project dhis2-core by dhis2.

the class EventBaseCheck method validateProgramInstance.

private void validateProgramInstance(ImmutableEvent event, WorkContext ctx, List<String> errors) {
    ProgramInstance programInstance = ctx.getProgramInstanceMap().get(event.getUid());
    ImportOptions importOptions = ctx.getImportOptions();
    if (programInstance == null) {
        errors.add("No program instance found for event: " + event.getEvent());
    } else if (COMPLETED.equals(programInstance.getStatus())) {
        if (importOptions == null || importOptions.getUser() == null || importOptions.getUser().isAuthorized(F_EDIT_EXPIRED.getAuthority())) {
            return;
        }
        Date referenceDate = parseDate(event.getCreated());
        if (referenceDate == null) {
            referenceDate = new Date();
        }
        referenceDate = removeTimeStamp(referenceDate);
        if (referenceDate.after(removeTimeStamp(programInstance.getEndDate()))) {
            errors.add("Not possible to add event to a completed enrollment. Event created date ( " + referenceDate + " ) is after enrollment completed date ( " + removeTimeStamp(programInstance.getEndDate()) + " ).");
        }
    }
}
Also used : ProgramInstance(org.hisp.dhis.program.ProgramInstance) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) Date(java.util.Date) DateUtils.parseDate(org.hisp.dhis.util.DateUtils.parseDate)

Aggregations

WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)12 Test (org.junit.jupiter.api.Test)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 ArrayList (java.util.ArrayList)8 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)7 Date (java.util.Date)6 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)6 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)6 AvailabilityStatus (org.hisp.dhis.dxf2.synch.AvailabilityStatus)6 DhisHttpResponse (org.hisp.dhis.system.util.DhisHttpResponse)6 HttpUtils (org.hisp.dhis.system.util.HttpUtils)6 User (org.hisp.dhis.user.User)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 List (java.util.List)5 Map (java.util.Map)5 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)4 Event (org.hisp.dhis.dxf2.events.event.Event)4 HashMap (java.util.HashMap)3