@Override public String parseAndValidate( final ScalarModel scalarModel, final String proposedPojoAsStr) { final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty(); ParseableFacet parseableFacet = property.getFacet(ParseableFacet.class); if (parseableFacet == null) { parseableFacet = property.getSpecification().getFacet(ParseableFacet.class); } try { final ObjectAdapter parentAdapter = scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK); final ObjectAdapter currentValue = property.get(parentAdapter); Localization localization = IsisContext.getLocalization(); final ObjectAdapter proposedAdapter = parseableFacet.parseTextEntry(currentValue, proposedPojoAsStr, localization); final Consent valid = property.isAssociationValid(parentAdapter, proposedAdapter); return valid.isAllowed() ? null : valid.getReason(); } catch (final ConcurrencyException ex) { // disregard concurrency exceptions because will pick up at the IFormValidator level // rather // than each individual property. return null; } catch (final Exception ex) { return ex.getLocalizedMessage(); } }
@Override public String validate(final ScalarModel scalarModel, final ObjectAdapter proposedAdapter) { final ObjectAdapter parentAdapter = scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK); final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty(); try { final Consent valid = property.isAssociationValid(parentAdapter, proposedAdapter); return valid.isAllowed() ? null : valid.getReason(); } catch (final Exception ex) { return ex.getLocalizedMessage(); } }