use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STOREDBY in project dhis2-core by dhis2.
the class GetHistoryAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
DataElement dataElement = dataElementService.getDataElement(dataElementId);
CategoryOptionCombo categoryOptionCombo = categoryService.getCategoryOptionCombo(optionComboId);
if (categoryOptionCombo == null) {
categoryOptionCombo = categoryService.getDefaultCategoryOptionCombo();
}
if (dataElement == null) {
throw new IllegalArgumentException("DataElement doesn't exist: " + dataElementId);
}
Period period = PeriodType.getPeriodFromIsoString(periodId);
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
CategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
dataElementHistory = historyRetriever.getHistory(dataElement, categoryOptionCombo, attributeOptionCombo, organisationUnit, period, HISTORY_LENGTH);
dataValueAudits = dataValueAuditService.getDataValueAudits(Lists.newArrayList(dataElement), Lists.newArrayList(period), Lists.newArrayList(organisationUnit), categoryOptionCombo, attributeOptionCombo, null);
dataValue = dataValueService.getDataValue(dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo);
if (dataValue != null) {
User credentials = userService.getUserByUsername(dataValue.getStoredBy());
storedBy = credentials != null ? credentials.getName() : dataValue.getStoredBy();
}
if (dataElement.isFileType()) {
fileNames = new HashMap<String, String>();
dataValueAudits.removeIf(audit -> fileResourceService.getFileResource(audit.getValue()) == null);
dataValueAudits.stream().filter(audit -> audit != null).map(audit -> fileResourceService.getFileResource(audit.getValue())).forEach(fr -> fileNames.put(fr.getUid(), fr.getName()));
}
historyInvalid = dataElementHistory == null;
minMaxInvalid = !dataElement.getValueType().isNumeric();
commentOptionSet = dataElement.getCommentOptionSet();
attributeOptionComboId = attributeOptionCombo.getUid();
return SUCCESS;
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STOREDBY in project dhis2-core by dhis2.
the class EventStoredByPreProcessor method process.
@Override
public void process(Event event, WorkContext ctx) {
final String storedBy = EventUtils.getValidUsername(event.getStoredBy(), ctx.getImportOptions());
event.setStoredBy(storedBy);
Set<DataValue> dataValues = event.getDataValues();
for (DataValue dataValue : dataValues) {
dataValue.setStoredBy(storedBy);
}
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STOREDBY in project dhis2-core by dhis2.
the class AbstractTrackedEntityInstanceService method addAttributeValues.
private void addAttributeValues(TrackedEntityInstance dtoEntityInstance, org.hisp.dhis.trackedentity.TrackedEntityInstance daoEntityInstance, User user) {
for (Attribute dtoAttribute : dtoEntityInstance.getAttributes()) {
TrackedEntityAttribute daoEntityAttribute = trackedEntityAttributeService.getTrackedEntityAttribute(dtoAttribute.getAttribute());
if (daoEntityAttribute != null) {
TrackedEntityAttributeValue daoAttributeValue = new TrackedEntityAttributeValue();
daoAttributeValue.setEntityInstance(daoEntityInstance);
daoAttributeValue.setValue(dtoAttribute.getValue());
daoAttributeValue.setAttribute(daoEntityAttribute);
daoEntityInstance.addAttributeValue(daoAttributeValue);
String storedBy = getStoredBy(dtoAttribute, new ImportSummary(), User.username(user, Constants.UNKNOWN));
daoAttributeValue.setStoredBy(storedBy);
trackedEntityAttributeValueService.addTrackedEntityAttributeValue(daoAttributeValue);
}
}
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STOREDBY in project dhis2-core by dhis2.
the class AbstractTrackedEntityInstanceService method updateAttributeValues.
private void updateAttributeValues(TrackedEntityInstance dtoEntityInstance, org.hisp.dhis.trackedentity.TrackedEntityInstance daoEntityInstance, Program program, User user) {
Set<String> incomingAttributes = new HashSet<>();
Map<String, TrackedEntityAttributeValue> teiAttributeToValueMap = getTeiAttributeValueMap(trackedEntityAttributeValueService.getTrackedEntityAttributeValues(daoEntityInstance));
for (Attribute dtoAttribute : dtoEntityInstance.getAttributes()) {
String storedBy = getStoredBy(dtoAttribute, new ImportSummary(), User.username(user, Constants.UNKNOWN));
TrackedEntityAttributeValue existingAttributeValue = teiAttributeToValueMap.get(dtoAttribute.getAttribute());
incomingAttributes.add(dtoAttribute.getAttribute());
if (// value exists
existingAttributeValue != null) {
if (// value
!existingAttributeValue.getValue().equals(dtoAttribute.getValue())) // is
// changed,
// do
// update
{
existingAttributeValue.setStoredBy(storedBy);
existingAttributeValue.setValue(dtoAttribute.getValue());
trackedEntityAttributeValueService.updateTrackedEntityAttributeValue(existingAttributeValue, user);
}
} else // value is new, do add
{
TrackedEntityAttribute daoEntityAttribute = trackedEntityAttributeService.getTrackedEntityAttribute(dtoAttribute.getAttribute());
TrackedEntityAttributeValue newAttributeValue = new TrackedEntityAttributeValue();
newAttributeValue.setStoredBy(storedBy);
newAttributeValue.setEntityInstance(daoEntityInstance);
newAttributeValue.setValue(dtoAttribute.getValue());
newAttributeValue.setAttribute(daoEntityAttribute);
daoEntityInstance.getTrackedEntityAttributeValues().add(newAttributeValue);
trackedEntityAttributeValueService.addTrackedEntityAttributeValue(newAttributeValue);
}
}
if (program != null) {
for (TrackedEntityAttribute att : program.getTrackedEntityAttributes()) {
TrackedEntityAttributeValue attVal = teiAttributeToValueMap.get(att.getUid());
if (attVal != null && !incomingAttributes.contains(att.getUid())) {
trackedEntityAttributeValueService.deleteTrackedEntityAttributeValue(attVal);
}
}
}
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STOREDBY 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;
}
Aggregations