@Override protected Consent determineConsent(final PerformContext performContext, final ObjectAdapter toValidateAdapter) { final ObjectAdapter onAdapter = performContext.getOnAdapter(); final OneToManyAssociation otma = (OneToManyAssociation) performContext.getObjectMember(); return otma.isValidToAdd(onAdapter, toValidateAdapter); }
@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 @POST @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 addToList(@PathParam("domainType") String domainType, @PathParam("instanceId") final String instanceId, @PathParam("collectionId") final String collectionId, final InputStream body) { 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); 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 = Util.asStringUtf8(body); final ObjectAdapter argAdapter = new JsonParserHelper(getResourceContext(), collectionSpec).parseAsMapWithSingleValue( bodyAsString); final Consent consent = collection.isValidToAdd(objectAdapter, argAdapter, InteractionInitiatedBy.USER); if (consent.isVetoed()) { throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.UNAUTHORIZED, consent.getReason()); } collection.addElement(objectAdapter, argAdapter, InteractionInitiatedBy.USER); return helper.collectionDetails(collectionId, MemberReprMode.WRITE); }
@Override @PUT @Path("/{oid}/collections/{collectionId}") @Consumes({ MediaType.WILDCARD }) @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_ERROR }) public Response addToSet(@PathParam("oid") final String oidStr, @PathParam("collectionId") final String collectionId, final InputStream body) { 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()); if (!collection.getCollectionSemantics().isSet()) { throw RestfulObjectsApplicationException.create(HttpStatusCode.BAD_REQUEST, "Collection '%s' does not have set 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.create(HttpStatusCode.UNAUTHORIZED, consent.getReason()); } collection.addElement(objectAdapter, argAdapter); return helper.collectionDetails(objectAdapter, collectionId, MemberMode.MUTATING, Caching.NONE, getResourceContext().getWhere()); }
@Override @PUT @Path("/{domainType}/{instanceId}/collections/{collectionId}") @Consumes({ MediaType.WILDCARD }) @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_ERROR }) public Response addToSet(@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().isSet()) { throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.BAD_REQUEST, "Collection '%s' does not have set 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 @PUT @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 addToSet(@PathParam("domainType") String domainType, @PathParam("instanceId") final String instanceId, @PathParam("collectionId") final String collectionId, final InputStream body) { 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); if (!collection.getCollectionSemantics().isSet()) { throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.BAD_REQUEST, "Collection '%s' does not have set semantics", collectionId); } final ObjectSpecification collectionSpec = collection.getSpecification(); final String bodyAsString = Util.asStringUtf8(body); final ObjectAdapter argAdapter = new JsonParserHelper(getResourceContext(), collectionSpec).parseAsMapWithSingleValue( bodyAsString); final Consent consent = collection.isValidToAdd(objectAdapter, argAdapter, InteractionInitiatedBy.USER); if (consent.isVetoed()) { throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.UNAUTHORIZED, consent.getReason()); } collection.addElement(objectAdapter, argAdapter, InteractionInitiatedBy.USER); return helper.collectionDetails(collectionId, MemberReprMode.WRITE); }
@Override @POST @Path("/{oid}/collections/{collectionId}") @Consumes({ MediaType.WILDCARD }) @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_ERROR }) public Response addToList(@PathParam("oid") final String oidStr, @PathParam("collectionId") final String collectionId, final InputStream body) { 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()); if (!collection.getCollectionSemantics().isListOrArray()) { throw RestfulObjectsApplicationException.create(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.create(HttpStatusCode.UNAUTHORIZED, consent.getReason()); } collection.addElement(objectAdapter, argAdapter); return helper.collectionDetails(objectAdapter, collectionId, MemberMode.MUTATING, Caching.NONE, getResourceContext().getWhere()); }
final InteractionResult interactionResult = otma.isValidToAdd(targetAdapter, argumentNO, getInteractionInitiatedBy()).getInteractionResult(); notifyListenersAndVetoIfRequired(interactionResult);
@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(); 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 addToFacet.add(onAdapter, toAddAdapter); }