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);
}
}
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;
}
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();
}
}
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;
}
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);
}
Aggregations