use of org.craftercms.studio.api.v1.to.DmError in project studio by craftercms.
the class WorkflowServiceImpl method submitForApproval.
@SuppressWarnings("unchecked")
protected ResultTO submitForApproval(final String site, String submittedBy, final String request, final boolean delete) throws ServiceLayerException {
RequestContext requestContext = RequestContextBuilder.buildSubmitContext(site, submittedBy);
ResultTO result = new ResultTO();
try {
SimpleDateFormat format = new SimpleDateFormat(StudioConstants.DATE_PATTERN_WORKFLOW_WITH_TZ);
JSONObject requestObject = JSONObject.fromObject(request);
JSONArray items = requestObject.getJSONArray(JSON_KEY_ITEMS);
int length = items.size();
if (length > 0) {
for (int index = 0; index < length; index++) {
objectStateService.setSystemProcessing(site, items.optString(index), true);
}
}
boolean isNow = (requestObject.containsKey(JSON_KEY_SCHEDULE)) ? StringUtils.equalsIgnoreCase(requestObject.getString(JSON_KEY_SCHEDULE), JSON_KEY_IS_NOW) : false;
ZonedDateTime scheduledDate = null;
if (!isNow) {
scheduledDate = (requestObject.containsKey(JSON_KEY_SCHEDULED_DATE)) ? getScheduledDate(site, format, requestObject.getString(JSON_KEY_SCHEDULED_DATE)) : null;
}
boolean sendEmail = (requestObject.containsKey(JSON_KEY_SEND_EMAIL)) ? requestObject.getBoolean(JSON_KEY_SEND_EMAIL) : false;
String environment = (requestObject != null && requestObject.containsKey(JSON_KEY_ENVIRONMENT)) ? requestObject.getString(JSON_KEY_ENVIRONMENT) : null;
String submissionComment = (requestObject != null && requestObject.containsKey(JSON_KEY_SUBMISSION_COMMENT)) ? requestObject.getString(JSON_KEY_SUBMISSION_COMMENT) : null;
// TODO: check scheduled date to make sure it is not null when isNow
// = true and also it is not past
String schDate = null;
if (requestObject.containsKey(JSON_KEY_SCHEDULED_DATE)) {
schDate = requestObject.getString(JSON_KEY_SCHEDULED_DATE);
}
if (length > 0) {
List<DmDependencyTO> submittedItems = new ArrayList<DmDependencyTO>();
for (int index = 0; index < length; index++) {
String stringItem = items.optString(index);
DmDependencyTO submittedItem = getSubmittedItem(site, stringItem, format, schDate, null);
String user = submittedBy;
submittedItems.add(submittedItem);
if (delete) {
submittedItem.setSubmittedForDeletion(true);
}
}
submittedItems.addAll(addDependenciesForSubmitForApproval(site, submittedItems, format, schDate));
List<String> submittedPaths = new ArrayList<String>();
for (DmDependencyTO goLiveItem : submittedItems) {
submittedPaths.add(goLiveItem.getUri());
objectStateService.setSystemProcessing(site, goLiveItem.getUri(), true);
DependencyRules rule = new DependencyRules(site);
rule.setObjectStateService(objectStateService);
rule.setContentService(contentService);
Set<DmDependencyTO> depSet = rule.applySubmitRule(goLiveItem);
for (DmDependencyTO dep : depSet) {
submittedPaths.add(dep.getUri());
objectStateService.setSystemProcessing(site, dep.getUri(), true);
}
}
List<DmError> errors = submitToGoLive(submittedItems, scheduledDate, sendEmail, delete, requestContext, submissionComment, environment);
SiteFeed siteFeed = siteService.getSite(site);
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_REQUEST_PUBLISH);
auditLog.setActorId(submittedBy);
auditLog.setSiteId(siteFeed.getId());
auditLog.setPrimaryTargetId(site);
auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
auditLog.setPrimaryTargetValue(site);
auditServiceInternal.insertAuditLog(auditLog);
result.setSuccess(true);
result.setStatus(200);
result.setMessage(notificationService.getNotificationMessage(site, NotificationMessageType.CompleteMessages, COMPLETE_SUBMIT_TO_GO_LIVE_MSG, Locale.ENGLISH));
for (String relativePath : submittedPaths) {
objectStateService.setSystemProcessing(site, relativePath, false);
}
}
} catch (Exception e) {
result.setSuccess(false);
result.setMessage(e.getMessage());
logger.error("Error while submitting content for approval.", e);
}
return result;
}
use of org.craftercms.studio.api.v1.to.DmError in project studio by craftercms.
the class WorkflowServiceImpl method submitToGoLive.
protected List<DmError> submitToGoLive(List<DmDependencyTO> submittedItems, ZonedDateTime scheduledDate, boolean sendEmail, boolean submitForDeletion, RequestContext requestContext, String submissionComment, String environment) throws ServiceLayerException {
List<DmError> errors = new ArrayList<DmError>();
String site = requestContext.getSite();
String submittedBy = requestContext.getUser();
for (DmDependencyTO submittedItem : submittedItems) {
try {
DependencyRules rule = new DependencyRules(site);
rule.setContentService(contentService);
rule.setObjectStateService(objectStateService);
submitThisAndReferredComponents(submittedItem, site, scheduledDate, sendEmail, submitForDeletion, submittedBy, rule, submissionComment, environment);
List<DmDependencyTO> children = submittedItem.getChildren();
if (children != null && !submitForDeletion) {
for (DmDependencyTO child : children) {
if (!child.isReference()) {
submitThisAndReferredComponents(child, site, scheduledDate, sendEmail, submitForDeletion, submittedBy, rule, submissionComment, environment);
}
}
}
} catch (ContentNotFoundException e) {
errors.add(new DmError(site, submittedItem.getUri(), e));
}
}
notificationService.notifyApprovesContentSubmission(site, null, getDeploymentPaths(submittedItems), submittedBy, scheduledDate, submitForDeletion, submissionComment, Locale.ENGLISH);
return errors;
}
Aggregations