Java Code Examples for com.google.api.server.spi.config.ApiMethod.HttpMethod#DELETE

The following examples show how to use com.google.api.server.spi.config.ApiMethod.HttpMethod#DELETE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlobEndpoint.java    From io2014-codelabs with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes a blob.
 *
 * @param bucketName Google Cloud Storage bucket where the object was uploaded.
 * @param objectPath path to the object in the bucket.
 * @param user       the user making the request.
 * @throws com.google.api.server.spi.response.UnauthorizedException        if the user is not authorized.
 * @throws com.google.api.server.spi.response.BadRequestException          if the bucketName or objectPath are not valid.
 * @throws com.google.api.server.spi.response.InternalServerErrorException when the operation failed.
 */
@ApiMethod(httpMethod = HttpMethod.DELETE, path = "blobs/{bucketName}/{objectPath}")
public void deleteBlob(
  @Named("bucketName") String bucketName, @Named("objectPath") String objectPath, User user)
  throws UnauthorizedException, BadRequestException, InternalServerErrorException {
  validateUser(user);

  validateBucketAndObjectPath(bucketName, objectPath);

  boolean blobExists = checkDeletePermissions(bucketName, objectPath, user);

  if (!blobExists) {
    // DELETE operation is idempotent. The object doesn't exist, so there is no more work to do.
    return;
  }

  if (!deleteAllBlobInformation(bucketName, objectPath)) {
    throw new InternalServerErrorException("Deleting blob failed. You can retry.");
  }
}
 
Example 2
Source File: BlobEndpoint.java    From io2014-codelabs with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes a blob.
 *
 * @param bucketName Google Cloud Storage bucket where the object was uploaded.
 * @param objectPath path to the object in the bucket.
 * @param user       the user making the request.
 * @throws com.google.api.server.spi.response.UnauthorizedException        if the user is not authorized.
 * @throws com.google.api.server.spi.response.BadRequestException          if the bucketName or objectPath are not valid.
 * @throws com.google.api.server.spi.response.InternalServerErrorException when the operation failed.
 */
@ApiMethod(httpMethod = HttpMethod.DELETE, path = "blobs/{bucketName}/{objectPath}")
public void deleteBlob(
  @Named("bucketName") String bucketName, @Named("objectPath") String objectPath, User user)
  throws UnauthorizedException, BadRequestException, InternalServerErrorException {
  validateUser(user);

  validateBucketAndObjectPath(bucketName, objectPath);

  boolean blobExists = checkDeletePermissions(bucketName, objectPath, user);

  if (!blobExists) {
    // DELETE operation is idempotent. The object doesn't exist, so there is no more work to do.
    return;
  }

  if (!deleteAllBlobInformation(bucketName, objectPath)) {
    throw new InternalServerErrorException("Deleting blob failed. You can retry.");
  }
}
 
Example 3
Source File: BlobEndpoint.java    From solutions-mobile-backend-starter-java with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes a blob.
 *
 * @param bucketName Google Cloud Storage bucket where the object was uploaded.
 * @param objectPath path to the object in the bucket.
 * @param user the user making the request.
 * @throws UnauthorizedException if the user is not authorized.
 * @throws BadRequestException if the bucketName or objectPath are not valid.
 * @throws InternalServerErrorException when the operation failed.
 */
@ApiMethod(httpMethod = HttpMethod.DELETE, path = "blobs/{bucketName}/{objectPath}")
public void deleteBlob(
    @Named("bucketName") String bucketName, @Named("objectPath") String objectPath, User user)
    throws UnauthorizedException, BadRequestException, InternalServerErrorException {
  validateUser(user);

  validateBucketAndObjectPath(bucketName, objectPath);

  boolean blobExists = checkDeletePermissions(bucketName, objectPath, user);

  if (!blobExists) {
    // DELETE operation is idempotent. The object doesn't exist, so there is no more work to do.
    return;
  }

  if (!deleteAllBlobInformation(bucketName, objectPath)) {
    throw new InternalServerErrorException("Deleting blob failed. You can retry.");
  }
}
 
Example 4
Source File: Endpoint1.java    From endpoints-java with Apache License 2.0 5 votes vote down vote up
@ApiMethod(
    name = "foos.remove",
    path = "foos/{id}",
    httpMethod = HttpMethod.DELETE,
    cacheControl = @ApiMethodCacheControl(
        noCache = false,
        maxAge = 5
    )
)
public void removeFoo(@Named("id") String id) {
}
 
