Search in sources :

Example 6 with GeneratedDownload

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

the class GetGeneratedDownloadsResponse method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("downloads")) {
        JsonElement jsonDownloads = jsonObject.get("downloads");
        if (jsonDownloads != null) {
            downloads = new ArrayList<GeneratedDownload>();
            GeneratedDownload item = null;
            for (int i = 0; i < jsonDownloads.getAsJsonArray().size(); i++) {
                if (jsonDownloads.getAsJsonArray().get(i) != null) {
                    (item = new GeneratedDownload()).fromJson(jsonDownloads.getAsJsonArray().get(i).getAsJsonObject());
                    downloads.add(item);
                }
            }
        }
    }
    if (jsonObject.has("pager")) {
        JsonElement jsonPager = jsonObject.get("pager");
        if (jsonPager != null) {
            pager = new Pager();
            pager.fromJson(jsonPager.getAsJsonObject());
        }
    }
}
Also used : GeneratedDownload(com.willshex.blogwt.shared.api.datatype.GeneratedDownload) JsonElement(com.google.gson.JsonElement) Pager(com.willshex.blogwt.shared.api.Pager)

Example 7 with GeneratedDownload

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

the class DownloadsPage method createColumns.

/**
 */
private void createColumns() {
    Column<GeneratedDownload, SafeHtml> name = new Column<GeneratedDownload, SafeHtml>(UiHelper.SAFE_HTML_PROTOTYPE) {

        @Override
        public SafeHtml getValue(GeneratedDownload object) {
            String parameters = object.parameters.replace("/send", "");
            String label = parameters.replace(Filter.QUERY + "/", "").replace("/", " > ");
            label = URL.decodeQueryString(label);
            return parameters.startsWith("proforma") || parameters.startsWith("invoice") ? Templates.INSTANCE.label(label) : Templates.INSTANCE.label(label, PageTypeHelper.slugToHref(parameters));
        }
    };
    TextColumn<GeneratedDownload> date = new TextColumn<GeneratedDownload>() {

        @Override
        public String getValue(GeneratedDownload object) {
            Date date;
            if (object.created == null) {
                date = DateTimeHelper.now();
            } else {
                date = object.created;
            }
            return DateTimeHelper.ago(date);
        }
    };
    TextColumn<GeneratedDownload> status = new TextColumn<GeneratedDownload>() {

        @Override
        public String getValue(GeneratedDownload object) {
            return object.status.toString();
        }
    };
    Column<GeneratedDownload, SafeHtml> download = new Column<GeneratedDownload, SafeHtml>(UiHelper.SAFE_HTML_PROTOTYPE) {

        @Override
        public SafeHtml getValue(GeneratedDownload object) {
            return object.status == GeneratedDownloadStatusType.GeneratedDownloadStatusTypeReady ? Templates.INSTANCE.download(UriUtils.fromString(object.url)) : SafeHtmlUtils.EMPTY_SAFE_HTML;
        }
    };
    tblDownloads.setColumnWidth(download, 1.0, Unit.PX);
    Column<GeneratedDownload, String> delete = new Column<GeneratedDownload, String>(ACTION_BUTTON_PROTOTYPE) {

        @Override
        public String getValue(GeneratedDownload object) {
            return "delete";
        }
    };
    delete.setFieldUpdater(new FieldUpdater<GeneratedDownload, String>() {

        @Override
        public void update(int index, GeneratedDownload object, String value) {
            if (Window.confirm("Are you sure you want to delete export with parameters " + URL.decodeQueryString(object.parameters) + "?")) {
                GeneratedDownloadController.get().deleteGeneratedDownload(object);
            }
        }
    });
    tblDownloads.setColumnWidth(delete, 1.0, Unit.PX);
    tblDownloads.addColumn(name, "Type");
    tblDownloads.addColumn(date, "Date");
    tblDownloads.addColumn(status, "Completion");
    // actions
    tblDownloads.addColumn(download);
    tblDownloads.addColumn(delete);
}
Also used : GeneratedDownload(com.willshex.blogwt.shared.api.datatype.GeneratedDownload) TextColumn(com.google.gwt.user.cellview.client.TextColumn) Column(com.google.gwt.user.cellview.client.Column) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Date(java.util.Date) TextColumn(com.google.gwt.user.cellview.client.TextColumn)

Example 8 with GeneratedDownload

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

