use of org.craftercms.studio.api.v1.to.DmDependencyTO in project studio by craftercms.
the class WorkflowServiceImpl method approve_new.
/**
* approve workflows and schedule them as specified in the request
*
* @param site
* @param request
* @return call result
* @throws ServiceLayerException
*/
@SuppressWarnings("unchecked")
protected ResultTO approve_new(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.");
}
List<String> submittedPaths = new ArrayList<String>();
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);
submittedPaths.add(stringItem);
DmDependencyTO submittedItem = null;
submittedItem = getSubmittedItem_new(site, stringItem, format, scheduledDate);
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) {
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_new(site, goLiveItems, true);
List<DmDependencyTO> children = getRefAndChildOfDiffDateFromParent_new(site, goLiveItems, false);
goLiveItems.addAll(references);
goLiveItems.addAll(children);
List<DmDependencyTO> dependencies = addDependenciesForSubmittedItems(site, submittedItems, format, scheduledDate);
goLiveItems.addAll(dependencies);
List<String> goLivePaths = new ArrayList<>();
List<AuditLogParameter> auditLogParameters = new ArrayList<AuditLogParameter>();
for (DmDependencyTO goLiveItem : goLiveItems) {
goLivePaths.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);
}
goLive(site, goLiveItems, approver, mcpContext);
SiteFeed siteFeed = siteService.getSite(site);
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setActorId(approver);
auditLog.setSiteId(siteFeed.getId());
auditLog.setPrimaryTargetId(site);
auditLog.setPrimaryTargetType(TARGET_TYPE_SITE);
auditLog.setPrimaryTargetValue(site);
auditLog.setParameters(auditLogParameters);
if (scheduledDate != null && !isNow) {
auditLog.setOperation(OPERATION_APPROVE_SCHEDULED);
} else {
auditLog.setOperation(OPERATION_APPROVE);
}
auditServiceInternal.insertAuditLog(auditLog);
}
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>();
List<AuditLogParameter> auditLogParameters = new ArrayList<AuditLogParameter>();
for (DmDependencyTO deletedItem : submittedItems) {
// deletedItem.setScheduledDate(getScheduledDate(site, format, scheduledDate));
deletePaths.add(deletedItem.getUri());
AuditLogParameter auditLogParameter = new AuditLogParameter();
auditLogParameter.setTargetId(site + ":" + deletedItem.getUri());
auditLogParameter.setTargetType(TARGET_TYPE_CONTENT_ITEM);
auditLogParameter.setTargetValue(deletedItem.getUri());
auditLogParameters.add(auditLogParameter);
}
doDelete(site, submittedItems, approver);
SiteFeed siteFeed = siteService.getSite(site);
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_APPROVE);
auditLog.setActorId(approver);
auditLog.setSiteId(siteFeed.getId());
auditLog.setPrimaryTargetId(site);
auditLog.setPrimaryTargetType(TARGET_TYPE_SITE);
auditLog.setPrimaryTargetValue(site);
auditLog.setParameters(auditLogParameters);
auditServiceInternal.insertAuditLog(auditLog);
}
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 _reject.
protected void _reject(String site, DmDependencyTO dmDependencyTO, String approver, boolean sendEmail, String reason) {
boolean contentExists = contentService.contentExists(site, dmDependencyTO.getUri());
if (contentExists) {
if (!objectMetadataManager.metadataExist(site, dmDependencyTO.getUri())) {
objectMetadataManager.insertNewObjectMetadata(site, dmDependencyTO.getUri());
}
Map<String, Object> newProps = new HashMap<String, Object>();
newProps.put(ItemMetadata.PROP_SUBMITTED_BY, "");
newProps.put(ItemMetadata.PROP_SEND_EMAIL, 0);
newProps.put(ItemMetadata.PROP_SUBMITTED_FOR_DELETION, 0);
newProps.put(ItemMetadata.PROP_LAUNCH_DATE, null);
newProps.put(ItemMetadata.PROP_SUBMITTED_TO_ENVIRONMENT, StringUtils.EMPTY);
objectMetadataManager.setObjectMetadata(site, dmDependencyTO.getUri(), newProps);
ContentItemTO item = contentService.getContentItem(site, dmDependencyTO.getUri());
objectStateService.transition(site, item, TransitionEvent.REJECT);
}
}
use of org.craftercms.studio.api.v1.to.DmDependencyTO in project studio by craftercms.
the class WorkflowServiceImpl method applyDeleteDependencyRule.
protected void applyDeleteDependencyRule(String site, SubmitPackage pack, DmDependencyTO dmDependencyTO) {
pack.addToPackage(dmDependencyTO);
DependencyRules rule = new DependencyRules(site);
rule.setObjectStateService(objectStateService);
rule.setContentService(contentService);
Set<DmDependencyTO> dependencyTOSet = rule.applyDeleteDependencyRule(dmDependencyTO);
for (DmDependencyTO dependencyTO : dependencyTOSet) {
pack.addToPackage(dependencyTO);
}
}
use of org.craftercms.studio.api.v1.to.DmDependencyTO in project studio by craftercms.
the class WorkflowServiceImpl method getRefAndChildOfDiffDateFromParent.
protected List<DmDependencyTO> getRefAndChildOfDiffDateFromParent(String site, List<DmDependencyTO> submittedItems, boolean removeInPages) throws ServiceLayerException {
List<DmDependencyTO> childAndReferences = new ArrayList<>();
for (DmDependencyTO submittedItem : submittedItems) {
List<DmDependencyTO> children = submittedItem.getChildren();
ZonedDateTime date = submittedItem.getScheduledDate();
if (children != null) {
Iterator<DmDependencyTO> childItr = children.iterator();
while (childItr.hasNext()) {
DmDependencyTO child = childItr.next();
ZonedDateTime pageDate = child.getScheduledDate();
if ((date == null && pageDate != null) || (date != null && !date.equals(pageDate))) {
if (!submittedItem.isNow()) {
child.setNow(false);
if (date != null && (pageDate != null && pageDate.isBefore(date))) {
child.setScheduledDate(date);
}
}
childAndReferences.add(child);
List<DmDependencyTO> childDeps = child.flattenChildren();
for (DmDependencyTO childDep : childDeps) {
if (objectStateService.isUpdatedOrNew(site, childDep.getUri())) {
childAndReferences.add(childDep);
}
}
child.setReference(false);
childItr.remove();
if (removeInPages) {
String uri = child.getUri();
List<DmDependencyTO> pages = submittedItem.getPages();
if (pages != null) {
Iterator<DmDependencyTO> pagesIter = pages.iterator();
while (pagesIter.hasNext()) {
DmDependencyTO page = pagesIter.next();
if (page.getUri().equals(uri)) {
pagesIter.remove();
}
}
}
}
}
}
}
List<String> dependenciesPaths = dependencyService.getPublishingDependencies(site, submittedItem.getUri());
for (String depPath : dependenciesPaths) {
DmDependencyTO dmDependencyTO = new DmDependencyTO();
dmDependencyTO.setUri(depPath);
childAndReferences.add(dmDependencyTO);
}
}
return childAndReferences;
}
use of org.craftercms.studio.api.v1.to.DmDependencyTO in project studio by craftercms.
the class WorkflowServiceImpl method rejectThisAndReferences.
protected void rejectThisAndReferences(String site, DmDependencyTO dmDependencyTO, DependencyRules rule, String approver, String reason) {
_reject(site, dmDependencyTO, approver, true, reason);
Set<DmDependencyTO> dependencyTOSet = rule.applyRejectRule(dmDependencyTO);
for (DmDependencyTO dependencyTO : dependencyTOSet) {
boolean lsendEmail = true;
try {
ContentItemTO contentItem = contentService.getContentItem(site, dependencyTO.getUri());
lsendEmail = !contentItem.isDocument() && !contentItem.isComponent() && !contentItem.isAsset();
} catch (Exception e) {
logger.error("during rejection, content retrieve failed");
lsendEmail = false;
}
_reject(site, dependencyTO, approver, lsendEmail, reason);
}
}
Aggregations