Example 5
Source File: ConferenceApi.java    From ud859 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Unregister from the specified Conference.
 *
 * @param user An user who invokes this method, null when the user is not signed in.
 * @param websafeConferenceKey The String representation of the Conference Key to unregister
 *                             from.
 * @return Boolean true when success, otherwise false.
 * @throws UnauthorizedException when the user is not signed in.
 * @throws NotFoundException when there is no Conference with the given conferenceId.
 */
@ApiMethod(
        name = "unregisterFromConference",
        path = "conference/{websafeConferenceKey}/registration",
        httpMethod = HttpMethod.DELETE
)
public WrappedBoolean unregisterFromConference(final User user,
                                        @Named("websafeConferenceKey")
                                        final String websafeConferenceKey)
        throws UnauthorizedException, NotFoundException, ForbiddenException, ConflictException {
    // If not signed in, throw a 401 error.
    if (user == null) {
        throw new UnauthorizedException("Authorization required");
    }
    final String userId = getUserId(user);
    TxResult<Boolean> result = ofy().transact(new Work<TxResult<Boolean>>() {
        @Override
        public TxResult<Boolean> run() {
            Key<Conference> conferenceKey = Key.create(websafeConferenceKey);
            Conference conference = ofy().load().key(conferenceKey).now();
            // 404 when there is no Conference with the given conferenceId.
            if (conference == null) {
                return new TxResult<>(new NotFoundException(
                        "No Conference found with key: " + websafeConferenceKey));
            }
            // Un-registering from the Conference.
            Profile profile = getProfileFromUser(user, userId);
            if (profile.getConferenceKeysToAttend().contains(websafeConferenceKey)) {
                profile.unregisterFromConference(websafeConferenceKey);
                conference.giveBackSeats(1);
                ofy().save().entities(profile, conference).now();
                return new TxResult<>(true);
            } else {
                return new TxResult<>(false);
            }
        }
    });
    // NotFoundException is actually thrown here.
    return new WrappedBoolean(result.getResult());
}
 
Example 6
Source File: FooDescriptionEndpoint.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
@ApiMethod(name = "foo.delete", description = "delete desc", path = "foos/{id}",
    httpMethod = HttpMethod.DELETE)
public FooDescription deleteFoo(@Named("id") @Description("id desc") String id) {
  return null;
}
 
Example 7
Source File: FooEndpoint.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
@ApiMethod(name = "foo.delete", description = "delete desc", path = "foos/{id}",
    httpMethod = HttpMethod.DELETE)
public Foo deleteFoo(@Named("id") @Description("id desc") String id) {
  return null;
}
 
Example 8
Source File: NonDiscoverableEndpoint.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
@ApiMethod(name = "foo.delete", description = "delete desc", path = "foos/{id}",
    httpMethod = HttpMethod.DELETE)
public Foo deleteFoo(@Named("id") @Description("id desc") String id) {
  return null;
}
 
Example 9
Source File: AnnotationApiConfigGeneratorTest.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
@ApiMethod(name = "delete", path = "item/{id}", httpMethod = HttpMethod.DELETE)
public void delete(@Named("id") String id) {}
 
Example 10
Source File: ConferenceApi.java    From ud859 with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Unregister from the specified Conference.
 *
 * @param user An user who invokes this method, null when the user is not signed in.
 * @param websafeConferenceKey The String representation of the Conference Key to unregister
 *                             from.
 * @return Boolean true when success, otherwise false.
 * @throws UnauthorizedException when the user is not signed in.
 * @throws NotFoundException when there is no Conference with the given conferenceId.
 */
@ApiMethod(
        name = "unregisterFromConference",
        path = "conference/{websafeConferenceKey}/registration",
        httpMethod = HttpMethod.DELETE
)
public WrappedBoolean unregisterFromConference(final User user,
                                        @Named("websafeConferenceKey")
                                        final String websafeConferenceKey)
        throws UnauthorizedException, NotFoundException, ForbiddenException, ConflictException {
    // If not signed in, throw a 401 error.
    if (user == null) {
        throw new UnauthorizedException("Authorization required");
    }

    WrappedBoolean result = ofy().transact(new Work<WrappedBoolean>() {
        @Override
        public WrappedBoolean run() {
            Key<Conference> conferenceKey = Key.create(websafeConferenceKey);
            Conference conference = ofy().load().key(conferenceKey).now();
            // 404 when there is no Conference with the given conferenceId.
            if (conference == null) {
                return new  WrappedBoolean(false,
                        "No Conference found with key: " + websafeConferenceKey);
            }

            // Un-registering from the Conference.
            Profile profile = getProfileFromUser(user);
            if (profile.getConferenceKeysToAttend().contains(websafeConferenceKey)) {
                profile.unregisterFromConference(websafeConferenceKey);
                conference.giveBackSeats(1);
                ofy().save().entities(profile, conference).now();
                return new WrappedBoolean(true);
            } else {
                return new WrappedBoolean(false, "You are not registered for this conference");
            }
        }
    });
    // if result is false
    if (!result.getResult()) {
        if (result.getReason().contains("No Conference found with key")) {
            throw new NotFoundException (result.getReason());
        }
        else {
            throw new ForbiddenException(result.getReason());
        }
    }
    // NotFoundException is actually thrown here.
    return new WrappedBoolean(result.getResult());
}
 
