Search in sources :

Example 1 with ContentTypeConfigTO

use of org.craftercms.studio.api.v1.to.ContentTypeConfigTO in project studio by craftercms.

the class ContentTypeServiceInternalImpl method getQuickCreatableContentTypes.

@Override
public List<QuickCreateItem> getQuickCreatableContentTypes(String siteId) {
    List<QuickCreateItem> toRet = new ArrayList<QuickCreateItem>();
    List<ContentTypeConfigTO> allContentTypes = contentTypeService.getAllContentTypes(siteId, true);
    List<ContentTypeConfigTO> quickCreatable = allContentTypes.stream().filter(ct -> ct.isQuickCreate()).collect(Collectors.toList());
    for (ContentTypeConfigTO ctto : quickCreatable) {
        QuickCreateItem qci = new QuickCreateItem();
        qci.setSiteId(siteId);
        qci.setContentTypeId(ctto.getForm());
        qci.setLabel(ctto.getLabel());
        qci.setPath(ctto.getQuickCreatePath());
        Set<String> allowedPermission = securityService.getUserPermissions(siteId, ctto.getQuickCreatePath(), securityService.getCurrentUser(), null);
        if (allowedPermission.contains("create content")) {
            toRet.add(qci);
        }
    }
    return toRet;
}
Also used : ContentTypeConfigTO(org.craftercms.studio.api.v1.to.ContentTypeConfigTO) QuickCreateItem(org.craftercms.studio.api.v2.dal.QuickCreateItem) List(java.util.List) SecurityService(org.craftercms.studio.api.v1.service.security.SecurityService) ContentTypeService(org.craftercms.studio.api.v1.service.content.ContentTypeService) ContentTypeServiceInternal(org.craftercms.studio.api.v2.service.content.internal.ContentTypeServiceInternal) Set(java.util.Set) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ContentTypeConfigTO(org.craftercms.studio.api.v1.to.ContentTypeConfigTO) QuickCreateItem(org.craftercms.studio.api.v2.dal.QuickCreateItem) ArrayList(java.util.ArrayList)

Example 2 with ContentTypeConfigTO

use of org.craftercms.studio.api.v1.to.ContentTypeConfigTO in project studio by craftercms.

the class ContentServiceImpl method loadContentTypeProperties.

protected void loadContentTypeProperties(String site, ContentItemTO item, String contentType) {
    // TODO: SJ: Refactor in 2.7.x
    if (item.isFolder()) {
        item.setContentType(CONTENT_TYPE_FOLDER);
    } else {
        if (contentType != null && !contentType.equals(CONTENT_TYPE_FOLDER) && !contentType.equals("asset") && !contentType.equals(CONTENT_TYPE_UNKNOWN)) {
            ContentTypeConfigTO config = servicesConfig.getContentTypeConfig(site, contentType);
            if (config != null) {
                item.setForm(config.getForm());
                item.setFormPagePath(config.getFormPath());
                item.setPreviewable(config.isPreviewable());
                item.isPreviewable = item.previewable;
            }
        } else {
            MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
            String mimeType = mimeTypesMap.getContentType(item.getName());
            if (mimeType != null && !StringUtils.isEmpty(mimeType)) {
                item.setPreviewable(ContentUtils.matchesPatterns(mimeType, servicesConfig.getPreviewableMimetypesPaterns(site)));
                item.isPreviewable = item.previewable;
            }
        }
    }
// TODO CodeRev:but what if the config is null?
}
Also used : MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap) ContentTypeConfigTO(org.craftercms.studio.api.v1.to.ContentTypeConfigTO)

Example 3 with ContentTypeConfigTO

use of org.craftercms.studio.api.v1.to.ContentTypeConfigTO in project studio by craftercms.

the class ContentTypesConfigImpl method reloadConfiguration.

@Override
@ValidateParams
public ContentTypeConfigTO reloadConfiguration(@ValidateStringParam(name = "site") String site, @ValidateStringParam(name = "contentType") String contentType) {
    StudioCacheContext cacheContext = new StudioCacheContext(site, true);
    String siteConfigPath = getConfigPath().replaceAll(StudioConstants.PATTERN_SITE, site).replaceAll(StudioConstants.PATTERN_CONTENT_TYPE, contentType);
    ContentTypeConfigTO config = loadConfiguration(site, contentType);
    return config;
}
Also used : ContentTypeConfigTO(org.craftercms.studio.api.v1.to.ContentTypeConfigTO) StudioCacheContext(org.craftercms.studio.impl.v1.service.StudioCacheContext) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 4 with ContentTypeConfigTO

use of org.craftercms.studio.api.v1.to.ContentTypeConfigTO in project studio by craftercms.

the class ContentTypesConfigImpl method loadConfiguration.

