Search in sources :

Example 16 with AuditLog

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

the class AuditController method getAuditLog.

@GetMapping("/api/2/audit")
public ResponseBody getAuditLog(@RequestParam(value = REQUEST_PARAM_SITEID, required = false) String siteId, @RequestParam(value = REQUEST_PARAM_SITE_NAME, required = false) String siteName, @RequestParam(value = REQUEST_PARAM_OFFSET, required = false, defaultValue = "0") int offset, @RequestParam(value = REQUEST_PARAM_LIMIT, required = false, defaultValue = "10") int limit, @RequestParam(value = REQUEST_PARAM_USER, required = false, defaultValue = "") String user, @RequestParam(value = REQUEST_PARAM_OPERATIONS, required = false) List<String> operations, @RequestParam(value = REQUEST_PARAM_INCLUDE_PARAMETERS, required = false) boolean includeParameters, @RequestParam(value = REQUEST_PARAM_DATE_FROM, required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) ZonedDateTime dateFrom, @RequestParam(value = REQUEST_PARAM_DATE_TO, required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) ZonedDateTime dateTo, @RequestParam(value = REQUEST_PARAM_TARGET, required = false) String target, @RequestParam(value = REQUEST_PARAM_ORIGIN, required = false) String origin, @RequestParam(value = REQUEST_PARAM_CLUSTER_NODE_ID, required = false) String clusterNodeId, @RequestParam(value = REQUEST_PARAM_SORT, required = false) String sort, @RequestParam(value = REQUEST_PARAM_ORDER, required = false) String order) throws SiteNotFoundException {
    if (StringUtils.isNotEmpty(siteId) && !siteService.existsById(siteId)) {
        throw new SiteNotFoundException("Site " + siteId + " not found.");
    }
    if (StringUtils.isNotEmpty(siteName) && !siteService.existsByName(siteName)) {
        throw new SiteNotFoundException("Site " + siteName + " not found.");
    }
    int total = auditService.getAuditLogTotal(siteId, siteName, user, operations, includeParameters, dateFrom, dateTo, target, origin, clusterNodeId);
    List<AuditLog> auditLog = auditService.getAuditLog(siteId, siteName, offset, limit, user, operations, includeParameters, dateFrom, dateTo, target, origin, clusterNodeId, sort, order);
    ResponseBody responseBody = new ResponseBody();
    PaginatedResultList<AuditLog> result = new PaginatedResultList<>();
    result.setTotal(total);
    result.setLimit(CollectionUtils.isEmpty(auditLog) ? 0 : auditLog.size());
    result.setOffset(offset);
    result.setEntities(RESULT_KEY_AUDIT_LOG, auditLog);
    result.setResponse(ApiResponse.OK);
    responseBody.setResult(result);
    return responseBody;
}
Also used : SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) PaginatedResultList(org.craftercms.studio.model.rest.PaginatedResultList) ResponseBody(org.craftercms.studio.model.rest.ResponseBody) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 17 with AuditLog

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

the class AuditController method getAuditLogEntry.

@GetMapping("/api/2/audit/{id}")
public ResponseBody getAuditLogEntry(@PathVariable(REQUEST_PARAM_ID) long auditLogId) {
    AuditLog auditLogEntry = auditService.getAuditLogEntry(auditLogId);
    ResponseBody responseBody = new ResponseBody();
    ResultOne<AuditLog> result = new ResultOne<AuditLog>();
    result.setEntity(RESULT_KEY_AUDIT_LOG, auditLogEntry);
    result.setResponse(ApiResponse.OK);
    responseBody.setResult(result);
    return responseBody;
}
Also used : ResultOne(org.craftercms.studio.model.rest.ResultOne) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) ResponseBody(org.craftercms.studio.model.rest.ResponseBody) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 18 with AuditLog

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

the class DashboardController method getAuditDashboard.

@GetMapping(value = AUDIT_DASHBOARD, produces = APPLICATION_JSON_VALUE)
public ResponseBody getAuditDashboard(@Valid AuditDashboardRequestParameters requestParameters) {
    String user = null;
    List<String> operations = null;
    ZonedDateTime dateFrom = null;
    ZonedDateTime dateTo = null;
    String target = null;
    if (requestParameters.getFilters() != null) {
        user = requestParameters.getFilters().getActor();
        operations = requestParameters.getFilters().getOperations();
        dateFrom = requestParameters.getFilters().getOperationTimestampFrom();
        dateTo = requestParameters.getFilters().getOperationTimestampTo();
        target = requestParameters.getFilters().getTarget();
    }
    int total = dashboardService.getAuditDashboardTotal(requestParameters.getSiteId(), user, operations, dateFrom, dateTo, target);
    List<AuditLog> auditLog = dashboardService.getAuditDashboard(requestParameters.getSiteId(), requestParameters.getOffset(), requestParameters.getLimit(), user, operations, dateFrom, dateTo, target, requestParameters.getSortBy(), requestParameters.getOrder());
    ResponseBody responseBody = new ResponseBody();
    PaginatedResultList<AuditDashboardItem> result = new PaginatedResultList<AuditDashboardItem>();
    result.setTotal(total);
    result.setLimit(CollectionUtils.isEmpty(auditLog) ? 0 : auditLog.size());
    result.setOffset(requestParameters.getOffset());
    result.setEntities(RESULT_KEY_ITEMS, prepareAuditResult(auditLog));
    result.setResponse(OK);
    responseBody.setResult(result);
    return responseBody;
}
Also used : ZonedDateTime(java.time.ZonedDateTime) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) PaginatedResultList(org.craftercms.studio.model.rest.PaginatedResultList) ResponseBody(org.craftercms.studio.model.rest.ResponseBody) AuditDashboardItem(org.craftercms.studio.model.rest.dashboard.AuditDashboardItem) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 19 with AuditLog

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

