use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class FormDmContentProcessor method writeContent.
protected void writeContent(PipelineContent content, ResultTO result) throws ServiceLayerException {
String user = content.getProperty(DmConstants.KEY_USER);
String site = content.getProperty(DmConstants.KEY_SITE);
String path = content.getProperty(DmConstants.KEY_PATH);
String fileName = content.getProperty(DmConstants.KEY_FILE_NAME);
String contentType = content.getProperty(DmConstants.KEY_CONTENT_TYPE);
InputStream input = content.getContentStream();
boolean isPreview = ContentFormatUtils.getBooleanValue(content.getProperty(DmConstants.KEY_IS_PREVIEW));
boolean createFolders = ContentFormatUtils.getBooleanValue(content.getProperty(DmConstants.KEY_CREATE_FOLDERS));
String unlockValue = content.getProperty(DmConstants.KEY_UNLOCK);
boolean unlock = (!StringUtils.isEmpty(unlockValue) && unlockValue.equalsIgnoreCase("false")) ? false : true;
String parentContentPath = path;
if (parentContentPath.endsWith(FILE_SEPARATOR + fileName)) {
parentContentPath = parentContentPath.replace(FILE_SEPARATOR + fileName, "");
} else {
path = path + FILE_SEPARATOR + fileName;
}
try {
// look up the path content first
ContentItemTO parentItem = contentService.getContentItem(site, parentContentPath, 0);
boolean parentContentExists = contentService.contentExists(site, parentContentPath);
if (!parentContentExists && createFolders) {
parentItem = createMissingFoldersInPath(site, path, isPreview);
}
if (parentItem != null) {
// look up the path content first
if (parentItem.getName().equals(fileName)) {
ContentItemTO item = contentService.getContentItem(site, path, 0);
InputStream existingContent = contentService.getContent(site, path);
updateFile(site, item, path, input, user, isPreview, unlock, result);
content.addProperty(DmConstants.KEY_ACTIVITY_TYPE, OPERATION_UPDATE);
if (unlock) {
// TODO: We need ability to lock/unlock content in repo
contentService.unLockContent(site, path);
logger.debug("Unlocked the content " + parentContentPath);
}
return;
} else {
// otherwise, create new one
if (path.endsWith(DmConstants.XML_PATTERN) && !path.endsWith(DmConstants.INDEX_FILE)) {
parentContentPath = path.substring(0, path.lastIndexOf(FILE_SEPARATOR));
parentItem = contentService.getContentItem(site, parentContentPath, 0);
}
boolean fileExists = contentService.contentExists(site, path);
if (fileExists) {
ContentItemTO contentItem = contentService.getContentItem(site, path, 0);
InputStream existingContent = contentService.getContent(site, path);
updateFile(site, contentItem, path, input, user, isPreview, unlock, result);
content.addProperty(DmConstants.KEY_ACTIVITY_TYPE, OPERATION_UPDATE);
if (unlock) {
// TODO: We need ability to lock/unlock content in repo
contentService.unLockContent(site, path);
logger.debug("Unlocked the content site: " + site + " path: " + path);
}
return;
} else {
ContentItemTO newFileItem = createNewFile(site, parentItem, fileName, contentType, input, user, unlock, result);
content.addProperty(DmConstants.KEY_ACTIVITY_TYPE, OPERATION_CREATE);
return;
}
}
} else {
throw new ContentNotFoundException(path + " does not exist in site: " + site);
}
} catch (ContentNotFoundException | RepositoryLockedException e) {
throw e;
} catch (Exception e) {
logger.error("Error: ", e);
throw new ContentNotFoundException("Unexpected exception ", e);
} finally {
ContentUtils.release(input);
}
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class FormDmContentProcessor method fileToFolder.
@Override
public String fileToFolder(String site, String path) throws SiteNotFoundException {
if (contentService.contentExists(site, path)) {
ContentItemTO itemTO = contentService.getContentItem(site, path, 0);
if (itemTO.isFolder() || itemTO.isDeleted()) {
return path;
}
int index = path.lastIndexOf(FILE_SEPARATOR);
String folderPath = path.substring(0, index);
String parentFileName = itemTO.getName();
int dotIndex = parentFileName.indexOf(".");
String folderName = (dotIndex > 0) ? parentFileName.substring(0, parentFileName.indexOf(".")) : parentFileName;
contentService.createFolder(site, folderPath, folderName);
folderPath = folderPath + FILE_SEPARATOR + folderName;
contentService.moveContent(site, path, folderPath + FILE_SEPARATOR + DmConstants.INDEX_FILE);
logger.debug("Changed file to folder from " + path + " to " + folderPath);
return folderPath;
} else {
return path;
}
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class WorkflowServiceImpl method getCategoryItems.
/**
* get the top category items that to be displayed in UI
*
* @param site
*/
protected List<ContentItemTO> getCategoryItems(final String site) {
String siteRootPrefix = servicesConfig.getRootPrefix(site);
List<ContentItemTO> categories = new ArrayList<>();
List<DmFolderConfigTO> folders = servicesConfig.getFolders(site);
for (DmFolderConfigTO folder : folders) {
String uri = (folder.isAttachRootPrefix()) ? siteRootPrefix + folder.getPath() : folder.getPath();
// child folders and add them as categories
if (folder.isReadDirectChildren()) {
ContentItemTO rootItem = contentService.getContentItemTree(site, siteRootPrefix + folder.getPath(), 1);
if (rootItem != null) {
if (rootItem.children != null) {
for (ContentItemTO childItem : rootItem.children) {
categories.add(childItem);
}
}
categories.add(rootItem);
}
} else {
ContentItemTO categoryItem = new ContentItemTO();
String timeZone = servicesConfig.getDefaultTimezone(site);
categoryItem.setTimezone(timeZone);
categoryItem.setName(folder.getName());
categoryItem.setInternalName(folder.getName());
categoryItem.setUri(uri);
categoryItem.setPath(uri);
categoryItem.setCategoryRoot(uri);
categories.add(categoryItem);
}
}
return categories;
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class WorkflowServiceImpl method doSubmit.
protected void doSubmit(final String site, final DmDependencyTO dependencyTO, final ZonedDateTime scheduledDate, final boolean sendEmail, final boolean submitForDeletion, final String user, final boolean notifyAdmin, final String submissionComment, String environment) throws ServiceLayerException {
// first remove from workflow
removeFromWorkflow(site, dependencyTO.getUri(), true);
ContentItemTO item = contentService.getContentItem(site, dependencyTO.getUri());
Map<String, Object> properties = new HashMap<>();
properties.put(ItemMetadata.PROP_SUBMITTED_BY, user);
properties.put(ItemMetadata.PROP_SEND_EMAIL, sendEmail ? 1 : 0);
properties.put(ItemMetadata.PROP_SUBMITTED_FOR_DELETION, submitForDeletion ? 1 : 0);
properties.put(ItemMetadata.PROP_SUBMISSION_COMMENT, submissionComment);
properties.put(ItemMetadata.PROP_SUBMITTED_TO_ENVIRONMENT, environment);
if (null == scheduledDate) {
properties.put(ItemMetadata.PROP_LAUNCH_DATE, null);
} else {
properties.put(ItemMetadata.PROP_LAUNCH_DATE, scheduledDate);
}
if (!objectMetadataManager.metadataExist(site, dependencyTO.getUri())) {
objectMetadataManager.insertNewObjectMetadata(site, dependencyTO.getUri());
}
objectMetadataManager.setObjectMetadata(site, dependencyTO.getUri(), properties);
if (scheduledDate != null) {
objectStateService.transition(site, item, TransitionEvent.SUBMIT_WITH_WORKFLOW_SCHEDULED);
} else {
objectStateService.transition(site, item, TransitionEvent.SUBMIT_WITH_WORKFLOW_UNSCHEDULED);
}
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class WorkflowServiceImpl method fillQueue.
@Override
@ValidateParams
public void fillQueue(@ValidateStringParam(name = "site") String site, GoLiveQueue goLiveQueue, GoLiveQueue inProcessQueue) throws ServiceLayerException {
List<ItemState> changeSet = objectStateService.getSubmittedItems(site);
// regular categories specified in the configuration
if (changeSet != null) {
// add all content items from each task if task is the review task
for (ItemState state : changeSet) {
try {
if (contentService.contentExists(state.getSite(), state.getPath())) {
ContentItemTO item = contentService.getContentItem(state.getSite(), state.getPath(), 0);
Set<String> permissions = securityService.getUserPermissions(site, item.getUri(), securityService.getCurrentUser(), Collections.<String>emptyList());
if (permissions.contains(StudioConstants.PERMISSION_VALUE_PUBLISH)) {
addToQueue(site, goLiveQueue, inProcessQueue, item, state);
}
} else {
_cancelWorkflow(site, state.getPath());
objectStateService.deleteObjectStateForPath(site, state.getPath());
objectMetadataManager.deleteObjectMetadata(site, state.getPath());
}
} catch (Exception e) {
logger.error("Could not warm cache for [" + state.getSite() + " : " + state.getPath() + "] " + e.getMessage());
}
}
}
}
Aggregations