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();
}
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));
}
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);
}
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;
}
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;
}
Aggregations