use of org.craftercms.studio.api.v1.to.DmDependencyTO in project studio by craftercms.
the class WorkflowServiceImpl method getSubmittedItems.
/**
* get submitted items from JSON request
*
* @param site
* @param items
* @param format
* @return submitted items
* @throws JSONException
*/
protected List<DmDependencyTO> getSubmittedItems(String site, JSONArray items, SimpleDateFormat format, String schDate) throws JSONException, ServiceLayerException {
if (items != null) {
int length = items.size();
if (length > 0) {
List<DmDependencyTO> submittedItems = new ArrayList<>();
for (int index = 0; index < length; index++) {
JSONObject item = items.getJSONObject(index);
DmDependencyTO submittedItem = getSubmittedItem(site, item, format, schDate);
submittedItems.add(submittedItem);
}
return submittedItems;
}
}
return null;
}
use of org.craftercms.studio.api.v1.to.DmDependencyTO in project studio by craftercms.
the class WorkflowServiceImpl method sendDeleteApprovalNotification.
protected void sendDeleteApprovalNotification(String site, DmDependencyTO submittedItem, String approver) {
try {
if (submittedItem.isSendEmail()) {
String uri = submittedItem.getUri();
ContentItemTO contentItem = contentService.getContentItem(site, uri);
if (contentItem != null) {
// Prepare to send notification
}
}
} catch (Exception e) {
logger.error("Could not send delete approval notification for newly created item", e);
}
}
use of org.craftercms.studio.api.v1.to.DmDependencyTO in project studio by craftercms.
the class WorkflowServiceImpl method getSubmittedItemApproveWithoutDependencies.
protected DmDependencyTO getSubmittedItemApproveWithoutDependencies(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 getSubmittedItem.
protected DmDependencyTO getSubmittedItem(String site, String itemPath, SimpleDateFormat format, String globalSchDate, Set<String> processedDependencies) throws JSONException {
DmDependencyTO submittedItem = new DmDependencyTO();
submittedItem.setUri(itemPath);
// 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);
if (processedDependencies == null) {
processedDependencies = new HashSet<String>();
}
if (CollectionUtils.isNotEmpty(submittedItem.getComponents())) {
for (DmDependencyTO component : submittedItem.getComponents()) {
if (!processedDependencies.contains(component.getUri())) {
component = getSubmittedItem(site, component.getUri(), format, globalSchDate, processedDependencies);
}
}
}
if (CollectionUtils.isNotEmpty(submittedItem.getDocuments())) {
for (DmDependencyTO document : submittedItem.getDocuments()) {
if (!processedDependencies.contains(document.getUri())) {
document = getSubmittedItem(site, document.getUri(), format, globalSchDate, processedDependencies);
}
}
}
if (CollectionUtils.isNotEmpty(submittedItem.getAssets())) {
for (DmDependencyTO asset : submittedItem.getAssets()) {
if (!processedDependencies.contains(asset.getUri())) {
asset = getSubmittedItem(site, asset.getUri(), format, globalSchDate, processedDependencies);
}
}
}
if (CollectionUtils.isNotEmpty(submittedItem.getRenderingTemplates())) {
for (DmDependencyTO template : submittedItem.getRenderingTemplates()) {
if (!processedDependencies.contains(template.getUri())) {
template = getSubmittedItem(site, template.getUri(), format, globalSchDate, processedDependencies);
}
}
}
if (CollectionUtils.isNotEmpty(submittedItem.getDeletedItems())) {
for (DmDependencyTO deletedItem : submittedItem.getDeletedItems()) {
if (!processedDependencies.contains(deletedItem.getUri())) {
deletedItem = getSubmittedItem(site, deletedItem.getUri(), format, globalSchDate, processedDependencies);
}
}
}
if (CollectionUtils.isNotEmpty(submittedItem.getChildren())) {
for (DmDependencyTO child : submittedItem.getChildren()) {
if (!processedDependencies.contains(child.getUri())) {
child = getSubmittedItem(site, child.getUri(), format, globalSchDate, processedDependencies);
}
}
}
return submittedItem;
}
use of org.craftercms.studio.api.v1.to.DmDependencyTO in project studio by craftercms.
the class WorkflowServiceImpl method getSubmittedItem.
/**
* get a submitted item from a JSON item
*
* @param site
* @param item
* @param format
* @return submitted item
* @throws net.sf.json.JSONException
*/
protected DmDependencyTO getSubmittedItem(String site, JSONObject item, SimpleDateFormat format, String globalSchDate) throws JSONException, ServiceLayerException {
DmDependencyTO submittedItem = new DmDependencyTO();
String uri = item.getString(JSON_KEY_URI);
submittedItem.setUri(uri);
boolean deleted = (item.containsKey(JSON_KEY_DELETED)) ? item.getBoolean(JSON_KEY_DELETED) : false;
submittedItem.setDeleted(deleted);
boolean isNow = (item.containsKey(JSON_KEY_IS_NOW)) ? item.getBoolean(JSON_KEY_IS_NOW) : false;
submittedItem.setNow(isNow);
boolean submittedForDeletion = (item.containsKey(JSON_KEY_SUBMITTED_FOR_DELETION)) ? item.getBoolean(JSON_KEY_SUBMITTED_FOR_DELETION) : false;
boolean submitted = (item.containsKey(JSON_KEY_SUBMITTED)) ? item.getBoolean(JSON_KEY_SUBMITTED) : false;
boolean inProgress = (item.containsKey(JSON_KEY_IN_PROGRESS)) ? item.getBoolean(JSON_KEY_IN_PROGRESS) : false;
boolean isReference = (item.containsKey(JSON_KEY_IN_REFERENCE)) ? item.getBoolean(JSON_KEY_IN_REFERENCE) : false;
submittedItem.setReference(isReference);
// boolean submittedForDeletion =
// (item.containsKey(JSON_KEY_SUBMITTED_FOR_DELETION)) ?
// item.getBoolean(JSON_KEY_SUBMITTED_FOR_DELETION) : false;
submittedItem.setSubmittedForDeletion(submittedForDeletion);
submittedItem.setSubmitted(submitted);
submittedItem.setInProgress(inProgress);
// 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 (item.containsKey(JSON_KEY_SCHEDULED_DATE)) {
String dateStr = item.getString(JSON_KEY_SCHEDULED_DATE);
if (!StringUtils.isEmpty(dateStr)) {
scheduledDate = getScheduledDate(site, format, dateStr);
}
}
}
if (scheduledDate == null && isNow == false) {
submittedItem.setNow(true);
}
submittedItem.setScheduledDate(scheduledDate);
JSONArray components = (item.containsKey(JSON_KEY_COMPONENTS) && !item.getJSONObject(JSON_KEY_COMPONENTS).isNullObject()) ? item.getJSONArray(JSON_KEY_COMPONENTS) : null;
List<DmDependencyTO> submittedComponents = getSubmittedItems(site, components, format, globalSchDate);
submittedItem.setComponents(submittedComponents);
JSONArray documents = (item.containsKey(JSON_KEY_DOCUMENTS) && !item.getJSONObject(JSON_KEY_DOCUMENTS).isNullObject()) ? item.getJSONArray(JSON_KEY_DOCUMENTS) : null;
List<DmDependencyTO> submittedDocuments = getSubmittedItems(site, documents, format, globalSchDate);
submittedItem.setDocuments(submittedDocuments);
JSONArray assets = (item.containsKey(JSON_KEY_ASSETS) && !item.getJSONObject(JSON_KEY_ASSETS).isNullObject()) ? item.getJSONArray(JSON_KEY_ASSETS) : null;
List<DmDependencyTO> submittedAssets = getSubmittedItems(site, assets, format, globalSchDate);
submittedItem.setAssets(submittedAssets);
JSONArray templates = (item.containsKey(JSON_KEY_RENDERING_TEMPLATES) && !item.getJSONObject(JSON_KEY_RENDERING_TEMPLATES).isNullObject()) ? item.getJSONArray(JSON_KEY_RENDERING_TEMPLATES) : null;
List<DmDependencyTO> submittedTemplates = getSubmittedItems(site, templates, format, globalSchDate);
submittedItem.setRenderingTemplates(submittedTemplates);
JSONArray deletedItems = (item.containsKey(JSON_KEY_DELETED_ITEMS) && !item.getJSONObject(JSON_KEY_DELETED_ITEMS).isNullObject()) ? item.getJSONArray(JSON_KEY_DELETED_ITEMS) : null;
List<DmDependencyTO> deletes = getSubmittedItems(site, deletedItems, format, globalSchDate);
submittedItem.setDeletedItems(deletes);
JSONArray children = (item.containsKey(JSON_KEY_CHILDREN)) ? item.getJSONArray(JSON_KEY_CHILDREN) : null;
List<DmDependencyTO> submittedChidren = getSubmittedItems(site, children, format, globalSchDate);
submittedItem.setChildren(submittedChidren);
if (uri.endsWith(DmConstants.XML_PATTERN)) {
/**
* Get dependent pages
*/
Set<String> deps = dependencyService.getItemDependencies(site, uri, 1);
List<String> pagePatterns = servicesConfig.getPagePatterns(site);
List<String> documentPatterns = servicesConfig.getDocumentPatterns(site);
List<DmDependencyTO> dependentPages = new ArrayList<>();
List<DmDependencyTO> dependentDocuments = new ArrayList<>();
for (String dep : deps) {
if (ContentUtils.matchesPatterns(dep, pagePatterns)) {
DmDependencyTO dmDependencyTO = new DmDependencyTO();
dmDependencyTO.setUri(dep);
dependentPages.add(dmDependencyTO);
} else if (ContentUtils.matchesPatterns(dep, documentPatterns)) {
DmDependencyTO dmDependencyTO = new DmDependencyTO();
dmDependencyTO.setUri(dep);
dependentDocuments.add(dmDependencyTO);
}
}
submittedItem.setPages(dependentPages);
submittedItem.setDocuments(dependentDocuments);
}
return submittedItem;
}
Aggregations