use of org.craftercms.studio.api.v1.exception.ContentNotFoundException in project studio by craftercms.
the class DependencyServiceImpl method upsertDependencies.
@Override
public Set<String> upsertDependencies(String site, String path) throws SiteNotFoundException, ContentNotFoundException, ServiceLayerException {
Set<String> toRet = new HashSet<String>();
logger.debug("Resolving dependencies for content site: " + site + " path: " + path);
Map<String, Set<String>> dependencies = dependencyResolver.resolve(site, path);
List<DependencyEntity> dependencyEntities = new ArrayList<>();
if (dependencies != null) {
logger.debug("Found " + dependencies.size() + " dependencies. Create entities to insert into database.");
for (String type : dependencies.keySet()) {
dependencyEntities.addAll(createDependencyEntities(site, path, dependencies.get(type), type, toRet));
}
logger.debug("Preparing transaction for database updates.");
DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
defaultTransactionDefinition.setName("upsertDependencies");
String lock = site + ":upsertDependencies";
generalLockService.lock(lock);
logger.debug("Starting transaction.");
TransactionStatus txStatus = transactionManager.getTransaction(defaultTransactionDefinition);
try {
logger.debug("Delete all source dependencies for site: " + site + " path: " + path);
deleteAllSourceDependencies(site, path);
logger.debug("Insert all extracted dependencies entries for site: " + site + " path: " + path);
insertDependenciesIntoDatabase(dependencyEntities);
logger.debug("Committing transaction.");
transactionManager.commit(txStatus);
} catch (Exception e) {
logger.debug("Rolling back transaction.", e);
transactionManager.rollback(txStatus);
throw new ServiceLayerException("Failed to upsert dependencies for site: " + site + " path: " + path, e);
} finally {
generalLockService.unlock(lock);
}
}
return toRet;
}
use of org.craftercms.studio.api.v1.exception.ContentNotFoundException 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.exception.ContentNotFoundException in project studio by craftercms.
the class WorkflowServiceImpl method submitToGoLive.
protected List<DmError> submitToGoLive(List<DmDependencyTO> submittedItems, ZonedDateTime scheduledDate, boolean sendEmail, boolean submitForDeletion, RequestContext requestContext, String submissionComment, String environment) throws ServiceLayerException {
List<DmError> errors = new ArrayList<DmError>();
String site = requestContext.getSite();
String submittedBy = requestContext.getUser();
for (DmDependencyTO submittedItem : submittedItems) {
try {
DependencyRules rule = new DependencyRules(site);
rule.setContentService(contentService);
rule.setObjectStateService(objectStateService);
submitThisAndReferredComponents(submittedItem, site, scheduledDate, sendEmail, submitForDeletion, submittedBy, rule, submissionComment, environment);
List<DmDependencyTO> children = submittedItem.getChildren();
if (children != null && !submitForDeletion) {
for (DmDependencyTO child : children) {
if (!child.isReference()) {
submitThisAndReferredComponents(child, site, scheduledDate, sendEmail, submitForDeletion, submittedBy, rule, submissionComment, environment);
}
}
}
} catch (ContentNotFoundException e) {
errors.add(new DmError(site, submittedItem.getUri(), e));
}
}
notificationService.notifyApprovesContentSubmission(site, null, getDeploymentPaths(submittedItems), submittedBy, scheduledDate, submitForDeletion, submissionComment, Locale.ENGLISH);
return errors;
}
use of org.craftercms.studio.api.v1.exception.ContentNotFoundException 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.");
}
}
use of org.craftercms.studio.api.v1.exception.ContentNotFoundException in project studio by craftercms.
the class ContentServiceImpl method getContentAsDocument.
@Override
@ValidateParams
public Document getContentAsDocument(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path) throws DocumentException {
// TODO: SJ: Refactor in 4.x as this already exists in Crafter Core (which is part of the new Studio)
Document retDocument = null;
InputStream is = null;
try {
is = this.getContent(site, path);
} catch (ContentNotFoundException | CryptoException e) {
logger.debug("Content not found for path {0}", e, path);
}
if (is != null) {
try {
SAXReader saxReader = new SAXReader();
try {
saxReader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
saxReader.setFeature("http://xml.org/sax/features/external-general-entities", false);
saxReader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
} catch (SAXException ex) {
logger.error("Unable to turn off external entity loading, This could be a security risk.", ex);
}
retDocument = saxReader.read(is);
} finally {
try {
if (is != null) {
is.close();
}
} catch (IOException err) {
logger.debug("Error closing stream for path {0}", err, path);
}
}
}
return retDocument;
}
Aggregations