use of org.hisp.dhis.relationship.RelationshipItem in project dhis2-core by dhis2.
the class TranslationServiceTest method testFormNameTranslationForRelationShip.
@Test
void testFormNameTranslationForRelationShip() {
RelationshipType relationshipType = createRelationshipType('A');
OrganisationUnit organisationUnit = createOrganisationUnit('A');
TrackedEntityAttribute attribute = createTrackedEntityAttribute('A');
manager.save(relationshipType);
manager.save(organisationUnit);
manager.save(attribute);
TrackedEntityInstance trackedEntityInstance = createTrackedEntityInstance('A', organisationUnit, attribute);
manager.save(trackedEntityInstance);
Relationship relationship = new Relationship();
RelationshipItem from = new RelationshipItem();
from.setTrackedEntityInstance(trackedEntityInstance);
RelationshipItem to = new RelationshipItem();
to.setTrackedEntityInstance(trackedEntityInstance);
relationship.setFrom(from);
relationship.setTo(to);
relationship.setRelationshipType(relationshipType);
relationship.setKey(RelationshipUtils.generateRelationshipKey(relationship));
relationship.setInvertedKey(RelationshipUtils.generateRelationshipInvertedKey(relationship));
manager.save(relationship);
String translatedValue = "RelationShip FormName Translated";
Set<Translation> translations = new HashSet<>(relationship.getTranslations());
translations.add(new Translation(locale.getLanguage(), "FORM_NAME", translatedValue));
manager.updateTranslations(relationship, translations);
assertEquals(translatedValue, relationship.getDisplayFormName());
}
use of org.hisp.dhis.relationship.RelationshipItem in project dhis2-core by dhis2.
the class RelationshipUtilsTest method testGenerateRelationshipInvertedKey.
@Test
void testGenerateRelationshipInvertedKey() {
RelationshipItem from = new RelationshipItem();
RelationshipItem to = new RelationshipItem();
from.setTrackedEntityInstance(teiA);
to.setTrackedEntityInstance(teiB);
Relationship relationship = new Relationship();
relationship.setRelationshipType(relationshipType);
relationship.setFrom(from);
relationship.setTo(to);
String invertedKey = relationshipType.getUid() + "_" + teiB.getUid() + "_" + teiA.getUid();
assertEquals(invertedKey, RelationshipUtils.generateRelationshipInvertedKey(relationship));
}
use of org.hisp.dhis.relationship.RelationshipItem in project dhis2-core by dhis2.
the class MaintenanceServiceTest method testDeleteSoftDeletedProgramInstanceLinkedToARelationshipItem.
@Test
void testDeleteSoftDeletedProgramInstanceLinkedToARelationshipItem() {
RelationshipType rType = createRelationshipType('A');
rType.getFromConstraint().setRelationshipEntity(RelationshipEntity.PROGRAM_INSTANCE);
rType.getFromConstraint().setProgram(program);
rType.getToConstraint().setRelationshipEntity(RelationshipEntity.TRACKED_ENTITY_INSTANCE);
rType.getFromConstraint().setTrackedEntityType(entityInstance.getTrackedEntityType());
relationshipTypeService.addRelationshipType(rType);
Relationship r = new Relationship();
RelationshipItem rItem1 = new RelationshipItem();
rItem1.setProgramInstance(programInstance);
RelationshipItem rItem2 = new RelationshipItem();
rItem2.setTrackedEntityInstance(entityInstance);
r.setFrom(rItem1);
r.setTo(rItem2);
r.setRelationshipType(rType);
r.setKey(RelationshipUtils.generateRelationshipKey(r));
r.setInvertedKey(RelationshipUtils.generateRelationshipInvertedKey(r));
relationshipService.addRelationship(r);
assertNotNull(programInstanceService.getProgramInstance(programInstance.getId()));
assertNotNull(relationshipService.getRelationship(r.getId()));
programInstanceService.deleteProgramInstance(programInstance);
assertNull(programInstanceService.getProgramInstance(programInstance.getId()));
assertNull(relationshipService.getRelationship(r.getId()));
assertTrue(programInstanceService.programInstanceExistsIncludingDeleted(programInstance.getUid()));
maintenanceService.deleteSoftDeletedProgramInstances();
assertFalse(programInstanceService.programInstanceExistsIncludingDeleted(programInstance.getUid()));
}
use of org.hisp.dhis.relationship.RelationshipItem in project dhis2-core by dhis2.
the class DeduplicationHelper method getMergeableRelationships.
private List<String> getMergeableRelationships(TrackedEntityInstance original, TrackedEntityInstance duplicate) {
List<String> relationships = new ArrayList<>();
for (RelationshipItem ri : duplicate.getRelationshipItems()) {
TrackedEntityInstance from = ri.getRelationship().getFrom().getTrackedEntityInstance();
TrackedEntityInstance to = ri.getRelationship().getTo().getTrackedEntityInstance();
if ((from != null && from.getUid().equals(original.getUid())) || (to != null && to.getUid().equals(original.getUid()))) {
continue;
}
boolean duplicateRelationship = false;
for (RelationshipItem ri2 : original.getRelationshipItems()) {
TrackedEntityInstance originalFrom = ri2.getRelationship().getFrom().getTrackedEntityInstance();
TrackedEntityInstance originalTo = ri2.getRelationship().getTo().getTrackedEntityInstance();
if ((originalFrom != null && originalFrom.getUid().equals(duplicate.getUid())) || (originalTo != null && originalTo.getUid().equals(duplicate.getUid()))) {
continue;
}
if (isSameRelationship(ri2.getRelationship(), ri.getRelationship())) {
duplicateRelationship = true;
break;
}
}
if (duplicateRelationship) {
continue;
}
relationships.add(ri.getRelationship().getUid());
}
return relationships;
}
use of org.hisp.dhis.relationship.RelationshipItem in project dhis2-core by dhis2.
the class DefaultTrackerAccessManager method canRead.
@Override
public List<String> canRead(User user, Relationship relationship) {
List<String> errors = new ArrayList<>();
RelationshipType relationshipType;
RelationshipItem from;
RelationshipItem to;
// always allow if user == null (internal process) or user is superuser
if (user == null || user.isSuper() || relationship == null) {
return errors;
}
relationshipType = relationship.getRelationshipType();
if (!aclService.canDataRead(user, relationshipType)) {
errors.add("User has no data read access to relationshipType: " + relationshipType.getUid());
}
from = relationship.getFrom();
to = relationship.getTo();
errors.addAll(canRead(user, from.getTrackedEntityInstance()));
errors.addAll(canRead(user, from.getProgramInstance(), false));
errors.addAll(canRead(user, from.getProgramStageInstance(), false));
errors.addAll(canRead(user, to.getTrackedEntityInstance()));
errors.addAll(canRead(user, to.getProgramInstance(), false));
errors.addAll(canRead(user, to.getProgramStageInstance(), false));
return errors;
}
Aggregations