private void updateOneToManyAssociation(final ObjectAdapter objectAdapter, final OneToManyAssociation otma, final CollectionData collectionData) { final ObjectAdapter collection = otma.get(objectAdapter, InteractionInitiatedBy.FRAMEWORK); final CollectionFacet facet = CollectionFacetUtils.getCollectionFacetFromSpec(collection); final List<ObjectAdapter> original = Lists.newArrayList(); for (final ObjectAdapter adapter : facet.iterable(collection)) { original.add(adapter); } final Data[] elements = collectionData.elements; for (final Data data : elements) { final ObjectAdapter elementAdapter = recreateReference(data); if (!facet.contains(collection, elementAdapter)) { if (LOG.isDebugEnabled()) { LOG.debug(" association {} changed, added {}", otma, elementAdapter.getOid()); } otma.addElement(objectAdapter, elementAdapter, InteractionInitiatedBy.FRAMEWORK); } else { otma.removeElement(objectAdapter, elementAdapter, InteractionInitiatedBy.FRAMEWORK); } } for (final ObjectAdapter element : original) { if (LOG.isDebugEnabled()) { LOG.debug(" association {} changed, removed {}", otma, element.getOid()); } otma.removeElement(objectAdapter, element, InteractionInitiatedBy.FRAMEWORK); } }
private EntityCollectionModel(final EntityModel entityModel) { this.type = Type.PARENTED; this.entityModel = entityModel; final OneToManyAssociation collection = collectionFor(entityModel.getObjectAdapterMemento(), getLayoutData()); this.typeOf = forName(collection.getSpecification()); this.collectionMemento = new CollectionMemento(collection, entityModel.getIsisSessionFactory()); this.pageSize = pageSize(collection.getFacet(PagedFacet.class), PAGE_SIZE_DEFAULT_FOR_PARENTED); final SortedByFacet sortedByFacet = collection.getFacet(SortedByFacet.class); this.sortedBy = sortedByFacet != null ? sortedByFacet.value(): null; this.toggledMementosList = Lists.newArrayList(); }
@Override @POST @Path("/{domainType}/{instanceId}/collections/{collectionId}") @Consumes({ MediaType.WILDCARD }) @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_ERROR }) public Response addToList(@PathParam("domainType") String domainType, @PathParam("instanceId") final String instanceId, @PathParam("collectionId") final String collectionId, final InputStream body) { init(Where.PARENTED_TABLES); final ObjectAdapter objectAdapter = getObjectAdapterElseThrowNotFound(domainType, instanceId); final DomainResourceHelper helper = new DomainResourceHelper(getResourceContext(), objectAdapter); final OneToManyAssociation collection = helper.getCollectionThatIsVisibleForIntent(collectionId, Intent.MUTATE, getResourceContext().getWhere()); if (!collection.getCollectionSemantics().isListOrArray()) { throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.METHOD_NOT_ALLOWED, "Collection '%s' does not have list or array semantics", collectionId); } final ObjectSpecification collectionSpec = collection.getSpecification(); final String bodyAsString = DomainResourceHelper.asStringUtf8(body); final ObjectAdapter argAdapter = helper.parseAsMapWithSingleValue(collectionSpec, bodyAsString); final Consent consent = collection.isValidToAdd(objectAdapter, argAdapter); if (consent.isVetoed()) { throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.UNAUTHORIZED, consent.getReason()); } collection.addElement(objectAdapter, argAdapter); return helper.collectionDetails(collectionId, MemberMode.MUTATING, Caching.NONE, getResourceContext().getWhere()); }
@Override @DELETE @Path("/{domainType}/{instanceId}/collections/{collectionId}") @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_ERROR }) public Response removeFromCollection(@PathParam("domainType") String domainType, @PathParam("instanceId") final String instanceId, @PathParam("collectionId") final String collectionId) { init(Where.PARENTED_TABLES); final ObjectAdapter objectAdapter = getObjectAdapterElseThrowNotFound(domainType, instanceId); final DomainResourceHelper helper = new DomainResourceHelper(getResourceContext(), objectAdapter); final OneToManyAssociation collection = helper.getCollectionThatIsVisibleForIntent(collectionId, Intent.MUTATE, getResourceContext().getWhere()); final ObjectSpecification collectionSpec = collection.getSpecification(); final ObjectAdapter argAdapter = helper.parseAsMapWithSingleValue(collectionSpec, getResourceContext().getQueryString()); final Consent consent = collection.isValidToRemove(objectAdapter, argAdapter); if (consent.isVetoed()) { throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.UNAUTHORIZED, consent.getReason()); } collection.removeElement(objectAdapter, argAdapter); return helper.collectionDetails(collectionId, MemberMode.MUTATING, Caching.NONE, getResourceContext().getWhere()); }
@Override public void doHandle(final PerformContext performContext) { final ObjectAdapter onAdapter = performContext.getOnAdapter(); final ObjectMember nakedObjectMember = performContext.getObjectMember(); final OneToManyAssociation otma = (OneToManyAssociation) nakedObjectMember; result = otma.get(onAdapter); }
collection = oneToManyAssociation.get(object); final ObjectSpecification referencedTypeNos = oneToManyAssociation.getSpecification(); final String fullyQualifiedClassName = referencedTypeNos.getFullIdentifier(); xsdFieldElement = schema.createXsElementForNofCollection(xsElement, xmlCollectionElement, oneToManyAssociation.getSpecification().getFullIdentifier(), FacetUtil.getFacetsByType(oneToManyAssociation));
private EntityCollectionModel(final ObjectAdapterMemento parentAdapterMemento, final OneToManyAssociation collection) { this.type = Type.PARENTED; this.typeOf = ClassLoaders.forName(collection.getSpecification()); this.parentObjectAdapterMemento = parentAdapterMemento; this.collectionMemento = new CollectionMemento(collection); }
private void addValue() { final ObjectAdapter valueAdapter = objectMember.get(objectAdapter); if (valueAdapter == null) { return; } final RenderFacet renderFacet = objectMember.getFacet(RenderFacet.class); boolean eagerlyRender = renderFacet != null && renderFacet.value() == Type.EAGERLY && rendererContext.canEagerlyRender(valueAdapter); final CollectionFacet facet = CollectionFacetUtils.getCollectionFacetFromSpec(valueAdapter); final List<JsonRepresentation> list = Lists.newArrayList(); for (final ObjectAdapter elementAdapter : facet.iterable(valueAdapter)) { final LinkBuilder valueLinkBuilder = DomainObjectReprRenderer.newLinkToBuilder(rendererContext, Rel.VALUE, elementAdapter); if(eagerlyRender) { final DomainObjectReprRenderer renderer = new DomainObjectReprRenderer(getRendererContext(), getLinkFollowSpecs(), JsonRepresentation.newMap()); renderer.with(elementAdapter); if(mode.isEventSerialization()) { renderer.asEventSerialization(); } valueLinkBuilder.withValue(renderer.render()); } list.add(valueLinkBuilder.build()); } representation.mapPut("value", list); }
@Test(expected = IllegalArgumentException.class) public void cannotAddNull() { association.addElement(mockOwnerAdapter, null); }
final ObjectAdapter currentReferencedAdapter = collection.get(targetAdapter, interactionInitiatedBy); final CollectionAccessEvent ev = new CollectionAccessEvent(getDelegate(), collection.getIdentifier());
@Test(expected = IllegalArgumentException.class) public void cannotRemoveNull() { association.removeElement(mockOwnerAdapter, null); }
final InteractionResult interactionResult = collection.isValidToRemove(targetAdapter, argumentAdapter, getInteractionInitiatedBy()).getInteractionResult(); notifyListenersAndVetoIfRequired(interactionResult); collection.removeElement(targetAdapter, argumentAdapter, getInteractionInitiatedBy()); } else { try { collection.removeElement(targetAdapter, argumentAdapter, getInteractionInitiatedBy()); } catch(Exception ignore) {
public static LinkBuilder newLinkToBuilder(final ResourceContext resourceContext, final Rel rel, final ObjectSpecification objectSpecification, final OneToManyAssociation collection) { final String typeFullName = objectSpecification.getFullIdentifier(); final String collectionId = collection.getId(); final String url = "domainTypes/" + typeFullName + "/collections/" + collectionId; return LinkBuilder.newBuilder(resourceContext, rel, RepresentationType.COLLECTION_DESCRIPTION, url); }
private boolean renderEagerly() { final RenderFacet renderFacet = objectMember.getFacet(RenderFacet.class); return renderFacet != null && renderFacet.value() == Type.EAGERLY; }
final InteractionResult interactionResult = otma.isValidToAdd(targetAdapter, argumentNO, getInteractionInitiatedBy()).getInteractionResult(); notifyListenersAndVetoIfRequired(interactionResult); otma.addElement(targetAdapter, argumentNO, getInteractionInitiatedBy()); } else { try { otma.addElement(targetAdapter, argumentNO, getInteractionInitiatedBy()); } catch(Exception ignore) {
public String getName(final SpecificationLoader specificationLoader) { return getCollection(specificationLoader).getName(); }
public static CollectionSemantics determine(final OneToManyAssociation collection) { return collection.getCollectionSemantics().isSet() ? CollectionSemantics.SET : CollectionSemantics.LIST; }
@Override protected Consent determineConsent(final PerformContext performContext, final ObjectAdapter toValidateAdapter) { final ObjectAdapter onAdapter = performContext.getOnAdapter(); final OneToManyAssociation otma = (OneToManyAssociation) performContext.getObjectMember(); return otma.isValidToRemove(onAdapter, toValidateAdapter); }
private void appendObjectTo( final RepresentationService.Context2 rendererContext, final ObjectAdapter objectAdapter, final JsonRepresentation rootRepresentation) { appendPropertiesTo(rendererContext, objectAdapter, rootRepresentation); final List<OneToManyAssociation> collections = objectAdapter.getSpecification().getCollections(Contributed.INCLUDED); final Where where = rendererContext.getWhere(); for (final OneToManyAssociation collection : collections) { final JsonRepresentation collectionRepresentation = JsonRepresentation.newArray(); rootRepresentation.mapPut(collection.getId(), collectionRepresentation); final InteractionInitiatedBy interactionInitiatedBy = determineInteractionInitiatedByFrom(rendererContext); final Consent visibility = collection.isVisible(objectAdapter, interactionInitiatedBy, where); if (!visibility.isAllowed()) { continue; } appendCollectionTo(rendererContext, objectAdapter, collection, collectionRepresentation); } }