Search in sources :

Example 31 with SiteFeed

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

the class SiteServiceImpl method updateLastSyncedGitlogCommitId.

@Override
public void updateLastSyncedGitlogCommitId(String site, String commitId) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("siteId", site);
    params.put("commitId", commitId);
    retryingOperationFacade.updateSiteLastSyncedGitlogCommitId(params);
    try {
        ClusterMember clusterMember = clusterDao.getMemberByLocalAddress(studioClusterUtils.getClusterNodeLocalAddress());
        if (Objects.nonNull(clusterMember)) {
            SiteFeed siteFeed = getSite(site);
            retryingOperationFacade.updateClusterNodeLastSyncedGitlogCommitId(clusterMember.getId(), siteFeed.getId(), commitId);
        }
    } catch (SiteNotFoundException e) {
        logger.error("Site not found " + site);
    }
}
Also used : ClusterMember(org.craftercms.studio.api.v2.dal.ClusterMember) HashMap(java.util.HashMap) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException)

Example 32 with SiteFeed

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

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

the class SiteServiceImpl method deleteSite.

@Override
@ValidateParams
public boolean deleteSite(@ValidateStringParam(name = "siteId") String siteId) {
    boolean success = true;
    logger.debug("Deleting site:" + siteId);
    try {
        enablePublishing(siteId, false);
    } catch (SiteNotFoundException e) {
        success = false;
        logger.error("Failed to stop publishing for site:" + siteId, e);
    }
    try {
        logger.debug("Deleting Deployer targets");
        deployer.deleteTargets(siteId);
    } catch (Exception e) {
        success = false;
        logger.error("Failed to delete the Deployer target for sites:" + siteId, e);
    }
    try {
        success = success && destroySitePreviewContext(siteId);
    } catch (Exception e) {
        success = false;
        logger.error("Failed to destroy the preview context for site:" + siteId, e);
    }
    try {
        logger.debug("Deleting repo");
        contentRepository.deleteSite(siteId);
    } catch (Exception e) {
        success = false;
        logger.error("Failed to delete the repository for site:" + siteId, e);
    }
    try {
        // delete database records
        logger.debug("Deleting database records");
        SiteFeed siteFeed = getSite(siteId);
        siteFeedMapper.deleteSite(siteId);
        dependencyService.deleteSiteDependencies(siteId);
        deploymentService.deleteDeploymentDataForSite(siteId);
        objectStateService.deleteObjectStatesForSite(siteId);
        objectMetadataManager.deleteObjectMetadataForSite(siteId);
        dmPageNavigationOrderService.deleteSequencesForSite(siteId);
        contentRepository.deleteGitLogForSite(siteId);
        contentRepository.removeRemoteRepositoriesForSite(siteId);
        auditServiceInternal.deleteAuditLogForSite(siteFeed.getId());
        insertDeleteSiteAuditLog(siteId, siteFeed.getName());
    } catch (Exception e) {
        success = false;
        logger.error("Failed to delete the database for site:" + siteId, e);
    }
    return success;
}
Also used : SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) SiteConfigNotFoundException(org.craftercms.studio.api.v1.service.site.SiteConfigNotFoundException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) SiteCreationException(org.craftercms.studio.api.v1.exception.SiteCreationException) MissingPluginParameterException(org.craftercms.studio.api.v2.exception.MissingPluginParameterException) IOException(java.io.IOException) RemoteRepositoryNotFoundException(org.craftercms.studio.api.v1.exception.repository.RemoteRepositoryNotFoundException) UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) InvalidRemoteUrlException(org.craftercms.studio.api.v1.exception.repository.InvalidRemoteUrlException) DeployerTargetException(org.craftercms.studio.api.v1.exception.DeployerTargetException) RestServiceException(org.craftercms.commons.rest.RestServiceException) SiteAlreadyExistsException(org.craftercms.studio.api.v1.exception.SiteAlreadyExistsException) GroupAlreadyExistsException(org.craftercms.studio.api.v1.exception.security.GroupAlreadyExistsException) DocumentException(org.dom4j.DocumentException) EntitlementException(org.craftercms.commons.entitlements.exception.EntitlementException) BlueprintNotFoundException(org.craftercms.studio.api.v1.exception.BlueprintNotFoundException) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) CryptoException(org.craftercms.commons.crypto.CryptoException) RemoteRepositoryNotBareException(org.craftercms.studio.api.v1.exception.repository.RemoteRepositoryNotBareException) InvalidRemoteRepositoryCredentialsException(org.craftercms.studio.api.v1.exception.repository.InvalidRemoteRepositoryCredentialsException) InvalidRemoteRepositoryException(org.craftercms.studio.api.v1.exception.repository.InvalidRemoteRepositoryException) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 34 with SiteFeed

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

the class SiteServiceImpl method updateLastVerifiedGitlogCommitId.

@Override
public void updateLastVerifiedGitlogCommitId(String site, String commitId) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("siteId", site);
    params.put("commitId", commitId);
    retryingOperationFacade.updateSiteLastVerifiedGitlogCommitId(params);
    try {
        ClusterMember clusterMember = clusterDao.getMemberByLocalAddress(studioClusterUtils.getClusterNodeLocalAddress());
        if (Objects.nonNull(clusterMember)) {
            SiteFeed siteFeed = getSite(site);
            retryingOperationFacade.updateClusterNodeLastVerifiedGitlogCommitId(clusterMember.getId(), siteFeed.getId(), commitId);
        }
    } catch (SiteNotFoundException e) {
        logger.error("Site not found " + site);
    }
}
Also used : ClusterMember(org.craftercms.studio.api.v2.dal.ClusterMember) HashMap(java.util.HashMap) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException)

Example 35 with SiteFeed

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

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