public String check( Naked[] values) { final Consent usable = getValueAssociationInstance().getValueAssociation().isUsable(); return usable.isAllowed()?null:usable.getReason(); }
public ObjectData[] clearValue(final Session session, final String fieldIdentifier, final IdentityData target) { LOG.debug("request clearValue " + fieldIdentifier + " on " + target + " for " + session); NakedObject inObject = getPersistentNakedObject(session, target); ValueAssociation association = (ValueAssociation) inObject.getSpecification().getField(fieldIdentifier); if (!association.isVisible() || association.isUsable(inObject).isVetoed()) { throw new IllegalRequestException("can't modify field as not visible or editable"); } association.clearValue(inObject); return getUpdates(); }
public String check( Naked[] values) { final Consent usable = getValueAssociationInstance().getValueAssociation().isUsable(getValueAssociationInstance().getNakedObject()); return usable.isAllowed()?null:usable.getReason(); }
public ObjectData[] setValue( final Session session, final String fieldIdentifier, final IdentityData target, final ValueData value) { Assert.assertNotNull(value); LOG.debug("request setValue " + fieldIdentifier + " on " + target + " with " + value + " for " + session); NakedObject inObject = getPersistentNakedObject(session, target); ValueAssociation association = (ValueAssociation) inObject.getSpecification().getField(fieldIdentifier); if (!association.isVisible() || association.isUsable(inObject).isVetoed()) { throw new IllegalRequestException("can't modify field as not visible or editable"); } NakedValue fieldValue = (NakedValue) association.get(inObject); if (fieldValue != null) { // /byte[] encodedString = // NakedObjectsContext.getObjectLoader().createAdapterForValue(value).asEncodedString(); fieldValue.restoreFromEncodedString(value.getEncodedValue()); } NakedValue valueAdapter = NakedObjectsContext.getObjectLoader().createValueInstance(association.getSpecification()); valueAdapter.restoreFromEncodedString(value.getEncodedValue()); association.setValue(inObject, valueAdapter); return getUpdates(); }
public void testSetAssociationFailsWhenUnavailable() { associationControl.expectAndReturn(association.getId(), "name"); // the field is authorised, but not available associationControl.expectAndReturn(association.isVisible(), true); associationControl.expectAndReturn(association.isUsable(movieAdapter), Veto.DEFAULT); replay(); try { server.setValue(session, "name", movieData, new DummyValueData("test data")); fail(); } catch (IllegalRequestException expected) { assertEquals("can't modify field as not visible or editable", expected.getMessage()); } verify(); }
public void testSetValue() { associationControl.expectAndReturn(association.getSpecification(), new TestSpecification()); // the field must be authorised and available associationControl.expectAndReturn(association.getId(), "name"); associationControl.expectAndReturn(association.isVisible(), true); associationControl.expectAndReturn(association.isUsable(movieAdapter), Allow.DEFAULT); // the value adapter is accessed and then changed associationControl.expectAndReturn(association.get(movieAdapter), stringAdapter); // after checking association is asked to do setting association.setValue(movieAdapter, new TestValueAdapter("name of movie")); replay(); ObjectData[] updates = server.setValue(session, "name", movieData, new DummyValueData("name of movie")); verify(); assertEquals("name of movie", stringAdapter.stringValue()); assertEquals(0, updates.length); }