use of org.craftercms.studio.api.v1.to.DmDependencyTO in project studio by craftercms.
the class WorkflowServiceImpl method getSubmittedItem_new.
protected DmDependencyTO getSubmittedItem_new(String site, String itemPath, SimpleDateFormat format, String globalSchDate) throws JSONException {
DmDependencyTO submittedItem = new DmDependencyTO();
submittedItem.setUri(itemPath);
// TODO: check scheduled date to make sure it is not null when isNow =
// true and also it is not past
ZonedDateTime scheduledDate = null;
if (globalSchDate != null && !StringUtils.isEmpty(globalSchDate)) {
scheduledDate = getScheduledDate(site, format, globalSchDate);
} else {
if (submittedItem.getScheduledDate() != null) {
scheduledDate = getScheduledDate(site, format, submittedItem.getScheduledDate().format(DateTimeFormatter.ofPattern(format.toPattern())));
}
}
if (scheduledDate == null) {
submittedItem.setNow(true);
}
submittedItem.setScheduledDate(scheduledDate);
return submittedItem;
}
use of org.craftercms.studio.api.v1.to.DmDependencyTO in project studio by craftercms.
the class WorkflowServiceImpl method doDelete.
protected void doDelete(String site, List<DmDependencyTO> submittedItems, String approver) throws ServiceLayerException {
long start = System.currentTimeMillis();
String user = securityService.getCurrentUser();
// get web project information
// String assignee = getAssignee(site, sub);
// Don't make go live an item if it is new and to be deleted
final ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
List<String> itemsToDelete = new ArrayList<>();
List<DmDependencyTO> deleteItems = new ArrayList<>();
List<DmDependencyTO> scheItems = new ArrayList<>();
for (DmDependencyTO submittedItem : submittedItems) {
String uri = submittedItem.getUri();
ZonedDateTime schDate = submittedItem.getScheduledDate();
boolean isItemForSchedule = false;
if (schDate == null || schDate.isBefore(now)) {
// Sending Notification
if (StringUtils.isNotEmpty(approver)) {
// immediate delete
if (submittedItem.isSendEmail()) {
sendDeleteApprovalNotification(site, submittedItem, approver);
// TODO move it after delete actually happens
}
}
if (submittedItem.getUri().endsWith(DmConstants.INDEX_FILE)) {
submittedItem.setUri(submittedItem.getUri().replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""));
}
itemsToDelete.add(uri);
} else {
scheItems.add(submittedItem);
isItemForSchedule = true;
}
submittedItem.setDeleted(true);
// replace with the folder name
boolean isNew = objectStateService.isNew(site, uri);
if (!isNew || isItemForSchedule) {
deleteItems.add(submittedItem);
}
}
GoLiveContext context = new GoLiveContext(approver, site);
final String pathPrefix = FILE_SEPARATOR + "wem-projects" + FILE_SEPARATOR + site + FILE_SEPARATOR + site + FILE_SEPARATOR + "work-area";
Map<ZonedDateTime, List<DmDependencyTO>> groupedPackages = groupByDate(deleteItems, now);
if (groupedPackages.isEmpty()) {
groupedPackages.put(now, Collections.<DmDependencyTO>emptyList());
}
for (ZonedDateTime scheduledDate : groupedPackages.keySet()) {
List<DmDependencyTO> deletePackage = groupedPackages.get(scheduledDate);
SubmitPackage submitpackage = new SubmitPackage(pathPrefix);
Set<String> rescheduledUris = new HashSet<String>();
if (deletePackage != null) {
ZonedDateTime launchDate = scheduledDate.equals(now) ? null : scheduledDate;
Set<String> processedUris = new HashSet<String>();
for (DmDependencyTO dmDependencyTO : deletePackage) {
if (launchDate != null) {
handleReferences(site, submitpackage, dmDependencyTO, true, null, "", rescheduledUris, processedUris);
} else {
applyDeleteDependencyRule(site, submitpackage, dmDependencyTO);
}
}
String label = submitpackage.getLabel();
SubmitLifeCycleOperation deleteOperation = null;
Set<String> liveDependencyItems = new HashSet<String>();
Set<String> allItems = new HashSet<String>();
for (String uri : itemsToDelete) {
// $ToDO $ remove this case and keep the item in go live queue
GoLiveDeleteCandidates deleteCandidate = contentService.getDeleteCandidates(context.getSite(), uri);
allItems.addAll(deleteCandidate.getAllItems());
// get all dependencies that has to be removed as well
liveDependencyItems.addAll(deleteCandidate.getLiveDependencyItems());
}
List<String> submitPackPaths = submitpackage.getPaths();
if (launchDate != null) {
deleteOperation = new PreScheduleDeleteOperation(this, submitpackage.getUris(), launchDate, context, rescheduledUris);
label = DmConstants.DM_SCHEDULE_SUBMISSION_FLOW + ":" + label;
} else {
// add dependencies to submitPackage
for (String liveDependency : liveDependencyItems) {
submitpackage.addToPackage(liveDependency);
}
submitPackPaths = submitpackage.getPaths();
deleteOperation = new PreSubmitDeleteOperation(this, new HashSet<String>(allItems), context, rescheduledUris);
removeChildFromSubmitPackForDelete(submitPackPaths);
}
Map<String, String> submittedBy = new HashMap<>();
workflowProcessor.addToWorkflow(site, new ArrayList<String>(), launchDate, label, deleteOperation, approver, null);
}
}
long end = System.currentTimeMillis();
logger.debug("Submitted deleted items to queue time = " + (end - start));
}
use of org.craftercms.studio.api.v1.to.DmDependencyTO in project studio by craftercms.
the class WorkflowServiceImpl method doSubmit.
protected void doSubmit(final String site, final DmDependencyTO dependencyTO, final ZonedDateTime scheduledDate, final boolean sendEmail, final boolean submitForDeletion, final String user, final boolean notifyAdmin, final String submissionComment, String environment) throws ServiceLayerException {
// first remove from workflow
removeFromWorkflow(site, dependencyTO.getUri(), true);
ContentItemTO item = contentService.getContentItem(site, dependencyTO.getUri());
Map<String, Object> properties = new HashMap<>();
properties.put(ItemMetadata.PROP_SUBMITTED_BY, user);
properties.put(ItemMetadata.PROP_SEND_EMAIL, sendEmail ? 1 : 0);
properties.put(ItemMetadata.PROP_SUBMITTED_FOR_DELETION, submitForDeletion ? 1 : 0);
properties.put(ItemMetadata.PROP_SUBMISSION_COMMENT, submissionComment);
properties.put(ItemMetadata.PROP_SUBMITTED_TO_ENVIRONMENT, environment);
if (null == scheduledDate) {
properties.put(ItemMetadata.PROP_LAUNCH_DATE, null);
} else {
properties.put(ItemMetadata.PROP_LAUNCH_DATE, scheduledDate);
}
if (!objectMetadataManager.metadataExist(site, dependencyTO.getUri())) {
objectMetadataManager.insertNewObjectMetadata(site, dependencyTO.getUri());
}
objectMetadataManager.setObjectMetadata(site, dependencyTO.getUri(), properties);
if (scheduledDate != null) {
objectStateService.transition(site, item, TransitionEvent.SUBMIT_WITH_WORKFLOW_SCHEDULED);
} else {
objectStateService.transition(site, item, TransitionEvent.SUBMIT_WITH_WORKFLOW_UNSCHEDULED);
}
}
use of org.craftercms.studio.api.v1.to.DmDependencyTO in project studio by craftercms.
the class WorkflowServiceImpl method groupByDate.
@Override
public Map<ZonedDateTime, List<DmDependencyTO>> groupByDate(List<DmDependencyTO> submittedItems, ZonedDateTime now) {
Map<ZonedDateTime, List<DmDependencyTO>> groupedPackages = new HashMap<>();
for (DmDependencyTO submittedItem : submittedItems) {
ZonedDateTime scheduledDate = (submittedItem.isNow()) ? null : submittedItem.getScheduledDate();
if (scheduledDate == null || scheduledDate.isBefore(now)) {
scheduledDate = now;
}
List<DmDependencyTO> goLivePackage = groupedPackages.get(scheduledDate);
if (goLivePackage == null)
goLivePackage = new ArrayList<>();
goLivePackage.add(submittedItem);
groupedPackages.put(scheduledDate, goLivePackage);
}
return groupedPackages;
}
use of org.craftercms.studio.api.v1.to.DmDependencyTO 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