use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class ContentServiceImpl method getOrders.
private List<DmOrderTO> getOrders(String site, String relativePath, String orderName, boolean includeFloating) {
// otherwise remove the file name only
if (!StringUtils.isEmpty(relativePath)) {
if (relativePath.endsWith(DmConstants.XML_PATTERN)) {
int index = relativePath.lastIndexOf(FILE_SEPARATOR);
if (index > 0) {
String fileName = relativePath.substring(index + 1);
String path = relativePath.substring(0, index);
if (DmConstants.INDEX_FILE.equals(fileName)) {
int secondIndex = path.lastIndexOf(FILE_SEPARATOR);
if (secondIndex > 0) {
path = path.substring(0, secondIndex);
}
}
relativePath = path;
}
}
}
// get the root item and its children
ContentItemTO item = getContentItem(site, relativePath);
if (item.getChildren() != null) {
List<DmOrderTO> orders = new ArrayList<DmOrderTO>(item.getChildren().size());
String pathIndex = relativePath + FILE_SEPARATOR + DmConstants.INDEX_FILE;
for (ContentItemTO child : item.getChildren()) {
// exclude index.xml, the level descriptor and floating pages at the path
if (!(pathIndex.equals(child.getUri()) || child.isLevelDescriptor() || child.isDeleted()) && (!child.isFloating() || includeFloating)) {
DmOrderTO order = new DmOrderTO();
order.setId(child.getUri());
Double orderNumber = child.getOrder(orderName);
// add only if the page contains order information
if (orderNumber != null && orderNumber > 0) {
order.setOrder(child.getOrder(orderName));
order.setName(child.getInternalName());
if (child.isDisabled())
order.setDisabled("true");
else
order.setDisabled("false");
if (child.isNavigation())
order.setPlaceInNav("true");
else
order.setPlaceInNav("false");
orders.add(order);
}
}
}
return orders;
}
return null;
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class ContentServiceImpl method createNewContentItemTO.
/* ======================== */
protected ContentItemTO createNewContentItemTO(String site, String contentPath) {
ContentItemTO item = new ContentItemTO();
// FIXME: SJ: This is another workaround for UI issues
contentPath = FilenameUtils.normalize(contentPath, true);
item.uri = contentPath;
item.path = contentPath.substring(0, contentPath.lastIndexOf(FILE_SEPARATOR));
item.name = contentPath.substring(contentPath.lastIndexOf(FILE_SEPARATOR) + 1);
item.asset = true;
item.site = site;
item.internalName = item.name;
item.contentType = CONTENT_TYPE_UNKNOWN;
item.disabled = false;
item.savedAsDraft = false;
item.floating = false;
item.hideInAuthoring = false;
item.page = false;
item.previewable = false;
item.isPreviewable = false;
item.component = false;
item.document = false;
item.asset = true;
item.browserUri = "";
// populate with workflow states and other metadata
item.isNew = true;
item.submitted = false;
item.scheduled = false;
item.deleted = false;
item.submittedForDeletion = false;
item.inProgress = true;
item.live = false;
// TODO: DB: Review again in 3.1+
item.folder = _contentRepository.isFolder(site, contentPath);
return item;
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class ContentServiceImpl method writeContentAsset.
/**
* write content asset
*
* @param site
* @param path
* @param assetName
* @param in
* @param isImage
* is this asset an image?
* @param allowedWidth
* specifies the allowed image width in pixel if the asset is an image
* @param allowedHeight
* specifies the allowed image height in pixel if the asset is an image
* @param unlock
* unlock the content upon edit?
* @return content asset info
* @throws ServiceLayerException
*/
@Override
@ValidateParams
public Map<String, Object> writeContentAsset(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path, @ValidateStringParam(name = "assetName") String assetName, InputStream in, String isImage, String allowedWidth, String allowedHeight, String allowLessSize, String draft, String unlock, String systemAsset) throws ServiceLayerException {
try {
entitlementValidator.validateEntitlement(EntitlementType.ITEM, 1);
} catch (EntitlementException e) {
throw new ServiceLayerException("Unable to complete request due to entitlement limits. Please contact your " + "system administrator.");
}
boolean isSystemAsset = Boolean.valueOf(systemAsset);
Map<String, String> params = new HashMap<String, String>();
params.put(DmConstants.KEY_SITE, site);
params.put(DmConstants.KEY_PATH, path);
params.put(DmConstants.KEY_FILE_NAME, assetName);
params.put(DmConstants.KEY_IS_IMAGE, isImage);
params.put(DmConstants.KEY_ALLOW_LESS_SIZE, allowLessSize);
params.put(DmConstants.KEY_ALLOWED_WIDTH, allowedWidth);
params.put(DmConstants.KEY_ALLOWED_HEIGHT, allowedHeight);
params.put(DmConstants.KEY_CONTENT_TYPE, "");
params.put(DmConstants.KEY_CREATE_FOLDERS, "true");
params.put(DmConstants.KEY_UNLOCK, unlock);
params.put(DmConstants.KEY_SYSTEM_ASSET, String.valueOf(isSystemAsset));
boolean exists = contentExists(site, path + FILE_SEPARATOR + assetName);
params.put(DmConstants.KEY_ACTIVITY_TYPE, (exists ? OPERATION_UPDATE : OPERATION_CREATE));
String id = site + ":" + path + ":" + assetName + ":" + "";
// processContent will close the input stream
ContentItemTO item = null;
try {
path = path + FILE_SEPARATOR + assetName;
item = getContentItem(site, path);
if (item != null) {
ItemState itemState = objectStateService.getObjectState(site, path);
if (itemState != null) {
if (itemState.getSystemProcessing() != 0) {
logger.error(String.format("Error Content %s is being processed " + "(Object State is SYSTEM_PROCESSING);", path));
throw new RuntimeException(String.format("Content \"%s\" is being processed", path));
}
objectStateService.setSystemProcessing(site, path, true);
}
}
if (objectStateService.deletedPathExists(site, path) || objectMetadataManager.movedPathExists(site, path)) {
throw new ServiceLayerException("Content " + path + " for site " + site + ", cannot be created because" + " this name/URL was in use by another content item that has been moved or deleted by " + "not yet published.");
}
ResultTO result = processContent(id, in, false, params, DmConstants.CONTENT_CHAIN_ASSET);
ContentAssetInfoTO assetInfoTO = (ContentAssetInfoTO) result.getItem();
if (isSystemAsset) {
path = path.replace(assetName, assetInfoTO.getFileName());
}
item = getContentItem(site, path);
item.setSize(assetInfoTO.getSize());
item.setSizeUnit(assetInfoTO.getSizeUnit());
if (item != null) {
if (result.getCommitId() != null) {
objectStateService.transition(site, item, SAVE);
} else {
objectStateService.transition(site, item, TransitionEvent.CANCEL_EDIT);
}
}
PreviewEventContext context = new PreviewEventContext();
context.setSite(site);
eventService.publish(EVENT_PREVIEW_SYNC, context);
Map<String, Object> toRet = new HashMap<String, Object>();
toRet.put("success", true);
toRet.put("message", item);
return toRet;
} catch (Exception e) {
logger.error("Error processing content", e);
Map<String, Object> toRet = new HashMap<String, Object>();
toRet.put("success", true);
toRet.put("message", e.getMessage());
toRet.put("error", e);
return toRet;
} finally {
if (item != null) {
objectStateService.setSystemProcessing(site, path, false);
}
}
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class ContentServiceImpl method getDeletePatternConfig.
protected List<DeleteDependencyConfigTO> getDeletePatternConfig(String site, String relativePath, boolean isInLiveRepo) throws ServiceLayerException {
List<DeleteDependencyConfigTO> deleteAssociations = new ArrayList<DeleteDependencyConfigTO>();
ContentItemTO dependencyItem = getContentItem(site, relativePath, 0);
String contentType = dependencyItem.getContentType();
deleteAssociations = servicesConfig.getDeleteDependencyPatterns(site, contentType);
return deleteAssociations;
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class ContentTypeServiceImpl method changeContentType.
@Override
@ValidateParams
public boolean changeContentType(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path, @ValidateStringParam(name = "contentType") String contentType) throws ServiceLayerException {
ContentTypeConfigTO contentTypeConfigTO = getContentType(site, contentType);
if (contentTypeConfigTO.getFormPath().equalsIgnoreCase(DmConstants.CONTENT_TYPE_CONFIG_FORM_PATH_SIMPLE)) {
// Simple form engine is not using templates - skip copying template and merging content
return true;
}
// get new template and the current data and merge data
ContentItemTO item = contentService.getContentItem(site, path, 0);
if (item != null) {
contentService.lockContent(site, path);
Document original = null;
try {
original = contentService.getContentAsDocument(site, path);
} catch (DocumentException e) {
logger.error("Error while getting document for site: " + site + " path: " + path, e);
return false;
}
throw new RuntimeException("Is it getting here?");
} else {
throw new ContentNotFoundException(path + " is not a valid content path.");
}
}
Aggregations