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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations