use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class ContentServiceImpl method populateContentDrivenProperties.
@SuppressWarnings("unchecked")
protected ContentItemTO populateContentDrivenProperties(String site, ContentItemTO item) throws Exception {
// This method load an XML content item and populates properties in the TO from the XML
// TODO: SJ: Two problems here that need to be fixed in 3.1+
// TODO: SJ: Use Crafter Core for some/all of this work
// TODO: SJ: Much of this seems hardcoded and must be extensible/configurable via key:xpath in config
String contentPath = item.uri;
logger.debug("Populating page props '{}'", contentPath);
item.setLevelDescriptor(item.name.equals(servicesConfig.getLevelDescriptorName(site)));
item.page = ContentUtils.matchesPatterns(item.getUri(), servicesConfig.getPagePatterns(site));
item.isPage = item.page;
// TODO: SJ: This and item below are duplicated due to UI issues
item.previewable = item.page;
// TODO: SJ: Fix this in 3.1+
item.isPreviewable = item.previewable;
item.component = ContentUtils.matchesPatterns(item.getUri(), servicesConfig.getComponentPatterns(site)) || item.isLevelDescriptor();
item.isComponent = item.component;
item.asset = ContentUtils.matchesPatterns(item.getUri(), servicesConfig.getAssetPatterns(site));
item.isAsset = item.asset;
item.document = ContentUtils.matchesPatterns(item.getUri(), servicesConfig.getDocumentPatterns(site));
item.isDocument = item.document;
item.uri = contentPath;
// TODO: SJ: This is hokey, fix in 3.1+
item.path = contentPath.substring(0, contentPath.lastIndexOf(FILE_SEPARATOR));
// TODO: SJ: This is hokey, fix in 3.1+
item.name = contentPath.substring(contentPath.lastIndexOf(FILE_SEPARATOR) + 1);
item.browserUri = contentPath;
if (item.page) {
// TODO: SJ: This is hokey, fix in 4.x
item.browserUri = contentPath.replace(FILE_SEPARATOR + "site" + FILE_SEPARATOR + "website", "").replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, "");
}
Document contentDoc = this.getContentAsDocument(site, contentPath);
if (contentDoc != null) {
Element rootElement = contentDoc.getRootElement();
String internalName = rootElement.valueOf("internal-name");
String contentType = rootElement.valueOf("content-type");
String disabled = rootElement.valueOf("disabled");
String savedAsDraft = rootElement.valueOf("savedAsDraft");
String navigation = rootElement.valueOf("placeInNav");
String hideInAuthoring = rootElement.valueOf("hideInAuthoring");
String displayTemplate = rootElement.valueOf("display-template");
item.internalName = (internalName != null) ? internalName : null;
item.contentType = (contentType != null) ? contentType : null;
item.disabled = (disabled != null && "true".equalsIgnoreCase(disabled)) ? true : false;
item.savedAsDraft = (savedAsDraft != null && "true".equalsIgnoreCase(savedAsDraft)) ? true : false;
item.hideInAuthoring = (hideInAuthoring != null && "true".equalsIgnoreCase(hideInAuthoring)) ? true : false;
item.navigation = (navigation != null && "true".equalsIgnoreCase(navigation)) ? true : false;
item.floating = !item.navigation;
item.setOrders(getItemOrders(rootElement.selectNodes("//" + DmXmlConstants.ELM_ORDER_DEFAULT)));
if (displayTemplate != null) {
RenderingTemplateTO template = new RenderingTemplateTO();
template.uri = displayTemplate;
// FIXME: SJ: 3.1+
template.name = "DEFAULT";
item.renderingTemplates.add(template);
}
} else {
logger.debug("no xml document could be loaded for site '{}' path '{}'", site, contentPath);
}
Pattern taxonomyPattern = Pattern.compile(CONTENT_TYPE_TAXONOMY_REGEX);
Matcher matcher = taxonomyPattern.matcher(contentPath);
if (matcher.matches()) {
item.contentType = CONTENT_TYPE_TAXONOMY;
}
return item;
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class ContentServiceImpl method getDeleteCandidates.
@Override
@ValidateParams
public GoLiveDeleteCandidates getDeleteCandidates(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "relativePath") String relativePath) throws ServiceLayerException {
ContentItemTO contentItem = getContentItem(site, relativePath);
GoLiveDeleteCandidates deletedItems = new GoLiveDeleteCandidates(site, this, objectStateService);
if (contentItem != null) {
childDeleteItems(site, contentItem, deletedItems);
// update summary for all uri's delete
}
return deletedItems;
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class ContentServiceImpl method createDummyDmContentItemForDeletedNode.
@Override
@ValidateParams
public ContentItemTO createDummyDmContentItemForDeletedNode(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "relativePath") String relativePath) {
// TODO: SJ: Think of another way to do this in 3.1+
ContentItemTO item = new ContentItemTO();
String timeZone = servicesConfig.getDefaultTimezone(site);
item.timezone = timeZone;
String name = ContentUtils.getPageName(relativePath);
String folderPath = (name.equals(DmConstants.INDEX_FILE)) ? relativePath.replace(FILE_SEPARATOR + name, "") : relativePath;
item.path = folderPath;
/**
* Internal name should be just folder name
*/
String internalName = folderPath;
int index = folderPath.lastIndexOf(FILE_SEPARATOR);
if (index != -1)
internalName = folderPath.substring(index + 1);
item.internalName = internalName;
item.isDisabled = false;
item.isNavigation = false;
item.name = name;
item.uri = relativePath;
// set content type based on the relative Path
String contentTypeClass = getContentTypeClass(site, relativePath);
item.contentType = contentTypeClass;
if (contentTypeClass.equals(CONTENT_TYPE_COMPONENT)) {
item.component = true;
} else if (contentTypeClass.equals(CONTENT_TYPE_DOCUMENT)) {
item.document = true;
}
// set if the content is new
item.isDeleted = true;
item.deleted = true;
item.isContainer = false;
item.container = false;
item.isNew = false;
item.isInProgress = false;
item.timezone = servicesConfig.getDefaultTimezone(site);
item.isPreviewable = false;
item.browserUri = getBrowserUri(item);
return item;
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class ContentServiceImpl method updateDatabaseOnMove.
protected void updateDatabaseOnMove(String site, String fromPath, String movePath) throws SiteNotFoundException {
logger.debug("updateDatabaseOnMove FROM {0} TO {1} ", fromPath, movePath);
String user = securityService.getCurrentUser();
Map<String, String> params = new HashMap<>();
params.put(DmConstants.KEY_SOURCE_PATH, fromPath);
params.put(DmConstants.KEY_TARGET_PATH, movePath);
// These do not exist in 3.0, note some extensions may be using it
// params.put(DmConstants.KEY_SOURCE_FULL_PATH, expandRelativeSitePath(site, fromPath));
// params.put(DmConstants.KEY_TARGET_FULL_PATH, expandRelativeSitePath(site, movePath));
ContentItemTO renamedItem = getContentItem(site, movePath, 0);
String contentType = renamedItem.getContentType();
if (!renamedItem.isFolder()) {
dmContentLifeCycleService.process(site, user, movePath, contentType, DmContentLifeCycleService.ContentLifeCycleOperation.RENAME, params);
// change the path of this object in the object state database
objectStateService.updateObjectPath(site, fromPath, movePath);
objectStateService.transition(site, renamedItem, SAVE);
renamedItem = getContentItem(site, movePath, 0);
}
// update metadata
if (!objectMetadataManager.isRenamed(site, fromPath)) {
// if an item was previously moved, we do not track intermediate moves because it will
// ultimately orphan deployed content. Old Path is always the OLDEST DEPLOYED PATH
ItemMetadata metadata = objectMetadataManager.getProperties(site, fromPath);
if (metadata == null && !renamedItem.isFolder()) {
if (!objectMetadataManager.metadataExist(site, fromPath)) {
objectMetadataManager.insertNewObjectMetadata(site, fromPath);
}
metadata = objectMetadataManager.getProperties(site, fromPath);
}
if (!renamedItem.isNew() && !renamedItem.isFolder()) {
// if the item is not new, we need to track the old URL for deployment
logger.debug("item is not new, and has not previously been moved. Track the old URL {0}", fromPath);
Map<String, Object> objMetadataProps = new HashMap<String, Object>();
objMetadataProps.put(ItemMetadata.PROP_RENAMED, 1);
objMetadataProps.put(ItemMetadata.PROP_OLD_URL, fromPath);
objectMetadataManager.setObjectMetadata(site, fromPath, objMetadataProps);
}
}
if (!renamedItem.isFolder()) {
if (objectMetadataManager.metadataExist(site, movePath)) {
if (!StringUtils.equalsIgnoreCase(fromPath, movePath)) {
objectMetadataManager.deleteObjectMetadata(site, movePath);
}
}
objectMetadataManager.updateObjectPath(site, fromPath, movePath);
}
// write activity stream
SiteFeed siteFeed = siteService.getSite(site);
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_MOVE);
auditLog.setSiteId(siteFeed.getId());
auditLog.setActorId(user);
auditLog.setPrimaryTargetId(site + ":" + movePath);
if (renamedItem.isFolder()) {
auditLog.setPrimaryTargetType(TARGET_TYPE_FOLDER);
} else {
auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
}
auditLog.setPrimaryTargetValue(movePath);
auditLog.setPrimaryTargetSubtype(getContentTypeClass(site, movePath));
auditServiceInternal.insertAuditLog(auditLog);
updateDependenciesOnMove(site, fromPath, movePath);
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class ContentServiceImpl method getNextAvailableName.
@Override
@ValidateParams
public String getNextAvailableName(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path) {
// TODO: SJ: Refactor to be faster, and make it work regardless (seems to fail above 10) in 3.1+
String[] levels = path.split(FILE_SEPARATOR);
int length = levels.length;
if (length > 0) {
ContentItemTO item = getContentItem(site, path, 0);
if (item != null) {
String name = ContentUtils.getPageName(path);
String parentPath = ContentUtils.getParentUrl(path);
ContentItemTO parentItem = getContentItemTree(site, parentPath, 1);
if (parentItem != null) {
int lastIndex = name.lastIndexOf(".");
String ext = (item.isFolder()) ? "" : name.substring(lastIndex);
String originalName = (item.isFolder() || item.isContainer()) ? name : name.substring(0, lastIndex);
List<ContentItemTO> children = parentItem.getChildren();
// pattern matching doesn't work here
// String childNamePattern = originalName + "%" + ext;
int lastNumber = 0;
String namePattern = originalName + "-[0-9]+" + ext;
if (children != null && children.size() > 0) {
// since it is already sorted, we only care about the last matching item
for (ContentItemTO child : children) {
if (((item.isFolder() || item.isContainer()) == (child.isFolder() || child.isContainer()))) {
String childName = child.getName();
if ((child.isFolder() || child.isContainer())) {
childName = ContentUtils.getPageName(child.getBrowserUri());
}
if (childName.matches(namePattern)) {
Pattern pattern = (item.isFolder() || item.isContainer()) ? COPY_FOLDER_PATTERN : COPY_FILE_PATTERN;
Matcher matcher = pattern.matcher(childName);
if (matcher.matches()) {
int helper = ContentFormatUtils.getIntValue(matcher.group(2));
lastNumber = (helper > lastNumber) ? helper : lastNumber;
}
}
}
}
}
String nextName = originalName + "-" + ++lastNumber + ext;
return nextName;
} else {
// if parent doesn't exist, it is new item so the current name is available one
}
}
} else {
// cannot generate a name
return "";
}
// if not found the current name is available
return levels[length - 1];
}
Aggregations