Search in sources :

Example 1 with Resource

use of com.willshex.blogwt.shared.api.datatype.Resource in project blogwt by billy1380.

the class EditResourcePage method onImageUploadFinished.

@SuppressWarnings("deprecation")
private void onImageUploadFinished(IUploader uploader) {
    if (uploader.getStatus() == Status.SUCCESS) {
        String msg = uploader.getServerMessage().getMessage();
        if (msg != null && msg.startsWith("data:")) {
            // NOTE: this does not happen
            new PreloadedImage(msg, EditResourcePage.this::onImagePreloaderFinished);
        } else {
            Resource resource = new Resource();
            if (uploader.getServerInfo().ctype.startsWith("image")) {
                resource.type = ResourceTypeType.ResourceTypeTypeGoogleCloudServiceImage;
            }
            for (String name : uploader.getServerMessage().getUploadedFileNames()) {
                resource.name = name;
                break;
            }
            resource.id = Long.valueOf(uploader.getServerInfo().message);
            resource.description = "New uploaded file " + resource.name;
            resource.properties = "{\"contentType\":" + uploader.getServerInfo().ctype + "}";
            resource.data = "gs://" + uploader.getServerInfo().key;
            if (EditResourcePage.this.resource == null) {
                EditResourcePage.this.resource = resource;
            } else {
            // find out if the page status is new then delete the preciously uploaded resource
            }
            uploader.getStatusWidget().setVisible(false);
            show(EditResourcePage.this.resource = resource);
            if (resource.type == ResourceTypeType.ResourceTypeTypeGoogleCloudServiceImage) {
                for (String url : uploader.getServerMessage().getUploadedFileUrls()) {
                    new PreloadedImage(url.replace(ApiHelper.BASE_URL, ""), EditResourcePage.this::onImagePreloaderFinished);
                    break;
                }
            }
        }
        actionText = UPDATE_ACTION_TEXT;
        elHeading.setInnerText(getHeadingText());
    } else {
    // Failed :(
    }
    ready();
}
Also used : PreloadedImage(gwtupload.client.PreloadedImage) Resource(com.willshex.blogwt.shared.api.datatype.Resource)

Example 2 with Resource

use of com.willshex.blogwt.shared.api.datatype.Resource in project blogwt by billy1380.

