Search in sources :

Example 6 with EVENT_PREVIEW_SYNC

use of org.craftercms.studio.api.v1.ebus.EBusConstants.EVENT_PREVIEW_SYNC in project studio by craftercms.

the class DeploymentServiceImpl method syncAllContentToPreview.

@Override
@ValidateParams
public void syncAllContentToPreview(@ValidateStringParam(name = "site") String site, boolean waitTillDone) throws ServiceLayerException {
    PreviewEventContext context = new PreviewEventContext(waitTillDone);
    context.setSite(site);
    eventService.publish(EVENT_PREVIEW_SYNC, context);
}
Also used : PreviewEventContext(org.craftercms.studio.api.v1.ebus.PreviewEventContext) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 7 with EVENT_PREVIEW_SYNC

use of org.craftercms.studio.api.v1.ebus.EBusConstants.EVENT_PREVIEW_SYNC in project studio by craftercms.

the class ContentServiceImpl method deleteContent.

@Override
@ValidateParams
public boolean deleteContent(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path, boolean generateActivity, @ValidateStringParam(name = "approver") String approver) throws SiteNotFoundException {
    String commitId;
    boolean toReturn = false;
    if (generateActivity) {
        generateDeleteActivity(site, path, approver);
    }
    commitId = _contentRepository.deleteContent(site, path, approver);
    objectStateService.deleteObjectStateForPath(site, path);
    objectMetadataManager.deleteObjectMetadata(site, path);
    try {
        dependencyService.deleteItemDependencies(site, path);
    } catch (ServiceLayerException e) {
        logger.error("Error deleting dependencies for site " + site + " path " + path, e);
    }
    if (StringUtils.isNotEmpty(commitId)) {
        contentRepository.insertGitLog(site, commitId, 1);
    }
    PreviewEventContext context = new PreviewEventContext();
    context.setSite(site);
    eventService.publish(EVENT_PREVIEW_SYNC, context);
    if (commitId != null) {
        toReturn = true;
    }
    return toReturn;
}
Also used : ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) PreviewEventContext(org.craftercms.studio.api.v1.ebus.PreviewEventContext) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 8 with EVENT_PREVIEW_SYNC

use of org.craftercms.studio.api.v1.ebus.EBusConstants.EVENT_PREVIEW_SYNC in project studio by craftercms.

the class ContentServiceImpl method renameFolder.

@Override
@ValidateParams
public boolean renameFolder(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path, @ValidateStringParam(name = "name") String name) throws ServiceLayerException {
    boolean toRet = false;
    String parentPath = FILE_SEPARATOR + FilenameUtils.getPathNoEndSeparator(path);
    String targetPath = parentPath + FILE_SEPARATOR + name;
    if (contentExists(site, targetPath)) {
        Map<String, String> ids = contentItemIdGenerator.getIds();
        String id = ids.get(KEY_PAGE_GROUP_ID);
        targetPath += "-" + id;
    }
    logger.debug("Rename folder for site {0} sourcePath {3} to target path {4}", site, path, targetPath);
    // NOTE: IN WRITE SCENARIOS the repository OP IS PART of this PIPELINE, for some reason,
    // historically with MOVE it is not
    Map<String, String> commitIds = _contentRepository.moveContent(site, path, targetPath);
    if (commitIds != null) {
        // Update the database with the commitId for the target item
        updateDatabaseOnMove(site, path, targetPath);
        updateChildrenOnMove(site, path, targetPath);
        for (Map.Entry<String, String> entry : commitIds.entrySet()) {
            objectMetadataManager.updateCommitId(site, FILE_SEPARATOR + entry.getKey(), entry.getValue());
            contentRepository.insertGitLog(site, entry.getValue(), 1);
        }
        siteService.updateLastCommitId(site, _contentRepository.getRepoLastCommitId(site));
        PreviewEventContext context = new PreviewEventContext();
        context.setSite(site);
        eventService.publish(EVENT_PREVIEW_SYNC, context);
        toRet = true;
    } else {
        logger.error("Repository move failed site {0} from {1} to {2}", site, path, targetPath);
    }
    return toRet;
}
Also used : Map(java.util.Map) HashMap(java.util.HashMap) MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap) PreviewEventContext(org.craftercms.studio.api.v1.ebus.PreviewEventContext) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 9 with EVENT_PREVIEW_SYNC