the class DevServlet method doGet.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.service.ContextAwareServlet#doGet() */
@Override
protected void doGet() throws ServletException, IOException {
    super.doGet();
    String action = REQUEST.get().getParameter("action");
    if (action != null) {
        action = action.toLowerCase();
    }
    if ("gentags".equals(action)) {
        TagServiceProvider.provide().generateTags();
    } else if (action != null && action.startsWith("index")) {
        PageServiceProvider.provide();
        PostServiceProvider.provide();
        UserServiceProvider.provide();
        ((ISearch<?>) ServiceDiscovery.getService("blogwt." + action.replace("index", ""))).indexAll();
    } else if ("clearsearch".equals(action)) {
        PersistenceServiceProvider.provide();
        String name = REQUEST.get().getParameter("index");
        String ids = REQUEST.get().getParameter("ids");
        String[] split = ids.split(",");
        for (String id : split) {
            SearchHelper.deleteSearch(name, id);
        }
    } else if ("linkall".equals(action)) {
        PostServiceProvider.provide().linkAll();
    } else if ("clearlinks".equals(action)) {
        PostServiceProvider.provide().clearLinks();
    } else if ("archiveall".equals(action)) {
        ArchiveEntryServiceProvider.provide().generateArchive();
    } else if ("fixroles".equals(action)) {
        Collection<Role> all = RoleHelper.createAll();
        all.stream().forEach(role -> {
            Role loaded = RoleServiceProvider.provide().getCodeRole(role.code);
            if (loaded == null || loaded.id == null) {
                RoleServiceProvider.provide().addRole(role);
            }
            if (role.permissions != null) {
                role.permissions.stream().forEach(i -> {
                    Permission lp = PermissionServiceProvider.provide().getCodePermission(i.code);
                    if (lp == null) {
                        if (LOG.isLoggable(Level.WARNING)) {
                            LOG.warning("Could not find permission with code [" + i.code + "], might want to run [fixpermissions] action");
                        }
                    } else {
                        if (loaded.permissions == null) {
                            loaded.permissions = new ArrayList<>();
                        }
                        loaded.permissions.add(lp);
                    }
                });
                RoleServiceProvider.provide().updateRole(loaded);
            }
        });
    } else if ("fixpermissions".equals(action)) {
        Collection<Permission> all = PermissionHelper.createAll();
        Permission loaded;
        for (Permission permission : all) {
            loaded = PermissionServiceProvider.provide().getCodePermission(permission.code);
            if (loaded == null || loaded.id == null) {
                PermissionServiceProvider.provide().addPermission(permission);
            }
        }
    } else if ("getposts".equals(action)) {
        RESPONSE.get().getOutputStream().print(JsonUtils.beautifyJson((new GetPostsActionHandler()).handle((GetPostsRequest) new GetPostsRequest().showAll(Boolean.TRUE).pager(PagerHelper.createDefaultPager()).accessCode(ApiValidator.DEV_ACCESS_CODE)).toString()));
    } else if ("staticurl".equals(action)) {
        List<Resource> resources = ResourceServiceProvider.provide().getResources(Integer.valueOf(0), Integer.valueOf(Integer.MAX_VALUE), null, null);
        JsonObject object;
        for (Resource resource : resources) {
            if (resource.properties != null) {
                if (resource.properties.contains(":image")) {
                    resource.properties = resource.properties.replace(":image", ":\"image").replace("}", "\"}");
                }
                object = new JsonParser().parse(resource.properties).getAsJsonObject();
            } else {
                object = new JsonObject();
            }
            if (!object.has("staticUrl") || object.get("staticUrl").getAsString().startsWith("http")) {
                try {
                    object.addProperty("staticUrl", ImagesServiceFactory.getImagesService().getServingUrl(ServingUrlOptions.Builder.withBlobKey(new BlobKey(resource.data.replace("gs://", "")))).replaceFirst("https:\\/\\/", "//").replaceFirst("http:\\/\\/", "//"));
                } catch (Throwable e) {
                    if (LOG.isLoggable(Level.FINE)) {
                        LOG.fine("Could not update resource");
                    }
                }
                resource.properties = object.toString();
                ResourceServiceProvider.provide().updateResource(resource);
            }
        }
    } else if ("fixmetanotifications".equals(action)) {
        List<MetaNotification> metas = MetaNotificationHelper.createAll();
        for (MetaNotification meta : metas) {
            if (MetaNotificationServiceProvider.provide().getCodeMetaNotification(meta.code) == null) {
                meta = MetaNotificationServiceProvider.provide().addMetaNotification(meta);
                LOG.info("added meta notification [" + meta.code + "] with id [" + meta.id + "]");
            } else {
                LOG.info("Meta notification [" + meta.code + "] already exists");
            }
        }
    } else if ("admin".equals(action)) {
        User user = UserServiceProvider.provide().getUsernameUser(REQUEST.get().getParameter("user"));
        UserServiceProvider.provide().addUserRolesAndPermissions(user, Arrays.asList(RoleServiceProvider.provide().getCodeRole(RoleHelper.ADMIN)), null);
    } else if ("genandshowdownload".equals(action)) {
        String idParam = REQUEST.get().getParameter("id");
        Long id = Long.valueOf(idParam);
        GeneratedDownload d = GeneratedDownloadServiceProvider.provide().getGeneratedDownload(id);
        Stack stack = Stack.parse(d.parameters);
        Filter filter = Filter.fromStack(stack);
        switch(filter.type) {
            default:
                break;
        }
    }
}
Also used : GetPostsActionHandler(com.willshex.blogwt.server.api.blog.action.GetPostsActionHandler) User(com.willshex.blogwt.shared.api.datatype.User) GetPostsRequest(com.willshex.blogwt.shared.api.blog.call.GetPostsRequest) Resource(com.willshex.blogwt.shared.api.datatype.Resource) JsonObject(com.google.gson.JsonObject) MetaNotification(com.willshex.blogwt.shared.api.datatype.MetaNotification) Stack(com.willshex.blogwt.shared.page.Stack) Role(com.willshex.blogwt.shared.api.datatype.Role) BlobKey(com.google.appengine.api.blobstore.BlobKey) GeneratedDownload(com.willshex.blogwt.shared.api.datatype.GeneratedDownload) Filter(com.willshex.blogwt.shared.page.search.Filter) Permission(com.willshex.blogwt.shared.api.datatype.Permission) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) JsonParser(com.google.gson.JsonParser)

