Search in sources :

Example 1 with ContentMapper

use of com.enonic.xp.lib.content.mapper.ContentMapper in project xp by enonic.

the class ModifyContentHandler method doExecute.

@Override
protected Object doExecute() {
    final Content existingContent = getExistingContent(this.key);
    if (existingContent == null) {
        return null;
    }
    final UpdateContentParams params = new UpdateContentParams();
    params.contentId(existingContent.getId());
    params.editor(newContentEditor(existingContent));
    params.requireValid(this.requireValid);
    final Content result = this.contentService.update(params);
    return result != null ? new ContentMapper(result) : null;
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) EditableContent(com.enonic.xp.content.EditableContent) ContentMapper(com.enonic.xp.lib.content.mapper.ContentMapper)

Example 2 with ContentMapper

use of com.enonic.xp.lib.content.mapper.ContentMapper in project xp by enonic.

the class CreateContentHandler method doExecute.

@Override
protected Object doExecute() {
    if (nullToEmpty(this.name).isBlank() && !nullToEmpty(this.displayName).isBlank() && !nullToEmpty(this.parentPath).isBlank()) {
        this.name = generateUniqueContentName(ContentPath.from(this.parentPath), this.displayName);
    }
    if (nullToEmpty(this.displayName).isBlank() && !nullToEmpty(this.name).isBlank()) {
        this.displayName = this.name;
    }
    final CreateContentParams params = createParams();
    final Content result = this.contentService.create(params);
    return new ContentMapper(result);
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) ContentMapper(com.enonic.xp.lib.content.mapper.ContentMapper)

Example 3 with ContentMapper

use of com.enonic.xp.lib.content.mapper.ContentMapper in project xp by enonic.

the class CreateMediaHandler method doExecute.

@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);
}
Also used : CreateMediaParams(com.enonic.xp.content.CreateMediaParams) Content(com.enonic.xp.content.Content) ContentAlreadyExistsException(com.enonic.xp.content.ContentAlreadyExistsException) ContentMapper(com.enonic.xp.lib.content.mapper.ContentMapper) ContentPath(com.enonic.xp.content.ContentPath)

Aggregations

Content (com.enonic.xp.content.Content)3 ContentMapper (com.enonic.xp.lib.content.mapper.ContentMapper)3 ContentAlreadyExistsException (com.enonic.xp.content.ContentAlreadyExistsException)1 ContentPath (com.enonic.xp.content.ContentPath)1 CreateContentParams (com.enonic.xp.content.CreateContentParams)1 CreateMediaParams (com.enonic.xp.content.CreateMediaParams)1 EditableContent (com.enonic.xp.content.EditableContent)1 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)1