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