@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("/{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()); }
public static CollectionSemantics determine(final OneToManyAssociation collection) { return collection.getCollectionSemantics().isSet() ? CollectionSemantics.SET : CollectionSemantics.LIST; }
public static CollectionSemantics determine(final ResourceContext resourceContext, final OneToManyAssociation collection) { return collection.getCollectionSemantics().isSet() ? CollectionSemantics.SET : CollectionSemantics.LIST; }