Search in sources :

Example 36 with SiteFeed

use of org.craftercms.studio.api.v1.dal.SiteFeed 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)

Example 37 with SiteFeed

use of org.craftercms.studio.api.v1.dal.SiteFeed in project studio by craftercms.

the class StudioPublisherTask method generateWorkflowActivity.

protected void generateWorkflowActivity(String site, String environment, Set<String> packageIds, String username, String operation) throws SiteNotFoundException {
    SiteFeed siteFeed = siteService.getSite(site);
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(operation);
    auditLog.setActorId(username);
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setPrimaryTargetId(site + ":" + environment);
    auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
    auditLog.setPrimaryTargetValue(environment);
    List<AuditLogParameter> auditLogParameters = new ArrayList<AuditLogParameter>();
    for (String packageId : packageIds) {
        AuditLogParameter auditLogParameter = new AuditLogParameter();
        auditLogParameter.setTargetId(site + ":" + environment);
        auditLogParameter.setTargetType(TARGET_TYPE_CONTENT_ITEM);
        auditLogParameter.setTargetValue(packageId);
        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 38 with SiteFeed

use of org.craftercms.studio.api.v1.dal.SiteFeed in project studio by craftercms.

the class StudioSyncRepositoryTask method syncRepository.

private void syncRepository(String site) throws SiteNotFoundException, IOException {
    logger.debug("Getting last verified commit for site: " + site);
    SiteFeed siteFeed = siteService.getSite(site);
    if (checkSiteUuid(site, siteFeed.getSiteUuid())) {
        String lastProcessedCommit = siteService.getLastVerifiedGitlogCommitId(site);
        if (StringUtils.isNotEmpty(lastProcessedCommit)) {
            GitLog gl = contentRepository.getGitLog(site, lastProcessedCommit);
            if (Objects.nonNull(gl)) {
                String lastRepoCommitId = contentRepository.getRepoLastCommitId(site);
                if (StringUtils.equals(lastRepoCommitId, lastProcessedCommit)) {
                    contentRepository.markGitLogVerifiedProcessed(site, gl.getCommitId());
                    contentRepository.markGitLogProcessedBeforeMarker(site, gl.getId(), 1);
                } else {
                    logger.debug("Syncing database with repository for site " + site + " from last processed commit " + lastProcessedCommit);
                    List<GitLog> unprocessedCommitIds = contentRepository.getUnprocessedCommits(site, gl.getId());
                    if (unprocessedCommitIds != null && unprocessedCommitIds.size() > 0) {
                        siteService.syncDatabaseWithRepoUnprocessedCommits(site, unprocessedCommitIds);
                        GitLog gitLog = unprocessedCommitIds.get(0);
                        String commitBeforeUnprocessedCommit = contentRepository.getPreviousCommitId(site, gitLog.getCommitId());
                        siteService.syncDatabaseWithRepo(site, commitBeforeUnprocessedCommit);
                        unprocessedCommitIds.forEach(x -> {
                            contentRepository.markGitLogVerifiedProcessed(site, x.getCommitId());
                        });
                        // Sync all preview deployers
                        try {
                            logger.debug("Sync preview for site " + site);
                            deploymentService.syncAllContentToPreview(site, false);
                        } catch (ServiceLayerException e) {
                            logger.error("Error synchronizing preview with repository for site: " + site, e);
                        }
                    } else {
                        GitLog gl2 = contentRepository.getGitLog(site, lastRepoCommitId);
                        if (Objects.nonNull(gl2) && !StringUtils.equals(lastRepoCommitId, lastProcessedCommit)) {
                            siteService.updateLastVerifiedGitlogCommitId(site, lastRepoCommitId);
                            contentRepository.markGitLogProcessedBeforeMarker(site, gl2.getId(), 1);
                        } else {
                            contentRepository.markGitLogProcessedBeforeMarker(site, gl.getId(), 1);
                        }
                    }
                }
            }
        }
    }
}
Also used : SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) GitLog(org.craftercms.studio.api.v2.dal.GitLog) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException)

Example 39 with SiteFeed

use of org.craftercms.studio.api.v1.dal.SiteFeed in project studio by craftercms.

the class SiteServiceImpl method insertRemoveRemoteAuditLog.

private void insertRemoveRemoteAuditLog(String siteId, String remoteName) throws SiteNotFoundException {
    SiteFeed siteFeed = getSite(siteId);
    String user = securityService.getCurrentUser();
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(OPERATION_REMOVE_REMOTE);
    auditLog.setActorId(user);
    auditLog.setSiteId(siteFeed.getId());
    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 40 with SiteFeed

use of org.craftercms.studio.api.v1.dal.SiteFeed in project studio by craftercms.

the class SiteServiceImpl method setPublishedRepoCreated.

@Override
public void setPublishedRepoCreated(String siteId) {
    siteFeedMapper.setPublishedRepoCreated(siteId);
    try {
        ClusterMember clusterMember = clusterDao.getMemberByLocalAddress(studioClusterUtils.getClusterNodeLocalAddress());
        if (Objects.nonNull(clusterMember)) {
            SiteFeed siteFeed = getSite(siteId);
            clusterDao.setPublishedRepoCreated(clusterMember.getId(), siteFeed.getId());
        }
    } catch (SiteNotFoundException e) {
        logger.error("Site not found " + siteId);
    }
}
Also used : ClusterMember(org.craftercms.studio.api.v2.dal.ClusterMember) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException)

Aggregations

SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)58 AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)39 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)21 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)18 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)15 AuditLogParameter (org.craftercms.studio.api.v2.dal.AuditLogParameter)12 Group (org.craftercms.studio.api.v2.dal.Group)12 HasPermission (org.craftercms.commons.security.permissions.annotations.HasPermission)11 UserNotFoundException (org.craftercms.studio.api.v1.exception.security.UserNotFoundException)11 User (org.craftercms.studio.api.v2.dal.User)10 IOException (java.io.IOException)9 ClusterMember (org.craftercms.studio.api.v2.dal.ClusterMember)9 CryptoException (org.craftercms.commons.crypto.CryptoException)8 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)8 EntitlementException (org.craftercms.commons.entitlements.exception.EntitlementException)6 ZonedDateTime (java.time.ZonedDateTime)5 AuthenticationSystemException (org.craftercms.studio.api.v1.exception.security.AuthenticationSystemException)5 UserAlreadyExistsException (org.craftercms.studio.api.v1.exception.security.UserAlreadyExistsException)5 SiteService (org.craftercms.studio.api.v1.service.site.SiteService)5