use of org.craftercms.studio.api.v2.dal.AuditLogConstants.OPERATION_UPDATE in project studio by craftercms.
the class ConfigurationServiceImpl method generateAuditLog.
private void generateAuditLog(String siteId, String path, String user) throws SiteNotFoundException {
SiteFeed siteFeed = siteService.getSite(siteId);
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_UPDATE);
auditLog.setSiteId(siteFeed.getId());
auditLog.setActorId(user);
auditLog.setPrimaryTargetId(siteId + ":" + path);
auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
auditLog.setPrimaryTargetValue(path);
auditLog.setPrimaryTargetSubtype(CONTENT_TYPE_CONFIGURATION);
auditServiceInternal.insertAuditLog(auditLog);
}
use of org.craftercms.studio.api.v2.dal.AuditLogConstants.OPERATION_UPDATE in project studio by craftercms.
the class GroupServiceImpl method updateGroup.
@Override
@HasPermission(type = DefaultPermission.class, action = "update_groups")
public Group updateGroup(long orgId, Group group) throws ServiceLayerException, GroupNotFoundException, AuthenticationException {
Group toRet = groupServiceInternal.updateGroup(orgId, group);
SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_UPDATE);
auditLog.setSiteId(siteFeed.getId());
auditLog.setActorId(userService.getCurrentUser().getUsername());
auditLog.setPrimaryTargetId(group.getGroupName());
auditLog.setPrimaryTargetType(TARGET_TYPE_GROUP);
auditLog.setPrimaryTargetValue(group.getGroupName());
auditServiceInternal.insertAuditLog(auditLog);
return toRet;
}
use of org.craftercms.studio.api.v2.dal.AuditLogConstants.OPERATION_UPDATE in project studio by craftercms.
the class StudioAuditLogProcessingTask method processAuditLogFromRepo.
private void processAuditLogFromRepo(String siteId, int batchSize) throws SiteNotFoundException {
List<GitLog> unauditedGitlogs = contentRepository.getUnauditedCommits(siteId, batchSize);
if (unauditedGitlogs != null) {
SiteFeed siteFeed = siteService.getSite(siteId);
for (GitLog gl : unauditedGitlogs) {
if (contentRepository.commitIdExists(siteId, gl.getCommitId())) {
String prevCommitId = gl.getCommitId() + PREVIOUS_COMMIT_SUFFIX;
List<RepoOperation> operations = contentRepository.getOperationsFromDelta(siteId, prevCommitId, gl.getCommitId());
for (RepoOperation repoOperation : operations) {
Map<String, String> activityInfo = new HashMap<String, String>();
String contentClass;
AuditLog auditLog;
switch(repoOperation.getAction()) {
case CREATE:
case COPY:
contentClass = contentService.getContentTypeClass(siteId, repoOperation.getPath());
if (repoOperation.getPath().endsWith(DmConstants.XML_PATTERN)) {
activityInfo.put(DmConstants.KEY_CONTENT_TYPE, contentClass);
}
logger.debug("Insert audit log for site: " + siteId + " path: " + repoOperation.getPath());
auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_CREATE);
auditLog.setOperationTimestamp(repoOperation.getDateTime());
auditLog.setSiteId(siteFeed.getId());
auditLog.setActorId(repoOperation.getAuthor());
auditLog.setActorDetails(repoOperation.getAuthor());
auditLog.setPrimaryTargetId(siteId + ":" + repoOperation.getPath());
auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
auditLog.setPrimaryTargetValue(repoOperation.getPath());
auditLog.setPrimaryTargetSubtype(contentService.getContentTypeClass(siteId, repoOperation.getPath()));
auditLog.setOrigin(ORIGIN_GIT);
auditServiceInternal.insertAuditLog(auditLog);
break;
case UPDATE:
contentClass = contentService.getContentTypeClass(siteId, repoOperation.getPath());
if (repoOperation.getPath().endsWith(DmConstants.XML_PATTERN)) {
activityInfo.put(DmConstants.KEY_CONTENT_TYPE, contentClass);
}
logger.debug("Insert audit log for site: " + siteId + " path: " + repoOperation.getPath());
auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_UPDATE);
auditLog.setOperationTimestamp(repoOperation.getDateTime());
auditLog.setSiteId(siteFeed.getId());
auditLog.setActorId(repoOperation.getAuthor());
auditLog.setActorDetails(repoOperation.getAuthor());
auditLog.setOrigin(ORIGIN_GIT);
auditLog.setPrimaryTargetId(siteId + ":" + repoOperation.getPath());
auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
auditLog.setPrimaryTargetValue(repoOperation.getPath());
auditLog.setPrimaryTargetSubtype(contentService.getContentTypeClass(siteId, repoOperation.getPath()));
auditServiceInternal.insertAuditLog(auditLog);
break;
case DELETE:
contentClass = contentService.getContentTypeClass(siteId, repoOperation.getPath());
if (repoOperation.getPath().endsWith(DmConstants.XML_PATTERN)) {
activityInfo.put(DmConstants.KEY_CONTENT_TYPE, contentClass);
}
logger.debug("Insert audit log for site: " + siteId + " path: " + repoOperation.getPath());
auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_DELETE);
auditLog.setOperationTimestamp(repoOperation.getDateTime());
auditLog.setSiteId(siteFeed.getId());
auditLog.setOrigin(ORIGIN_GIT);
auditLog.setActorId(repoOperation.getAuthor());
auditLog.setActorDetails(repoOperation.getAuthor());
auditLog.setPrimaryTargetId(siteId + ":" + repoOperation.getPath());
auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
auditLog.setPrimaryTargetValue(repoOperation.getPath());
auditLog.setPrimaryTargetSubtype(contentService.getContentTypeClass(siteId, repoOperation.getPath()));
auditServiceInternal.insertAuditLog(auditLog);
break;
case MOVE:
contentClass = contentService.getContentTypeClass(siteId, repoOperation.getMoveToPath());
if (repoOperation.getMoveToPath().endsWith(DmConstants.XML_PATTERN)) {
activityInfo.put(DmConstants.KEY_CONTENT_TYPE, contentClass);
}
logger.debug("Insert audit log for site: " + siteId + " path: " + repoOperation.getMoveToPath());
auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_MOVE);
auditLog.setOperationTimestamp(repoOperation.getDateTime());
auditLog.setSiteId(siteFeed.getId());
auditLog.setActorId(repoOperation.getAuthor());
auditLog.setActorDetails(repoOperation.getAuthor());
auditLog.setOrigin(ORIGIN_GIT);
auditLog.setPrimaryTargetId(siteId + ":" + repoOperation.getMoveToPath());
auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
auditLog.setPrimaryTargetValue(repoOperation.getMoveToPath());
auditLog.setPrimaryTargetSubtype(contentService.getContentTypeClass(siteId, repoOperation.getMoveToPath()));
auditServiceInternal.insertAuditLog(auditLog);
break;
default:
logger.error("Error: Unknown repo operation for site " + siteId + " operation: " + repoOperation.getAction());
break;
}
}
}
contentRepository.markGitLogAudited(siteId, gl.getCommitId());
}
}
}
use of org.craftercms.studio.api.v2.dal.AuditLogConstants.OPERATION_UPDATE 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.v2.dal.AuditLogConstants.OPERATION_UPDATE 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