protected final Site getSiteOrNull( final Content content ) { return content != null ? this.contentService.getNearestSite( content.getId() ) : null; }
private boolean doDelete( final DeleteContentParams params ) { try { return this.contentService.deleteWithoutFetch( params ) != null; } catch ( final ContentNotFoundException e ) { return false; } }
final Content sourceContent = contentService.getByPath( sourcePath ); sourceId = sourceContent.getId(); final Content sourceContent = contentService.getById( sourceId ); sourcePath = sourceContent.getPath(); if ( contentService.contentExists( targetPath ) )
private Content getContentByPath( final ContentPath contentPath ) { try { return this.contentService.getByPath( contentPath ); } catch ( ContentNotFoundException e ) { return null; } }
private Content getContentById( final ContentId contentId ) { try { return this.contentService.getById( contentId ); } catch ( final Exception e ) { return null; } }
public void execute() { UpdateContentParams updateContent = new UpdateContentParams(); if ( !this.key.startsWith( "/" ) ) { updateContent.contentId( ContentId.from( this.key ) ); } else { final Content contentByPath = this.contentService.getByPath( ContentPath.from( key ) ); updateContent.contentId( contentByPath.getId() ); } BinaryReferences binaryRefs = BinaryReferences.from( Arrays.stream( this.names ).map( BinaryReference::from ).collect( toList() ) ); updateContent.removeAttachments( binaryRefs ); contentService.update( updateContent ); }
private boolean contentExists( final String contentSelector ) { final ContentId contentId = ContentId.from( contentSelector.substring( 1 ) ); final ContentPath contentPath = ContentPath.from( contentSelector ).asAbsolute(); return this.contentService.contentExists( contentId ) || this.contentService.contentExists( contentPath ); }
private Content move( final ContentId sourceId, final ContentPath newPath ) { final MoveContentParams moveParams = MoveContentParams.create(). contentId( sourceId ). parentContentPath( newPath ). build(); final MoveContentsResult result = contentService.move( moveParams ); return contentService.getById( result.getMovedContents().first() ); }
edit.permissions = permissions; } ); contentService.update( updatePermissionsParams ); contentService.applyPermissions( ApplyContentPermissionsParams.create(). contentId( contentId ). overwriteChildPermissions( overwriteChildPermissions ).
@Override protected Object doExecute() { if ( isBlank( this.name ) && isNotBlank( this.displayName ) && isNotBlank( this.parentPath ) ) { this.name = generateUniqueContentName( ContentPath.from( this.parentPath ), this.displayName ); } if ( isBlank( this.displayName ) && isNotBlank( this.name ) ) { this.displayName = this.name; } final CreateContentParams params = createParams(); final Content result = this.contentService.create( params ); return new ContentMapper( result ); }
private ByteSource getAttachment( final Content content, final String attachmentName ) { final Attachment attachment = content.getAttachments().byName( attachmentName ); if ( attachment == null ) { return null; } return this.contentService.getBinary( content.getId(), attachment.getBinaryReference() ); }
private ContentsResultMapper getChildren( final FindContentByParentParams.Builder findContentByParent, final int start, final int count, final String sortExpr ) { final ChildOrder childOrder = ChildOrder.from( sortExpr ); try { final FindContentByParentResult result = this.contentService.findByParent( findContentByParent. from( start ). size( count ). childOrder( childOrder ).build() ); return convert( result ); } catch ( final ContentNotFoundException e ) { return new ContentsResultMapper( Contents.empty(), 0 ); } }
@Override protected Object doExecute() { final int start = valueOrDefault( this.start, 0 ); final int count = valueOrDefault( this.count, GetChildContentHandler.DEFAULT_COUNT ); final String query = valueOrDefault( this.query, "" ).trim(); final String sort = valueOrDefault( this.sort, "" ).trim(); final ContentTypeNames contentTypeNames = getContentTypeNames(); final List<OrderExpr> orderExpressions = QueryParser.parseOrderExpressions( sort ); final ConstraintExpr constraintExpr = QueryParser.parseCostraintExpression( query ); final QueryExpr queryExpr = QueryExpr.from( constraintExpr, orderExpressions ); final Filters filters = JsonToFilterMapper.create( this.filters ); final Set<AggregationQuery> aggregations = new QueryAggregationParams().getAggregations( this.aggregations ); final ContentQuery.Builder queryBuilder = ContentQuery.create(). from( start ). size( count ). aggregationQueries( aggregations ). addContentTypeNames( contentTypeNames ). queryExpr( queryExpr ); for ( final Filter filter : filters ) { queryBuilder.queryFilter( filter ); } final FindContentIdsByQueryResult queryResult = contentService.find( queryBuilder.build() ); return convert( queryResult ); }
private Content getByPath( final ContentPath contentPath ) { try { return this.contentService.getByPath( contentPath ); } catch ( ContentNotFoundException e ) { return null; } }
private ByteSource getById( final ContentId key ) { try { return getAttachment( this.contentService.getById( key ), this.name ); } catch ( final ContentNotFoundException e ) { return null; } }
public void execute() { UpdateContentParams updateContent = new UpdateContentParams(); if ( !this.key.startsWith( "/" ) ) { updateContent.contentId( ContentId.from( this.key ) ); } else { final Content contentByPath = this.contentService.getByPath( ContentPath.from( key ) ); updateContent.contentId( contentByPath.getId() ); } final CreateAttachment createAttachment = CreateAttachment.create(). name( this.name ). label( this.label ). mimeType( this.mimeType ). byteSource( getData() ). build(); updateContent.createAttachments( CreateAttachments.from( createAttachment ) ); contentService.update( updateContent ); }
protected String generateUniqueContentName( final Supplier<String> idGenerator, final ContentPath parent, final String baseName ) { String name = baseName; while ( this.contentService.contentExists( ContentPath.from( parent, name ) ) ) { final String randomId = idGenerator.get(); if ( baseName.contains( "." ) ) { final String fileName = StringUtils.substringBeforeLast( baseName, "." ); final String ext = StringUtils.substringAfterLast( baseName, "." ); name = fileName + "-" + randomId + "." + ext; } else { name = baseName + "-" + randomId; } } return name; }
@Override protected Object doExecute() { String name = this.name; Content result = null; final ContentPath parent = this.parentPath != null ? ContentPath.from( this.parentPath ) : ContentPath.ROOT; while ( result == null ) { final CreateMediaParams params = createParams( name ); try { result = this.contentService.create( params ); } catch ( ContentAlreadyExistsException e ) { name = generateUniqueContentName( this.idGenerator, parent, this.name ); } } return new ContentMapper( result ); }
private Content getByPath( final ContentPath contentPath ) { try { return this.contentService.getByPath( contentPath ); } catch ( ContentNotFoundException e ) { return null; } }