Search in sources :

Example 1 with UpdateRepositoryParams

use of com.enonic.xp.repository.UpdateRepositoryParams in project xp by enonic.

the class ModifyRepositoryHandler method execute.

public RepositoryMapper execute() {
    final RepositoryId repositoryId = RepositoryId.from(id);
    final UpdateRepositoryParams updateRepositoryParams = UpdateRepositoryParams.create().repositoryId(repositoryId).editor(this::editRepository).build();
    return new RepositoryMapper(repositoryServiceSupplier.get().updateRepository(updateRepositoryParams));
}
Also used : RepositoryMapper(com.enonic.xp.lib.repo.mapper.RepositoryMapper) UpdateRepositoryParams(com.enonic.xp.repository.UpdateRepositoryParams) RepositoryId(com.enonic.xp.repository.RepositoryId)

Example 2 with UpdateRepositoryParams

use of com.enonic.xp.repository.UpdateRepositoryParams in project xp by enonic.

the class ModifyRepositoryHandlerTest method modifyScoped.

@Test
void modifyScoped() throws Exception {
    runScript("/lib/xp/examples/repo/modifyScoped.js");
    ArgumentCaptor<UpdateRepositoryParams> captor = ArgumentCaptor.forClass(UpdateRepositoryParams.class);
    Mockito.verify(this.repositoryService, Mockito.times(1)).updateRepository(captor.capture());
    final UpdateRepositoryParams capturedParams = captor.getValue();
    final EditableRepository edited = new EditableRepository(MOCK_REPO);
    capturedParams.getEditor().accept(edited);
    assertEquals("toBeModified", edited.source.getData().getString("myScopedObject.myScopedString"), "Test is invalid");
    assertEquals("modified", edited.data.getString("myScopedObject.myScopedString"));
    assertEquals("toBeKeptValue", edited.data.getString("toBeKept"));
    final BinaryAttachment attachment = edited.binaryAttachments.get(0);
    assertEquals(BinaryReference.from("myFile"), attachment.getReference());
    assertTrue(attachment.getByteSource().contentEquals(ByteSource.wrap("Hello World".getBytes())));
}
Also used : UpdateRepositoryParams(com.enonic.xp.repository.UpdateRepositoryParams) EditableRepository(com.enonic.xp.repository.EditableRepository) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) Test(org.junit.jupiter.api.Test)

Example 3 with UpdateRepositoryParams

use of com.enonic.xp.repository.UpdateRepositoryParams in project xp by enonic.

the class ModifyRepositoryHandlerTest method modifyRemoveProperty.

@Test
void modifyRemoveProperty() {
    runScript("/lib/xp/examples/repo/modifyRemoveProperty.js");
    ArgumentCaptor<UpdateRepositoryParams> captor = ArgumentCaptor.forClass(UpdateRepositoryParams.class);
    Mockito.verify(this.repositoryService, Mockito.times(1)).updateRepository(captor.capture());
    final UpdateRepositoryParams capturedParams = captor.getValue();
    final EditableRepository edited = new EditableRepository(MOCK_REPO);
    capturedParams.getEditor().accept(edited);
    assertTrue(edited.source.getData().hasProperty("myScopedObject"), "Test is invalid");
    assertFalse(edited.data.hasProperty("myScopedObject"));
}
Also used : UpdateRepositoryParams(com.enonic.xp.repository.UpdateRepositoryParams) EditableRepository(com.enonic.xp.repository.EditableRepository) Test(org.junit.jupiter.api.Test)

Example 4 with UpdateRepositoryParams

use of com.enonic.xp.repository.UpdateRepositoryParams in project xp by enonic.

the class ProjectServiceImpl method doModify.

