for (final ObjectAssociation association : properties) {
final OneToOneAssociation property = (OneToOneAssociation) association;
final ObjectSpecification propertySpec = property.getSpecification();
final String id = property.getId();
final JsonRepresentation propertyRepr = propertiesList.getRepresentation(id);
final Consent visibility = property.isVisible(resourceContext.getAuthenticationSession() , objectAdapter, resourceContext.getWhere());
final Consent usability = property.isUsable(resourceContext.getAuthenticationSession() , objectAdapter, resourceContext.getWhere());
final boolean invisible = visibility.isVetoed();
final boolean disabled = usability.isVetoed();
final boolean valueProvided = propertyRepr != null;
if(!valueProvided) {
// no value provided
if(invisible || disabled) {
// that's ok, indeed expected
continue;
}
if (!property.isMandatory()) {
// optional, so also not a problem
continue;
}
// otherwise, is an error.
final String invalidReason = propertiesList.getString("x-ro-invalidReason");
if(invalidReason != null) {
propertiesList.mapPut("x-ro-invalidReason", invalidReason + "; " + property.getName());
} else {
propertiesList.mapPut("x-ro-invalidReason", "Mandatory field(s) missing: " + property.getName());
}
allOk = false;
continue;
} else {
// value has been provided
if (invisible) {
// silently ignore; don't want to acknowledge the existence of this property to the caller
continue;
}
if (disabled) {
// not allowed to update
propertyRepr.mapPut("invalidReason", usability.getReason());
allOk = false;
continue;
}
// ok, we have a value, and the property is not invisible, and is not disabled
final ObjectAdapter valueAdapter;
try {
valueAdapter = objectAdapterFor(resourceContext, propertySpec, propertyRepr);
} catch(IllegalArgumentException ex) {
propertyRepr.mapPut("invalidReason", ex.getMessage());
allOk = false;
continue;
}
// check if the proposed value is valid
final Consent validity = property.isAssociationValid(objectAdapter, valueAdapter);
if (validity.isAllowed()) {
try {
property.set(objectAdapter, valueAdapter);
} catch (final IllegalArgumentException ex) {
propertyRepr.mapPut("invalidReason", ex.getMessage());
allOk = false;
}
} else {
propertyRepr.mapPut("invalidReason", validity.getReason());
allOk = false;
}
}
}