Search in sources :

Example 21 with AuditLog

use of org.craftercms.studio.api.v2.dal.AuditLog in project studio by craftercms.

the class SiteServiceImpl method writeConfiguration.

@Override
@ValidateParams
public boolean writeConfiguration(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path, InputStream content) throws ServiceLayerException {
    // Write site configuration
    String operation = OPERATION_UPDATE;
    if (!contentRepository.contentExists(site, path)) {
        operation = OPERATION_CREATE;
    }
    String commitId = contentRepository.writeContent(site, path, content);
    contentRepository.reloadRepository(site);
    PreviewEventContext context = new PreviewEventContext();
    context.setSite(site);
    eventService.publish(EVENT_PREVIEW_SYNC, context);
    String user = securityService.getCurrentUser();
    Map<String, String> extraInfo = new HashMap<String, String>();
    if (StringUtils.startsWith(path, contentTypeService.getConfigPath())) {
        extraInfo.put(DmConstants.KEY_CONTENT_TYPE, StudioConstants.CONTENT_TYPE_CONTENT_TYPE);
    } else {
        extraInfo.put(DmConstants.KEY_CONTENT_TYPE, StudioConstants.CONTENT_TYPE_CONFIGURATION);
    }
    SiteFeed siteFeed = getSite(site);
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(operation);
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setActorId(user);
    auditLog.setPrimaryTargetId(site + ":" + path);
    auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
    auditLog.setPrimaryTargetValue(path);
    auditServiceInternal.insertAuditLog(auditLog);
    objectStateService.transition(site, path, TransitionEvent.SAVE);
    if (!objectMetadataManager.metadataExist(site, path)) {
        objectMetadataManager.insertNewObjectMetadata(site, path);
    }
    Map<String, Object> properties = new HashMap<>();
    properties.put(ItemMetadata.PROP_NAME, FilenameUtils.getName(path));
    properties.put(ItemMetadata.PROP_MODIFIED, ZonedDateTime.now(ZoneOffset.UTC));
    properties.put(ItemMetadata.PROP_MODIFIER, user);
    objectMetadataManager.setObjectMetadata(site, path, properties);
    if (commitId != null) {
        objectMetadataManager.updateCommitId(site, path, commitId);
        contentRepositoryV2.insertGitLog(site, commitId, 1);
    }
    boolean toRet = StringUtils.isEmpty(commitId);
    return toRet;
}
Also used : HashMap(java.util.HashMap) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) PreviewEventContext(org.craftercms.studio.api.v1.ebus.PreviewEventContext) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 22 with AuditLog

use of org.craftercms.studio.api.v2.dal.AuditLog in project studio by craftercms.

the class SiteServiceImpl method insertAddRemoteAuditLog.

private void insertAddRemoteAuditLog(String siteId, String remoteName) throws SiteNotFoundException {
    SiteFeed siteFeed = getSite(siteId);
    String user = securityService.getCurrentUser();
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(OPERATION_ADD_REMOTE);
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setActorId(user);
    auditLog.setPrimaryTargetId(remoteName);
    auditLog.setPrimaryTargetType(TARGET_TYPE_REMOTE_REPOSITORY);
    auditLog.setPrimaryTargetValue(remoteName);
    auditServiceInternal.insertAuditLog(auditLog);
}
Also used : SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog)

Example 23 with AuditLog

use of org.craftercms.studio.api.v2.dal.AuditLog in project studio by craftercms.

the class SiteServiceImpl method insertCreateSiteAuditLog.

private void insertCreateSiteAuditLog(String siteId, String siteName, Map<String, String> createdFiles) throws SiteNotFoundException {
    SiteFeed siteFeed = getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
    String user = securityService.getCurrentUser();
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(OPERATION_CREATE);
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setActorId(user);
    auditLog.setPrimaryTargetId(siteId);
    auditLog.setPrimaryTargetType(TARGET_TYPE_SITE);
    auditLog.setPrimaryTargetValue(siteName);
    List<AuditLogParameter> auditLogParameters = new ArrayList<AuditLogParameter>();
    createdFiles.forEach((k, v) -> {
        String targetPath = k;
        if (StringUtils.length(v) > 1) {
            targetPath = v;
        }
        AuditLogParameter auditLogParameter = new AuditLogParameter();
        auditLogParameter.setTargetId(siteId + ":" + targetPath);
        auditLogParameter.setTargetType(TARGET_TYPE_CONTENT_ITEM);
        auditLogParameter.setTargetValue(targetPath);
        auditLogParameters.add(auditLogParameter);
    });
    auditLog.setParameters(auditLogParameters);
    auditServiceInternal.insertAuditLog(auditLog);
}
Also used : SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) ArrayList(java.util.ArrayList) AuditLogParameter(org.craftercms.studio.api.v2.dal.AuditLogParameter) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog)