private Project doModify(final ModifyProjectParams params) {
    final UpdateRepositoryParams updateParams = UpdateRepositoryParams.create().repositoryId(params.getName().getRepoId()).editor(editableRepository -> modifyProjectData(params, editableRepository.data)).build();
    final Repository updatedRepository = repositoryService.updateRepository(updateParams);
    if (!ProjectConstants.DEFAULT_PROJECT_NAME.equals(params.getName())) {
        UpdateProjectRoleNamesCommand.create().securityService(securityService).projectName(params.getName()).projectDisplayName(params.getDisplayName()).build().execute();
    }
    return Project.from(updatedRepository);
}
Also used : ArchiveInitializer(com.enonic.xp.core.impl.project.init.ArchiveInitializer) DeleteRepositoryParams(com.enonic.xp.repository.DeleteRepositoryParams) RepositoryService(com.enonic.xp.repository.RepositoryService) LoggerFactory(org.slf4j.LoggerFactory) AttachmentSerializer(com.enonic.xp.attachment.AttachmentSerializer) ImageHelper(com.enonic.xp.image.ImageHelper) IndexService(com.enonic.xp.index.IndexService) BigDecimal(java.math.BigDecimal) RepositoryId(com.enonic.xp.repository.RepositoryId) ContextAccessor(com.enonic.xp.context.ContextAccessor) NodeService(com.enonic.xp.node.NodeService) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) ImageIO(javax.imageio.ImageIO) ContextBuilder(com.enonic.xp.context.ContextBuilder) EnumSet(java.util.EnumSet) SecurityService(com.enonic.xp.security.SecurityService) RoundingMode(java.math.RoundingMode) BinaryReference(com.enonic.xp.util.BinaryReference) ProjectService(com.enonic.xp.project.ProjectService) Projects(com.enonic.xp.project.Projects) BufferedImage(java.awt.image.BufferedImage) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) Project(com.enonic.xp.project.Project) Collectors(java.util.stream.Collectors) CreateProjectParams(com.enonic.xp.project.CreateProjectParams) UpdateRepositoryParams(com.enonic.xp.repository.UpdateRepositoryParams) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) ProjectNotFoundException(com.enonic.xp.project.ProjectNotFoundException) Optional(java.util.Optional) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) Queue(java.util.Queue) Repository(com.enonic.xp.repository.Repository) EventPublisher(com.enonic.xp.event.EventPublisher) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Callable(java.util.concurrent.Callable) Attachment(com.enonic.xp.attachment.Attachment) ProjectConstants(com.enonic.xp.project.ProjectConstants) ProjectGraphEntry(com.enonic.xp.project.ProjectGraphEntry) ArrayList(java.util.ArrayList) IssueInitializer(com.enonic.xp.core.impl.project.init.IssueInitializer) ProjectRole(com.enonic.xp.project.ProjectRole) CreateAttachments(com.enonic.xp.attachment.CreateAttachments) ProjectName(com.enonic.xp.project.ProjectName) ContentInitializer(com.enonic.xp.core.impl.project.init.ContentInitializer) ModifyProjectIconParams(com.enonic.xp.project.ModifyProjectIconParams) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) Logger(org.slf4j.Logger) ProjectGraph(com.enonic.xp.project.ProjectGraph) ProjectPermissions(com.enonic.xp.project.ProjectPermissions) PropertySet(com.enonic.xp.data.PropertySet) IOException(java.io.IOException) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) ModifyProjectParams(com.enonic.xp.project.ModifyProjectParams) InputStream(java.io.InputStream) Repository(com.enonic.xp.repository.Repository) UpdateRepositoryParams(com.enonic.xp.repository.UpdateRepositoryParams)

Example 5 with UpdateRepositoryParams

use of com.enonic.xp.repository.UpdateRepositoryParams in project xp by enonic.

the class ProjectServiceImpl method doModifyIcon.

