Search in sources :

Example 26 with CREATED

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

the class DashboardController method postJsonItemContent.

@RequestMapping(value = "/{dashboardUid}/items/content", method = RequestMethod.POST)
public void postJsonItemContent(HttpServletResponse response, HttpServletRequest request, @PathVariable String dashboardUid, @RequestParam DashboardItemType type, @RequestParam("id") String contentUid) throws Exception {
    Dashboard dashboard = dashboardService.getDashboard(dashboardUid);
    if (dashboard == null) {
        throw new WebMessageException(WebMessageUtils.notFound("Dashboard does not exist: " + dashboardUid));
    }
    if (!aclService.canUpdate(currentUserService.getCurrentUser(), dashboard)) {
        throw new UpdateAccessDeniedException("You don't have the proper permissions to update this dashboard.");
    }
    DashboardItem item = dashboardService.addItemContent(dashboardUid, type, contentUid);
    if (item == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Max number of dashboard items reached: " + MAX_ITEMS));
    } else {
        response.addHeader("Location", DashboardItemSchemaDescriptor.API_ENDPOINT + "/" + item.getUid());
        webMessageService.send(WebMessageUtils.created("Dashboard item created"), response, request);
    }
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) Dashboard(org.hisp.dhis.dashboard.Dashboard) DashboardItem(org.hisp.dhis.dashboard.DashboardItem) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 27 with CREATED

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

the class AbstractEnrollmentService method saveTrackedEntityComment.

private void saveTrackedEntityComment(ProgramInstance programInstance, Enrollment enrollment, User user) {
    for (Note note : enrollment.getNotes()) {
        String noteUid = CodeGenerator.isValidUid(note.getNote()) ? note.getNote() : CodeGenerator.generateUid();
        if (!commentService.trackedEntityCommentExists(noteUid) && !StringUtils.isEmpty(note.getValue())) {
            TrackedEntityComment comment = new TrackedEntityComment();
            comment.setUid(noteUid);
            comment.setCommentText(note.getValue());
            comment.setCreator(StringUtils.isEmpty(note.getStoredBy()) ? user.getUsername() : note.getStoredBy());
            Date created = DateUtils.parseDate(note.getStoredDate());
            if (created == null) {
                created = new Date();
            }
            comment.setCreated(created);
            comment.setLastUpdatedBy(user);
            comment.setLastUpdated(new Date());
            commentService.addTrackedEntityComment(comment);
            programInstance.getComments().add(comment);
            programInstanceService.updateProgramInstance(programInstance, user);
            teiService.updateTrackedEntityInstance(programInstance.getEntityInstance(), user);
        }
    }
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) Note(org.hisp.dhis.dxf2.events.event.Note) Date(java.util.Date)

Example 28 with CREATED

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

the class AbstractTrackedEntityInstanceService method mergeOrDeleteTrackedEntityInstances.

// -------------------------------------------------------------------------
// CREATE, UPDATE or DELETE
// -------------------------------------------------------------------------
@Override
@Transactional
public ImportSummaries mergeOrDeleteTrackedEntityInstances(List<TrackedEntityInstance> trackedEntityInstances, ImportOptions importOptions, JobConfiguration jobId) {
    notifier.clear(jobId).notify(jobId, "Importing tracked entities");
    try {
        ImportSummaries importSummaries = new ImportSummaries();
        importOptions = updateImportOptions(importOptions);
        List<TrackedEntityInstance> create = new ArrayList<>();
        List<TrackedEntityInstance> update = new ArrayList<>();
        List<TrackedEntityInstance> delete = new ArrayList<>();
        // TODO: Check whether relationships are modified during
        // create/update/delete TEI logic. Decide whether logic below can be
        // removed
        List<Relationship> relationships = getRelationships(trackedEntityInstances);
        setTrackedEntityListByStrategy(trackedEntityInstances, importOptions, create, update, delete);
        importSummaries.addImportSummaries(addTrackedEntityInstances(create, importOptions));
        importSummaries.addImportSummaries(updateTrackedEntityInstances(update, importOptions));
        importSummaries.addImportSummaries(deleteTrackedEntityInstances(delete, importOptions));
        // TODO: Created importSummaries don't contain correct href (TEI
        // endpoint instead of relationships is used)
        importSummaries.addImportSummaries(relationshipService.processRelationshipList(relationships, importOptions));
        if (ImportReportMode.ERRORS == importOptions.getReportMode()) {
            importSummaries.getImportSummaries().removeIf(is -> !is.hasConflicts());
        }
        notifier.notify(jobId, NotificationLevel.INFO, "Import done", true).addJobSummary(jobId, importSummaries, ImportSummaries.class);
        return importSummaries;
    } catch (RuntimeException ex) {
        log.error(DebugUtils.getStackTrace(ex));
        notifier.notify(jobId, ERROR, "Process failed: " + ex.getMessage(), true);
        return new ImportSummaries().addImportSummary(new ImportSummary(ImportStatus.ERROR, "The import process failed: " + ex.getMessage()));
    }
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ArrayList(java.util.ArrayList) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) Transactional(org.springframework.transaction.annotation.Transactional)

