Search in sources :

Example 36 with RepositoryId

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

the class RenameContentCommandTest method test_already_exists.

@Test
void test_already_exists() {
    Node mockNode = Node.create().id(NodeId.from("testId")).build();
    final RepositoryId repositoryId = RepositoryId.from("some.repo");
    final Branch branch = Branch.from("somebranch");
    when(nodeService.rename(isA(RenameNodeParams.class))).thenThrow(new NodeAlreadyExistAtPathException(NodePath.create("/content/mycontent2").build(), repositoryId, branch));
    when(nodeService.getById(mockNode.id())).thenReturn(mockNode);
    final Content content = createContent(true);
    final RenameContentCommand command = createCommand(RenameContentParams.create().contentId(content.getId()).newName(ContentName.from("mycontent2")).build());
    final ContentAlreadyExistsException exception = assertThrows(ContentAlreadyExistsException.class, command::execute);
    assertEquals(branch, exception.getBranch());
    assertEquals(repositoryId, exception.getRepositoryId());
}
Also used : Branch(com.enonic.xp.branch.Branch) Content(com.enonic.xp.content.Content) Node(com.enonic.xp.node.Node) RenameNodeParams(com.enonic.xp.node.RenameNodeParams) ContentAlreadyExistsException(com.enonic.xp.content.ContentAlreadyExistsException) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) RepositoryId(com.enonic.xp.repository.RepositoryId) Test(org.junit.jupiter.api.Test)

Example 37 with RepositoryId

use of com.enonic.xp.repository.RepositoryId 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 38 with RepositoryId

use of com.enonic.xp.repository.RepositoryId 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)

Example 39 with RepositoryId

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

the class AbstractMetaDumpUpgrader method doUpgrade.

@Override
public void doUpgrade(final String dumpName) {
    super.doUpgrade(dumpName);
    final String timeMillis = Long.toString(System.currentTimeMillis());
    FilePaths tmpFilePaths = new DefaultFilePaths() {

        @Override
        public PathRef branchMetaPath(final RepositoryId repositoryId, final Branch branch) {
            return branchRootPath(repositoryId).resolve(branch.toString()).resolve("meta-" + timeMillis + ".tar.gz");
        }

        @Override
        public PathRef versionMetaPath(final RepositoryId repositoryId) {
            return branchRootPath(repositoryId).resolve("versions-" + timeMillis + ".tar.gz");
        }
    };
    tmpDumpReader = FileDumpReader.create(null, basePath, dumpName, tmpFilePaths);
    tmpDumpWriter = FileDumpWriter.create(basePath, dumpName, null, tmpFilePaths);
    try {
        dumpReader.getRepositories().forEach(this::upgradeRepository);
        overwriteSourceFiles();
    } catch (Exception e) {
        try {
            deleteBufferFiles();
        } catch (Exception e2) {
            LOG.error("Error while deleting buffer files", e);
        }
        throw new DumpUpgradeException("Error while upgrading dump [" + dumpName + "]", e);
    } finally {
        try {
            tmpDumpReader.close();
            tmpDumpWriter.close();
        } catch (IOException e) {
            LOG.error("Error while closing dump writer", e);
        }
    }
}
Also used : FilePaths(com.enonic.xp.repo.impl.dump.FilePaths) DefaultFilePaths(com.enonic.xp.repo.impl.dump.DefaultFilePaths) Branch(com.enonic.xp.branch.Branch) DefaultFilePaths(com.enonic.xp.repo.impl.dump.DefaultFilePaths) IOException(java.io.IOException) RepositoryId(com.enonic.xp.repository.RepositoryId) IOException(java.io.IOException)

Example 40 with RepositoryId

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

the class CommitDumpUpgrader method upgradeVersionEntry.

@Override
protected byte[] upgradeVersionEntry(final RepositoryId repositoryId, final String entryContent) {
    final Pre6VersionsDumpEntryJson sourceEntry = deserializeValue(entryContent, Pre6VersionsDumpEntryJson.class);
    final VersionsDumpEntryJson.Builder upgradedEntry = VersionsDumpEntryJson.create().nodeId(sourceEntry.getNodeId());
    sourceEntry.getVersions().stream().map(version -> {
        final boolean commit = commitedVersionIds.contains(version.getVersion());
        return upgradeVersionDumpEntry(version, commit);
    }).forEach(upgradedEntry::version);
    return serialize(upgradedEntry.build());
}
Also used : AbstractMetaDumpUpgrader(com.enonic.xp.repo.impl.dump.upgrade.AbstractMetaDumpUpgrader) BranchDumpEntryJson(com.enonic.xp.repo.impl.dump.serializer.json.BranchDumpEntryJson) VersionsDumpEntryJson(com.enonic.xp.repo.impl.dump.serializer.json.VersionsDumpEntryJson) Files(java.nio.file.Files) Version(com.enonic.xp.util.Version) Pre6VersionsDumpEntryJson(com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre6.Pre6VersionsDumpEntryJson) NodeCommitId(com.enonic.xp.node.NodeCommitId) VersionDumpEntryJson(com.enonic.xp.repo.impl.dump.serializer.json.VersionDumpEntryJson) Pre6BranchDumpEntryJson(com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre6.Pre6BranchDumpEntryJson) HashSet(java.util.HashSet) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) RepositoryId(com.enonic.xp.repository.RepositoryId) Pre6VersionDumpEntryJson(com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre6.Pre6VersionDumpEntryJson) CommitDumpEntryJson(com.enonic.xp.repo.impl.dump.serializer.json.CommitDumpEntryJson) Path(java.nio.file.Path) RepositoryConstants(com.enonic.xp.repository.RepositoryConstants) VersionsDumpEntryJson(com.enonic.xp.repo.impl.dump.serializer.json.VersionsDumpEntryJson) Pre6VersionsDumpEntryJson(com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre6.Pre6VersionsDumpEntryJson) Pre6VersionsDumpEntryJson(com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre6.Pre6VersionsDumpEntryJson)

Aggregations

RepositoryId (com.enonic.xp.repository.RepositoryId)61 Test (org.junit.jupiter.api.Test)21 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)19 Branch (com.enonic.xp.branch.Branch)14 Repository (com.enonic.xp.repository.Repository)11 Node (com.enonic.xp.node.Node)9 ByteSource (com.google.common.io.ByteSource)8 IOException (java.io.IOException)7 PropertyTree (com.enonic.xp.data.PropertyTree)6 Segment (com.enonic.xp.blob.Segment)5 Context (com.enonic.xp.context.Context)5 ContextAccessor (com.enonic.xp.context.ContextAccessor)5 ContextBuilder (com.enonic.xp.context.ContextBuilder)5 BlobKey (com.enonic.xp.blob.BlobKey)4 EventPublisher (com.enonic.xp.event.EventPublisher)4 BinaryAttachment (com.enonic.xp.node.BinaryAttachment)4 Project (com.enonic.xp.project.Project)4 DumpConstants (com.enonic.xp.repo.impl.dump.DumpConstants)4 DumpBlobRecord (com.enonic.xp.repo.impl.dump.blobstore.DumpBlobRecord)4 RepositoryIds (com.enonic.xp.repository.RepositoryIds)4