Example 24 with AuditLog

use of org.craftercms.studio.api.v2.dal.AuditLog in project studio by craftercms.

the class RepositoryManagementServiceImpl method insertAddRemoteAuditLog.

private void insertAddRemoteAuditLog(String siteId, String operation, String primaryTargetId, String primaryTargetValue) throws SiteNotFoundException {
    SiteFeed siteFeed = siteService.getSite(siteId);
    String user = securityService.getCurrentUser();
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(operation);
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setActorId(user);
    auditLog.setPrimaryTargetId(primaryTargetId);
    auditLog.setPrimaryTargetType(TARGET_TYPE_REMOTE_REPOSITORY);
    auditLog.setPrimaryTargetValue(primaryTargetValue);
    auditServiceInternal.insertAuditLog(auditLog);
}
Also used : SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog)

Example 25 with AuditLog

use of org.craftercms.studio.api.v2.dal.AuditLog in project studio by craftercms.

the class ContentServiceImpl method insertDeleteContentApprovedActivity.

private void insertDeleteContentApprovedActivity(String siteId, String aprover, List<String> contentToDelete) throws SiteNotFoundException {
    SiteFeed siteFeed = siteService.getSite(siteId);
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(OPERATION_APPROVE);
    auditLog.setActorId(aprover);
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setPrimaryTargetId(siteId);
    auditLog.setPrimaryTargetType(TARGET_TYPE_SITE);
    auditLog.setPrimaryTargetValue(siteId);
    List<AuditLogParameter> auditLogParameters = new ArrayList<AuditLogParameter>();
    for (String itemToDelete : contentToDelete) {
        AuditLogParameter auditLogParameter = new AuditLogParameter();
        auditLogParameter.setTargetId(siteId + ":" + itemToDelete);
        auditLogParameter.setTargetType(TARGET_TYPE_CONTENT_ITEM);
        auditLogParameter.setTargetValue(itemToDelete);
        auditLogParameters.add(auditLogParameter);
    }
    auditLog.setParameters(auditLogParameters);
    auditServiceInternal.insertAuditLog(auditLog);
}
Also used : SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) ArrayList(java.util.ArrayList) AuditLogParameter(org.craftercms.studio.api.v2.dal.AuditLogParameter) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog)

Aggregations

AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)44 SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)38 ArrayList (java.util.ArrayList)16 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)11 AuditLogParameter (org.craftercms.studio.api.v2.dal.AuditLogParameter)11 HasPermission (org.craftercms.commons.security.permissions.annotations.HasPermission)10 Group (org.craftercms.studio.api.v2.dal.Group)10 User (org.craftercms.studio.api.v2.dal.User)9 HashMap (java.util.HashMap)7 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)6 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)5 AuthenticationSystemException (org.craftercms.studio.api.v1.exception.security.AuthenticationSystemException)5 UserAlreadyExistsException (org.craftercms.studio.api.v1.exception.security.UserAlreadyExistsException)4 UserNotFoundException (org.craftercms.studio.api.v1.exception.security.UserNotFoundException)4 SiteService (org.craftercms.studio.api.v1.service.site.SiteService)4 UserGroup (org.craftercms.studio.api.v2.dal.UserGroup)4 AuditServiceInternal (org.craftercms.studio.api.v2.service.audit.internal.AuditServiceInternal)4 StudioConfiguration (org.craftercms.studio.api.v2.utils.StudioConfiguration)4 SimpleDateFormat (java.text.SimpleDateFormat)3 GroupDAO (org.craftercms.studio.api.v2.dal.GroupDAO)3