Search in sources :

Example 1 with ValidateParams

use of org.craftercms.commons.validation.annotations.param.ValidateParams in project studio by craftercms.

the class NotificationServiceImpl method notifyRepositoryMergeConflict.

@Override
@ValidateParams
public void notifyRepositoryMergeConflict(@ValidateStringParam(name = "site") final String site, final List<String> filesUnableToMerge, final Locale locale) {
    try {
        final NotificationConfigTO notificationConfig = getNotificationConfig(site, locale);
        final Map<String, Object> templateModel = new HashMap<>();
        templateModel.put("files", filesUnableToMerge);
        notify(site, notificationConfig.getRepositoryMergeConflictNotifications(), NOTIFICATION_KEY_REPOSITORY_MERGE_CONFLICT, locale, templateModel);
    } catch (Throwable ex) {
        logger.error("Unable to Notify Error", ex);
    }
}
Also used : HashMap(java.util.HashMap) NotificationConfigTO(org.craftercms.studio.api.v1.to.NotificationConfigTO) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 2 with ValidateParams

use of org.craftercms.commons.validation.annotations.param.ValidateParams in project studio by craftercms.

the class ContentServiceImpl method moveContent.

@Override
@ValidateParams
public String moveContent(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "fromPath") String fromPath, @ValidateSecurePathParam(name = "toPath") String toPath) {
    String retNewFileName = null;
    boolean opSuccess = false;
    String movePath = null;
    try {
        String sourcePath = (fromPath.indexOf("" + FILE_SEPARATOR + DmConstants.INDEX_FILE) != -1) ? fromPath.substring(0, fromPath.lastIndexOf(FILE_SEPARATOR)) : fromPath;
        String sourcePathOnly = fromPath.substring(0, fromPath.lastIndexOf(FILE_SEPARATOR));
        Map<String, String> movePathMap = constructNewPathforCutCopy(site, fromPath, toPath, true);
        movePath = movePathMap.get("FILE_PATH");
        String moveFileName = movePathMap.get("FILE_NAME");
        String movePathOnly = movePath.substring(0, movePath.lastIndexOf(FILE_SEPARATOR));
        boolean moveAltFileName = "true".equals(movePathMap.get("ALT_NAME"));
        boolean targetIsIndex = DmConstants.INDEX_FILE.equals(moveFileName);
        boolean sourceIsIndex = DmConstants.INDEX_FILE.equals(fromPath);
        String targetPath = movePathOnly;
        if (movePathOnly.equals(sourcePathOnly) || (moveAltFileName == true && !targetIsIndex) || (!sourceIsIndex && !targetIsIndex)) {
            // we never send index.xml to the repo, we move folders (and the folder has the rename)
            // SO otherwise, this is a rename and we need to forward the full path
            targetPath = movePath;
        }
        logger.debug("Move file for site {0} from {1} to {2}, sourcePath {3} to target path {4}", site, fromPath, toPath, sourcePath, 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, sourcePath, targetPath);
        if (commitIds != null) {
            // Update the database with the commitId for the target item
            updateDatabaseOnMove(site, fromPath, movePath);
            updateChildrenOnMove(site, fromPath, movePath);
            for (Map.Entry<String, String> entry : commitIds.entrySet()) {
                objectMetadataManager.updateCommitId(site, FILE_SEPARATOR + entry.getKey(), entry.getValue());
                contentRepository.insertGitLog(site, entry.getValue(), 1, 1);
            }
            siteService.updateLastCommitId(site, _contentRepository.getRepoLastCommitId(site));
        } else {
            logger.error("Repository move failed site {0} from {1} to {2}", site, sourcePath, targetPath);
            movePath = fromPath;
        }
        PreviewEventContext context = new PreviewEventContext();
        context.setSite(site);
        eventService.publish(EVENT_PREVIEW_SYNC, context);
    } catch (ServiceLayerException eMoveErr) {
        logger.error("Content not found while moving content for site {0} from {1} to {2}, new name is {3}", eMoveErr, site, fromPath, toPath, movePath);
    }
    return movePath;
}
Also used : ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) 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 3 with ValidateParams

use of org.craftercms.commons.validation.annotations.param.ValidateParams in project studio by craftercms.

the class ContentServiceImpl method getDeleteCandidates.

@Override
@ValidateParams
public GoLiveDeleteCandidates getDeleteCandidates(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "relativePath") String relativePath) throws ServiceLayerException {
    ContentItemTO contentItem = getContentItem(site, relativePath);
    GoLiveDeleteCandidates deletedItems = new GoLiveDeleteCandidates(site, this, objectStateService);
    if (contentItem != null) {
        childDeleteItems(site, contentItem, deletedItems);
    // update summary for all uri's delete
    }
    return deletedItems;
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) GoLiveDeleteCandidates(org.craftercms.studio.api.v1.to.GoLiveDeleteCandidates) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 4 with ValidateParams

use of org.craftercms.commons.validation.annotations.param.ValidateParams in project studio by craftercms.

the class ContentTypesConfigImpl method reloadConfiguration.