private void doModifyIcon(final ModifyProjectIconParams params) {
    final UpdateRepositoryParams updateParams = UpdateRepositoryParams.create().repositoryId(params.getName().getRepoId()).editor(editableRepository -> {
        if (params.getIcon() != null) {
            try {
                editableRepository.binaryAttachments.add(createProjectIcon(params.getIcon(), params.getScaleWidth()));
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }
        final PropertySet projectData = editableRepository.data.getSet(ProjectConstants.PROJECT_DATA_SET_NAME);
        setIconData(projectData, params.getIcon());
    }).build();
    repositoryService.updateRepository(updateParams);
}
Also used : ArchiveInitializer(com.enonic.xp.core.impl.project.init.ArchiveInitializer) DeleteRepositoryParams(com.enonic.xp.repository.DeleteRepositoryParams) RepositoryService(com.enonic.xp.repository.RepositoryService) LoggerFactory(org.slf4j.LoggerFactory) AttachmentSerializer(com.enonic.xp.attachment.AttachmentSerializer) ImageHelper(com.enonic.xp.image.ImageHelper) IndexService(com.enonic.xp.index.IndexService) BigDecimal(java.math.BigDecimal) RepositoryId(com.enonic.xp.repository.RepositoryId) ContextAccessor(com.enonic.xp.context.ContextAccessor) NodeService(com.enonic.xp.node.NodeService) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) ImageIO(javax.imageio.ImageIO) ContextBuilder(com.enonic.xp.context.ContextBuilder) EnumSet(java.util.EnumSet) SecurityService(com.enonic.xp.security.SecurityService) RoundingMode(java.math.RoundingMode) BinaryReference(com.enonic.xp.util.BinaryReference) ProjectService(com.enonic.xp.project.ProjectService) Projects(com.enonic.xp.project.Projects) BufferedImage(java.awt.image.BufferedImage) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) Project(com.enonic.xp.project.Project) Collectors(java.util.stream.Collectors) CreateProjectParams(com.enonic.xp.project.CreateProjectParams) UpdateRepositoryParams(com.enonic.xp.repository.UpdateRepositoryParams) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) ProjectNotFoundException(com.enonic.xp.project.ProjectNotFoundException) Optional(java.util.Optional) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) Queue(java.util.Queue) Repository(com.enonic.xp.repository.Repository) EventPublisher(com.enonic.xp.event.EventPublisher) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Callable(java.util.concurrent.Callable) Attachment(com.enonic.xp.attachment.Attachment) ProjectConstants(com.enonic.xp.project.ProjectConstants) ProjectGraphEntry(com.enonic.xp.project.ProjectGraphEntry) ArrayList(java.util.ArrayList) IssueInitializer(com.enonic.xp.core.impl.project.init.IssueInitializer) ProjectRole(com.enonic.xp.project.ProjectRole) CreateAttachments(com.enonic.xp.attachment.CreateAttachments) ProjectName(com.enonic.xp.project.ProjectName) ContentInitializer(com.enonic.xp.core.impl.project.init.ContentInitializer) ModifyProjectIconParams(com.enonic.xp.project.ModifyProjectIconParams) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) Logger(org.slf4j.Logger) ProjectGraph(com.enonic.xp.project.ProjectGraph) ProjectPermissions(com.enonic.xp.project.ProjectPermissions) PropertySet(com.enonic.xp.data.PropertySet) IOException(java.io.IOException) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) ModifyProjectParams(com.enonic.xp.project.ModifyProjectParams) InputStream(java.io.InputStream) UpdateRepositoryParams(com.enonic.xp.repository.UpdateRepositoryParams) PropertySet(com.enonic.xp.data.PropertySet) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Aggregations

UpdateRepositoryParams (com.enonic.xp.repository.UpdateRepositoryParams)6 BinaryAttachment (com.enonic.xp.node.BinaryAttachment)4 RepositoryId (com.enonic.xp.repository.RepositoryId)3 Attachment (com.enonic.xp.attachment.Attachment)2 AttachmentSerializer (com.enonic.xp.attachment.AttachmentSerializer)2 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)2 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)2 Context (com.enonic.xp.context.Context)2 ContextAccessor (com.enonic.xp.context.ContextAccessor)2 ContextBuilder (com.enonic.xp.context.ContextBuilder)2 ArchiveInitializer (com.enonic.xp.core.impl.project.init.ArchiveInitializer)2 ContentInitializer (com.enonic.xp.core.impl.project.init.ContentInitializer)2 IssueInitializer (com.enonic.xp.core.impl.project.init.IssueInitializer)2 PropertySet (com.enonic.xp.data.PropertySet)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 EventPublisher (com.enonic.xp.event.EventPublisher)2 ImageHelper (com.enonic.xp.image.ImageHelper)2 IndexService (com.enonic.xp.index.IndexService)2 NodeService (com.enonic.xp.node.NodeService)2 CreateProjectParams (com.enonic.xp.project.CreateProjectParams)2