Package org.apache.isis.core.metamodel.spec.feature

Examples of org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation


        // title & Oid
        Element div = asDivTableObjectDetails(objectAdapter);
        xhtml.appendToBody(div);

        // collection name & contents
        final OneToManyAssociation collection = (OneToManyAssociation) association;

        div = xhtmlRenderer.div_p(collectionId, HtmlClass.COLLECTION);

        final Element ul = xhtmlRenderer.ul(HtmlClass.COLLECTION);
        div.appendChild(ul);

        final ObjectAdapter collectionObj = collection.get(objectAdapter);

        final CollectionFacet facet = CollectionFacetUtils.getCollectionFacetFromSpec(collectionObj);
        for (final Iterator<ObjectAdapter> iter = facet.iterator(collectionObj); iter.hasNext();) {
            final ObjectAdapter associatedNO = iter.next();
            ul.appendChild(toLiAHref(associatedNO));
View Full Code Here


            throw new WebApplicationException(responseOfGone("could not determine object"));
        }

        final ObjectSpecification noSpec = objectAdapter.getSpecification();

        final OneToManyAssociation collection = (OneToManyAssociation) noSpec.getAssociation(collectionId);

        ObjectAdapter proposedValueNO = null;
        proposedValueNO = getObjectAdapter(proposedValueOidStr);

        if (proposedValueNO == null) {
            throw new WebApplicationException(responseOfGone("could not determine proposed value"));
        }

        // validate
        final Consent consent =
            modification == CollectionModificationType.ADD_TO ? collection.isValidToAdd(objectAdapter, proposedValueNO)
                : collection.isValidToRemove(objectAdapter, proposedValueNO);
        if (consent.isVetoed()) {
            throw new WebApplicationException(responseOfBadRequest(consent));
        }

        // html template
        final XhtmlTemplate xhtml =
            new XhtmlTemplate(objectAdapter.titleString() + "." + collectionId, getServletRequest());
        xhtml.appendToBody(asDivIsisSession());
        xhtml.appendToBody(resourcesDiv());

        // title & Oid
        final Element div = asDivTableObjectDetails(objectAdapter);
        xhtml.appendToBody(div);

        // if valid, then set
        if (modification == CollectionModificationType.ADD_TO) {
            collection.addElement(objectAdapter, proposedValueNO);
        } else {
            collection.removeElement(objectAdapter, proposedValueNO);
        }

        return xhtml.toXML();
    }
View Full Code Here

        final ObjectAdapter onAdapter = performContext.getOnAdapter();
        final ObjectMember nakedObjectMember = performContext.getObjectMember();
        final CellBinding onMemberBinding = performContext.getPeer().getOnMemberBinding();

        final OneToManyAssociation otma = (OneToManyAssociation) nakedObjectMember;

        final CollectionAddToFacet addToFacet = nakedObjectMember.getFacet(CollectionAddToFacet.class);
        if (addToFacet == null) {
            throw ScenarioBoundValueException.current(onMemberBinding, "(cannot add to collection)");
        }

        // safe since guaranteed by superclass
        final CellBinding arg0Binding = performContext.getPeer().getArg0Binding();
        final ScenarioCell arg0Cell = arg0Binding.getCurrentCell();
        final String toAddAlias = arg0Cell.getText();

        final ObjectAdapter toAddAdapter = performContext.getPeer().getAliasRegistry().getAliased(toAddAlias);
        if (toAddAdapter == null) {
            throw ScenarioBoundValueException.current(arg0Binding, "(unknown alias)");
        }

        // validate argument
        otma.createValidateAddInteractionContext(getSession(), InteractionInvocationMethod.BY_USER, onAdapter,
            toAddAdapter);
        final Consent validToAdd = otma.isValidToAdd(onAdapter, toAddAdapter);
        if (validToAdd.isVetoed()) {
            throw ScenarioBoundValueException.current(arg0Binding, validToAdd.getReason());
        }

        // add
View Full Code Here

        @SuppressWarnings("unused")
        final ScenarioCell onMemberCell = onMemberBinding.getCurrentCell();

        final List<ScenarioCell> argumentCells = performContext.getArgumentCells();

        final OneToManyAssociation otma = (OneToManyAssociation) nakedObjectMember;

        // safe since guaranteed by superclass
        final CellBinding arg0Binding = performContext.getPeer().getArg0Binding();
        final ScenarioCell arg0Cell = argumentCells.get(0);
        final String toRemove = arg0Cell.getText();

        final CollectionRemoveFromFacet removeFromFacet = nakedObjectMember.getFacet(CollectionRemoveFromFacet.class);
        if (removeFromFacet == null) {
            throw ScenarioBoundValueException.current(onMemberBinding, "(cannot remove from collection)");
        }

        final ObjectAdapter toRemoveAdapter = performContext.getPeer().getAliasRegistry().getAliased(toRemove);
        if (toRemoveAdapter == null) {
            throw ScenarioBoundValueException.current(arg0Binding, "(unknown alias)");
        }

        // validate argument
        otma.createValidateAddInteractionContext(getSession(), InteractionInvocationMethod.BY_USER, onAdapter,
            toRemoveAdapter);
        final Consent validToRemove = otma.isValidToRemove(onAdapter, toRemoveAdapter);
        if (validToRemove.isVetoed()) {
            throw ScenarioBoundValueException.current(onMemberBinding, validToRemove.getReason());
        }

        // remove
