Search in sources :

Example 11 with HasPermission

use of org.craftercms.commons.security.permissions.annotations.HasPermission in project studio by craftercms.

the class PublishServiceImpl method cancelPublishingPackages.

@Override
@HasPermission(type = DefaultPermission.class, action = ACTION_CANCEL_PUBLISH)
public void cancelPublishingPackages(@ProtectedResourceId(SITE_ID_RESOURCE_ID) String siteId, List<String> packageIds) throws SiteNotFoundException {
    if (!siteService.exists(siteId)) {
        throw new SiteNotFoundException(siteId);
    }
    publishServiceInternal.cancelPublishingPackages(siteId, packageIds);
    List<AuditLogParameter> auditLogParameters = new ArrayList<AuditLogParameter>();
    for (String pId : packageIds) {
        PublishingPackageDetails packageDetails = publishServiceInternal.getPublishingPackageDetails(siteId, pId);
        List<String> paths = new ArrayList<String>();
        for (PublishingPackageDetails.PublishingPackageItem item : packageDetails.getItems()) {
            paths.add(item.getPath());
            ItemMetadata itemMetadata = objectMetadataManager.getProperties(siteId, item.getPath());
            if (itemMetadata != null) {
                itemMetadata.setSubmittedBy(StringUtils.EMPTY);
                itemMetadata.setSendEmail(0);
                itemMetadata.setSubmittedForDeletion(0);
                itemMetadata.setSubmissionComment(StringUtils.EMPTY);
                itemMetadata.setLaunchDate(null);
                itemMetadata.setSubmittedToEnvironment(StringUtils.EMPTY);
                objectMetadataManager.updateObjectMetadata(itemMetadata);
            }
            AuditLogParameter auditLogParameter = new AuditLogParameter();
            auditLogParameter.setTargetId(siteId + ":" + item.getPath());
            auditLogParameter.setTargetType(TARGET_TYPE_CONTENT_ITEM);
            auditLogParameter.setTargetValue(item.getPath());
            auditLogParameters.add(auditLogParameter);
        }
        objectStateService.transitionBulk(siteId, paths, REJECT, NEW_UNPUBLISHED_UNLOCKED);
        createAuditLogEntry(siteId, auditLogParameters);
    }
}
Also used : ArrayList(java.util.ArrayList) AuditLogParameter(org.craftercms.studio.api.v2.dal.AuditLogParameter) PublishingPackageDetails(org.craftercms.studio.api.v2.dal.PublishingPackageDetails) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) ItemMetadata(org.craftercms.studio.api.v1.dal.ItemMetadata) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission)

Example 12 with HasPermission

use of org.craftercms.commons.security.permissions.annotations.HasPermission in project studio by craftercms.

the class CmisServiceImpl method list.

@Override
@HasPermission(type = DefaultPermission.class, action = "list_cmis")
public List<CmisContentItem> list(@ProtectedResourceId(SITE_ID_RESOURCE_ID) String siteId, String cmisRepo, String path) throws CmisRepositoryNotFoundException, CmisUnavailableException, CmisTimeoutException, ConfigurationException {
    List<CmisContentItem> items = new ArrayList<CmisContentItem>();
    DataSourceRepository repositoryConfig = getConfiguration(siteId, cmisRepo);
    Session session = createCMISSession(repositoryConfig);
    if (session != null) {
        String contentPath = Paths.get(repositoryConfig.getBasePath(), path).toString();
        CmisObject cmisObject = session.getObjectByPath(contentPath);
        if (cmisObject != null && CMIS_FOLDER.equals(cmisObject.getBaseTypeId())) {
            Folder folder = (Folder) cmisObject;
            Iterable<CmisObject> iterable = folder.getChildren();
            for (CmisObject cmisItem : iterable) {
                CmisContentItem item = new CmisContentItem();
                item.setItemName(cmisItem.getName());
                if (CMIS_DOCUMENT.equals(cmisItem.getBaseTypeId())) {
                    Document cmisDoc = (Document) cmisItem;
                    item.setItemPath(cmisDoc.getPaths().get(0));
                    item.setMimeType(cmisDoc.getContentStreamMimeType());
                    String contentId = cmisDoc.getId();
                    StringTokenizer st = new StringTokenizer(contentId, ";");
                    if (st.hasMoreTokens()) {
                        item.setItemId(st.nextToken());
                    }
                    item.setSize(cmisDoc.getContentStreamLength());
                    items.add(item);
                } else if (CMIS_FOLDER.equals(cmisItem.getBaseTypeId())) {
                    Folder cmisFolder = (Folder) cmisItem;
                    item.setItemId(cmisFolder.getId());
                    item.setItemPath(cmisFolder.getPath());
                    item.setMimeType(MIME_TYPE_FOLDER);
                    item.setSize(-1);
                    items.add(item);
                }
            }
        }
    }
    return items;
}
Also used : CmisContentItem(org.craftercms.studio.api.v2.dal.CmisContentItem) DataSourceRepository(org.craftercms.studio.api.v2.dal.DataSourceRepository) StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) Session(org.apache.chemistry.opencmis.client.api.Session) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission)

