use of org.hisp.dhis.tracker.domain.Attribute in project dhis2-core by dhis2.
the class AssignValueImplementer method isTheSameValue.
private boolean isTheSameValue(EnrollmentActionRule actionRule, TrackerPreheat preheat) {
TrackedEntityAttribute attribute = preheat.get(TrackedEntityAttribute.class, actionRule.getField());
String value = actionRule.getValue();
Optional<Attribute> optionalAttribute = actionRule.getAttributes().stream().filter(at -> at.getAttribute().equals(actionRule.getField())).findAny();
if (optionalAttribute.isPresent()) {
return areEquals(value, optionalAttribute.get().getValue(), attribute.getValueType());
}
return false;
}
use of org.hisp.dhis.tracker.domain.Attribute in project dhis2-core by dhis2.
the class LastUpdateImportTest method shouldUpdateTeiIfTeiIsUpdated.
@Test
void shouldUpdateTeiIfTeiIsUpdated() throws IOException {
TrackerImportParams trackerImportParams = fromJson("tracker/single_tei.json", user.getUid());
trackerImportParams.setImportStrategy(TrackerImportStrategy.UPDATE);
Attribute attribute = new Attribute();
attribute.setAttribute("toUpdate000");
attribute.setValue("value");
trackedEntity.setAttributes(Collections.singletonList(attribute));
Date lastUpdateBefore = trackedEntityInstanceService.getTrackedEntityInstance(trackedEntity.getTrackedEntity()).getLastUpdated();
assertNoImportErrors(trackerImportService.importTracker(trackerImportParams));
assertTrue(manager.get(TrackedEntityInstance.class, trackedEntity.getTrackedEntity()).getLastUpdated().getTime() > lastUpdateBefore.getTime());
}
use of org.hisp.dhis.tracker.domain.Attribute in project dhis2-core by dhis2.
the class AbstractTrackerPersister method handleTrackedEntityAttributeValues.
protected void handleTrackedEntityAttributeValues(Session session, TrackerPreheat preheat, List<Attribute> payloadAttributes, TrackedEntityInstance trackedEntityInstance) {
if (payloadAttributes.isEmpty()) {
return;
}
Map<String, TrackedEntityAttributeValue> attributeValueByUid = trackedEntityInstance.getTrackedEntityAttributeValues().stream().collect(Collectors.toMap(teav -> teav.getAttribute().getUid(), Function.identity()));
payloadAttributes.forEach(attribute -> {
// We cannot get the value from attributeToStore because it uses
// encryption logic, so we need to use the one from payload
boolean isDelete = StringUtils.isEmpty(attribute.getValue());
TrackedEntityAttributeValue trackedEntityAttributeValue = attributeValueByUid.get(attribute.getAttribute());
boolean isUpdated = false;
boolean isNew = Objects.isNull(trackedEntityAttributeValue);
if (isDelete && isNew) {
return;
}
if (isDelete) {
delete(session, preheat, trackedEntityAttributeValue, trackedEntityInstance);
} else {
if (!isNew) {
isUpdated = !trackedEntityAttributeValue.getPlainValue().equals(attribute.getValue());
}
trackedEntityAttributeValue = Optional.ofNullable(trackedEntityAttributeValue).orElseGet(() -> new TrackedEntityAttributeValue().setAttribute(getTrackedEntityAttributeFromPreheat(preheat, attribute.getAttribute())).setEntityInstance(trackedEntityInstance)).setStoredBy(attribute.getStoredBy()).setValue(attribute.getValue());
saveOrUpdate(session, preheat, isNew, trackedEntityInstance, trackedEntityAttributeValue, isUpdated);
}
handleReservedValue(trackedEntityAttributeValue);
});
}
use of org.hisp.dhis.tracker.domain.Attribute in project dhis2-core by dhis2.
the class EnrollmentAttributeValidationHook method validateEnrollment.
@Override
public void validateEnrollment(ValidationErrorReporter reporter, Enrollment enrollment) {
TrackerImportValidationContext context = reporter.getValidationContext();
Program program = context.getProgram(enrollment.getProgram());
checkNotNull(program, TrackerImporterAssertErrors.PROGRAM_CANT_BE_NULL);
TrackedEntityInstance tei = context.getTrackedEntityInstance(enrollment.getTrackedEntity());
OrganisationUnit orgUnit = context.getOrganisationUnit(getOrgUnitUidFromTei(context, enrollment.getTrackedEntity()));
Map<String, String> attributeValueMap = Maps.newHashMap();
for (Attribute attribute : enrollment.getAttributes()) {
validateRequiredProperties(reporter, enrollment, attribute, program);
TrackedEntityAttribute teAttribute = context.getTrackedEntityAttribute(attribute.getAttribute());
if (attribute.getAttribute() != null && attribute.getValue() != null && teAttribute != null) {
attributeValueMap.put(attribute.getAttribute(), attribute.getValue());
validateAttrValueType(reporter, enrollment, attribute, teAttribute);
validateOptionSet(reporter, enrollment, teAttribute, attribute.getValue());
validateAttributeUniqueness(reporter, enrollment, attribute.getValue(), teAttribute, tei, orgUnit);
}
}
validateMandatoryAttributes(reporter, program, attributeValueMap, enrollment);
}
use of org.hisp.dhis.tracker.domain.Attribute in project dhis2-core by dhis2.
the class EnrollmentAttributeValidationHook method validateRequiredProperties.
protected void validateRequiredProperties(ValidationErrorReporter reporter, Enrollment enrollment, Attribute attribute, Program program) {
reporter.addErrorIfNull(attribute.getAttribute(), enrollment, E1075, attribute);
Optional<ProgramTrackedEntityAttribute> optionalTrackedAttr = program.getProgramAttributes().stream().filter(pa -> pa.getAttribute().getUid().equals(attribute.getAttribute()) && pa.isMandatory()).findFirst();
if (optionalTrackedAttr.isPresent()) {
reporter.addErrorIfNull(attribute.getValue(), enrollment, E1076, TrackedEntityAttribute.class.getSimpleName(), attribute.getAttribute());
}
if (attribute.getAttribute() != null) {
TrackedEntityAttribute teAttribute = reporter.getValidationContext().getTrackedEntityAttribute(attribute.getAttribute());
reporter.addErrorIfNull(teAttribute, enrollment, E1006, attribute.getAttribute());
}
}
Aggregations