@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); }
@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 @DELETE @Path("/{domainType}/{instanceId}/collections/{collectionId}") @Consumes({ MediaType.WILDCARD }) @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_OBJECT_COLLECTION, RestfulMediaType.APPLICATION_JSON_ERROR, MediaType.APPLICATION_XML, RestfulMediaType.APPLICATION_XML_OBJECT_COLLECTION, RestfulMediaType.APPLICATION_XML_ERROR }) public Response removeFromCollection(@PathParam("domainType") String domainType, @PathParam("instanceId") final String instanceId, @PathParam("collectionId") final String collectionId) { init(Where.PARENTED_TABLES, RepresentationService.Intent.NOT_APPLICABLE); final ObjectAdapter objectAdapter = getObjectAdapterElseThrowNotFound(domainType, instanceId); final DomainResourceHelper helper = newDomainResourceHelper(objectAdapter); final ObjectAdapterAccessHelper accessHelper = new ObjectAdapterAccessHelper(getResourceContext(), objectAdapter); final OneToManyAssociation collection = accessHelper.getCollectionThatIsVisibleForIntent( collectionId, ObjectAdapterAccessHelper.Intent.MUTATE); final ObjectSpecification collectionSpec = collection.getSpecification(); final ObjectAdapter argAdapter = new JsonParserHelper(getResourceContext(), collectionSpec).parseAsMapWithSingleValue( getResourceContext().getUrlUnencodedQueryString()); final Consent consent = collection.isValidToRemove(objectAdapter, argAdapter, InteractionInitiatedBy.USER); if (consent.isVetoed()) { throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.UNAUTHORIZED, consent.getReason()); } collection.removeElement(objectAdapter, argAdapter, InteractionInitiatedBy.USER); return helper.collectionDetails(collectionId, MemberReprMode.WRITE); }
@Override @DELETE @Path("/{oid}/collections/{collectionId}") @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_ERROR }) public Response removeFromCollection(@PathParam("oid") final String oidStr, @PathParam("collectionId") final String collectionId) { init(Where.PARENTED_TABLES); final ObjectAdapter objectAdapter = getObjectAdapter(oidStr); final DomainResourceHelper helper = new DomainResourceHelper(getResourceContext(), objectAdapter); final OneToManyAssociation collection = helper.getCollectionThatIsVisibleAndUsable(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.create(HttpStatusCode.UNAUTHORIZED, consent.getReason()); } collection.removeElement(objectAdapter, argAdapter); return helper.collectionDetails(objectAdapter, collectionId, MemberMode.MUTATING, Caching.NONE, getResourceContext().getWhere()); }
@Override public void doHandle(final PerformContext performContext) throws ScenarioBoundValueException { final ObjectAdapter onAdapter = performContext.getOnAdapter(); final ObjectMember nakedObjectMember = performContext.getObjectMember(); final CellBinding onMemberBinding = performContext.getPeer().getOnMemberBinding(); @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 removeFromFacet.remove(onAdapter, toRemoveAdapter); }
final InteractionResult interactionResult = collection.isValidToRemove(targetAdapter, argumentAdapter, getInteractionInitiatedBy()).getInteractionResult(); notifyListenersAndVetoIfRequired(interactionResult);
usable = ((OneToManyAssociation) field).isValidToRemove(adapter, element);