Example 13 with HasPermission

use of org.craftercms.commons.security.permissions.annotations.HasPermission in project studio by craftercms.

the class CmisServiceImpl method cloneContent.

@Override
@HasPermission(type = DefaultPermission.class, action = "clone_content_cmis")
public void cloneContent(@ProtectedResourceId(SITE_ID_RESOURCE_ID) String siteId, String cmisRepoId, String cmisPath, @ProtectedResourceId(PATH_RESOURCE_ID) String studioPath) throws StudioPathNotFoundException, CmisRepositoryNotFoundException, CmisUnavailableException, CmisTimeoutException, CmisPathNotFoundException, ServiceLayerException {
    if (!contentService.contentExists(siteId, studioPath))
        throw new StudioPathNotFoundException("Studio repository path does not exist for site " + siteId + " (path: " + studioPath + ")");
    DataSourceRepository repositoryConfig = getConfiguration(siteId, cmisRepoId);
    logger.debug("Create new CMIS session");
    Session session = createCMISSession(repositoryConfig);
    if (session != null) {
        String contentPath = Paths.get(repositoryConfig.getBasePath(), cmisPath).toString();
        logger.debug("Find object for CMIS path: " + contentPath);
        CmisObject cmisObject = session.getObjectByPath(contentPath);
        if (cmisObject != null) {
            if (BaseTypeId.CMIS_FOLDER.equals(cmisObject.getBaseTypeId())) {
                throw new CmisPathNotFoundException();
            } else if (CMIS_DOCUMENT.equals(cmisObject.getBaseTypeId())) {
                Document cmisDoc = (Document) cmisObject;
                String fileName = cmisDoc.getName();
                String savePath = studioPath + FILE_SEPARATOR + fileName;
                ContentStream cs = cmisDoc.getContentStream();
                logger.debug("Save CMIS file to: " + savePath);
                contentService.writeContent(siteId, savePath, cs.getStream());
            }
        } else {
            throw new CmisPathNotFoundException();
        }
    } else {
        throw new CmisUnauthorizedException();
    }
}
Also used : StudioPathNotFoundException(org.craftercms.studio.api.v1.exception.StudioPathNotFoundException) DataSourceRepository(org.craftercms.studio.api.v2.dal.DataSourceRepository) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) CmisUnauthorizedException(org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException) Document(org.apache.chemistry.opencmis.client.api.Document) CmisPathNotFoundException(org.craftercms.studio.api.v1.exception.CmisPathNotFoundException) Session(org.apache.chemistry.opencmis.client.api.Session) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission)

Example 14 with HasPermission

use of org.craftercms.commons.security.permissions.annotations.HasPermission in project studio by craftercms.

the class CmisServiceImpl method search.