View Full Code Here

    protected void doExecute(final Context context, final ViewPane content, final ObjectAdapter object,
        final String field) {
        final String id = context.mapObject(object);
        final ObjectSpecification specification = object.getSpecification();

        final OneToManyAssociation collection = (OneToManyAssociation) specification.getAssociation(field);

        IsisContext.getPersistenceSession().resolveField(object, collection);

        context.addCollectionFieldCrumb(collection.getName());
        content.add(context.getComponentFactory().createHeading(collection.getName()));
        final Table table = TableUtil.createTable(context, id, object, collection);
        content.add(table);
        if (collection.isUsable(IsisContext.getAuthenticationSession(), object).isAllowed()) {
            content.add(context.getComponentFactory().createAddOption(id, collection.getId()));
        }
    }
View Full Code Here

    }

    @Override
    public Consent canClear() {
        final ObjectAdapter parentObject = getParent();
        final OneToManyAssociation association = getOneToManyAssociation();
        final ObjectAdapter associatedObject = getObject();

        final Consent isEditable = isEditable();
        if (isEditable.isVetoed()) {
            return isEditable;
        }

        final Consent consent = association.isValidToRemove(parentObject, associatedObject);
        if (consent.isAllowed()) {
            consent.setDescription("Clear the association to this object from '" + parentObject.titleString() + "'");
        }
        return consent;
    }
View Full Code Here

    }

    @Override
    public void clear() {
        final ObjectAdapter parentObject = getParent();
        final OneToManyAssociation association = getOneToManyAssociation();
        LOG.debug("remove " + element + " from " + parentObject);
        association.removeElement(parentObject, element);
    }
View Full Code Here

    @Override
    public void build(final View view, final Axes axes) {
        Assert.assertEquals(view.getView(), view);

        final Content content = view.getContent();
        final OneToManyAssociation field =
            content instanceof OneToManyField ? ((OneToManyField) content).getOneToManyAssociation() : null;

        LOG.debug("rebuild view " + view + " for " + content);

        final CollectionContent collectionContent = ((CollectionContent) content);
View Full Code Here

        } else if (field instanceof OneToManyAssociation) {
          if(LOG.isDebugEnabled()) {
            LOG.debug("includeField(Pl, Vec, Str): field is 1->M");
          }

            final OneToManyAssociation oneToManyAssociation = (OneToManyAssociation) field;
            final ObjectAdapter collection = oneToManyAssociation.get(fieldPlace.getObject());
            final CollectionFacet facet = collection.getSpecification().getFacet(CollectionFacet.class);

            if(LOG.isDebugEnabled()) {
              LOG.debug("includeField(Pl, Vec, Str): 1->M: " + log("collection.size", "" + facet.size(collection)));
            }
View Full Code Here

              if(LOG.isDebugEnabled()) {
                LOG.debug("objectToElement(NO): " + log("field", fieldName) + " is OneToManyAssociation");
              }

                final OneToManyAssociation oneToManyAssociation = (OneToManyAssociation) field;
                final Element xmlCollectionElement = xmlFieldElement; // more meaningful locally scoped name

                ObjectAdapter collection;
                try {
                    collection = oneToManyAssociation.get(object);
                    final ObjectSpecification referencedTypeNos = oneToManyAssociation.getSpecification();
                    final String fullyQualifiedClassName = referencedTypeNos.getFullIdentifier();

                    // XML
                    isisMetaModel.setNofCollection(xmlCollectionElement, schema.getPrefix(), fullyQualifiedClassName, collection);
                } catch (final Exception ex) {
                    LOG.warn("objectToElement(NO): " + log("field", fieldName)
                            + ": get(obj) threw exception - skipping XML generation");
                }

                // XSD
                xsdFieldElement = schema.createXsElementForNofCollection(xsElement, xmlCollectionElement, oneToManyAssociation
                        .getSpecification().getFullIdentifier(), FacetUtil.getFacetsByType(oneToManyAssociation));

            } else {
              if(LOG.isInfoEnabled()) {
                LOG.info("objectToElement(NO): " + log("field", fieldName) + " is unknown type; ignored");
View Full Code Here

TOP

Related Classes of org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation

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.