Search in sources :

Example 31 with ContentItemTO

use of org.craftercms.studio.api.v1.to.ContentItemTO 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);
    }
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) ContentNotFoundException(org.craftercms.studio.api.v1.exception.ContentNotFoundException) JSONException(net.sf.json.JSONException) DeploymentException(org.craftercms.studio.api.v1.service.deployment.DeploymentException)

Example 32 with ContentItemTO

use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.

the class WorkflowServiceImpl method addToQueue.

protected void addToQueue(String site, GoLiveQueue queue, GoLiveQueue inProcessQueue, ContentItemTO item, ItemState itemState) throws ServiceLayerException {
    if (item != null) {
        State state = State.valueOf(itemState.getState());
        // add only submitted items to go live Q.
        if (State.isSubmitted(state)) {
            queue.add(item);
        }
        if (inProcessQueue != null) {
            if (!State.isLive(state)) {
                inProcessQueue.add(item);
                inProcessQueue.add(item.getPath(), item);
            }
        }
    } else {
        objectStateService.deleteObjectState(itemState.getObjectId());
    }
}
Also used : ItemState(org.craftercms.studio.api.v1.dal.ItemState) State(org.craftercms.studio.api.v1.service.objectstate.State)

Example 33 with ContentItemTO

use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.

the class WorkflowServiceImpl method addInProgressItems.

protected void addInProgressItems(String site, ContentItemTO item, List<ContentItemTO> categoryItems, DmContentItemComparator comparator, boolean inProgressOnly) {
    if (addToQueue(false, inProgressOnly, true)) {
        if (!(item.isSubmitted() || item.isInProgress())) {
            return;
        }
        item.setDeleted(false);
        ContentItemTO found = null;
        String uri = item.getUri();
        for (ContentItemTO categoryItem : categoryItems) {
            String categoryPath = categoryItem.getPath() + FILE_SEPARATOR;
            if (uri.startsWith(categoryPath)) {
                found = categoryItem;
                break;
            }
        }
        if (found != null && !found.getUri().equals(item.getUri())) {
            found.addChild(item, comparator, true);
        }
    }
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO)

Example 34 with ContentItemTO

use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.

the class GoLiveQueueOrganizer method addThis.

protected void addThis(List<ContentItemTO> categoryItems, DmContentItemComparator comparator, ContentItemTO itemToAdd, boolean includeInProgress) {
    boolean include = itemToAdd.isSubmitted() || itemToAdd.isSubmittedForDeletion();
    if (includeInProgress) {
        include = include || itemToAdd.isInProgress();
    }
    if (!include) {
        return;
    }
    ContentItemTO found = null;
    String uri = itemToAdd.getUri();
    for (ContentItemTO categoryItem : categoryItems) {
        String categoryPath = categoryItem.getPath() + FILE_SEPARATOR;
        if (uri.startsWith(categoryPath)) {
            found = categoryItem;
            break;
        }
    }
    if (found != null && !found.getUri().equals(itemToAdd.getUri())) {
        found.addChild(itemToAdd, comparator, true, childFilter);
    }
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO)

Example 35 with ContentItemTO

use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.

the class AssetDmContentProcessor method writeContentAsset.

/**
 * upload content asset to the given path
 *
 * @param site
 * @param path
 * @param assetName
 * @param in
 *            input stream to read the asset from
 * @param width
 * @param height
 * @param createFolders
 * 				create missing folders?
 * @param isPreview
 * @param unlock
 * 			unlock the content upon update?
 * @return asset information
 * @throws ServiceLayerException
 */
protected ContentAssetInfoTO writeContentAsset(PipelineContent content, String site, String user, String path, String assetName, InputStream in, int width, int height, boolean createFolders, boolean isPreview, boolean unlock, boolean isSystemAsset, ResultTO result) throws ServiceLayerException {
    logger.debug("Writing content asset: [site: " + site + ", path: " + path + ", assetName: " + assetName + ", createFolders: " + createFolders);
    String ext = null;
    int index = assetName.lastIndexOf(".");
    if (index > 0 && (index + 1) < assetName.length()) {
        ext = assetName.substring(index + 1).toUpperCase();
    }
    String contentPath = path + FILE_SEPARATOR + assetName;
    try {
        // look up the path content first
        ContentItemTO parentContentItem = contentService.getContentItem(site, path, 0);
        boolean parentExists = contentService.contentExists(site, path);
        if (!parentExists && createFolders) {
            parentContentItem = createMissingFoldersInPath(site, path, isPreview);
            parentExists = contentService.contentExists(site, path);
        }
        if (parentExists && parentContentItem.isFolder()) {
            boolean exists = contentService.contentExists(site, path + FILE_SEPARATOR + assetName);
            ContentItemTO contentItem = null;
            if (exists) {
                contentItem = contentService.getContentItem(site, path + FILE_SEPARATOR + assetName, 0);
                updateFile(site, contentItem, contentPath, in, user, isPreview, unlock, result);
                content.addProperty(DmConstants.KEY_ACTIVITY_TYPE, OPERATION_UPDATE);
            } else {
                // TODO: define content type
                contentItem = createNewFile(site, parentContentItem, assetName, null, in, user, unlock, result);
                content.addProperty(DmConstants.KEY_ACTIVITY_TYPE, OPERATION_CREATE);
                objectStateService.insertNewEntry(site, contentItem);
            }
            ContentAssetInfoTO assetInfo = new ContentAssetInfoTO();
            assetInfo.setFileName(assetName);
            long sizeInBytes = contentService.getContentSize(site, path + FILE_SEPARATOR + assetName);
            double convertedSize = 0;
            if (sizeInBytes > 0) {
                convertedSize = sizeInBytes / 1024d;
                if (convertedSize >= 1024) {
                    assetInfo.setSizeUnit(FILE_SIZE_MB);
                    assetInfo.setSize(convertedSize / 1024d);
                } else {
                    if (convertedSize > 0 && convertedSize < 1) {
                        assetInfo.setSize(1);
                    } else {
                        assetInfo.setSize(Math.round(convertedSize));
                    }
                    assetInfo.setSizeUnit(FILE_SIZE_KB);
                }
            }
            assetInfo.setFileExtension(ext);
            return assetInfo;
        } else {
            throw new ServiceLayerException(path + " does not exist or not a directory.");
        }
    } finally {
        ContentUtils.release(in);
    }
}
Also used : ContentAssetInfoTO(org.craftercms.studio.api.v1.to.ContentAssetInfoTO) ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException)

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