Example 11
Source File: ConferenceApi.java    From ud859 with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Unregister from the specified Conference.
 *
 * @param user An user who invokes this method, null when the user is not signed in.
 * @param websafeConferenceKey The String representation of the Conference Key to unregister
 *                             from.
 * @return Boolean true when success, otherwise false.
 * @throws UnauthorizedException when the user is not signed in.
 * @throws NotFoundException when there is no Conference with the given conferenceId.
 */
@ApiMethod(
        name = "unregisterFromConference",
        path = "conference/{websafeConferenceKey}/registration",
        httpMethod = HttpMethod.DELETE
)
public WrappedBoolean unregisterFromConference(final User user,
                                        @Named("websafeConferenceKey")
                                        final String websafeConferenceKey)
        throws UnauthorizedException, NotFoundException, ForbiddenException, ConflictException {
    // If not signed in, throw a 401 error.
    if (user == null) {
        throw new UnauthorizedException("Authorization required");
    }

    WrappedBoolean result = ofy().transact(new Work<WrappedBoolean>() {
        @Override
        public WrappedBoolean run() {
            Key<Conference> conferenceKey = Key.create(websafeConferenceKey);
            Conference conference = ofy().load().key(conferenceKey).now();
            // 404 when there is no Conference with the given conferenceId.
            if (conference == null) {
                return new  WrappedBoolean(false,
                        "No Conference found with key: " + websafeConferenceKey);
            }

            // Un-registering from the Conference.
            Profile profile = getProfileFromUser(user);
            if (profile.getConferenceKeysToAttend().contains(websafeConferenceKey)) {
                profile.unregisterFromConference(websafeConferenceKey);
                conference.giveBackSeats(1);
                ofy().save().entities(profile, conference).now();
                return new WrappedBoolean(true);
            } else {
                return new WrappedBoolean(false, "You are not registered for this conference");
            }
        }
    });
    // if result is false
    if (!result.getResult()) {
        if (result.getReason().contains("No Conference found with key")) {
            throw new NotFoundException (result.getReason());
        }
        else {
            throw new ForbiddenException(result.getReason());
        }
    }
    // NotFoundException is actually thrown here.
    return new WrappedBoolean(result.getResult());
}
 
Example 12
Source File: EndpointV1.java    From io2014-codelabs with Apache License 2.0 3 votes vote down vote up
/**
 * Deletes the CloudEntity specified by its Id.
 *
 * @param kindName
 *          Name of the kind for the CloudEntity to delete.
 * @param id
 *          Id of the CloudEntity to delete.
 * @return {@link com.google.cloud.backend.beans.EntityDto} a dummy object (Endpoints requires to return any
 *         bean object).
 * @throws com.google.api.server.spi.response.UnauthorizedException
 *           if the requesting {@link com.google.appengine.api.users.User} has no sufficient permission for
 *           the operation.
 */
@ApiMethod(path = "CloudEntities/{kind}/{id}", httpMethod = HttpMethod.DELETE)
public EntityDto delete(@Named("kind") String kindName, @Named("id") String id, User user)
    throws UnauthorizedException {

  SecurityChecker.getInstance().checkIfUserIsAvailable(user);
  return CrudOperations.getInstance().delete(kindName, id, user);
}
 
Example 13
Source File: EndpointV1.java    From solutions-mobile-backend-starter-java with Apache License 2.0 3 votes vote down vote up
/**
 * Deletes the CloudEntity specified by its Id.
 *
 * @param kindName
 *          Name of the kind for the CloudEntity to delete.
 * @param id
 *          Id of the CloudEntity to delete.
 * @return {@link EntityDto} a dummy object (Endpoints requires to return any
 *         bean object).
 * @throws UnauthorizedException
 *           if the requesting {@link User} has no sufficient permission for
 *           the operation.
 */
@ApiMethod(path = "CloudEntities/{kind}/{id}", httpMethod = HttpMethod.DELETE)
public EntityDto delete(@Named("kind") String kindName, @Named("id") String id, User user)
    throws UnauthorizedException {

  SecurityChecker.getInstance().checkIfUserIsAvailable(user);
  return CrudOperations.getInstance().delete(kindName, id, user);
}