use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.
the class RepositoryManagementController method getDiffForConflictedFile.
@GetMapping(DIFF_CONFLICTED_FILE)
public ResponseBody getDiffForConflictedFile(@RequestParam(value = REQUEST_PARAM_SITEID) String siteId, @RequestParam(value = REQUEST_PARAM_PATH) String path) throws ServiceLayerException, CryptoException {
if (!siteService.exists(siteId)) {
throw new SiteNotFoundException(siteId);
}
String diffPath = path;
if (!diffPath.startsWith(FILE_SEPARATOR)) {
diffPath = FILE_SEPARATOR + diffPath;
}
DiffConflictedFile diff = repositoryManagementService.getDiffForConflictedFile(siteId, diffPath);
ResponseBody responseBody = new ResponseBody();
ResultOne<DiffConflictedFile> result = new ResultOne<DiffConflictedFile>();
result.setEntity(RESULT_KEY_DIFF, diff);
result.setResponse(OK);
responseBody.setResult(result);
return responseBody;
}
use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.
the class GitContentRepository method writeContent.
@Override
public String writeContent(String site, String path, InputStream content) {
// Write content to git and commit it
String commitId = null;
String gitLockKey = SITE_SANDBOX_REPOSITORY_GIT_LOCK.replaceAll(PATTERN_SITE, site);
generalLockService.lock(gitLockKey);
try {
GitRepositoryHelper helper = GitRepositoryHelper.getHelper(studioConfiguration, securityService, userServiceInternal, encryptor, generalLockService, retryingRepositoryOperationFacade);
synchronized (helper.getRepository(site, StringUtils.isEmpty(site) ? GLOBAL : SANDBOX)) {
Repository repo = helper.getRepository(site, StringUtils.isEmpty(site) ? GLOBAL : SANDBOX);
if (repo != null) {
if (helper.writeFile(repo, site, path, content)) {
PersonIdent user = helper.getCurrentUserIdent();
String username = securityService.getCurrentUser();
String comment = helper.getCommitMessage(REPO_SANDBOX_WRITE_COMMIT_MESSAGE).replace(REPO_COMMIT_MESSAGE_USERNAME_VAR, username).replace(REPO_COMMIT_MESSAGE_PATH_VAR, path);
commitId = helper.commitFile(repo, site, path, comment, user);
} else {
logger.error("Failed to write content site: " + site + " path: " + path);
}
} else {
logger.error("Missing repository during write for site: " + site + " path: " + path);
}
}
} catch (ServiceLayerException | UserNotFoundException | CryptoException e) {
logger.error("Unknown service error during write for site: " + site + " path: " + path, e);
} finally {
generalLockService.unlock(gitLockKey);
}
return commitId;
}
use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.
the class GitContentRepository method deleteContent.
@Override
public String deleteContent(String site, String path, String approver) {
String commitId = null;
boolean isPage = path.endsWith(FILE_SEPARATOR + INDEX_FILE);
String gitLockKey = SITE_SANDBOX_REPOSITORY_GIT_LOCK.replaceAll(PATTERN_SITE, site);
generalLockService.lock(gitLockKey);
try {
GitRepositoryHelper helper = GitRepositoryHelper.getHelper(studioConfiguration, securityService, userServiceInternal, encryptor, generalLockService, retryingRepositoryOperationFacade);
synchronized (helper.getRepository(site, StringUtils.isEmpty(site) ? GLOBAL : SANDBOX)) {
Repository repo = helper.getRepository(site, StringUtils.isEmpty(site) ? GLOBAL : SANDBOX);
try (Git git = new Git(repo)) {
String pathToDelete = helper.getGitPath(path);
Path parentToDelete = Paths.get(pathToDelete).getParent();
RmCommand rmCommand = git.rm().addFilepattern(pathToDelete).setCached(false);
retryingRepositoryOperationFacade.call(rmCommand);
String pathToCommit = pathToDelete;
if (isPage) {
pathToCommit = deleteParentFolder(git, parentToDelete, true);
}
// TODO: SJ: we need to define messages in a string table of sorts
commitId = helper.commitFile(repo, site, pathToCommit, helper.getCommitMessage(REPO_DELETE_CONTENT_COMMIT_MESSAGE).replaceAll(PATTERN_PATH, path), StringUtils.isEmpty(approver) ? helper.getCurrentUserIdent() : helper.getAuthorIdent(approver));
}
}
} catch (GitAPIException | UserNotFoundException | IOException e) {
logger.error("Error while deleting content for site: " + site + " path: " + path, e);
} catch (ServiceLayerException | CryptoException e) {
logger.error("Unknown service error during delete for site: " + site + " path: " + path, e);
} finally {
generalLockService.unlock(gitLockKey);
}
return commitId;
}
use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.
the class SitesController method getAvailableBlueprints.
@GetMapping("/available_blueprints")
public ResponseBody getAvailableBlueprints() throws ServiceLayerException {
List<PluginDescriptor> blueprintDescriptors = null;
try {
blueprintDescriptors = sitesService.getAvailableBlueprints();
} catch (Exception e) {
throw new ServiceLayerException(e);
}
ResponseBody responseBody = new ResponseBody();
ResultList<PluginDescriptor> result = new ResultList<>();
result.setEntities(RESULT_KEY_BLUEPRINTS, blueprintDescriptors);
result.setResponse(ApiResponse.OK);
responseBody.setResult(result);
return responseBody;
}
use of org.craftercms.studio.api.v1.exception.ServiceLayerException 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);
}
}
Aggregations