Search in sources :

Example 46 with ContentItemTO

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);
        }
    }
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO)

Example 47 with ContentItemTO

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;
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) DeploymentHistoryGroup(org.craftercms.studio.api.v2.dal.DeploymentHistoryGroup)

Example 48 with ContentItemTO

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;
}
Also used : DeploymentHistoryItem(org.craftercms.studio.api.v2.dal.DeploymentHistoryItem) HashSet(java.util.HashSet) Set(java.util.Set) DeploymentHistoryGroup(org.craftercms.studio.api.v2.dal.DeploymentHistoryGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) ZonedDateTime(java.time.ZonedDateTime)

Example 49 with ContentItemTO

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;
    }
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) ZonedDateTime(java.time.ZonedDateTime) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException)

Example 50 with ContentItemTO

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);
    }
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) DmOrderTO(org.craftercms.studio.api.v1.to.DmOrderTO) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Aggregations

ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)60 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)19 HashMap (java.util.HashMap)16 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)15 ArrayList (java.util.ArrayList)10 ItemState (org.craftercms.studio.api.v1.dal.ItemState)10 ContentNotFoundException (org.craftercms.studio.api.v1.exception.ContentNotFoundException)10 JSONObject (net.sf.json.JSONObject)6 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)6 HashSet (java.util.HashSet)5 JSONException (net.sf.json.JSONException)5 ItemMetadata (org.craftercms.studio.api.v1.dal.ItemMetadata)5 ZonedDateTime (java.time.ZonedDateTime)4 CryptoException (org.craftercms.commons.crypto.CryptoException)4 EntitlementException (org.craftercms.commons.entitlements.exception.EntitlementException)4 DeploymentException (org.craftercms.studio.api.v1.service.deployment.DeploymentException)4 DocumentException (org.dom4j.DocumentException)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 MimetypesFileTypeMap (javax.activation.MimetypesFileTypeMap)3