use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class CompleteDataSetRegistrationController method saveCompleteDataSetRegistration.
@ApiVersion({ DhisApiVersion.V23, DhisApiVersion.V24, DhisApiVersion.V25 })
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", value = MULTIPLE_SAVE_RESOURCE_PATH)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void saveCompleteDataSetRegistration(@RequestBody CompleteDataSetRegistrationRequests completeDataSetRegistrationRequests, HttpServletResponse response) throws WebMessageException {
List<CompleteDataSetRegistration> registrations = new ArrayList<>();
for (CompleteDataSetRegistrationRequest completeDataSetRegistrationRequest : completeDataSetRegistrationRequests) {
String ds = completeDataSetRegistrationRequest.getDs();
DataSet dataSet = dataSetService.getDataSet(ds);
if (dataSet == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal data set identifier: " + ds));
}
String pe = completeDataSetRegistrationRequest.getPe();
Period period = PeriodType.getPeriodFromIsoString(pe);
if (period == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal period identifier: " + pe));
}
String ou = completeDataSetRegistrationRequest.getOu();
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou);
if (organisationUnit == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal organisation unit identifier: " + ou));
}
String cc = completeDataSetRegistrationRequest.getCc();
String cp = completeDataSetRegistrationRequest.getCp();
DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
if (attributeOptionCombo == null) {
return;
}
// ---------------------------------------------------------------------
// Check locked status
// ---------------------------------------------------------------------
boolean multiOu = completeDataSetRegistrationRequest.isMultiOu();
if (dataSetService.isLocked(dataSet, period, organisationUnit, attributeOptionCombo, null, multiOu)) {
throw new WebMessageException(WebMessageUtils.conflict("Data set is locked: " + ds));
}
// ---------------------------------------------------------------------
// Register as completed data set
// ---------------------------------------------------------------------
String sb = completeDataSetRegistrationRequest.getSb();
String storedBy = (sb == null) ? currentUserService.getCurrentUsername() : sb;
Date cd = completeDataSetRegistrationRequest.getCd();
Date completionDate = (cd == null) ? new Date() : cd;
Set<OrganisationUnit> orgUnits = new HashSet<>();
orgUnits.add(organisationUnit);
if (multiOu) {
orgUnits.addAll(organisationUnit.getChildren());
}
addRegistrationsForOrgUnits(registrations, orgUnits, dataSet, period, attributeOptionCombo, storedBy, completionDate);
}
registrationService.saveCompleteDataSetRegistrations(registrations, true);
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class TrackedEntityInstanceAggregate method filterAttributes.
/**
* Filter attributes based on queryParams, ownership and super user status
*/
private List<Attribute> filterAttributes(Collection<Attribute> attributes, Collection<String> programs, Set<TrackedEntityAttribute> trackedEntityTypeAttributes, Map<Program, Set<TrackedEntityAttribute>> teaByProgram, AggregateContext ctx) {
List<Attribute> attributeList = new ArrayList<>();
// Nothing to filter from, return empty
if (attributes.isEmpty()) {
return attributeList;
}
// Add all tet attributes. Conditionally filter out the ones marked for
// skipSynchronization in case this is a dataSynchronization query
Set<String> allowedAttributeUids = trackedEntityTypeAttributes.stream().filter(att -> (!ctx.getParams().isDataSynchronizationQuery() || !att.getSkipSynchronization())).map(BaseIdentifiableObject::getUid).collect(Collectors.toSet());
for (Program program : teaByProgram.keySet()) {
if (programs.contains(program.getUid()) || ctx.isSuperUser()) {
allowedAttributeUids.addAll(teaByProgram.get(program).stream().filter(att -> (!ctx.getParams().isDataSynchronizationQuery() || !att.getSkipSynchronization())).map(BaseIdentifiableObject::getUid).collect(Collectors.toSet()));
}
}
for (Attribute attributeValue : attributes) {
if (allowedAttributeUids.contains(attributeValue.getAttribute())) {
attributeList.add(attributeValue);
}
}
return attributeList;
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS 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;
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class MetadataSyncPostProcessor method handleSyncNotificationsAndAbortStatus.
public boolean handleSyncNotificationsAndAbortStatus(MetadataSyncSummary metadataSyncSummary, MetadataRetryContext retryContext, MetadataVersion dataVersion) {
ImportReport importReport = metadataSyncSummary.getImportReport();
if (importReport == null) {
handleImportFailedContext(null, retryContext, dataVersion);
return true;
}
Status syncStatus = importReport.getStatus();
log.info("Import completed. Import Status: " + syncStatus);
if (Status.OK.equals(syncStatus) || (Status.WARNING.equals(syncStatus) && VersionType.BEST_EFFORT.equals(dataVersion.getType()))) {
sendSuccessMailToAdmin(metadataSyncSummary);
return false;
}
if (Status.ERROR.equals(syncStatus)) {
handleImportFailedContext(metadataSyncSummary, retryContext, dataVersion);
return true;
}
return false;
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class EnrollmentSecurityTest method testGetEnrollmentsInSearchScopeForUser.
/**
* program = DATA READ orgUnit = Accessible in search scope status = SUCCESS
*/
@Test
void testGetEnrollmentsInSearchScopeForUser() {
ImportSummary importSummary = enrollmentService.addEnrollment(createEnrollment(programA.getUid(), maleA.getUid()), ImportOptions.getDefaultImportOptions());
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
programA.getSharing().setPublicAccess(AccessStringHelper.DATA_READ);
manager.update(programA);
User user = createUser("user1");
user.setOrganisationUnits(Sets.newHashSet(organisationUnitB));
user.setTeiSearchOrganisationUnits(Sets.newHashSet(organisationUnitA, organisationUnitB));
user.setDataViewOrganisationUnits(Sets.newHashSet(organisationUnitB));
injectSecurityContext(user);
ProgramInstanceQueryParams params = new ProgramInstanceQueryParams();
params.setProgram(programA);
params.setOrganisationUnitMode(OrganisationUnitSelectionMode.ACCESSIBLE);
params.setUser(user);
Enrollments enrollments = enrollmentService.getEnrollments(params);
assertNotNull(enrollments);
assertNotNull(enrollments.getEnrollments());
assertEquals(1, enrollments.getEnrollments().size());
assertEquals(importSummary.getReference(), enrollments.getEnrollments().get(0).getEnrollment());
}
Aggregations