use of org.craftercms.studio.api.v1.ebus.EBusConstants.EVENT_PREVIEW_SYNC in project studio by craftercms.

the class ContentServiceImpl method writeContentAsset.

/**
 * write content asset
 *
 * @param site
 * @param path
 * @param assetName
 * @param in
 * @param isImage
 * 			is this asset an image?
 * @param allowedWidth
 * 			specifies the allowed image width in pixel if the asset is an image
 * @param allowedHeight
 * 			specifies the allowed image height in pixel if the asset is an image
 * @param unlock
 * 			unlock the content upon edit?
 * @return content asset info
 * @throws ServiceLayerException
 */
@Override
@ValidateParams
public Map<String, Object> writeContentAsset(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path, @ValidateStringParam(name = "assetName") String assetName, InputStream in, String isImage, String allowedWidth, String allowedHeight, String allowLessSize, String draft, String unlock, String systemAsset) throws ServiceLayerException {
    try {
        entitlementValidator.validateEntitlement(EntitlementType.ITEM, 1);
    } catch (EntitlementException e) {
        throw new ServiceLayerException("Unable to complete request due to entitlement limits. Please contact your " + "system administrator.");
    }
    boolean isSystemAsset = Boolean.valueOf(systemAsset);
    Map<String, String> params = new HashMap<String, String>();
    params.put(DmConstants.KEY_SITE, site);
    params.put(DmConstants.KEY_PATH, path);
    params.put(DmConstants.KEY_FILE_NAME, assetName);
    params.put(DmConstants.KEY_IS_IMAGE, isImage);
    params.put(DmConstants.KEY_ALLOW_LESS_SIZE, allowLessSize);
    params.put(DmConstants.KEY_ALLOWED_WIDTH, allowedWidth);
    params.put(DmConstants.KEY_ALLOWED_HEIGHT, allowedHeight);
    params.put(DmConstants.KEY_CONTENT_TYPE, "");
    params.put(DmConstants.KEY_CREATE_FOLDERS, "true");
    params.put(DmConstants.KEY_UNLOCK, unlock);
    params.put(DmConstants.KEY_SYSTEM_ASSET, String.valueOf(isSystemAsset));
    boolean exists = contentExists(site, path + FILE_SEPARATOR + assetName);
    params.put(DmConstants.KEY_ACTIVITY_TYPE, (exists ? OPERATION_UPDATE : OPERATION_CREATE));
    String id = site + ":" + path + ":" + assetName + ":" + "";
    // processContent will close the input stream
    ContentItemTO item = null;
    try {
        path = path + FILE_SEPARATOR + assetName;
        item = getContentItem(site, path);
        if (item != null) {
            ItemState itemState = objectStateService.getObjectState(site, path);
            if (itemState != null) {
                if (itemState.getSystemProcessing() != 0) {
                    logger.error(String.format("Error Content %s is being processed " + "(Object State is SYSTEM_PROCESSING);", path));
                    throw new RuntimeException(String.format("Content \"%s\" is being processed", path));
                }
                objectStateService.setSystemProcessing(site, path, true);
            }
        }
        if (objectStateService.deletedPathExists(site, path) || objectMetadataManager.movedPathExists(site, path)) {
            throw new ServiceLayerException("Content " + path + " for site " + site + ", cannot be created because" + " this name/URL was in use by another content item that has been moved or deleted by " + "not yet published.");
        }
        ResultTO result = processContent(id, in, false, params, DmConstants.CONTENT_CHAIN_ASSET);
        ContentAssetInfoTO assetInfoTO = (ContentAssetInfoTO) result.getItem();
        if (isSystemAsset) {
            path = path.replace(assetName, assetInfoTO.getFileName());
        }
        item = getContentItem(site, path);
        item.setSize(assetInfoTO.getSize());
        item.setSizeUnit(assetInfoTO.getSizeUnit());
        if (item != null) {
            if (result.getCommitId() != null) {
                objectStateService.transition(site, item, SAVE);
            } else {
                objectStateService.transition(site, item, TransitionEvent.CANCEL_EDIT);
            }
        }
        PreviewEventContext context = new PreviewEventContext();
        context.setSite(site);
        eventService.publish(EVENT_PREVIEW_SYNC, context);
        Map<String, Object> toRet = new HashMap<String, Object>();
        toRet.put("success", true);
        toRet.put("message", item);
        return toRet;
    } catch (Exception e) {
        logger.error("Error processing content", e);
        Map<String, Object> toRet = new HashMap<String, Object>();
        toRet.put("success", true);
        toRet.put("message", e.getMessage());
        toRet.put("error", e);
        return toRet;
    } finally {
        if (item != null) {
            objectStateService.setSystemProcessing(site, path, false);
        }
    }
}
Also used : ContentAssetInfoTO(org.craftercms.studio.api.v1.to.ContentAssetInfoTO) HashMap(java.util.HashMap) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) ResultTO(org.craftercms.studio.api.v1.to.ResultTO) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) IOException(java.io.IOException) AuthenticationException(org.craftercms.studio.api.v1.exception.security.AuthenticationException) InvalidRemoteUrlException(org.craftercms.studio.api.v1.exception.repository.InvalidRemoteUrlException) SAXException(org.xml.sax.SAXException) ContentNotFoundException(org.craftercms.studio.api.v1.exception.ContentNotFoundException) DocumentException(org.dom4j.DocumentException) EntitlementException(org.craftercms.commons.entitlements.exception.EntitlementException) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) CryptoException(org.craftercms.commons.crypto.CryptoException) EntitlementException(org.craftercms.commons.entitlements.exception.EntitlementException) ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) ItemState(org.craftercms.studio.api.v1.dal.ItemState) Map(java.util.Map) HashMap(java.util.HashMap) MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap) PreviewEventContext(org.craftercms.studio.api.v1.ebus.PreviewEventContext) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 10 with EVENT_PREVIEW_SYNC

