Package com.psddev.dari.db

Examples of com.psddev.dari.db.ObjectType


        if (settings == null) {
            settings = page.getCmsTool().getBulkUploadSettings();
        }

        ObjectType defaultType = settings != null ? settings.getDefaultType() : null;

        page.writeStart("div", "class", "widget uploadable");
            page.writeStart("h1", "class", "icon icon-action-upload").writeHtml("Bulk Upload").writeEnd();
            page.writeStart("div", "class", "message message-info");

                if (!hasUploadable) {
                    page.writeHtml("There aren't any content types that can be uploaded in bulk.");

                } else {
                    page.writeHtml("Drag and drop or ");
                    page.writeStart("a",
                            "class", "uploadableLink",
                            "target", "uploadFiles",
                            "href", page.url("/content/uploadFiles",
                                    "typeId", ObjectType.getInstance(Content.class).getId(),
                                    "type", defaultType != null ? defaultType.getId() : null));
                        page.writeHtml("select");
                    page.writeEnd();
                    page.writeHtml(" files.");
                }
View Full Code Here


    }

    @Override
    protected void doService(final ToolPageContext page) throws IOException, ServletException {
        String type = page.pageParam(String.class, "type", null);
        final ObjectType itemType = Query.findById(ObjectType.class, page.pageParam(UUID.class, "itemType", null));
        long offset = page.param(long.class, "offset");
        int limit = page.pageParam(Integer.class, "limit", 20);

        List<ObjectType> types = new ArrayList<ObjectType>();
        boolean typeFound = false;

        for (ObjectType t : Database.Static.getDefault().getEnvironment().getTypes()) {
            if (t.as(ToolUi.class).isGlobalFilter()) {
                types.add(t);
                if (type != null && type.equals(t.getId().toString())) {
                    typeFound = true;
                }
            }
        }

        Collections.sort(types);

        if (!typeFound) {
            type = URL_TYPE;
        }

        String valueParameter = type + ".value";
        final String value = page.pageParam(String.class, valueParameter, null);
        Object valueObject = Query.from(Object.class).where("_id = ?", value).first();
        PaginatedResult<?> result = null;
        Long count = null;

        if (type.equals(URL_TYPE)) {
            if (!(valueObject instanceof Directory)) {
                valueObject = Query.from(Directory.class).where("path = /").first();
            }

            if (valueObject != null) {
                result = new AggregateQueryResult<Object>(offset, limit, new DirectoryQueryIterator(Query.
                        from(Directory.class).
                        where("path startsWith ?", ((Directory) valueObject).getPath()).
                        sortAscending("path")) {

                    @Override
                    protected Query<?> createQuery(Directory directory) {
                        return (itemType != null ? Query.fromType(itemType) : Query.fromAll()).
                                and(page.siteItemsSearchPredicate()).
                                and(directory.itemsPredicate(page.getSite())).
                                sortAscending(Directory.PATHS_FIELD);
                    }
                });

                count = null;
            }

        } else if (valueObject != null) {
            Query<?> query = (itemType != null ? Query.fromType(itemType) : Query.fromAll()).
                    and(page.siteItemsPredicate()).
                    and("* matches ?", value).
                    and("cms.directory.paths != missing");

            if (query.hasMoreThan(250)) {
                result = new AggregateQueryResult<Object>(offset, limit, new DirectoryQueryIterator(Query.
                        from(Directory.class).
                        where("path startsWith /").
                        sortAscending("path")) {

                    @Override
                    protected Query<?> createQuery(Directory directory) {
                        return (itemType != null ? Query.fromType(itemType) : Query.fromAll()).
                                and(page.siteItemsPredicate()).
                                and(directory.itemsPredicate(page.getSite())).
                                and("* matches ?", value).
                                and("cms.directory.paths != missing");
                    }
                });

                count = query.count();

            } else {
                @SuppressWarnings("unchecked")
                List<Object> items = (List<Object>) query.selectAll();

                Collections.sort(items, new Comparator<Object>() {
                    @Override
                    public int compare(Object x, Object y) {
                        return ObjectUtils.compare(
                                State.getInstance(x).as(Directory.ObjectModification.class).getPermalink(),
                                State.getInstance(y).as(Directory.ObjectModification.class).getPermalink(),
                                true);
                    }
                });

                result = new PaginatedResult<Object>(offset, limit, items);
                count = (long) items.size();
            }
        }

        if (count == null && result != null && result.getFirstItemIndex() == 1 && !result.hasNext()) {
            count = (long) result.getItems().size();
        }

        page.writeStart("div", "class", "widget");
            page.writeStart("h1", "class", "icon icon-sitemap");
                page.writeHtml("Sitemap");
            page.writeEnd();

            page.writeStart("form",
                    "method", "get",
                    "action", page.url(null));
                page.writeStart("ul", "class", "oneLine");
                    page.writeStart("li");
                        page.writeTypeSelect(
                                Template.Static.findUsedTypes(page.getSite()),
                                itemType,
                                "Any Types",
                                "name", "itemType",
                                "data-bsp-autosubmit", "",
                                "data-searchable", "true");
                    page.writeEnd();

                    if (types.isEmpty()) {
                        page.writeElement("input",
                                "type", "hidden",
                                "name", "type",
                                "value", URL_TYPE);

                    } else {
                        page.writeStart("li");
                            page.writeHtml("with ");

                            page.writeStart("select",
                                    "data-bsp-autosubmit", "",
                                    "name", "type");

                                page.writeStart("option",
                                        "selected", type.equals(URL_TYPE) ? "selected" : null,
                                        "value", URL_TYPE);
                                    page.writeHtml("URL");
                                page.writeEnd();

                                for (ObjectType t : types) {
                                    String id = t.getId().toString();
                                    page.writeStart("option",
                                            "selected", type.equals(id) ? "selected" : null,
                                            "value", id);
                                        page.writeHtml(t.getDisplayName());
                                    page.writeEnd();
                                }

                            page.writeEnd();
                        page.writeEnd();
                    }

                    page.writeStart("li");
                        page.writeHtml("in ");

                        Query<?> valueQuery;
                        ObjectType valueType;

                        if (type.equals(URL_TYPE)) {
                            valueType = ObjectType.getInstance(Directory.class);
                            valueQuery = Query.from(Directory.class).sortAscending("path");
                            valueQuery.where("path != missing");

                        } else {
                            valueType = ObjectType.getInstance(ObjectUtils.to(UUID.class, type));
                            valueQuery = Query.fromType(valueType);

                            for (String fieldName : valueType.getLabelFields()) {
                                ObjectField field = valueType.getField(fieldName);

                                if (field != null && valueType.getIndex(fieldName) != null) {
                                    valueQuery.sortAscending(valueType.getInternalName() + "/" + fieldName);
                                }
                            }
                        }

                        if (valueQuery.hasMoreThan(250)) {
                            page.writeElement("input",
                                    "type", "text",
                                    "class", "objectId",
                                    "data-bsp-autosubmit", "",
                                    "data-editable", false,
                                    "data-label", valueObject != null ? State.getInstance(valueObject).getLabel() : null,
                                    "data-typeIds", valueType.getId(),
                                    "name", valueParameter,
                                    "value", value);

                        } else {
                            page.writeStart("select",
                                    "name", valueParameter,
                                    "data-bsp-autosubmit", "",
                                    "data-searchable", "true");

                                if (!type.equals(URL_TYPE)) {
                                    page.writeStart("option", "value", "").writeEnd();
                                }

                                for (Object v : valueQuery.selectAll()) {
                                    State state = State.getInstance(v);

                                    page.writeStart("option",
                                            "value", state.getId(),
                                            "selected", v.equals(valueObject) ? "selected" : null);
                                        page.writeHtml(state.getLabel());
                                    page.writeEnd();
                                }

                            page.writeEnd();
                        }
                    page.writeEnd();
                page.writeEnd();
            page.writeEnd();

            if (valueObject == null) {
                page.writeStart("div", "class", "message message-warning");
                    page.writeStart("p");
                        page.writeHtml("Please select a ");
                        page.writeStart("strong").writeHtml(valueType.getLabel()).writeEnd();
                        page.writeHtml(".");
                    page.writeEnd();
                page.writeEnd();

            } else if (!result.hasPages()) {
View Full Code Here

        return null;
    }

    @Override
    protected void doService(ToolPageContext page) throws IOException, ServletException {
        ObjectType type = ObjectType.getInstance(page.param(UUID.class, "typeId"));

        if (type == null) {
            throw new IllegalArgumentException();
        }

        String fieldName = page.param(String.class, "field");
        ObjectField field = type.getField(fieldName);

        if (field == null) {
            field = type.getEnvironment().getField(fieldName);
        }

        page.writeHeader();
            page.writeStart("style", "type", "text/css");
                page.writeCss(".cms-guideField th",
View Full Code Here

        this.sortField = null;
    }

    public List<ObjectField> getIndexedFields() {
        if (indexedFields == null) {
            ObjectType type = getQueryType();
            Set<String> indexedFieldNames = new HashSet<String>();
            List<ObjectField> newIndexedFields = new ArrayList<ObjectField>();

            for (ObjectIndex index : type.getIndexes()) {
                List<String> fields = index.getFields();
                if (fields != null) {
                    indexedFieldNames.addAll(fields);
                }
            }

            for (ObjectField field : type.getFields()) {
                if (indexedFieldNames.contains(field.getInternalName())) {
                    newIndexedFields.add(field);
                }
            }
View Full Code Here

        return sortableFields;
    }

    public ObjectField getSortField() {
        if (sortField == null) {
            ObjectType type = getQueryType();
            ObjectField newSortField = null;

            for (ObjectField field : getSortableFields()) {
                if (field.getInternalName().equals(getSortFieldName())) {
                    newSortField = field;
                    break;
                }
            }

            if (newSortField == null) {
                LABEL_FIELD: for (String labelField : type.getLabelFields()) {
                    for (ObjectField field : getSortableFields()) {
                        if (field.getInternalName().equals(labelField)) {
                            newSortField = field;
                            break LABEL_FIELD;
                        }
                    }
                }
            }

            if (newSortField == null) {
                newSortField = type.getState().getDatabase().getEnvironment().getField("cms.content.publishDate");
            }

            sortField = newSortField;
        }
View Full Code Here

                if (Boolean.TRUE.equals(map.get("_isIgnore"))) {
                    return null;
                }

                ObjectType type = ObjectType.getInstance((String) map.get("_type"));
                if (type == null) {
                    return map;
                }

                UUID sectionPageId = ObjectUtils.to(UUID.class, map.get("page"));
                Object section;
                if (!Boolean.TRUE.equals(map.get("isShareable")) &&
                        !page.getId().equals(sectionPageId)) {
                    section = type.createObject(null);
                } else {
                    UUID id = ObjectUtils.to(UUID.class, map.get("_id"));
                    section = Query.findById(Object.class, id);
                    if (section == null) {
                        section = type.createObject(id);
                    } else if (!(section instanceof Section)) {
                        section = type.createObject(null);
                    } else {
                        State.getInstance(section).setType(type);
                    }
                }
View Full Code Here

        Map<String, Object> definition = super.toDefinition();
        Object content = getContent();

        if (content != null) {
            State contentState = State.getInstance(content);
            ObjectType contentType = contentState.getType();

            definition.put("content", contentState.getId().toString());
            definition.put("contentLabel", contentState.getLabel());

            if (contentType != null) {
                definition.put("contentTypeLabel", contentType.getLabel());
            }
        }

        return definition;
    }
View Full Code Here

    @Override
    protected void doService(ToolPageContext page) throws IOException, ServletException {
        Search search = new Search(page);
        Query<?> query = search.toQuery(page.getSite());
        DatabaseEnvironment environment = Database.Static.getDefault().getEnvironment();
        ObjectType type = search.getSelectedType();
        List<Display> allDisplays = new ArrayList<Display>();

        allDisplays.add(new ReferencesDisplay());
        allDisplays.add(new PathsDisplay());

        for (String name : new String[] {
                "cms.content.publishDate",
                "cms.content.publishUser",
                "cms.content.updateDate",
                "cms.content.updateUser" }) {

            allDisplays.add(new ObjectFieldDisplay(environment.getField(name)));
        }

        if (type != null) {
            for (ObjectField field : type.getFields()) {
                allDisplays.add(new ObjectFieldDisplay(field));
            }
        }

        List<String> displayNames = page.params(String.class, FIELDS_PARAMETER);
View Full Code Here

                        "width", "50%"));
                    page.writeStart("h2").writeHtml("Create New").writeEnd();

                    page.writeStart("ul", "class", "links pageThumbnails");
                        for (TypeTemplate typeTemplate : favorites) {
                            ObjectType type = typeTemplate.type;
                            Template template = typeTemplate.template;
                            State state = State.getInstance(Query.fromType(type).where("cms.template.default = ?", template).first());
                            String permalink = null;

                            if (state != null) {
                                permalink = state.as(Directory.ObjectModification.class).getPermalink();
                            }

                            page.writeStart("li", "data-preview-url", permalink);
                                page.writeStart("a",
                                        "target", "_top",
                                        "href", page.url("/content/edit.jsp",
                                                "typeId", type.getId(),
                                                "templateId", template != null ? template.getId() : null));
                                    page.writeHtml(getTypeTemplateLabel(typeCounts, typeTemplate));
                                page.writeEnd();
                            page.writeEnd();
                        }
View Full Code Here

            }
        page.writeEnd();
    }

    private String getTypeTemplateLabel(Map<ObjectType, Integer> typeCounts, TypeTemplate typeTemplate) {
        ObjectType type = typeTemplate.type;
        Template template = typeTemplate.template;
        StringBuilder label = new StringBuilder();

        label.append(ToolPageContext.Static.getObjectLabel(type));
View Full Code Here

TOP

Related Classes of com.psddev.dari.db.ObjectType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.