@Override
@HasPermission(type = DefaultPermission.class, action = "search_cmis")
public List<CmisContentItem> search(@ProtectedResourceId(SITE_ID_RESOURCE_ID) String siteId, String cmisRepo, String searchTerm, String path) throws CmisRepositoryNotFoundException, CmisUnavailableException, CmisTimeoutException, ConfigurationException {
    List<CmisContentItem> toRet = new ArrayList<CmisContentItem>();
    DataSourceRepository repositoryConfig = getConfiguration(siteId, cmisRepo);
    Session session = createCMISSession(repositoryConfig);
    if (session != null) {
        String contentPath = Paths.get(repositoryConfig.getBasePath(), path).toString();
        CmisObject cmisObject = session.getObjectByPath(contentPath);
        if (cmisObject != null) {
            if (CMIS_FOLDER.equals(cmisObject.getBaseTypeId())) {
                String queryString = CMIS_SEARCH_QUERY.replace(CMIS_SEARCH_QUERY_FOLDER_ID_VARIABLE, cmisObject.getId()).replace(CMIS_SEARCH_QUERY_SEARCH_TERM_VARIABLE, searchTerm);
                ItemIterable<QueryResult> result = session.query(queryString, false);
                for (QueryResult qr : result) {
                    CmisContentItem item = new CmisContentItem();
                    String contentId = qr.getPropertyById(OBJECT_ID).getFirstValue().toString();
                    StringTokenizer st = new StringTokenizer(contentId, ";");
                    if (st.hasMoreTokens()) {
                        item.setItemId(st.nextToken());
                    }
                    CmisObject qrObject = session.getObject(item.getItemId());
                    Document cmisDoc = (Document) qrObject;
                    item.setItemName(cmisDoc.getName());
                    item.setItemPath(cmisDoc.getPaths().get(0));
                    item.setMimeType(cmisDoc.getContentStreamMimeType());
                    item.setSize(cmisDoc.getContentStreamLength());
                    toRet.add(item);
                }
            }
        }
    }
    return toRet;
}
Also used : CmisContentItem(org.craftercms.studio.api.v2.dal.CmisContentItem) DataSourceRepository(org.craftercms.studio.api.v2.dal.DataSourceRepository) QueryResult(org.apache.chemistry.opencmis.client.api.QueryResult) StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) Document(org.apache.chemistry.opencmis.client.api.Document) Session(org.apache.chemistry.opencmis.client.api.Session) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission)

Example 15 with HasPermission

use of org.craftercms.commons.security.permissions.annotations.HasPermission in project studio by craftercms.

the class ConfigurationServiceImpl method writeConfiguration.

@Override
@HasPermission(type = DefaultPermission.class, action = "write_configuration")
public void writeConfiguration(@ProtectedResourceId(SITE_ID_RESOURCE_ID) String siteId, String module, String path, String environment, InputStream content) throws ServiceLayerException {
    writeEnvironmentConfiguration(siteId, module, path, environment, content);
    PreviewEventContext context = new PreviewEventContext();
    context.setSite(siteId);
    eventService.publish(EVENT_PREVIEW_SYNC, context);
}
Also used : PreviewEventContext(org.craftercms.studio.api.v1.ebus.PreviewEventContext) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission)

Aggregations

HasPermission (org.craftercms.commons.security.permissions.annotations.HasPermission)25 ArrayList (java.util.ArrayList)13 SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)11 AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)11 AuditLogParameter (org.craftercms.studio.api.v2.dal.AuditLogParameter)8 Group (org.craftercms.studio.api.v2.dal.Group)8 User (org.craftercms.studio.api.v2.dal.User)6 AuthenticatedUser (org.craftercms.studio.model.AuthenticatedUser)6 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)5 List (java.util.List)4 StringTokenizer (java.util.StringTokenizer)4 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)4 Document (org.apache.chemistry.opencmis.client.api.Document)4 Session (org.apache.chemistry.opencmis.client.api.Session)4 AmazonS3 (com.amazonaws.services.s3.AmazonS3)3 StringUtils (org.apache.commons.lang3.StringUtils)3 DataSourceRepository (org.craftercms.studio.api.v2.dal.DataSourceRepository)3 Sardine (com.github.sardine.Sardine)2 InputStream (java.io.InputStream)2 Collections (java.util.Collections)2