Example 9 with GeneratedDownload

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

the class GeneratedDownloadValidator method lookup.

public static GeneratedDownload lookup(GeneratedDownload generatedDownload, String name) throws InputValidationException {
    if (generatedDownload == null)
        throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
    notNull(generatedDownload.id, Long.class, name + ".id");
    GeneratedDownload lookupGeneratedDownload = GeneratedDownloadServiceProvider.provide().getGeneratedDownload(generatedDownload.id);
    if (lookupGeneratedDownload == null)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return lookupGeneratedDownload;
}
Also used : GeneratedDownload(com.willshex.blogwt.shared.api.datatype.GeneratedDownload) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Example 10 with GeneratedDownload

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

the class GeneratedDownloadService method addGeneratedDownload.

@Override
public GeneratedDownload addGeneratedDownload(GeneratedDownload generatedDownload) {
    if (generatedDownload.created == null) {
        generatedDownload.created = new Date();
    }
    generatedDownload.userKey = Key.create(generatedDownload.user);
    generatedDownload.status = GeneratedDownloadStatusType.GeneratedDownloadStatusTypeGenerating;
    Key<GeneratedDownload> generatedKey = provide().save().entity(generatedDownload).now();
    generatedDownload.id = Long.valueOf(generatedKey.getId());
    GenerateDownloadServlet.generateDownload(generatedDownload);
    return generatedDownload;
}
Also used : GeneratedDownload(com.willshex.blogwt.shared.api.datatype.GeneratedDownload) Date(java.util.Date)

Aggregations

GeneratedDownload (com.willshex.blogwt.shared.api.datatype.GeneratedDownload)13 JsonElement (com.google.gson.JsonElement)5 Filter (com.willshex.blogwt.shared.page.search.Filter)3 User (com.willshex.blogwt.shared.api.datatype.User)2 Stack (com.willshex.blogwt.shared.page.Stack)2 Date (java.util.Date)2 BlobKey (com.google.appengine.api.blobstore.BlobKey)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 Column (com.google.gwt.user.cellview.client.Column)1 TextColumn (com.google.gwt.user.cellview.client.TextColumn)1 GetPostsActionHandler (com.willshex.blogwt.server.api.blog.action.GetPostsActionHandler)1 IGenerator (com.willshex.blogwt.server.background.generatedownload.generator.IGenerator)1 Pager (com.willshex.blogwt.shared.api.Pager)1 GetPostsRequest (com.willshex.blogwt.shared.api.blog.call.GetPostsRequest)1 MetaNotification (com.willshex.blogwt.shared.api.datatype.MetaNotification)1 Permission (com.willshex.blogwt.shared.api.datatype.Permission)1 Resource (com.willshex.blogwt.shared.api.datatype.Resource)1 Role (com.willshex.blogwt.shared.api.datatype.Role)1