use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class WorkflowServiceImpl method sendDeleteApprovalNotification.
protected void sendDeleteApprovalNotification(String site, DmDependencyTO submittedItem, String approver) {
try {
if (submittedItem.isSendEmail()) {
String uri = submittedItem.getUri();
ContentItemTO contentItem = contentService.getContentItem(site, uri);
if (contentItem != null) {
// Prepare to send notification
}
}
} catch (Exception e) {
logger.error("Could not send delete approval notification for newly created item", e);
}
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class WorkflowServiceImpl method addToQueue.
protected void addToQueue(String site, GoLiveQueue queue, GoLiveQueue inProcessQueue, ContentItemTO item, ItemState itemState) throws ServiceLayerException {
if (item != null) {
State state = State.valueOf(itemState.getState());
// add only submitted items to go live Q.
if (State.isSubmitted(state)) {
queue.add(item);
}
if (inProcessQueue != null) {
if (!State.isLive(state)) {
inProcessQueue.add(item);
inProcessQueue.add(item.getPath(), item);
}
}
} else {
objectStateService.deleteObjectState(itemState.getObjectId());
}
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class WorkflowServiceImpl method addInProgressItems.
protected void addInProgressItems(String site, ContentItemTO item, List<ContentItemTO> categoryItems, DmContentItemComparator comparator, boolean inProgressOnly) {
if (addToQueue(false, inProgressOnly, true)) {
if (!(item.isSubmitted() || item.isInProgress())) {
return;
}
item.setDeleted(false);
ContentItemTO found = null;
String uri = item.getUri();
for (ContentItemTO categoryItem : categoryItems) {
String categoryPath = categoryItem.getPath() + FILE_SEPARATOR;
if (uri.startsWith(categoryPath)) {
found = categoryItem;
break;
}
}
if (found != null && !found.getUri().equals(item.getUri())) {
found.addChild(item, comparator, true);
}
}
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class GoLiveQueueOrganizer method addThis.
protected void addThis(List<ContentItemTO> categoryItems, DmContentItemComparator comparator, ContentItemTO itemToAdd, boolean includeInProgress) {
boolean include = itemToAdd.isSubmitted() || itemToAdd.isSubmittedForDeletion();
if (includeInProgress) {
include = include || itemToAdd.isInProgress();
}
if (!include) {
return;
}
ContentItemTO found = null;
String uri = itemToAdd.getUri();
for (ContentItemTO categoryItem : categoryItems) {
String categoryPath = categoryItem.getPath() + FILE_SEPARATOR;
if (uri.startsWith(categoryPath)) {
found = categoryItem;
break;
}
}
if (found != null && !found.getUri().equals(itemToAdd.getUri())) {
found.addChild(itemToAdd, comparator, true, childFilter);
}
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class AssetDmContentProcessor method writeContentAsset.
/**
* upload content asset to the given path
*
* @param site
* @param path
* @param assetName
* @param in
* input stream to read the asset from
* @param width
* @param height
* @param createFolders
* create missing folders?
* @param isPreview
* @param unlock
* unlock the content upon update?
* @return asset information
* @throws ServiceLayerException
*/
protected ContentAssetInfoTO writeContentAsset(PipelineContent content, String site, String user, String path, String assetName, InputStream in, int width, int height, boolean createFolders, boolean isPreview, boolean unlock, boolean isSystemAsset, ResultTO result) throws ServiceLayerException {
logger.debug("Writing content asset: [site: " + site + ", path: " + path + ", assetName: " + assetName + ", createFolders: " + createFolders);
String ext = null;
int index = assetName.lastIndexOf(".");
if (index > 0 && (index + 1) < assetName.length()) {
ext = assetName.substring(index + 1).toUpperCase();
}
String contentPath = path + FILE_SEPARATOR + assetName;
try {
// look up the path content first
ContentItemTO parentContentItem = contentService.getContentItem(site, path, 0);
boolean parentExists = contentService.contentExists(site, path);
if (!parentExists && createFolders) {
parentContentItem = createMissingFoldersInPath(site, path, isPreview);
parentExists = contentService.contentExists(site, path);
}
if (parentExists && parentContentItem.isFolder()) {
boolean exists = contentService.contentExists(site, path + FILE_SEPARATOR + assetName);
ContentItemTO contentItem = null;
if (exists) {
contentItem = contentService.getContentItem(site, path + FILE_SEPARATOR + assetName, 0);
updateFile(site, contentItem, contentPath, in, user, isPreview, unlock, result);
content.addProperty(DmConstants.KEY_ACTIVITY_TYPE, OPERATION_UPDATE);
} else {
// TODO: define content type
contentItem = createNewFile(site, parentContentItem, assetName, null, in, user, unlock, result);
content.addProperty(DmConstants.KEY_ACTIVITY_TYPE, OPERATION_CREATE);
objectStateService.insertNewEntry(site, contentItem);
}
ContentAssetInfoTO assetInfo = new ContentAssetInfoTO();
assetInfo.setFileName(assetName);
long sizeInBytes = contentService.getContentSize(site, path + FILE_SEPARATOR + assetName);
double convertedSize = 0;
if (sizeInBytes > 0) {
convertedSize = sizeInBytes / 1024d;
if (convertedSize >= 1024) {
assetInfo.setSizeUnit(FILE_SIZE_MB);
assetInfo.setSize(convertedSize / 1024d);
} else {
if (convertedSize > 0 && convertedSize < 1) {
assetInfo.setSize(1);
} else {
assetInfo.setSize(Math.round(convertedSize));
}
assetInfo.setSizeUnit(FILE_SIZE_KB);
}
}
assetInfo.setFileExtension(ext);
return assetInfo;
} else {
throw new ServiceLayerException(path + " does not exist or not a directory.");
}
} finally {
ContentUtils.release(in);
}
}
Aggregations