Example 29 with CREATED

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

the class EnrollmentRowCallbackHandler method getEnrollment.

private Enrollment getEnrollment(ResultSet rs) throws SQLException {
    Enrollment enrollment = new Enrollment();
    enrollment.setEnrollment(rs.getString(getColumnName(UID)));
    MapperGeoUtils.resolveGeometry(rs.getBytes(getColumnName(GEOMETRY))).ifPresent(enrollment::setGeometry);
    enrollment.setTrackedEntityType(rs.getString(getColumnName(TEI_TYPE_UID)));
    enrollment.setTrackedEntityInstance(rs.getString(getColumnName(TEI_UID)));
    enrollment.setOrgUnit(rs.getString(getColumnName(ORGUNIT_UID)));
    enrollment.setOrgUnitName(rs.getString(getColumnName(ORGUNIT_NAME)));
    enrollment.setCreated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATED))));
    enrollment.setCreatedAtClient(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATEDCLIENT))));
    setUserInfoSnapshot(rs, getColumnName(CREATED_BY), enrollment::setCreatedByUserInfo);
    enrollment.setLastUpdated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATED))));
    enrollment.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATEDCLIENT))));
    setUserInfoSnapshot(rs, getColumnName(LAST_UPDATED_BY), enrollment::setLastUpdatedByUserInfo);
    enrollment.setProgram(rs.getString(getColumnName(PROGRAM_UID)));
    enrollment.setStatus(EnrollmentStatus.fromStatusString(rs.getString(getColumnName(STATUS))));
    enrollment.setEnrollmentDate(rs.getTimestamp(getColumnName(ENROLLMENTDATE)));
    enrollment.setIncidentDate(rs.getTimestamp(getColumnName(INCIDENTDATE)));
    final boolean followup = rs.getBoolean(getColumnName(FOLLOWUP));
    enrollment.setFollowup(rs.wasNull() ? null : followup);
    enrollment.setCompletedDate(rs.getTimestamp(getColumnName(COMPLETED)));
    enrollment.setCompletedBy(rs.getString(getColumnName(COMPLETEDBY)));
    enrollment.setStoredBy(rs.getString(getColumnName(STOREDBY)));
    enrollment.setDeleted(rs.getBoolean(getColumnName(DELETED)));
    enrollment.setId(rs.getLong(getColumnName(ID)));
    return enrollment;
}
Also used : Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment)

Example 30 with CREATED

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

the class RelationshipRowCallbackHandler method getRelationship.

private Relationship getRelationship(ResultSet rs) throws SQLException {
    Relationship relationship = new Relationship();
    relationship.setRelationship(rs.getString("rel_uid"));
    relationship.setRelationshipType(rs.getString("reltype_uid"));
    relationship.setRelationshipName(rs.getString("reltype_name"));
    relationship.setFrom(createItem(rs.getString("from_uid")));
    relationship.setTo(createItem(rs.getString("to_uid")));
    relationship.setBidirectional(rs.getBoolean("reltype_bi"));
    relationship.setCreated(DateUtils.getIso8601NoTz(rs.getTimestamp("created")));
    relationship.setLastUpdated(DateUtils.getIso8601NoTz(rs.getTimestamp("lastupdated")));
    return relationship;
}
Also used : Relationship(org.hisp.dhis.dxf2.events.trackedentity.Relationship)

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