Search in sources :

Example 1 with BlobInfo

use of com.google.appengine.api.blobstore.BlobInfo in project teammates by TEAMMATES.

the class ImageUploadAction method prepareData.

protected FileUploadPageData prepareData() {
    FileUploadPageData data = new FileUploadPageData(account, sessionToken);
    BlobInfo blobInfo = extractImageKey(getImageKeyParam());
    if (blobInfo == null) {
        data.isFileUploaded = false;
        data.fileSrcUrl = null;
        log.warning("Image Upload Failed");
        statusToAdmin = "Image Upload Failed";
        return data;
    }
    BlobKey blobKey = blobInfo.getBlobKey();
    data.isFileUploaded = true;
    AppUrl fileSrcUrl = Config.getAppUrl(Const.ActionURIs.PUBLIC_IMAGE_SERVE).withParam(Const.ParamsNames.BLOB_KEY, blobKey.getKeyString());
    String absoluteFileSrcUrl = fileSrcUrl.toAbsoluteString();
    data.fileSrcUrl = fileSrcUrl.toString();
    log.info("New Image Uploaded : " + absoluteFileSrcUrl);
    statusToAdmin = "New Image Uploaded : " + "<a href=" + data.fileSrcUrl + " target=\"_blank\">" + absoluteFileSrcUrl + "</a>";
    data.ajaxStatus = "Image Successfully Uploaded to Google Cloud Storage";
    return data;
}
Also used : BlobKey(com.google.appengine.api.blobstore.BlobKey) AppUrl(teammates.common.util.AppUrl) BlobInfo(com.google.appengine.api.blobstore.BlobInfo) FileUploadPageData(teammates.ui.pagedata.FileUploadPageData)

Example 2 with BlobInfo

use of com.google.appengine.api.blobstore.BlobInfo in project teammates by TEAMMATES.

the class ImageUploadAction method extractImageKey.

/**
 * Extracts the image metadata by the passed image key parameter.
 */
protected BlobInfo extractImageKey(String param) {
    try {
        Map<String, List<BlobInfo>> blobsMap = BlobstoreServiceFactory.getBlobstoreService().getBlobInfos(request);
        List<BlobInfo> blobs = blobsMap.get(param);
        if (blobs == null || blobs.isEmpty()) {
            data.ajaxStatus = Const.StatusMessages.NO_IMAGE_GIVEN;
            isError = true;
            return null;
        }
        BlobInfo image = blobs.get(0);
        return validateImage(image);
    } catch (IllegalStateException e) {
        return null;
    }
}
Also used : List(java.util.List) BlobInfo(com.google.appengine.api.blobstore.BlobInfo)

Example 3 with BlobInfo

use of com.google.appengine.api.blobstore.BlobInfo in project teammates by TEAMMATES.

the class AdminEmailGroupReceiverListUploadAction method execute.

@Override
protected ActionResult execute() {
    gateKeeper.verifyAdminPrivileges(account);
    data = new AdminEmailComposePageData(account, sessionToken);
    BlobInfo blobInfo = extractGroupReceiverListFileKey();
    if (blobInfo == null) {
        data.isFileUploaded = false;
        data.fileSrcUrl = null;
        log.info("Group Receiver List Upload Failed");
        statusToAdmin = "Group Receiver List Upload Failed";
        data.ajaxStatus = "Group receiver list upload failed. Please try again.";
        return createAjaxResult(data);
    }
    try {
        List<List<String>> groupReceiverList = GoogleCloudStorageHelper.getGroupReceiverList(blobInfo.getBlobKey());
        // log all email addresses retrieved from the txt file
        int i = 0;
        for (List<String> list : groupReceiverList) {
            for (String str : list) {
                log.info(str + " - " + i + " \n");
                i++;
            }
        }
    } catch (IOException e) {
        data.isFileUploaded = false;
        data.fileSrcUrl = null;
        log.info("Group Receiver List Upload Failed: uploaded file is corrupted");
        statusToAdmin = "Group Receiver List Upload Failed: uploaded file is corrupted";
        data.ajaxStatus = "Group receiver list upload failed: uploaded file is corrupted. " + "Please make sure the txt file contains only email addresses " + "separated by comma";
        deleteGroupReceiverListFile(blobInfo.getBlobKey());
        return createAjaxResult(data);
    }
    BlobKey blobKey = blobInfo.getBlobKey();
    data.groupReceiverListFileKey = blobKey.getKeyString();
    data.isFileUploaded = true;
    statusToAdmin = "New Group Receiver List Uploaded";
    data.ajaxStatus = "Group receiver list successfully uploaded to Google Cloud Storage";
    return createAjaxResult(data);
}
Also used : BlobKey(com.google.appengine.api.blobstore.BlobKey) List(java.util.List) AdminEmailComposePageData(teammates.ui.pagedata.AdminEmailComposePageData) BlobInfo(com.google.appengine.api.blobstore.BlobInfo) IOException(java.io.IOException)

