Package com.psddev.dari.db

Examples of com.psddev.dari.db.ObjectType


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

                        if (object != null) {
                            ObjectType type = state.getType();

                            page.writeStart("table", "class", "table-striped");
                                page.writeStart("tbody");
                                    if (type != null) {
                                        Class<?> objectClass = type.getObjectClass();

                                        if (objectClass != null) {
                                            page.writeStart("tr");
                                                page.writeStart("th");
                                                    page.writeStart("label", "for", page.createId());
                                                        page.writeHtml("Class");
                                                    page.writeEnd();
                                                page.writeEnd();

                                                page.writeStart("td");
                                                    page.writeJavaClassLink(objectClass);
                                                page.writeEnd();
                                            page.writeEnd();
                                        }
                                    }

                                    page.writeStart("tr");
                                        page.writeStart("th");
                                            page.writeStart("label", "for", page.createId());
                                                page.writeHtml("ID");
                                            page.writeEnd();
                                        page.writeEnd();

                                        page.writeStart("td");
                                            page.writeElement("input",
                                                    "type", "text",
                                                    "id", page.getId(),
                                                    "class", "code",
                                                    "value", state.getId(),
                                                    "readonly", "readonly",
                                                    "style", "width:100%;",
                                                    "onclick", "this.select();");
                                        page.writeEnd();
                                    page.writeEnd();

                                    page.writeStart("tr");
                                        page.writeStart("th");
                                            page.writeStart("label", "for", page.createId());
                                                page.writeHtml("URL");
                                            page.writeEnd();
                                        page.writeEnd();

                                        page.writeStart("td");
                                            page.writeElement("input",
                                                    "type", "text",
                                                    "id", page.getId(),
                                                    "value", JspUtils.getAbsoluteUrl(page.getRequest(), page.cmsUrl("/content/edit.jsp", "id", state.getId())),
                                                    "readonly", "readonly",
                                                    "style", "width:100%;",
                                                    "onclick", "this.select();");
                                        page.writeEnd();
                                    page.writeEnd();
                                page.writeEnd();
                            page.writeEnd();
                        }

                        if (object != null) {
                            ObjectType type = state.getType();

                            if (type != null) {
                                if (!ObjectUtils.isBlank(type.as(Renderer.TypeModification.class).getEmbedPath())) {
                                    String permalink = state.as(Directory.ObjectModification.class).getPermalink();

                                    if (!ObjectUtils.isBlank(permalink)) {
                                        String siteUrl = Application.Static.getInstance(CmsTool.class).getDefaultSiteUrl();
                                        StringBuilder embedCode = new StringBuilder();

                                        embedCode.append("<script type=\"text/javascript\" src=\"");
                                        embedCode.append(StringUtils.addQueryParameters(
                                                StringUtils.removeEnd(siteUrl, "/") + permalink,
                                                "_embed", true,
                                                "_format", "js"));
                                        embedCode.append("\"></script>");

                                        page.writeHtml("Embed Code:");
                                        page.writeElement("br");
                                        page.writeStart("textarea",
                                                "class", "code",
                                                "data-expandable-class", "code",
                                                "readonly", "readonly",
                                                "onclick", "this.select();");
                                            page.writeHtml(embedCode);
                                        page.writeEnd();
                                    }
                                }

                                String defaultPath = type.as(Renderer.TypeModification.class).getPath();
                                Map<String, String> paths = type.as(Renderer.TypeModification.class).getPaths();

                                if (!ObjectUtils.isBlank(defaultPath) || !ObjectUtils.isBlank(paths)) {
                                    page.writeStart("h2");
                                        page.writeHtml("Renderers");
                                    page.writeEnd();

                                    page.writeStart("table", "class", "table-striped");
                                        page.writeStart("tbody");
                                            if (!ObjectUtils.isBlank(defaultPath)) {
                                                page.writeStart("tr");
                                                    page.writeStart("th");
                                                        page.writeStart("code");
                                                            page.writeHtml("Default");
                                                        page.writeEnd();
                                                    page.writeEnd();

                                                    page.writeStart("td");
                                                        page.writeStart("code");
                                                            page.writeStart("a",
                                                                    "target", "_blank",
                                                                    "href", DebugFilter.Static.getServletPath(page.getRequest(), "code",
                                                                            "action", "edit",
                                                                            "type", "JSP",
                                                                            "servletPath", defaultPath));
                                                                page.writeHtml(defaultPath);
                                                            page.writeEnd();
                                                        page.writeEnd();
                                                    page.writeEnd();
                                                page.writeEnd();
                                            }

                                            for (Map.Entry<String, String> entry : paths.entrySet()) {
                                                page.writeStart("tr");
                                                    page.writeStart("th");
                                                        page.writeStart("code");
                                                            page.writeHtml(entry.getKey());
                                                        page.writeEnd();
                                                    page.writeEnd();

                                                    page.writeStart("td");
                                                        page.writeStart("code");
                                                            page.writeStart("a",
                                                                    "target", "_blank",
                                                                    "href", DebugFilter.Static.getServletPath(page.getRequest(), "code",
                                                                            "action", "edit",
                                                                            "type", "JSP",
                                                                            "servletPath", entry.getValue()));
                                                                page.writeHtml(entry.getValue());
                                                            page.writeEnd();
                                                        page.writeEnd();
                                                    page.writeEnd();
                                                page.writeEnd();
                                            }
                                        page.writeEnd();
                                    page.writeEnd();
                                }

                                Class<?> objectClass = type.getObjectClass();

                                if (objectClass != null) {
                                    Static.writeJavaAnnotationDescriptions(page, objectClass);
                                }
                            }
View Full Code Here


                            if (objectStrings != null) {
                                for (String objectString : objectStrings) {
                                    if (!ObjectUtils.isBlank(objectString)) {
                                        @SuppressWarnings("unchecked")
                                        Map<String, Object> objectMap = (Map<String, Object>) ObjectUtils.fromJson(objectString.trim());
                                        ObjectType type = ObjectType.getInstance(ObjectUtils.to(UUID.class, objectMap.remove("_typeId")));

                                        if (type != null) {
                                            Object object = type.createObject(ObjectUtils.to(UUID.class, objectMap.remove("_id")));
                                            State objectState = State.getInstance(object);

                                            objectState.setValues(objectMap);
                                            substitutions.put(objectState.getId(), object);
                                        }
View Full Code Here

         */
        public static String getTypeLabelOrDefault(Object object, String defaultLabel) {
            State state = State.getInstance(object);

            if (state != null) {
                ObjectType type = state.getType();

                if (type != null) {
                    return getObjectLabel(type);
                }
            }
View Full Code Here

     *
     * @param object Can't be {@code null}.
     */
    public void update(Object object) {
        State state = State.getInstance(object);
        ObjectType type = state.getType();
        SharedUpdatable sharedUpdatable = type != null ?
                type.as(TypeData.class).createSharedUpdatable() :
                null;

        if (sharedUpdatable != null) {
            sharedUpdatable.updateStageBefore(object, this);
        }
View Full Code Here

        if (value != null) {
            if (value instanceof Recordable) {
                State valueState = ((Recordable) value).getState();

                if (valueState.isNew()) {
                    ObjectType type;

                    if (embedded ||
                            ((type = valueState.getType()) != null &&
                            type.isEmbedded())) {
                        Object found = findContent(value, id);

                        if (found != null) {
                            return found;
                        }
View Full Code Here

        setName(page.param(String.class, NAME_PARAMETER));

        if (typeIds != null) {
            for (UUID typeId : typeIds) {
                ObjectType type = ObjectType.getInstance(typeId);

                if (type != null) {
                    getTypes().add(type);
                }
            }
View Full Code Here

    public Set<ObjectType> findValidTypes() {
        Set<ObjectType> types = getTypes();
        List<ObjectType> validTypes = new ArrayList<ObjectType>();

        if (types.size() == 1) {
            ObjectType type = types.iterator().next();

            if (type != null && Content.class.equals(type.getObjectClass())) {
                types.clear();
            }
        }

        for (ObjectType type : types) {
            validTypes.addAll(type.as(ToolUi.class).findDisplayTypes());
        }

        Collections.sort(validTypes);
        return new LinkedHashSet<ObjectType>(validTypes);
    }
View Full Code Here

     * @return Never {@code null}. The key is the unique ID, and the value
     * is the label. Sorted by the label.
     */
    public Map<String, String> findSorts() {
        Map<String, String> sorts = new LinkedHashMap<String, String>();
        ObjectType selectedType = getSelectedType();

        if (!ObjectUtils.isBlank(getQueryString())) {
            sorts.put(RELEVANT_SORT_VALUE, RELEVANT_SORT_LABEL);
        }

View Full Code Here

            }
        }

        Query<?> query = null;
        Set<ObjectType> types = getTypes();
        ObjectType selectedType = getSelectedType();
        Set<ObjectType> validTypes = findValidTypes();
        Set<UUID> validTypeIds = null;
        boolean isAllSearchable = true;

        if (selectedType != null) {
            isAllSearchable = Content.Static.isSearchableType(selectedType);
            query = Query.fromType(selectedType);

        } else {
            for (ObjectType type : validTypes) {
                if (!Content.Static.isSearchableType(type)) {
                    isAllSearchable = false;
                }
            }

            if (types.size() == 1) {
                for (ObjectType type : types) {
                    query = Query.fromType(type);
                    break;
                }

            } else {
                query = isAllSearchable ? Query.fromGroup(Content.SEARCHABLE_GROUP) : Query.fromAll();

                if (!validTypes.isEmpty()) {
                    validTypeIds = new HashSet<UUID>();

                    for (ObjectType t : validTypes) {
                        validTypeIds.add(t.getId());
                    }
                }
            }
        }

        String sort = getSort();
        boolean metricSort = false;

        if (RELEVANT_SORT_VALUE.equals(sort)) {
            if (isAllSearchable) {
                query.sortRelevant(100.0, "_label = ?", queryString);
                query.sortRelevant(10.0, "_label matches ?", queryString);
            }

        } else if (sort != null) {
            ObjectField sortField = selectedType != null ?
                    selectedType.getFieldGlobally(sort) :
                    Database.Static.getDefault().getEnvironment().getField(sort);

            if (sortField != null) {
                if (sortField.isMetric()) {
                    metricSort = true;
                }

                String sortName = selectedType != null ?
                        selectedType.getInternalName() + "/" + sort :
                        sort;

                if (ObjectField.TEXT_TYPE.equals(sortField.getInternalType())) {
                    query.sortAscending(sortName);

                } else {
                    query.sortDescending(sortName);
                }

                if (!isShowMissing()) {
                    query.and(sortName + " != missing");
                }
            }
        }

        if (metricSort) {
            // Skip Solr-related operations if sorting by metrics.

        } else if (ObjectUtils.isBlank(queryString)) {
            if (isAllSearchable) {
                query.and("* ~= *");
            }

        } else {

            // Strip http: or https: from the query for search by path below.
            if (queryString.length() > 8 &&
                    StringUtils.matches(queryString, "(?i)https?://.*")) {
                int slashAt = queryString.indexOf("/", 8);

                if (slashAt > -1) {
                    queryString = queryString.substring(slashAt);
                }
            }

            // Search by path.
            if (isAllSearchable && queryString.startsWith("/") && queryString.length() > 1) {
                List<String> paths = new ArrayList<String>();

                for (Directory directory : Query.
                        from(Directory.class).
                        where("path ^=[c] ?", queryString).
                        selectAll()) {
                    paths.add(directory.getRawPath());
                }

                int lastSlashAt = queryString.lastIndexOf("/");

                if (lastSlashAt > 0) {
                    for (Directory directory : Query.
                            from(Directory.class).
                            where("path ^=[c] ?", queryString.substring(0, lastSlashAt)).
                            selectAll()) {
                        paths.add(directory.getRawPath() + queryString.substring(lastSlashAt + 1));
                    }
                }

                query.and(Directory.PATHS_FIELD + " ^= ?", paths);

            // Full text search.
            } else if (isAllSearchable) {
                int lastSpaceAt = queryString.lastIndexOf(" ");

                if (lastSpaceAt > -1) {
                    query.and("* ~= ?", Arrays.asList(queryString, queryString.substring(0, lastSpaceAt)));

                } else {
                    query.and("* ~= ?", queryString);
                }

            } else if (selectedType != null) {
                for (String field : selectedType.getLabelFields()) {
                    if (selectedType.getIndex(field) != null) {
                        query.and(selectedType.getInternalName() + "/" + field + " contains[c] ?", queryString);
                    }
                    break;
                }

            } else {
                Predicate predicate = null;

                for (ObjectType type : validTypes) {
                    String prefix = type.getInternalName() + "/";

                    for (String field : type.getLabelFields()) {
                        if (type.getIndex(field) != null) {
                            predicate = CompoundPredicate.combine(
                                    PredicateParser.OR_OPERATOR,
                                    predicate,
                                    PredicateParser.Static.parse(prefix + field + " ^=[c] ?", queryString));
                        }
                        break;
                    }
                }

                query.and(predicate);
            }
        }

        if (isOnlyPathed()) {
            query.and(Directory.Static.hasPathPredicate());
        }

        if (isAllSearchable && selectedType == null) {
            DatabaseEnvironment environment = Database.Static.getDefault().getEnvironment();
            String q = getQueryString();

            if (!ObjectUtils.isBlank(q)) {
                q = q.replaceAll("\\s+", "").toLowerCase(Locale.ENGLISH);

                for (ObjectType t : environment.getTypes()) {
                    String name = t.getDisplayName();

                    if (!ObjectUtils.isBlank(name) &&
                            q.contains(name.replaceAll("\\s+", "").toLowerCase(Locale.ENGLISH))) {
                        query.sortRelevant(20.0, "_type = ?", t.as(ToolUi.class).findDisplayTypes());
                    }
                }
            }

            query.sortRelevant(10.0, "_type = ?", environment.getTypeByClass(Singleton.class).as(ToolUi.class).findDisplayTypes());
        }

        String additionalPredicate = getAdditionalPredicate();

        if (!ObjectUtils.isBlank(additionalPredicate)) {
            Object parent = Query.
                    from(Object.class).
                    where("_id = ?", getParentId()).
                    first();
            if (parent == null && getParentTypeId() != null) {
                ObjectType parentType = ObjectType.getInstance(getParentTypeId());
                parent = parentType.createObject(null);
            }
            query.and(additionalPredicate, parent);
        }

        String advancedQuery = getAdvancedQuery();
View Full Code Here

        @Override
        public void process(ObjectType type, CompatibleTypes annotation) {
            Set<ObjectType> compatibleTypes = new HashSet<ObjectType>();
            DatabaseEnvironment environment = type.getState().getDatabase().getEnvironment();
            for (Class<?> typeClass : annotation.value()) {
                ObjectType compatibleType = environment.getTypeByClass(typeClass);
                if (compatibleType != null) {
                    compatibleTypes.add(compatibleType);
                }
            }
            setCompatibleTypes(type, compatibleTypes);
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.