@Override
@ValidateParams
public ContentTypeConfigTO reloadConfiguration(@ValidateStringParam(name = "site") String site, @ValidateStringParam(name = "contentType") String contentType) {
    StudioCacheContext cacheContext = new StudioCacheContext(site, true);
    String siteConfigPath = getConfigPath().replaceAll(StudioConstants.PATTERN_SITE, site).replaceAll(StudioConstants.PATTERN_CONTENT_TYPE, contentType);
    ContentTypeConfigTO config = loadConfiguration(site, contentType);
    return config;
}
Also used : ContentTypeConfigTO(org.craftercms.studio.api.v1.to.ContentTypeConfigTO) StudioCacheContext(org.craftercms.studio.impl.v1.service.StudioCacheContext) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 5 with ValidateParams

use of org.craftercms.commons.validation.annotations.param.ValidateParams in project studio by craftercms.

the class ContentTypesConfigImpl method loadConfiguration.

@SuppressWarnings("unchecked")
@Override
@ValidateParams
public ContentTypeConfigTO loadConfiguration(@ValidateStringParam(name = "site") String site, @ValidateStringParam(name = "contentType") String contentType) {
    String siteConfigPath = getConfigPath().replaceAll(StudioConstants.PATTERN_SITE, site).replaceAll(StudioConstants.PATTERN_CONTENT_TYPE, contentType);
    String configFileFullPath = siteConfigPath + FILE_SEPARATOR + getConfigFileName();
    Document document = null;
    try {
        if (contentService.contentExists(site, configFileFullPath)) {
            document = contentService.getContentAsDocument(site, configFileFullPath);
        }
    } catch (DocumentException e) {
        logger.debug("No content type configuration document found at " + configFileFullPath, e);
    }
    if (document != null) {
        Element root = document.getRootElement();
        String name = root.valueOf("@name");
        ContentTypeConfigTO contentTypeConfig = new ContentTypeConfigTO();
        contentTypeConfig.setName(name);
        contentTypeConfig.setLabel(root.valueOf("label"));
        String imageThumbnail = root.valueOf("image-thumbnail");
        if (imageThumbnail != null)
            contentTypeConfig.setImageThumbnail(imageThumbnail);
        contentTypeConfig.setForm(root.valueOf("form"));
        boolean previewable = ContentFormatUtils.getBooleanValue(root.valueOf("previewable"));
        contentTypeConfig.setFormPath(root.valueOf("form-path"));
        contentTypeConfig.setPreviewable(previewable);
        contentTypeConfig.setModelInstancePath(root.valueOf("model-instance-path"));
        boolean contentAsFolder = ContentFormatUtils.getBooleanValue(root.valueOf("content-as-folder"));
        contentTypeConfig.setContentAsFolder(contentAsFolder);
        boolean useRoundedFolder = ContentFormatUtils.getBooleanValue(root.valueOf("use-rounded-folder"));
        contentTypeConfig.setUseRoundedFolder(useRoundedFolder);
        List<String> pathIncludes = getPaths(root, "paths/includes/pattern");
        if (pathIncludes.size() == 0) {
            // if no configuration, include every path
            pathIncludes.add(".*");
        }
        contentTypeConfig.setPathIncludes(pathIncludes);
        List<String> pathExcludes = getPaths(root, "paths/excludes/pattern");
        contentTypeConfig.setPathExcludes(pathExcludes);
        loadRoles(contentTypeConfig, root.selectNodes("allowed-roles/role"));
        loadDeleteDependencies(contentTypeConfig, root.selectNodes("delete-dependencies/delete-dependency"));
        loadCopyDependencyPatterns(contentTypeConfig, root.selectNodes("copy-dependencies/copy-dependency"));
        contentTypeConfig.setLastUpdated(ZonedDateTime.now(ZoneOffset.UTC));
        contentTypeConfig.setType(getContentTypeTypeByName(name));
        boolean quickCreate = ContentFormatUtils.getBooleanValue(root.valueOf(QUICK_CREATE));
        contentTypeConfig.setQuickCreate(quickCreate);
        contentTypeConfig.setQuickCreatePath(root.valueOf(QUICK_CREATE_PATH));
        return contentTypeConfig;
    } else {
        logger.debug("No content type configuration document found at " + configFileFullPath);
        return null;
    }
}
Also used : ContentTypeConfigTO(org.craftercms.studio.api.v1.to.ContentTypeConfigTO) DocumentException(org.dom4j.DocumentException) Element(org.dom4j.Element) Document(org.dom4j.Document) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Aggregations

ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)86 HashMap (java.util.HashMap)29 ItemState (org.craftercms.studio.api.v1.dal.ItemState)19 ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)18 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)15 ArrayList (java.util.ArrayList)14 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)10 SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)9 IOException (java.io.IOException)8 PublishRequest (org.craftercms.studio.api.v1.dal.PublishRequest)8 ZonedDateTime (java.time.ZonedDateTime)7 PreviewEventContext (org.craftercms.studio.api.v1.ebus.PreviewEventContext)7 UserNotFoundException (org.craftercms.studio.api.v1.exception.security.UserNotFoundException)7 ContentTypeConfigTO (org.craftercms.studio.api.v1.to.ContentTypeConfigTO)7 DocumentException (org.dom4j.DocumentException)7 CryptoException (org.craftercms.commons.crypto.CryptoException)6 RetryingOperation (org.craftercms.studio.api.v2.annotation.RetryingOperation)6 AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)6 HashSet (java.util.HashSet)5 List (java.util.List)5