Example 4 with BlobInfo

use of com.google.appengine.api.blobstore.BlobInfo in project teammates by TEAMMATES.

the class StudentProfilePictureUploadAction method execute.

/*
     * This class is not tested in ActionTests as it is difficult to
     * reproduce the upload action done by Google Blobstore API
     * without the server running.
     * This class is covered in UiTests.
     */
@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    gateKeeper.verifyLoggedInUserPrivileges();
    String pictureKey = "";
    BlobKey blobKey = new BlobKey("");
    RedirectResult r = createRedirectResult(Const.ActionURIs.STUDENT_PROFILE_PAGE);
    try {
        BlobInfo blobInfo = extractProfilePictureKey();
        if (!isError) {
            blobKey = blobInfo.getBlobKey();
            pictureKey = renameFileToGoogleId(blobInfo);
            logic.updateStudentProfilePicture(account.googleId, pictureKey);
            statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_PROFILE_PICTURE_SAVED, StatusMessageColor.SUCCESS));
            r.addResponseParam(Const.ParamsNames.STUDENT_PROFILE_PHOTOEDIT, "true");
        }
    } catch (BlobstoreFailureException | IOException bfe) {
        deletePicture(blobKey);
        updateStatusesForBlobstoreFailure();
        isError = true;
    } catch (Exception e) {
        /*
             * This is for other exceptions like EntityNotFound, IllegalState, etc
             * that occur rarely and are handled higher up.
             */
        deletePicture(new BlobKey(pictureKey));
        statusToUser.clear();
        throw e;
    }
    return r;
}
Also used : BlobKey(com.google.appengine.api.blobstore.BlobKey) BlobstoreFailureException(com.google.appengine.api.blobstore.BlobstoreFailureException) BlobInfo(com.google.appengine.api.blobstore.BlobInfo) IOException(java.io.IOException) BlobstoreFailureException(com.google.appengine.api.blobstore.BlobstoreFailureException) IOException(java.io.IOException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) StatusMessage(teammates.common.util.StatusMessage)

Example 5 with BlobInfo

use of com.google.appengine.api.blobstore.BlobInfo in project teammates by TEAMMATES.

the class AdminEmailGroupReceiverListUploadAction method extractGroupReceiverListFileKey.

private BlobInfo extractGroupReceiverListFileKey() {
    try {
        Map<String, List<BlobInfo>> blobsMap = BlobstoreServiceFactory.getBlobstoreService().getBlobInfos(request);
        List<BlobInfo> blobs = blobsMap.get(Const.ParamsNames.ADMIN_EMAIL_GROUP_RECEIVER_LIST_TO_UPLOAD);
        if (blobs == null || blobs.isEmpty()) {
            data.ajaxStatus = Const.StatusMessages.NO_GROUP_RECEIVER_LIST_FILE_GIVEN;
            isError = true;
            return null;
        }
        BlobInfo groupReceiverListFile = blobs.get(0);
        return validateGroupReceiverListFile(groupReceiverListFile);
    } catch (IllegalStateException e) {
        return null;
    }
}
Also used : List(java.util.List) BlobInfo(com.google.appengine.api.blobstore.BlobInfo)

Aggregations

BlobInfo (com.google.appengine.api.blobstore.BlobInfo)6 List (java.util.List)4 BlobKey (com.google.appengine.api.blobstore.BlobKey)3 IOException (java.io.IOException)2 StatusMessage (teammates.common.util.StatusMessage)2 BlobstoreFailureException (com.google.appengine.api.blobstore.BlobstoreFailureException)1 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)1 AppUrl (teammates.common.util.AppUrl)1 AdminEmailComposePageData (teammates.ui.pagedata.AdminEmailComposePageData)1 FileUploadPageData (teammates.ui.pagedata.FileUploadPageData)1