use of org.hisp.dhis.tracker.TrackerIdScheme in project dhis2-core by dhis2.
the class TrackerPreheat method getRelationship.
public Relationship getRelationship(TrackerIdScheme identifier, org.hisp.dhis.tracker.domain.Relationship relationship) {
if (!relationships.containsKey(identifier)) {
return null;
}
RelationshipType relationshipType = get(RelationshipType.class, relationship.getRelationshipType());
if (Objects.nonNull(relationshipType)) {
RelationshipKey relationshipKey = getRelationshipKey(relationship);
RelationshipKey inverseKey = null;
if (relationshipType.isBidirectional()) {
inverseKey = relationshipKey.inverseKey();
}
return Stream.of(relationshipKey, inverseKey).filter(Objects::nonNull).map(key -> relationships.get(identifier).get(key.asString())).filter(Objects::nonNull).findFirst().orElse(null);
}
return null;
}
use of org.hisp.dhis.tracker.TrackerIdScheme in project dhis2-core by dhis2.
the class ProgramInstancesWithAtLeastOneEventSupplier method preheatAdd.
@Override
public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) {
final Map<TrackerIdScheme, Map<String, ProgramInstance>> enrollmentsMap = preheat.getEnrollments();
final Map<String, ProgramInstance> enrollments = enrollmentsMap.getOrDefault(TrackerIdScheme.UID, new HashMap<>());
List<Long> programStageIds = enrollments.values().stream().map(BaseIdentifiableObject::getId).collect(Collectors.toList());
if (!programStageIds.isEmpty()) {
List<String> uids = new ArrayList<>();
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("ids", programStageIds);
jdbcTemplate.query(SQL, parameters, rs -> {
uids.add(rs.getString(COLUMN));
});
preheat.setProgramInstanceWithOneOrMoreNonDeletedEvent(uids);
}
}
use of org.hisp.dhis.tracker.TrackerIdScheme in project dhis2-core by dhis2.
the class AbstractSchemaStrategy method cacheAwareFetch.
@SuppressWarnings({ "unchecked", "rawtypes" })
private List<IdentifiableObject> cacheAwareFetch(User user, Schema schema, TrackerIdentifier identifier, List<String> ids, Class<? extends PreheatMapper> mapper) {
TrackerIdScheme idScheme = identifier.getIdScheme();
List<IdentifiableObject> objects;
final String cacheKey = buildCacheKey(schema);
if (// check if this strategy requires caching
isCacheable()) {
if (isLoadAllEntities(ids)) {
return map(cacheAndReturnLookupData(schema), mapper);
} else {
Map<String, IdentifiableObject> foundInCache = new HashMap<>();
for (String id : ids) {
// is the object reference by the given id in cache?
cache.get(cacheKey, id).ifPresent(identifiableObject -> foundInCache.put(id, identifiableObject));
}
// is there any object which was not found in cache?
if (ids.size() > foundInCache.size()) {
// remove from the list of ids the ids found in cache
ids.removeAll(foundInCache.keySet());
// execute the query, fetching only the ids which are not in
// cache
objects = map((List<IdentifiableObject>) queryService.query(buildQuery(schema, user, idScheme, ids)), mapper);
// put objects in query based on given scheme. If the key
// can't get resolved, send null to the
// cacheService, which will ignore the entry
objects.forEach(o -> cache.put(cacheKey, identifier.getIdentifier(o), o, getCacheTTL(), getCapacity()));
// add back the cached objects to the final list
objects.addAll(foundInCache.values());
} else {
objects = new ArrayList<>(foundInCache.values());
}
}
} else {
objects = isLoadAllEntities(ids) ? manager.getAll((Class<IdentifiableObject>) schema.getKlass()) : map((List<IdentifiableObject>) queryService.query(buildQuery(schema, user, idScheme, ids)), mapper);
}
return objects;
}
use of org.hisp.dhis.tracker.TrackerIdScheme in project dhis2-core by dhis2.
the class AbstractSchemaStrategy method queryForIdentifiableObjects.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void queryForIdentifiableObjects(TrackerPreheat preheat, Schema schema, TrackerIdentifier identifier, List<List<String>> splitList, Class<? extends PreheatMapper> mapper) {
TrackerIdScheme idScheme = identifier.getIdScheme();
for (List<String> ids : splitList) {
List<? extends IdentifiableObject> objects;
if (TrackerIdScheme.ATTRIBUTE.equals(idScheme)) {
Attribute attribute = new Attribute();
attribute.setUid(identifier.getValue());
objects = manager.getAllByAttributeAndValues((Class<? extends IdentifiableObject>) schema.getKlass(), attribute, ids);
} else {
objects = cacheAwareFetch(preheat.getUser(), schema, identifier, ids, mapper);
}
preheat.put(identifier, objects);
}
}
Aggregations