the class WorkflowServiceImpl method reject.

@Override
@SuppressWarnings("unchecked")
@ValidateParams
public ResultTO reject(@ValidateStringParam(name = "site") String site, String request) throws ServiceLayerException {
    ResultTO result = new ResultTO();
    try {
        String approver = securityService.getCurrentUser();
        JSONObject requestObject = JSONObject.fromObject(request);
        String reason = (requestObject.containsKey(JSON_KEY_REASON)) ? requestObject.getString(JSON_KEY_REASON) : "";
        JSONArray items = requestObject.getJSONArray(JSON_KEY_ITEMS);
        String scheduledDate = null;
        if (requestObject.containsKey(JSON_KEY_SCHEDULED_DATE)) {
            scheduledDate = requestObject.getString(JSON_KEY_SCHEDULED_DATE);
        }
        int length = items.size();
        if (length > 0) {
            SimpleDateFormat format = new SimpleDateFormat(StudioConstants.DATE_PATTERN_WORKFLOW_WITH_TZ);
            List<DmDependencyTO> submittedItems = new ArrayList<DmDependencyTO>();
            for (int index = 0; index < length; index++) {
                String stringItem = items.optString(index);
                // JSONObject item = items.getJSONObject(index);
                // getSubmittedItem(site, item, format, scheduledDate);
                DmDependencyTO submittedItem = null;
                submittedItem = getSubmittedItem(site, stringItem, format, scheduledDate, null);
                submittedItems.add(submittedItem);
            }
            List<String> paths = new ArrayList<String>();
            List<AuditLogParameter> auditLogParameters = new ArrayList<AuditLogParameter>();
            for (DmDependencyTO goLiveItem : submittedItems) {
                if (contentService.contentExists(site, goLiveItem.getUri())) {
                    paths.add(goLiveItem.getUri());
                }
                AuditLogParameter auditLogParameter = new AuditLogParameter();
                auditLogParameter.setTargetId(site + ":" + goLiveItem.getUri());
                auditLogParameter.setTargetType(TARGET_TYPE_CONTENT_ITEM);
                auditLogParameter.setTargetValue(goLiveItem.getUri());
                auditLogParameters.add(auditLogParameter);
            }
            objectStateService.setSystemProcessingBulk(site, paths, true);
            Set<String> cancelPaths = new HashSet<String>();
            cancelPaths.addAll(paths);
            deploymentService.cancelWorkflowBulk(site, cancelPaths);
            reject(site, submittedItems, reason, approver);
            SiteFeed siteFeed = siteService.getSite(site);
            AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
            auditLog.setOperation(OPERATION_REJECT);
            auditLog.setActorId(approver);
            auditLog.setSiteId(siteFeed.getId());
            auditLog.setPrimaryTargetId(site);
            auditLog.setPrimaryTargetType(TARGET_TYPE_SITE);
            auditLog.setPrimaryTargetValue(site);
            auditLog.setParameters(auditLogParameters);
            auditServiceInternal.insertAuditLog(auditLog);
            objectStateService.setSystemProcessingBulk(site, paths, false);
            result.setSuccess(true);
            result.setStatus(200);
            result.setMessage(notificationService.getNotificationMessage(site, NotificationMessageType.CompleteMessages, NotificationService.COMPLETE_REJECT, Locale.ENGLISH));
        } else {
            result.setSuccess(false);
            result.setMessage("No items provided for preparation.");
        }
    } catch (JSONException | DeploymentException e) {
        result.setSuccess(false);
        result.setMessage(e.getMessage());
    }
    return result;
}
Also used : JSONArray(net.sf.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(net.sf.json.JSONException) DmDependencyTO(org.craftercms.studio.api.v1.to.DmDependencyTO) ResultTO(org.craftercms.studio.api.v1.to.ResultTO) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) JSONObject(net.sf.json.JSONObject) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) DeploymentException(org.craftercms.studio.api.v1.service.deployment.DeploymentException) AuditLogParameter(org.craftercms.studio.api.v2.dal.AuditLogParameter) SimpleDateFormat(java.text.SimpleDateFormat) HashSet(java.util.HashSet) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 20 with AuditLog

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

the class SiteServiceImpl method insertDeleteSiteAuditLog.

private void insertDeleteSiteAuditLog(String siteId, String siteName) throws SiteNotFoundException {
    SiteFeed siteFeed = getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
    String user = securityService.getCurrentUser();
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(OPERATION_DELETE);
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setActorId(user);
    auditLog.setPrimaryTargetId(siteId);
    auditLog.setPrimaryTargetType(TARGET_TYPE_SITE);
    auditLog.setPrimaryTargetValue(siteName);
    auditServiceInternal.insertAuditLog(auditLog);
}
Also used : SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) 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