use of org.craftercms.studio.api.v1.exception.SiteNotFoundException 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.exception.SiteNotFoundException in project studio by craftercms.
the class FormDmContentProcessor method createMissingFoldersInPath.
@Override
public ContentItemTO createMissingFoldersInPath(String site, String path, boolean isPreview) throws SiteNotFoundException {
// create parent folders if missing
String[] levels = path.split(FILE_SEPARATOR);
String parentPath = "";
ContentItemTO lastItem = null;
for (String level : levels) {
if (!StringUtils.isEmpty(level) && !level.endsWith(DmConstants.XML_PATTERN)) {
String currentPath = parentPath + FILE_SEPARATOR + level;
if (!contentService.contentExists(site, currentPath)) {
contentService.createFolder(site, parentPath, level);
}
parentPath = currentPath;
}
}
lastItem = contentService.getContentItem(site, parentPath, 0);
return lastItem;
}
use of org.craftercms.studio.api.v1.exception.SiteNotFoundException 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.exception.SiteNotFoundException in project studio by craftercms.
the class SiteServiceImpl method setSiteState.
@Override
public void setSiteState(String siteId, String state) {
siteFeedMapper.setSiteState(siteId, state);
try {
ClusterMember clusterMember = clusterDao.getMemberByLocalAddress(studioClusterUtils.getClusterNodeLocalAddress());
if (Objects.nonNull(clusterMember)) {
SiteFeed siteFeed = getSite(siteId);
clusterDao.setSiteState(clusterMember.getId(), siteFeed.getId(), state);
}
} catch (SiteNotFoundException e) {
logger.error("Site not found " + siteId);
}
}
use of org.craftercms.studio.api.v1.exception.SiteNotFoundException in project studio by craftercms.
the class DependencyServiceImpl method upsertDependencies.
@Override
public Set<String> upsertDependencies(String site, List<String> paths) throws SiteNotFoundException, ContentNotFoundException, ServiceLayerException {
Set<String> toRet = new HashSet<String>();
List<DependencyEntity> dependencyEntities = new ArrayList<>();
StringBuilder sbPaths = new StringBuilder();
logger.debug("Resolving dependencies for list of paths.");
for (String path : paths) {
sbPaths.append("\n").append(path);
logger.debug("Resolving dependencies for content site: " + site + " path: " + path);
Map<String, Set<String>> dependencies = dependencyResolver.resolve(site, path);
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 list of paths site: " + site);
for (String path : paths) {
deleteAllSourceDependencies(site, path);
}
logger.debug("Insert all extracted dependencies entries lof list of paths for site: " + site);
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 + " paths: " + sbPaths.toString(), e);
} finally {
generalLockService.unlock(lock);
}
return toRet;
}
Aggregations