use of org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams in project dhis2-core by dhis2.
the class TrackedEntityInstanceSupportService method getTrackedEntityInstanceParams.
public TrackedEntityInstanceParams getTrackedEntityInstanceParams(List<String> fields) {
String joined = Joiner.on("").join(fields);
if (joined.contains("*")) {
return TrackedEntityInstanceParams.TRUE;
}
TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
if (joined.contains("relationships")) {
params.setIncludeRelationships(true);
}
if (joined.contains("enrollments")) {
params.setIncludeEnrollments(true);
}
if (joined.contains("events")) {
params.setIncludeEvents(true);
}
if (joined.contains("programOwners")) {
params.setIncludeProgramOwners(true);
}
return params;
}
use of org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams in project dhis2-core by dhis2.
the class TrackedEntityInstanceSupportService method getTrackedEntityInstance.
@SneakyThrows
public TrackedEntityInstance getTrackedEntityInstance(String id, String pr, List<String> fields) {
User user = currentUserService.getCurrentUser();
TrackedEntityInstanceParams trackedEntityInstanceParams = getTrackedEntityInstanceParams(fields);
TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(id, trackedEntityInstanceParams);
if (trackedEntityInstance == null) {
throw new NotFoundException("TrackedEntityInstance", id);
}
if (pr != null) {
Program program = programService.getProgram(pr);
if (program == null) {
throw new NotFoundException("Program", pr);
}
List<String> errors = trackerAccessManager.canRead(user, instanceService.getTrackedEntityInstance(trackedEntityInstance.getTrackedEntityInstance()), program, false);
if (!errors.isEmpty()) {
if (program.getAccessLevel() == AccessLevel.CLOSED) {
throw new WebMessageException(unauthorized(TrackerOwnershipManager.PROGRAM_ACCESS_CLOSED));
}
throw new WebMessageException(unauthorized(TrackerOwnershipManager.OWNERSHIP_ACCESS_DENIED));
}
if (trackedEntityInstanceParams.isIncludeProgramOwners()) {
List<ProgramOwner> filteredProgramOwners = trackedEntityInstance.getProgramOwners().stream().filter(tei -> tei.getProgram().equals(pr)).collect(Collectors.toList());
trackedEntityInstance.setProgramOwners(filteredProgramOwners);
}
} else {
// return only tracked entity type attributes
TrackedEntityType trackedEntityType = trackedEntityTypeService.getTrackedEntityType(trackedEntityInstance.getTrackedEntityType());
if (trackedEntityType != null) {
List<String> tetAttributes = trackedEntityType.getTrackedEntityAttributes().stream().map(TrackedEntityAttribute::getUid).collect(Collectors.toList());
trackedEntityInstance.setAttributes(trackedEntityInstance.getAttributes().stream().filter(att -> tetAttributes.contains(att.getAttribute())).collect(Collectors.toList()));
}
}
return trackedEntityInstance;
}
use of org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams in project dhis2-core by dhis2.
the class TrackedEntityInstanceAttributesAggregateAclTest method verifyTeiCanBeAccessedWhenDATA_READPublicAccessOnTrackedEntityType.
@Test
void verifyTeiCanBeAccessedWhenDATA_READPublicAccessOnTrackedEntityType() {
final String tetUid = CodeGenerator.generateUid();
doInTransaction(() -> {
TrackedEntityType trackedEntityTypeZ = createTrackedEntityType('Z');
trackedEntityTypeZ.setUid(tetUid);
trackedEntityTypeZ.setName("TrackedEntityTypeZ" + trackedEntityTypeZ.getUid());
trackedEntityTypeService.addTrackedEntityType(trackedEntityTypeZ);
// When saving the trackedEntityType using addTrackedEntityType, the
// public access value is ignored
// therefore we need to update the previously saved TeiType
final TrackedEntityType trackedEntityType = trackedEntityTypeService.getTrackedEntityType(trackedEntityTypeZ.getUid());
trackedEntityType.setPublicAccess(DATA_READ);
trackedEntityTypeService.updateTrackedEntityType(trackedEntityType);
this.persistTrackedEntityInstance(ImmutableMap.of("trackedEntityType", trackedEntityType));
this.persistTrackedEntityInstance(ImmutableMap.of("trackedEntityType", trackedEntityType));
this.persistTrackedEntityInstance();
this.persistTrackedEntityInstance();
});
final TrackedEntityType trackedEntityType = trackedEntityTypeService.getTrackedEntityType(tetUid);
TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
queryParams.setTrackedEntityType(trackedEntityType);
queryParams.setIncludeAllAttributes(true);
TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(trackedEntityInstances, hasSize(2));
}
use of org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams in project dhis2-core by dhis2.
the class TrackedEntityInstanceAttributesAggregateTest method testTrackedEntityInstanceIncludeSpecificProtectedProgram.
@Test
void testTrackedEntityInstanceIncludeSpecificProtectedProgram() {
populatePrerequisites(false);
TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
queryParams.setProgram(programB);
TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertAttributes(trackedEntityInstances.get(0).getAttributes(), "A", "B", "E");
}
use of org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams in project dhis2-core by dhis2.
the class TrackedEntityInstanceAttributesAggregateTest method testTrackedEntityInstanceIncludeAllAttributes.
@Test
void testTrackedEntityInstanceIncludeAllAttributes() {
populatePrerequisites(false);
TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
queryParams.setTrackedEntityType(trackedEntityTypeA);
queryParams.setIncludeAllAttributes(true);
TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertAttributes(trackedEntityInstances.get(0).getAttributes(), "A", "B", "C", "E");
}
Aggregations