use of org.craftercms.studio.api.v1.ebus.EBusConstants.EVENT_PREVIEW_SYNC in project studio by craftercms.

the class ContentServiceImpl method revertContentItem.

@Override
@ValidateParams
public boolean revertContentItem(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path, @ValidateStringParam(name = "version") String version, boolean major, @ValidateStringParam(name = "comment") String comment) throws SiteNotFoundException {
    boolean toReturn = false;
    String commitId = _contentRepository.revertContent(site, path, version, major, comment);
    if (commitId != null) {
        try {
            dependencyService.upsertDependencies(site, path);
        } catch (ServiceLayerException e) {
            logger.error("Error while extracting dependencies for reverted content. Site: " + site + " path: " + path + " version: " + version);
        }
        // Update the database with the commitId for the target item
        objectStateService.transition(site, path, REVERT);
        objectMetadataManager.updateCommitId(site, path, commitId);
        SiteFeed siteFeed = siteService.getSite(site);
        AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
        auditLog.setOperation(OPERATION_REVERT);
        auditLog.setSiteId(siteFeed.getId());
        auditLog.setActorId(securityService.getCurrentUser());
        auditLog.setPrimaryTargetId(site + ":" + path);
        auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
        auditLog.setPrimaryTargetValue(path);
        auditLog.setPrimaryTargetSubtype(getContentTypeClass(site, path));
        auditServiceInternal.insertAuditLog(auditLog);
        contentRepository.insertGitLog(site, commitId, 1, 1);
        siteService.updateLastCommitId(site, commitId);
        toReturn = true;
    }
    if (toReturn) {
        PreviewEventContext context = new PreviewEventContext();
        context.setSite(site);
        eventService.publish(EVENT_PREVIEW_SYNC, context);
    }
    return toReturn;
}
Also used : SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) PreviewEventContext(org.craftercms.studio.api.v1.ebus.PreviewEventContext) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Aggregations

PreviewEventContext (org.craftercms.studio.api.v1.ebus.PreviewEventContext)11 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)8 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)6 HashMap (java.util.HashMap)5 Map (java.util.Map)3 MimetypesFileTypeMap (javax.activation.MimetypesFileTypeMap)3 EntitlementException (org.craftercms.commons.entitlements.exception.EntitlementException)2 ItemState (org.craftercms.studio.api.v1.dal.ItemState)2 SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)2 ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)2 AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 CryptoException (org.craftercms.commons.crypto.CryptoException)1 HasPermission (org.craftercms.commons.security.permissions.annotations.HasPermission)1 ContentNotFoundException (org.craftercms.studio.api.v1.exception.ContentNotFoundException)1 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)1 InvalidRemoteUrlException (org.craftercms.studio.api.v1.exception.repository.InvalidRemoteUrlException)1 AuthenticationException (org.craftercms.studio.api.v1.exception.security.AuthenticationException)1 ContentRepository (org.craftercms.studio.api.v1.repository.ContentRepository)1