use of org.hisp.dhis.trackedentity.TrackedEntityProgramOwner in project dhis2-core by dhis2.
the class AbstractTrackedEntityInstanceService method getTei.
private TrackedEntityInstance getTei(org.hisp.dhis.trackedentity.TrackedEntityInstance daoTrackedEntityInstance, Set<TrackedEntityAttribute> readableAttributes, TrackedEntityInstanceParams params, User user) {
if (daoTrackedEntityInstance == null) {
return null;
}
TrackedEntityInstance trackedEntityInstance = new TrackedEntityInstance();
trackedEntityInstance.setTrackedEntityInstance(daoTrackedEntityInstance.getUid());
trackedEntityInstance.setOrgUnit(daoTrackedEntityInstance.getOrganisationUnit().getUid());
trackedEntityInstance.setTrackedEntityType(daoTrackedEntityInstance.getTrackedEntityType().getUid());
trackedEntityInstance.setCreated(DateUtils.getIso8601NoTz(daoTrackedEntityInstance.getCreated()));
trackedEntityInstance.setCreatedAtClient(DateUtils.getIso8601NoTz(daoTrackedEntityInstance.getCreatedAtClient()));
trackedEntityInstance.setLastUpdated(DateUtils.getIso8601NoTz(daoTrackedEntityInstance.getLastUpdated()));
trackedEntityInstance.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(daoTrackedEntityInstance.getLastUpdatedAtClient()));
trackedEntityInstance.setInactive(Optional.ofNullable(daoTrackedEntityInstance.isInactive()).orElse(false));
trackedEntityInstance.setGeometry(daoTrackedEntityInstance.getGeometry());
trackedEntityInstance.setDeleted(daoTrackedEntityInstance.isDeleted());
trackedEntityInstance.setPotentialDuplicate(daoTrackedEntityInstance.isPotentialDuplicate());
trackedEntityInstance.setStoredBy(daoTrackedEntityInstance.getStoredBy());
trackedEntityInstance.setCreatedByUserInfo(daoTrackedEntityInstance.getCreatedByUserInfo());
trackedEntityInstance.setLastUpdatedByUserInfo(daoTrackedEntityInstance.getLastUpdatedByUserInfo());
if (daoTrackedEntityInstance.getGeometry() != null) {
Geometry geometry = daoTrackedEntityInstance.getGeometry();
FeatureType featureType = FeatureType.getTypeFromName(geometry.getGeometryType());
trackedEntityInstance.setFeatureType(featureType);
trackedEntityInstance.setCoordinates(GeoUtils.getCoordinatesFromGeometry(geometry));
}
if (params.isIncludeRelationships()) {
for (RelationshipItem relationshipItem : daoTrackedEntityInstance.getRelationshipItems()) {
org.hisp.dhis.relationship.Relationship daoRelationship = relationshipItem.getRelationship();
if (trackerAccessManager.canRead(user, daoRelationship).isEmpty()) {
Relationship relationship = relationshipService.getRelationship(relationshipItem.getRelationship(), RelationshipParams.FALSE, user);
trackedEntityInstance.getRelationships().add(relationship);
}
}
}
if (params.isIncludeEnrollments()) {
for (ProgramInstance programInstance : daoTrackedEntityInstance.getProgramInstances()) {
if (trackerAccessManager.canRead(user, programInstance, false).isEmpty() && (params.isIncludeDeleted() || !programInstance.isDeleted())) {
trackedEntityInstance.getEnrollments().add(enrollmentService.getEnrollment(user, programInstance, params, true));
}
}
}
if (params.isIncludeProgramOwners()) {
for (TrackedEntityProgramOwner programOwner : daoTrackedEntityInstance.getProgramOwners()) {
trackedEntityInstance.getProgramOwners().add(new ProgramOwner(programOwner));
}
}
Set<TrackedEntityAttribute> readableAttributesCopy = filterOutSkipSyncAttributesIfApplies(params, trackedEntityInstance, readableAttributes);
for (TrackedEntityAttributeValue attributeValue : daoTrackedEntityInstance.getTrackedEntityAttributeValues()) {
if (readableAttributesCopy.contains(attributeValue.getAttribute())) {
Attribute attribute = new Attribute();
attribute.setCreated(DateUtils.getIso8601NoTz(attributeValue.getCreated()));
attribute.setLastUpdated(DateUtils.getIso8601NoTz(attributeValue.getLastUpdated()));
attribute.setDisplayName(attributeValue.getAttribute().getDisplayName());
attribute.setAttribute(attributeValue.getAttribute().getUid());
attribute.setValueType(attributeValue.getAttribute().getValueType());
attribute.setCode(attributeValue.getAttribute().getCode());
attribute.setValue(attributeValue.getValue());
attribute.setStoredBy(attributeValue.getStoredBy());
attribute.setSkipSynchronization(attributeValue.getAttribute().getSkipSynchronization());
trackedEntityInstance.getAttributes().add(attribute);
}
}
return trackedEntityInstance;
}
use of org.hisp.dhis.trackedentity.TrackedEntityProgramOwner in project dhis2-core by dhis2.
the class OwnershipTest method testProgramOwnerWhenEnrolled.
@Test
void testProgramOwnerWhenEnrolled() throws IOException {
TrackerImportParams enrollmentParams = fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid());
List<TrackedEntityInstance> teis = manager.getAll(TrackedEntityInstance.class);
assertEquals(1, teis.size());
TrackedEntityInstance tei = teis.get(0);
assertNotNull(tei.getProgramOwners());
Set<TrackedEntityProgramOwner> tepos = tei.getProgramOwners();
assertEquals(1, tepos.size());
TrackedEntityProgramOwner tepo = tepos.iterator().next();
assertNotNull(tepo.getEntityInstance());
assertNotNull(tepo.getProgram());
assertNotNull(tepo.getOrganisationUnit());
assertEquals(enrollmentParams.getEnrollments().get(0).getProgram(), tepo.getProgram().getUid());
assertEquals(enrollmentParams.getEnrollments().get(0).getOrgUnit(), tepo.getOrganisationUnit().getUid());
assertEquals(enrollmentParams.getEnrollments().get(0).getTrackedEntity(), tepo.getEntityInstance().getUid());
}
Aggregations