use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class WorkflowServiceImpl method getMandatoryChildren.
private void getMandatoryChildren(String site, String path, List<String> affectedPaths) {
ContentItemTO item = contentService.getContentItem(site, path);
for (ContentItemTO child : item.getChildren()) {
if (!affectedPaths.contains(child.getUri())) {
affectedPaths.add(child.getUri());
getMandatoryChildren(site, child.getUri(), affectedPaths);
}
}
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class PublishServiceImpl method createDeploymentHistoryGroup.
private DeploymentHistoryGroup createDeploymentHistoryGroup(String deployedLabel, ContentItemTO item) {
// otherwise just add as the last task
DeploymentHistoryGroup group = new DeploymentHistoryGroup();
group.setInternalName(deployedLabel);
List<ContentItemTO> taskItems = group.getChildren();
if (taskItems == null) {
taskItems = new ArrayList<ContentItemTO>();
group.setChildren(taskItems);
}
taskItems.add(item);
group.setNumOfChildren(taskItems.size());
return group;
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class PublishServiceImpl method getDeploymentHistory.
@Override
public List<DeploymentHistoryGroup> getDeploymentHistory(String siteId, int daysFromToday, int numberOfItems, String filterType) {
ZonedDateTime toDate = ZonedDateTime.now(ZoneOffset.UTC);
ZonedDateTime fromDate = toDate.minusDays(daysFromToday);
List<String> environments = studioUtils.getEnvironmentNames(siteId);
List<DeploymentHistoryItem> deploymentHistoryItems = publishServiceInternal.getDeploymentHistory(siteId, environments, fromDate, toDate, filterType, numberOfItems);
List<DeploymentHistoryGroup> groups = new ArrayList<DeploymentHistoryGroup>();
if (deploymentHistoryItems != null) {
int count = 0;
String timezone = servicesConfig.getDefaultTimezone(siteId);
Map<String, Set<String>> processedItems = new HashMap<String, Set<String>>();
for (int index = 0; index < deploymentHistoryItems.size() && count < numberOfItems; index++) {
DeploymentHistoryItem entry = deploymentHistoryItems.get(index);
String env = entry.getEnvironment();
if (!processedItems.containsKey(env)) {
processedItems.put(env, new HashSet<String>());
}
if (!processedItems.get(env).contains(entry.getPath())) {
ContentItemTO deployedItem = studioUtils.getContentItemForDashboard(entry.getSite(), entry.getPath());
if (deployedItem != null) {
deployedItem.eventDate = entry.getDeploymentDate();
deployedItem.endpoint = entry.getTarget();
deployedItem.setUser(entry.getUser());
deployedItem.setEndpoint(entry.getEnvironment());
String deployedLabel = entry.getDeploymentDate().withZoneSameInstant(ZoneId.of(timezone)).format(ISO_OFFSET_DATE);
if (groups.size() > 0) {
DeploymentHistoryGroup group = groups.get(groups.size() - 1);
String lastDeployedLabel = group.getInternalName();
if (lastDeployedLabel.equals(deployedLabel)) {
// add to the last task if it is deployed on the same day
group.setNumOfChildren(group.getNumOfChildren() + 1);
group.getChildren().add(deployedItem);
} else {
groups.add(createDeploymentHistoryGroup(deployedLabel, deployedItem));
}
} else {
groups.add(createDeploymentHistoryGroup(deployedLabel, deployedItem));
}
processedItems.get(env).add(entry.getPath());
}
}
}
}
return groups;
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class AuditServiceImpl method createActivityItem.
protected ContentItemTO createActivityItem(String site, AuditLog auditLog, String id) {
try {
ContentItemTO item = contentService.getContentItem(site, id, 0);
if (item == null || item.isDeleted()) {
item = contentService.createDummyDmContentItemForDeletedNode(site, id);
String modifier = auditLog.getActorId();
if (modifier != null && !modifier.isEmpty()) {
item.user = modifier;
}
item.contentType = auditLog.getPrimaryTargetSubtype();
item.setLockOwner("");
}
ZonedDateTime editedDate = auditLog.getOperationTimestamp();
if (editedDate != null) {
item.eventDate = editedDate.withZoneSameInstant(ZoneOffset.UTC);
} else {
item.eventDate = editedDate;
}
return item;
} catch (Exception e) {
logger.error("Error fetching content item for [" + id + "]", e.getMessage());
return null;
}
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class ContentServiceImpl method reorderItems.
@Override
@ValidateParams
public double reorderItems(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "relativePath") String relativePath, @ValidateSecurePathParam(name = "before") String before, @ValidateSecurePathParam(name = "after") String after, @ValidateStringParam(name = "orderName") String orderName) throws ServiceLayerException {
Double beforeOrder = null;
Double afterOrder = null;
DmOrderTO beforeOrderTO = null;
DmOrderTO afterOrderTO = null;
// if the path is not provided, the order is 0
if (!StringUtils.isEmpty(before)) {
ContentItemTO beforeItem = getContentItem(site, before, 0);
beforeOrder = beforeItem.getOrder(orderName);
beforeOrderTO = new DmOrderTO();
beforeOrderTO.setId(before);
if (beforeOrder != null && beforeOrder > 0) {
beforeOrderTO.setOrder(beforeOrder);
}
}
// ORDER_INCREMENT
if (!StringUtils.isEmpty(after)) {
ContentItemTO afterItem = getContentItem(site, after, 0);
afterOrder = afterItem.getOrder(orderName);
afterOrderTO = new DmOrderTO();
afterOrderTO.setId(after);
if (afterOrder != null && afterOrder > 0) {
afterOrderTO.setOrder(afterOrder);
}
}
// if no after and before provided, the initial value is ORDER_INCREMENT
if (afterOrder == null && beforeOrder == null) {
return dmPageNavigationOrderService.getNewNavOrder(site, ContentUtils.getParentUrl(relativePath.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, "")));
} else if (beforeOrder == null) {
return (0 + afterOrder) / 2;
} else if (afterOrder == null) {
logger.info("afterOrder == null");
return dmPageNavigationOrderService.getNewNavOrder(site, ContentUtils.getParentUrl(relativePath.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, "")), beforeOrder);
} else {
// return (beforeOrder + afterOrder) / 2;
return computeReorder(site, relativePath, beforeOrderTO, afterOrderTO, orderName);
}
}
Aggregations