use of org.craftercms.studio.api.v1.to.DmDependencyTO in project studio by craftercms.
the class WorkflowServiceImpl method addDependenciesForSubmitForApproval.
protected List<DmDependencyTO> addDependenciesForSubmitForApproval(String site, List<DmDependencyTO> submittedItems, SimpleDateFormat format, String globalScheduledDate) throws ServiceLayerException {
List<DmDependencyTO> dependencies = new ArrayList<DmDependencyTO>();
Set<String> dependenciesPaths = new HashSet<String>();
for (DmDependencyTO submittedItem : submittedItems) {
dependenciesPaths.addAll(dependencyService.getPublishingDependencies(site, submittedItem.getUri()));
}
for (String depPath : dependenciesPaths) {
dependencies.add(getSubmittedItem(site, depPath, format, globalScheduledDate, null));
}
return dependencies;
}
use of org.craftercms.studio.api.v1.to.DmDependencyTO in project studio by craftercms.
the class WorkflowServiceImpl method approve.
/**
* approve workflows and schedule them as specified in the request
*
* @param site
* @param request
* @return call result
* @throws ServiceLayerException
*/
@SuppressWarnings("unchecked")
protected ResultTO approve(String site, String request, Operation operation) {
String approver = securityService.getCurrentUser();
ResultTO result = new ResultTO();
try {
JSONObject requestObject = JSONObject.fromObject(request);
JSONArray items = requestObject.getJSONArray(JSON_KEY_ITEMS);
String scheduledDate = null;
if (requestObject.containsKey(JSON_KEY_SCHEDULED_DATE)) {
scheduledDate = requestObject.getString(JSON_KEY_SCHEDULED_DATE);
}
boolean isNow = (requestObject.containsKey(JSON_KEY_IS_NOW)) ? requestObject.getBoolean(JSON_KEY_IS_NOW) : false;
String publishChannelGroupName = (requestObject.containsKey(JSON_KEY_PUBLISH_CHANNEL)) ? requestObject.getString(JSON_KEY_PUBLISH_CHANNEL) : null;
JSONObject jsonObjectStatus = requestObject.getJSONObject(JSON_KEY_STATUS_SET);
String statusMessage = (jsonObjectStatus != null && jsonObjectStatus.containsKey(JSON_KEY_STATUS_MESSAGE)) ? jsonObjectStatus.getString(JSON_KEY_STATUS_MESSAGE) : null;
String submissionComment = (requestObject != null && requestObject.containsKey(JSON_KEY_SUBMISSION_COMMENT)) ? requestObject.getString(JSON_KEY_SUBMISSION_COMMENT) : "Test Go Live";
MultiChannelPublishingContext mcpContext = new MultiChannelPublishingContext(publishChannelGroupName, statusMessage, submissionComment);
int length = items.size();
if (length == 0) {
throw new ServiceLayerException("No items provided to go live.");
}
String responseMessageKey = null;
SimpleDateFormat format = new SimpleDateFormat(StudioConstants.DATE_PATTERN_WORKFLOW_WITH_TZ);
List<DmDependencyTO> submittedItems = new ArrayList<>();
for (int index = 0; index < length; index++) {
String stringItem = items.optString(index);
DmDependencyTO submittedItem = null;
submittedItem = getSubmittedItem(site, stringItem, format, scheduledDate, null);
List<DmDependencyTO> submitForDeleteChildren = removeSubmitToDeleteChildrenForGoLive(submittedItem, operation);
if (submittedItem.isReference()) {
submittedItem.setReference(false);
}
submittedItems.add(submittedItem);
submittedItems.addAll(submitForDeleteChildren);
}
switch(operation) {
case GO_LIVE:
if (scheduledDate != null && isNow == false) {
responseMessageKey = NotificationService.COMPLETE_SCHEDULE_GO_LIVE;
} else {
responseMessageKey = NotificationService.COMPLETE_GO_LIVE;
}
List<DmDependencyTO> submitToDeleteItems = new ArrayList<>();
List<DmDependencyTO> goLiveItems = new ArrayList<>();
List<DmDependencyTO> renameItems = new ArrayList<>();
for (DmDependencyTO item : submittedItems) {
if (item.isSubmittedForDeletion()) {
submitToDeleteItems.add(item);
} else {
if (!isItemRenamed(site, item)) {
goLiveItems.add(item);
} else {
renameItems.add(item);
}
}
}
if (!submitToDeleteItems.isEmpty()) {
doDelete(site, submitToDeleteItems, approver);
}
if (!goLiveItems.isEmpty()) {
List<DmDependencyTO> references = getRefAndChildOfDiffDateFromParent(site, goLiveItems, true);
List<DmDependencyTO> children = getRefAndChildOfDiffDateFromParent(site, goLiveItems, false);
goLiveItems.addAll(references);
goLiveItems.addAll(children);
List<String> goLivePaths = new ArrayList<>();
Set<String> processedPaths = new HashSet<String>();
for (DmDependencyTO goLiveItem : goLiveItems) {
resolveSubmittedPaths(site, goLiveItem, goLivePaths, processedPaths);
}
List<String> nodeRefs = new ArrayList<>();
goLive(site, goLiveItems, approver, mcpContext);
}
if (!renameItems.isEmpty()) {
List<String> renamePaths = new ArrayList<>();
List<DmDependencyTO> renamedChildren = new ArrayList<>();
for (DmDependencyTO renameItem : renameItems) {
renamedChildren.addAll(getChildrenForRenamedItem(site, renameItem));
renamePaths.add(renameItem.getUri());
objectStateService.setSystemProcessing(site, renameItem.getUri(), true);
}
for (DmDependencyTO renamedChild : renamedChildren) {
renamePaths.add(renamedChild.getUri());
objectStateService.setSystemProcessing(site, renamedChild.getUri(), true);
}
renameItems.addAll(renamedChildren);
// Set proper information of all renameItems before send them to GoLive
for (int i = 0; i < renameItems.size(); i++) {
DmDependencyTO renamedItem = renameItems.get(i);
if (renamedItem.getScheduledDate() != null && renamedItem.getScheduledDate().isAfter(ZonedDateTime.now(ZoneOffset.UTC))) {
renamedItem.setNow(false);
} else {
renamedItem.setNow(true);
}
renameItems.set(i, renamedItem);
}
goLive(site, renameItems, approver, mcpContext);
}
break;
case DELETE:
responseMessageKey = NotificationService.COMPLETE_DELETE;
List<String> deletePaths = new ArrayList<>();
List<String> nodeRefs = new ArrayList<String>();
for (DmDependencyTO deletedItem : submittedItems) {
deletePaths.add(deletedItem.getUri());
ContentItemTO contentItem = contentService.getContentItem(site, deletedItem.getUri());
if (contentItem != null) {
// nodeRefs.add(nodeRef.getId());
}
}
doDelete(site, submittedItems, approver);
}
result.setSuccess(true);
result.setStatus(200);
result.setMessage(notificationService.getNotificationMessage(site, NotificationMessageType.CompleteMessages, responseMessageKey, Locale.ENGLISH));
} catch (JSONException e) {
logger.error("error performing operation " + operation + " " + e);
result.setSuccess(false);
result.setMessage(e.getMessage());
} catch (ServiceLayerException e) {
logger.error("error performing operation " + operation + " " + e);
result.setSuccess(false);
result.setMessage(e.getMessage());
}
return result;
}
use of org.craftercms.studio.api.v1.to.DmDependencyTO in project studio by craftercms.
the class WorkflowServiceImpl method isRescheduleRequest.
@Override
@ValidateParams
public boolean isRescheduleRequest(DmDependencyTO dependencyTO, @ValidateStringParam(name = "site") String site) {
if ((dependencyTO.isDeleted() || (!dependencyTO.isSubmitted() && !dependencyTO.isInProgress()))) {
ContentItemTO to = contentService.getContentItem(site, dependencyTO.getUri());
ZonedDateTime newDate = dependencyTO.getScheduledDate();
ZonedDateTime oldDate = to.getScheduledDate();
return !areEqual(oldDate, newDate);
}
return false;
}
use of org.craftercms.studio.api.v1.to.DmDependencyTO in project studio by craftercms.
the class WorkflowServiceImpl method goLive.
/**
* approve workflows and schedule them as specified in the request
*
* @param site
* @throws ServiceLayerException
*/
protected void goLive(final String site, final List<DmDependencyTO> submittedItems, String approver, MultiChannelPublishingContext mcpContext) throws ServiceLayerException {
// get web project information
final ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
if (submittedItems != null) {
// group submitted items into packages by their scheduled date
Map<ZonedDateTime, List<DmDependencyTO>> groupedPackages = groupByDate(submittedItems, now);
for (ZonedDateTime scheduledDate : groupedPackages.keySet()) {
List<DmDependencyTO> goLivePackage = groupedPackages.get(scheduledDate);
if (goLivePackage != null) {
ZonedDateTime launchDate = scheduledDate.equals(now) ? null : scheduledDate;
final boolean isNotScheduled = (launchDate == null);
// for submit direct, package them together and submit them
// together as direct submit
final SubmitPackage submitpackage = new SubmitPackage("");
/*
dependencyPackage holds references of page.
*/
final Set<String> rescheduledUris = new HashSet<String>();
final SubmitPackage dependencyPackage = new SubmitPackage("");
Set<String> processedUris = new HashSet<String>();
for (final DmDependencyTO dmDependencyTO : goLivePackage) {
goLivepackage(site, submitpackage, dmDependencyTO, isNotScheduled, dependencyPackage, approver, rescheduledUris, processedUris);
}
List<String> stringList = submitpackage.getPaths();
String label = submitpackage.getLabel();
SubmitLifeCycleOperation operation = null;
GoLiveContext context = new GoLiveContext(approver, site);
if (!isNotScheduled) {
Set<String> uris = new HashSet<String>();
uris.addAll(dependencyPackage.getUris());
uris.addAll(submitpackage.getUris());
label = getScheduleLabel(submitpackage, dependencyPackage);
operation = new PreScheduleOperation(this, uris, launchDate, context, rescheduledUris);
} else {
operation = new PreGoLiveOperation(this, submitpackage.getUris(), context, rescheduledUris);
}
if (!stringList.isEmpty()) {
// get the workflow initiator mapping
Map<String, String> submittedBy = new HashMap<String, String>();
for (String uri : stringList) {
dmPublishService.cancelScheduledItem(site, uri);
}
workflowProcessor.addToWorkflow(site, stringList, launchDate, label, operation, approver, mcpContext);
}
}
}
}
}
use of org.craftercms.studio.api.v1.to.DmDependencyTO 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;
}
Aggregations