@SuppressWarnings("unchecked")
@Override
@ValidateParams
public ContentTypeConfigTO loadConfiguration(@ValidateStringParam(name = "site") String site, @ValidateStringParam(name = "contentType") String contentType) {
    String siteConfigPath = getConfigPath().replaceAll(StudioConstants.PATTERN_SITE, site).replaceAll(StudioConstants.PATTERN_CONTENT_TYPE, contentType);
    String configFileFullPath = siteConfigPath + FILE_SEPARATOR + getConfigFileName();
    Document document = null;
    try {
        if (contentService.contentExists(site, configFileFullPath)) {
            document = contentService.getContentAsDocument(site, configFileFullPath);
        }
    } catch (DocumentException e) {
        logger.debug("No content type configuration document found at " + configFileFullPath, e);
    }
    if (document != null) {
        Element root = document.getRootElement();
        String name = root.valueOf("@name");
        ContentTypeConfigTO contentTypeConfig = new ContentTypeConfigTO();
        contentTypeConfig.setName(name);
        contentTypeConfig.setLabel(root.valueOf("label"));
        String imageThumbnail = root.valueOf("image-thumbnail");
        if (imageThumbnail != null)
            contentTypeConfig.setImageThumbnail(imageThumbnail);
        contentTypeConfig.setForm(root.valueOf("form"));
        boolean previewable = ContentFormatUtils.getBooleanValue(root.valueOf("previewable"));
        contentTypeConfig.setFormPath(root.valueOf("form-path"));
        contentTypeConfig.setPreviewable(previewable);
        contentTypeConfig.setModelInstancePath(root.valueOf("model-instance-path"));
        boolean contentAsFolder = ContentFormatUtils.getBooleanValue(root.valueOf("content-as-folder"));
        contentTypeConfig.setContentAsFolder(contentAsFolder);
        boolean useRoundedFolder = ContentFormatUtils.getBooleanValue(root.valueOf("use-rounded-folder"));
        contentTypeConfig.setUseRoundedFolder(useRoundedFolder);
        List<String> pathIncludes = getPaths(root, "paths/includes/pattern");
        if (pathIncludes.size() == 0) {
            // if no configuration, include every path
            pathIncludes.add(".*");
        }
        contentTypeConfig.setPathIncludes(pathIncludes);
        List<String> pathExcludes = getPaths(root, "paths/excludes/pattern");
        contentTypeConfig.setPathExcludes(pathExcludes);
        loadRoles(contentTypeConfig, root.selectNodes("allowed-roles/role"));
        loadDeleteDependencies(contentTypeConfig, root.selectNodes("delete-dependencies/delete-dependency"));
        loadCopyDependencyPatterns(contentTypeConfig, root.selectNodes("copy-dependencies/copy-dependency"));
        contentTypeConfig.setLastUpdated(ZonedDateTime.now(ZoneOffset.UTC));
        contentTypeConfig.setType(getContentTypeTypeByName(name));
        boolean quickCreate = ContentFormatUtils.getBooleanValue(root.valueOf(QUICK_CREATE));
        contentTypeConfig.setQuickCreate(quickCreate);
        contentTypeConfig.setQuickCreatePath(root.valueOf(QUICK_CREATE_PATH));
        return contentTypeConfig;
    } else {
        logger.debug("No content type configuration document found at " + configFileFullPath);
        return null;
    }
}
Also used : ContentTypeConfigTO(org.craftercms.studio.api.v1.to.ContentTypeConfigTO) DocumentException(org.dom4j.DocumentException) Element(org.dom4j.Element) Document(org.dom4j.Document) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 5 with ContentTypeConfigTO

use of org.craftercms.studio.api.v1.to.ContentTypeConfigTO in project studio by craftercms.

the class ContentTypesConfigImpl method loadDeleteDependencies.

/**
 * load delete dependencies mapping
 *
 * @param contentTypeConfig
 * @param nodes
 */
protected void loadDeleteDependencies(ContentTypeConfigTO contentTypeConfig, List<Node> nodes) {
    List<DeleteDependencyConfigTO> deleteConfigs = new ArrayList<>();
    if (nodes != null) {
        for (Node node : nodes) {
            Node patternNode = node.selectSingleNode("pattern");
            Node removeFolderNode = node.selectSingleNode("remove-empty-folder");
            if (patternNode != null) {
                String pattern = patternNode.getText();
                String removeEmptyFolder = removeFolderNode.getText();
                boolean isRemoveEmptyFolder = false;
                if (removeEmptyFolder != null) {
                    isRemoveEmptyFolder = Boolean.valueOf(removeEmptyFolder);
                }
                if (StringUtils.isNotEmpty(pattern)) {
                    DeleteDependencyConfigTO deleteConfigTO = new DeleteDependencyConfigTO(pattern, isRemoveEmptyFolder);
                    deleteConfigs.add(deleteConfigTO);
                }
            }
        }
        contentTypeConfig.setDeleteDependencies(deleteConfigs);
    }
}
Also used : Node(org.dom4j.Node) ArrayList(java.util.ArrayList) DeleteDependencyConfigTO(org.craftercms.studio.api.v1.to.DeleteDependencyConfigTO)

Aggregations

ContentTypeConfigTO (org.craftercms.studio.api.v1.to.ContentTypeConfigTO)10 ArrayList (java.util.ArrayList)6 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)6 RepositoryItem (org.craftercms.studio.api.v1.repository.RepositoryItem)3 Document (org.dom4j.Document)2 DocumentException (org.dom4j.DocumentException)2 Node (org.dom4j.Node)2 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 MimetypesFileTypeMap (javax.activation.MimetypesFileTypeMap)1 ContentNotFoundException (org.craftercms.studio.api.v1.exception.ContentNotFoundException)1 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)1 ContentTypeService (org.craftercms.studio.api.v1.service.content.ContentTypeService)1 SecurityService (org.craftercms.studio.api.v1.service.security.SecurityService)1 ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)1 CopyDependencyConfigTO (org.craftercms.studio.api.v1.to.CopyDependencyConfigTO)1 DeleteDependencyConfigTO (org.craftercms.studio.api.v1.to.DeleteDependencyConfigTO)1 PermissionsConfigTO (org.craftercms.studio.api.v1.to.PermissionsConfigTO)1