use of org.craftercms.studio.api.v1.to.ResultTO in project studio by craftercms.
the class ContentServiceImpl method processContent.
@Override
@ValidateParams
public ResultTO processContent(@ValidateStringParam(name = "id") String id, InputStream input, boolean isXml, Map<String, String> params, @ValidateStringParam(name = "contentChainForm") String contentChainForm) throws ServiceLayerException {
// TODO: SJ: Pipeline Processor is not defined right, we need to refactor in 3.1+
// TODO: SJ: Pipeline should take input, and give you back output
// TODO: SJ: Presently, this takes action and performs the action as a side effect of the processor chain
// TODO: SJ: Furthermore, we have redundancy in the code of the processors
// get sandbox if not provided
long start = System.currentTimeMillis();
try {
String[] strings = id.split(":");
long startTime = System.currentTimeMillis();
ResultTO to = contentProcessor.processContent(id, input, isXml, params, contentChainForm);
long duration = System.currentTimeMillis() - startTime;
logger.debug("Write Duration: '{}'", duration);
return to;
} finally {
long end = System.currentTimeMillis();
logger.debug("Write complete for [" + id + "] in time [" + (end - start) + "]");
}
}
use of org.craftercms.studio.api.v1.to.ResultTO in project studio by craftercms.
the class FormDmContentProcessor method createNewFile.
/**
* create new file to the given path. If the path is a file name, it will
* create a new folder with the same name as the file name (without the
* prefix) and move the existing file to the folder created. Then it creates
* new file to the folder
*
* @param site
* Site name
* @param fileName
* new file name
* @param contentType
* content type
* @param input
* file content
* @param user
* current user
* @throws ContentNotFoundException
*/
protected ContentItemTO createNewFile(String site, ContentItemTO parentItem, String fileName, String contentType, InputStream input, String user, boolean unlock, ResultTO result) throws ContentNotFoundException, SiteNotFoundException {
ContentItemTO fileItem = null;
if (parentItem != null) {
// convert file to folder if target path is a file
String folderPath = fileToFolder(site, parentItem.getUri());
try {
contentService.writeContent(site, parentItem.getUri() + FILE_SEPARATOR + fileName, input);
if (!objectMetadataManager.metadataExist(site, parentItem.getUri() + FILE_SEPARATOR + fileName)) {
objectMetadataManager.insertNewObjectMetadata(site, parentItem.getUri() + FILE_SEPARATOR + fileName);
}
Map<String, Object> properties = new HashMap<>();
properties.put(ItemMetadata.PROP_NAME, fileName);
properties.put(ItemMetadata.PROP_MODIFIED, ZonedDateTime.now(ZoneOffset.UTC));
properties.put(ItemMetadata.PROP_CREATOR, user);
properties.put(ItemMetadata.PROP_MODIFIER, user);
properties.put(ItemMetadata.PROP_OWNER, user);
if (unlock) {
properties.put(ItemMetadata.PROP_LOCK_OWNER, StringUtils.EMPTY);
} else {
properties.put(ItemMetadata.PROP_LOCK_OWNER, user);
}
objectMetadataManager.setObjectMetadata(site, parentItem.getUri() + FILE_SEPARATOR + fileName, properties);
result.setCommitId(objectMetadataManager.getProperties(site, parentItem.getUri() + FILE_SEPARATOR + fileName).getCommitId());
} catch (Exception e) {
logger.error("Error writing new file: " + fileName, e);
} finally {
IOUtils.closeQuietly(input);
}
// unlock the content upon save
if (unlock) {
contentRepository.unLockItem(site, parentItem.getUri() + FILE_SEPARATOR + fileName);
} else {
}
fileItem = contentService.getContentItem(site, parentItem.getUri() + FILE_SEPARATOR + fileName, 0);
return fileItem;
} else {
throw new ContentNotFoundException(parentItem.getUri() + " does not exist in site: " + site);
}
}
use of org.craftercms.studio.api.v1.to.ResultTO in project studio by craftercms.
the class PostActivityProcessor method process.
public void process(PipelineContent content, ResultTO result) throws SiteNotFoundException {
if (result.getCommitId() != null) {
String site = content.getProperty(DmConstants.KEY_SITE);
boolean skipAuditLogInsert = ContentFormatUtils.getBooleanValue(content.getProperty(DmConstants.KEY_SKIP_AUDIT_LOG_INSERT));
if (!skipAuditLogInsert) {
String type = content.getProperty(DmConstants.KEY_ACTIVITY_TYPE);
String user = content.getProperty(DmConstants.KEY_USER);
String activityType = OPERATION_CREATE.equals(type) ? OPERATION_CREATE : OPERATION_UPDATE;
String folderPath = content.getProperty(DmConstants.KEY_FOLDER_PATH);
String fileName = content.getProperty(DmConstants.KEY_FILE_NAME);
boolean isSystemAsset = ContentFormatUtils.getBooleanValue(content.getProperty(DmConstants.KEY_SYSTEM_ASSET));
if (isSystemAsset) {
ContentAssetInfoTO assetInfoTO = (ContentAssetInfoTO) result.getItem();
fileName = assetInfoTO.getFileName();
}
String uri = (folderPath.endsWith(FILE_SEPARATOR)) ? folderPath + fileName : folderPath + FILE_SEPARATOR + fileName;
SiteFeed siteFeed = siteService.getSite(site);
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(activityType);
auditLog.setActorId(user);
auditLog.setSiteId(siteFeed.getId());
auditLog.setPrimaryTargetId(site + ":" + uri);
auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
auditLog.setPrimaryTargetValue(uri);
auditLog.setPrimaryTargetSubtype(contentService.getContentTypeClass(site, uri));
auditServiceInternal.insertAuditLog(auditLog);
}
contentRepository.markGitLogAudited(site, result.getCommitId());
}
}
use of org.craftercms.studio.api.v1.to.ResultTO in project studio by craftercms.
the class CheckImageSizeProcessor method process.
public void process(PipelineContent content, ResultTO result) throws ContentProcessException {
String name = content.getProperty(DmConstants.KEY_FILE_NAME);
MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
String mimetype = mimeTypesMap.getContentType(name);
boolean process = (StringUtils.isEmpty(mimetype)) ? false : mimetype.startsWith("image/") && !StringUtils.equalsIgnoreCase(mimetype, "image/svg+xml");
if (process) {
String allowLessSize = content.getProperty(DmConstants.KEY_ALLOW_LESS_SIZE);
boolean lessSize = ContentFormatUtils.getBooleanValue(allowLessSize);
String allowedWidth = content.getProperty(DmConstants.KEY_ALLOWED_WIDTH);
String allowedHeight = content.getProperty(DmConstants.KEY_ALLOWED_HEIGHT);
int width = (StringUtils.isEmpty(allowedWidth)) ? -1 : ContentFormatUtils.getIntValue(allowedWidth);
int height = (StringUtils.isEmpty(allowedHeight)) ? -1 : ContentFormatUtils.getIntValue(allowedHeight);
InputStream in = content.getContentStream();
ContentAssetInfoTO assetInfo = (result.getItem() == null) ? new ContentAssetInfoTO() : (ContentAssetInfoTO) result.getItem();
in = checkForImageSize(in, width, height, lessSize, assetInfo);
content.getProperties().put(DmConstants.KEY_WIDTH, String.valueOf(assetInfo.getWidth()));
content.getProperties().put(DmConstants.KEY_HEIGHT, String.valueOf(assetInfo.getHeight()));
assetInfo.getWidth();
result.setItem(assetInfo);
content.setContentStream(in);
}
}
use of org.craftercms.studio.api.v1.to.ResultTO in project studio by craftercms.
the class ExtractDependencyProcessor method process.
public void process(PipelineContent content, ResultTO result) throws ContentProcessException {
String site = content.getProperty(DmConstants.KEY_SITE);
String folderPath = content.getProperty(DmConstants.KEY_FOLDER_PATH);
String fileName = content.getProperty(DmConstants.KEY_FILE_NAME);
String path = (folderPath.endsWith(FILE_SEPARATOR)) ? folderPath + fileName : folderPath + FILE_SEPARATOR + fileName;
try {
dependencyService.upsertDependencies(site, path);
} catch (ServiceLayerException e) {
throw new ContentProcessException(e);
}
}
Aggregations