use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.
the class ProgramInstanceSupplier method get.
public Map<String, ProgramInstance> get(ImportOptions importOptions, Map<String, Pair<TrackedEntityInstance, Boolean>> teiMap, List<Event> events) {
if (events == null) {
return new HashMap<>();
}
// Collect all the program instance UIDs to pass as SQL query argument
Set<String> programInstanceUids = events.stream().filter(e -> StringUtils.isNotEmpty(e.getEnrollment())).map(Event::getEnrollment).collect(Collectors.toSet());
Map<String, ProgramInstance> programInstances = new HashMap<>();
if (!programInstanceUids.isEmpty()) {
// Create a bi-directional map enrollment uid -> event uid
Multimap<String, String> programInstanceToEvent = HashMultimap.create();
for (Event event : events) {
programInstanceToEvent.put(event.getEnrollment(), event.getUid());
}
// Collect all the Program Stage Instances specified in the Events
// (enrollment
// property)
programInstances = getProgramInstancesByUid(importOptions, events, programInstanceToEvent, programInstanceUids);
}
mapExistingEventsToProgramInstances(importOptions, events, programInstances);
mapEventsToProgramInstanceByTei(importOptions, events, programInstances, teiMap);
return programInstances;
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.
the class TrackedEntityInstanceSupplier method get.
@Override
public Map<String, Pair<TrackedEntityInstance, Boolean>> get(ImportOptions importOptions, List<Event> events) {
if (events == null) {
return new HashMap<>();
}
// @formatter:off
// Collect all the org unit uids to pass as SQL query argument
Set<String> teiUids = events.stream().filter(e -> e.getTrackedEntityInstance() != null).map(Event::getTrackedEntityInstance).collect(Collectors.toSet());
if (isEmpty(teiUids)) {
return new HashMap<>();
}
// Create a map: tei uid -> List [event uid]
Multimap<String, String> teiToEvent = HashMultimap.create();
for (Event event : events) {
teiToEvent.put(event.getTrackedEntityInstance(), event.getUid());
}
//
// Get all TEI associated to the events
//
Map<String, TrackedEntityInstance> teiMap = getTrackedEntityInstances(teiUids, teiToEvent);
Map<String, Pair<TrackedEntityInstance, Boolean>> result = new HashMap<>();
//
for (String event : teiMap.keySet()) {
TrackedEntityInstance tei = teiMap.get(event);
result.put(event, Pair.of(tei, !importOptions.isSkipLastUpdated() ? aclService.canUpdate(importOptions.getUser(), tei) : null));
}
return result;
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.
the class AssignedUserSupplier method get.
@Override
public Map<String, User> get(ImportOptions importOptions, List<Event> events) {
// @formatter:off
// Collect all the "assigned user" uids to pass as SQL query argument
Set<String> userUids = events.stream().filter(e -> StringUtils.isNotEmpty(e.getAssignedUser())).map(Event::getAssignedUser).collect(Collectors.toSet());
// Create a map user -> event
Multimap<String, String> userToEvent = HashMultimap.create();
for (Event event : events) {
userToEvent.put(event.getAssignedUser(), event.getUid());
}
if (!userUids.isEmpty()) {
final String sql = "select userinfoid, uid, code from userinfo " + "where uid in (:ids)";
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("ids", userUids);
return jdbcTemplate.query(sql, parameters, (ResultSet rs) -> {
Map<String, User> results = new HashMap<>();
while (rs.next()) {
User user = new User();
user.setId(rs.getLong("userinfoid"));
user.setUid(rs.getString("uid"));
user.setCode(rs.getString("code"));
for (String event : userToEvent.get(user.getUid())) {
results.put(event, user);
}
}
return results;
});
}
return new HashMap<>();
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID 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;
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.
the class AbstractTrackedEntityInstanceService method checkAttributes.
private void checkAttributes(TrackedEntityInstance dtoEntityInstance, ImportOptions importOptions, ImportConflicts importConflicts, boolean teiExistsInDatabase) {
if (dtoEntityInstance.getAttributes().isEmpty()) {
return;
}
List<String> fileValues = new ArrayList<>();
org.hisp.dhis.trackedentity.TrackedEntityInstance daoEntityInstance = null;
if (teiExistsInDatabase) {
daoEntityInstance = teiService.getTrackedEntityInstance(dtoEntityInstance.getTrackedEntityInstance(), importOptions.getUser());
if (daoEntityInstance == null) {
return;
}
daoEntityInstance.getTrackedEntityAttributeValues().stream().filter(attrVal -> attrVal.getAttribute().getValueType().isFile()).forEach(attrVal -> fileValues.add(attrVal.getValue()));
}
for (Attribute attribute : dtoEntityInstance.getAttributes()) {
if (StringUtils.isNotEmpty(attribute.getValue())) {
// Cache was populated in prepareCaches, so I should hit the
// cache
TrackedEntityAttribute daoEntityAttribute = getTrackedEntityAttribute(importOptions.getIdSchemes(), attribute.getAttribute());
if (daoEntityAttribute == null) {
importConflicts.addConflict("Attribute.attribute", "Invalid attribute " + attribute.getAttribute());
continue;
}
if (attribute.getValue() != null && attribute.getValue().length() > TEA_VALUE_MAX_LENGTH) {
// We shorten the value to first 25 characters, since we
// dont want to post a 1200+ string back.
importConflicts.addConflict("Attribute.value", String.format("Value exceeds the character limit of %s characters: '%s...'", TEA_VALUE_MAX_LENGTH, attribute.getValue().substring(0, 25)));
}
if (daoEntityAttribute.isUnique()) {
// Cache was populated in prepareCaches, so I should hit the
// cache
OrganisationUnit organisationUnit = getOrganisationUnit(importOptions.getIdSchemes(), dtoEntityInstance.getOrgUnit());
checkAttributeUniquenessWithinScope(daoEntityInstance, daoEntityAttribute, attribute.getValue(), organisationUnit, importConflicts);
}
validateAttributeType(attribute, importOptions, importConflicts);
if (daoEntityAttribute.getValueType().isFile() && checkAssigned(attribute, fileValues)) {
importConflicts.addConflict("Attribute.value", String.format("File resource with uid '%s' has already been assigned to a different object", attribute.getValue()));
}
}
}
}
Aggregations