the class EditResourcePage method onAttach.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.client.page.Page#onAttach() */
@Override
protected void onAttach() {
    super.onAttach();
    register(DefaultEventBus.get().addHandlerToSource(NavigationChangedEventHandler.TYPE, NavigationController.get(), (p, c) -> {
        reset();
        if ("id".equals(c.getAction()) && c.getParameterCount() > 0) {
            Long id = Long.valueOf(c.getParameter(0));
            ResourceController.get().getResource(ApiHelper.dataType(new Resource(), id));
            actionText = UPDATE_ACTION_TEXT;
        } else if ("new".equals(c.getAction())) {
            actionText = ADD_ACTION_TEXT;
        }
        elHeading.setInnerText(getHeadingText());
        ready();
    }));
    register(DefaultEventBus.get().addHandlerToSource(GetResourceEventHandler.TYPE, ResourceController.get(), this));
    register(DefaultEventBus.get().addHandlerToSource(UpdateResourceEventHandler.TYPE, ResourceController.get(), this));
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Image(com.google.gwt.user.client.ui.Image) ResourceController(com.willshex.blogwt.client.controller.ResourceController) UpdateResourceEventHandler(com.willshex.blogwt.client.api.blog.event.UpdateResourceEventHandler) UiHandler(com.google.gwt.uibinder.client.UiHandler) TextBox(com.google.gwt.user.client.ui.TextBox) NavigationChangedEventHandler(com.willshex.blogwt.client.event.NavigationChangedEventHandler) Resources(com.willshex.blogwt.client.Resources) PreloadedImage(gwtupload.client.PreloadedImage) GWT(com.google.gwt.core.client.GWT) Upload(com.willshex.blogwt.shared.api.upload.Upload) GetResourceRequest(com.willshex.blogwt.shared.api.blog.call.GetResourceRequest) UiBinder(com.google.gwt.uibinder.client.UiBinder) IUploader(gwtupload.client.IUploader) StatusType(com.willshex.gson.web.service.shared.StatusType) BaseUploadStatus(gwtupload.client.BaseUploadStatus) GetResourceEventHandler(com.willshex.blogwt.client.api.blog.event.GetResourceEventHandler) TextArea(com.google.gwt.user.client.ui.TextArea) Page(com.willshex.blogwt.client.page.Page) Status(gwtupload.client.IUploadStatus.Status) Button(com.google.gwt.user.client.ui.Button) GetResourceResponse(com.willshex.blogwt.shared.api.blog.call.GetResourceResponse) UiHelper(com.willshex.blogwt.client.helper.UiHelper) HTMLPanel(com.google.gwt.user.client.ui.HTMLPanel) WizardDialog(com.willshex.blogwt.client.wizard.WizardDialog) Resource(com.willshex.blogwt.shared.api.datatype.Resource) UpdateResourceResponse(com.willshex.blogwt.shared.api.blog.call.UpdateResourceResponse) ApiHelper(com.willshex.blogwt.client.helper.ApiHelper) Widget(com.google.gwt.user.client.ui.Widget) UpdateResourceRequest(com.willshex.blogwt.shared.api.blog.call.UpdateResourceRequest) FileInputType(gwtupload.client.IFileInput.FileInputType) UiField(com.google.gwt.uibinder.client.UiField) NavigationController(com.willshex.blogwt.client.controller.NavigationController) Element(com.google.gwt.dom.client.Element) DefaultEventBus(com.willshex.blogwt.client.DefaultEventBus) ResourceTypeType(com.willshex.blogwt.shared.api.datatype.ResourceTypeType) FormPanel(com.google.gwt.user.client.ui.FormPanel) SingleUploader(gwtupload.client.SingleUploader) Resource(com.willshex.blogwt.shared.api.datatype.Resource)

Example 3 with Resource

use of com.willshex.blogwt.shared.api.datatype.Resource in project blogwt by billy1380.

the class UpdateResourceActionHandler method handle.

/* (non-Javadoc)
	 * 
	 * @see
	 * com.willshex.gson.web.service.server.ActionHandler#handle(com.willshex.
	 * gson.web.service.shared.Request,
	 * com.willshex.gson.web.service.shared.Response) */
@Override
protected void handle(UpdateResourceRequest input, UpdateResourceResponse output) throws Exception {
    ApiValidator.request(input, UpdateResourceRequest.class);
    ApiValidator.accessCode(input.accessCode, "input.accessCode");
    output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
    UserValidator.authorisation(input.session.user, Arrays.asList(PermissionServiceProvider.provide().getCodePermission(PermissionHelper.MANAGE_RESOURCES)), "input.session.user");
    Resource updatedResource = input.resource;
    input.resource = ResourceValidator.lookup(input.resource, "input.resource");
    updatedResource = ResourceValidator.validate(updatedResource, "input.resource");
    input.resource.name = updatedResource.name;
    input.resource.description = updatedResource.description;
    output.resource = ResourceServiceProvider.provide().updateResource(input.resource);
}
Also used : Resource(com.willshex.blogwt.shared.api.datatype.Resource)

Example 4 with Resource

use of com.willshex.blogwt.shared.api.datatype.Resource in project blogwt by billy1380.

the class ResourceValidator method lookup.

public static Resource lookup(Resource resource, String name) throws InputValidationException {
    if (resource == null)
        throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
    boolean isIdLookup = false;
    if (resource.id != null) {
        isIdLookup = true;
    }
    if (!isIdLookup)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
    Resource lookupResource = null;
    if (isIdLookup) {
        lookupResource = ResourceServiceProvider.provide().getResource(resource.id);
    }
    if (lookupResource == null)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return lookupResource;
}
Also used : Resource(com.willshex.blogwt.shared.api.datatype.Resource) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Example 5 with Resource

use of com.willshex.blogwt.shared.api.datatype.Resource in project blogwt by billy1380.

the class ResourceService method addResource.

/* (non-Javadoc)
	 * 
	 * @see
	 * com.willshex.blogwt.server.service.resource.IResourceService#addResource
	 * (com.willshex.blogwt.shared.api.datatype.Resource) */
@Override
public Resource addResource(Resource resource) {
    if (resource.created == null) {
        resource.created = new Date();
    }
    Key<Resource> key = provide().save().entity(resource).now();
    resource.id = keyToId(key);
    return resource;
}
Also used : Resource(com.willshex.blogwt.shared.api.datatype.Resource) Date(java.util.Date)

Aggregations

Resource (com.willshex.blogwt.shared.api.datatype.Resource)14 JsonElement (com.google.gson.JsonElement)6 PreloadedImage (gwtupload.client.PreloadedImage)3 JsonObject (com.google.gson.JsonObject)2 BlobKey (com.google.appengine.api.blobstore.BlobKey)1 JsonParser (com.google.gson.JsonParser)1 GWT (com.google.gwt.core.client.GWT)1 Element (com.google.gwt.dom.client.Element)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 UiBinder (com.google.gwt.uibinder.client.UiBinder)1 UiField (com.google.gwt.uibinder.client.UiField)1 UiHandler (com.google.gwt.uibinder.client.UiHandler)1 Button (com.google.gwt.user.client.ui.Button)1 FormPanel (com.google.gwt.user.client.ui.FormPanel)1 HTMLPanel (com.google.gwt.user.client.ui.HTMLPanel)1 Image (com.google.gwt.user.client.ui.Image)1 TextArea (com.google.gwt.user.client.ui.TextArea)1 TextBox (com.google.gwt.user.client.ui.TextBox)1 Widget (com.google.gwt.user.client.ui.Widget)1 DefaultEventBus (com.willshex.blogwt.client.DefaultEventBus)1