Package org.apache.isis.core.metamodel.consent

Examples of org.apache.isis.core.metamodel.consent.Consent


    public static boolean isVisible(final ObjectAdapter object, final ObjectAction action, Where where) {
        return action.isVisible(getAuthenticationSession(), object, where).isAllowed();
    }

    public static String isUsable(final ObjectAdapter object, final ObjectAction action, Where where) {
        final Consent usable = action.isUsable(getAuthenticationSession(), object, where);
        final boolean isUsable = getSession() != null && usable.isAllowed();
        return isUsable ? null : usable.getReason();
    }
View Full Code Here


    private void initializeFields(final RequestContext context, final ObjectAdapter object, final InputField[] formFields, final FormState entryState, final boolean includeUnusableFields) {
        for (final InputField formField : formFields) {
            final String fieldId = formField.getName();
            final ObjectAssociation field = object.getSpecification().getAssociation(fieldId);
            final AuthenticationSession session = IsisContext.getAuthenticationSession();
            final Consent usable = field.isUsable(session, object, where);
            final ObjectAdapter[] options = field.getChoices(object);
            FieldFactory.initializeField(context, object, field, options, field.isMandatory(), formField);

            final boolean isEditable = usable.isAllowed();
            if (!isEditable) {
                formField.setDescription(usable.getReason());
            }
            formField.setEditable(isEditable);
            final boolean hiddenField = field.isVisible(session, object, where).isVetoed();
            final boolean unusable = usable.isVetoed();
            final boolean hideAsUnusable = unusable && !includeUnusableFields;
            if (hiddenField || hideAsUnusable) {
                formField.setHidden(true);
            }
        }
View Full Code Here

                } else {
                    newEntry = "";
                }
            }
            final FieldEditState fieldState = formState.createField(fieldName, newEntry);
            Consent consent = null;

            if (!parameters2.get(i).isOptional() && newEntry.equals("")) {
                consent = new Veto(parameters2.get(i).getName() + " required");
                formState.setError("Not all fields have been set");

            } else if (parameters2.get(i).getSpecification().getFacet(ParseableFacet.class) != null) {
                try {
                    final ParseableFacet facet = parameters2.get(i).getSpecification().getFacet(ParseableFacet.class);
                    Localization localization = IsisContext.getLocalization();
                    final String message = parameters2.get(i).isValid(object, newEntry, localization);
                    if (message != null) {
                        consent = new Veto(message);
                        formState.setError("Not all fields are valid");
                    }
                    final ObjectAdapter entry = facet.parseTextEntry(null, newEntry, localization);
                    fieldState.setValue(entry);
                } catch (final TextEntryParseException e) {
                    consent = new Veto(e.getMessage());
                    formState.setError("Not all fields are valid");
                }
            } else {
                fieldState.setValue(newEntry == null ? null : context.getMappedObject(newEntry));
            }
            if (consent != null && consent.isVetoed()) {
                fieldState.setError(consent.getReason());
            }
        }

        if (formState.isValid()) {
            final ObjectAdapter[] parameters = getParameters(action, formState);
            final Consent consent = action.isProposedArgumentSetValid(object, parameters);
            if (consent != null && consent.isVetoed()) {
                formState.setError(consent.getReason());
            }
        }

        return formState;
    }
View Full Code Here

                    continue;
                }
            }
            final FieldEditState fieldState = formState.createField(fieldId, newEntry);

            Consent consent = null;
            if (field.isMandatory() && (newEntry.equals("") || newEntry.equals("NULL"))) {
                consent = new Veto(field.getName() + " required");
                formState.setError("Not all fields have been set");
            } else if (field.getSpecification().containsFacet(ParseableFacet.class)) {
                try {
                    final ParseableFacet facet = field.getSpecification().getFacet(ParseableFacet.class);
                    final ObjectAdapter originalValue = field.get(object);
                    Localization localization = IsisContext.getLocalization();
                    final ObjectAdapter newValue = facet.parseTextEntry(originalValue, newEntry, localization);
                    consent = ((OneToOneAssociation) field).isAssociationValid(object, newValue);
                    fieldState.setValue(newValue);
                } catch (final TextEntryParseException e) {
                    consent = new Veto(e.getMessage());
                    // formState.setError("Not all fields have been entered correctly");
                }

            } else {
                final ObjectAdapter associate = newEntry.equals("null") ? null : context.getMappedObject(newEntry);
                if (associate != null) {
                    IsisContext.getPersistenceSession().resolveImmediately(associate);
                }
                consent = ((OneToOneAssociation) field).isAssociationValid(object, associate);
                fieldState.setValue(associate);

            }
            if (consent.isVetoed()) {
                fieldState.setError(consent.getReason());
                formState.setError("Not all fields have been entered correctly");
            }
        }

        // TODO check the state of the complete object.
View Full Code Here

        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 = new JsonParserHelper(resourceContext, propertySpec).objectAdapterFor(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;
                }
            }
        }
View Full Code Here

        super(field, "Paste");
    }

    @Override
    public Consent disabled(final View view) {
        final Consent changable = view.canChangeValue();
        if (changable.isVetoed()) {
            return changable;
        } else {
            return changable.setDescription(String.format("Replace field content with '%s' from clipboard", getClipboard(view)));
        }
    }
View Full Code Here

        final AuthenticationSession authenticationSession = rendererContext.getAuthenticationSession();
        if (objectMember.isVisible(authenticationSession, objectAdapter, where).isVetoed()) {
            throwNotFoundException(memberId, memberType);
        }
        if (intent.isMutate()) {
            final Consent usable = objectMember.isUsable(authenticationSession, objectAdapter, where);
            if (usable.isVetoed()) {
                throw RestfulObjectsApplicationException.createWithMessage(RestfulResponse.HttpStatusCode.FORBIDDEN, usable.getReason());
            }
        }
        return objectMember;
    }
View Full Code Here

    }

    @Override
    public Consent disabled(final View view) {
        final ObjectAdapter value = getValue(view);
        final Consent consent = view.canChangeValue();
        if (consent.isVetoed()) {
            return consent;
        }
        final Consent canClear = field.canClear();
        if (canClear.isVetoed()) {
            // TODO: move logic into Facets.
            return new Veto(String.format("Can't clear %s values", value.getSpecification().getShortIdentifier()));
        }
        if (value == null || isEmpty(view)) {
            // TODO: move logic into Facets.
View Full Code Here

    }

    private ObjectAdapter validateAndParse(final String entryText) {
        final ObjectAdapter newValue = parse(entryText);
        final OneToOneAssociation objectAssociation = (OneToOneAssociation) field.getObjectAssociation();
        final Consent valid = objectAssociation.isAssociationValid(parent, newValue);
        if (valid.isVetoed()) {
            throw new InvalidEntryException(valid.getReason());
        }
        return newValue;
    }
View Full Code Here

        super(content, specification);
    }

    @Override
    public void dragIn(final ContentDrag drag) {
        final Consent consent = getContent().canDrop(drag.getSourceContent());
        final String description = getContent().getDescription();
        if (consent.isAllowed()) {
            getFeedbackManager().setAction(consent.getDescription() + " " + description);
            getState().setCanDrop();
        } else {
            getFeedbackManager().setAction(consent.getReason() + " " + description);
            getState().setCantDrop();
        }
        markDamaged();
    }
View Full Code Here

TOP

Related Classes of org.apache.isis.core.metamodel.consent.Consent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.